VSF Documented
Data Structures | Macros | Typedefs | Enumerations | Functions
vsf_template_spi.h File Reference
#include "./vsf_template_hal_driver.h"
#include "hal/arch/vsf_arch.h"

Go to the source code of this file.

Data Structures

struct  vsf_spi_status_t
 Predefined VSF SPI status that can be reimplemented in specific HAL drivers. Even if the hardware doesn't support these features, these status must be kept. More...
 
struct  vsf_spi_capability_t
 Predefined VSF SPI capability that can be reimplemented in specific HAL drivers. Even if the hardware doesn't support these features, these capabilities must be kept. More...
 
struct  vsf_spi_isr_t
 SPI interrupt service routine configuration structure. More...
 
struct  vsf_spi_cfg_t
 Configuration structure for SPI. More...
 
struct  vsf_spi_op_t
 SPI operation function pointer type, used for SPI Multi Class support. More...
 
struct  vsf_spi_t
 SPI instance structure, used for SPI Multi Class support, not needed in non Multi Class mode. More...
 

Macros

#define VSF_SPI_CFG_MULTI_CLASS   ENABLED
 Enable multi-class support by default for maximum availability.
 
#define VSF_SPI_CFG_PREFIX   vsf
 Define SPI hardware mask if count is defined.
 
#define VSF_SPI_CFG_FUNCTION_RENAME   ENABLED
 Disable VSF_SPI_CFG_FUNCTION_RENAME to use the original function names (e.g., vsf_spi_init()).
 
#define VSF_SPI_CFG_REIMPLEMENT_TYPE_MODE   DISABLED
 Enable macro VSF_SPI_CFG_REIMPLEMENT_TYPE_MODE in specific hardware drivers to redefine enum vsf_spi_mode_t.
 
#define VSF_SPI_CFG_REIMPLEMENT_TYPE_IRQ_MASK   DISABLED
 In specific hardware driver, enable macro VSF_SPI_CFG_REIMPLEMENT_TYPE_IRQ_MASK to redefine enum vsf_spi_irq_mask_t.
 
#define VSF_SPI_CFG_REIMPLEMENT_TYPE_STATUS   DISABLED
 In specific hardware driver, enable macro VSF_SPI_CFG_REIMPLEMENT_TYPE_STATUS to redefine struct vsf_spi_status_t.
 
#define VSF_SPI_CFG_REIMPLEMENT_TYPE_CFG   DISABLED
 In specific hardware driver, enable macro VSF_SPI_CFG_REIMPLEMENT_TYPE_CFG to redefine struct vsf_spi_cfg_t. For compatibility, members should not be deleted when redefining vsf_spi_cfg_t. The type vsf_spi_isr_handler_t also needs to be redefined.
 
#define VSF_SPI_CFG_REIMPLEMENT_TYPE_CTRL   DISABLED
 In specific hardware driver, enable macro VSF_SPI_CFG_REIMPLEMENT_TYPE_CTRL to redefine enum vsf_spi_ctrl_t.
 
#define VSF_SPI_CFG_REIMPLEMENT_TYPE_CAPABILITY   DISABLED
 In specific hardware driver, enable macro VSF_SPI_CFG_REIMPLEMENT_TYPE_CAPABILITY to redefine struct vsf_spi_capability_t. For compatibility, members should not be deleted.
 
#define VSF_SPI_CFG_REIMPLEMENT_MODE_TO_DATA_BITS   DISABLED
 In specific hardware driver, enable macro VSF_SPI_CFG_REIMPLEMENT_MODE_TO_DATA_BITS to reimplement the function vsf_spi_mode_to_data_bits().
 
#define VSF_SPI_CFG_REIMPLEMENT_DATA_BITS_TO_MODE   DISABLED
 In specific hardware driver, enable macro VSF_SPI_CFG_REIMPLEMENT_DATA_BITS_TO_MODE to reimplement the function vsf_spi_data_bits_to_mode().
 
#define VSF_SPI_CFG_REIMPLEMENT_MODE_TO_BYTES   DISABLED
 In specific hardware driver, enable macro VSF_SPI_CFG_REIMPLEMENT_MODE_TO_BYTES to reimplement the function vsf_spi_mode_to_data_bytes().
 
#define VSF_SPI_CFG_INHERIT_HAL_CAPABILITY   ENABLED
 In specific hardware driver, enable macro VSF_SPI_CFG_INHERIT_HAL_CAPABILITY to inherit the structure vsf_peripheral_capability_t.
 
#define VSF_SPI_APIS(__prefix)
 SPI API template, used to generate SPI type, specific prefix function declarations, etc.
 

Typedefs

typedef enum vsf_spi_mode_t vsf_spi_mode_t
 Predefined VSF SPI modes that can be reimplemented in specific HAL drivers.If we want to add optional modes in the specific driver, we need to provide one or more enum options, and a macro with the same name to determine if they are supported at runtime. If the feature supports more than one option, it also needs to provide the corresponding MASK option, so that the user can switch to different modes at compile-time.
 
typedef enum vsf_spi_irq_mask_t vsf_spi_irq_mask_t
 Predefined VSF SPI interrupt masks that can be reimplemented in specific HAL drivers. Optional interrupts need to provide one or more enum options and a macro with the same name to determine if they are supported at runtime. If multiple options are supported, a corresponding MASK option should be provided to allow switching between modes at runtime.
 
typedef struct vsf_spi_status_t vsf_spi_status_t
 Predefined VSF SPI status that can be reimplemented in specific HAL drivers. Even if the hardware doesn't support these features, these status must be kept.
 
typedef struct vsf_spi_capability_t vsf_spi_capability_t
 Predefined VSF SPI capability that can be reimplemented in specific HAL drivers. Even if the hardware doesn't support these features, these capabilities must be kept.
 
typedef struct vsf_spi_t vsf_spi_t
 SPI forward declaration.
 
typedef void vsf_spi_isr_handler_t(void *target_ptr, vsf_spi_t *spi_ptr, vsf_spi_irq_mask_t irq_mask)
 SPI interrupt handler type declaration.
 
typedef struct vsf_spi_isr_t vsf_spi_isr_t
 SPI interrupt service routine configuration structure.
 
typedef struct vsf_spi_cfg_t vsf_spi_cfg_t
 Configuration structure for SPI.
 
typedef enum vsf_spi_ctrl_t vsf_spi_ctrl_t
 Predefined VSF SPI control commands that can be reimplemented in specific HAL drivers.Optional control commands require one or more enumeration options and a macro with the same name to determine if they are supported at runtime. If the feature supports more than one option, it is recommended to provide the corresponding MASK option, so that the user can check for supported features at compile-time.
 
typedef struct vsf_spi_op_t vsf_spi_op_t
 SPI operation function pointer type, used for SPI Multi Class support.
 

Enumerations

enum  vsf_spi_mode_t {
  VSF_SPI_MASTER = 0x00ul << 0 ,
  VSF_SPI_SLAVE = 0x01ul << 0 ,
  VSF_SPI_MSB_FIRST = 0x00ul << 1 ,
  VSF_SPI_LSB_FIRST = 0x01ul << 1 ,
  VSF_SPI_CPOL_LOW = 0x00ul << 2 ,
  VSF_SPI_CPOL_HIGH = 0x01ul << 2 ,
  VSF_SPI_CPHA_LOW = 0x00ul << 2 ,
  VSF_SPI_CPHA_HIGH = 0x01ul << 2 ,
  VSF_SPI_MODE_0 = VSF_SPI_CPOL_LOW | VSF_SPI_CPHA_LOW ,
  VSF_SPI_MODE_1 = VSF_SPI_CPOL_LOW | VSF_SPI_CPHA_HIGH ,
  VSF_SPI_MODE_2 = VSF_SPI_CPOL_HIGH | VSF_SPI_CPHA_LOW ,
  VSF_SPI_MODE_3 = VSF_SPI_CPOL_HIGH | VSF_SPI_CPHA_HIGH ,
  VSF_SPI_CS_SOFTWARE_MODE = 0x00ul << 4 ,
  VSF_SPI_CS_HARDWARE_MODE = 0x01ul << 4 ,
  VSF_SPI_DATASIZE_8 = 0x00ul << 8 ,
  VSF_SPI_DATASIZE_16 = 0x01ul << 8 ,
  VSF_SPI_DATASIZE_32 = 0x02ul << 8
}
 Predefined VSF SPI modes that can be reimplemented in specific HAL drivers.If we want to add optional modes in the specific driver, we need to provide one or more enum options, and a macro with the same name to determine if they are supported at runtime. If the feature supports more than one option, it also needs to provide the corresponding MASK option, so that the user can switch to different modes at compile-time. More...
 
enum  {
  VSF_SPI_DIR_MODE_MASK ,
  VSF_SPI_BIT_ORDER_MASK ,
  VSF_SPI_MODE_MASK ,
  VSF_SPI_CS_MODE_MASK ,
  VSF_SPI_DATASIZE_MASK ,
  VSF_SPI_MODE_ALL_BITS_MASK
}
 SPI mode completion, used to simplify the definition of SPI mode. More...
 
enum  vsf_spi_irq_mask_t {
  VSF_SPI_IRQ_MASK_TX = 0x01ul << 0 ,
  VSF_SPI_IRQ_MASK_RX = 0x01ul << 1 ,
  VSF_SPI_IRQ_MASK_TX_CPL = 0x01ul << 2 ,
  VSF_SPI_IRQ_MASK_CPL = 0x01ul << 3 ,
  VSF_SPI_IRQ_MASK_OVERFLOW_ERR = 0x01ul << 4
}
 Predefined VSF SPI interrupt masks that can be reimplemented in specific HAL drivers. Optional interrupts need to provide one or more enum options and a macro with the same name to determine if they are supported at runtime. If multiple options are supported, a corresponding MASK option should be provided to allow switching between modes at runtime. More...
 
enum  {
  VSF_SPI_IRQ_MASK_TX_FIFO_THRESHOLD = VSF_SPI_IRQ_MASK_TX ,
  VSF_SPI_IRQ_MASK_RX_FIFO_THRESHOLD = VSF_SPI_IRQ_MASK_RX ,
  VSF_SPI_IRQ_MASK_RX_CPL = VSF_SPI_IRQ_MASK_CPL ,
  VSF_SPI_IRQ_MASK_ERR = VSF_SPI_IRQ_MASK_OVERFLOW_ERR ,
  VSF_SPI_IRQ_ALL_BITS_MASK
}
 SPI IRQ mask completion, used to simplify the definition of SPI IRQ mask. More...
 
enum  vsf_spi_ctrl_t { __VSF_SPI_CTRL_DUMMY = 0 }
 Predefined VSF SPI control commands that can be reimplemented in specific HAL drivers.Optional control commands require one or more enumeration options and a macro with the same name to determine if they are supported at runtime. If the feature supports more than one option, it is recommended to provide the corresponding MASK option, so that the user can check for supported features at compile-time. More...
 

Functions

vsf_err_t vsf_spi_init (vsf_spi_t *spi_ptr, vsf_spi_cfg_t *cfg_ptr)
 Initialize a SPI instance.
 
void vsf_spi_fini (vsf_spi_t *spi_ptr)
 Finalize (deinitialize) a SPI instance.
 
fsm_rt_t vsf_spi_enable (vsf_spi_t *spi_ptr)
 Enable a SPI instance for operation.
 
fsm_rt_t vsf_spi_disable (vsf_spi_t *spi_ptr)
 Disable a SPI instance from operation.
 
void vsf_spi_irq_enable (vsf_spi_t *spi_ptr, vsf_spi_irq_mask_t irq_mask)
 Enable specific interrupts for a SPI instance.
 
void vsf_spi_irq_disable (vsf_spi_t *spi_ptr, vsf_spi_irq_mask_t irq_mask)
 Disable specific interrupts for a SPI instance.
 
vsf_err_t vsf_spi_cs_active (vsf_spi_t *spi_ptr, uint_fast8_t index)
 Activate (assert) a SPI chip select line.
 
vsf_err_t vsf_spi_cs_inactive (vsf_spi_t *spi_ptr, uint_fast8_t index)
 Deactivate (deassert) a SPI chip select line.
 
vsf_spi_status_t vsf_spi_status (vsf_spi_t *spi_ptr)
 Get the current status of a SPI instance.
 
vsf_spi_capability_t vsf_spi_capability (vsf_spi_t *spi_ptr)
 Get the capabilities of a SPI instance.
 
void vsf_spi_fifo_transfer (vsf_spi_t *spi_ptr, void *out_buffer_ptr, uint_fast32_t *out_offset_ptr, void *in_buffer_ptr, uint_fast32_t *in_offset_ptr, uint_fast32_t count)
 Perform FIFO-based data transfer on a SPI instance.
 
vsf_err_t vsf_spi_request_transfer (vsf_spi_t *spi_ptr, void *out_buffer_ptr, void *in_buffer_ptr, uint_fast32_t count)
 Request a SPI data transfer operation.
 
vsf_err_t vsf_spi_cancel_transfer (vsf_spi_t *spi_ptr)
 Cancel an ongoing SPI transfer operation.
 
void vsf_spi_get_transferred_count (vsf_spi_t *spi_ptr, uint_fast32_t *sent_count, uint_fast32_t *received_count)
 Get the number of data units transferred in the current or last SPI operation.
 
vsf_err_t vsf_spi_ctrl (vsf_spi_t *spi_ptr, vsf_spi_ctrl_t ctrl, void *param)
 Execute a control command on the SPI instance.
 

Macro Definition Documentation

◆ VSF_SPI_CFG_MULTI_CLASS

#define VSF_SPI_CFG_MULTI_CLASS   ENABLED

Enable multi-class support by default for maximum availability.

◆ VSF_SPI_CFG_PREFIX

#define VSF_SPI_CFG_PREFIX   vsf

Define SPI hardware mask if count is defined.

Define SPI hardware count if mask is defined

We can redefine macro VSF_SPI_CFG_PREFIX to specify a prefix to call a specific driver directly in the application code.

◆ VSF_SPI_CFG_FUNCTION_RENAME

#define VSF_SPI_CFG_FUNCTION_RENAME   ENABLED

Disable VSF_SPI_CFG_FUNCTION_RENAME to use the original function names (e.g., vsf_spi_init()).

◆ VSF_SPI_CFG_REIMPLEMENT_TYPE_MODE

#define VSF_SPI_CFG_REIMPLEMENT_TYPE_MODE   DISABLED

Enable macro VSF_SPI_CFG_REIMPLEMENT_TYPE_MODE in specific hardware drivers to redefine enum vsf_spi_mode_t.

◆ VSF_SPI_CFG_REIMPLEMENT_TYPE_IRQ_MASK

#define VSF_SPI_CFG_REIMPLEMENT_TYPE_IRQ_MASK   DISABLED

In specific hardware driver, enable macro VSF_SPI_CFG_REIMPLEMENT_TYPE_IRQ_MASK to redefine enum vsf_spi_irq_mask_t.

◆ VSF_SPI_CFG_REIMPLEMENT_TYPE_STATUS

#define VSF_SPI_CFG_REIMPLEMENT_TYPE_STATUS   DISABLED

In specific hardware driver, enable macro VSF_SPI_CFG_REIMPLEMENT_TYPE_STATUS to redefine struct vsf_spi_status_t.

◆ VSF_SPI_CFG_REIMPLEMENT_TYPE_CFG

#define VSF_SPI_CFG_REIMPLEMENT_TYPE_CFG   DISABLED

In specific hardware driver, enable macro VSF_SPI_CFG_REIMPLEMENT_TYPE_CFG to redefine struct vsf_spi_cfg_t. For compatibility, members should not be deleted when redefining vsf_spi_cfg_t. The type vsf_spi_isr_handler_t also needs to be redefined.

◆ VSF_SPI_CFG_REIMPLEMENT_TYPE_CTRL

#define VSF_SPI_CFG_REIMPLEMENT_TYPE_CTRL   DISABLED

In specific hardware driver, enable macro VSF_SPI_CFG_REIMPLEMENT_TYPE_CTRL to redefine enum vsf_spi_ctrl_t.

◆ VSF_SPI_CFG_REIMPLEMENT_TYPE_CAPABILITY

#define VSF_SPI_CFG_REIMPLEMENT_TYPE_CAPABILITY   DISABLED

In specific hardware driver, enable macro VSF_SPI_CFG_REIMPLEMENT_TYPE_CAPABILITY to redefine struct vsf_spi_capability_t. For compatibility, members should not be deleted.

◆ VSF_SPI_CFG_REIMPLEMENT_MODE_TO_DATA_BITS

#define VSF_SPI_CFG_REIMPLEMENT_MODE_TO_DATA_BITS   DISABLED

In specific hardware driver, enable macro VSF_SPI_CFG_REIMPLEMENT_MODE_TO_DATA_BITS to reimplement the function vsf_spi_mode_to_data_bits().

◆ VSF_SPI_CFG_REIMPLEMENT_DATA_BITS_TO_MODE

#define VSF_SPI_CFG_REIMPLEMENT_DATA_BITS_TO_MODE   DISABLED

In specific hardware driver, enable macro VSF_SPI_CFG_REIMPLEMENT_DATA_BITS_TO_MODE to reimplement the function vsf_spi_data_bits_to_mode().

◆ VSF_SPI_CFG_REIMPLEMENT_MODE_TO_BYTES

#define VSF_SPI_CFG_REIMPLEMENT_MODE_TO_BYTES   DISABLED

In specific hardware driver, enable macro VSF_SPI_CFG_REIMPLEMENT_MODE_TO_BYTES to reimplement the function vsf_spi_mode_to_data_bytes().

◆ VSF_SPI_CFG_INHERIT_HAL_CAPABILITY

#define VSF_SPI_CFG_INHERIT_HAL_CAPABILITY   ENABLED

In specific hardware driver, enable macro VSF_SPI_CFG_INHERIT_HAL_CAPABILITY to inherit the structure vsf_peripheral_capability_t.

◆ VSF_SPI_APIS

#define VSF_SPI_APIS (   __prefix)
Value:
__VSF_HAL_TEMPLATE_API(__prefix, vsf_err_t, spi, init, VSF_MCONNECT(__prefix, _spi_t) *spi_ptr, vsf_spi_cfg_t *cfg_ptr) \
__VSF_HAL_TEMPLATE_API(__prefix, void, spi, fini, VSF_MCONNECT(__prefix, _spi_t) *spi_ptr) \
__VSF_HAL_TEMPLATE_API(__prefix, fsm_rt_t, spi, enable, VSF_MCONNECT(__prefix, _spi_t) *spi_ptr) \
__VSF_HAL_TEMPLATE_API(__prefix, fsm_rt_t, spi, disable, VSF_MCONNECT(__prefix, _spi_t) *spi_ptr) \
__VSF_HAL_TEMPLATE_API(__prefix, void, spi, irq_enable, VSF_MCONNECT(__prefix, _spi_t) *spi_ptr, vsf_spi_irq_mask_t irq_mask) \
__VSF_HAL_TEMPLATE_API(__prefix, void, spi, irq_disable, VSF_MCONNECT(__prefix, _spi_t) *spi_ptr, vsf_spi_irq_mask_t irq_mask) \
__VSF_HAL_TEMPLATE_API(__prefix, vsf_spi_status_t, spi, status, VSF_MCONNECT(__prefix, _spi_t) *spi_ptr) \
__VSF_HAL_TEMPLATE_API(__prefix, vsf_spi_capability_t, spi, capability, VSF_MCONNECT(__prefix, _spi_t) *spi_ptr) \
__VSF_HAL_TEMPLATE_API(__prefix, vsf_err_t, spi, cs_active, VSF_MCONNECT(__prefix, _spi_t) *spi_ptr, uint_fast8_t index) \
__VSF_HAL_TEMPLATE_API(__prefix, vsf_err_t, spi, cs_inactive, VSF_MCONNECT(__prefix, _spi_t) *spi_ptr, uint_fast8_t index) \
__VSF_HAL_TEMPLATE_API(__prefix, void, spi, fifo_transfer, VSF_MCONNECT(__prefix, _spi_t) *spi_ptr, void *out_buffer_ptr, uint_fast32_t *out_offset_ptr, void *in_buffer_ptr, uint_fast32_t *in_offset_ptr, uint_fast32_t cnt) \
__VSF_HAL_TEMPLATE_API(__prefix, vsf_err_t, spi, request_transfer, VSF_MCONNECT(__prefix, _spi_t) *spi_ptr, void *out_buffer_ptr, void *in_buffer_ptr, uint_fast32_t count) \
__VSF_HAL_TEMPLATE_API(__prefix, vsf_err_t, spi, cancel_transfer, VSF_MCONNECT(__prefix, _spi_t) *spi_ptr) \
__VSF_HAL_TEMPLATE_API(__prefix, void, spi, get_transferred_count, VSF_MCONNECT(__prefix, _spi_t) *spi_ptr, uint_fast32_t * tx_count, uint_fast32_t *rx_count) \
__VSF_HAL_TEMPLATE_API(__prefix, vsf_err_t, spi, ctrl, VSF_MCONNECT(__prefix, _spi_t) *spi_ptr, vsf_spi_ctrl_t ctrl, void* param)
vsf_err_t
Definition __type.h:42
struct VSF_MCONNECT(VSF_FLASH_CFG_IMP_PREFIX, _flash_t)
Definition flash.c:53
__le16 capability
Definition ieee80211.h:134
const i_spi_t vsf_spi_irq_mask_t irq_mask
Definition spi_interface.h:38
unsigned char uint_fast8_t
Definition stdint.h:23
unsigned int uint_fast32_t
Definition stdint.h:27
Predefined VSF SPI capability that can be reimplemented in specific HAL drivers. Even if the hardware...
Definition vsf_template_spi.h:655
Configuration structure for SPI.
Definition vsf_template_spi.h:708
Predefined VSF SPI status that can be reimplemented in specific HAL drivers. Even if the hardware doe...
Definition vsf_template_spi.h:635
fsm_rt_t
Definition vsf_fsm.h:315
#define __VSF_HAL_TEMPLATE_API
Definition vsf_template_instance_declaration.h:57
vsf_spi_irq_mask_t
Predefined VSF SPI interrupt masks that can be reimplemented in specific HAL drivers....
Definition vsf_template_spi.h:579
vsf_spi_ctrl_t
Predefined VSF SPI control commands that can be reimplemented in specific HAL drivers....
Definition vsf_template_spi.h:734
uint8_t status
Definition vsf_tgui.h:144

SPI API template, used to generate SPI type, specific prefix function declarations, etc.

Parameters
[in]__prefixThe prefix used for generating SPI functions.

Typedef Documentation

◆ vsf_spi_mode_t

Predefined VSF SPI modes that can be reimplemented in specific HAL drivers.If we want to add optional modes in the specific driver, we need to provide one or more enum options, and a macro with the same name to determine if they are supported at runtime. If the feature supports more than one option, it also needs to provide the corresponding MASK option, so that the user can switch to different modes at compile-time.

◆ vsf_spi_irq_mask_t

Predefined VSF SPI interrupt masks that can be reimplemented in specific HAL drivers. Optional interrupts need to provide one or more enum options and a macro with the same name to determine if they are supported at runtime. If multiple options are supported, a corresponding MASK option should be provided to allow switching between modes at runtime.

◆ vsf_spi_status_t

Predefined VSF SPI status that can be reimplemented in specific HAL drivers. Even if the hardware doesn't support these features, these status must be kept.

  • is_busy: indicates if the SPI is currently busy

◆ vsf_spi_capability_t

Predefined VSF SPI capability that can be reimplemented in specific HAL drivers. Even if the hardware doesn't support these features, these capabilities must be kept.

◆ vsf_spi_t

typedef struct vsf_spi_t vsf_spi_t

SPI forward declaration.

◆ vsf_spi_isr_handler_t

typedef void vsf_spi_isr_handler_t(void *target_ptr, vsf_spi_t *spi_ptr, vsf_spi_irq_mask_t irq_mask)

SPI interrupt handler type declaration.

Parameters
[in,out]target_ptrUser defined target pointer passed to the handler
[in,out]spi_ptrSPI instance pointer vsf_spi_t
[in]irq_maskInterrupt mask indicating which events occurred

◆ vsf_spi_isr_t

typedef struct vsf_spi_isr_t vsf_spi_isr_t

SPI interrupt service routine configuration structure.

Note
The interrupt will not be enabled if handler_fn is NULL

◆ vsf_spi_cfg_t

typedef struct vsf_spi_cfg_t vsf_spi_cfg_t

Configuration structure for SPI.

◆ vsf_spi_ctrl_t

Predefined VSF SPI control commands that can be reimplemented in specific HAL drivers.Optional control commands require one or more enumeration options and a macro with the same name to determine if they are supported at runtime. If the feature supports more than one option, it is recommended to provide the corresponding MASK option, so that the user can check for supported features at compile-time.

◆ vsf_spi_op_t

typedef struct vsf_spi_op_t vsf_spi_op_t

SPI operation function pointer type, used for SPI Multi Class support.

Enumeration Type Documentation

◆ vsf_spi_mode_t

Predefined VSF SPI modes that can be reimplemented in specific HAL drivers.If we want to add optional modes in the specific driver, we need to provide one or more enum options, and a macro with the same name to determine if they are supported at runtime. If the feature supports more than one option, it also needs to provide the corresponding MASK option, so that the user can switch to different modes at compile-time.

Enumerator
VSF_SPI_MASTER 

Master mode (controller)

VSF_SPI_SLAVE 

Slave mode (peripheral)

VSF_SPI_MSB_FIRST 

Most Significant Bit (MSB) first.

VSF_SPI_LSB_FIRST 

Least Significant Bit (LSB) first.

VSF_SPI_CPOL_LOW 

Clock polarity: idle state is low.

VSF_SPI_CPOL_HIGH 

Clock polarity: idle state is high.

VSF_SPI_CPHA_LOW 

Clock phase: sample on first edge.

VSF_SPI_CPHA_HIGH 

Clock phase: sample on second edge.

VSF_SPI_MODE_0 

Mode 0: CPOL=0 (idle low), CPHA=0 (sample on first edge)

VSF_SPI_MODE_1 

Mode 1: CPOL=0 (idle low), CPHA=1 (sample on second edge)

VSF_SPI_MODE_2 

Mode 2: CPOL=1 (idle high), CPHA=0 (sample on first edge)

VSF_SPI_MODE_3 

Mode 3: CPOL=1 (idle high), CPHA=1 (sample on second edge)

VSF_SPI_CS_SOFTWARE_MODE 

Software controlled chip select.

VSF_SPI_CS_HARDWARE_MODE 

Hardware controlled chip select.

VSF_SPI_DATASIZE_8 

8-bit data transfer size

VSF_SPI_DATASIZE_16 

16-bit data transfer size

VSF_SPI_DATASIZE_32 

32-bit data transfer size

◆ anonymous enum

anonymous enum

SPI mode completion, used to simplify the definition of SPI mode.

Enumerator
VSF_SPI_DIR_MODE_MASK 

SPI direction mode mask for master/slave selection.

Note
Combines VSF_SPI_MASTER and VSF_SPI_SLAVE
VSF_SPI_BIT_ORDER_MASK 

SPI bit order mask for MSB/LSB first selection.

Note
Combines VSF_SPI_MSB_FIRST and VSF_SPI_LSB_FIRST
VSF_SPI_MODE_MASK 

SPI mode mask for clock polarity and phase configuration.

Note
Combines all four modes (0-3) with different CPOL/CPHA combinations
VSF_SPI_CS_MODE_MASK 

Some hardware supports more chip select mode, can be redefined inside the specific driver.

VSF_SPI_DATASIZE_MASK 

Some hardware supports more data bits, default defined as 8, 16, 32 bits.

VSF_SPI_MODE_ALL_BITS_MASK 

SPI Mode All Bits Mask.

◆ vsf_spi_irq_mask_t

Predefined VSF SPI interrupt masks that can be reimplemented in specific HAL drivers. Optional interrupts need to provide one or more enum options and a macro with the same name to determine if they are supported at runtime. If multiple options are supported, a corresponding MASK option should be provided to allow switching between modes at runtime.

Enumerator
VSF_SPI_IRQ_MASK_TX 

TX FIFO threshold interrupt (triggers when TX FIFO level is below threshold)

VSF_SPI_IRQ_MASK_RX 

RX FIFO threshold interrupt (triggers when RX FIFO level is above threshold)

VSF_SPI_IRQ_MASK_TX_CPL 

TX complete interrupt (triggers when all TX data has been sent)

VSF_SPI_IRQ_MASK_CPL 

Transfer complete interrupt (triggers when both TX and RX are complete)

VSF_SPI_IRQ_MASK_OVERFLOW_ERR 

Overflow error interrupt (triggers when RX FIFO overflows)

◆ anonymous enum

anonymous enum

SPI IRQ mask completion, used to simplify the definition of SPI IRQ mask.

Enumerator
VSF_SPI_IRQ_MASK_TX_FIFO_THRESHOLD 

VSF_SPI_IRQ_MASK_TX 的别名

VSF_SPI_IRQ_MASK_RX_FIFO_THRESHOLD 

VSF_SPI_IRQ_MASK_RX 的别名

VSF_SPI_IRQ_MASK_RX_CPL 

For SPI transfer, if RX transfer is done, then TX is done too.

VSF_SPI_IRQ_MASK_ERR 

Some hardware supports more different error interrupts, we can redefine it inside the specific driver.

VSF_SPI_IRQ_ALL_BITS_MASK 

Combined IRQ mask for all SPI interrupts.

◆ vsf_spi_ctrl_t

Predefined VSF SPI control commands that can be reimplemented in specific HAL drivers.Optional control commands require one or more enumeration options and a macro with the same name to determine if they are supported at runtime. If the feature supports more than one option, it is recommended to provide the corresponding MASK option, so that the user can check for supported features at compile-time.

Enumerator
__VSF_SPI_CTRL_DUMMY 

Dummy value for compilation.

Function Documentation

◆ vsf_spi_init()

vsf_err_t vsf_spi_init ( vsf_spi_t spi_ptr,
vsf_spi_cfg_t cfg_ptr 
)
extern

Initialize a SPI instance.

Parameters
[in,out]spi_ptrPointer to SPI instance structure vsf_spi_t
[in]cfg_ptrPointer to SPI configuration structure vsf_spi_cfg_t
Returns
vsf_err_t: VSF_ERR_NONE if initialization successful, otherwise returns error code
Note
The configuration includes clock settings, transfer modes, and interrupt handlers
This must be called before any other SPI operations except for vsf_spi_capability()

◆ vsf_spi_fini()

void vsf_spi_fini ( vsf_spi_t spi_ptr)
extern

Finalize (deinitialize) a SPI instance.

Parameters
[in,out]spi_ptrPointer to SPI instance structure vsf_spi_t
Note
This function should be called when the SPI instance is no longer needed
Ensure all transfers are complete before calling this function

◆ vsf_spi_enable()

fsm_rt_t vsf_spi_enable ( vsf_spi_t spi_ptr)
extern

Enable a SPI instance for operation.

Parameters
[in,out]spi_ptrPointer to SPI instance structure vsf_spi_t
Returns
fsm_rt_t: fsm_rt_cpl if SPI was enabled immediately, fsm_rt_on_going if enabling is in progress
Note
The instance must be initialized before enabling

◆ vsf_spi_disable()

fsm_rt_t vsf_spi_disable ( vsf_spi_t spi_ptr)
extern

Disable a SPI instance from operation.

Parameters
[in,out]spi_ptrPointer to SPI instance structure vsf_spi_t
Returns
fsm_rt_t: fsm_rt_cpl if SPI was disabled immediately, fsm_rt_on_going if disabling is in progress
Note
Any ongoing transfers should be completed or cancelled before disabling

◆ vsf_spi_irq_enable()

void vsf_spi_irq_enable ( vsf_spi_t spi_ptr,
vsf_spi_irq_mask_t  irq_mask 
)
extern

Enable specific interrupts for a SPI instance.

Parameters
[in,out]spi_ptrPointer to SPI instance structure vsf_spi_t
[in]irq_maskInterrupt mask(s) to enable from vsf_spi_irq_mask_t
Note
Clear any pending interrupts before enabling new ones
Multiple interrupts can be enabled by OR-ing the masks

◆ vsf_spi_irq_disable()

void vsf_spi_irq_disable ( vsf_spi_t spi_ptr,
vsf_spi_irq_mask_t  irq_mask 
)
extern

Disable specific interrupts for a SPI instance.

Parameters
[in,out]spi_ptrPointer to SPI instance structure vsf_spi_t
[in]irq_maskInterrupt mask(s) to disable from vsf_spi_irq_mask_t
Note
Multiple interrupts can be disabled by OR-ing the masks

◆ vsf_spi_cs_active()

vsf_err_t vsf_spi_cs_active ( vsf_spi_t spi_ptr,
uint_fast8_t  index 
)
extern

Activate (assert) a SPI chip select line.

Parameters
[in,out]spi_ptrPointer to SPI instance structure vsf_spi_t
[in]indexChip select line index (0 to cs_count-1)
Returns
vsf_err_t: VSF_ERR_NONE if successful, otherwise returns error code
Note
Hardware chip select support must be available if using hardware mode

◆ vsf_spi_cs_inactive()

vsf_err_t vsf_spi_cs_inactive ( vsf_spi_t spi_ptr,
uint_fast8_t  index 
)
extern

Deactivate (deassert) a SPI chip select line.

Parameters
[in,out]spi_ptrPointer to SPI instance structure vsf_spi_t
[in]indexChip select line index (0 to cs_count-1)
Returns
vsf_err_t: VSF_ERR_NONE if successful, otherwise returns error code
Note
Hardware chip select support must be available if using hardware mode

◆ vsf_spi_status()

vsf_spi_status_t vsf_spi_status ( vsf_spi_t spi_ptr)
extern

Get the current status of a SPI instance.

Parameters
[in,out]spi_ptrPointer to SPI instance structure vsf_spi_t
Returns
vsf_spi_status_t: Current status flags of the SPI instance
Note
Status includes busy flag and other peripheral status information

◆ vsf_spi_capability()

vsf_spi_capability_t vsf_spi_capability ( vsf_spi_t spi_ptr)
extern

Get the capabilities of a SPI instance.

Parameters
[in,out]spi_ptrPointer to SPI instance structure vsf_spi_t
Returns
vsf_spi_capability_t: Hardware capabilities of the SPI instance
Note
Capabilities include supported features, modes, and limitations

◆ vsf_spi_fifo_transfer()

void vsf_spi_fifo_transfer ( vsf_spi_t spi_ptr,
void *  out_buffer_ptr,
uint_fast32_t out_offset_ptr,
void *  in_buffer_ptr,
uint_fast32_t in_offset_ptr,
uint_fast32_t  count 
)
extern

Perform FIFO-based data transfer on a SPI instance.

Parameters
[in,out]spi_ptrPointer to SPI instance structure vsf_spi_t
[in]out_buffer_ptrPointer to transmit data buffer (can be NULL for receive-only)
[in,out]out_offset_ptrPointer to transmit buffer offset
[out]in_buffer_ptrPointer to receive data buffer (can be NULL for transmit-only)
[in,out]in_offset_ptrPointer to receive buffer offset
[in]countNumber of data units to transfer
Note
Data unit size is determined by the configured data size in SPI mode
In master mode, out_buffer_ptr data is sent through MOSI pin, in_buffer_ptr receives from MISO pin
In slave mode, out_buffer_ptr data is sent through MISO pin, in_buffer_ptr receives from MOSI pin

◆ vsf_spi_request_transfer()

vsf_err_t vsf_spi_request_transfer ( vsf_spi_t spi_ptr,
void *  out_buffer_ptr,
void *  in_buffer_ptr,
uint_fast32_t  count 
)
extern

Request a SPI data transfer operation.

Parameters
[in,out]spi_ptrPointer to SPI instance structure vsf_spi_t
[in]out_buffer_ptrPointer to output data buffer (NULL for receive-only)
[in]in_buffer_ptrPointer to input data buffer (NULL for transmit-only)
[in]countNumber of data units to transfer
Returns
vsf_err_t: VSF_ERR_NONE if transfer started successfully, or error code
Note
This is an asynchronous operation, register for completion interrupts to be notified
If both out_buffer_ptr and in_buffer_ptr are not NULL, data is exchanged in full-duplex mode
In master mode, out_buffer_ptr data is sent through MOSI pin, in_buffer_ptr receives from MISO pin
In slave mode, out_buffer_ptr data is sent through MISO pin, in_buffer_ptr receives from MOSI pin

◆ vsf_spi_cancel_transfer()

vsf_err_t vsf_spi_cancel_transfer ( vsf_spi_t spi_ptr)
extern

Cancel an ongoing SPI transfer operation.

Parameters
[in,out]spi_ptrPointer to SPI instance structure vsf_spi_t
Returns
vsf_err_t: VSF_ERR_NONE if cancellation was successful, or error code
Note
SPI hardware may not be able to cancel immediately if busy

◆ vsf_spi_get_transferred_count()

void vsf_spi_get_transferred_count ( vsf_spi_t spi_ptr,
uint_fast32_t sent_count,
uint_fast32_t received_count 
)
extern

Get the number of data units transferred in the current or last SPI operation.

Parameters
[in,out]spi_ptrPointer to SPI instance structure vsf_spi_t
[out]sent_countPointer to store the number of data units transmitted (can be NULL if not needed)
[out]received_countPointer to store the number of data units received (can be NULL if not needed)
Note
Data unit count is based on the configured data size (e.g., for 16-bit data size, count is in 16-bit units)
For ongoing transfers, returns the current progress; for completed transfers, returns final counts

◆ vsf_spi_ctrl()

vsf_err_t vsf_spi_ctrl ( vsf_spi_t spi_ptr,
vsf_spi_ctrl_t  ctrl,
void *  param 
)
extern

Execute a control command on the SPI instance.

Parameters
[in,out]spi_ptrPointer to SPI instance structure vsf_spi_t
[in]ctrlControl command from vsf_spi_ctrl_t enumeration
[in]paramCommand-specific parameter (can be NULL depending on command)
Returns
vsf_err_t: VSF_ERR_NONE if command executed successfully, VSF_ERR_NOT_SUPPORT if command is not supported, other negative error codes for specific failures
Note
Available commands and their parameters are hardware-dependent
Some commands may not be supported on all hardware platforms
Generated from commit: vsfteam/vsf@2b286be