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
 
struct  vsf_spi_capability_t
 
struct  vsf_spi_isr_t
 spi isr for api More...
 
struct  vsf_spi_cfg_t
 spi configuration for api More...
 
struct  vsf_spi_op_t
 
struct  vsf_spi_t
 

Macros

#define VSF_SPI_CFG_MULTI_CLASS   ENABLED
 
#define VSF_SPI_CFG_PREFIX   vsf
 
#define VSF_SPI_CFG_FUNCTION_RENAME   ENABLED
 
#define VSF_SPI_CFG_REIMPLEMENT_TYPE_MODE   DISABLED
 
#define VSF_SPI_CFG_REIMPLEMENT_TYPE_IRQ_MASK   DISABLED
 
#define VSF_SPI_CFG_REIMPLEMENT_TYPE_STATUS   DISABLED
 
#define VSF_SPI_CFG_REIMPLEMENT_TYPE_CFG   DISABLED
 
#define VSF_SPI_CFG_REIMPLEMENT_TYPE_CAPABILITY   DISABLED
 
#define VSF_SPI_CFG_REIMPLEMENT_MODE_TO_DATA_BITS   DISABLED
 
#define VSF_SPI_CFG_REIMPLEMENT_DATA_BITS_TO_MODE   DISABLED
 
#define VSF_SPI_CFG_REIMPLEMENT_DATA_BITS_TO_BYTES   DISABLED
 
#define VSF_SPI_CFG_INHERT_HAL_CAPABILITY   ENABLED
 
#define VSF_SPI_APIS(__prefix_name)
 
#define __VSF_HAL_TEMPLATE_API   VSF_HAL_TEMPLATE_API_FP
 
#define __vsf_spi_t   VSF_MCONNECT(VSF_SPI_CFG_PREFIX, _spi_t)
 
#define vsf_spi_init(__SPI, ...)   VSF_MCONNECT(VSF_SPI_CFG_PREFIX, _spi_init) ((__vsf_spi_t *)(__SPI), ##__VA_ARGS__)
 
#define vsf_spi_enable(__SPI)   VSF_MCONNECT(VSF_SPI_CFG_PREFIX, _spi_enable) ((__vsf_spi_t *)(__SPI))
 
#define vsf_spi_disable(__SPI)   VSF_MCONNECT(VSF_SPI_CFG_PREFIX, _spi_disable) ((__vsf_spi_t *)(__SPI))
 
#define vsf_spi_irq_enable(__SPI, ...)   VSF_MCONNECT(VSF_SPI_CFG_PREFIX, _spi_irq_enable) ((__vsf_spi_t *)(__SPI), ##__VA_ARGS__)
 
#define vsf_spi_irq_disable(__SPI, ...)   VSF_MCONNECT(VSF_SPI_CFG_PREFIX, _spi_irq_disable) ((__vsf_spi_t *)(__SPI), ##__VA_ARGS__)
 
#define vsf_spi_status(__SPI)   VSF_MCONNECT(VSF_SPI_CFG_PREFIX, _spi_status) ((__vsf_spi_t *)(__SPI))
 
#define vsf_spi_capability(__SPI)   VSF_MCONNECT(VSF_SPI_CFG_PREFIX, _spi_capability) ((__vsf_spi_t *)(__SPI))
 
#define vsf_spi_cs_active(__SPI, ...)   VSF_MCONNECT(VSF_SPI_CFG_PREFIX, _spi_cs_active) ((__vsf_spi_t *)(__SPI), ##__VA_ARGS__)
 
#define vsf_spi_cs_inactive(__SPI, ...)   VSF_MCONNECT(VSF_SPI_CFG_PREFIX, _spi_cs_inactive) ((__vsf_spi_t *)(__SPI), ##__VA_ARGS__)
 
#define vsf_spi_fifo_transfer(__SPI, ...)   VSF_MCONNECT(VSF_SPI_CFG_PREFIX, _spi_fifo_transfer) ((__vsf_spi_t *)(__SPI), ##__VA_ARGS__)
 
#define vsf_spi_request_transfer(__SPI, ...)   VSF_MCONNECT(VSF_SPI_CFG_PREFIX, _spi_request_transfer) ((__vsf_spi_t *)(__SPI), ##__VA_ARGS__)
 
#define vsf_spi_cancel_transfer(__SPI)   VSF_MCONNECT(VSF_SPI_CFG_PREFIX, _spi_cancel_transfer) ((__vsf_spi_t *)(__SPI))
 
#define vsf_spi_get_transferred_count(__SPI, ...)   VSF_MCONNECT(VSF_SPI_CFG_PREFIX, _spi_get_transferred_count) ((__vsf_spi_t *)(__SPI), ##__VA_ARGS__)
 

Typedefs

typedef enum vsf_spi_mode_t vsf_spi_mode_t
 Predefined VSF SPI modes that can be reimplemented in specific hal drivers.
 
typedef enum vsf_spi_irq_mask_t vsf_spi_irq_mask_t
 Predefined VSF SPI interrupt that can be reimplemented in specific hal drivers.
 
typedef struct vsf_spi_status_t vsf_spi_status_t
 
typedef struct vsf_spi_capability_t vsf_spi_capability_t
 
typedef struct vsf_spi_t vsf_spi_t
 
typedef void vsf_spi_isr_handler_t(void *target_ptr, vsf_spi_t *spi_ptr, vsf_spi_irq_mask_t irq_mask)
 
typedef struct vsf_spi_isr_t vsf_spi_isr_t
 spi isr for api
 
typedef struct vsf_spi_cfg_t vsf_spi_cfg_t
 spi configuration for api
 
typedef struct vsf_spi_op_t vsf_spi_op_t
 

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. 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
}
 
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 ,
  VSF_SPI_IRQ_MASK_ERROR = 0x01ul << 5
}
 Predefined VSF SPI interrupt that can be reimplemented in specific hal drivers. 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_ALL_BITS_MASK
}
 

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 a spi instance.
 
fsm_rt_t vsf_spi_enable (vsf_spi_t *spi_ptr)
 enable interrupt masks of spi instance.
 
fsm_rt_t vsf_spi_disable (vsf_spi_t *spi_ptr)
 disable interrupt masks of spi instance.
 
void vsf_spi_irq_enable (vsf_spi_t *spi_ptr, vsf_spi_irq_mask_t irq_mask)
 enable interrupt masks of spi instance.
 
void vsf_spi_irq_disable (vsf_spi_t *spi_ptr, vsf_spi_irq_mask_t irq_mask)
 disable interrupt masks of spi instance.
 
void vsf_spi_cs_active (vsf_spi_t *spi_ptr, uint_fast8_t index)
 spi set chip select active
 
void vsf_spi_cs_inactive (vsf_spi_t *spi_ptr, uint_fast8_t index)
 spi set chip select inactive
 
vsf_spi_status_t vsf_spi_status (vsf_spi_t *spi_ptr)
 get the status of spi instance.
 
vsf_spi_capability_t vsf_spi_capability (vsf_spi_t *spi_ptr)
 get the capability of 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)
 spi fifo 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)
 start spi transfer. The best way to do this is to use DMA. Software implementation is the solution when DMA cannot be used
 
vsf_err_t vsf_spi_cancel_transfer (vsf_spi_t *spi_ptr)
 spi cancel transfer
 
void vsf_spi_get_transferred_count (vsf_spi_t *spi_ptr, uint_fast32_t *sent_count, uint_fast32_t *received_count)
 spi get transferred counter
 

Macro Definition Documentation

◆ VSF_SPI_CFG_MULTI_CLASS

#define VSF_SPI_CFG_MULTI_CLASS   ENABLED

◆ VSF_SPI_CFG_PREFIX

#define VSF_SPI_CFG_PREFIX   vsf

◆ VSF_SPI_CFG_FUNCTION_RENAME

#define VSF_SPI_CFG_FUNCTION_RENAME   ENABLED

◆ VSF_SPI_CFG_REIMPLEMENT_TYPE_MODE

#define VSF_SPI_CFG_REIMPLEMENT_TYPE_MODE   DISABLED

In the specific hardware driver, we can enable VSF_SPI_CFG_REIMPLEMENT_TYPE_MODE to redefine vsf_spi_mode_t as needed.

◆ VSF_SPI_CFG_REIMPLEMENT_TYPE_IRQ_MASK

#define VSF_SPI_CFG_REIMPLEMENT_TYPE_IRQ_MASK   DISABLED

In the specific hardware driver, we can enable VSF_SPI_CFG_REIMPLEMENT_TYPE_IRQ_MASK to redefine vsf_spi_irq_mask_t as needed.

◆ VSF_SPI_CFG_REIMPLEMENT_TYPE_STATUS

#define VSF_SPI_CFG_REIMPLEMENT_TYPE_STATUS   DISABLED

In the specific hardware driver, we can enable VSF_SPI_CFG_REIMPLEMENT_TYPE_STATUS to redefine vsf_spi_status_t as needed.

◆ VSF_SPI_CFG_REIMPLEMENT_TYPE_CFG

#define VSF_SPI_CFG_REIMPLEMENT_TYPE_CFG   DISABLED

Redefine struct vsf_spi_cfg_t. The vsf_spi_isr_handler_t type also needs to be redefined For compatibility, members should not be deleted when struct vsf_spi_cfg_t redefining.

◆ VSF_SPI_CFG_REIMPLEMENT_TYPE_CAPABILITY

#define VSF_SPI_CFG_REIMPLEMENT_TYPE_CAPABILITY   DISABLED

Redefine struct vsf_spi_capability_t. For compatibility, members should not be deleted when struct vsf_spi_capability_t redefining.

◆ VSF_SPI_CFG_REIMPLEMENT_MODE_TO_DATA_BITS

#define VSF_SPI_CFG_REIMPLEMENT_MODE_TO_DATA_BITS   DISABLED

In the specific hardware driver, we can enable VSF_SPI_CFG_REIMPLEMENT_MODE_TO_DATA_BITS to reimplement the function vsf_spi_mode_to_data_bits as needed.

◆ VSF_SPI_CFG_REIMPLEMENT_DATA_BITS_TO_MODE

#define VSF_SPI_CFG_REIMPLEMENT_DATA_BITS_TO_MODE   DISABLED

In the specific hardware driver, we can enable VSF_SPI_CFG_REIMPLEMENT_MODE_TO_DATA_BITS to reimplement the function vsf_spi_data_bits_to_mode as needed.

◆ VSF_SPI_CFG_REIMPLEMENT_DATA_BITS_TO_BYTES

#define VSF_SPI_CFG_REIMPLEMENT_DATA_BITS_TO_BYTES   DISABLED

In the specific hardware driver, we can enable VSF_SPI_CFG_REIMPLEMENT_MODE_TO_DATA_BITS to reimplement the function vsf_spi_data_bits_to_mode as needed.

◆ VSF_SPI_CFG_INHERT_HAL_CAPABILITY

#define VSF_SPI_CFG_INHERT_HAL_CAPABILITY   ENABLED

◆ VSF_SPI_APIS

#define VSF_SPI_APIS (   __prefix_name)
Value:
__VSF_HAL_TEMPLATE_API(__prefix_name, vsf_err_t, spi, init, VSF_MCONNECT(__prefix_name, _spi_t) *spi_ptr, vsf_spi_cfg_t *cfg_ptr) \
__VSF_HAL_TEMPLATE_API(__prefix_name, void, spi, fini, VSF_MCONNECT(__prefix_name, _spi_t) *spi_ptr) \
__VSF_HAL_TEMPLATE_API(__prefix_name, fsm_rt_t, spi, enable, VSF_MCONNECT(__prefix_name, _spi_t) *spi_ptr) \
__VSF_HAL_TEMPLATE_API(__prefix_name, fsm_rt_t, spi, disable, VSF_MCONNECT(__prefix_name, _spi_t) *spi_ptr) \
__VSF_HAL_TEMPLATE_API(__prefix_name, void, spi, irq_enable, VSF_MCONNECT(__prefix_name, _spi_t) *spi_ptr, vsf_spi_irq_mask_t irq_mask) \
__VSF_HAL_TEMPLATE_API(__prefix_name, void, spi, irq_disable, VSF_MCONNECT(__prefix_name, _spi_t) *spi_ptr, vsf_spi_irq_mask_t irq_mask) \
__VSF_HAL_TEMPLATE_API(__prefix_name, vsf_spi_status_t, spi, status, VSF_MCONNECT(__prefix_name, _spi_t) *spi_ptr) \
__VSF_HAL_TEMPLATE_API(__prefix_name, vsf_spi_capability_t, spi, capability, VSF_MCONNECT(__prefix_name, _spi_t) *spi_ptr) \
__VSF_HAL_TEMPLATE_API(__prefix_name, void, spi, cs_active, VSF_MCONNECT(__prefix_name, _spi_t) *spi_ptr, uint_fast8_t index) \
__VSF_HAL_TEMPLATE_API(__prefix_name, void, spi, cs_inactive, VSF_MCONNECT(__prefix_name, _spi_t) *spi_ptr, uint_fast8_t index) \
__VSF_HAL_TEMPLATE_API(__prefix_name, void, spi, fifo_transfer, VSF_MCONNECT(__prefix_name, _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_name, vsf_err_t, spi, request_transfer, VSF_MCONNECT(__prefix_name, _spi_t) *spi_ptr, void *out_buffer_ptr, \
void *in_buffer_ptr, uint_fast32_t count) \
__VSF_HAL_TEMPLATE_API(__prefix_name, vsf_err_t, spi, cancel_transfer, VSF_MCONNECT(__prefix_name, _spi_t) *spi_ptr) \
__VSF_HAL_TEMPLATE_API(__prefix_name, void, spi, get_transferred_count, VSF_MCONNECT(__prefix_name, _spi_t) *spi_ptr, uint_fast32_t * tx_count, uint_fast32_t *rx_count)
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
Definition vsf_template_spi.h:495
spi configuration for api
Definition vsf_template_spi.h:525
Definition vsf_template_spi.h:484
fsm_rt_t
Definition vsf_fsm.h:315
#define __VSF_HAL_TEMPLATE_API
Definition vsf_template_spi.h:535
vsf_spi_irq_mask_t
Predefined VSF SPI interrupt that can be reimplemented in specific hal drivers.
Definition vsf_template_spi.h:454
uint8_t status
Definition vsf_tgui.h:122

◆ __VSF_HAL_TEMPLATE_API

#define __VSF_HAL_TEMPLATE_API   VSF_HAL_TEMPLATE_API_FP

◆ __vsf_spi_t

#define __vsf_spi_t   VSF_MCONNECT(VSF_SPI_CFG_PREFIX, _spi_t)

◆ vsf_spi_init

#define vsf_spi_init (   __SPI,
  ... 
)    VSF_MCONNECT(VSF_SPI_CFG_PREFIX, _spi_init) ((__vsf_spi_t *)(__SPI), ##__VA_ARGS__)

◆ vsf_spi_enable

#define vsf_spi_enable (   __SPI)    VSF_MCONNECT(VSF_SPI_CFG_PREFIX, _spi_enable) ((__vsf_spi_t *)(__SPI))

◆ vsf_spi_disable

#define vsf_spi_disable (   __SPI)    VSF_MCONNECT(VSF_SPI_CFG_PREFIX, _spi_disable) ((__vsf_spi_t *)(__SPI))

◆ vsf_spi_irq_enable

#define vsf_spi_irq_enable (   __SPI,
  ... 
)    VSF_MCONNECT(VSF_SPI_CFG_PREFIX, _spi_irq_enable) ((__vsf_spi_t *)(__SPI), ##__VA_ARGS__)

◆ vsf_spi_irq_disable

#define vsf_spi_irq_disable (   __SPI,
  ... 
)    VSF_MCONNECT(VSF_SPI_CFG_PREFIX, _spi_irq_disable) ((__vsf_spi_t *)(__SPI), ##__VA_ARGS__)

◆ vsf_spi_status

#define vsf_spi_status (   __SPI)    VSF_MCONNECT(VSF_SPI_CFG_PREFIX, _spi_status) ((__vsf_spi_t *)(__SPI))

◆ vsf_spi_capability

#define vsf_spi_capability (   __SPI)    VSF_MCONNECT(VSF_SPI_CFG_PREFIX, _spi_capability) ((__vsf_spi_t *)(__SPI))

◆ vsf_spi_cs_active

#define vsf_spi_cs_active (   __SPI,
  ... 
)    VSF_MCONNECT(VSF_SPI_CFG_PREFIX, _spi_cs_active) ((__vsf_spi_t *)(__SPI), ##__VA_ARGS__)

◆ vsf_spi_cs_inactive

#define vsf_spi_cs_inactive (   __SPI,
  ... 
)    VSF_MCONNECT(VSF_SPI_CFG_PREFIX, _spi_cs_inactive) ((__vsf_spi_t *)(__SPI), ##__VA_ARGS__)

◆ vsf_spi_fifo_transfer

#define vsf_spi_fifo_transfer (   __SPI,
  ... 
)    VSF_MCONNECT(VSF_SPI_CFG_PREFIX, _spi_fifo_transfer) ((__vsf_spi_t *)(__SPI), ##__VA_ARGS__)

◆ vsf_spi_request_transfer

#define vsf_spi_request_transfer (   __SPI,
  ... 
)    VSF_MCONNECT(VSF_SPI_CFG_PREFIX, _spi_request_transfer) ((__vsf_spi_t *)(__SPI), ##__VA_ARGS__)

◆ vsf_spi_cancel_transfer

#define vsf_spi_cancel_transfer (   __SPI)    VSF_MCONNECT(VSF_SPI_CFG_PREFIX, _spi_cancel_transfer) ((__vsf_spi_t *)(__SPI))

◆ vsf_spi_get_transferred_count

#define vsf_spi_get_transferred_count (   __SPI,
  ... 
)    VSF_MCONNECT(VSF_SPI_CFG_PREFIX, _spi_get_transferred_count) ((__vsf_spi_t *)(__SPI), ##__VA_ARGS__)

Typedef Documentation

◆ vsf_spi_mode_t

Predefined VSF SPI modes that can be reimplemented in specific hal drivers.

Even if the hardware doesn't support these modes, the following modes must be kept, If the hardware supports more modes, e.g. more databits, more slave select mode, we can implement it in the hardware driver:

If more new modes are added to the driver, then the corresponding MASK macros need to be defined to include the values of the new modes. For example, Adding the new databit option requires that the macro VSF_SPI_DATASIZE_MASK be defined.

Optional features 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 switch to different modes at compile-time.

◆ vsf_spi_irq_mask_t

Predefined VSF SPI interrupt that can be reimplemented in specific hal drivers.

Even if the hardware doesn't support these features, these interrupt must be kept.

◆ vsf_spi_status_t

◆ vsf_spi_capability_t

◆ vsf_spi_t

typedef struct vsf_spi_t vsf_spi_t

◆ 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)

◆ vsf_spi_isr_t

typedef struct vsf_spi_isr_t vsf_spi_isr_t

spi isr for api

◆ vsf_spi_cfg_t

typedef struct vsf_spi_cfg_t vsf_spi_cfg_t

spi configuration for api

◆ vsf_spi_op_t

typedef struct vsf_spi_op_t vsf_spi_op_t

Enumeration Type Documentation

◆ vsf_spi_mode_t

Predefined VSF SPI modes that can be reimplemented in specific hal drivers.

Even if the hardware doesn't support these modes, the following modes must be kept, If the hardware supports more modes, e.g. more databits, more slave select mode, we can implement it in the hardware driver:

If more new modes are added to the driver, then the corresponding MASK macros need to be defined to include the values of the new modes. For example, Adding the new databit option requires that the macro VSF_SPI_DATASIZE_MASK be defined.

Optional features 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 switch to different modes at compile-time.

Enumerator
VSF_SPI_MASTER 

select master mode

VSF_SPI_SLAVE 

select slave mode

VSF_SPI_MSB_FIRST 

default enable MSB

VSF_SPI_LSB_FIRST 

transfer LSB first

VSF_SPI_CPOL_LOW 

SCK clock polarity is low.

VSF_SPI_CPOL_HIGH 

SCK clock polarity is high.

VSF_SPI_CPHA_LOW 

SCK clock phase is low.

VSF_SPI_CPHA_HIGH 

SCK clock phase is high.

VSF_SPI_MODE_0 
VSF_SPI_MODE_1 
VSF_SPI_MODE_2 
VSF_SPI_MODE_3 
VSF_SPI_CS_SOFTWARE_MODE 

SCK Chip Select by software(vsf_spi_cs_active/vsf_spi_cs_inactive)

VSF_SPI_CS_HARDWARE_MODE 

Hardware dependent, possibly low all the time spi is enabled, possibly low only when spi is transmitted

VSF_SPI_DATASIZE_8 
VSF_SPI_DATASIZE_16 
VSF_SPI_DATASIZE_32 

◆ anonymous enum

anonymous enum
Enumerator
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 

◆ vsf_spi_irq_mask_t

Predefined VSF SPI interrupt that can be reimplemented in specific hal drivers.

Even if the hardware doesn't support these features, these interrupt must be kept.

Enumerator
VSF_SPI_IRQ_MASK_TX 
VSF_SPI_IRQ_MASK_RX 
VSF_SPI_IRQ_MASK_TX_CPL 
VSF_SPI_IRQ_MASK_CPL 
VSF_SPI_IRQ_MASK_OVERFLOW_ERR 
VSF_SPI_IRQ_MASK_ERROR 

◆ anonymous enum

anonymous enum
Enumerator
VSF_SPI_IRQ_MASK_TX_FIFO_THRESHOLD 
VSF_SPI_IRQ_MASK_RX_FIFO_THRESHOLD 
VSF_SPI_IRQ_MASK_RX_CPL 

For SPI transfers, send completion is definitely earlier than receive completion.

VSF_SPI_IRQ_ALL_BITS_MASK 

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]spi_ptra pointer to structure vsf_spi_t
[in]cfg_ptra pointer to structure vsf_spi_cfg_t
Returns
vsf_err_t: VSF_ERR_NONE if spi was initialized, or a negative error code

◆ vsf_spi_fini()

void vsf_spi_fini ( vsf_spi_t spi_ptr)
extern

finalize a spi instance.

Parameters
[in]spi_ptra pointer to structure vsf_spi_t
Returns
none

◆ vsf_spi_enable()

fsm_rt_t vsf_spi_enable ( vsf_spi_t spi_ptr)
extern

enable interrupt masks of spi instance.

Parameters
[in]spi_ptra pointer to structure vsf_spi_t
Returns
none.

◆ vsf_spi_disable()

fsm_rt_t vsf_spi_disable ( vsf_spi_t spi_ptr)
extern

disable interrupt masks of spi instance.

Parameters
[in]spi_ptra pointer to structure vsf_spi_t
Returns
none.

◆ vsf_spi_irq_enable()

void vsf_spi_irq_enable ( vsf_spi_t spi_ptr,
vsf_spi_irq_mask_t  irq_mask 
)
extern

enable interrupt masks of spi instance.

Parameters
[in]spi_ptra pointer to structure vsf_spi_t
[in]irq_maskone or more value of enum vsf_spi_irq_mask_t
Returns
none.
Note
All pending interrupts should be cleared before interrupts are enabled.

◆ vsf_spi_irq_disable()

void vsf_spi_irq_disable ( vsf_spi_t spi_ptr,
vsf_spi_irq_mask_t  irq_mask 
)
extern

disable interrupt masks of spi instance.

Parameters
[in]spi_ptra pointer to structure vsf_spi_t
[in]irq_maskone or more value of enum vsf_spi_irq_mask_t, vsf_spi_irq_mask_t
Returns
none.

◆ vsf_spi_cs_active()

void vsf_spi_cs_active ( vsf_spi_t spi_ptr,
uint_fast8_t  index 
)
extern

spi set chip select active

Parameters
[in]spi_ptra pointer to structure vsf_spi_t
[in]indexchip select index
Returns
none.

◆ vsf_spi_cs_inactive()

void vsf_spi_cs_inactive ( vsf_spi_t spi_ptr,
uint_fast8_t  index 
)
extern

spi set chip select inactive

Parameters
[in]spi_ptra pointer to structure vsf_spi_t
[in]indexchip select index
Returns
none.

◆ vsf_spi_status()

vsf_spi_status_t vsf_spi_status ( vsf_spi_t spi_ptr)
extern

get the status of spi instance.

Parameters
[in]spi_ptra pointer to structure vsf_spi_t
Returns
vsf_spi_status_t: return all status of current spi

◆ vsf_spi_capability()

vsf_spi_capability_t vsf_spi_capability ( vsf_spi_t spi_ptr)
extern

get the capability of spi instance.

Parameters
[in]spi_ptra pointer to structure vsf_spi_t
Returns
vsf_spi_capability_t: return all capability of current spi vsf_spi_capability_t

◆ 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

spi fifo transfer

Parameters
[in]spi_ptra pointer to structure vsf_spi_t
[in]out_buffer_ptra pointer to spi send data buffer, it can be a null pointer
[in,out]out_offset_ptra pointer to spi send data buffer offset
[in]in_buffer_ptra pointer to spi receive data buffer, it can be a null pointer
[in,out]in_offset_ptra pointer to spi send data buffer offset
[in]countThe number of data received or sent
Returns
vsf_err_t: VSF_ERR_NONE if spi transfer successfully, or a negative error code

◆ 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

start spi transfer. The best way to do this is to use DMA. Software implementation is the solution when DMA cannot be used

Note
When using DMA, you need to use DMA to receive data first, and then process DMA to send data.
Parameters
[in]spi_ptra pointer to structure vsf_spi_t
[in]out_buffer_ptra pointer to spi send data buffer, it can be a null pointer
[in]in_buffer_ptra pointer to spi receive data buffer, it can be a null pointer
[in]countThe number of data received or sent
Returns
vsf_err_t: VSF_ERR_NONE if spi transfer successfully, or a negative error code

◆ vsf_spi_cancel_transfer()

vsf_err_t vsf_spi_cancel_transfer ( vsf_spi_t spi_ptr)
extern

spi cancel transfer

Parameters
[in]spi_ptra pointer to structure vsf_spi_t
Returns
vsf_err_t: VSF_ERR_NONE if spi cancel transfer successfully, or a negative error code

◆ 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

spi get transferred counter

Parameters
[in]spi_ptra pointer to structure vsf_spi_t
[out]send_counta pointer to the number of spi data already sent
[out]received_counta pointer to the number of spi data already received
Returns
vsf_err_t: VSF_ERR_NONE if spi cancel transfer successfully, or a negative error code