SPI_MASTER: Methods

SPI_MASTER

SPI_MASTER
Methods
DAVE_APP_VERSION_t SPI_MASTER_GetAppVersion (void)
 Get SPI_MASTER APP version. More...
 
SPI_MASTER_STATUS_t SPI_MASTER_Init (SPI_MASTER_t *const handle)
 Initialize the SPI channel as per the configuration made in GUI. More...
 
SPI_MASTER_STATUS_t SPI_MASTER_SetMode (SPI_MASTER_t *const handle, const XMC_SPI_CH_MODE_t mode)
 Set the communication mode along with required port configuration. More...
 
SPI_MASTER_STATUS_t SPI_MASTER_SetBaudRate (SPI_MASTER_t *const handle, const uint32_t baud_rate)
 Set the required baud rate during runtime. More...
 
SPI_MASTER_STATUS_t SPI_MASTER_Transmit (const SPI_MASTER_t *const handle, uint8_t *dataptr, uint32_t count)
 Transmits the specified number of data words and execute the callback defined in GUI, if enabled. More...
 
SPI_MASTER_STATUS_t SPI_MASTER_Receive (const SPI_MASTER_t *const handle, uint8_t *dataptr, uint32_t count)
 Receives the specified number of data words and execute the callback defined in GUI, if enabled. More...
 
SPI_MASTER_STATUS_t SPI_MASTER_Transfer (const SPI_MASTER_t *const handle, uint8_t *tx_dataptr, uint8_t *rx_dataptr, uint32_t count)
 Transmits and Receives the specified number of data words and execute the receive callback if it is enabled in GUI. More...
 
__STATIC_INLINE uint32_t SPI_MASTER_GetFlagStatus (const SPI_MASTER_t *handle, const uint32_t flag)
 Returns the state of the specified interrupt flag. More...
 
__STATIC_INLINE void SPI_MASTER_ClearFlag (const SPI_MASTER_t *handle, const uint32_t flag_mask)
 Clears the status of the specified interrupt flags. More...
 
__STATIC_INLINE bool SPI_MASTER_IsTxBusy (const SPI_MASTER_t *const handle)
 return the txbusy flag state More...
 
__STATIC_INLINE bool SPI_MASTER_IsRxBusy (const SPI_MASTER_t *const handle)
 return the rxbusy flag state More...
 
__STATIC_INLINE void SPI_MASTER_EnableSlaveSelectSignal (const SPI_MASTER_t *handle, const SPI_MASTER_SS_SIGNAL_t slave)
 Enables the specified slave select line. More...
 
__STATIC_INLINE void SPI_MASTER_DisableSlaveSelectSignal (const SPI_MASTER_t *handle)
 Disables the all the slave select lines. More...
 
__STATIC_INLINE uint16_t SPI_MASTER_GetReceivedWord (const SPI_MASTER_t *const handle)
 Provides data received in the receive buffer. More...
 
__STATIC_INLINE void SPI_MASTER_TransmitWord (const SPI_MASTER_t *const handle, const uint16_t data)
 Transmits a word of data. More...
 
__STATIC_INLINE void SPI_MASTER_EnableEvent (const SPI_MASTER_t *const handle, const uint32_t event_mask)
 Enables the selected protocol events for interrupt generation. More...
 
__STATIC_INLINE void SPI_MASTER_DisableEvent (const SPI_MASTER_t *const handle, const uint32_t event_mask)
 Disables selected events from generating interrupt. More...
 
__STATIC_INLINE void SPI_MASTER_SetTXFIFOTriggerLimit (const SPI_MASTER_t *const handle, const uint32_t limit)
 Configures trigger limit for the transmit FIFO. More...
 
__STATIC_INLINE void SPI_MASTER_SetRXFIFOTriggerLimit (const SPI_MASTER_t *const handle, const uint32_t limit)
 Configures trigger limit for the receive FIFO. More...
 
__STATIC_INLINE void SPI_MASTER_TXFIFO_EnableEvent (const SPI_MASTER_t *const handle, const uint32_t event)
 Enables the interrupt events related to transmit FIFO. More...
 
__STATIC_INLINE void SPI_MASTER_TXFIFO_DisableEvent (const SPI_MASTER_t *const handle, const uint32_t event)
 Disables the interrupt events related to transmit FIFO. More...
 
__STATIC_INLINE uint32_t SPI_MASTER_TXFIFO_GetEvent (const SPI_MASTER_t *const handle)
 Gets the transmit FIFO event status. More...
 
__STATIC_INLINE void SPI_MASTER_TXFIFO_ClearEvent (const SPI_MASTER_t *const handle, const uint32_t event)
 Clears the transmit FIFO event flags in the status register. More...
 
__STATIC_INLINE bool SPI_MASTER_IsTxFIFOFull (const SPI_MASTER_t *const handle)
 Checks if the transmit FIFO is full. More...
 
__STATIC_INLINE void SPI_MASTER_RXFIFO_EnableEvent (const SPI_MASTER_t *const handle, const uint32_t event)
 Enables the interrupt events related to transmit FIFO. More...
 
__STATIC_INLINE void SPI_MASTER_RXFIFO_DisableEvent (const SPI_MASTER_t *const handle, const uint32_t event)
 Disables the selected interrupt events related to receive FIFO. More...
 
__STATIC_INLINE uint32_t SPI_MASTER_RXFIFO_GetEvent (const SPI_MASTER_t *const handle)
 Get the receive FIFO events status. More...
 
__STATIC_INLINE void SPI_MASTER_RXFIFO_ClearEvent (const SPI_MASTER_t *const handle, const uint32_t event)
 Clears the receive FIFO event flags in the status register. More...
 
__STATIC_INLINE bool SPI_MASTER_IsRxFIFOEmpty (const SPI_MASTER_t *const handle)
 Checks if receive FIFO is empty. More...
 
SPI_MASTER_STATUS_t SPI_MASTER_AbortTransmit (const SPI_MASTER_t *const handle)
 Aborts the ongoing data transmission. More...
 
SPI_MASTER_STATUS_t SPI_MASTER_AbortReceive (const SPI_MASTER_t *const handle)
 Stops the active data reception request. More...
 

Detailed Description

Methods

Function Documentation

SPI_MASTER_STATUS_t SPI_MASTER_AbortReceive ( const SPI_MASTER_t *const  handle)

Stops the active data reception request.

Parameters
handlePointer to static and dynamic content of APP configuration.
Returns
None
Description:
If a reception is in progress, it will be stopped. When a reception request is active, user will not be able to place a new receive request till the active reception is complete. This API can stop the progressing reception to make a new receive request.

Example Usage:

#include <DAVE.h> //Declarations from DAVE Code Generation (includes SFR declaration)
//Description:
//Transmits the string "Infineon DAVE application" to the slave.
//Starts to receive data from slave, checks if the first byte is 0x55.
//If so, aborts the reception and retransmits 0x55 to slave.
int main(void)
{
DAVE_STATUS_t status;
uint8_t Send_Data[] = "Infineon DAVE application.";
uint8_t Rec_Data[64];
status = DAVE_Init(); // SPI_MASTER_Init() is called from DAVE_Init()
if(status == DAVE_STATUS_SUCCESS)
{
SPI_MASTER_Transmit(&SPI_MASTER_0, Send_Data, sizeof(Send_Data));
while(SPI_MASTER_0.runtime->tx_busy);
SPI_MASTER_Receive(&SPI_MASTER_0, Rec_Data, 15U);
if(SPI_MASTER_0.runtime->rx_data[0] == 0x55)
{
SPI_MASTER_AbortReceive(&SPI_MASTER_0);
SPI_MASTER_Transmit(&SPI_MASTER_0, Rec_Data, 1);
}
}
else
{
XMC_DEBUG("main: Application initialization failed");
while(1U)
{
}
}
return 1U;
}

Definition at line 813 of file SPI_MASTER.c.

References SPI_MASTER::channel, SPI_MASTER::config, SPI_MASTER_CONFIG::receive_mode, SPI_MASTER::runtime, SPI_MASTER_RUNTIME::rx_busy, SPI_MASTER_RUNTIME::rx_data, SPI_MASTER_CONFIG::rx_fifo_size, SPI_MASTER_AbortTransmit(), SPI_MASTER_STATUS_FAILURE, SPI_MASTER_STATUS_SUCCESS, SPI_MASTER_TRANSFER_MODE_DIRECT, SPI_MASTER_TRANSFER_MODE_DMA, and SPI_MASTER_RUNTIME::tx_data_dummy.

SPI_MASTER_STATUS_t SPI_MASTER_AbortTransmit ( const SPI_MASTER_t *const  handle)

Aborts the ongoing data transmission.

Parameters
handlePointer to static and dynamic content of APP configuration.
Returns
None
Description:
If there is a transmission in progress, it will be stopped. If transmit FIFO is used, the existing data will be flushed. After the transmission is stopped, user can start a new transmission without delay.

Example Usage:

#include <DAVE.h> //Declarations from DAVE Code Generation (includes SFR declaration)
//Description:
//Transmits test data from buffer Send_Data and aborts it immediately.
//Retransmits data from NewData.
int main(void)
{
DAVE_STATUS_t status;
uint8_t Send_Data[] = "Infineon DAVE application.";
uint8_t NewData[] = "New data message";
status = DAVE_Init(); // SPI_MASTER_Init() is called from DAVE_Init()
if(status == DAVE_STATUS_SUCCESS)
{
SPI_MASTER_Transmit(&SPI_MASTER_0, Send_Data, sizeof(Send_Data));
if(SPI_MASTER_0.runtime->tx_busy)
{
SPI_MASTER_AbortTransmit(&SPI_MASTER_0);
SPI_MASTER_Transmit(&SPI_MASTER_0, NewData, sizeof(NewData));
}
}
else
{
XMC_DEBUG("main: Application initialization failed");
while(1U)
{
}
}
return 1U;
}

Definition at line 871 of file SPI_MASTER.c.

References SPI_MASTER::channel, SPI_MASTER::config, SPI_MASTER::runtime, SPI_MASTER_STATUS_FAILURE, SPI_MASTER_STATUS_SUCCESS, SPI_MASTER_TRANSFER_MODE_DIRECT, SPI_MASTER_TRANSFER_MODE_DMA, SPI_MASTER_CONFIG::transmit_mode, SPI_MASTER_RUNTIME::tx_busy, SPI_MASTER_RUNTIME::tx_data, SPI_MASTER_RUNTIME::tx_data_dummy, and SPI_MASTER_CONFIG::tx_fifo_size.

Referenced by SPI_MASTER_AbortReceive().

__STATIC_INLINE void SPI_MASTER_ClearFlag ( const SPI_MASTER_t handle,
const uint32_t  flag_mask 
)

Clears the status of the specified interrupt flags.

Parameters
handlePointer to static and dynamic content of APP configuration.
flag_maskInterrupt for which status has to be cleared Use type XMC_SPI_CH_STATUS_FLAG_t for the bitmask of events.
Description:
During communication the events occurred has to be cleared to get the successive events.
e.g: During transmission Transmit buffer event occurs to indicating data word transfer has started. This event has to be cleared after transmission of each data word. Otherwise next event is not considered as valid.

Example Usage:

#include <DAVE.h>
//Description:
//It transmits "Infineon" to the SPI slave. After calling the transmit API, it will poll for the transmit shift
//indication flag to know the data has shifted out or not, and clears the flag.
int main(void)
{
DAVE_STATUS_t status;
uint8_t Send_Data[] = "Infineon";
status = DAVE_Init(); // SPI_MASTER_Init() is called from DAVE_Init()
if(status == DAVE_STATUS_SUCCESS)
{
SPI_MASTER_Transmit(&SPI_MASTER_0, Send_Data, sizeof(Send_Data));
while(SPI_MASTER_GetFlagStatus(&SPI_MASTER_0, (uint32_t)XMC_SPI_CH_STATUS_FLAG_TRANSMIT_SHIFT_INDICATION));
SPI_MASTER_ClearFlag(&SPI_MASTER_0, (uint32_t)XMC_SPI_CH_STATUS_FLAG_TRANSMIT_SHIFT_INDICATION);
}
else
{
XMC_DEBUG("main: Application initialization failed");
while(1U)
{
}
}
return 1U;
}


Definition at line 1124 of file SPI_MASTER.h.

References SPI_MASTER::channel.

__STATIC_INLINE void SPI_MASTER_DisableEvent ( const SPI_MASTER_t *const  handle,
const uint32_t  event_mask 
)

Disables selected events from generating interrupt.

Parameters
handlePointer to static and dynamic content of APP configuration.
eventProtocol events which have to be disabled. Refer @ XMC_SPI_CH_EVENT_t for valid values. OR combinations of these enum item can be used as input.
Description:
Disables the SPI protocol specific events, by configuring PCR register.

After disabling the events, SPI_MASTER_EnableEvent() has to be invoked to re-enable the events.

Definition at line 1423 of file SPI_MASTER.h.

References SPI_MASTER::channel.

__STATIC_INLINE void SPI_MASTER_DisableSlaveSelectSignal ( const SPI_MASTER_t handle)

Disables the all the slave select lines.

Parameters
handlePointer to static and dynamic content of APP configuration.
Description:
Disable all the slave signals by clearing PCR.SELO bits.

Example Usage:

#include <DAVE.h>
//Precondition:
//Configure to use two slaves".
//Description:
//Transmits 10 bytes of data to slave-0 and disables the slave-o. Then enable the slave-1 and transmits the data.
int main(void)
{
DAVE_STATUS_t status;
uint8_t Send_Data[] = "Infineon";
status = DAVE_Init(); // SPI_MASTER_Init() is called from DAVE_Init()
if(status == DAVE_STATUS_SUCCESS)
{
SPI_MASTER_Transmit(&SPI_MASTER_0, Send_Data, sizeof(Send_Data));
SPI_MASTER_Transmit(&SPI_MASTER_0, Send_Data, sizeof(Send_Data));
}
else
{
XMC_DEBUG("main: Application initialization failed");
while(1U)
{
}
}
return 1U;
}


Definition at line 1344 of file SPI_MASTER.h.

References SPI_MASTER::channel.

__STATIC_INLINE void SPI_MASTER_EnableEvent ( const SPI_MASTER_t *const  handle,
const uint32_t  event_mask 
)

Enables the selected protocol events for interrupt generation.

Parameters
handlePointer to static and dynamic content of APP configuration.
eventProtocol events which have to be enabled. Refer @ XMC_SPI_CH_EVENT_t for valid values. OR combinations of these enum items can be used as input.
Description:
Enables the events by configuring CCR or PCR register based on the event. When the event is enabled, an interrupt can be generated on occurrence of the event. The API can be used for protocol events(PCR_SSC events) only when the callback functions are not registered under 'Error and Protocol Handling' group.

Definition at line 1405 of file SPI_MASTER.h.

References SPI_MASTER::channel.

__STATIC_INLINE void SPI_MASTER_EnableSlaveSelectSignal ( const SPI_MASTER_t handle,
const SPI_MASTER_SS_SIGNAL_t  slave 
)

Enables the specified slave select line.

Parameters
handlePointer to static and dynamic content of APP configuration.
slavewhich slave signal has to be enabled
Description:
Each slave is connected with one slave select signal. At a time only one slave can be communicate. Enable the required slave to start the communication.

Example Usage: Generate code for multiple slave by configuring in "Advanced settings tab". Transmit the data to the required slave.

#include <DAVE.h>
//Precondition:
//Configure to use two slaves".
//Description:
//Transmits 10 bytes of data to slave-0 and disables the slave-o. Then enable the slave-1 and transmits the data.
int main(void)
{
DAVE_STATUS_t status;
uint8_t Send_Data[] = "Infineon";
status = DAVE_Init(); // SPI_MASTER_Init() is called from DAVE_Init()
if(status == DAVE_STATUS_SUCCESS)
{
SPI_MASTER_Transmit(&SPI_MASTER_0, Send_Data, sizeof(Send_Data));
SPI_MASTER_Transmit(&SPI_MASTER_0, Send_Data, sizeof(Send_Data));
}
else
{
XMC_DEBUG("main: Application initialization failed");
while(1U)
{
}
}
return 1U;
}


Definition at line 1285 of file SPI_MASTER.h.

References SPI_MASTER::channel, SPI_MASTER::config, SPI_MASTER_GPIO_CONFIG::slave_select_ch, SPI_MASTER_CONFIG::slave_select_pin_config, SPI_MASTER_SS_SIGNAL_0, SPI_MASTER_SS_SIGNAL_1, SPI_MASTER_SS_SIGNAL_2, SPI_MASTER_SS_SIGNAL_3, SPI_MASTER_SS_SIGNAL_4, SPI_MASTER_SS_SIGNAL_5, SPI_MASTER_SS_SIGNAL_6, and SPI_MASTER_SS_SIGNAL_7.

DAVE_APP_VERSION_t SPI_MASTER_GetAppVersion ( void  )

Get SPI_MASTER APP version.

Returns
DAVE_APP_VERSION_t APP version information (major, minor and patch number)
Description:
The function can be used to check application software compatibility with a specific version of the APP.

Example Usage:

#include <DAVE.h>
int main(void)
{
DAVE_STATUS_t status;
DAVE_APP_VERSION_t app_version;
status = DAVE_Init(); // SPI_MASTER_Init() is called from DAVE_Init()
app_version = SPI_MASTER_GetAppVersion();
if (app_version.major != 4U)
{
// Probably, not the right version.
}
while(1U)
{
}
return 1;
}


Definition at line 187 of file SPI_MASTER.c.

__STATIC_INLINE uint32_t SPI_MASTER_GetFlagStatus ( const SPI_MASTER_t handle,
const uint32_t  flag 
)

Returns the state of the specified interrupt flag.

Parameters
handlePointer to static and dynamic content of APP configuration.
flagInterrupt for which status is required Use type XMC_SPI_CH_STATUS_FLAG_t for the bitmask of events.
Returns
uint32_t status of the interrupt
Description:
Returns the status of the events, by reading PSR register. This indicates the status of the all the events, for SPI communication.

Example Usage:

#include <DAVE.h>
//Description:
//It transmits "Infineon" to the SPI slave. After calling the transmit API, it will poll for the transmit shift
//indication flag to know the data has shifted out or not.
int main(void)
{
DAVE_STATUS_t status;
uint8_t Send_Data[] = "Infineon";
status = DAVE_Init(); // SPI_MASTER_Init() is called from DAVE_Init()
if(status == DAVE_STATUS_SUCCESS)
{
SPI_MASTER_Transmit(&SPI_MASTER_0, Send_Data, sizeof(Send_Data));
while(SPI_MASTER_GetFlagStatus(&SPI_MASTER_0, XMC_SPI_CH_STATUS_FLAG_TRANSMIT_SHIFT_INDICATION));
}
else
{
XMC_DEBUG("main: Application initialization failed");
while(1U)
{
}
}
return 1U;
}


Definition at line 1074 of file SPI_MASTER.h.

References SPI_MASTER::channel.

__STATIC_INLINE uint16_t SPI_MASTER_GetReceivedWord ( const SPI_MASTER_t *const  handle)

Provides data received in the receive buffer.

Parameters
handlePointer to static and dynamic content of APP configuration.
Returns
uint16_t Data read from the receive buffer.
Description:
This can be used in receive mode "Direct" to read the received data. If receive FIFO is not configured, function reads the value of RBUF register. Otherwise the data is read from OUTR register. User can poll for receive event or configure an interrupt by connecting external INTERRUPT APP with receive event signals. This API can be used inside the ISR to read the received data.

Definition at line 1365 of file SPI_MASTER.h.

References SPI_MASTER::channel.

SPI_MASTER_STATUS_t SPI_MASTER_Init ( SPI_MASTER_t *const  handle)

Initialize the SPI channel as per the configuration made in GUI.

Parameters
handlePointer to static and dynamic content of APP configuration.
Returns
SPI_MASTER_STATUS_t: Status of SPI_MASTER driver initialization.
SPI_MASTER_STATUS_SUCCESS - on successful initialization.
SPI_MASTER_STATUS_FAILURE - if initialization fails.
Description:
Initializes IO pins used for the SPI_MASTER communication and configures USIC registers based on the settings provided in the GUI. Calculates divider values PDIV and STEP for a precise baudrate. It also enables configured interrupt flags and service request values.

Example Usage:

#include <DAVE.h> //Declarations from DAVE Code Generation (includes SFR declaration)
int main(void)
{
DAVE_STATUS_t status;
status = DAVE_Init(); // SPI_MASTER_Init() is called from DAVE_Init()
if(status == DAVE_STATUS_SUCCESS)
{
while(1U)
{
}
}
else
{
XMC_DEBUG("main: Application initialization failed");
while(1U)
{
}
}
return 1U;
}

Definition at line 201 of file SPI_MASTER.c.

References SPI_MASTER::config, and SPI_MASTER_CONFIG::fptr_spi_master_config.

__STATIC_INLINE bool SPI_MASTER_IsRxBusy ( const SPI_MASTER_t *const  handle)

return the rxbusy flag state

Parameters
handlePointer to static and dynamic content of APP configuration.
Returns
bool : status of rxbusy flag


Description:
This is used to check whether any receive process is going or not. If no process is going then only the new request is accepted. SPI_MASTER_AbortReceive() can be used to stop the current process and start the new request.

Example Usage:

#include <DAVE.h>
//Description:
//Receives 10 bytes of data from slave.
int main(void)
{
DAVE_STATUS_t status;
uint8_t ReadData[10];
status = DAVE_Init(); // SPI_MASTER_Init() is called from DAVE_Init()
if(status == DAVE_STATUS_SUCCESS)
{
if(SPI_MASTER_Receive(&SPI_MASTER_0, ReadData, 10U))
{
while(SPI_MASTER_IsRxBusy(&SPI_MASTER_0))
{
}
}
}
else
{
XMC_DEBUG("main: Application initialization failed");
while(1U)
{
}
}
return 1U;
}


Definition at line 1231 of file SPI_MASTER.h.

References SPI_MASTER::runtime, and SPI_MASTER_RUNTIME::rx_busy.

__STATIC_INLINE bool SPI_MASTER_IsRxFIFOEmpty ( const SPI_MASTER_t *const  handle)

Checks if receive FIFO is empty.

Parameters
handlePointer to static and dynamic content of APP configuration.
Returns
bool true if receive FIFO is empty, false if receive FIFO has some data.
Description
When the receive FIFO is empty, received data will be put in receive FIFO. When the last received word in the FIFO is read, FIFO empty flag is set. Any attempt to read from an empty receive FIFO will set the receive FIFO error flag.

Definition at line 1650 of file SPI_MASTER.h.

References SPI_MASTER::channel.

__STATIC_INLINE bool SPI_MASTER_IsTxBusy ( const SPI_MASTER_t *const  handle)

return the txbusy flag state

Parameters
handlePointer to static and dynamic content of APP configuration.
Returns
bool : status of txbusy flag


Description:
This is used to check whether any transmit process is going or not. If no process is going then only the new request is accepted. SPI_MASTER_AbortTransmit() can be used to stop the current process and start the new request.

Example Usage:

#include <DAVE.h>
//Description:
//Transmits "Infineon" to the slave device.
int main(void)
{
DAVE_STATUS_t status;
uint8_t Send_Data[] = "Infineon";
status = DAVE_Init(); // SPI_MASTER_Init() is called from DAVE_Init()
if(status == DAVE_STATUS_SUCCESS)
{
if(SPI_MASTER_Transmit(&SPI_MASTER_0, Send_Data, sizeof(Send_Data)) == SPI_MASTER_STATUS_SUCCESS)
{
while(SPI_MASTER_IsTxBusy(&SPI_MASTER_0))
{
}
}
}
else
{
XMC_DEBUG("main: Application initialization failed");
while(1U)
{
}
}
return 1U;
}


Definition at line 1179 of file SPI_MASTER.h.

References SPI_MASTER::runtime, and SPI_MASTER_RUNTIME::tx_busy.

__STATIC_INLINE bool SPI_MASTER_IsTxFIFOFull ( const SPI_MASTER_t *const  handle)

Checks if the transmit FIFO is full.

Parameters
handlePointer to static and dynamic content of APP configuration.
Returns
bool Status of transmit FIFO filling level.
true - if transmit FIFO is full.
false - if transmit FIFO is not full.
Description
Checks if transmit FIFO is full.

Checks the status using the register TRBSR. Can be used while filling data to the transmit FIFO.

Definition at line 1559 of file SPI_MASTER.h.

References SPI_MASTER::channel.

SPI_MASTER_STATUS_t SPI_MASTER_Receive ( const SPI_MASTER_t *const  handle,
uint8_t *  dataptr,
uint32_t  count 
)

Receives the specified number of data words and execute the callback defined in GUI, if enabled.

Parameters
handlePointer to static and dynamic content of APP configuration.
dataptrPointer to data in which value is written
countnumber of data words (word length configured) to be read
Returns
SPI_MASTER_STATUS_t SPI_MASTER_STATUS_SUCCESS : if read is successful
SPI_MASTER_STATUS_BUSY : if SPI channel is busy with other operation
Description:
Data will be received from the SPI slave synchronously. After the requested number of data bytes are received, optionally, the user configured callback function will be executed. Data reception is accomplished using the receive mode selected in the UI. Interrupt:
Based on the UI configuration, either standard receive buffer(RBUF) or receive FIFO(OUT) is used for data reception. An interrupt is configured for reading received data from the bus. This function only registers a request to receive a number of data bytes from a USIC channel. If FIFO is configured for reception, the FIFO limit is dynamically configured to optimally utilize the CPU load. Before starting data reception, the receive buffers are flushed. So only those data, received after calling the API, will be placed in the user buffer. When all the requested number of data bytes are received, the configured callback function will be executed. If a callback function is not configured, the user has to poll for the value of the variable, handle->runtime->rx_busy to be false. The value is updated to false when all the requested number of data bytes are received.
DMA:
DMA mode is available only in XMC4x family of microcontrollers. In this mode, a DMA channel is configured for receiving data from standard receive buffer(RBUF) to the user buffer. By calling this API, the DMA channel destination address is configured to the user buffer and the channel is enabled. Receive FIFO will not be used when the receive mode is DMA. Before starting data reception, the receive buffers are flushed. So only those data, received after calling the API, will be placed in the user buffer. When all the requested number of data bytes are received, the configured callback function will be executed. If a callback function is not configured, the user has to poll for the value of the variable, handle->runtime->rx_busy to be false. The value is updated to false when all the requested number of data bytes are received.
Direct
In Direct receive mode, neither interrupt nor DMA is used. The API polls the receive flag to read the received data and waits for all the requested number of bytes to be received. Based on FIFO configuration, either RBUF or OUT register is used for reading received data. Before starting data reception, the receive buffers are flushed. So only those data, received after calling the API, will be placed in the user buffer. Note: In Direct mode, the API blocks the CPU until the count of bytes requested is received.

Example Usage:

#include <DAVE.h>
//Description:
//Receives 10 bytes of data from slave.
int main(void)
{
DAVE_STATUS_t status;
uint8_t ReadData[10];
status = DAVE_Init(); // SPI_MASTER_Init() is called from DAVE_Init()
if(status == DAVE_STATUS_SUCCESS)
{
if(SPI_MASTER_Receive(&SPI_MASTER_0, ReadData, 10U))
{
while(SPI_MASTER_0.runtime->rx_busy)
{
}
}
}
else
{
XMC_DEBUG("main: Application initialization failed");
while(1U)
{
}
}
return 1U;
}


Definition at line 322 of file SPI_MASTER.c.

References SPI_MASTER::config, SPI_MASTER_CONFIG::receive_mode, SPI_MASTER_STATUS_FAILURE, SPI_MASTER_TRANSFER_MODE_DIRECT, SPI_MASTER_TRANSFER_MODE_DMA, and SPI_MASTER_TRANSFER_MODE_INTERRUPT.

__STATIC_INLINE void SPI_MASTER_RXFIFO_ClearEvent ( const SPI_MASTER_t *const  handle,
const uint32_t  event 
)

Clears the receive FIFO event flags in the status register.

Parameters
handlePointer to static and dynamic content of APP configuration.
eventReceive FIFO events to be cleared.
Range: XMC_USIC_CH_RXFIFO_EVENT_STANDARD, XMC_USIC_CH_RXFIFO_EVENT_ERROR, XMC_USIC_CH_RXFIFO_EVENT_ALTERNATE.
Description
USIC channel peripheral does not clear the event flags after they are read. This API clears the events provided in the mask value. XMC_USIC_CH_RXFIFO_EVENT enumeration can be used as input.

Definition at line 1632 of file SPI_MASTER.h.

References SPI_MASTER::channel.

__STATIC_INLINE void SPI_MASTER_RXFIFO_DisableEvent ( const SPI_MASTER_t *const  handle,
const uint32_t  event 
)

Disables the selected interrupt events related to receive FIFO.

Parameters
handlePointer to static and dynamic content of APP configuration.
eventEvents to be disabled.
Range: XMC_USIC_CH_RXFIFO_EVENT_CONF_STANDARD, XMC_USIC_CH_RXFIFO_EVENT_CONF_ERROR, XMC_USIC_CH_RXFIFO_EVENT_CONF_ALTERNATE.
Description
By disabling the interrupt events, generation of interrupt is stopped. User can poll the event flags from the status register using the API SPI_MASTER_RXFIFO_GetEvent().

Definition at line 1595 of file SPI_MASTER.h.

References SPI_MASTER::channel.

__STATIC_INLINE void SPI_MASTER_RXFIFO_EnableEvent ( const SPI_MASTER_t *const  handle,
const uint32_t  event 
)

Enables the interrupt events related to transmit FIFO.

Parameters
handlePointer to static and dynamic content of APP configuration.
eventEvents to be enabled. Multiple events can be bitwise OR combined.
Range: XMC_USIC_CH_RXFIFO_EVENT_CONF_STANDARD, XMC_USIC_CH_RXFIFO_EVENT_CONF_ERROR, XMC_USIC_CH_RXFIFO_EVENT_CONF_ALTERNATE.
Description
Multiple events can be enabled by providing multiple events in a single call. For providing multiple events, combine the events using bitwise OR operation.

Definition at line 1577 of file SPI_MASTER.h.

References SPI_MASTER::channel.

__STATIC_INLINE uint32_t SPI_MASTER_RXFIFO_GetEvent ( const SPI_MASTER_t *const  handle)

Get the receive FIFO events status.

Parameters
handlePointer to static and dynamic content of APP configuration.
Returns
uint32_t Status of receive FIFO events.
Description
Gives the status of receive FIFO standard receive buffer event, alternative receive buffer event and receive buffer error event. The status bits are located at their bit positions in the TRBSR register in the returned value. User can make use of the XMC_USIC_CH_RXFIFO_EVENT enumeration for checking the status of return value.

Definition at line 1613 of file SPI_MASTER.h.

References SPI_MASTER::channel.

SPI_MASTER_STATUS_t SPI_MASTER_SetBaudRate ( SPI_MASTER_t *const  handle,
const uint32_t  baud_rate 
)

Set the required baud rate during runtime.

Parameters
handlehandle Pointer to static and dynamic content of APP configuration.
baud_raterequired baud rate
Returns
SPI_MASTER_STATUS_t SPI_MASTER_STATUS_SUCCESS : if updation of baud rate is successful
SPI_MASTER_STATUS_FAILURE : if updation is failed
SPI_MASTER_STATUS_BUSY : if SPI channel is busy with other operation

Description:
While setting the baud rate to avoid noise of the port pins, all the pins are changed to input. After setting the required baud again ports are initialised with the configured settings.

Example Usage:

#include <DAVE.h>
//Description:
//The following code changes the SPI master baud rate to 9600 and starts sending the data stored in
//the buffer.
int main(void)
{
DAVE_STATUS_t status;
SPI_MASTER_STATUS_t spi_status;
uint8_t Send_Data[] = "Infineon DAVE application.";
uint32_t baud_rate;
status = DAVE_Init(); // SPI_MASTER_Init() is called from DAVE_Init()
if(status == DAVE_STATUS_SUCCESS)
{
baud_rate = 9600U;
spi_status = SPI_MASTER_SetBaudRate(&SPI_MASTER_0, baud_rate);
if(spi_status == SPI_MASTER_STATUS_SUCCESS)
{
SPI_MASTER_Transmit(&SPI_MASTER_0, Send_Data, sizeof(Send_Data));
}
}
else
{
XMC_DEBUG("main: Application initialization failed");
while(1U)
{
}
}
return 1U;
}


Definition at line 250 of file SPI_MASTER.c.

References SPI_MASTER::channel, SPI_MASTER::config, SPI_MASTER_CONFIG::leading_trailing_delay, SPI_MASTER::runtime, SPI_MASTER_RUNTIME::rx_busy, SPI_MASTER_CONFIG::shift_clk_passive_level, SPI_MASTER_STATUS_BUSY, SPI_MASTER_STATUS_SUCCESS, and SPI_MASTER_RUNTIME::tx_busy.

SPI_MASTER_STATUS_t SPI_MASTER_SetMode ( SPI_MASTER_t *const  handle,
const XMC_SPI_CH_MODE_t  mode 
)

Set the communication mode along with required port configuration.

Parameters
handlehandle Pointer to static and dynamic content of APP configuration.
modeSPI working mode
Returns
SPI_MASTER_STATUS_t SPI_MASTER_STATUS_SUCCESS : if updation of settings are successful
SPI_MASTER_STATUS_FAILURE : if mode is not supported by the selected pins
SPI_MASTER_STATUS_BUSY : if SPI channel is busy with transmit or receive operation

Description:
To change the mode of communication, it is advised to generate the code in Quad/Dual mode initially. Then changing the mode will be taken care by the APP.
  • If code is generated for Quad mode, it is possible to change to other modes like Dual, Half Duplex and Full Duplex
  • If code is generated for Dual mode, it is possible to change to other modes like Half Duplex and Full Duplex only
  • If code is generated for full-duplex mode, it is possible to change to Half Duplex only


Example Usage:

#include <DAVE.h>
//Precondition:
//Configure the SPI_MASTER APP operation mode as 'Quad SPI'.
//Description:
//The following code changes the SPI master device mode to Full duplex mode and starts sending the data stored in
//the buffer.
int main(void)
{
DAVE_STATUS_t status;
SPI_MASTER_STATUS_t spi_status;
uint8_t Send_Data[] = "Infineon DAVE application.";
status = DAVE_Init(); // SPI_MASTER_Init() is called from DAVE_Init()
if(status == DAVE_STATUS_SUCCESS)
{
spi_status = SPI_MASTER_SetMode(&SPI_MASTER_0, XMC_SPI_CH_MODE_STANDARD);
if(spi_status == SPI_MASTER_STATUS_SUCCESS)
{
SPI_MASTER_Transmit(&SPI_MASTER_0, Send_Data, sizeof(Send_Data));
}
}
else
{
XMC_DEBUG("main: Application initialization failed");
while(1U)
{
}
}
return 1U;
}


Definition at line 216 of file SPI_MASTER.c.

References SPI_MASTER::runtime, SPI_MASTER_RUNTIME::rx_busy, SPI_MASTER_RUNTIME::spi_master_mode, SPI_MASTER_STATUS_BUSY, SPI_MASTER_STATUS_SUCCESS, and SPI_MASTER_RUNTIME::tx_busy.

__STATIC_INLINE void SPI_MASTER_SetRXFIFOTriggerLimit ( const SPI_MASTER_t *const  handle,
const uint32_t  limit 
)

Configures trigger limit for the receive FIFO.

Parameters
handlePointer to static and dynamic content of APP configuration.
sizeValue of receive FIFO filling level, transition above which the interrupt should be generated.
: 0 to receive FIFO size.
e.g, If receive FIFO size is 16, and limit is configured as 8, FIFO receive buffer interrupt will be generated when the FIFO filling level rises from 8 to 9.
Description
Receive FIFO trigger limit is configured by setting its value in the RBCTR register. Receive FIFO is configured to generate interrupt when the FIFO filling level rises above the trigger limit.

Definition at line 1464 of file SPI_MASTER.h.

References SPI_MASTER::channel, SPI_MASTER::config, and SPI_MASTER_CONFIG::rx_fifo_size.

__STATIC_INLINE void SPI_MASTER_SetTXFIFOTriggerLimit ( const SPI_MASTER_t *const  handle,
const uint32_t  limit 
)

Configures trigger limit for the transmit FIFO.

Parameters
handlePointer to static and dynamic content of APP configuration.
limitValue of transmit FIFO filling level, transition below which the interrupt should be generated.
: 0 to transmit FIFO size.
e.g, If transmit FIFO size is 16, and limit is configured as 8, FIFO standard transmit buffer interrupt will be generated when the FIFO filling level drops from 8 to 7.
Description
Transmit FIFO trigger limit is configured by setting its value in the TBCTR register. Transmit FIFO is configured to generate interrupt when the FIFO filling level drops below the trigger limit.

Definition at line 1443 of file SPI_MASTER.h.

References SPI_MASTER::channel, SPI_MASTER::config, and SPI_MASTER_CONFIG::tx_fifo_size.

SPI_MASTER_STATUS_t SPI_MASTER_Transfer ( const SPI_MASTER_t *const  handle,
uint8_t *  tx_dataptr,
uint8_t *  rx_dataptr,
uint32_t  count 
)

Transmits and Receives the specified number of data words and execute the receive callback if it is enabled in GUI.

Parameters
handlePointer to static and dynamic content of APP configuration.
tx_dataptrPointer to data buffer which has to be send
rx_dataptrPointer to data buffer where the received data has to be stored.
countnumber of data words (word length configured) to be read and write
Returns
SPI_MASTER_STATUS_t SPI_MASTER_STATUS_SUCCESS : if transfer of data is successful
SPI_MASTER_STATUS_FAILURE : if transfer of data is failed (or) in other than standard full duplex mode SPI_MASTER_STATUS_BUFFER_INVALID : if passed buffers are NULL pointers (or) length of data transfer is zero.
Description:
Transmits and receives data simultaneously using the SPI channel as a master device. API is applicable only in Full duplex</> operation mode. Data transfer happens based on the individual modes configured for transmission and reception.
Two data pins MOSI and MISO will be used for receiving and transmitting data respectively. A callback function can be configured to execute after completing the transfer when 'Interrupt' or 'DMA' mode is used. The callback function should be configured for
End of receive/transfer callback in the 'Interrupt Settings' tab. The callback function will be executed when the last word of data is received.


Example Usage:

#include <DAVE.h>
//Precondition: Operation mode should be 'Full Duplex"
//Description:
//Transmits and Receives 10 bytes of data from slave in parallel.
int main(void)
{
DAVE_STATUS_t status;
uint8_t ReadData[10];
uint8_t SendData[10] = {0x1, 0x2, 0x3, 0x4, 0x5, 0x6, 0x7, 0x8, 0x9, 0xA};
status = DAVE_Init(); // SPI_MASTER_Init() is called from DAVE_Init()
if(status == DAVE_STATUS_SUCCESS)
{
SPI_MASTER_Transfer(&SPI_MASTER_0, SendData, ReadData, 10);
}
else
{
XMC_DEBUG("main: Application initialization failed");
while(1U)
{
}
}
return 1U;
}


Definition at line 747 of file SPI_MASTER.c.

References SPI_MASTER::config, SPI_MASTER_CONFIG::receive_mode, SPI_MASTER::runtime, SPI_MASTER_RUNTIME::rx_busy, SPI_MASTER_RUNTIME::rx_data, SPI_MASTER_RUNTIME::rx_data_dummy, SPI_MASTER_RUNTIME::spi_master_mode, SPI_MASTER_STATUS_BUFFER_INVALID, SPI_MASTER_STATUS_BUSY, SPI_MASTER_STATUS_FAILURE, SPI_MASTER_TRANSFER_MODE_DIRECT, SPI_MASTER_TRANSFER_MODE_DMA, SPI_MASTER_TRANSFER_MODE_INTERRUPT, SPI_MASTER_RUNTIME::tx_busy, SPI_MASTER_RUNTIME::tx_data, SPI_MASTER_RUNTIME::tx_data_count, and SPI_MASTER_RUNTIME::tx_data_dummy.

SPI_MASTER_STATUS_t SPI_MASTER_Transmit ( const SPI_MASTER_t *const  handle,
uint8_t *  dataptr,
uint32_t  count 
)

Transmits the specified number of data words and execute the callback defined in GUI, if enabled.

Parameters
handlePointer to static and dynamic content of APP configuration.
dataptrPointer to data
countnumber of data words (word length configured) to be transmitted
Returns
SPI_MASTER_STATUS_t SPI_MASTER_STATUS_SUCCESS : if transmit is successful
SPI_MASTER_STATUS_BUSY : if SPI channel is busy with other operation
Description:
Transmits data using the SPI channel as a master device. Transmission is accomplished using the transmit mode as configured in the UI.
Interrupt:
The data transmission is accomplished using transmit interrupt. User can configure a callback function in the APP UI. When the data is fully transmitted, the callback function will be executed. If transmit FIFO is enabled, the trigger limit is set to 1. So the transmit interrupt will be generated when all the data in FIFO is moved out of FIFO. The APP handle's runtime structure is used to store the data pointer, count, data index and status of transmission. This function only registers a data transmission request if there is no active transmission in progress. Actual data transmission happens in the transmit interrupt service routine. A trigger is generated for the transmit interrupt to start loading the data to the transmit buffer. If transmit FIFO is configured, the data is filled into the FIFO. Transmit interrupt will be generated subsequently when the transmit FIFO is empty. At this point of time, if there is some more data to be transmitted, it is loaded to the FIFO again. When FIFO is not enabled, data is transmitted one byte at a time. On transmission of each byte an interrupt is generated and the next byte is transmitted in the interrupt service routine. Callback function is executed when all the data bytes are transmitted. If a callback function is not configured, user has to poll for the value of tx_busy flag of the APP handle structure( handle->runtime->tx_busy ) to check for the completion of data transmission or use SPI_MASTER_IsTxBusy() API.
DMA:
DMA mode is available only in XMC4x family of microcontrollers. A DMA channel is configured to provide data to the SPI channel transmit buffer. This removes the load off the CPU. This API will only configure and enable the DMA channel by specifying the data buffer and count of bytes to transmit. Rest is taken care without the CPU's intervention. User can configure a callback function in the APP UI. When the transmission is complete, the callback function will be executed. FIFO will not be used in DMA mode. Receive start interrupt is configured for triggering the DMA channel. So each byte is transmitted in the background through the DMA channel. If the callback function is not configured, handle->runtime->tx_busy flag can be checked to verify if the transmission is complete. Direct:
Data will be transmitted using polling method. Status flags are used to check if data can be transmitted. Note: In Direct mode, the API blocks the CPU until the count of bytes requested is transmitted.

Example Usage:

#include <DAVE.h>
//Description:
//Transmits "Infineon" to the slave device.
int main(void)
{
DAVE_STATUS_t status;
uint8_t Send_Data[] = "Infineon";
status = DAVE_Init(); // SPI_MASTER_Init() is called from DAVE_Init()
if(status == DAVE_STATUS_SUCCESS)
{
if(SPI_MASTER_Transmit(&SPI_MASTER_0, Send_Data, sizeof(Send_Data)) == SPI_MASTER_STATUS_SUCCESS)
{
while(SPI_MASTER_0.runtime->tx_busy)
{
}
}
}
else
{
XMC_DEBUG("main: Application initialization failed");
while(1U)
{
}
}
return 1U;
}


Definition at line 292 of file SPI_MASTER.c.

References SPI_MASTER::config, SPI_MASTER_STATUS_FAILURE, SPI_MASTER_TRANSFER_MODE_DIRECT, SPI_MASTER_TRANSFER_MODE_DMA, SPI_MASTER_TRANSFER_MODE_INTERRUPT, and SPI_MASTER_CONFIG::transmit_mode.

__STATIC_INLINE void SPI_MASTER_TransmitWord ( const SPI_MASTER_t *const  handle,
const uint16_t  data 
)

Transmits a word of data.

Parameters
handlePointer to static and dynamic content of APP configuration.
dataData to be transmitted
Description:
Transmits a word of data through the SPI channel as a master device. If transmit FIFO is configured, the data is placed in the IN[0] register of the USIC channel. If transmit FIFO is not configured, API waits for the TBUF to be free and then places the data in the TBUF register. User can poll for receive event or configure interrupt by connecting an external INTERRUPT APP. This API can be used inside the ISR to read the received data.

Definition at line 1384 of file SPI_MASTER.h.

References SPI_MASTER::channel, SPI_MASTER::runtime, and SPI_MASTER_RUNTIME::spi_master_mode.

__STATIC_INLINE void SPI_MASTER_TXFIFO_ClearEvent ( const SPI_MASTER_t *const  handle,
const uint32_t  event 
)

Clears the transmit FIFO event flags in the status register.

Parameters
handlePointer to static and dynamic content of APP configuration.
eventTransmit FIFO events to be cleared.
Range: XMC_USIC_CH_TXFIFO_EVENT_STANDARD, XMC_USIC_CH_TXFIFO_EVENT_ERROR.
Returns
None
Description
USIC channel peripheral does not clear the event flags after they are read. This API clears the events provided in the mask value. XMC_USIC_CH_TXFIFO_EVENT enumeration can be used as input. Multiple events can be cleared by providing a mask value obtained by bitwise OR operation of multiple event enumerations.

Definition at line 1540 of file SPI_MASTER.h.

References SPI_MASTER::channel.

__STATIC_INLINE void SPI_MASTER_TXFIFO_DisableEvent ( const SPI_MASTER_t *const  handle,
const uint32_t  event 
)

Disables the interrupt events related to transmit FIFO.

Parameters
handlePointer to static and dynamic content of APP configuration.
eventEvents to be disabled.
Range: XMC_USIC_CH_TXFIFO_EVENT_CONF_STANDARD, XMC_USIC_CH_TXFIFO_EVENT_CONF_ERROR.
Description
By disabling the interrupt events, generation of interrupt is stopped. User can poll the event flags from the status register using the API SPI_MASTER_TXFIFO_GetEvent(). Event bitmasks can be constructed using the enumeration XMC_USIC_CH_TXFIFO_EVENT_CONF. For providing multiple events, combine the events using bitwise OR operation.

Definition at line 1500 of file SPI_MASTER.h.

References SPI_MASTER::channel.

__STATIC_INLINE void SPI_MASTER_TXFIFO_EnableEvent ( const SPI_MASTER_t *const  handle,
const uint32_t  event 
)

Enables the interrupt events related to transmit FIFO.

Parameters
handlePointer to static and dynamic content of APP configuration.
eventEvents to be enabled. Multiple events can be bitwise OR combined.
XMC_USIC_CH_TXFIFO_EVENT_CONF_STANDARD, XMC_USIC_CH_TXFIFO_EVENT_CONF_ERROR.
Description
Event bitmasks can be constructed using the enumeration XMC_USIC_CH_TXFIFO_EVENT_CONF.For providing multiple events, combine the events using bitwise OR operation. Events are configured in the TBCTR register.

Definition at line 1481 of file SPI_MASTER.h.

References SPI_MASTER::channel.

__STATIC_INLINE uint32_t SPI_MASTER_TXFIFO_GetEvent ( const SPI_MASTER_t *const  handle)

Gets the transmit FIFO event status.

Parameters
handlePointer to static and dynamic content of APP configuration.
Returns
Status of standard transmit and transmit buffer error events.
Range: XMC_USIC_CH_TXFIFO_EVENT_STANDARD, XMC_USIC_CH_TXFIFO_EVENT_ERROR.
Description
Gives the status of transmit FIFO standard transmit buffer event and transmit buffer error event. The status bits are located at their bit positions in the TRBSR register in the returned value. User can make use of the XMC_USIC_CH_TXFIFO_EVENT enumeration for checking the status of return value. The status can be found by using the bitwise AND operation on the returned value with the enumerated value.

Definition at line 1519 of file SPI_MASTER.h.

References SPI_MASTER::channel.