VSF Documented
vsf_template_spi.h
Go to the documentation of this file.
1/*****************************************************************************
2 * Copyright(C)2009-2022 by VSF Team *
3 * *
4 * Licensed under the Apache License, Version 2.0 (the "License"); *
5 * you may not use this file except in compliance with the License. *
6 * You may obtain a copy of the License at *
7 * *
8 * http://www.apache.org/licenses/LICENSE-2.0 *
9 * *
10 * Unless required by applicable law or agreed to in writing, software *
11 * distributed under the License is distributed on an "AS IS" BASIS, *
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. *
13 * See the License for the specific language governing permissions and *
14 * limitations under the License. *
15 * *
16 ****************************************************************************/
17
18#ifndef __VSF_TEMPLATE_SPI_H__
19#define __VSF_TEMPLATE_SPI_H__
20
21/*============================ INCLUDES ======================================*/
22
24#include "hal/arch/vsf_arch.h"
25
26#ifdef __cplusplus
27extern "C" {
28#endif
29
30/*============================ MACROS ========================================*/
31
39#ifndef VSF_SPI_CFG_MULTI_CLASS
40# define VSF_SPI_CFG_MULTI_CLASS ENABLED
41#endif
42
50#if defined(VSF_HW_SPI_COUNT) && !defined(VSF_HW_SPI_MASK)
51# define VSF_HW_SPI_MASK VSF_HAL_COUNT_TO_MASK(VSF_HW_SPI_COUNT)
52#endif
53
61#if defined(VSF_HW_SPI_MASK) && !defined(VSF_HW_SPI_COUNT)
62# define VSF_HW_SPI_COUNT VSF_HAL_MASK_TO_COUNT(VSF_HW_SPI_MASK)
63#endif
64
73#ifndef VSF_SPI_CFG_PREFIX
74# if VSF_SPI_CFG_MULTI_CLASS == ENABLED
75# define VSF_SPI_CFG_PREFIX vsf
76# elif defined(VSF_HW_SPI_COUNT) && (VSF_HW_SPI_COUNT != 0)
77# define VSF_SPI_CFG_PREFIX vsf_hw
78# else
79# define VSF_SPI_CFG_PREFIX vsf
80# endif
81#endif
82
91#ifndef VSF_SPI_CFG_FUNCTION_RENAME
92# define VSF_SPI_CFG_FUNCTION_RENAME ENABLED
93#endif
94
103#ifndef VSF_SPI_CFG_REIMPLEMENT_TYPE_MODE
104# define VSF_SPI_CFG_REIMPLEMENT_TYPE_MODE DISABLED
105#endif
106
116#ifndef VSF_SPI_CFG_REIMPLEMENT_TYPE_IRQ_MASK
117# define VSF_SPI_CFG_REIMPLEMENT_TYPE_IRQ_MASK DISABLED
118#endif
119
129#ifndef VSF_SPI_CFG_REIMPLEMENT_TYPE_STATUS
130# define VSF_SPI_CFG_REIMPLEMENT_TYPE_STATUS DISABLED
131#endif
132
145#ifndef VSF_SPI_CFG_REIMPLEMENT_TYPE_CFG
146# define VSF_SPI_CFG_REIMPLEMENT_TYPE_CFG DISABLED
147#endif
148
158#ifndef VSF_SPI_CFG_REIMPLEMENT_TYPE_CTRL
159# define VSF_SPI_CFG_REIMPLEMENT_TYPE_CTRL DISABLED
160#endif
161
172#ifndef VSF_SPI_CFG_REIMPLEMENT_TYPE_CAPABILITY
173# define VSF_SPI_CFG_REIMPLEMENT_TYPE_CAPABILITY DISABLED
174#endif
175
185#ifndef VSF_SPI_CFG_REIMPLEMENT_MODE_TO_DATA_BITS
186# define VSF_SPI_CFG_REIMPLEMENT_MODE_TO_DATA_BITS DISABLED
187#endif
188
198#ifndef VSF_SPI_CFG_REIMPLEMENT_DATA_BITS_TO_MODE
199# define VSF_SPI_CFG_REIMPLEMENT_DATA_BITS_TO_MODE DISABLED
200#endif
201
211#ifndef VSF_SPI_CFG_REIMPLEMENT_MODE_TO_BYTES
212# define VSF_SPI_CFG_REIMPLEMENT_MODE_TO_BYTES DISABLED
213#endif
214
224#ifndef VSF_SPI_CFG_INHERIT_HAL_CAPABILITY
225# define VSF_SPI_CFG_INHERIT_HAL_CAPABILITY ENABLED
226#endif
227
259#ifndef __VSF_SPI_CFG_SUPPORT_STANDARD_OPTIONAL
260# define __VSF_SPI_CFG_SUPPORT_STANDARD_OPTIONAL DISABLED
261#endif
262
263/*============================ MACROFIED FUNCTIONS ===========================*/
264
273#define VSF_SPI_APIS(__prefix_name) \
274 __VSF_HAL_TEMPLATE_API(__prefix_name, vsf_err_t, spi, init, VSF_MCONNECT(__prefix_name, _t) *spi_ptr, vsf_spi_cfg_t *cfg_ptr) \
275 __VSF_HAL_TEMPLATE_API(__prefix_name, void, spi, fini, VSF_MCONNECT(__prefix_name, _t) *spi_ptr) \
276 __VSF_HAL_TEMPLATE_API(__prefix_name, vsf_err_t, spi, get_configuration, VSF_MCONNECT(__prefix_name, _t) *spi_ptr, vsf_spi_cfg_t *cfg_ptr) \
277 __VSF_HAL_TEMPLATE_API(__prefix_name, fsm_rt_t, spi, enable, VSF_MCONNECT(__prefix_name, _t) *spi_ptr) \
278 __VSF_HAL_TEMPLATE_API(__prefix_name, fsm_rt_t, spi, disable, VSF_MCONNECT(__prefix_name, _t) *spi_ptr) \
279 __VSF_HAL_TEMPLATE_API(__prefix_name, void, spi, irq_enable, VSF_MCONNECT(__prefix_name, _t) *spi_ptr, vsf_spi_irq_mask_t irq_mask) \
280 __VSF_HAL_TEMPLATE_API(__prefix_name, void, spi, irq_disable, VSF_MCONNECT(__prefix_name, _t) *spi_ptr, vsf_spi_irq_mask_t irq_mask) \
281 __VSF_HAL_TEMPLATE_API(__prefix_name, vsf_spi_irq_mask_t, spi, irq_clear, VSF_MCONNECT(__prefix_name, _t) *spi_ptr, vsf_spi_irq_mask_t irq_mask) \
282 __VSF_HAL_TEMPLATE_API(__prefix_name, vsf_spi_status_t, spi, status, VSF_MCONNECT(__prefix_name, _t) *spi_ptr) \
283 __VSF_HAL_TEMPLATE_API(__prefix_name, vsf_spi_capability_t, spi, capability, VSF_MCONNECT(__prefix_name, _t) *spi_ptr) \
284 __VSF_HAL_TEMPLATE_API(__prefix_name, vsf_err_t, spi, cs_active, VSF_MCONNECT(__prefix_name, _t) *spi_ptr, uint_fast8_t index) \
285 __VSF_HAL_TEMPLATE_API(__prefix_name, vsf_err_t, spi, cs_inactive, VSF_MCONNECT(__prefix_name, _t) *spi_ptr, uint_fast8_t index) \
286 __VSF_HAL_TEMPLATE_API(__prefix_name, void, spi, fifo_transfer, VSF_MCONNECT(__prefix_name, _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) \
287 __VSF_HAL_TEMPLATE_API(__prefix_name, vsf_err_t, spi, request_transfer, VSF_MCONNECT(__prefix_name, _t) *spi_ptr, void *out_buffer_ptr, void *in_buffer_ptr, uint_fast32_t count) \
288 __VSF_HAL_TEMPLATE_API(__prefix_name, vsf_err_t, spi, cancel_transfer, VSF_MCONNECT(__prefix_name, _t) *spi_ptr) \
289 __VSF_HAL_TEMPLATE_API(__prefix_name, void, spi, get_transferred_count, VSF_MCONNECT(__prefix_name, _t) *spi_ptr, uint_fast32_t * sent_count, uint_fast32_t *received_count) \
290 __VSF_HAL_TEMPLATE_API(__prefix_name, vsf_err_t, spi, ctrl, VSF_MCONNECT(__prefix_name, _t) *spi_ptr, vsf_spi_ctrl_t ctrl, void* param)
291
292
293/*============================ TYPES =========================================*/
294
295#if VSF_SPI_CFG_REIMPLEMENT_TYPE_MODE == DISABLED
359typedef enum vsf_spi_mode_t {
360 // Direction control (bit 0)
361 VSF_SPI_MASTER = 0x00ul << 0,
362 VSF_SPI_SLAVE = 0x01ul << 0,
363
364 // Bit order control (bit 1)
365 VSF_SPI_MSB_FIRST = 0x00ul << 1,
366 VSF_SPI_LSB_FIRST = 0x01ul << 1,
367
368 // SPI mode (bits 2-3: CPOL and CPHA)
369 VSF_SPI_MODE_0 = 0x00ul << 2,
370 VSF_SPI_MODE_1 = 0x01ul << 2,
371 VSF_SPI_MODE_2 = 0x02ul << 2,
372 VSF_SPI_MODE_3 = 0x03ul << 2,
373
374 // Chip select control (bit 4)
375 // \~english Software controlled chip select. The user must manually call vsf_spi_cs_active() and vsf_spi_cs_inactive() to control the CS line.
376 // \~chinese 软件控制片选。用户必须手动调用 vsf_spi_cs_active() 和 vsf_spi_cs_inactive() 来控制片选线。
378 // \~english Hardware controlled chip select. The hardware automatically controls the CS line specified by `auto_cs_index` during a transfer.
379 // \~chinese 硬件控制片选。硬件在传输期间自动控制由 `auto_cs_index` 指定的片选线。
381
382 // Data size control (bits 8-15)
383 // \~english Buffer size requirements: 4-8 bits = 1 byte, 9-16 bits = 2 bytes, 17-32 bits = 4 bytes
384 // \~chinese 缓冲区大小要求:4-8 位 = 1 字节,9-16 位 = 2 字节,17-32 位 = 4 字节
385 VSF_SPI_DATASIZE_8 = 0x00ul << 8,
386 VSF_SPI_DATASIZE_16 = 0x01ul << 8,
387 VSF_SPI_DATASIZE_32 = 0x02ul << 8,
388
397#if __VSF_SPI_CFG_SUPPORT_STANDARD_OPTIONAL
398 // Clock polarity control (bit 2)
399 VSF_SPI_CPOL_LOW = 0x00ul << 2,
400# define VSF_SPI_CPOL_LOW VSF_SPI_CPOL_LOW
401 VSF_SPI_CPOL_HIGH = 0x01ul << 2,
402# define VSF_SPI_CPOL_HIGH VSF_SPI_CPOL_HIGH
403
404 // Clock phase control (bit 3)
405 VSF_SPI_CPHA_LOW = 0x00ul << 3,
406# define VSF_SPI_CPHA_LOW VSF_SPI_CPHA_LOW
407 VSF_SPI_CPHA_HIGH = 0x01ul << 3,
408# define VSF_SPI_CPHA_HIGH VSF_SPI_CPHA_HIGH
409#endif
410
419#if __VSF_SPI_CFG_SUPPORT_STANDARD_OPTIONAL
422 VSF_SPI_MOTOROLA_MODE = (0x00ul << 20),
424 VSF_SPI_TI_MODE = (0x01ul << 20),
425# define VSF_SPI_TI_MODE VSF_SPI_TI_MODE
426# define VSF_SPI_MOTOROLA_TI_MASK (VSF_SPI_MOTOROLA_MODE | VSF_SPI_TI_MODE)
427#endif
428
437#if __VSF_SPI_CFG_SUPPORT_STANDARD_OPTIONAL
439 // @brief Optional CRC calculation support for data integrity
440 // @note Hardware CRC calculation is platform-dependent
441 // @note When enabled, CRC is automatically calculated and verified
443 // @brief 可选的 CRC 数据完整性校验支持
444 // @note 硬件 CRC 计算依赖于平台
445 // @note 当使能时,CRC 将自动计算和验证
446 VSF_SPI_CRC_DISABLED = (0x00ul << 21),
448 VSF_SPI_CRC_ENABLED = (0x01ul << 21),
449# define VSF_SPI_CRC_ENABLED VSF_SPI_CRC_ENABLED
450# define VSF_SPI_CRC_MASK (VSF_SPI_CRC_DISABLED | VSF_SPI_CRC_ENABLED)
451#endif
452
461#if __VSF_SPI_CFG_SUPPORT_STANDARD_OPTIONAL
464 VSF_SPI_CLOCK_PRESCALER_2 = (0x00ul << 22),
465# define VSF_SPI_CLOCK_PRESCALER_2 VSF_SPI_CLOCK_PRESCALER_2
466 VSF_SPI_CLOCK_PRESCALER_4 = (0x01ul << 22),
467# define VSF_SPI_CLOCK_PRESCALER_4 VSF_SPI_CLOCK_PRESCALER_4
468 VSF_SPI_CLOCK_PRESCALER_8 = (0x02ul << 22),
469# define VSF_SPI_CLOCK_PRESCALER_8 VSF_SPI_CLOCK_PRESCALER_8
470 VSF_SPI_CLOCK_PRESCALER_16 = (0x03ul << 22),
471# define VSF_SPI_CLOCK_PRESCALER_16 VSF_SPI_CLOCK_PRESCALER_16
472 VSF_SPI_CLOCK_PRESCALER_32 = (0x04ul << 22),
473# define VSF_SPI_CLOCK_PRESCALER_32 VSF_SPI_CLOCK_PRESCALER_32
474 VSF_SPI_CLOCK_PRESCALER_64 = (0x05ul << 22),
475# define VSF_SPI_CLOCK_PRESCALER_64 VSF_SPI_CLOCK_PRESCALER_64
476 VSF_SPI_CLOCK_PRESCALER_128 = (0x06ul << 22),
477# define VSF_SPI_CLOCK_PRESCALER_128 VSF_SPI_CLOCK_PRESCALER_128
478 VSF_SPI_CLOCK_PRESCALER_256 = (0x07ul << 22),
479# define VSF_SPI_CLOCK_PRESCALER_256 VSF_SPI_CLOCK_PRESCALER_256
480# define VSF_SPI_CLOCK_PRESCALER_MASK ( VSF_SPI_CLOCK_PRESCALER_2 \
481 | VSF_SPI_CLOCK_PRESCALER_4 \
482 | VSF_SPI_CLOCK_PRESCALER_8 \
483 | VSF_SPI_CLOCK_PRESCALER_16 \
484 | VSF_SPI_CLOCK_PRESCALER_32 \
485 | VSF_SPI_CLOCK_PRESCALER_64 \
486 | VSF_SPI_CLOCK_PRESCALER_128 \
487 | VSF_SPI_CLOCK_PRESCALER_256)
488#endif
489
498#if __VSF_SPI_CFG_SUPPORT_STANDARD_OPTIONAL
501 VSF_SPI_DATALINE_2_LINE_FULL_DUPLEX = (0x00ul << 16), // MOSI+MISO, full-duplex, standard spi
503 VSF_SPI_DATALINE_2_LINE_RX_ONLY = (0x01ul << 16), // MOSI+MISO, but rx only (MISO)
504# define VSF_SPI_DATALINE_2_LINE_RX_ONLY VSF_SPI_DATALINE_2_LINE_RX_ONLY
505 VSF_SPI_DATALINE_2_LINE_TX_ONLY = (0x02ul << 16), // MOSI+MISO, but tx only (MOSI)
506# define VSF_SPI_DATALINE_2_LINE_TX_ONLY VSF_SPI_DATALINE_2_LINE_TX_ONLY
507 VSF_SPI_DATALINE_1_LINE_HALF_DUPLEX = (0x03ul << 16), // 1 line (MOSI or MISO), half-duplex
508# define VSF_SPI_DATALINE_1_LINE_HALF_DUPLEX VSF_SPI_DATALINE_1_LINE_HALF_DUPLEX
509 VSF_SPI_DATALINE_2_LINE_HALF_DUPLEX = (0x04ul << 16), // 2 line (MOSI+MISO), half-duplex, dual spi
510# define VSF_SPI_DATALINE_2_LINE_HALF_DUPLEX VSF_SPI_DATALINE_2_LINE_HALF_DUPLEX
511 VSF_SPI_DATALINE_4_LINE_HALF_DUPLEX = (0x05ul << 16), // 4 line (IO0+IO1+IO2+IO3), half-duplex, quad spi
512# define VSF_SPI_DATALINE_4_LINE_HALF_DUPLEX VSF_SPI_DATALINE_4_LINE_HALF_DUPLEX
513 VSF_SPI_DATALINE_8_LINE_HALF_DUPLEX = (0x06ul << 16), // 8 line (IO0+IO1+IO2+IO3+IO4+IO5+IO6+IO7), half-duplex, octal spi
514# define VSF_SPI_DATALINE_8_LINE_HALF_DUPLEX VSF_SPI_DATALINE_8_LINE_HALF_DUPLEX
515 VSF_SPI_DATALINE_16_LINE_HALF_DUPLEX = (0x07ul << 16), // 16 line (IO0+IO1+IO2+IO3+IO4+IO5+IO6+IO7+IO8+IO9+IO10+IO11+IO12+IO13+IO14+IO15), half-duplex, hexadeca spi
516# define VSF_SPI_DATALINE_16_LINE_HALF_DUPLEX VSF_SPI_DATALINE_16_LINE_HALF_DUPLEX
517# define VSF_SPI_DATALINE_MASK ( VSF_SPI_DATALINE_2_LINE_FULL_DUPLEX \
518 | VSF_SPI_DATALINE_1_LINE_HALF_DUPLEX \
519 | VSF_SPI_DATALINE_2_LINE_HALF_DUPLEX \
520 | VSF_SPI_DATALINE_4_LINE_HALF_DUPLEX \
521 | VSF_SPI_DATALINE_8_LINE_HALF_DUPLEX \
522 | VSF_SPI_DATALINE_16_LINE_HALF_DUPLEX)
523#endif
525#endif
526
533enum {
544
555
568
573#ifndef VSF_SPI_CS_MODE_MASK
580#ifdef VSF_SPI_CS_HARDWARE_INPUT_MODE
581 | VSF_SPI_CS_HARDWARE_INPUT_MODE
582#endif
584#endif
585
590#ifndef VSF_SPI_DATASIZE_MASK
594#endif
595
596#ifndef VSF_SPI_MODE_ALL_BITS_MASK
606#ifdef VSF_SPI_DATALINE_MASK
607 | VSF_SPI_DATALINE_MASK
608#endif
609#ifdef VSF_SPI_MOTOROLA_TI_MASK
611#endif
612#ifdef VSF_SPI_CRC_MASK
613 | VSF_SPI_CRC_MASK
614#endif
615#ifdef VSF_SPI_CLOCK_PRESCALER_MASK
616 | VSF_SPI_CLOCK_PRESCALER_MASK
617#endif
618#endif
620
621#if VSF_SPI_CFG_REIMPLEMENT_TYPE_IRQ_MASK == DISABLED
633typedef enum vsf_spi_irq_mask_t {
634 VSF_SPI_IRQ_MASK_TX = 0x01ul << 0,
635 VSF_SPI_IRQ_MASK_RX = 0x01ul << 1,
639
653 // VSF_SPI_IRQ_MASK_CRC_ERR = 0x01ul << 5, //! \~english CRC error interrupt \~chinese CRC 错误中断
654
668 // VSF_SPI_IRQ_MASK_FRAME_ERR = 0x01ul << 6, //! \~english Frame error interrupt \~chinese 帧错误中断
670#endif
671
676enum {
679
685
686#ifndef VSF_SPI_IRQ_MASK_ERR
692#endif
693
694
695#ifndef VSF_SPI_IRQ_ALL_BITS_MASK
705#endif
706};
707
708#if VSF_SPI_CFG_REIMPLEMENT_TYPE_STATUS == DISABLED
719typedef struct vsf_spi_status_t {
720 union {
722 struct {
723 uint32_t is_busy : 1;
725 };
726 };
728#endif
729
730#if VSF_SPI_CFG_REIMPLEMENT_TYPE_CAPABILITY == DISABLED
752#endif
753
754#if VSF_SPI_CFG_REIMPLEMENT_TYPE_CFG == DISABLED
761typedef struct vsf_spi_t vsf_spi_t;
774typedef void vsf_spi_isr_handler_t(void *target_ptr,
775 vsf_spi_t *spi_ptr,
790
797typedef struct vsf_spi_cfg_t {
801 // \~english In hardware chip select mode (`VSF_SPI_CS_HARDWARE_MODE`), this specifies the hardware CS pin index (0 to cs_count-1) to be used for automatic chip select.
802 // \~chinese 在硬件片选模式 (`VSF_SPI_CS_HARDWARE_MODE`) 下,此成员指定用于自动片选的硬件 CS 引脚索引(0 到 cs_count-1)。在软件模式下,此成员被忽略。
805#endif
806
807
808#if VSF_SPI_CFG_REIMPLEMENT_TYPE_CTRL == DISABLED
842typedef enum vsf_spi_ctrl_t {
861
870#if __VSF_SPI_CFG_SUPPORT_STANDARD_OPTIONAL
873 VSF_SPI_CTRL_REQUEST_PAUSE = (0x1ul << 0),
874 VSF_SPI_CTRL_REQUEST_RESUME = (0x1ul << 1),
875# define VSF_SPI_CTRL_REQUEST_PAUSE VSF_SPI_CTRL_REQUEST_PAUSE
876# define VSF_SPI_CTRL_REQUEST_RESUME VSF_SPI_CTRL_REQUEST_RESUME
877#endif
878
887#if __VSF_SPI_CFG_SUPPORT_STANDARD_OPTIONAL
902
907 VSF_SPI_CTRL_QSPI_ENABLE = 0x00ul,
912 VSF_SPI_CTRL_QSPI_DISABLE = 0x01ul,
913# define VSF_SPI_CTRL_QSPI_ENABLE VSF_SPI_CTRL_QSPI_ENABLE
914# define VSF_SPI_CTRL_QSPI_DISABLE VSF_SPI_CTRL_QSPI_DISABLE
915
930
933 VSF_SPI_CTRL_QSPI_CMD_PHASE_ENABLE = 0x02ul,
936 VSF_SPI_CTRL_QSPI_CMD_PHASE_DISABLE = 0x03ul,
939 VSF_SPI_CTRL_QSPI_CMD_PHASE_SET_SIZE = 0x04ul,
942 VSF_SPI_CTRL_QSPI_CMD_PHASE_GET_SIZE = 0x05ul,
949 VSF_SPI_CTRL_QSPI_CMD_PHASE_SET_LINE_MODE = 0x06ul,
956 VSF_SPI_CTRL_QSPI_CMD_PHASE_GET_LINE_MODE = 0x07ul,
959 VSF_SPI_CTRL_QSPI_CMD_PHASE_SET_VALUE = 0x08ul,
962 VSF_SPI_CTRL_QSPI_CMD_PHASE_GET_VALUE = 0x09ul,
963# define VSF_SPI_CTRL_QSPI_CMD_PHASE_ENABLE VSF_SPI_CTRL_QSPI_CMD_PHASE_ENABLE
964# define VSF_SPI_CTRL_QSPI_CMD_PHASE_DISABLE VSF_SPI_CTRL_QSPI_CMD_PHASE_DISABLE
965# define VSF_SPI_CTRL_QSPI_CMD_PHASE_SET_SIZE VSF_SPI_CTRL_QSPI_CMD_PHASE_SET_SIZE
966# define VSF_SPI_CTRL_QSPI_CMD_PHASE_GET_SIZE VSF_SPI_CTRL_QSPI_CMD_PHASE_GET_SIZE
967# define VSF_SPI_CTRL_QSPI_CMD_PHASE_SET_LINE_MODE VSF_SPI_CTRL_QSPI_CMD_PHASE_SET_LINE_MODE
968# define VSF_SPI_CTRL_QSPI_CMD_PHASE_GET_LINE_MODE VSF_SPI_CTRL_QSPI_CMD_PHASE_GET_LINE_MODE
969# define VSF_SPI_CTRL_QSPI_CMD_PHASE_SET_VALUE VSF_SPI_CTRL_QSPI_CMD_PHASE_SET_VALUE
970# define VSF_SPI_CTRL_QSPI_CMD_PHASE_GET_VALUE VSF_SPI_CTRL_QSPI_CMD_PHASE_GET_VALUE
971
980
983 VSF_SPI_CTRL_QSPI_ADDRESS_PHASE_ENABLE = 0x0Aul,
986 VSF_SPI_CTRL_QSPI_ADDRESS_PHASE_DISABLE = 0x0Bul,
989 VSF_SPI_CTRL_QSPI_ADDRESS_PHASE_SET_SIZE = 0x0Cul,
992 VSF_SPI_CTRL_QSPI_ADDRESS_PHASE_GET_SIZE = 0x0Dul,
999 VSF_SPI_CTRL_QSPI_ADDRESS_PHASE_SET_LINE_MODE = 0x0Eul,
1000
1005 VSF_SPI_CTRL_QSPI_ADDRESS_PHASE_GET_LINE_MODE = 0x0Ful,
1008 VSF_SPI_CTRL_QSPI_ADDRESS_SET = 0x10ul,
1011 VSF_SPI_CTRL_QSPI_ADDRESS_GET = 0x11ul,
1012# define VSF_SPI_CTRL_QSPI_ADDRESS_PHASE_ENABLE VSF_SPI_CTRL_QSPI_ADDRESS_PHASE_ENABLE
1013# define VSF_SPI_CTRL_QSPI_ADDRESS_PHASE_DISABLE VSF_SPI_CTRL_QSPI_ADDRESS_PHASE_DISABLE
1014# define VSF_SPI_CTRL_QSPI_ADDRESS_PHASE_SET_SIZE VSF_SPI_CTRL_QSPI_ADDRESS_PHASE_SET_SIZE
1015# define VSF_SPI_CTRL_QSPI_ADDRESS_PHASE_GET_SIZE VSF_SPI_CTRL_QSPI_ADDRESS_PHASE_GET_SIZE
1016# define VSF_SPI_CTRL_QSPI_ADDRESS_PHASE_SET_LINE_MODE VSF_SPI_CTRL_QSPI_ADDRESS_PHASE_SET_LINE_MODE
1017# define VSF_SPI_CTRL_QSPI_ADDRESS_PHASE_GET_LINE_MODE VSF_SPI_CTRL_QSPI_ADDRESS_PHASE_GET_LINE_MODE
1018# define VSF_SPI_CTRL_QSPI_ADDRESS_SET VSF_SPI_CTRL_QSPI_ADDRESS_SET
1019# define VSF_SPI_CTRL_QSPI_ADDRESS_GET VSF_SPI_CTRL_QSPI_ADDRESS_GET
1020
1029
1032 VSF_SPI_CTRL_QSPI_DUMMY_PHASE_ENABLE = 0x18ul,
1035 VSF_SPI_CTRL_QSPI_DUMMY_PHASE_DISABLE = 0x19ul,
1038 VSF_SPI_CTRL_QSPI_DUMMY_PHASE_SET_CYCLES = 0x1Aul,
1041 VSF_SPI_CTRL_QSPI_DUMMY_PHASE_GET_CYCLES = 0x1Bul,
1042# define VSF_SPI_CTRL_QSPI_DUMMY_PHASE_ENABLE VSF_SPI_CTRL_QSPI_DUMMY_PHASE_ENABLE
1043# define VSF_SPI_CTRL_QSPI_DUMMY_PHASE_DISABLE VSF_SPI_CTRL_QSPI_DUMMY_PHASE_DISABLE
1044# define VSF_SPI_CTRL_QSPI_DUMMY_PHASE_SET_CYCLES VSF_SPI_CTRL_QSPI_DUMMY_PHASE_SET_CYCLES
1045# define VSF_SPI_CTRL_QSPI_DUMMY_PHASE_GET_CYCLES VSF_SPI_CTRL_QSPI_DUMMY_PHASE_GET_CYCLES
1046
1059
1062 VSF_SPI_CTRL_QSPI_DATA_PHASE_ENABLE = 0x12ul,
1065 VSF_SPI_CTRL_QSPI_DATA_PHASE_DISABLE = 0x13ul,
1068 VSF_SPI_CTRL_QSPI_DATA_PHASE_SET_SIZE = 0x14ul,
1071 VSF_SPI_CTRL_QSPI_DATA_PHASE_GET_SIZE = 0x15ul,
1072
1079 VSF_SPI_CTRL_QSPI_DATA_PHASE_SET_LINE_MODE = 0x16ul,
1080
1087 VSF_SPI_CTRL_QSPI_DATA_PHASE_GET_LINE_MODE = 0x17ul,
1088# define VSF_SPI_CTRL_QSPI_DATA_PHASE_ENABLE VSF_SPI_CTRL_QSPI_DATA_PHASE_ENABLE
1089# define VSF_SPI_CTRL_QSPI_DATA_PHASE_DISABLE VSF_SPI_CTRL_QSPI_DATA_PHASE_DISABLE
1090# define VSF_SPI_CTRL_QSPI_DATA_PHASE_SET_SIZE VSF_SPI_CTRL_QSPI_DATA_PHASE_SET_SIZE
1091# define VSF_SPI_CTRL_QSPI_DATA_PHASE_GET_SIZE VSF_SPI_CTRL_QSPI_DATA_PHASE_GET_SIZE
1092# define VSF_SPI_CTRL_QSPI_DATA_PHASE_SET_LINE_MODE VSF_SPI_CTRL_QSPI_DATA_PHASE_SET_LINE_MODE
1093# define VSF_SPI_CTRL_QSPI_DATA_PHASE_GET_LINE_MODE VSF_SPI_CTRL_QSPI_DATA_PHASE_GET_LINE_MODE
1094
1099 VSF_SPI_CTRL_QSPI_TRANSFER_SET_MODE = 0x1Cul,
1102 VSF_SPI_CTRL_QSPI_TRANSFER_GET_MODE = 0x1Dul,
1103# define VSF_SPI_CTRL_QSPI_TRANSFER_SET_MODE VSF_SPI_CTRL_QSPI_TRANSFER_SET_MODE
1104# define VSF_SPI_CTRL_QSPI_TRANSFER_GET_MODE VSF_SPI_CTRL_QSPI_TRANSFER_GET_MODE
1105#endif
1107#endif
1108
1115typedef struct vsf_spi_op_t {
1117# undef __VSF_HAL_TEMPLATE_API
1118# define __VSF_HAL_TEMPLATE_API VSF_HAL_TEMPLATE_API_FP
1120
1123
1124#if VSF_SPI_CFG_MULTI_CLASS == ENABLED
1133};
1134#endif
1135
1136/*============================ PROTOTYPES ====================================*/
1137
1154extern vsf_err_t vsf_spi_init(vsf_spi_t *spi_ptr, vsf_spi_cfg_t *cfg_ptr);
1155
1168extern void vsf_spi_fini(vsf_spi_t *spi_ptr);
1169
1188
1201extern fsm_rt_t vsf_spi_enable(vsf_spi_t *spi_ptr);
1202
1215extern fsm_rt_t vsf_spi_disable(vsf_spi_t *spi_ptr);
1216
1232
1246
1273
1289extern vsf_err_t vsf_spi_cs_active(vsf_spi_t *spi_ptr, uint_fast8_t index);
1290
1306extern vsf_err_t vsf_spi_cs_inactive(vsf_spi_t *spi_ptr, uint_fast8_t index);
1307
1321
1335
1387extern void vsf_spi_fifo_transfer(vsf_spi_t *spi_ptr,
1388 void *out_buffer_ptr, uint_fast32_t* out_offset_ptr,
1389 void *in_buffer_ptr, uint_fast32_t* in_offset_ptr,
1390 uint_fast32_t count);
1391
1438extern vsf_err_t vsf_spi_request_transfer(vsf_spi_t *spi_ptr, void *out_buffer_ptr,
1439 void *in_buffer_ptr, uint_fast32_t count);
1440
1454
1473extern void vsf_spi_get_transferred_count(vsf_spi_t *spi_ptr, uint_fast32_t *sent_count, uint_fast32_t *received_count);
1474
1497extern vsf_err_t vsf_spi_ctrl(vsf_spi_t *spi_ptr, vsf_spi_ctrl_t ctrl, void *param);
1498
1499
1500/*============================ INLINE FUNCTIONS ==============================*/
1501
1502#if VSF_SPI_CFG_REIMPLEMENT_MODE_TO_DATA_BITS == DISABLED
1517# if defined(VSF_SPI_DATASIZE_BIT_OFFSET) && defined(VSF_SPI_DATASIZE_VALUE_OFFSET)
1518static inline uint8_t vsf_spi_mode_to_data_bits(vsf_spi_mode_t mode)
1519{
1521 return bits + VSF_SPI_DATASIZE_VALUE_OFFSET;
1522}
1523# else
1524static inline uint8_t vsf_spi_mode_to_data_bits(vsf_spi_mode_t mode)
1525{
1527 switch(m) {
1528#ifdef VSF_SPI_DATASIZE_4
1529 case VSF_SPI_DATASIZE_4:
1530 return 4;
1531#endif
1532#ifdef VSF_SPI_DATASIZE_5
1533 case VSF_SPI_DATASIZE_5:
1534 return 5;
1535#endif
1536#ifdef VSF_SPI_DATASIZE_6
1537 case VSF_SPI_DATASIZE_6:
1538 return 6;
1539#endif
1540#ifdef VSF_SPI_DATASIZE_7
1541 case VSF_SPI_DATASIZE_7:
1542 return 7;
1543#endif
1544 case VSF_SPI_DATASIZE_8:
1545 return 8;
1546#ifdef VSF_SPI_DATASIZE_9
1547 case VSF_SPI_DATASIZE_9:
1548 return 9;
1549#endif
1550#ifdef VSF_SPI_DATASIZE_10
1552 return 10;
1553#endif
1554#ifdef VSF_SPI_DATASIZE_11
1556 return 11;
1557#endif
1558#ifdef VSF_SPI_DATASIZE_12
1560 return 12;
1561#endif
1562#ifdef VSF_SPI_DATASIZE_13
1564 return 13;
1565#endif
1566#ifdef VSF_SPI_DATASIZE_14
1568 return 14;
1569#endif
1570#ifdef VSF_SPI_DATASIZE_15
1572 return 15;
1573#endif
1574#ifdef VSF_SPI_DATASIZE_16
1576 return 16;
1577#endif
1578#ifdef VSF_SPI_DATASIZE_17
1580 return 17;
1581#endif
1582#ifdef VSF_SPI_DATASIZE_18
1584 return 18;
1585#endif
1586#ifdef VSF_SPI_DATASIZE_19
1588 return 19;
1589#endif
1590#ifdef VSF_SPI_DATASIZE_20
1592 return 20;
1593#endif
1594#ifdef VSF_SPI_DATASIZE_21
1596 return 21;
1597#endif
1598#ifdef VSF_SPI_DATASIZE_22
1600 return 22;
1601#endif
1602#ifdef VSF_SPI_DATASIZE_23
1604 return 23;
1605#endif
1606#ifdef VSF_SPI_DATASIZE_24
1608 return 24;
1609#endif
1610#ifdef VSF_SPI_DATASIZE_25
1612 return 25;
1613#endif
1614#ifdef VSF_SPI_DATASIZE_26
1616 return 26;
1617#endif
1618#ifdef VSF_SPI_DATASIZE_27
1620 return 27;
1621#endif
1622#ifdef VSF_SPI_DATASIZE_28
1624 return 28;
1625#endif
1626#ifdef VSF_SPI_DATASIZE_29
1628 return 29;
1629#endif
1630#ifdef VSF_SPI_DATASIZE_30
1632 return 30;
1633#endif
1634#ifdef VSF_SPI_DATASIZE_31
1636 return 31;
1637#endif
1638#ifdef VSF_SPI_DATASIZE_32
1640 return 32;
1641#endif
1642 default:
1643 return 0;
1644 }
1645}
1646# endif
1647#endif
1648
1649#if VSF_SPI_CFG_REIMPLEMENT_DATA_BITS_TO_MODE == DISABLED
1664# if defined(VSF_SPI_DATASIZE_BIT_OFFSET) && defined(VSF_SPI_DATASIZE_VALUE_OFFSET)
1665static inline vsf_spi_mode_t vsf_spi_data_bits_to_mode(uint8_t data_bits)
1666{
1668}
1669# else
1670static inline vsf_spi_mode_t vsf_spi_data_bits_to_mode(uint8_t data_bits)
1671{
1672 switch (data_bits) {
1673#ifdef VSF_SPI_DATASIZE_4
1674 case 4:
1675 return VSF_SPI_DATASIZE_4;
1676#endif
1677#ifdef VSF_SPI_DATASIZE_5
1678 case 5:
1679 return VSF_SPI_DATASIZE_5;
1680#endif
1681#ifdef VSF_SPI_DATASIZE_6
1682 case 6:
1683 return VSF_SPI_DATASIZE_6;
1684#endif
1685#ifdef VSF_SPI_DATASIZE_7
1686 case 7:
1687 return VSF_SPI_DATASIZE_7;
1688#endif
1689 case 8:
1690 return VSF_SPI_DATASIZE_8;
1691#ifdef VSF_SPI_DATASIZE_9
1692 case 9:
1693 return VSF_SPI_DATASIZE_9;
1694#endif
1695#ifdef VSF_SPI_DATASIZE_10
1696 case 10:
1697 return VSF_SPI_DATASIZE_10;
1698#endif
1699#ifdef VSF_SPI_DATASIZE_11
1700 case 11:
1701 return VSF_SPI_DATASIZE_11;
1702#endif
1703#ifdef VSF_SPI_DATASIZE_12
1704 case 12:
1705 return VSF_SPI_DATASIZE_12;
1706#endif
1707#ifdef VSF_SPI_DATASIZE_13
1708 case 13:
1709 return VSF_SPI_DATASIZE_13;
1710#endif
1711#ifdef VSF_SPI_DATASIZE_14
1712 case 14:
1713 return VSF_SPI_DATASIZE_14;
1714#endif
1715#ifdef VSF_SPI_DATASIZE_15
1716 case 15:
1717 return VSF_SPI_DATASIZE_15;
1718#endif
1719#ifdef VSF_SPI_DATASIZE_16
1720 case 16:
1721 return VSF_SPI_DATASIZE_16;
1722#endif
1723#ifdef VSF_SPI_DATASIZE_17
1724 case 17:
1725 return VSF_SPI_DATASIZE_17;
1726#endif
1727#ifdef VSF_SPI_DATASIZE_18
1728 case 18:
1729 return VSF_SPI_DATASIZE_18;
1730#endif
1731#ifdef VSF_SPI_DATASIZE_19
1732 case 19:
1733 return VSF_SPI_DATASIZE_19;
1734#endif
1735#ifdef VSF_SPI_DATASIZE_20
1736 case 20:
1737 return VSF_SPI_DATASIZE_20;
1738#endif
1739#ifdef VSF_SPI_DATASIZE_21
1740 case 21:
1741 return VSF_SPI_DATASIZE_21;
1742#endif
1743#ifdef VSF_SPI_DATASIZE_22
1744 case 22:
1745 return VSF_SPI_DATASIZE_22;
1746#endif
1747#ifdef VSF_SPI_DATASIZE_23
1748 case 23:
1749 return VSF_SPI_DATASIZE_23;
1750#endif
1751#ifdef VSF_SPI_DATASIZE_24
1752 case 24:
1753 return VSF_SPI_DATASIZE_24;
1754#endif
1755#ifdef VSF_SPI_DATASIZE_25
1756 case 25:
1757 return VSF_SPI_DATASIZE_25;
1758#endif
1759#ifdef VSF_SPI_DATASIZE_26
1760 case 26:
1761 return VSF_SPI_DATASIZE_26;
1762#endif
1763#ifdef VSF_SPI_DATASIZE_27
1764 case 27:
1765 return VSF_SPI_DATASIZE_27;
1766#endif
1767#ifdef VSF_SPI_DATASIZE_28
1768 case 28:
1769 return VSF_SPI_DATASIZE_28;
1770#endif
1771#ifdef VSF_SPI_DATASIZE_29
1772 case 29:
1773 return VSF_SPI_DATASIZE_29;
1774#endif
1775#ifdef VSF_SPI_DATASIZE_30
1776 case 30:
1777 return VSF_SPI_DATASIZE_30;
1778#endif
1779#ifdef VSF_SPI_DATASIZE_31
1780 case 31:
1781 return VSF_SPI_DATASIZE_31;
1782#endif
1783#ifdef VSF_SPI_DATASIZE_32
1784 case 32:
1785 return VSF_SPI_DATASIZE_32;
1786#endif
1787 default:
1788 return (vsf_spi_mode_t)0;
1789 }
1790}
1791# endif
1792#endif
1793
1794#if VSF_SPI_CFG_REIMPLEMENT_MODE_TO_BYTES == DISABLED
1809static inline uint8_t vsf_spi_mode_to_data_bytes(vsf_spi_mode_t mode)
1810{
1811 uint8_t bits = vsf_spi_mode_to_data_bits(mode);
1812 if (bits == 0) {
1813 return 0; // Error: invalid data bits
1814 } else if (bits <= 8) {
1815 return 1;
1816 } else if (bits <= 16) {
1817 return 2;
1818 } else {
1819 return 4;
1820 }
1821}
1822#endif
1823
1824/*============================ MACROFIED FUNCTIONS ===========================*/
1825
1827#if VSF_SPI_CFG_FUNCTION_RENAME == ENABLED
1828# define __vsf_spi_t VSF_MCONNECT(VSF_SPI_CFG_PREFIX, _spi_t)
1829# define vsf_spi_init(__SPI, ...) VSF_MCONNECT(VSF_SPI_CFG_PREFIX, _spi_init) ((__vsf_spi_t *)(__SPI), ##__VA_ARGS__)
1830# define vsf_spi_fini(__SPI) VSF_MCONNECT(VSF_SPI_CFG_PREFIX, _spi_fini) ((__vsf_spi_t *)(__SPI))
1831# define vsf_spi_get_configuration(__SPI, ...) VSF_MCONNECT(VSF_SPI_CFG_PREFIX, _spi_get_configuration) ((__vsf_spi_t *)(__SPI), ##__VA_ARGS__)
1832# define vsf_spi_enable(__SPI) VSF_MCONNECT(VSF_SPI_CFG_PREFIX, _spi_enable) ((__vsf_spi_t *)(__SPI))
1833# define vsf_spi_disable(__SPI) VSF_MCONNECT(VSF_SPI_CFG_PREFIX, _spi_disable) ((__vsf_spi_t *)(__SPI))
1834# define vsf_spi_irq_enable(__SPI, ...) VSF_MCONNECT(VSF_SPI_CFG_PREFIX, _spi_irq_enable) ((__vsf_spi_t *)(__SPI), ##__VA_ARGS__)
1835# define vsf_spi_irq_disable(__SPI, ...) VSF_MCONNECT(VSF_SPI_CFG_PREFIX, _spi_irq_disable) ((__vsf_spi_t *)(__SPI), ##__VA_ARGS__)
1836# define vsf_spi_irq_clear(__SPI, ...) VSF_MCONNECT(VSF_SPI_CFG_PREFIX, _spi_irq_clear) ((__vsf_spi_t *)(__SPI), ##__VA_ARGS__)
1837# define vsf_spi_status(__SPI) VSF_MCONNECT(VSF_SPI_CFG_PREFIX, _spi_status) ((__vsf_spi_t *)(__SPI))
1838# define vsf_spi_capability(__SPI) VSF_MCONNECT(VSF_SPI_CFG_PREFIX, _spi_capability) ((__vsf_spi_t *)(__SPI))
1839# define vsf_spi_cs_active(__SPI, ...) VSF_MCONNECT(VSF_SPI_CFG_PREFIX, _spi_cs_active) ((__vsf_spi_t *)(__SPI), ##__VA_ARGS__)
1840# define vsf_spi_cs_inactive(__SPI, ...) VSF_MCONNECT(VSF_SPI_CFG_PREFIX, _spi_cs_inactive) ((__vsf_spi_t *)(__SPI), ##__VA_ARGS__)
1841# define vsf_spi_fifo_transfer(__SPI, ...) VSF_MCONNECT(VSF_SPI_CFG_PREFIX, _spi_fifo_transfer) ((__vsf_spi_t *)(__SPI), ##__VA_ARGS__)
1842# define vsf_spi_request_transfer(__SPI, ...) VSF_MCONNECT(VSF_SPI_CFG_PREFIX, _spi_request_transfer) ((__vsf_spi_t *)(__SPI), ##__VA_ARGS__)
1843# define vsf_spi_cancel_transfer(__SPI) VSF_MCONNECT(VSF_SPI_CFG_PREFIX, _spi_cancel_transfer) ((__vsf_spi_t *)(__SPI))
1844# define vsf_spi_get_transferred_count(__SPI, ...) VSF_MCONNECT(VSF_SPI_CFG_PREFIX, _spi_get_transferred_count)((__vsf_spi_t *)(__SPI), ##__VA_ARGS__)
1845# define vsf_spi_ctrl(__SPI, ...) VSF_MCONNECT(VSF_SPI_CFG_PREFIX, _spi_ctrl) ((__vsf_spi_t *)(__SPI), ##__VA_ARGS__)
1846
1847# define vsf_qspi_t vsf_spi_t
1848# define vsf_qspi_mode_t vsf_spi_mode_t
1849# define vsf_qspi_irq_mask_t vsf_spi_irq_mask_t
1850# define vsf_qspi_status_t vsf_spi_status_t
1851# define vsf_qspi_capability_t vsf_spi_capability_t
1852# define vsf_qspi_isr_handler_t vsf_spi_isr_handler_t
1853# define vsf_qspi_isr_t vsf_spi_isr_t
1854# define vsf_qspi_cfg_t vsf_spi_cfg_t
1855# define vsf_qspi_ctrl_t vsf_spi_ctrl_t
1856
1871# define vsf_qspi_init(__SPI, __CFG_PTR) vsf_spi_init((__vsf_spi_t *)(__SPI), (__CFG_PTR))
1872
1885# define vsf_qspi_fini(__SPI) vsf_spi_fini((__vsf_spi_t *)(__SPI))
1886
1899# define vsf_qspi_enable(__SPI) vsf_spi_enable((__vsf_spi_t *)(__SPI))
1900
1913# define vsf_qspi_disable(__SPI) vsf_spi_disable((__vsf_spi_t *)(__SPI))
1914
1929# define vsf_qspi_irq_enable(__SPI, __IRQ_MASK) vsf_spi_irq_enable((__vsf_spi_t *)(__SPI), (__IRQ_MASK))
1930
1945# define vsf_qspi_irq_disable(__SPI, __IRQ_MASK) vsf_spi_irq_disable((__vsf_spi_t *)(__SPI), (__IRQ_MASK))
1946
1959# define vsf_qspi_status(__SPI) vsf_spi_status((__vsf_spi_t *)(__SPI))
1960
1973# define vsf_qspi_capability(__SPI) vsf_spi_capability((__vsf_spi_t *)(__SPI))
1974
1995# define vsf_qspi_fifo_write(__SPI, __OUT_BUFFER_PTR, __OUT_OFFSET_PTR, __COUNT) \
1996 vsf_spi_fifo_transfer((__vsf_spi_t *)(__SPI), (__OUT_BUFFER_PTR), (__OUT_OFFSET_PTR), NULL, NULL, (__COUNT))
1997
2018# define vsf_qspi_fifo_read(__SPI, __IN_BUFFER_PTR, __IN_OFFSET_PTR, __COUNT) \
2019 vsf_spi_fifo_transfer((__vsf_spi_t *)(__SPI), NULL, NULL, (__IN_BUFFER_PTR), (__IN_OFFSET_PTR), (__COUNT))
2020
2039# define vsf_qspi_request_tx(__SPI, __OUT_BUF, __CNT) vsf_spi_request_transfer((__vsf_spi_t *)(__SPI), (__OUT_BUF), NULL, (__CNT))
2040
2059# define vsf_qspi_request_rx(__SPI, __IN_BUF, __CNT) vsf_spi_request_transfer((__vsf_spi_t *)(__SPI), NULL, (__IN_BUF), (__CNT))
2060
2084# define vsf_qspi_cancel_transfer(__SPI) vsf_spi_cancel_transfer((__vsf_spi_t *)(__SPI))
2085
2102# define vsf_qspi_get_transferred_count(__SPI, __TX_CNT, __RX_CNT) \
2103 vsf_spi_get_transferred_count((__vsf_spi_t *)(__SPI), (__TX_CNT), (__RX_CNT))
2104
2121# define vsf_qspi_ctrl(__SPI, __CTRL, __PARAM) vsf_spi_ctrl((__vsf_spi_t *)(__SPI), (__CTRL), (__PARAM))
2122#endif
2124
2125#ifdef __cplusplus
2126}
2127#endif
2128
2129#endif /*__VSF_TEMPLATE_SPI_H__*/
2130
vsf_err_t
Definition __type.h:42
vsf_spi_mode_t
Definition spi.h:33
@ VSF_SPI_DATASIZE_31
Definition spi.h:72
@ VSF_SPI_DATASIZE_28
Definition spi.h:69
@ VSF_SPI_DATASIZE_6
Definition spi.h:103
@ VSF_SPI_DATASIZE_17
Definition spi.h:58
@ VSF_SPI_DATASIZE_9
Definition spi.h:50
@ VSF_SPI_DATASIZE_18
Definition spi.h:59
@ VSF_SPI_DATASIZE_11
Definition spi.h:52
@ VSF_SPI_DATASIZE_20
Definition spi.h:61
@ VSF_SPI_DATASIZE_21
Definition spi.h:62
@ VSF_SPI_DATASIZE_27
Definition spi.h:68
@ VSF_SPI_DATASIZE_14
Definition spi.h:55
@ VSF_SPI_DATASIZE_26
Definition spi.h:67
@ VSF_SPI_DATASIZE_13
Definition spi.h:54
@ VSF_SPI_DATASIZE_7
Definition spi.h:104
@ VSF_SPI_DATASIZE_5
Definition spi.h:102
@ VSF_SPI_DATASIZE_12
Definition spi.h:53
@ VSF_SPI_DATASIZE_22
Definition spi.h:63
@ VSF_SPI_DATASIZE_24
Definition spi.h:65
@ VSF_SPI_DATASIZE_4
datasize is 8 bits
Definition spi.h:101
@ VSF_SPI_DATASIZE_29
Definition spi.h:70
@ VSF_SPI_DATASIZE_25
Definition spi.h:66
@ VSF_SPI_DATASIZE_30
Definition spi.h:71
@ VSF_SPI_DATASIZE_19
Definition spi.h:60
@ VSF_SPI_DATASIZE_23
Definition spi.h:64
@ VSF_SPI_DATASIZE_10
Definition spi.h:51
@ VSF_SPI_DATASIZE_15
Definition spi.h:56
#define VSF_SPI_CPOL_HIGH
Definition spi.h:123
vsf_spi_irq_mask_t
Definition spi.h:159
#define VSF_SPI_TI_MODE
Definition spi.h:95
#define VSF_SPI_CPHA_HIGH
Definition spi.h:128
#define VSF_SPI_DATALINE_2_LINE_FULL_DUPLEX
Definition spi.h:110
@ VSF_SPI_CRC_ENABLED
Definition spi.h:116
@ VSF_SPI_CRC_DISABLED
Definition spi.h:115
#define VSF_SPI_DATALINE_1_LINE_HALF_DUPLEX
Definition spi.h:112
#define VSF_SPI_DATALINE_2_LINE_RX_ONLY
Definition spi.h:111
#define VSF_SPI_CPHA_LOW
Definition spi.h:126
#define VSF_SPI_CPOL_LOW
Definition spi.h:121
#define VSF_SPI_MOTOROLA_MODE
Definition spi.h:94
#define VSF_SPI_MOTOROLA_TI_MASK
Definition spi.h:96
vsf_arch_prio_t
Definition cortex_a_generic.h:85
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 uint32_t
Definition stdint.h:9
unsigned int uint_fast32_t
Definition stdint.h:27
unsigned char uint8_t
Definition stdint.h:5
Definition vsf_template_hal_driver.h:204
Definition vsf_template_hal_driver.h:197
Predefined VSF SPI capability that can be reimplemented in specific HAL drivers. Even if the hardware...
Definition vsf_template_spi.h:739
uint8_t support_software_cs
Hardware chip select support (1: supported, 0: not supported)
Definition vsf_template_spi.h:746
uint32_t max_clock_hz
Number of available chip select lines (0-63)
Definition vsf_template_spi.h:749
uint8_t cs_count
Software chip select support (1: supported, 0: not supported)
Definition vsf_template_spi.h:747
vsf_spi_irq_mask_t irq_mask
Definition spi.h:137
uint8_t support_hardware_cs
Supported interrupt masks for SPI operations.
Definition vsf_template_spi.h:745
uint32_t min_clock_hz
Maximum supported SPI clock frequency in Hz.
Definition vsf_template_spi.h:750
inherit(vsf_peripheral_capability_t) vsf_spi_irq_mask_t irq_mask
Inherit peripheral capabilities.
Configuration structure for SPI.
Definition vsf_template_spi.h:797
uint32_t clock_hz
SPI operating mode (master/slave, CPOL/CPHA, bit order, data size)
Definition vsf_template_spi.h:799
vsf_spi_isr_t isr
SPI clock frequency in Hz (must be between min_clock_hz and max_clock_hz)
Definition vsf_template_spi.h:800
vsf_spi_mode_t mode
Definition vsf_template_spi.h:798
uint8_t auto_cs_index
Interrupt configuration (handler, target pointer, priority)
Definition vsf_template_spi.h:803
SPI interrupt service routine configuration structure.
Definition vsf_template_spi.h:785
vsf_spi_isr_handler_t * handler_fn
Definition vsf_template_spi.h:786
void * target_ptr
Interrupt handler function (NULL to disable interrupts)
Definition vsf_template_spi.h:787
vsf_arch_prio_t prio
User context pointer passed to handler.
Definition vsf_template_spi.h:788
SPI operation function pointer type, used for SPI Multi Class support.
Definition vsf_template_spi.h:1115
Predefined VSF SPI status that can be reimplemented in specific HAL drivers. Even if the hardware doe...
Definition vsf_template_spi.h:719
uint32_t is_busy
Definition spi.h:127
SPI instance structure, used for SPI Multi Class support, not needed in non Multi Class mode.
Definition vsf_template_spi.h:1131
const vsf_spi_op_t * op
Definition vsf_template_spi.h:1132
vsf_spi_irq_mask_t
Definition spi.h:148
vsf_spi_mode_t
Definition spi.h:119
#define VSF_SPI_DATASIZE_BIT_OFFSET
Definition spi.h:224
#define VSF_SPI_DATASIZE_VALUE_OFFSET
Definition spi.h:227
fsm_rt_t
Definition vsf_fsm.h:315
vsf_spi_t vsf_spi[SPI_COUNT]
Definition vsf_spi.c:3
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.
Definition spi_common.c:137
struct vsf_spi_isr_t vsf_spi_isr_t
SPI interrupt service routine configuration structure.
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.
Definition vsf_template_spi.h:774
@ VSF_SPI_IRQ_MASK_CPL
Alias for VSF_SPI_IRQ_MASK_RX.
Definition vsf_template_spi.h:684
@ VSF_SPI_IRQ_MASK_TX_FIFO_THRESHOLD
Definition vsf_template_spi.h:677
@ VSF_SPI_IRQ_ALL_BITS_MASK
Definition vsf_template_spi.h:700
@ VSF_SPI_IRQ_MASK_RX_FIFO_THRESHOLD
Alias for VSF_SPI_IRQ_MASK_TX.
Definition vsf_template_spi.h:678
@ VSF_SPI_IRQ_MASK_ERR
Definition vsf_template_spi.h:691
vsf_spi_status_t vsf_spi_status(vsf_spi_t *spi_ptr)
Get the current status of a SPI instance.
Definition spi_common.c:110
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.
Definition spi_common.c:149
struct vsf_spi_cfg_t vsf_spi_cfg_t
Configuration structure for SPI.
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...
#define VSF_SPI_APIS(__prefix_name)
SPI API template, used to generate SPI type, specific prefix function declarations,...
Definition vsf_template_spi.h:273
vsf_err_t vsf_spi_get_configuration(vsf_spi_t *spi_ptr, vsf_spi_cfg_t *cfg_ptr)
Get current configuration of a SPI instance.
Definition spi_common.c:55
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.
Definition spi_common.c:169
vsf_err_t vsf_spi_cs_active(vsf_spi_t *spi_ptr, uint_fast8_t index)
Activate (assert) a SPI chip select line.
Definition spi_common.c:119
vsf_spi_irq_mask_t
Predefined VSF SPI interrupt masks that can be reimplemented in specific HAL drivers....
Definition vsf_template_spi.h:633
@ VSF_SPI_IRQ_MASK_RX_OVERFLOW_ERR
RX complete interrupt (triggers when RX transfer is complete)
Definition vsf_template_spi.h:638
@ VSF_SPI_IRQ_MASK_RX_CPL
TX complete interrupt (triggers when all TX data has been sent)
Definition vsf_template_spi.h:637
@ VSF_SPI_IRQ_MASK_RX
TX FIFO threshold interrupt (triggers when TX FIFO level is below threshold)
Definition vsf_template_spi.h:635
@ VSF_SPI_IRQ_MASK_TX
Definition vsf_template_spi.h:634
@ VSF_SPI_IRQ_MASK_TX_CPL
RX FIFO threshold interrupt (triggers when RX FIFO level is above threshold)
Definition vsf_template_spi.h:636
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.
Definition spi_common.c:188
fsm_rt_t vsf_spi_enable(vsf_spi_t *spi_ptr)
Enable a SPI instance for operation.
Definition spi_common.c:65
vsf_spi_irq_mask_t vsf_spi_irq_clear(vsf_spi_t *spi_ptr, vsf_spi_irq_mask_t irq_mask)
Clear interrupt flags of SPI instance and return previous state.
Definition spi_common.c:101
fsm_rt_t vsf_spi_disable(vsf_spi_t *spi_ptr)
Disable a SPI instance from operation.
Definition spi_common.c:74
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 doe...
vsf_spi_mode_t
Predefined VSF SPI modes that can be reimplemented in specific HAL drivers.
Definition vsf_template_spi.h:359
@ VSF_SPI_SLAVE
Master mode (controller)
Definition vsf_template_spi.h:362
@ VSF_SPI_DATASIZE_16
8-bit data transfer size (requires 1-byte buffer)
Definition vsf_template_spi.h:386
@ VSF_SPI_LSB_FIRST
Most Significant Bit (MSB) first.
Definition vsf_template_spi.h:366
@ VSF_SPI_MODE_1
Mode 0: CPOL=0 (idle low), CPHA=0 (sample on first edge)
Definition vsf_template_spi.h:370
@ VSF_SPI_DATASIZE_8
Definition vsf_template_spi.h:385
@ VSF_SPI_MASTER
Definition vsf_template_spi.h:361
@ VSF_SPI_MSB_FIRST
Slave mode (peripheral)
Definition vsf_template_spi.h:365
@ VSF_SPI_DATASIZE_32
16-bit data transfer size (requires 2-byte buffer)
Definition vsf_template_spi.h:387
@ VSF_SPI_CS_SOFTWARE_MODE
Mode 3: CPOL=1 (idle high), CPHA=1 (sample on second edge)
Definition vsf_template_spi.h:377
@ VSF_SPI_MODE_0
Least Significant Bit (LSB) first.
Definition vsf_template_spi.h:369
@ VSF_SPI_CS_HARDWARE_MODE
Definition vsf_template_spi.h:380
@ VSF_SPI_MODE_3
Mode 2: CPOL=1 (idle high), CPHA=0 (sample on first edge)
Definition vsf_template_spi.h:372
@ VSF_SPI_MODE_2
Mode 1: CPOL=0 (idle low), CPHA=1 (sample on second edge)
Definition vsf_template_spi.h:371
struct vsf_spi_op_t vsf_spi_op_t
SPI operation function pointer type, used for SPI Multi Class support.
void vsf_spi_irq_disable(vsf_spi_t *spi_ptr, vsf_spi_irq_mask_t irq_mask)
Disable specific interrupts for a SPI instance.
Definition spi_common.c:92
vsf_spi_ctrl_t
Predefined VSF SPI control commands that can be reimplemented in specific HAL drivers.
Definition vsf_template_spi.h:842
@ __VSF_SPI_CTRL_DUMMY
Dummy value for compilation, required when no actual control commands are defined.
Definition vsf_template_spi.h:860
vsf_err_t vsf_spi_init(vsf_spi_t *spi_ptr, vsf_spi_cfg_t *cfg_ptr)
Initialize a SPI instance.
Definition spi_common.c:37
@ VSF_SPI_MODE_MASK
SPI mode mask for clock polarity and phase configuration.
Definition vsf_template_spi.h:564
@ VSF_SPI_BIT_ORDER_MASK
SPI bit order mask for MSB/LSB first selection.
Definition vsf_template_spi.h:553
@ VSF_SPI_DIR_MODE_MASK
SPI direction mode mask for master/slave selection.
Definition vsf_template_spi.h:542
@ VSF_SPI_CS_MODE_MASK
Definition vsf_template_spi.h:574
@ VSF_SPI_MODE_ALL_BITS_MASK
Definition vsf_template_spi.h:601
@ VSF_SPI_DATASIZE_MASK
Definition vsf_template_spi.h:591
void vsf_spi_irq_enable(vsf_spi_t *spi_ptr, vsf_spi_irq_mask_t irq_mask)
Enable specific interrupts for a SPI instance.
Definition spi_common.c:83
void vsf_spi_fini(vsf_spi_t *spi_ptr)
Finalize (deinitialize) a SPI instance.
Definition spi_common.c:46
vsf_err_t vsf_spi_cs_inactive(vsf_spi_t *spi_ptr, uint_fast8_t index)
Deactivate (deassert) a SPI chip select line.
Definition spi_common.c:128
vsf_err_t vsf_spi_cancel_transfer(vsf_spi_t *spi_ptr)
Cancel an ongoing SPI transfer operation.
Definition spi_common.c:160
vsf_spi_capability_t vsf_spi_capability(vsf_spi_t *spi_ptr)
Get the capabilities of a SPI instance.
Definition spi_common.c:179
Generated from commit: vsfteam/vsf@5de27dd