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/*\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// IPCore
44#if defined(__VSF_HAL_${SPI_IP}_SPI_CLASS_IMPLEMENT)
45# define __VSF_CLASS_IMPLEMENT__
46#elif defined(__VSF_HAL_${SPI_IP}_SPI_CLASS_INHERIT__)
47# define __VSF_CLASS_INHERIT__
48#endif
49
50#include "utilities/ooc_class.h"
51// IPCore end
52
53#ifdef __cplusplus
54extern "C" {
55#endif
56
57/*============================ MACROS ========================================*/
58
59/*\note VSF_${SPI_IP}_SPI_CFG_MULTI_CLASS should be implemented for IP drives and open to user,
60 * while VSF_HW_SPI_CFG_MULTI_CLASS should be in spi.c.
61 */
62
63// IPCore
64#ifndef VSF_${SPI_IP}_SPI_CFG_MULTI_CLASS
65# define VSF_${SPI_IP}_SPI_CFG_MULTI_CLASS VSF_SPI_CFG_MULTI_CLASS
66#endif
67// IPCore end
68
69// HW
70/*\note hw SPI driver can reimplement following types:
71 * To enable reimplementation, please enable macro below:
72 * VSF_SPI_CFG_REIMPLEMENT_TYPE_MODE for vsf_spi_mode_t
73 * VSF_SPI_CFG_REIMPLEMENT_TYPE_STATUS for vsf_spi_status_t
74 * VSF_SPI_CFG_REIMPLEMENT_TYPE_IRQ_MASK for vsf_spi_irq_mask_t
75 * VSF_SPI_CFG_REIMPLEMENT_TYPE_CTRL for vsf_spi_ctrl_t
76 * VSF_SPI_CFG_REIMPLEMENT_TYPE_CFG for vsf_spi_cfg_t
77 * VSF_SPI_CFG_REIMPLEMENT_TYPE_CAPABILITY for vsf_spi_capability_t
78 * Reimplementation is used for optimization hw/IPCore drivers, reimplement the bit mask according to hw registers.
79 * *** DO NOT reimplement these in emulated drivers. ***
80 */
81
82#define VSF_SPI_CFG_REIMPLEMENT_TYPE_MODE ENABLED
83#define VSF_SPI_CFG_REIMPLEMENT_TYPE_IRQ_MASK ENABLED
84#define VSF_SPI_CFG_REIMPLEMENT_TYPE_STATUS ENABLED
85#define VSF_SPI_CFG_REIMPLEMENT_TYPE_CTRL ENABLED
86#define VSF_SPI_CFG_REIMPLEMENT_TYPE_CFG ENABLED
87#define VSF_SPI_CFG_REIMPLEMENT_TYPE_CAPABILITY ENABLED
88// HW end
89
90/*============================ MACROFIED FUNCTIONS ===========================*/
91/*============================ TYPES =========================================*/
92
93// IPCore
94vsf_class(vsf_${spi_ip}_spi_t) {
95#if VSF_${SPI_IP}_CFG_MULTI_CLASS == ENABLED
96 public_member(
98 )
99#endif
100
101/*\note You can add more member in vsf_${spi_ip}_spi_t instance.
102 * For members accessible from child, put in protected_member.
103 * Else, put in private_member.
104 */
105
106 protected_member(
107 vsf_${spi_ip}_spi_reg_t *reg;
110};
111// IPCore end
112
113// HW/IPCore, not for emulated drivers
114#if VSF_SPI_CFG_REIMPLEMENT_TYPE_MODE == ENABLED
115typedef enum vsf_spi_mode_t {
116 VSF_SPI_MASTER = 0x00ul << 0,
117 VSF_SPI_SLAVE = 0x01ul << 0,
118 VSF_SPI_MSB_FIRST = 0x00ul << 1,
119 VSF_SPI_LSB_FIRST = 0x01ul << 1,
120 VSF_SPI_CPOL_LOW = 0x00ul << 2,
121 VSF_SPI_CPOL_HIGH = 0x01ul << 2,
122 VSF_SPI_CPHA_LOW = 0x00ul << 2,
123 VSF_SPI_CPHA_HIGH = 0x01ul << 2,
130 VSF_SPI_DATASIZE_8 = 0x00ul << 8,
131 VSF_SPI_DATASIZE_16 = 0x01ul << 8,
132 VSF_SPI_DATASIZE_32 = 0x02ul << 8,
133
134 // more vendor specified modes can be added here
136#endif
137
138#if VSF_SPI_CFG_REIMPLEMENT_TYPE_IRQ_MASK == ENABLED
139typedef enum vsf_spi_irq_mask_t {
140 VSF_SPI_IRQ_MASK_TX = 0x01ul << 0,
141 VSF_SPI_IRQ_MASK_RX = 0x01ul << 1,
143 VSF_SPI_IRQ_MASK_CPL = 0x01ul << 3,
145
146 // more vendor specified irq_masks can be added here
148#endif
149
150#if VSF_SPI_CFG_REIMPLEMENT_TYPE_STATUS == ENABLED
151typedef struct vsf_spi_status_t {
152 union {
153 struct {
154 uint32_t is_busy : 1;
155 };
156 };
157
158 // more vendor specified status can be added here
160#endif
161
162#if VSF_SPI_CFG_REIMPLEMENT_TYPE_CAPABILITY == ENABLED
163typedef struct vsf_spi_capability_t {
167 uint8_t cs_count : 6;
170
171 // more vendor specified capability can be added here
173#endif
174
175#if VSF_SPI_CFG_REIMPLEMENT_TYPE_CTRL == ENABLED
179typedef struct vsf_spi_t vsf_spi_t;
180typedef void vsf_spi_isr_handler_t(void *target_ptr,
181 vsf_spi_t *spi_ptr,
183typedef struct vsf_spi_isr_t {
185 void *target_ptr;
188typedef struct vsf_spi_cfg_t {
193
194 // more vendor specified cfg can be added here
196#endif
197
198#if VSF_SPI_CFG_REIMPLEMENT_TYPE_CTRL == ENABLED
199typedef enum vsf_spi_ctrl_t {
202#endif
203// HW/IPCore end
204
205/*============================ INCLUDES ======================================*/
206
207// IPCore
208/*\note Extern APIs for ip core diriver.
209 * There is no requirement about how APIs of IPCore drivers should be implemented.
210 * Just consider the simplicity for actual peripheral drivers.
211 */
212// IPCore end
213
214#ifdef __cplusplus
215}
216#endif
217
218// IPCore
219#undef __VSF_HAL_${SPI_IP}_SPI_CLASS_IMPLEMENT
220#undef __VSF_HAL_${SPI_IP}_SPI_CLASS_INHERIT__
221// IPCore end
222
223#endif // VSF_HAL_USE_SPI
224#endif // __HAL_DRIVER_${SERIES/SPI_IP}_SPI_H__
225/* 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_MODE_0
Definition spi.h:37
@ VSF_SPI_MODE_3
Definition spi.h:40
@ VSF_SPI_MODE_2
Definition spi.h:39
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:144
struct vsf_spi_cfg_t vsf_spi_cfg_t
struct vsf_spi_capability_t vsf_spi_capability_t
@ VSF_SPI_IRQ_MASK_OVERFLOW_ERR
Definition spi.h:108
@ VSF_SPI_IRQ_MASK_RX
Definition spi.h:105
@ VSF_SPI_IRQ_MASK_TX
Definition spi.h:104
struct vsf_spi_status_t vsf_spi_status_t
vsf_spi_mode_t
Definition spi.h:79
@ VSF_SPI_CPHA_LOW
Definition spi.h:86
@ VSF_SPI_LSB_FIRST
Definition spi.h:83
@ VSF_SPI_CPOL_HIGH
Definition spi.h:85
@ VSF_SPI_CPHA_HIGH
Definition spi.h:87
@ VSF_SPI_MSB_FIRST
Definition spi.h:82
@ VSF_SPI_CS_SOFTWARE_MODE
Definition spi.h:92
@ VSF_SPI_CS_HARDWARE_MODE
Definition spi.h:93
@ VSF_SPI_CPOL_LOW
Definition spi.h:84
vsf_spi_ctrl_t
Definition spi.h:163
@ __VSF_SPI_CTRL_DUMMY
Definition spi.h:164
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
Definition adc.h:92
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:688
uint8_t support_software_cs
Hardware chip select support (1: supported, 0: not supported)
Definition vsf_template_spi.h:695
uint32_t max_clock_hz
Number of available chip select lines (0-63)
Definition vsf_template_spi.h:698
uint8_t cs_count
Software chip select support (1: supported, 0: not supported)
Definition vsf_template_spi.h:696
vsf_spi_irq_mask_t irq_mask
Definition spi.h:128
uint8_t support_hardware_cs
Supported interrupt masks for SPI operations.
Definition vsf_template_spi.h:694
uint32_t min_clock_hz
Maximum supported SPI clock frequency in Hz.
Definition vsf_template_spi.h:699
Configuration structure for SPI.
Definition vsf_template_spi.h:746
uint32_t clock_hz
SPI operating mode (master/slave, CPOL/CPHA, bit order, data size)
Definition vsf_template_spi.h:748
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:749
vsf_spi_mode_t mode
Definition vsf_template_spi.h:747
uint8_t auto_cs_index
Interrupt configuration (handler, target pointer, priority)
Definition vsf_template_spi.h:752
SPI interrupt service routine configuration structure.
Definition vsf_template_spi.h:734
vsf_spi_isr_handler_t * handler_fn
Definition vsf_template_spi.h:735
void * target_ptr
Interrupt handler function (NULL to disable interrupts)
Definition vsf_template_spi.h:736
vsf_arch_prio_t prio
User context pointer passed to handler.
Definition vsf_template_spi.h:737
Predefined VSF SPI status that can be reimplemented in specific HAL drivers. Even if the hardware doe...
Definition vsf_template_spi.h:668
uint32_t is_busy
Definition spi.h:118
SPI instance structure, used for SPI Multi Class support, not needed in non Multi Class mode.
Definition vsf_template_spi.h:1034
void vsf_spi_isr_handler_t(void *target_ptr, vsf_spi_t *spi_ptr, vsf_spi_irq_mask_t irq_mask)
Definition spi.h:180
class vsf_$ * reg
vsf_spi_isr_t isr
Definition spi.h:109
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:612
vsf_spi_ctrl_t
Predefined VSF SPI control commands that can be reimplemented in specific HAL drivers.
Definition vsf_template_spi.h:778
Generated from commit: vsfteam/vsf@74aa6ce