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 VSF_SPI_CPOL_LOW = 0x00ul << 2,
85 VSF_SPI_CPOL_HIGH = 0x01ul << 2,
86 VSF_SPI_CPHA_LOW = 0x00ul << 2,
87 VSF_SPI_CPHA_HIGH = 0x01ul << 2,
94 VSF_SPI_DATASIZE_8 = 0x00ul << 8,
95 VSF_SPI_DATASIZE_16 = 0x01ul << 8,
96 VSF_SPI_DATASIZE_32 = 0x02ul << 8,
97
98 // more vendor specified modes can be added here
100#endif
101
102#if VSF_SPI_CFG_REIMPLEMENT_TYPE_IRQ_MASK == ENABLED
103typedef enum vsf_spi_irq_mask_t {
104 VSF_SPI_IRQ_MASK_TX = 0x01ul << 0,
105 VSF_SPI_IRQ_MASK_RX = 0x01ul << 1,
107 VSF_SPI_IRQ_MASK_CPL = 0x01ul << 3,
109
110 // more vendor specified irq_masks can be added here
112#endif
113
114#if VSF_SPI_CFG_REIMPLEMENT_TYPE_STATUS == ENABLED
115typedef struct vsf_spi_status_t {
116 union {
117 struct {
119 };
120 };
121
122 // more vendor specified status can be added here
124#endif
125
126#if VSF_SPI_CFG_REIMPLEMENT_TYPE_CAPABILITY == ENABLED
127typedef struct vsf_spi_capability_t {
131 uint8_t cs_count : 6;
134
135 // more vendor specified capability can be added here
137#endif
138
139#if VSF_SPI_CFG_REIMPLEMENT_TYPE_CTRL == ENABLED
143typedef struct vsf_spi_t vsf_spi_t;
144typedef void vsf_spi_isr_handler_t(void *target_ptr,
145 vsf_spi_t *spi_ptr,
147typedef struct vsf_spi_isr_t {
149 void *target_ptr;
152typedef struct vsf_spi_cfg_t {
157
158 // more vendor specified cfg can be added here
160#endif
161
162#if VSF_SPI_CFG_REIMPLEMENT_TYPE_CTRL == ENABLED
163typedef enum vsf_spi_ctrl_t {
166#endif
167// HW/IPCore end
168
169/*============================ INCLUDES ======================================*/
170
171#ifdef __cplusplus
172}
173#endif
174
175#endif // VSF_HAL_USE_SPI
176#endif // __HAL_DRIVER_NATIONS_N32H76X_N32H78X_SPI_H__
177/* 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
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: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
vsf_spi_irq_mask_t
Definition spi.h:139
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