Synergy Software Package User's Manual

RTOS-integrated SPI Framework. More...

Data Structures

struct  sf_spi_instance_ctrl_t
 

Functions

ssp_err_t SF_SPI_Open (sf_spi_ctrl_t *const p_api_ctrl, sf_spi_cfg_t const *const p_cfg)
 Initialize a SPI bus and open low level SPI driver. More...
 
ssp_err_t SF_SPI_Read (sf_spi_ctrl_t *const p_api_ctrl, void *const p_dest, uint32_t const length, spi_bit_width_t const bit_width, uint32_t const timeout)
 Starts the transfer process and receives data from SPI device. More...
 
ssp_err_t SF_SPI_Write (sf_spi_ctrl_t *const p_api_ctrl, void *const p_src, uint32_t const length, spi_bit_width_t const bit_width, uint32_t const timeout)
 Starts the transfer process and writes data to SPI device. More...
 
ssp_err_t SF_SPI_WriteRead (sf_spi_ctrl_t *const p_api_ctrl, void *const p_src, void *const p_dest, uint32_t const length, spi_bit_width_t const bit_width, uint32_t const timeout)
 Simultaneously transmit data to SPI device while receiving data from SPI device(full duplex). More...
 
ssp_err_t SF_SPI_Close (sf_spi_ctrl_t *const p_api_ctrl)
 Disable the SPI device designated by the control handle and close the RTOS services used by the bus if no devices are connected to the bus. More...
 
ssp_err_t SF_SPI_Lock (sf_spi_ctrl_t *const p_api_ctrl)
 Lock the bus for a device. More...
 
ssp_err_t SF_SPI_Unlock (sf_spi_ctrl_t *const p_api_ctrl)
 Unlock the bus for a particular device and make the bus usable for other devices. More...
 
ssp_err_t SF_SPI_VersionGet (ssp_version_t *const p_version)
 Get the version information of the framework. More...
 
ssp_err_t SF_SPI_LockWait (sf_spi_ctrl_t *const p_api_ctrl, uint32_t const timeout)
 Lock the SPI bus resource. Once bus is locked by a device it can not be used by other devices. More...
 

Detailed Description

RTOS-integrated SPI Framework.

Function Documentation

◆ SF_SPI_Close()

ssp_err_t SF_SPI_Close ( sf_spi_ctrl_t *const  p_api_ctrl)

Disable the SPI device designated by the control handle and close the RTOS services used by the bus if no devices are connected to the bus.

Return values
SSP_SUCCESSSPI channel is successfully closed.
SSP_ERR_ASSERTIONp_api_ctrl is NULL.
SSP_ERR_NOT_OPENDevice not opened.
Returns
See Common Error Codes and lower level driver function for other possible return codes. This driver function is:
Note
This function is reentrant for any device.

Check whether device is open.

Acquire the device count mutex before accessing the shared resource in close.

Check the count of opened devices on the bus. If there are no devices opened or all other devices on the bus are closed then close the low level SPI driver and release the RTOS services used by the bus.

Get the low level control in use.

Close low level driver.

Delete RTOS services used by the bus.

Decrement device count.

Delete the device count mutex

Decrement device count.

Release the device count mutex

Set device to closed state

◆ SF_SPI_Lock()

ssp_err_t SF_SPI_Lock ( sf_spi_ctrl_t *const  p_api_ctrl)

Lock the bus for a device.

Return values
SSP_SUCCESSSPI bus is successfully locked.
SSP_ERR_ASSERTIONp_api_ctrl is NULL.
SSP_ERR_NOT_OPENDevice not opened.
SSP_ERR_IN_USEIn-use error.
Note
This function is reentrant for any device.

Check whether device is open.

Get the mutex for this device.

Start transfer process - check lock, check reconfiguration, check bus compatibility, enable chip select.

Release the mutex

Set lock flag.

◆ SF_SPI_LockWait()

ssp_err_t SF_SPI_LockWait ( sf_spi_ctrl_t *const  p_api_ctrl,
uint32_t const  timeout 
)

Lock the SPI bus resource. Once bus is locked by a device it can not be used by other devices.

Return values
SSP_SUCCESSSPI channel is successfully locked within the specified timeout.
SSP_ERR_ASSERTIONPointer to SPI control block is NULL.
SSP_ERR_NOT_OPENDevice not opened.
SSP_ERR_TIMEOUTMutex not available in timeout.
Note
This function is reentrant for any device.

Check whether device is open.

Get the mutex for this device.

Set lock flag.

Enable slave.

◆ SF_SPI_Open()

ssp_err_t SF_SPI_Open ( sf_spi_ctrl_t *const  p_api_ctrl,
sf_spi_cfg_t const *const  p_cfg 
)

Initialize a SPI bus and open low level SPI driver.

Return values
SSP_SUCCESSSPI channel is successfully opened.
SSP_ERR_ASSERTIONOne of the following parameters is NULL: p_api_ctrl, p_cfg, Pointer to Open, Close, Read, Write, or Writeread API interfaces, p_cfg->p_bus or p_cfg->p_lower_lvl_cfg.
SSP_ERR_INTERNALInternal error occurred.
SSP_ERR_ALREADY_OPENSame SPI framework device is already open.
Returns
See Common Error Codes and lower level driver function for other possible return codes. This driver function is
Note
This function is reentrant for any channel.
Control block must be cleared by caller before calling this function.

Check whether device is already opened or not.

Copy bus to control

Copy chip_select to control

Copy chip_select level to control

Initialize bus lock to false

Set framework level callback function.

Save context for use in ISRs.

Use bus channel in device open.

Enter a critical section before checking the device count mutex status.

Check if device count mutex is already created. If not then create the mutex.

Create device_count_mutex. This is used to protect shared variable device_count in bus control structure.

If mutex create fails, return error.

Exit critical section

Acquire the device count mutex before accessing the shared resource. Try again if the mutex was deleted in close.

Increment device count.

Save device configuration for reconfiguration.

Set device state as Opened.

Initialize chip select.

◆ SF_SPI_Read()

ssp_err_t SF_SPI_Read ( sf_spi_ctrl_t *const  p_api_ctrl,
void *const  p_dest,
uint32_t const  length,
spi_bit_width_t const  bit_width,
uint32_t const  timeout 
)

Starts the transfer process and receives data from SPI device.

Return values
SSP_SUCCESSData read completed successfully.
SSP_ERR_ASSERTIONOne of the following parameters is NULL: p_api_ctrl, p_dest, length.
SSP_ERR_NOT_OPENDevice not opened.
Returns
See Common Error Codes and lower level driver function for other possible return codes. This driver function is:

Check whether device is open.

Get mutex for this bus.

Start transfer process - check lock, check reconfiguration, check bus compatibility, enable chip select.

Release the mutex

Perform read.

Finish transfer.

◆ SF_SPI_Unlock()

ssp_err_t SF_SPI_Unlock ( sf_spi_ctrl_t *const  p_api_ctrl)

Unlock the bus for a particular device and make the bus usable for other devices.

Return values
SSP_SUCCESSSPI bus is successfully unlocked.
SSP_ERR_ASSERTIONp_api_ctrl is NULL.
SSP_ERR_NOT_OPENDevice not opened.
SSP_ERR_IN_USEIn-use error.
Note
This function is reentrant for any device.

Check whether device is open.

Acquire the mutex.

Clear lock flag.

Disable slave.

Release the mutex so that others can use the bus.

◆ SF_SPI_VersionGet()

ssp_err_t SF_SPI_VersionGet ( ssp_version_t *const  p_version)

Get the version information of the framework.

Return values
SSP_ERR_ASSERTIONp_version is NULL.
SSP_SUCCESSSuccessful return.

Checks error. Further parameter checking can be done at the driver layer.

◆ SF_SPI_Write()

ssp_err_t SF_SPI_Write ( sf_spi_ctrl_t *const  p_api_ctrl,
void *const  p_src,
uint32_t const  length,
spi_bit_width_t const  bit_width,
uint32_t const  timeout 
)

Starts the transfer process and writes data to SPI device.

Return values
SSP_SUCCESSData write completed successfully.
SSP_ERR_ASSERTIONOne of the following parameters may be NULL: p_api_ctrl, p_src, length.
SSP_ERR_NOT_OPENDevice not opened.
Returns
See Common Error Codes and lower level driver function for other possible return codes. This driver function is:

Check whether device is open.

Get mutex for this bus.

Start transfer process - check lock, check reconfiguration, check bus compatibility, enable chip select.

Release the mutex

Perform write.

Finish transfer.

◆ SF_SPI_WriteRead()

ssp_err_t SF_SPI_WriteRead ( sf_spi_ctrl_t *const  p_api_ctrl,
void *const  p_src,
void *const  p_dest,
uint32_t const  length,
spi_bit_width_t const  bit_width,
uint32_t const  timeout 
)

Simultaneously transmit data to SPI device while receiving data from SPI device(full duplex).

Return values
SSP_SUCCESSData write completed successfully.
SSP_ERR_ASSERTIONOne of the following parameters may be NULL: p_api_ctrl, p_src, p_dest, length.
SSP_ERR_NOT_OPENDevice not opened.
Returns
See Common Error Codes and lower level driver function for other possible return codes. This driver function is:

Check whether device is open.

Get mutex for this bus.

Start transfer process - check lock, check reconfiguration, check bus compatibility, enable chip select.

Release the mutex

Perform write read.

Finish transfer.