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_ARTERY_AT32F402_405_SPI_H__
19#define __HAL_DRIVER_ARTERY_AT32F402_405_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// HW
50/*\note hw SPI driver can reimplement following types:
51 * To enable reimplementation, please enable macro below:
52 * VSF_SPI_CFG_REIMPLEMENT_TYPE_MODE for vsf_spi_mode_t
53 * VSF_SPI_CFG_REIMPLEMENT_TYPE_STATUS for vsf_spi_status_t
54 * VSF_SPI_CFG_REIMPLEMENT_TYPE_IRQ_MASK for vsf_spi_irq_mask_t
55 * VSF_SPI_CFG_REIMPLEMENT_TYPE_CTRL for vsf_spi_ctrl_t
56 * VSF_SPI_CFG_REIMPLEMENT_TYPE_CFG for vsf_spi_cfg_t
57 * VSF_SPI_CFG_REIMPLEMENT_TYPE_CAPABILITY for vsf_spi_capability_t
58 * Reimplementation is used for optimization hw/IPCore drivers, reimplement the bit mask according to hw registers.
59 * *** DO NOT reimplement these in emulated drivers. ***
60 */
61
62#define VSF_SPI_CFG_REIMPLEMENT_TYPE_MODE ENABLED
63#define VSF_SPI_CFG_REIMPLEMENT_TYPE_IRQ_MASK ENABLED
64#define VSF_SPI_CFG_REIMPLEMENT_TYPE_STATUS ENABLED
65#define VSF_SPI_CFG_REIMPLEMENT_TYPE_CTRL ENABLED
66#define VSF_SPI_CFG_REIMPLEMENT_TYPE_CFG ENABLED
67#define VSF_SPI_CFG_REIMPLEMENT_TYPE_CAPABILITY ENABLED
68// HW end
69
70/*============================ MACROFIED FUNCTIONS ===========================*/
71/*============================ TYPES =========================================*/
72
73// HW/IPCore, not for emulated drivers
74#if VSF_SPI_CFG_REIMPLEMENT_TYPE_MODE == ENABLED
75typedef enum vsf_spi_mode_t {
76 VSF_SPI_MASTER = 0x00ul << 0,
77 VSF_SPI_SLAVE = 0x01ul << 0,
78 VSF_SPI_MSB_FIRST = 0x00ul << 1,
79 VSF_SPI_LSB_FIRST = 0x01ul << 1,
80 VSF_SPI_CPOL_LOW = 0x00ul << 2,
81 VSF_SPI_CPOL_HIGH = 0x01ul << 2,
82 VSF_SPI_CPHA_LOW = 0x00ul << 2,
83 VSF_SPI_CPHA_HIGH = 0x01ul << 2,
90 VSF_SPI_DATASIZE_8 = 0x00ul << 8,
91 VSF_SPI_DATASIZE_16 = 0x01ul << 8,
92 VSF_SPI_DATASIZE_32 = 0x02ul << 8,
93
94 // more vendor specified modes can be added here
96#endif
97
98#if VSF_SPI_CFG_REIMPLEMENT_TYPE_IRQ_MASK == ENABLED
99typedef enum vsf_spi_irq_mask_t {
100 VSF_SPI_IRQ_MASK_TX = 0x01ul << 0,
101 VSF_SPI_IRQ_MASK_RX = 0x01ul << 1,
105
106 // more vendor specified irq_masks can be added here
108#endif
109
110#if VSF_SPI_CFG_REIMPLEMENT_TYPE_STATUS == ENABLED
111typedef struct vsf_spi_status_t {
112 union {
113 struct {
115 };
116 };
117
118 // more vendor specified status can be added here
120#endif
121
122#if VSF_SPI_CFG_REIMPLEMENT_TYPE_CAPABILITY == ENABLED
123typedef struct vsf_spi_capability_t {
130
131 // more vendor specified capability can be added here
133#endif
134
135#if VSF_SPI_CFG_REIMPLEMENT_TYPE_CTRL == ENABLED
139typedef struct vsf_spi_t vsf_spi_t;
140typedef void vsf_spi_isr_handler_t(void *target_ptr,
141 vsf_spi_t *spi_ptr,
143typedef struct vsf_spi_isr_t {
148typedef struct vsf_spi_cfg_t {
153
154 // more vendor specified cfg can be added here
156#endif
157
158#if VSF_SPI_CFG_REIMPLEMENT_TYPE_CTRL == ENABLED
159typedef enum vsf_spi_ctrl_t {
162#endif
163// HW/IPCore end
164
165/*============================ INCLUDES ======================================*/
166
167#ifdef __cplusplus
168}
169#endif
170
171#endif // VSF_HAL_USE_SPI
172#endif // __HAL_DRIVER_ARTERY_AT32F402_405_SPI_H__
173/* 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_cfg_t vsf_spi_cfg_t
vsf_spi_irq_mask_t
Definition spi.h:99
@ VSF_SPI_IRQ_MASK_RX_OVERFLOW_ERR
Definition spi.h:104
@ VSF_SPI_IRQ_MASK_RX_CPL
Definition spi.h:103
@ VSF_SPI_IRQ_MASK_RX
Definition spi.h:101
@ VSF_SPI_IRQ_MASK_TX
Definition spi.h:100
@ VSF_SPI_IRQ_MASK_TX_CPL
Definition spi.h:102
vsf_spi_mode_t
Definition spi.h:75
@ VSF_SPI_CPHA_LOW
Definition spi.h:82
@ VSF_SPI_LSB_FIRST
Definition spi.h:79
@ VSF_SPI_CPOL_HIGH
Definition spi.h:81
@ VSF_SPI_CPHA_HIGH
Definition spi.h:83
@ VSF_SPI_MSB_FIRST
Definition spi.h:78
@ VSF_SPI_CS_SOFTWARE_MODE
Definition spi.h:88
@ VSF_SPI_CS_HARDWARE_MODE
Definition spi.h:89
@ VSF_SPI_CPOL_LOW
Definition spi.h:80
vsf_spi_ctrl_t
Definition spi.h:159
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_capability_t vsf_spi_capability_t
struct vsf_spi_status_t vsf_spi_status_t
@ __VSF_SPI_CTRL_DUMMY
Definition spi.h:164
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 spi.h:123
uint8_t support_software_cs
Hardware chip select support (1: supported, 0: not supported)
Definition spi.h:126
uint32_t max_clock_hz
Number of available chip select lines (0-63)
Definition spi.h:128
uint8_t cs_count
Software chip select support (1: supported, 0: not supported)
Definition spi.h:127
vsf_spi_irq_mask_t irq_mask
Definition spi.h:124
uint8_t support_hardware_cs
Supported interrupt masks for SPI operations.
Definition spi.h:125
uint32_t min_clock_hz
Maximum supported SPI clock frequency in Hz.
Definition spi.h:129
Configuration structure for SPI.
Definition spi.h:148
uint32_t clock_hz
SPI operating mode (master/slave, CPOL/CPHA, bit order, data size)
Definition spi.h:150
vsf_spi_isr_t isr
SPI clock frequency in Hz (must be between min_clock_hz and max_clock_hz)
Definition spi.h:151
vsf_spi_mode_t mode
Definition spi.h:149
uint8_t auto_cs_index
Interrupt configuration (handler, target pointer, priority)
Definition spi.h:152
SPI interrupt service routine configuration structure.
Definition spi.h:143
vsf_spi_isr_handler_t * handler_fn
Definition spi.h:144
void * target_ptr
Interrupt handler function (NULL to disable interrupts)
Definition spi.h:145
vsf_arch_prio_t prio
User context pointer passed to handler.
Definition spi.h:146
Predefined VSF SPI status that can be reimplemented in specific HAL drivers. Even if the hardware doe...
Definition spi.h:111
uint32_t is_busy
Definition spi.h:114
SPI instance structure, used for SPI Multi Class support, not needed in non Multi Class mode.
Definition vsf_template_spi.h:1072
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_mode_t
Definition spi.h:115
Generated from commit: vsfteam/vsf@368bfa6