Hilscher netX microcontroller driver
V0.0.5.0
Documentation of the netX driver package
|
The SPI driver, defined by DRV_SPI_HANDLE_T. More...
Data Structures | |
struct | DRV_SPI_MODE_T |
Bitfield for the spi mode. More... | |
union | DRV_SPI_MODE_U |
Union for the spi mode. More... | |
struct | DRV_SPI_CONFIGURATION_T |
The configuration structure of the SPI device driver. More... | |
struct | DRV_SPI_HANDLE_T |
The handle of the driver. More... | |
Macros | |
#define | DRV_HANDLE_CHECK(handle) |
#define | DRV_SPI_IRQHandler_Generator(id, _) DRV_Default_IRQHandler_Function_Generator(DRV_SPI_IRQ_HANDLER ## id,DRV_SPI_IRQ_Inline_Handler,(DRV_SPI_DEVICE_ID_E)(DRV_SPI_DEVICE_ID_MIN + id)) |
Functions | |
static void | DRV_SPI_Flush_DMA_Callback_Rx (void *ptDriverHandle, DRV_SPI_HANDLE_T *const ptDriver) |
static void | DRV_SPI_Flush_DMA_Callback_Tx (void *ptDriverHandle, DRV_SPI_HANDLE_T *const ptDriver) |
DRV_STATUS_E | DRV_SPI_HANDLE_T::DRV_SPI_Init (DRV_SPI_HANDLE_T *const ptDriver) |
This function initializes the DRV_SPI_HANDLE_T object. More... | |
DRV_STATUS_E | DRV_SPI_HANDLE_T::DRV_SPI_DeInit (DRV_SPI_HANDLE_T *const ptDriver) |
This function disables the DRV_SPI_HANDLE_T object. More... | |
DRV_STATUS_E | DRV_SPI_HANDLE_T::DRV_SPI_Transmit (DRV_SPI_HANDLE_T *const ptDriver, uint8_t *pcData, size_t size) |
Function for transmitting data of given size via the SPI device. More... | |
DRV_STATUS_E | DRV_SPI_HANDLE_T::DRV_SPI_Receive (DRV_SPI_HANDLE_T *const ptDriver, uint8_t *pcData, size_t size) |
Function for receiveing data of given size by the SPI device. More... | |
DRV_STATUS_E | DRV_SPI_HANDLE_T::DRV_SPI_TransmitReceive (DRV_SPI_HANDLE_T *const ptDriver, uint8_t *txData, uint8_t *rxData, size_t size) |
Function for transmitting and receiveing data at the same time of given size by the SPI device. More... | |
DRV_STATUS_E | DRV_SPI_HANDLE_T::DRV_SPI_ChangeFss (DRV_SPI_HANDLE_T *const ptDriver, DRV_SPI_FSS_E eFss) |
Function for changing the fss between transactions. More... | |
DRV_STATUS_E | DRV_SPI_HANDLE_T::DRV_SPI_Abort (DRV_SPI_HANDLE_T *const ptDriver) |
Function for aborting the current data transfer on the SPI device. More... | |
DRV_STATUS_E | DRV_SPI_HANDLE_T::DRV_SPI_GetState (DRV_SPI_HANDLE_T *const ptDriver, DRV_SPI_STATE_E *const ptState) |
Function returning a driver spi state enumeration and a return code. More... | |
__STATIC_INLINE DRV_STATUS_E | DRV_SPI_HANDLE_T::DRV_SPI_Flush_Buffers (DRV_SPI_HANDLE_T *const ptDriver) |
This function shall flush the software and hardware buffers of the device. More... | |
static DRV_STATUS_E | DRV_SPI_HANDLE_T::DRV_SPI_Flush_POLL (DRV_SPI_HANDLE_T *const ptDriver) |
This method shall perform a flush by polling mode. More... | |
static DRV_STATUS_E | DRV_SPI_HANDLE_T::DRV_SPI_Flush_IRQ (DRV_SPI_HANDLE_T *const ptDriver) |
This method shall perform a flush by interrupt mode. More... | |
static DRV_STATUS_E | DRV_SPI_HANDLE_T::DRV_SPI_Flush_DMA (DRV_SPI_HANDLE_T *const ptDriver) |
This method shall perform a flush by dma mode. More... | |
__STATIC_INLINE void | DRV_SPI_HANDLE_T::DRV_SPI_IRQ_Inline_Handler (DRV_SPI_DEVICE_ID_E const eDeviceID) |
Variables | |
static DRV_SPI_DEVICE_U const | s_apDeviceAddressTable [DRV_SPI_DEVICE_COUNT] = DRV_SPI_DEVICE_LIST |
Table of the device addresses. More... | |
static DRV_DMAC_PERIPHERAL_E const | s_apDeviceDmacTable [DRV_SPI_DEVICE_COUNT] = DRV_SPI_DEVICE_DMA_LIST |
Table of the dma channels of the devices. More... | |
static IRQn_Type const | s_apHandleIRQnTable [DRV_SPI_DEVICE_COUNT] = DRV_SPI_DEVICE_IRQ_LIST |
Table of the IRQ vector numbers. More... | |
static DRV_SPI_HANDLE_T * | s_apHandleAddressTable [DRV_SPI_DEVICE_COUNT] = { 0 } |
Used for mapping the handle to an interrupt. More... | |
The SPI driver, defined by DRV_SPI_HANDLE_T.
#define DRV_HANDLE_CHECK | ( | handle | ) |
Define for checking the consistency of the handle or static representation of the driver.
Definition at line 92 of file netx_drv_spi.c.
#define DRV_SPI_IRQHandler_Generator | ( | id, | |
_ | |||
) | DRV_Default_IRQHandler_Function_Generator(DRV_SPI_IRQ_HANDLER ## id,DRV_SPI_IRQ_Inline_Handler,(DRV_SPI_DEVICE_ID_E)(DRV_SPI_DEVICE_ID_MIN + id)) |
The generator define for generating irq handler source code.
Definition at line 1262 of file netx_drv_spi.c.
enum DRV_SPI_BEHAVIOUR_E |
Enumeration of the master/slave mode.
Enumerator | |
---|---|
DRV_SPI_BEHAVIOUR_MASTER |
Behaves as master. |
DRV_SPI_BEHAVIOUR_SLAVE |
Behaves as slave |
Definition at line 90 of file netx_drv_spi.h.
Enumeration of the data size of a word transmitted. Has no impact on SQI devices.
Definition at line 264 of file netx_drv_spi.h.
Enumeration of dummy patterns available to send when only one of the full duplex lines are used.
Definition at line 252 of file netx_drv_spi.h.
enum DRV_SPI_DUPLEX_E |
Enumeration of the duplex mode.
Full duplex is only available for SPI mode. QSPI with 1/2/4 bit is only half duplex.
Enumerator | |
---|---|
DRV_SPI_DUPLEX_HALF |
First edge |
DRV_SPI_DUPLEX_FULL |
Second edge |
Definition at line 126 of file netx_drv_spi.h.
enum DRV_SPI_ENDIANESS_E |
Enumeration of the Endianess used.
This is necessary if more than 8 bit data size is selected.
Enumerator | |
---|---|
DRV_SPI_ENDIANESS_LITTLE |
Little Endian |
DRV_SPI_ENDIANESS_BIG |
Big Endian |
Definition at line 182 of file netx_drv_spi.h.
enum DRV_SPI_FIFO_WM_E |
Enumeration of the water mark level of the fifos.
Definition at line 201 of file netx_drv_spi.h.
enum DRV_SPI_FILTER_E |
Enumeration of the filter state.
Enumerator | |
---|---|
DRV_SPI_FILTER_INACTIVE |
Disabled |
DRV_SPI_FILTER_ACTIVE |
Enabled |
Definition at line 233 of file netx_drv_spi.h.
Enumeration of the available frame formats of the spi.
Definition at line 212 of file netx_drv_spi.h.
enum DRV_SPI_FREQUENCY_E |
Enumeration of useful spi frequencies.
The value is a clock divider.
Definition at line 67 of file netx_drv_spi.h.
enum DRV_SPI_FSS_E |
Enumeration of the frame or slave select (FSS) signal pin mask.
This signal is commonly known as frame select FS, slave select SS or SSEL, chip select CS, chip enable CE or slave transmit enable STE.
Enumerator | |
---|---|
DRV_SPI_FSS_NONE |
No fss selected |
DRV_SPI_FSS_0 |
Drive pin 0 |
DRV_SPI_FSS_1 |
Drive pin 1 |
DRV_SPI_FSS_2 |
Drive pin 2 |
DRV_SPI_FSS_ALL |
Drive all pins |
Definition at line 53 of file netx_drv_spi.h.
enum DRV_SPI_FSS_STATIC_E |
Enumeration of the frame/chip select modes.
Definition at line 191 of file netx_drv_spi.h.
Enumeration of the loop back mode.
Enumerator | |
---|---|
DRV_SPI_LOOP_BACK_MODE_INACTIVE |
Disabled |
DRV_SPI_LOOP_BACK_MODE_ACTIVE |
Enabled |
Definition at line 242 of file netx_drv_spi.h.
enum DRV_SPI_MISO_E |
Enumeration of the mosi drive state as slave.
Enumerator | |
---|---|
DRV_SPI_MISO_ACTIVE |
MISO activated |
DRV_SPI_MISO_INACTIVE |
MISO deactivated |
Definition at line 42 of file netx_drv_spi.h.
enum DRV_SPI_MODE_E |
Enumeration of the sampling mode.
Enumerator | |
---|---|
DRV_SPI_MODE_0 |
CPOL 0 CPHA 0 |
DRV_SPI_MODE_1 |
CPOL 0 CPHA 1 |
DRV_SPI_MODE_2 |
CPOL 1 CPHA 0 |
DRV_SPI_MODE_3 |
CPOL 1 CPHA 1 |
DRV_SPI_MODE_MIN |
Minimum value |
DRV_SPI_MODE_MAX |
Maximum value |
Definition at line 99 of file netx_drv_spi.h.
Enumeration of the parallelism.
It defines how many bits will be transmitted in parallel on each clock. 2/4 Bit are only available as QSPI half duplex mode.
Definition at line 138 of file netx_drv_spi.h.
Enumeration of the modes of the early response bit generation.
Enumerator | |
---|---|
DRV_SPI_SLV_SIG_NOT_EARLY |
Generate first bit not early |
DRV_SPI_SLV_SIG_EARLY |
Generate first bit early |
Definition at line 224 of file netx_drv_spi.h.
enum DRV_SPI_SPH_E |
Enumeration of the serial clock phase.
If the data is sampled at the rising/first or falling/second edge. (DRV_SPI_SPO_CLOCK_INACTIVE_LOW)
Enumerator | |
---|---|
DRV_SPI_SPH_SAMPLE_AT_FIRST_EDGE |
First edge |
DRV_SPI_SPH_SAMPLE_AT_SECOND_EDGE |
Second edge |
Definition at line 115 of file netx_drv_spi.h.
enum DRV_SPI_SPO_E |
Enumeration of the serial clock polarity.
Definition at line 151 of file netx_drv_spi.h.
enum DRV_SPI_STATE_E |
Enumeration of the spi state informations.
Definition at line 288 of file netx_drv_spi.h.
DRV_STATUS_E DRV_SPI_Abort | ( | DRV_SPI_HANDLE_T *const | ptDriver | ) |
Function for aborting the current data transfer on the SPI device.
The abort function shall end pending interactions and reset any transaction. It forces the bus speed to zero and stops the device first, then sets the FSS to zero so that no peripheral is selected and masks all interrupts out or if dma is used calls the dma abort functionality. All buffers will then be reset and the device deactivated to reset its internal states. At last, the FSS and and bus speeds are set as configured again and the device is activated again.
[in,out] | ptDriver | The given handle of the drivers class |
Definition at line 1068 of file netx_drv_spi.c.
DRV_STATUS_E DRV_SPI_ChangeFss | ( | DRV_SPI_HANDLE_T *const | ptDriver, |
DRV_SPI_FSS_E | eFss | ||
) |
Function for changing the fss between transactions.
The change fss function checks only if the driver is not locked and the device is not busy. If that is true the configuration attribute is changed like in the init method specified.
[in,out] | ptDriver | The given handle of the drivers class |
[in] | eFss | The new FSS state |
Definition at line 1031 of file netx_drv_spi.c.
DRV_STATUS_E DRV_SPI_DeInit | ( | DRV_SPI_HANDLE_T *const | ptDriver | ) |
This function disables the DRV_SPI_HANDLE_T object.
The de-initialize function is supposed to reset the handle, the device and disable the interrupt signaling. The handle might be used afterwards again for initializing a SPI device driver handle.
[in,out] | ptDriver | The ptDriver to be deinitialized |
Definition at line 397 of file netx_drv_spi.c.
|
private |
This function shall flush the software and hardware buffers of the device.
This function is the hardware closest layer of the spi driver. The handle contains some variables defining the software buffer state. This state shall be equalized in this function. The transmit buffer is transfered to the transmit fifo of the device from the actual counter position to the given size. The receive fifo of the device is written to the current counter position until the given size is reached. If there is no buffer given, the function will transmit the dummy pattern specified in the attributes, and receives what is contained in the receive fifo but discard it.
[in,out] | ptDriver | The given handle of the drivers class |
Definition at line 424 of file netx_drv_spi.c.
|
private |
This method shall perform a flush by dma mode.
It is the middle layer between the api calls and the flush itself.
[in,out] | ptDriver | The given handle of the drivers class |
Definition at line 624 of file netx_drv_spi.c.
|
static |
This callback is used in dma operation mode. It is registered in the dmac api to get informed if the dma finished copying.
Definition at line 107 of file netx_drv_spi.c.
|
static |
This callback is used in dma operation mode. It is registered in the dmac api to get informed if the dma finished copying.
Definition at line 130 of file netx_drv_spi.c.
|
private |
This method shall perform a flush by interrupt mode.
It is the middle layer between the api calls and the flush itself. Because every flow is handled in the interrupt handler this method only modifies the interrupt masks.
[in,out] | ptDriver | The given handle of the drivers class |
Definition at line 582 of file netx_drv_spi.c.
|
private |
This method shall perform a flush by polling mode.
This method is the middle layer between the api calls and the hardware close flushing. It contains the polling method specific functionalities. After calling the hardware near flushing function DRV_SPI_Flush_Buffers() and waiting, that all data has been flushed, it waits until the driver has transmitted everything on the media and is finished. Then the FSS can be reset if it is software controlled and the software buffers can be reset again.
[in,out] | ptDriver | The given handle of the drivers class |
Definition at line 532 of file netx_drv_spi.c.
DRV_STATUS_E DRV_SPI_GetState | ( | DRV_SPI_HANDLE_T *const | ptDriver, |
DRV_SPI_STATE_E *const | ptState | ||
) |
Function returning a driver spi state enumeration and a return code.
The state of the driver is written to the ptSpiState pointer and an indicating status of the driver is returned. The returned status is the same as the other functions use to indicate a correct configure and idle driver and device ready for transmission. Because the error states depend mostly on the used transaction the spi state has to be checked by the caller. If a Tx buffer overflow occurs the function will return a DRV_ERROR because it is always an error.
Tx data has to be written to the spi device in master mode for reading data and TxBuffer underruns might occur. Rx data can be discarded in master mode for sending only but a RxBuffer overflow is produced. Rx data can be discarded in slave mode for sending only but a RxBuffer overflow is produced. Tx data might not be provided if a slave is reading only but a buffer underrun is produced.
[in,out] | ptDriver | The given handle of the drivers class. |
[out] | ptState | Pointer to a DRV_SPI_STATE_E where the state is written to. |
Definition at line 1159 of file netx_drv_spi.c.
DRV_STATUS_E DRV_SPI_Init | ( | DRV_SPI_HANDLE_T *const | ptDriver | ) |
This function initializes the DRV_SPI_HANDLE_T object.
The function takes a DRV_SPI_HANDLE_T pointer which contains a DRV_SPI_ATTRIBUTES_T structure. Those structure contains the configuration/initialization parameters of the device. While most attributes have valid default behavior, it is necessary to configure a bus speed and the DRV_SPI_DEVICE_ID_E
It is not possible to support all bus speeds by the driver. In future, there will be a matrix with configuration options and build options followed by possible speeds. At the moment we recommend to use DRV_SPI_Frequency_1_5625MHz as value for ulFrequency.
The SPIs initialize function forces the initialization of the SPI peripheral and the handle. The driver lock is set and the given parameters in the DRV_SPI_ATTRIBUTES_T structure are checked if there are parameter combinations not feasible. If everything is ok, the Buffers will be reset and the configuration registers are written, regarding the given attributes. At last the lock will be released.
[out] | ptDriver | The ptDriver to be |
Definition at line 167 of file netx_drv_spi.c.
|
private |
This function is the true interrupt service routine or interrupt handler of the SPI device interrupts. The interrupt handlers called by the controller should inline this handler and the constant eSPIDeviceID should define the specific device in compile time. For debug and development purposes a check of the pointers is performed in front that is not necessary for release. It is necessary because a debugger stopped controller does not perform a reset of the interrupt vector and so the ISR shall cope with the not initialized handle pointer.
After that the buffer flush is performed to transmit and receive data pending and then checks for the frame end are performed. If the frame has ended, the buffers and the FFS (if static) are reset.
[in,out] | eDeviceID | The given id of the drivers class |
Definition at line 1199 of file netx_drv_spi.c.
DRV_STATUS_E DRV_SPI_Receive | ( | DRV_SPI_HANDLE_T *const | ptDriver, |
uint8_t * | pcData, | ||
size_t | size | ||
) |
Function for receiveing data of given size by the SPI device.
The receive function takes besides the this handle a data pointer and a size to perform the receiving of the given data. It will check consistency of the handle, the lockage of the driver api and checks if the driver is busy. After everything is ready for transmission the software buffers are configured and the FSS static is set if it is software controlled and the device is master. At last, the flushing is performed regarding the chosen control flow method, the driver is unlocked and the function returns.
[in,out] | ptDriver | The given handle of the drivers class |
[out] | pcData | Pointer to the data to receive |
[in] | size | Amount of chars to receive |
Definition at line 840 of file netx_drv_spi.c.
DRV_STATUS_E DRV_SPI_Transmit | ( | DRV_SPI_HANDLE_T *const | ptDriver, |
uint8_t * | pcData, | ||
size_t | size | ||
) |
Function for transmitting data of given size via the SPI device.
The Transmit function takes besides the this handle a data pointer and a size to perform the transmission of the given data. It will check consistency of the handle, the locking of the driver api and checks if the driver is busy. After everything is ready for transmission the software buffers are set and the FSS static is set if it is software controlled and the device is master. At last, the flushing is performed regarding the chosen control flow method, the driver is unlocked and the function returns.
[in,out] | ptDriver | The given handle of the drivers class |
[in] | pcData | Pointer to the data to transmit |
[in] | size | Amount of chars to transmit |
Definition at line 723 of file netx_drv_spi.c.
DRV_STATUS_E DRV_SPI_TransmitReceive | ( | DRV_SPI_HANDLE_T *const | ptDriver, |
uint8_t * | pcTxData, | ||
uint8_t * | pcRxData, | ||
size_t | size | ||
) |
Function for transmitting and receiveing data at the same time of given size by the SPI device.
The receive and transmit function takes besides the this handle a data pointer and a size to perform the receiving and transmitting of the given data. It will check consistency of the handle, the lockage of the driver api and checks if the driver is busy. After everything is ready for transmission the software buffers are configured and the FSS static is set if it is software controlled and the device is master. At last, the flushing is performed regarding the chosen control flow method, the driver is unlocked and the function returns.
[in,out] | ptDriver | The given handle of the drivers class |
[out] | pcTxData | Pointer to the data to transmit |
[in] | pcRxData | Pointer to the data to receive |
[in] | size | Amount of chars to receive |
Definition at line 956 of file netx_drv_spi.c.
|
static |
Table of the device addresses.
Used to identify the device addresses by the device id.
Definition at line 69 of file netx_drv_spi.c.
|
static |
Table of the dma channels of the devices.
Definition at line 74 of file netx_drv_spi.c.
|
static |
Used for mapping the handle to an interrupt.
Threadsafe and reentrant because its is only written in normal context an used in interrupt context of the specific interrupt.
Definition at line 86 of file netx_drv_spi.c.
|
static |
Table of the IRQ vector numbers.
Used to identify the interrupt channels by the device id.
Definition at line 80 of file netx_drv_spi.c.