aboutsummaryrefslogtreecommitdiff
path: root/lib/chibios/os/hal/templates/hal_spi_lld.c
diff options
context:
space:
mode:
Diffstat (limited to 'lib/chibios/os/hal/templates/hal_spi_lld.c')
-rw-r--r--lib/chibios/os/hal/templates/hal_spi_lld.c263
1 files changed, 263 insertions, 0 deletions
diff --git a/lib/chibios/os/hal/templates/hal_spi_lld.c b/lib/chibios/os/hal/templates/hal_spi_lld.c
new file mode 100644
index 000000000..24f81757d
--- /dev/null
+++ b/lib/chibios/os/hal/templates/hal_spi_lld.c
@@ -0,0 +1,263 @@
1/*
2 ChibiOS - Copyright (C) 2006..2018 Giovanni Di Sirio
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 hal_spi_lld.c
19 * @brief PLATFORM SPI subsystem low level driver source.
20 *
21 * @addtogroup SPI
22 * @{
23 */
24
25#include "hal.h"
26
27#if (HAL_USE_SPI == TRUE) || defined(__DOXYGEN__)
28
29/*===========================================================================*/
30/* Driver local definitions. */
31/*===========================================================================*/
32
33/*===========================================================================*/
34/* Driver exported variables. */
35/*===========================================================================*/
36
37/**
38 * @brief SPI1 driver identifier.
39 */
40#if (PLATFORM_SPI_USE_SPI1 == TRUE) || defined(__DOXYGEN__)
41SPIDriver SPID1;
42#endif
43
44/*===========================================================================*/
45/* Driver local variables and types. */
46/*===========================================================================*/
47
48/*===========================================================================*/
49/* Driver local functions. */
50/*===========================================================================*/
51
52/*===========================================================================*/
53/* Driver interrupt handlers. */
54/*===========================================================================*/
55
56/*===========================================================================*/
57/* Driver exported functions. */
58/*===========================================================================*/
59
60/**
61 * @brief Low level SPI driver initialization.
62 *
63 * @notapi
64 */
65void spi_lld_init(void) {
66
67#if PLATFORM_SPI_USE_SPI1 == TRUE
68 /* Driver initialization.*/
69 spiObjectInit(&SPID1);
70#endif
71}
72
73/**
74 * @brief Configures and activates the SPI peripheral.
75 *
76 * @param[in] spip pointer to the @p SPIDriver object
77 *
78 * @notapi
79 */
80void spi_lld_start(SPIDriver *spip) {
81
82 if (spip->state == SPI_STOP) {
83 /* Enables the peripheral.*/
84#if PLATFORM_SPI_USE_SPI1 == TRUE
85 if (&SPID1 == spip) {
86
87 }
88#endif
89 }
90 /* Configures the peripheral.*/
91
92}
93
94/**
95 * @brief Deactivates the SPI peripheral.
96 *
97 * @param[in] spip pointer to the @p SPIDriver object
98 *
99 * @notapi
100 */
101void spi_lld_stop(SPIDriver *spip) {
102
103 if (spip->state == SPI_READY) {
104 /* Disables the peripheral.*/
105#if PLATFORM_SPI_USE_SPI1 == TRUE
106 if (&SPID1 == spip) {
107
108 }
109#endif
110 }
111}
112
113/**
114 * @brief Asserts the slave select signal and prepares for transfers.
115 *
116 * @param[in] spip pointer to the @p SPIDriver object
117 *
118 * @notapi
119 */
120void spi_lld_select(SPIDriver *spip) {
121
122 (void)spip;
123
124}
125
126/**
127 * @brief Deasserts the slave select signal.
128 * @details The previously selected peripheral is unselected.
129 *
130 * @param[in] spip pointer to the @p SPIDriver object
131 *
132 * @notapi
133 */
134void spi_lld_unselect(SPIDriver *spip) {
135
136 (void)spip;
137
138}
139
140/**
141 * @brief Ignores data on the SPI bus.
142 * @details This asynchronous function starts the transmission of a series of
143 * idle words on the SPI bus and ignores the received data.
144 * @post At the end of the operation the configured callback is invoked.
145 *
146 * @param[in] spip pointer to the @p SPIDriver object
147 * @param[in] n number of words to be ignored
148 *
149 * @notapi
150 */
151void spi_lld_ignore(SPIDriver *spip, size_t n) {
152
153 (void)spip;
154 (void)n;
155
156}
157
158/**
159 * @brief Exchanges data on the SPI bus.
160 * @details This asynchronous function starts a simultaneous transmit/receive
161 * operation.
162 * @post At the end of the operation the configured callback is invoked.
163 * @note The buffers are organized as uint8_t arrays for data sizes below or
164 * equal to 8 bits else it is organized as uint16_t arrays.
165 *
166 * @param[in] spip pointer to the @p SPIDriver object
167 * @param[in] n number of words to be exchanged
168 * @param[in] txbuf the pointer to the transmit buffer
169 * @param[out] rxbuf the pointer to the receive buffer
170 *
171 * @notapi
172 */
173void spi_lld_exchange(SPIDriver *spip, size_t n,
174 const void *txbuf, void *rxbuf) {
175
176 (void)spip;
177 (void)n;
178 (void)txbuf;
179 (void)rxbuf;
180
181}
182
183/**
184 * @brief Sends data over the SPI bus.
185 * @details This asynchronous function starts a transmit operation.
186 * @post At the end of the operation the configured callback is invoked.
187 * @note The buffers are organized as uint8_t arrays for data sizes below or
188 * equal to 8 bits else it is organized as uint16_t arrays.
189 *
190 * @param[in] spip pointer to the @p SPIDriver object
191 * @param[in] n number of words to send
192 * @param[in] txbuf the pointer to the transmit buffer
193 *
194 * @notapi
195 */
196void spi_lld_send(SPIDriver *spip, size_t n, const void *txbuf) {
197
198 (void)spip;
199 (void)n;
200 (void)txbuf;
201
202}
203
204/**
205 * @brief Receives data from the SPI bus.
206 * @details This asynchronous function starts a receive operation.
207 * @post At the end of the operation the configured callback is invoked.
208 * @note The buffers are organized as uint8_t arrays for data sizes below or
209 * equal to 8 bits else it is organized as uint16_t arrays.
210 *
211 * @param[in] spip pointer to the @p SPIDriver object
212 * @param[in] n number of words to receive
213 * @param[out] rxbuf the pointer to the receive buffer
214 *
215 * @notapi
216 */
217void spi_lld_receive(SPIDriver *spip, size_t n, void *rxbuf) {
218
219 (void)spip;
220 (void)n;
221 (void)rxbuf;
222
223}
224
225#if (SPI_SUPPORTS_CIRCULAR == TRUE) || defined(__DOXYGEN__)
226/**
227 * @brief Aborts the ongoing SPI operation, if any.
228 *
229 * @param[in] spip pointer to the @p SPIDriver object
230 *
231 * @notapi
232 */
233void spi_lld_abort(SPIDriver *spip) {
234
235 (void)spip;
236}
237#endif /* SPI_SUPPORTS_CIRCULAR == TRUE */
238
239/**
240 * @brief Exchanges one frame using a polled wait.
241 * @details This synchronous function exchanges one frame using a polled
242 * synchronization method. This function is useful when exchanging
243 * small amount of data on high speed channels, usually in this
244 * situation is much more efficient just wait for completion using
245 * polling than suspending the thread waiting for an interrupt.
246 *
247 * @param[in] spip pointer to the @p SPIDriver object
248 * @param[in] frame the data frame to send over the SPI bus
249 * @return The received data frame from the SPI bus.
250 *
251 * @notapi
252 */
253uint16_t spi_lld_polled_exchange(SPIDriver *spip, uint16_t frame) {
254
255 (void)spip;
256 (void)frame;
257
258 return 0;
259}
260
261#endif /* HAL_USE_SPI == TRUE */
262
263/** @} */