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#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#ifdef __cplusplus
46extern "C" {
47#endif
48
49/*============================ MACROS ========================================*/
50
51/*\note VSF_${SPI_IP}_SPI_CFG_MULTI_CLASS should be implemented for IP drives and open to user,
52 * while VSF_HW_SPI_CFG_MULTI_CLASS should be in spi.c.
53 */
54
55// HW
56/*\note hw SPI driver can reimplement following types:
57 * To enable reimplementation, please enable macro below:
58 * VSF_SPI_CFG_REIMPLEMENT_TYPE_MODE for vsf_spi_mode_t
59 * VSF_SPI_CFG_REIMPLEMENT_TYPE_STATUS for vsf_spi_status_t
60 * VSF_SPI_CFG_REIMPLEMENT_TYPE_IRQ_MASK for vsf_spi_irq_mask_t
61 * VSF_SPI_CFG_REIMPLEMENT_TYPE_CTRL for vsf_spi_ctrl_t
62 * VSF_SPI_CFG_REIMPLEMENT_TYPE_CFG for vsf_spi_cfg_t
63 * VSF_SPI_CFG_REIMPLEMENT_TYPE_CAPABILITY for vsf_spi_capability_t
64 * Reimplementation is used for optimization hw/IPCore drivers, reimplement the bit mask according to hw registers.
65 * *** DO NOT reimplement these in emulated drivers. ***
66 */
67
68#define VSF_SPI_CFG_REIMPLEMENT_TYPE_MODE ENABLED
69#define VSF_SPI_CFG_REIMPLEMENT_TYPE_IRQ_MASK ENABLED
70#define VSF_SPI_CFG_REIMPLEMENT_TYPE_STATUS ENABLED
71#define VSF_SPI_CFG_REIMPLEMENT_TYPE_CTRL ENABLED
72#define VSF_SPI_CFG_REIMPLEMENT_TYPE_CFG ENABLED
73#define VSF_SPI_CFG_REIMPLEMENT_TYPE_CAPABILITY ENABLED
74// HW end
75
76/*============================ MACROFIED FUNCTIONS ===========================*/
77/*============================ TYPES =========================================*/
78
79// HW/IPCore, not for emulated drivers
80#if VSF_SPI_CFG_REIMPLEMENT_TYPE_MODE == ENABLED
81typedef enum vsf_spi_mode_t {
82 VSF_SPI_MASTER = 0x00ul << 0,
83 VSF_SPI_SLAVE = 0x01ul << 0,
84 VSF_SPI_MSB_FIRST = 0x00ul << 1,
85 VSF_SPI_LSB_FIRST = 0x01ul << 1,
86 VSF_SPI_CPOL_LOW = 0x00ul << 2,
87 VSF_SPI_CPOL_HIGH = 0x01ul << 2,
88 VSF_SPI_CPHA_LOW = 0x00ul << 2,
89 VSF_SPI_CPHA_HIGH = 0x01ul << 2,
96 VSF_SPI_DATASIZE_8 = 0x00ul << 8,
97 VSF_SPI_DATASIZE_16 = 0x01ul << 8,
98 VSF_SPI_DATASIZE_32 = 0x02ul << 8,
99
100 // more vendor specified modes can be added here
102#endif
103
104#if VSF_SPI_CFG_REIMPLEMENT_TYPE_IRQ_MASK == ENABLED
105typedef enum vsf_spi_irq_mask_t {
106 VSF_SPI_IRQ_MASK_TX = 0x01ul << 0,
107 VSF_SPI_IRQ_MASK_RX = 0x01ul << 1,
109 VSF_SPI_IRQ_MASK_CPL = 0x01ul << 3,
111
112 // more vendor specified irq_masks can be added here
114#endif
115
116#if VSF_SPI_CFG_REIMPLEMENT_TYPE_STATUS == ENABLED
117typedef struct vsf_spi_status_t {
118 union {
119 struct {
121 };
122 };
123
124 // more vendor specified status can be added here
126#endif
127
128#if VSF_SPI_CFG_REIMPLEMENT_TYPE_CAPABILITY == ENABLED
129typedef struct vsf_spi_capability_t {
133 uint8_t cs_count : 6;
136
137 // more vendor specified capability can be added here
139#endif
140
141#if VSF_SPI_CFG_REIMPLEMENT_TYPE_CTRL == ENABLED
145typedef struct vsf_spi_t vsf_spi_t;
146typedef void vsf_spi_isr_handler_t(void *target_ptr,
147 vsf_spi_t *spi_ptr,
149typedef struct vsf_spi_isr_t {
151 void *target_ptr;
154typedef struct vsf_spi_cfg_t {
159
160 // more vendor specified cfg can be added here
162#endif
163
164#if VSF_SPI_CFG_REIMPLEMENT_TYPE_CTRL == ENABLED
165typedef enum vsf_spi_ctrl_t {
168#endif
169// HW/IPCore end
170
171/*============================ INCLUDES ======================================*/
172
173#ifdef __cplusplus
174}
175#endif
176
177#endif // VSF_HAL_USE_SPI
178#endif // __HAL_DRIVER_NATIONS_N32H76X_N32H78X_SPI_H__
179/* 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_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:146
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:110
@ VSF_SPI_IRQ_MASK_RX
Definition spi.h:107
@ VSF_SPI_IRQ_MASK_TX
Definition spi.h:106
struct vsf_spi_status_t vsf_spi_status_t
vsf_spi_mode_t
Definition spi.h:81
@ VSF_SPI_CPHA_LOW
Definition spi.h:88
@ VSF_SPI_LSB_FIRST
Definition spi.h:85
@ VSF_SPI_CPOL_HIGH
Definition spi.h:87
@ VSF_SPI_CPHA_HIGH
Definition spi.h:89
@ VSF_SPI_MSB_FIRST
Definition spi.h:84
@ VSF_SPI_DATASIZE_32
Definition spi.h:98
@ VSF_SPI_CS_SOFTWARE_MODE
Definition spi.h:94
@ VSF_SPI_CS_HARDWARE_MODE
Definition spi.h:95
@ VSF_SPI_CPOL_LOW
Definition spi.h:86
vsf_spi_ctrl_t
Definition spi.h:165
@ __VSF_SPI_CTRL_DUMMY
Definition spi.h:166
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:655
uint8_t support_software_cs
Hardware chip select support (1: supported, 0: not supported)
Definition vsf_template_spi.h:662
uint32_t max_clock_hz
Number of available chip select lines (0-63)
Definition vsf_template_spi.h:665
uint8_t cs_count
Software chip select support (1: supported, 0: not supported)
Definition vsf_template_spi.h:663
vsf_spi_irq_mask_t irq_mask
Definition spi.h:130
uint8_t support_hardware_cs
Supported interrupt masks for SPI operations.
Definition vsf_template_spi.h:661
uint32_t min_clock_hz
Maximum 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 operating mode (master/slave, CPOL/CPHA, bit order, data size)
Definition vsf_template_spi.h:710
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:711
vsf_spi_mode_t mode
Definition vsf_template_spi.h:709
uint8_t auto_cs_index
Interrupt configuration (handler, target pointer, priority)
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
Definition vsf_template_spi.h:697
void * target_ptr
Interrupt handler function (NULL to disable interrupts)
Definition vsf_template_spi.h:698
vsf_arch_prio_t prio
User context pointer passed to handler.
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:120
SPI instance structure, used for SPI Multi Class support, not needed in non Multi Class mode.
Definition vsf_template_spi.h:990
void vsf_spi_isr_handler_t(void *target_ptr, vsf_spi_t *spi_ptr, vsf_spi_irq_mask_t irq_mask)
Definition spi.h:182
vsf_spi_irq_mask_t
Definition spi.h:141
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:738
Generated from commit: vsfteam/vsf@cfd571b