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