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_${SERIES/SPI_IP}_SPI_H__
19#define __HAL_DRIVER_${SERIES/SPI_IP}_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#include "../../__device.h"
35
36/*\note Refer to template/README.md for usage cases.
37 * For peripheral drivers, blackbox mode is recommended but not required, reimplementation part MUST be open.
38 * For IPCore drivers, class structure, MULTI_CLASS configuration, reimplementation and class APIs should be open to user.
39 * For emulated drivers, **** No reimplementation ****.
40 */
41
42/*\note Includes CAN ONLY be put here. */
43/*\note If current header is for a peripheral driver(hw driver), and inherit from an IPCore driver, include IPCore header here. */
44
45// IPCore
46#if defined(__VSF_HAL_${SPI_IP}_SPI_CLASS_IMPLEMENT)
47# define __VSF_CLASS_IMPLEMENT__
48#elif defined(__VSF_HAL_${SPI_IP}_SPI_CLASS_INHERIT__)
49# define __VSF_CLASS_INHERIT__
50#endif
51
52#include "utilities/ooc_class.h"
53// IPCore end
54
55#ifdef __cplusplus
56extern "C" {
57#endif
58
59/*============================ MACROS ========================================*/
60
61/*\note VSF_${SPI_IP}_SPI_CFG_MULTI_CLASS should be implemented for IP drives and open to user,
62 * while VSF_HW_SPI_CFG_MULTI_CLASS should be in spi.c.
63 */
64
65// IPCore
66#ifndef VSF_${SPI_IP}_SPI_CFG_MULTI_CLASS
67# define VSF_${SPI_IP}_SPI_CFG_MULTI_CLASS VSF_SPI_CFG_MULTI_CLASS
68#endif
69// IPCore end
70
71// HW
72/*\note hw SPI driver can reimplement following types:
73 * To enable reimplementation, please enable macro below:
74 * VSF_SPI_CFG_REIMPLEMENT_TYPE_MODE for vsf_spi_mode_t
75 * VSF_SPI_CFG_REIMPLEMENT_TYPE_STATUS for vsf_spi_status_t
76 * VSF_SPI_CFG_REIMPLEMENT_TYPE_IRQ_MASK for vsf_spi_irq_mask_t
77 * VSF_SPI_CFG_REIMPLEMENT_TYPE_CTRL for vsf_spi_ctrl_t
78 * VSF_SPI_CFG_REIMPLEMENT_TYPE_CFG for vsf_spi_cfg_t
79 * VSF_SPI_CFG_REIMPLEMENT_TYPE_CAPABILITY for vsf_spi_capability_t
80 * Reimplementation is used for optimization hw/IPCore drivers, reimplement the bit mask according to hw registers.
81 * *** DO NOT reimplement these in emulated drivers. ***
82 */
83
84#define VSF_SPI_CFG_REIMPLEMENT_TYPE_MODE ENABLED
85#define VSF_SPI_CFG_REIMPLEMENT_TYPE_IRQ_MASK ENABLED
86#define VSF_SPI_CFG_REIMPLEMENT_TYPE_STATUS ENABLED
87#define VSF_SPI_CFG_REIMPLEMENT_TYPE_CTRL ENABLED
88#define VSF_SPI_CFG_REIMPLEMENT_TYPE_CFG ENABLED
89#define VSF_SPI_CFG_REIMPLEMENT_TYPE_CAPABILITY ENABLED
90// HW end
91
92/*============================ MACROFIED FUNCTIONS ===========================*/
93/*============================ TYPES =========================================*/
94
95vsf_class(vsf_${spi_ip}_spi_t) {
96#if VSF_${SPI_IP}_CFG_MULTI_CLASS == ENABLED
97 public_member(
99 )
100#endif
101
102/*\note You can add more member in vsf_${spi_ip}_spi_t instance.
103 * For members accessible from child, put in protected_member.
104 * Else, put in private_member.
105 */
106
107 protected_member(
108 vsf_${spi_ip}_spi_reg_t *reg;
111};
112// IPCore end
113
114// HW/IPCore, not for emulated drivers
115#if VSF_SPI_CFG_REIMPLEMENT_TYPE_MODE == ENABLED
116typedef enum vsf_spi_mode_t {
117 VSF_SPI_MASTER = 0x00ul << 0,
118 VSF_SPI_SLAVE = 0x01ul << 0,
119 VSF_SPI_MSB_FIRST = 0x00ul << 1,
120 VSF_SPI_LSB_FIRST = 0x01ul << 1,
121 VSF_SPI_CPOL_LOW = 0x00ul << 2,
122 VSF_SPI_CPOL_HIGH = 0x01ul << 2,
123 VSF_SPI_CPHA_LOW = 0x00ul << 2,
124 VSF_SPI_CPHA_HIGH = 0x01ul << 2,
131 VSF_SPI_DATASIZE_8 = 0x00ul << 8,
132 VSF_SPI_DATASIZE_16 = 0x01ul << 8,
133 VSF_SPI_DATASIZE_32 = 0x02ul << 8,
134
135 // more vendor specified modes can be added here
137#endif
138
139#if VSF_SPI_CFG_REIMPLEMENT_TYPE_IRQ_MASK == ENABLED
140typedef enum vsf_spi_irq_mask_t {
141 VSF_SPI_IRQ_MASK_TX = 0x01ul << 0,
142 VSF_SPI_IRQ_MASK_RX = 0x01ul << 1,
144 VSF_SPI_IRQ_MASK_CPL = 0x01ul << 3,
146
147 // more vendor specified irq_masks can be added here
149#endif
150
151#if VSF_SPI_CFG_REIMPLEMENT_TYPE_STATUS == ENABLED
152typedef struct vsf_spi_status_t {
153 union {
154 struct {
156 };
157 };
158
159 // more vendor specified status can be added here
161#endif
162
163#if VSF_SPI_CFG_REIMPLEMENT_TYPE_CAPABILITY == ENABLED
164typedef struct vsf_spi_capability_t {
168 uint8_t cs_count : 6;
171
172 // more vendor specified capability can be added here
174#endif
175
176#if VSF_SPI_CFG_REIMPLEMENT_TYPE_CTRL == ENABLED
180typedef struct vsf_spi_t vsf_spi_t;
181typedef void vsf_spi_isr_handler_t(void *target_ptr,
182 vsf_spi_t *spi_ptr,
184typedef struct vsf_spi_isr_t {
186 void *target_ptr;
189typedef struct vsf_spi_cfg_t {
194
195 // more vendor specified cfg can be added here
197#endif
198
199#if VSF_SPI_CFG_REIMPLEMENT_TYPE_CTRL == ENABLED
200typedef enum vsf_spi_ctrl_t {
203#endif
204// HW/IPCore end
205
206/*============================ INCLUDES ======================================*/
207
208// IPCore
209/*\note Extern APIs for ip core diriver.
210 * There is no requirement about how APIs of IPCore drivers should be implemented.
211 * Just consider the simplicity for actual peripheral drivers.
212 */
213// IPCore end
214
215#ifdef __cplusplus
216}
217#endif
218
219// IPCore
220#undef __VSF_HAL_${SPI_IP}_SPI_CLASS_IMPLEMENT
221#undef __VSF_HAL_${SPI_IP}_SPI_CLASS_INHERIT__
222// IPCore end
223
224#endif // VSF_HAL_USE_SPI
225#endif // __HAL_DRIVER_${SERIES/SPI_IP}_SPI_H__
226/* EOF */
vsf_spi_mode_t
Definition spi.h:33
@ VSF_SPI_SLAVE
Definition spi.h:34
@ VSF_SPI_DATASIZE_16
Definition spi.h:52
@ VSF_SPI_MODE_1
Definition spi.h:38
@ VSF_SPI_DATASIZE_8
datasize is 8 bits
Definition spi.h:44
@ VSF_SPI_MASTER
Definition spi.h:35
@ VSF_SPI_DATASIZE_32
Definition spi.h:68
@ VSF_SPI_CS_SOFTWARE_MODE
Definition spi.h:77
@ VSF_SPI_MODE_0
Definition spi.h:37
@ VSF_SPI_CS_HARDWARE_MODE
Definition spi.h:78
@ VSF_SPI_MODE_3
Definition spi.h:40
@ VSF_SPI_MODE_2
Definition spi.h:39
vsf_spi_irq_mask_t
Definition spi.h:41
@ VSF_SPI_IRQ_MASK_CPL
Definition spi.h:43
@ VSF_SPI_IRQ_MASK_TX_CPL
Definition spi.h:42
struct vsf_spi_status_t vsf_spi_status_t
@ VSF_SPI_LSB_FIRST
Definition spi.h:59
@ VSF_SPI_MSB_FIRST
Definition spi.h:58
Definition adc.h:94
vsf_arch_prio_t
Definition cortex_a_generic.h:88
#define vsf_class(__name)
Definition ooc_class.h:48
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:655
uint8_t support_software_cs
Software chip select support (1: supported, 0: not supported)
Definition vsf_template_spi.h:662
uint32_t max_clock_hz
Maximum supported SPI clock frequency in Hz.
Definition vsf_template_spi.h:665
uint8_t cs_count
Number of available chip select lines (0-63)
Definition vsf_template_spi.h:663
vsf_spi_irq_mask_t irq_mask
Definition spi.h:165
uint8_t support_hardware_cs
Hardware chip select support (1: supported, 0: not supported)
Definition vsf_template_spi.h:661
uint32_t min_clock_hz
Minimum supported SPI clock frequency in Hz.
Definition vsf_template_spi.h:666
Configuration structure for SPI.
Definition vsf_template_spi.h:708
uint32_t clock_hz
SPI clock frequency in Hz (must be between min_clock_hz and max_clock_hz)
Definition vsf_template_spi.h:710
vsf_spi_isr_t isr
Interrupt configuration (handler, target pointer, priority)
Definition vsf_template_spi.h:711
vsf_spi_mode_t mode
SPI operating mode (master/slave, CPOL/CPHA, bit order, data size)
Definition vsf_template_spi.h:709
uint8_t auto_cs_index
Hardware CS pin index (0 to cs_count-1) for auto chip select, if supported.
Definition vsf_template_spi.h:712
SPI interrupt service routine configuration structure.
Definition vsf_template_spi.h:696
vsf_spi_isr_handler_t * handler_fn
Interrupt handler function (NULL to disable interrupts)
Definition vsf_template_spi.h:697
void * target_ptr
User context pointer passed to handler.
Definition vsf_template_spi.h:698
vsf_arch_prio_t prio
Hardware-specific interrupt priority.
Definition vsf_template_spi.h:699
Predefined VSF SPI status that can be reimplemented in specific HAL drivers. Even if the hardware doe...
Definition vsf_template_spi.h:635
uint32_t is_busy
Definition spi.h:155
SPI instance structure, used for SPI Multi Class support, not needed in non Multi Class mode.
Definition vsf_template_spi.h:766
void vsf_spi_isr_handler_t(void *target_ptr, vsf_spi_t *spi_ptr, vsf_spi_irq_mask_t irq_mask)
Definition spi.h:181
vsf_spi_irq_mask_t
Definition spi.h:140
@ VSF_SPI_IRQ_MASK_OVERFLOW_ERR
Definition spi.h:145
@ VSF_SPI_IRQ_MASK_RX
Definition spi.h:142
@ VSF_SPI_IRQ_MASK_TX
Definition spi.h:141
class vsf_$ * reg
@ VSF_SPI_CPHA_LOW
Definition spi.h:123
@ VSF_SPI_CPOL_HIGH
Definition spi.h:122
@ VSF_SPI_CPHA_HIGH
Definition spi.h:124
@ VSF_SPI_CPOL_LOW
Definition spi.h:121
vsf_spi_ctrl_t
Definition spi.h:200
@ __VSF_SPI_CTRL_DUMMY
Definition spi.h:201
vsf_spi_isr_t isr
Definition spi.h:110
vsf_spi_t vsf_spi[SPI_COUNT]
Definition vsf_spi.c:3
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
Generated from commit: vsfteam/vsf@2b286be