VSF Documented
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 __HAL_DRIVER_NATIONS_N32H76X_N32H78X_SPI_H__
19#define __HAL_DRIVER_NATIONS_N32H76X_N32H78X_SPI_H__
20
21/*============================ INCLUDES ======================================*/
22
23#include "hal/vsf_hal_cfg.h"
24
25#if VSF_HAL_USE_SPI == ENABLED
26
27// HW/IPCore
32// HW/IPCore end
33
34/*\note Refer to template/README.md for usage cases.
35 * For peripheral drivers, blackbox mode is recommended but not required, reimplementation part MUST be open.
36 * For IPCore drivers, class structure, MULTI_CLASS configuration, reimplementation and class APIs should be open to user.
37 * For emulated drivers, **** No reimplementation ****.
38 */
39
40/*\note Includes CAN ONLY be put here. */
41/*\note If current header is for a peripheral driver(hw driver), and inherit from an IPCore driver, include IPCore header here. */
42
43#ifdef __cplusplus
44extern "C" {
45#endif
46
47/*============================ MACROS ========================================*/
48
49/*\note VSF_${SPI_IP}_SPI_CFG_MULTI_CLASS should be implemented for IP drives and open to user,
50 * while VSF_HW_SPI_CFG_MULTI_CLASS should be in spi.c.
51 */
52
53// HW
54/*\note hw SPI driver can reimplement following types:
55 * To enable reimplementation, please enable macro below:
56 * VSF_SPI_CFG_REIMPLEMENT_TYPE_MODE for vsf_spi_mode_t
57 * VSF_SPI_CFG_REIMPLEMENT_TYPE_STATUS for vsf_spi_status_t
58 * VSF_SPI_CFG_REIMPLEMENT_TYPE_IRQ_MASK for vsf_spi_irq_mask_t
59 * VSF_SPI_CFG_REIMPLEMENT_TYPE_CTRL for vsf_spi_ctrl_t
60 * VSF_SPI_CFG_REIMPLEMENT_TYPE_CFG for vsf_spi_cfg_t
61 * VSF_SPI_CFG_REIMPLEMENT_TYPE_CAPABILITY for vsf_spi_capability_t
62 * Reimplementation is used for optimization hw/IPCore drivers, reimplement the bit mask according to hw registers.
63 * *** DO NOT reimplement these in emulated drivers. ***
64 */
65
66#define VSF_SPI_CFG_REIMPLEMENT_TYPE_MODE ENABLED
67#define VSF_SPI_CFG_REIMPLEMENT_TYPE_IRQ_MASK ENABLED
68#define VSF_SPI_CFG_REIMPLEMENT_TYPE_STATUS ENABLED
69#define VSF_SPI_CFG_REIMPLEMENT_TYPE_CTRL ENABLED
70#define VSF_SPI_CFG_REIMPLEMENT_TYPE_CFG ENABLED
71#define VSF_SPI_CFG_REIMPLEMENT_TYPE_CAPABILITY ENABLED
72// HW end
73
74/*============================ MACROFIED FUNCTIONS ===========================*/
75/*============================ TYPES =========================================*/
76
77// HW/IPCore, not for emulated drivers
78#if VSF_SPI_CFG_REIMPLEMENT_TYPE_MODE == ENABLED
79typedef enum vsf_spi_mode_t {
80 VSF_SPI_MASTER = 0x00ul << 0,
81 VSF_SPI_SLAVE = 0x01ul << 0,
82 VSF_SPI_MSB_FIRST = 0x00ul << 1,
83 VSF_SPI_LSB_FIRST = 0x01ul << 1,
84
85 // SPI mode (bits 2-3: CPOL and CPHA)
86 VSF_SPI_MODE_0 = 0x00ul << 2,
87 VSF_SPI_MODE_1 = 0x01ul << 2,
88 VSF_SPI_MODE_2 = 0x02ul << 2,
89 VSF_SPI_MODE_3 = 0x03ul << 2,
90
93 VSF_SPI_DATASIZE_8 = 0x00ul << 8,
94 VSF_SPI_DATASIZE_16 = 0x01ul << 8,
95 VSF_SPI_DATASIZE_32 = 0x02ul << 8,
96
97 // Standard Optional: only include these if hardware supports them
98 VSF_SPI_CPOL_LOW = 0x00ul << 2,
99 #define VSF_SPI_CPOL_LOW VSF_SPI_CPOL_LOW
100 VSF_SPI_CPOL_HIGH = 0x01ul << 2,
101 #define VSF_SPI_CPOL_HIGH VSF_SPI_CPOL_HIGH
102 VSF_SPI_CPHA_LOW = 0x00ul << 3,
103 #define VSF_SPI_CPHA_LOW VSF_SPI_CPHA_LOW
104 VSF_SPI_CPHA_HIGH = 0x01ul << 3,
105 #define VSF_SPI_CPHA_HIGH VSF_SPI_CPHA_HIGH
106
107 // more vendor specified modes can be added here
109#endif
110
111#if VSF_SPI_CFG_REIMPLEMENT_TYPE_IRQ_MASK == ENABLED
112typedef enum vsf_spi_irq_mask_t {
113 VSF_SPI_IRQ_MASK_TX = 0x01ul << 0,
114 VSF_SPI_IRQ_MASK_RX = 0x01ul << 1,
118
119 // more vendor specified irq_masks can be added here
121#endif
122
123#if VSF_SPI_CFG_REIMPLEMENT_TYPE_STATUS == ENABLED
124typedef struct vsf_spi_status_t {
125 union {
126 struct {
128 };
129 };
130
131 // more vendor specified status can be added here
133#endif
134
135#if VSF_SPI_CFG_REIMPLEMENT_TYPE_CAPABILITY == ENABLED
136typedef struct vsf_spi_capability_t {
140 uint8_t cs_count : 6;
143
144 // more vendor specified capability can be added here
146#endif
147
148#if VSF_SPI_CFG_REIMPLEMENT_TYPE_CFG == ENABLED
152typedef struct vsf_spi_t vsf_spi_t;
153typedef void vsf_spi_isr_handler_t(void *target_ptr,
154 vsf_spi_t *spi_ptr,
156typedef struct vsf_spi_isr_t {
158 void *target_ptr;
161typedef struct vsf_spi_cfg_t {
166
167 // more vendor specified cfg can be added here
169#endif
170
171#if VSF_SPI_CFG_REIMPLEMENT_TYPE_CTRL == ENABLED
172typedef enum vsf_spi_ctrl_t {
175#endif
176// HW/IPCore end
177
178/*============================ INCLUDES ======================================*/
179
180#ifdef __cplusplus
181}
182#endif
183
184#endif // VSF_HAL_USE_SPI
185#endif // __HAL_DRIVER_NATIONS_N32H76X_N32H78X_SPI_H__
186/* EOF */
vsf_spi_mode_t
Definition spi.h:33
@ VSF_SPI_SLAVE
Definition spi.h:34
@ VSF_SPI_DATASIZE_16
Definition spi.h:57
@ VSF_SPI_MODE_1
Definition spi.h:41
@ VSF_SPI_DATASIZE_8
datasize is 8 bits
Definition spi.h:49
@ VSF_SPI_MASTER
Definition spi.h:35
@ VSF_SPI_DATASIZE_32
Definition spi.h:73
@ VSF_SPI_MODE_0
Definition spi.h:39
@ VSF_SPI_MODE_3
Definition spi.h:45
@ VSF_SPI_MODE_2
Definition spi.h:43
vsf_spi_irq_mask_t
Definition spi.h:159
@ VSF_SPI_LSB_FIRST
Definition spi.h:78
@ VSF_SPI_MSB_FIRST
Definition spi.h:77
@ VSF_SPI_CS_SOFTWARE_MODE
Definition spi.h:87
@ VSF_SPI_CS_HARDWARE_MODE
Definition spi.h:89
struct vsf_spi_isr_t vsf_spi_isr_t
void vsf_spi_isr_handler_t(void *target_ptr, vsf_spi_t *spi_ptr, vsf_spi_irq_mask_t irq_mask)
Definition spi.h:153
struct vsf_spi_cfg_t vsf_spi_cfg_t
struct vsf_spi_capability_t vsf_spi_capability_t
#define VSF_SPI_CPOL_HIGH
Definition spi.h:101
@ VSF_SPI_IRQ_MASK_RX_OVERFLOW_ERR
Definition spi.h:117
@ VSF_SPI_IRQ_MASK_RX
Definition spi.h:114
@ VSF_SPI_IRQ_MASK_TX
Definition spi.h:113
#define VSF_SPI_CPHA_HIGH
Definition spi.h:105
struct vsf_spi_status_t vsf_spi_status_t
vsf_spi_mode_t
Definition spi.h:79
#define VSF_SPI_CPHA_LOW
Definition spi.h:103
vsf_spi_ctrl_t
Definition spi.h:172
@ __VSF_SPI_CTRL_DUMMY
Definition spi.h:173
#define VSF_SPI_CPOL_LOW
Definition spi.h:99
vsf_spi_irq_mask_t
Definition spi.h:41
@ VSF_SPI_IRQ_MASK_RX_CPL
Definition spi.h:43
@ VSF_SPI_IRQ_MASK_TX_CPL
Definition spi.h:42
vsf_arch_prio_t
Definition cortex_a_generic.h:88
const i_spi_t vsf_spi_irq_mask_t irq_mask
Definition spi_interface.h:38
unsigned uint32_t
Definition stdint.h:9
unsigned char uint8_t
Definition stdint.h:5
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
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
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
void vsf_spi_isr_handler_t(void *target_ptr, vsf_spi_t *spi_ptr, vsf_spi_irq_mask_t irq_mask)
Definition spi.h:189
vsf_spi_irq_mask_t
Definition spi.h:148
vsf_spi_ctrl_t
Predefined VSF SPI control commands that can be reimplemented in specific HAL drivers.
Definition vsf_template_spi.h:842
Generated from commit: vsfteam/vsf@b2e9e8a