diff options
Diffstat (limited to 'lib/chibios/os/hal/ports/ADUCM/ADUCM36x/hal_spi_lld.h')
-rw-r--r-- | lib/chibios/os/hal/ports/ADUCM/ADUCM36x/hal_spi_lld.h | 231 |
1 files changed, 231 insertions, 0 deletions
diff --git a/lib/chibios/os/hal/ports/ADUCM/ADUCM36x/hal_spi_lld.h b/lib/chibios/os/hal/ports/ADUCM/ADUCM36x/hal_spi_lld.h new file mode 100644 index 000000000..21a4e9251 --- /dev/null +++ b/lib/chibios/os/hal/ports/ADUCM/ADUCM36x/hal_spi_lld.h | |||
@@ -0,0 +1,231 @@ | |||
1 | /* | ||
2 | ChibiOS - Copyright (C) 2019 Rocco Marco Guglielmi | ||
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 | * @file ADUCM36x/hal_spi_lld.h | ||
19 | * @brief ADUCM SPI subsystem low level driver header. | ||
20 | * | ||
21 | * @addtogroup SPI | ||
22 | * @{ | ||
23 | */ | ||
24 | |||
25 | #ifndef HAL_SPI_LLD_H | ||
26 | #define HAL_SPI_LLD_H | ||
27 | |||
28 | #if HAL_USE_SPI || defined(__DOXYGEN__) | ||
29 | |||
30 | /*===========================================================================*/ | ||
31 | /* Driver constants. */ | ||
32 | /*===========================================================================*/ | ||
33 | |||
34 | /** | ||
35 | * @brief Circular mode support flag. | ||
36 | */ | ||
37 | #define SPI_SUPPORTS_CIRCULAR FALSE | ||
38 | |||
39 | /** | ||
40 | * @name Register helpers not found in ADI headers | ||
41 | * @{ | ||
42 | */ | ||
43 | #define ADUCM_SPI_CON_ENABLE 0x0001U | ||
44 | #define ADUCM_SPI_CON_MASEN 0x0002U | ||
45 | #define ADUCM_SPI_CON_CPHA 0x0004U | ||
46 | #define ADUCM_SPI_CON_CPOL 0x0008U | ||
47 | #define ADUCM_SPI_CON_WOM 0x0010U | ||
48 | #define ADUCM_SPI_CON_LSB 0x0020U | ||
49 | #define ADUCM_SPI_CON_TIM 0x0040U | ||
50 | #define ADUCM_SPI_CON_ZEN 0x0080U | ||
51 | #define ADUCM_SPI_CON_RXOF 0x0100U | ||
52 | #define ADUCM_SPI_CON_OEN 0x0200U | ||
53 | #define ADUCM_SPI_CON_LOOPBACK 0x0400U | ||
54 | #define ADUCM_SPI_CON_CON 0x0800U | ||
55 | #define ADUCM_SPI_CON_RFLUSH 0x1000U | ||
56 | #define ADUCM_SPI_CON_TFLUSH 0x2000U | ||
57 | #define ADUCM_SPI_CON_MOD_MASK 0xC000U | ||
58 | #define ADUCM_SPI_CON_MOD_TX1RX1 0x0000U | ||
59 | #define ADUCM_SPI_CON_MOD_TX2RX2 0x4000U | ||
60 | #define ADUCM_SPI_CON_MOD_TX3RX3 0x8000U | ||
61 | #define ADUCM_SPI_CON_MOD_TX4RX4 0xC000U | ||
62 | |||
63 | #define ADUCM_SPI_DIV_0 0x0001U | ||
64 | #define ADUCM_SPI_DIV_1 0x0002U | ||
65 | #define ADUCM_SPI_DIV_2 0x0004U | ||
66 | #define ADUCM_SPI_DIV_3 0x0008U | ||
67 | #define ADUCM_SPI_DIV_4 0x00F0U | ||
68 | /** @} */ | ||
69 | |||
70 | /*===========================================================================*/ | ||
71 | /* Driver pre-compile time settings. */ | ||
72 | /*===========================================================================*/ | ||
73 | |||
74 | /** | ||
75 | * @name Configuration options | ||
76 | * @{ | ||
77 | */ | ||
78 | /** | ||
79 | * @brief SPI0 driver enable switch. | ||
80 | * @details If set to @p TRUE the support for SPI0 is included. | ||
81 | * @note The default is @p FALSE. | ||
82 | */ | ||
83 | #if !defined(ADUCM_SPI_USE_SPI0) || defined(__DOXYGEN__) | ||
84 | #define ADUCM_SPI_USE_SPI0 FALSE | ||
85 | #endif | ||
86 | |||
87 | /** | ||
88 | * @brief SPI1 driver enable switch. | ||
89 | * @details If set to @p TRUE the support for SPI1 is included. | ||
90 | * @note The default is @p FALSE. | ||
91 | */ | ||
92 | #if !defined(ADUCM_SPI_USE_SPI1) || defined(__DOXYGEN__) | ||
93 | #define ADUCM_SPI_USE_SPI1 FALSE | ||
94 | #endif | ||
95 | |||
96 | /** | ||
97 | * @brief SPI0 interrupt priority level setting. | ||
98 | */ | ||
99 | #if !defined(ADUCM_SPI_SPI0_IRQ_PRIORITY) || defined(__DOXYGEN__) | ||
100 | #define ADUCM_SPI_SPI0_IRQ_PRIORITY 5 | ||
101 | #endif | ||
102 | |||
103 | /** | ||
104 | * @brief SPI1 interrupt priority level setting. | ||
105 | */ | ||
106 | #if !defined(ADUCM_SPI_SPI1_IRQ_PRIORITY) || defined(__DOXYGEN__) | ||
107 | #define ADUCM_SPI_SPI1_IRQ_PRIORITY 5 | ||
108 | #endif | ||
109 | |||
110 | /** | ||
111 | * @brief Enable SPI DMA support | ||
112 | */ | ||
113 | #if !defined(ADUCM_SPI_USE_DMA) || defined(__DOXYGEN__) | ||
114 | #define ADUCM_SPI_USE_DMA FALSE | ||
115 | #endif | ||
116 | |||
117 | /** @} */ | ||
118 | |||
119 | /*===========================================================================*/ | ||
120 | /* Derived constants and error checks. */ | ||
121 | /*===========================================================================*/ | ||
122 | |||
123 | #if !ADUCM_SPI_USE_SPI0 && !ADUCM_SPI_USE_SPI1 | ||
124 | #error "SPI driver activated but no SPI peripheral assigned" | ||
125 | #endif | ||
126 | |||
127 | #if ADUCM_SPI_USE_SPI0 && \ | ||
128 | !OSAL_IRQ_IS_VALID_PRIORITY(ADUCM_SPI_SPI0_IRQ_PRIORITY) | ||
129 | #error "Invalid IRQ priority assigned to SPI0" | ||
130 | #endif | ||
131 | |||
132 | #if ADUCM_SPI_USE_SPI1 && \ | ||
133 | !OSAL_IRQ_IS_VALID_PRIORITY(ADUCM_SPI_SPI1_IRQ_PRIORITY) | ||
134 | #error "Invalid IRQ priority assigned to SPI1" | ||
135 | #endif | ||
136 | |||
137 | #if ADUCM_SPI_USE_DMA | ||
138 | #error "ADuCM SPI driver implementation does not supports DMA yet." | ||
139 | #endif | ||
140 | |||
141 | #if ADUCM_SPI_USE_DMA && ADUCM_SPI_USE_SPI0 | ||
142 | #error "ADuCM SPI0 does not supports DMA." | ||
143 | #endif | ||
144 | |||
145 | #if (ADUCM_SPI_USE_DMA == TRUE) && !defined(ADUCM_DMA_REQUIRED) | ||
146 | #define ADUCM_DMA_REQUIRED | ||
147 | #endif | ||
148 | |||
149 | #if (SPI_USE_CIRCULAR == TRUE) && (SPI_SUPPORTS_CIRCULAR == FALSE) | ||
150 | #error "ADuCM SPI does not support circular mode." | ||
151 | #endif | ||
152 | |||
153 | #if SPI_SELECT_MODE == SPI_SELECT_MODE_LLD | ||
154 | #error "SPI_SELECT_MODE_LLD not supported by this driver" | ||
155 | #endif | ||
156 | |||
157 | /*===========================================================================*/ | ||
158 | /* Driver data structures and types. */ | ||
159 | /*===========================================================================*/ | ||
160 | |||
161 | /*===========================================================================*/ | ||
162 | /* Driver macros. */ | ||
163 | /*===========================================================================*/ | ||
164 | |||
165 | /** | ||
166 | * @brief Low level fields of the SPI driver structure. | ||
167 | */ | ||
168 | #if ADUCM_SPI_USE_DMA | ||
169 | #define spi_lld_driver_fields \ | ||
170 | /* Empty placeholder for DMA based implementation. */ | ||
171 | #else | ||
172 | #define spi_lld_driver_fields \ | ||
173 | /* Pointer to the SPIx registers block.*/ \ | ||
174 | ADI_SPI_TypeDef *spi; \ | ||
175 | /* Receive buffer pointer.*/ \ | ||
176 | uint8_t *rxbuf; \ | ||
177 | /* Transmission buffer pointer.*/ \ | ||
178 | uint8_t *txbuf; \ | ||
179 | /* Transfert size.*/ \ | ||
180 | uint32_t size; | ||
181 | #endif /* ADUCM_SPI_USE_DMA */ | ||
182 | |||
183 | /** | ||
184 | * @brief Low level fields of the SPI configuration structure. | ||
185 | */ | ||
186 | #define spi_lld_config_fields \ | ||
187 | /* SPIxCON register initialization data.*/ \ | ||
188 | uint16_t con; \ | ||
189 | /* SPIxDIV register initialization data.*/ \ | ||
190 | uint16_t div | ||
191 | |||
192 | /*===========================================================================*/ | ||
193 | /* External declarations. */ | ||
194 | /*===========================================================================*/ | ||
195 | |||
196 | #if ADUCM_SPI_USE_SPI0 && !defined(__DOXYGEN__) | ||
197 | extern SPIDriver SPID0; | ||
198 | #endif | ||
199 | |||
200 | #if ADUCM_SPI_USE_SPI1 && !defined(__DOXYGEN__) | ||
201 | extern SPIDriver SPID1; | ||
202 | #endif | ||
203 | |||
204 | #ifdef __cplusplus | ||
205 | extern "C" { | ||
206 | #endif | ||
207 | void spi_lld_init(void); | ||
208 | void spi_lld_start(SPIDriver *spip); | ||
209 | void spi_lld_stop(SPIDriver *spip); | ||
210 | #if (SPI_SELECT_MODE == SPI_SELECT_MODE_LLD) || defined(__DOXYGEN__) | ||
211 | void spi_lld_select(SPIDriver *spip); | ||
212 | void spi_lld_unselect(SPIDriver *spip); | ||
213 | #endif | ||
214 | void spi_lld_ignore(SPIDriver *spip, size_t n); | ||
215 | void spi_lld_exchange(SPIDriver *spip, size_t n, | ||
216 | const void *txbuf, void *rxbuf); | ||
217 | void spi_lld_send(SPIDriver *spip, size_t n, const void *txbuf); | ||
218 | void spi_lld_receive(SPIDriver *spip, size_t n, void *rxbuf); | ||
219 | #if (SPI_SUPPORTS_CIRCULAR == TRUE) || defined(__DOXYGEN__) | ||
220 | void spi_lld_abort(SPIDriver *spip); | ||
221 | #endif | ||
222 | uint8_t spi_lld_polled_exchange(SPIDriver *spip, uint8_t frame); | ||
223 | #ifdef __cplusplus | ||
224 | } | ||
225 | #endif | ||
226 | |||
227 | #endif /* HAL_USE_SPI */ | ||
228 | |||
229 | #endif /* HAL_SPI_LLD_H */ | ||
230 | |||
231 | /** @} */ | ||