Middleware to implement a generic communications interface over SPI. This module implements the Communicatons Middleware Interface.
Overview
The RM_COMMS_SPI module implements COMMS API for SPI interface.
Features
The implementation of the SPI communications interface has the following key features:
- Read data from SPI bus
- Write data to SPI bus
- Simultaneously read from and write to SPI bus
- Support slave select and multiple slaves
Configuration
Build Time Configurations for rm_comms_spi
The following build time configurations are defined in fsp_cfg/rm_comms_spi_cfg.h:
Configuration | Options | Default | Description |
Parameter Checking |
-
Default (BSP)
-
Enabled
-
Disabled
| Default (BSP) | If selected code for parameter checking is included in the build. |
Auto Slave Select |
| Disabled | if selected slave select pin will be configured by module instance. |
Configurations for Connectivity > SPI Shared Bus (rm_comms_spi)
This module can be added to the Stacks tab via New Stack > Connectivity > SPI Shared Bus (rm_comms_spi).
Configuration | Options | Default | Description |
Name | Name must be a valid C symbol | g_comms_spi_bus0 | Module name. |
Bus Timeout | Value must be a non-negative integer less than or equal to 0xFFFFFFFF | 0xFFFFFFFF | Set timeout for locking bus in using RTOS. |
Semaphore for Blocking (RTOS only) |
| Use | Set Semaphore for blocking in using RTOS. |
Recursive Mutex for Bus (RTOS only) |
| Use | Set Mutex for locking bus in using RTOS. |
Configurations for Connectivity > SPI Communication Device (rm_comms_spi)
This module can be added to the Stacks tab via New Stack > Connectivity > SPI Communication Device (rm_comms_spi).
Configuration | Options | Default | Description |
Name | Name must be a valid C symbol | g_comms_spi_device0 | Module name. |
SSL Port Number | Refer to the RA Configuration tool for available options. | Disabled | GPIO output port number to select slave device. |
SSL Pin Number | Refer to the RA Configuration tool for available options. | Disabled | GPIO output pin number to select slave device. |
SSL Next Access Delay (Microseconds) | Value must be a non-negative integer | 1 | SSL next access delay. |
Slave Select Polarity |
| Active Low | Select the slave select active level. |
Semaphore Timeout (RTOS only) | Value must be a non-negative integer less than or equal to 0xFFFFFFFF | 0xFFFFFFFF | Set timeout for blocking in using RTOS. |
Callback | Name must be a valid C symbol | NULL | A user callback function can be provided. |
Pin Configuration
A GPIO can be configured for slave select.
Usage Notes
If an RTOS is used, blocking and bus lock is available via SPI shared bus. Bus lock is only available when blocking is used.
Limitations
Examples
Basic Example
This is a basic example of minimal use of SPI communications implementation in an application.
void rm_comms_spi_basic_example (void)
{
if (FSP_SUCCESS != err)
{
}
while (true)
{
g_error = 0;
g_completed = 0;
if (FSP_SUCCESS != err)
{
}
while ((0 == g_completed) && (0 == g_error))
{
}
g_error = 0;
g_completed = 0;
if (FSP_SUCCESS != err)
{
}
while ((0 == g_completed) && (0 == g_error))
{
}
}
}
{
if (p_args->event == RM_COMMS_EVENT_OPERATION_COMPLETE)
{
g_completed = 1;
}
else
{
g_error = 1;
}
}
◆ rm_comms_spi_instance_ctrl_t
struct rm_comms_spi_instance_ctrl_t |
Communications middleware control structure.
Data Fields |
uint32_t | open |
| Open flag.
|
|
rm_comms_cfg_t const * | p_cfg |
| Middleware configuration.
|
|
rm_comms_spi_bus_extended_cfg_t * | p_bus |
| Pointer to extended configuration structure.
|
|
rm_comms_spi_device_extended_cfg_t * | p_device |
| Pointer to device specific settings (lower level configuration structure)
|
|
void(* | p_callback )(rm_comms_callback_args_t *p_args) |
| Pointer to callback that is called when a spi_event_t occurs.
|
|
void const * | p_context |
| Pointer to context passed into callback function.
|
|
◆ RM_COMMS_SPI_Open()
Opens and configures the SPI Comms module. Implements rm_comms_api_t::open.
- Return values
-
FSP_SUCCESS | SPI Comms module successfully configured. |
FSP_ERR_ASSERTION | Null pointer, or one or more configuration options is invalid. |
FSP_ERR_ALREADY_OPEN | Module is already open. This module can only be opened once. |
- Returns
- See Common Error Codes or functions called by this function for other possible return codes.
◆ RM_COMMS_SPI_Close()
Disables specified SPI Comms module. Implements rm_comms_api_t::close.
- Return values
-
FSP_SUCCESS | Successfully closed. |
FSP_ERR_ASSERTION | Null pointer passed as a parameter. |
FSP_ERR_NOT_OPEN | Module is not open. |
- Returns
- See Common Error Codes or functions called by this function for other possible return codes.
◆ RM_COMMS_SPI_CallbackSet()
Updates the SPI Comms callback. Implements rm_comms_api_t::callbackSet.
- Return values
-
FSP_SUCCESS | Successfully set. |
FSP_ERR_ASSERTION | Null pointer passed as a parameter. |
FSP_ERR_NOT_OPEN | Module is not open. |
◆ RM_COMMS_SPI_Read()
Performs a read from the SPI bus. Implements rm_comms_api_t::read.
- Return values
-
FSP_SUCCESS | Successfully data decoded. |
FSP_ERR_ASSERTION | Null pointer passed as a parameter. |
FSP_ERR_NOT_OPEN | Module is not open. |
- Returns
- See Common Error Codes or functions called by this function for other possible return codes.
◆ RM_COMMS_SPI_Write()
Performs a write to the SPI bus. Implements rm_comms_api_t::write.
- Return values
-
FSP_SUCCESS | Successfully writing data . |
FSP_ERR_ASSERTION | Null pointer passed as a parameter. |
FSP_ERR_NOT_OPEN | Module is not open. |
- Returns
- See Common Error Codes or functions called by this function for other possible return codes.
◆ RM_COMMS_SPI_WriteRead()
Performs simultaneous read and write. Implements rm_comms_api_t::writeRead..
- Return values
-
FSP_SUCCESS | Transfer was started successfully. |
FSP_ERR_ASSERTION | Null pointer passed as a parameter. |
FSP_ERR_NOT_OPEN | Module is not open. |
FSP_ERR_INVALID_ARGUMENT | Read bytes and write bytes are not the same. |
- Returns
- See Common Error Codes or functions called by this function for other possible return codes.