ChibiOS 21.11.4
hal_spi_lld.c
Go to the documentation of this file.
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 (v1) subsystem low level driver source.
20 *
21 * @addtogroup SPI_V1
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__)
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.*/
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 */
81
82 if (spip->state == SPI_STOP) {
83
84 /* Enables the peripheral.*/
85 if (false) {
86 }
87
88#if PLATFORM_SPI_USE_SPI1 == TRUE
89 if (&SPID1 == spip) {
90
91 }
92#endif
93
94 else {
95 osalDbgAssert(false, "invalid SPI instance");
96 }
97 }
98
99 /* Configures the peripheral.*/
100
101}
102
103/**
104 * @brief Deactivates the SPI peripheral.
105 *
106 * @param[in] spip pointer to the @p SPIDriver object
107 *
108 * @notapi
109 */
111
112 if (spip->state == SPI_READY) {
113
114 /* Disables the peripheral.*/
115 if (false) {
116 }
117
118#if PLATFORM_SPI_USE_SPI1 == TRUE
119 if (&SPID1 == spip) {
120
121 }
122#endif
123
124 else {
125 osalDbgAssert(false, "invalid SPI instance");
126 }
127 }
128}
129
130#if (SPI_SELECT_MODE == SPI_SELECT_MODE_LLD) || defined(__DOXYGEN__)
131/**
132 * @brief Asserts the slave select signal and prepares for transfers.
133 *
134 * @param[in] spip pointer to the @p SPIDriver object
135 *
136 * @notapi
137 */
139
140 (void)spip;
141
142}
143
144/**
145 * @brief Deasserts the slave select signal.
146 * @details The previously selected peripheral is unselected.
147 *
148 * @param[in] spip pointer to the @p SPIDriver object
149 *
150 * @notapi
151 */
153
154 (void)spip;
155
156}
157#endif
158
159/**
160 * @brief Ignores data on the SPI bus.
161 * @details This asynchronous function starts the transmission of a series of
162 * idle words on the SPI bus and ignores the received data.
163 * @post At the end of the operation the configured callback is invoked.
164 *
165 * @param[in] spip pointer to the @p SPIDriver object
166 * @param[in] n number of words to be ignored
167 *
168 * @notapi
169 */
170void spi_lld_ignore(SPIDriver *spip, size_t n) {
171
172 (void)spip;
173 (void)n;
174
175}
176
177/**
178 * @brief Exchanges data on the SPI bus.
179 * @details This asynchronous function starts a simultaneous transmit/receive
180 * operation.
181 * @post At the end of the operation the configured callback is invoked.
182 * @note The buffers are organized as uint8_t arrays for data sizes below or
183 * equal to 8 bits else it is organized as uint16_t arrays.
184 *
185 * @param[in] spip pointer to the @p SPIDriver object
186 * @param[in] n number of words to be exchanged
187 * @param[in] txbuf the pointer to the transmit buffer
188 * @param[out] rxbuf the pointer to the receive buffer
189 *
190 * @notapi
191 */
192void spi_lld_exchange(SPIDriver *spip, size_t n,
193 const void *txbuf, void *rxbuf) {
194
195 (void)spip;
196 (void)n;
197 (void)txbuf;
198 (void)rxbuf;
199
200}
201
202/**
203 * @brief Sends data over the SPI bus.
204 * @details This asynchronous function starts a transmit operation.
205 * @post At the end of the operation the configured callback is invoked.
206 * @note The buffers are organized as uint8_t arrays for data sizes below or
207 * equal to 8 bits else it is organized as uint16_t arrays.
208 *
209 * @param[in] spip pointer to the @p SPIDriver object
210 * @param[in] n number of words to send
211 * @param[in] txbuf the pointer to the transmit buffer
212 *
213 * @notapi
214 */
215void spi_lld_send(SPIDriver *spip, size_t n, const void *txbuf) {
216
217 (void)spip;
218 (void)n;
219 (void)txbuf;
220
221}
222
223/**
224 * @brief Receives data from the SPI bus.
225 * @details This asynchronous function starts a receive operation.
226 * @post At the end of the operation the configured callback is invoked.
227 * @note The buffers are organized as uint8_t arrays for data sizes below or
228 * equal to 8 bits else it is organized as uint16_t arrays.
229 *
230 * @param[in] spip pointer to the @p SPIDriver object
231 * @param[in] n number of words to receive
232 * @param[out] rxbuf the pointer to the receive buffer
233 *
234 * @notapi
235 */
236void spi_lld_receive(SPIDriver *spip, size_t n, void *rxbuf) {
237
238 (void)spip;
239 (void)n;
240 (void)rxbuf;
241
242}
243
244#if (SPI_SUPPORTS_CIRCULAR == TRUE) || defined(__DOXYGEN__)
245/**
246 * @brief Aborts the ongoing SPI operation, if any.
247 *
248 * @param[in] spip pointer to the @p SPIDriver object
249 *
250 * @notapi
251 */
253
254 (void)spip;
255}
256#endif /* SPI_SUPPORTS_CIRCULAR == TRUE */
257
258/**
259 * @brief Exchanges one frame using a polled wait.
260 * @details This synchronous function exchanges one frame using a polled
261 * synchronization method. This function is useful when exchanging
262 * small amount of data on high speed channels, usually in this
263 * situation is much more efficient just wait for completion using
264 * polling than suspending the thread waiting for an interrupt.
265 *
266 * @param[in] spip pointer to the @p SPIDriver object
267 * @param[in] frame the data frame to send over the SPI bus
268 * @return The received data frame from the SPI bus.
269 *
270 * @notapi
271 */
272uint16_t spi_lld_polled_exchange(SPIDriver *spip, uint16_t frame) {
273
274 (void)spip;
275 (void)frame;
276
277 return 0;
278}
279
280#endif /* HAL_USE_SPI == TRUE */
281
282/** @} */
#define osalDbgAssert(c, remark)
Condition assertion.
Definition osal.h:264
void spi_lld_ignore(SPIDriver *spip, size_t n)
Ignores data on the SPI bus.
SPIDriver SPID1
SPI1 driver identifier.
Definition hal_spi_lld.c:41
void spi_lld_abort(SPIDriver *spip)
Aborts the ongoing SPI operation, if any.
void spi_lld_select(SPIDriver *spip)
Asserts the slave select signal and prepares for transfers.
void spi_lld_receive(SPIDriver *spip, size_t n, void *rxbuf)
Receives data from the SPI bus.
void spi_lld_init(void)
Low level SPI driver initialization.
Definition hal_spi_lld.c:65
void spi_lld_exchange(SPIDriver *spip, size_t n, const void *txbuf, void *rxbuf)
Exchanges data on the SPI bus.
void spiObjectInit(SPIDriver *spip)
Initializes the standard part of a SPIDriver structure.
void spi_lld_stop(SPIDriver *spip)
Deactivates the SPI peripheral.
void spi_lld_send(SPIDriver *spip, size_t n, const void *txbuf)
Sends data over the SPI bus.
struct hal_spi_driver SPIDriver
Type of a structure representing an SPI driver.
Definition hal_spi_v1.h:117
uint16_t spi_lld_polled_exchange(SPIDriver *spip, uint16_t frame)
Exchanges one frame using a polled wait.
void spi_lld_start(SPIDriver *spip)
Configures and activates the SPI peripheral.
Definition hal_spi_lld.c:80
void spi_lld_unselect(SPIDriver *spip)
Deasserts the slave select signal.
@ SPI_STOP
Definition hal_spi_v1.h:108
@ SPI_READY
Definition hal_spi_v1.h:109
HAL subsystem header.
spistate_t state
Driver state.
Definition hal_spi_v1.h:186