S32 SDK
lpspi_shared_function.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2015-2016, Freescale Semiconductor, Inc.
3  * Copyright 2016 NXP
4  * All rights reserved.
5  *
6  * THIS SOFTWARE IS PROVIDED BY NXP "AS IS" AND ANY EXPRESSED OR
7  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
8  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
9  * IN NO EVENT SHALL NXP OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
10  * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
11  * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
12  * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
13  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
14  * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
15  * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
16  * THE POSSIBILITY OF SUCH DAMAGE.
17  */
18 
34 #ifndef LPSPI_SHARED_FUNCTION_H
35 #define LPSPI_SHARED_FUNCTION_H
36 
37 #include <stdbool.h>
38 #include "edma_driver.h"
39 #include "clock_manager.h"
40 #include "osif.h"
41 #include "status.h"
42 #include "callbacks.h"
43 
50 /*******************************************************************************
51  * Definitions
52  ******************************************************************************/
53 
54 /* Extern for the LPSPI master driver's interrupt handler.*/
55 extern void LPSPI_DRV_MasterIRQHandler(uint32_t instance);
56 
57 /* Extern for the LPSPI slave driver's interrupt handler.*/
58 extern void LPSPI_DRV_SlaveIRQHandler(uint32_t instance);
59 
63 typedef enum
64 {
65  LPSPI_PCS0 = 0U,
66  LPSPI_PCS1 = 1U,
67  LPSPI_PCS2 = 2U,
68  LPSPI_PCS3 = 3U
70 
74 typedef enum
75 {
79 
83 typedef enum
84 {
88 
92 typedef enum
93 {
97 
98 
102 typedef enum
103 {
107 
110 typedef enum
111 {
116 
127 typedef struct
128 {
129  uint16_t bitsPerFrame;
131  uint16_t bytesPerFrame;
134  bool isBlocking;
135  uint32_t lpspiSrcClk;
136  volatile bool isTransferInProgress;
137  const uint8_t * txBuff;
138  uint8_t * rxBuff;
139  volatile uint16_t txCount;
140  volatile uint16_t rxCount;
141  volatile uint16_t txFrameCnt;
142  volatile uint16_t rxFrameCnt;
143  volatile bool lsb;
144  uint8_t fifoSize;
145  uint8_t rxDMAChannel;
146  uint8_t txDMAChannel;
148  semaphore_t lpspiSemaphore;
152 } lpspi_state_t;
153 
154 /*******************************************************************************
155  * Variables
156  ******************************************************************************/
159 
162 
163 /* Pointer to runtime state structure.*/
165 
166 /*******************************************************************************
167  * Prototypes
168  ******************************************************************************/
169 
180 void LPSPI_DRV_IRQHandler(uint32_t instance);
181 
186 void LPSPI_DRV_FillupTxBuffer(uint32_t instance);
187 
192 void LPSPI_DRV_ReadRXBuffer(uint32_t instance);
193 
198 void LPSPI_DRV_DisableTEIEInterrupts(uint32_t instance);
202 #endif /* __LPSPI_SHARED_FUNCTION_H__*/
203 /*******************************************************************************
204  * EOF
205  ******************************************************************************/
206 
volatile uint16_t rxFrameCnt
#define LPSPI_INSTANCE_COUNT
Definition: S32K142.h:6130
volatile uint16_t txFrameCnt
Runtime state structure for the LPSPI master driver.
void LPSPI_DRV_ReadRXBuffer(uint32_t instance)
The function LPSPI_DRV_ReadRXBuffer reads data from RX hardware buffer and writes this data in RX sof...
lpspi_transfer_type transferType
lpspi_state_t * g_lpspiStatePtr[LPSPI_INSTANCE_COUNT]
spi_callback_t callback
void(* spi_callback_t)(void *driverState, spi_event_t event, void *userData)
Definition: callbacks.h:44
void LPSPI_DRV_FillupTxBuffer(uint32_t instance)
The function LPSPI_DRV_FillupTxBuffer writes data in TX hardware buffer depending on driver state and...
volatile uint16_t rxCount
void LPSPI_DRV_MasterIRQHandler(uint32_t instance)
Interrupt handler for LPSPI master mode. This handler uses the buffers stored in the lpspi_master_sta...
volatile uint16_t txCount
void LPSPI_DRV_IRQHandler(uint32_t instance)
The function LPSPI_DRV_IRQHandler passes IRQ control to either the master or slave driver...
lpspi_signal_polarity_t
LPSPI Signal (PCS and Host Request) Polarity configuration. Implements : lpspi_signal_polarity_t_Clas...
lpspi_transfer_type
Type of LPSPI transfer (based on interrupts or DMA). Implements : lpspi_transfer_type_Class.
IRQn_Type g_lpspiIrqId[LPSPI_INSTANCE_COUNT]
Table to save LPSPI IRQ enumeration numbers defined in the CMSIS header file.
lpspi_which_pcs_t
LPSPI Peripheral Chip Select (PCS) configuration (which PCS to configure). Implements : lpspi_which_p...
void LPSPI_DRV_DisableTEIEInterrupts(uint32_t instance)
Disable the TEIE interrupts at the end of a transfer. Disable the interrupts and clear the status for...
lpspi_clock_phase_t
LPSPI clock phase configuration. Implements : lpspi_clock_phase_t_Class.
lpspi_sck_polarity_t
LPSPI Clock Signal (SCK) Polarity configuration. Implements : lpspi_sck_polarity_t_Class.
volatile bool isTransferInProgress
LPSPI_Type * g_lpspiBase[LPSPI_INSTANCE_COUNT]
Table of base pointers for SPI instances.
const uint8_t * txBuff
void LPSPI_DRV_SlaveIRQHandler(uint32_t instance)
Interrupt handler for LPSPI slave mode. This handler uses the buffers stored in the lpspi_master_stat...
semaphore_t lpspiSemaphore
transfer_status_t
Type of error reported by LPSPI.
IRQn_Type
Defines the Interrupt Numbers definitions.
Definition: S32K142.h:192
transfer_status_t status