ChibiOS/HAL 9.0.0
hal_spi_v2.inc
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.inc
19 * @brief SPI (v2) Driver code.
20 *
21 * @addtogroup SPI_V2
22 * @{
23 */
24
25#if (HAL_USE_SPI == TRUE) || defined(__DOXYGEN__)
26
27/*===========================================================================*/
28/* Driver local definitions. */
29/*===========================================================================*/
30
31/*===========================================================================*/
32/* Driver exported variables. */
33/*===========================================================================*/
34
35/*===========================================================================*/
36/* Driver local variables and types. */
37/*===========================================================================*/
38
39/*===========================================================================*/
40/* Driver local functions. */
41/*===========================================================================*/
42
43/*===========================================================================*/
44/* Driver exported functions. */
45/*===========================================================================*/
46
47/**
48 * @brief SPI Driver initialization.
49 * @note This function is implicitly invoked by @p halInit(), there is
50 * no need to explicitly initialize the driver.
51 *
52 * @init
53 */
54void spiInit(void) {
55
57}
58
59/**
60 * @brief Initializes the standard part of a @p SPIDriver structure.
61 *
62 * @param[out] spip pointer to the @p SPIDriver object
63 *
64 * @init
65 */
67
68 spip->state = SPI_STOP;
69 spip->config = NULL;
70#if SPI_USE_SYNCHRONIZATION == TRUE
71 spip->sync_transfer = NULL;
72#endif
73#if SPI_USE_MUTUAL_EXCLUSION == TRUE
75#endif
76#if defined(SPI_DRIVER_EXT_INIT_HOOK)
77 SPI_DRIVER_EXT_INIT_HOOK(spip);
78#endif
79}
80
81/**
82 * @brief Configures and activates the SPI peripheral.
83 *
84 * @param[in] spip pointer to the @p SPIDriver object
85 * @param[in] config pointer to the @p SPIConfig object
86 * @return The operation status.
87 *
88 * @api
89 */
90msg_t spiStart(SPIDriver *spip, const SPIConfig *config) {
91 msg_t msg;
92
93 osalDbgCheck((spip != NULL) && (config != NULL));
94
96 osalDbgAssert((spip->state == SPI_STOP) || (spip->state == SPI_READY),
97 "invalid state");
98
99 spip->config = config;
100
101 msg = spi_lld_start(spip);
102 if (msg == HAL_RET_SUCCESS) {
103 spip->state = SPI_READY;
104 }
105 else {
106 spip->state = SPI_STOP;
107 }
108
110
111#if SPI_USE_ASSERT_ON_ERROR == TRUE
112 osalDbgAssert(msg == HAL_RET_SUCCESS, "function failed");
113#endif
114
115 return msg;
116}
117
118/**
119 * @brief Deactivates the SPI peripheral.
120 *
121 * @param[in] spip pointer to the @p SPIDriver object
122 *
123 * @api
124 */
125void spiStop(SPIDriver *spip) {
126
127 osalDbgCheck(spip != NULL);
128
129 osalSysLock();
130
131 osalDbgAssert((spip->state == SPI_STOP) || (spip->state == SPI_READY),
132 "invalid state");
133
134 spi_lld_stop(spip);
135 spip->config = NULL;
136 spip->state = SPI_STOP;
137
139}
140
141/**
142 * @brief Asserts the slave select signal and prepares for transfers.
143 *
144 * @param[in] spip pointer to the @p SPIDriver object
145 *
146 * @api
147 */
148void spiSelect(SPIDriver *spip) {
149
150 osalDbgCheck(spip != NULL);
151
152 osalSysLock();
153 osalDbgAssert(spip->state == SPI_READY, "not ready");
154 spiSelectI(spip);
156}
157
158/**
159 * @brief Deasserts the slave select signal.
160 * @details The previously selected peripheral is unselected.
161 *
162 * @param[in] spip pointer to the @p SPIDriver object
163 *
164 * @api
165 */
167
168 osalDbgCheck(spip != NULL);
169
170 osalSysLock();
171 osalDbgAssert(spip->state == SPI_READY, "not ready");
172 spiUnselectI(spip);
174}
175
176/**
177 * @brief Ignores data on the SPI bus.
178 * @details This asynchronous function starts the transmission of a series of
179 * idle words on the SPI bus and ignores the received data.
180 * @pre A slave must have been selected using @p spiSelect() or
181 * @p spiSelectI().
182 * @post At the end of the operation the configured callback is invoked.
183 *
184 * @param[in] spip pointer to the @p SPIDriver object
185 * @param[in] n number of words to be ignored
186 * @return The operation status.
187 *
188 * @iclass
189 */
191 msg_t msg;
192
194
195 osalDbgCheck((spip != NULL) && (n > 0U));
196#if SPI_SUPPORTS_CIRCULAR
197 osalDbgCheck((spip->config->circular == false) || ((n & 1U) == 0U));
198#endif
199
200 osalDbgAssert(spip->state == SPI_READY, "not ready");
201
202 spip->state = SPI_ACTIVE;
203 msg = spi_lld_ignore(spip, n);
204
205#if SPI_USE_ASSERT_ON_ERROR == TRUE
206 osalDbgAssert(msg == HAL_RET_SUCCESS, "function failed");
207#endif
208
209 return msg;
210}
211
212/**
213 * @brief Ignores data on the SPI bus.
214 * @details This asynchronous function starts the transmission of a series of
215 * idle words on the SPI bus and ignores the received data.
216 * @pre A slave must have been selected using @p spiSelect() or
217 * @p spiSelectI().
218 * @post At the end of the operation the configured callback is invoked.
219 *
220 * @param[in] spip pointer to the @p SPIDriver object
221 * @param[in] n number of words to be ignored
222 * @return The operation status.
223 *
224 * @api
225 */
227 msg_t msg;
228
229 osalSysLock();
230 msg = spiStartIgnoreI(spip, n);
232
233 return msg;
234}
235
236/**
237 * @brief Exchanges data on the SPI bus.
238 * @details This asynchronous function starts a simultaneous transmit/receive
239 * operation.
240 * @pre A slave must have been selected using @p spiSelect() or
241 * @p spiSelectI().
242 * @post At the end of the operation the configured callback is invoked.
243 * @note The buffers are organized as uint8_t arrays for data sizes below
244 * or equal to 8 bits else it is organized as uint16_t arrays.
245 *
246 * @param[in] spip pointer to the @p SPIDriver object
247 * @param[in] n number of words to be exchanged
248 * @param[in] txbuf the pointer to the transmit buffer
249 * @param[out] rxbuf the pointer to the receive buffer
250 * @return The operation status.
251 *
252 * @iclass
253 */
255 const void *txbuf, void *rxbuf) {
256 msg_t msg;
257
259
260 osalDbgCheck((spip != NULL) && (n > 0U) &&
261 (rxbuf != NULL) && (txbuf != NULL));
262#if SPI_SUPPORTS_CIRCULAR
263 osalDbgCheck((spip->config->circular == false) || ((n & 1U) == 0U));
264#endif
265
266 osalDbgAssert(spip->state == SPI_READY, "not ready");
267
268 spip->state = SPI_ACTIVE;
269 msg = spi_lld_exchange(spip, n, txbuf, rxbuf);
270
271#if SPI_USE_ASSERT_ON_ERROR == TRUE
272 osalDbgAssert(msg == HAL_RET_SUCCESS, "function failed");
273#endif
274
275 return msg;
276}
277
278/**
279 * @brief Exchanges data on the SPI bus.
280 * @details This asynchronous function starts a simultaneous transmit/receive
281 * operation.
282 * @pre A slave must have been selected using @p spiSelect() or
283 * @p spiSelectI().
284 * @post At the end of the operation the configured callback is invoked.
285 * @note The buffers are organized as uint8_t arrays for data sizes below
286 * or equal to 8 bits else it is organized as uint16_t arrays.
287 *
288 * @param[in] spip pointer to the @p SPIDriver object
289 * @param[in] n number of words to be exchanged
290 * @param[in] txbuf the pointer to the transmit buffer
291 * @param[out] rxbuf the pointer to the receive buffer
292 * @return The operation status.
293 *
294 * @api
295 */
297 const void *txbuf, void *rxbuf) {
298 msg_t msg;
299
300 osalSysLock();
301 msg = spiStartExchangeI(spip, n, txbuf, rxbuf);
303
304 return msg;
305}
306
307/**
308 * @brief Sends data over the SPI bus.
309 * @details This asynchronous function starts a transmit operation.
310 * @pre A slave must have been selected using @p spiSelect() or
311 * @p spiSelectI().
312 * @post At the end of the operation the configured callback is invoked.
313 * @note The buffers are organized as uint8_t arrays for data sizes below
314 * or equal to 8 bits else it is organized as uint16_t arrays.
315 *
316 * @param[in] spip pointer to the @p SPIDriver object
317 * @param[in] n number of words to send
318 * @param[in] txbuf the pointer to the transmit buffer
319 * @return The operation status.
320 *
321 * @iclass
322 */
323msg_t spiStartSendI(SPIDriver *spip, size_t n, const void *txbuf) {
324 msg_t msg;
325
327
328 osalDbgCheck((spip != NULL) && (n > 0U) && (txbuf != NULL));
329#if SPI_SUPPORTS_CIRCULAR
330 osalDbgCheck((spip->config->circular == false) || ((n & 1U) == 0U));
331#endif
332
333 osalDbgAssert(spip->state == SPI_READY, "not ready");
334
335 spip->state = SPI_ACTIVE;
336 msg = spi_lld_send(spip, n, txbuf);
337
338#if SPI_USE_ASSERT_ON_ERROR == TRUE
339 osalDbgAssert(msg == HAL_RET_SUCCESS, "function failed");
340#endif
341
342 return msg;
343}
344
345/**
346 * @brief Sends data over the SPI bus.
347 * @details This asynchronous function starts a transmit operation.
348 * @pre A slave must have been selected using @p spiSelect() or
349 * @p spiSelectI().
350 * @post At the end of the operation the configured callback is invoked.
351 * @note The buffers are organized as uint8_t arrays for data sizes below
352 * or equal to 8 bits else it is organized as uint16_t arrays.
353 *
354 * @param[in] spip pointer to the @p SPIDriver object
355 * @param[in] n number of words to send
356 * @param[in] txbuf the pointer to the transmit buffer
357 * @return The operation status.
358 *
359 * @api
360 */
361msg_t spiStartSend(SPIDriver *spip, size_t n, const void *txbuf) {
362 msg_t msg;
363
364 osalSysLock();
365 msg = spiStartSendI(spip, n, txbuf);
367
368 return msg;
369}
370
371/**
372 * @brief Receives data from the SPI bus.
373 * @details This asynchronous function starts a receive operation.
374 * @pre A slave must have been selected using @p spiSelect() or
375 * @p spiSelectI().
376 * @post At the end of the operation the configured callback is invoked.
377 * @note The buffers are organized as uint8_t arrays for data sizes below
378 * or equal to 8 bits else it is organized as uint16_t arrays.
379 *
380 * @param[in] spip pointer to the @p SPIDriver object
381 * @param[in] n number of words to receive
382 * @param[out] rxbuf the pointer to the receive buffer
383 * @return The operation status.
384 *
385 * @iclass
386 */
387msg_t spiStartReceiveI(SPIDriver *spip, size_t n, void *rxbuf) {
388 msg_t msg;
389
391
392 osalDbgCheck((spip != NULL) && (n > 0U) && (rxbuf != NULL));
393#if SPI_SUPPORTS_CIRCULAR
394 osalDbgCheck((spip->config->circular == false) || ((n & 1U) == 0U));
395#endif
396
397 osalDbgAssert(spip->state == SPI_READY, "not ready");
398
399 spip->state = SPI_ACTIVE;
400 msg = spi_lld_receive(spip, n, rxbuf);
401
402#if SPI_USE_ASSERT_ON_ERROR == TRUE
403 osalDbgAssert(msg == HAL_RET_SUCCESS, "function failed");
404#endif
405
406 return msg;
407}
408
409/**
410 * @brief Receives data from the SPI bus.
411 * @details This asynchronous function starts a receive operation.
412 * @pre A slave must have been selected using @p spiSelect() or
413 * @p spiSelectI().
414 * @post At the end of the operation the configured callback is invoked.
415 * @note The buffers are organized as uint8_t arrays for data sizes below
416 * or equal to 8 bits else it is organized as uint16_t arrays.
417 *
418 * @param[in] spip pointer to the @p SPIDriver object
419 * @param[in] n number of words to receive
420 * @param[out] rxbuf the pointer to the receive buffer
421 * @return The operation status.
422 *
423 * @api
424 */
425msg_t spiStartReceive(SPIDriver *spip, size_t n, void *rxbuf) {
426 msg_t msg;
427
428 osalSysLock();
429 msg = spiStartReceiveI(spip, n, rxbuf);
431
432 return msg;
433}
434
435/**
436 * @brief Stops the ongoing SPI operation.
437 *
438 * @param[in] spip pointer to the @p SPIDriver object
439 * @param[out] sizep pointer to the counter of frames not yet
440 * transferred or @p NULL
441 * @return The operation status.
442 *
443 * @iclass
444 */
445msg_t spiStopTransferI(SPIDriver *spip, size_t *sizep) {
446 msg_t msg;
447
449
450 osalDbgCheck(spip != NULL);
451
452 osalDbgAssert((spip->state == SPI_READY) ||
453 (spip->state == SPI_ACTIVE) ||
454 (spip->state == SPI_COMPLETE),
455 "invalid state");
456
457 if ((spip->state == SPI_ACTIVE) || (spip->state == SPI_COMPLETE)) {
458
459 /* Stopping transfer at low level.*/
460 msg = spi_lld_stop_transfer(spip, sizep);
461 spip->state = SPI_READY;
462
463#if SPI_USE_SYNCHRONIZATION == TRUE
465#endif
466 }
467 else {
468 msg = HAL_RET_SUCCESS;
469 }
470
471 return msg;
472}
473
474/**
475 * @brief Stops the ongoing SPI operation, if any.
476 *
477 * @param[in] spip pointer to the @p SPIDriver object
478 * @param[out] sizep pointer to the counter of frames not yet
479 * transferred or @p NULL
480 * @return The operation status.
481 *
482 * @api
483 */
484msg_t spiStopTransfer(SPIDriver *spip, size_t *sizep) {
485 msg_t msg;
486
487 osalSysLock();
488
489 msg = spiStopTransferI(spip, sizep);
491
493
494 return msg;
495}
496
497#if (SPI_USE_SYNCHRONIZATION == TRUE) || defined(__DOXYGEN__)
498/**
499 * @brief Synchronizes with current transfer completion.
500 * @note This function can only be called by a single thread at time.
501 *
502 * @param[in] spip pointer to the @p SPIDriver object
503 * @param[in] timeout synchronization timeout
504 * @return The synchronization result.
505 * @retval MSG_OK if operation completed without errors.
506 * @retval MSG_TIMEOUT if synchronization timed out.
507 * @retval MSG_RESET if the transfer has been stopped.
508 *
509 * @sclass
510 */
512 msg_t msg;
513
514 osalDbgCheck(spip != NULL);
515 osalDbgAssert((spip->state == SPI_ACTIVE) || (spip->state == SPI_READY),
516 "invalid state");
517
518 if (spip->state == SPI_ACTIVE) {
519 msg = osalThreadSuspendTimeoutS(&spip->sync_transfer, timeout);
520 }
521 else {
522 msg = MSG_OK;
523 }
524
525 return msg;
526}
527
528/**
529 * @brief Synchronizes with current transfer completion.
530 * @note This function can only be called by a single thread at time.
531 *
532 * @param[in] spip pointer to the @p SPIDriver object
533 * @param[in] timeout synchronization timeout
534 * @return The synchronization result.
535 * @retval MSG_OK if operation completed without errors.
536 * @retval MSG_TIMEOUT if synchronization timed out.
537 * @retval MSG_RESET if the transfer has been stopped.
538 *
539 * @api
540 */
542 msg_t msg;
543
544 osalSysLock();
545 msg = spiSynchronizeS(spip, timeout);
547
548 return msg;
549}
550
551/**
552 * @brief Ignores data on the SPI bus.
553 * @details This synchronous function performs the transmission of a series of
554 * idle words on the SPI bus and ignores the received data.
555 * @pre In order to use this function the option @p SPI_USE_SYNCHRONIZATION
556 * must be enabled.
557 *
558 * @param[in] spip pointer to the @p SPIDriver object
559 * @param[in] n number of words to be ignored
560 * @return The operation status.
561 * @retval MSG_OK if operation completed without errors.
562 * @retval MSG_TIMEOUT if synchronization timed out.
563 * @retval MSG_RESET if the transfer has been stopped.
564 *
565 * @api
566 */
567msg_t spiIgnore(SPIDriver *spip, size_t n) {
568 msg_t msg;
569
570 osalSysLock();
571
572 msg = spiStartIgnoreI(spip, n);
573 if (msg == MSG_OK) {
574 msg = spiSynchronizeS(spip, TIME_INFINITE);
575 }
576
578
579 return msg;
580}
581
582/**
583 * @brief Exchanges data on the SPI bus.
584 * @details This synchronous function performs a simultaneous transmit/receive
585 * operation.
586 * @pre In order to use this function the option @p SPI_USE_SYNCHRONIZATION
587 * must be enabled.
588 * @note The buffers are organized as uint8_t arrays for data sizes below
589 * or equal to 8 bits else it is organized as uint16_t arrays.
590 *
591 * @param[in] spip pointer to the @p SPIDriver object
592 * @param[in] n number of words to be exchanged
593 * @param[in] txbuf the pointer to the transmit buffer
594 * @param[out] rxbuf the pointer to the receive buffer
595 * @return The operation status.
596 * @retval MSG_OK if operation completed without errors.
597 * @retval MSG_TIMEOUT if synchronization timed out.
598 * @retval MSG_RESET if the transfer has been stopped.
599 *
600 * @api
601 */
603 const void *txbuf, void *rxbuf) {
604 msg_t msg;
605
606 osalSysLock();
607
608 msg = spiStartExchangeI(spip, n, txbuf, rxbuf);
609 if (msg == MSG_OK) {
610 msg = spiSynchronizeS(spip, TIME_INFINITE);
611 }
612
614
615 return msg;
616}
617
618/**
619 * @brief Sends data over the SPI bus.
620 * @details This synchronous function performs a transmit operation.
621 * @pre In order to use this function the option @p SPI_USE_SYNCHRONIZATION
622 * must be enabled.
623 * @note The buffers are organized as uint8_t arrays for data sizes below
624 * or equal to 8 bits else it is organized as uint16_t arrays.
625 *
626 * @param[in] spip pointer to the @p SPIDriver object
627 * @param[in] n number of words to send
628 * @param[in] txbuf the pointer to the transmit buffer
629 * @return The operation status.
630 * @retval MSG_OK if operation completed without errors.
631 * @retval MSG_TIMEOUT if synchronization timed out.
632 * @retval MSG_RESET if the transfer has been stopped.
633 *
634 * @api
635 */
636msg_t spiSend(SPIDriver *spip, size_t n, const void *txbuf) {
637 msg_t msg;
638
639 osalSysLock();
640
641 msg = spiStartSendI(spip, n, txbuf);
642 if (msg == MSG_OK) {
643 msg = spiSynchronizeS(spip, TIME_INFINITE);
644 }
645
647
648 return msg;
649}
650
651/**
652 * @brief Receives data from the SPI bus.
653 * @details This synchronous function performs a receive operation.
654 * @pre In order to use this function the option @p SPI_USE_SYNCHRONIZATION
655 * must be enabled.
656 * @note The buffers are organized as uint8_t arrays for data sizes below
657 * or equal to 8 bits else it is organized as uint16_t arrays.
658 *
659 * @param[in] spip pointer to the @p SPIDriver object
660 * @param[in] n number of words to receive
661 * @param[out] rxbuf the pointer to the receive buffer
662 * @return The operation status.
663 * @retval MSG_OK if operation completed without errors.
664 * @retval MSG_TIMEOUT if synchronization timed out.
665 * @retval MSG_RESET if the transfer has been stopped.
666 *
667 * @api
668 */
669msg_t spiReceive(SPIDriver *spip, size_t n, void *rxbuf) {
670 msg_t msg;
671
672 osalSysLock();
673
674 msg = spiStartReceiveI(spip, n, rxbuf);
675 if (msg == MSG_OK) {
676 msg = spiSynchronizeS(spip, TIME_INFINITE);
677 }
678
680
681 return msg;
682}
683#endif /* SPI_USE_SYNCHRONIZATION == TRUE */
684
685#if (SPI_USE_MUTUAL_EXCLUSION == TRUE) || defined(__DOXYGEN__)
686/**
687 * @brief Gains exclusive access to the SPI bus.
688 * @details This function tries to gain ownership to the SPI bus, if the bus
689 * is already being used then the invoking thread is queued.
690 * @pre In order to use this function the option @p SPI_USE_MUTUAL_EXCLUSION
691 * must be enabled.
692 *
693 * @param[in] spip pointer to the @p SPIDriver object
694 *
695 * @api
696 */
698
699 osalDbgCheck(spip != NULL);
700
701 osalMutexLock(&spip->mutex);
702}
703
704/**
705 * @brief Releases exclusive access to the SPI bus.
706 * @pre In order to use this function the option @p SPI_USE_MUTUAL_EXCLUSION
707 * must be enabled.
708 *
709 * @param[in] spip pointer to the @p SPIDriver object
710 *
711 * @api
712 */
714
715 osalDbgCheck(spip != NULL);
716
717 osalMutexUnlock(&spip->mutex);
718}
719#endif /* SPI_USE_MUTUAL_EXCLUSION == TRUE */
720
721#endif /* HAL_USE_SPI == TRUE */
722
723/** @} */
#define HAL_RET_SUCCESS
Definition hal.h:93
static void osalSysLock(void)
Enters a critical zone from thread context.
Definition osal.h:601
static void osalMutexObjectInit(mutex_t *mp)
Initializes a mutex_t object.
Definition osal.h:753
static void osalSysUnlock(void)
Leaves a critical zone from thread context.
Definition osal.h:611
int32_t msg_t
Type of a message.
Definition osal.h:159
uint32_t sysinterval_t
Type of system time interval.
Definition osal.h:169
#define MSG_OK
Definition osal.h:56
void osalOsRescheduleS(void)
Checks if a reschedule is required and performs it.
Definition osal.c:119
void osalMutexLock(mutex_t *mp)
Locks the specified mutex.
Definition osal.c:380
void osalThreadResumeI(thread_reference_t *trp, msg_t msg)
Wakes up a thread waiting on a thread reference object.
Definition osal.c:227
#define osalDbgAssert(c, remark)
Condition assertion.
Definition osal.h:264
#define MSG_RESET
Definition osal.h:58
void osalMutexUnlock(mutex_t *mp)
Unlocks the specified mutex.
Definition osal.c:400
msg_t osalThreadSuspendTimeoutS(thread_reference_t *trp, sysinterval_t timeout)
Sends the current thread sleeping and sets a reference variable.
Definition osal.c:208
#define osalDbgCheck(c)
Function parameters check.
Definition osal.h:284
#define TIME_INFINITE
Definition osal.h:66
#define osalDbgCheckClassI()
I-Class state check.
Definition osal.h:298
#define spiUnselectI(spip)
Deasserts the slave select signal.
Definition hal_spi_v1.h:254
void spi_lld_ignore(SPIDriver *spip, size_t n)
Ignores data on the SPI bus.
#define spiStartReceiveI(spip, n, rxbuf)
Receives data from the SPI bus.
Definition hal_spi_v1.h:373
struct hal_spi_config SPIConfig
Type of a SPI driver configuration structure.
Definition hal_spi_v1.h:121
#define spiStartExchangeI(spip, n, txbuf, rxbuf)
Exchanges data on the SPI bus.
Definition hal_spi_v1.h:333
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 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
#define spiStartSendI(spip, n, txbuf)
Sends data over the SPI bus.
Definition hal_spi_v1.h:353
#define spiStartIgnoreI(spip, n)
Ignores data on the SPI bus.
Definition hal_spi_v1.h:311
void spi_lld_start(SPIDriver *spip)
Configures and activates the SPI peripheral.
Definition hal_spi_lld.c:80
#define spiSelectI(spip)
Asserts the slave select signal and prepares for transfers.
Definition hal_spi_v1.h:241
@ SPI_ACTIVE
Definition hal_spi_v1.h:110
@ SPI_STOP
Definition hal_spi_v1.h:108
@ SPI_READY
Definition hal_spi_v1.h:109
@ SPI_COMPLETE
Definition hal_spi_v1.h:111
void spiSelect(SPIDriver *spip)
Asserts the slave select signal and prepares for transfers.
void spiReleaseBus(SPIDriver *spip)
Releases exclusive access to the SPI bus.
void spiInit(void)
SPI Driver initialization.
msg_t spiExchange(SPIDriver *spip, size_t n, const void *txbuf, void *rxbuf)
Exchanges data on the SPI bus.
msg_t spiIgnore(SPIDriver *spip, size_t n)
Ignores data on the SPI bus.
msg_t spi_lld_stop_transfer(SPIDriver *spip, size_t *sizep)
Aborts the ongoing SPI operation, if any.
void spiAcquireBus(SPIDriver *spip)
Gains exclusive access to the SPI bus.
void spiObjectInit(SPIDriver *spip)
Initializes the standard part of a SPIDriver structure.
msg_t spiStartSend(SPIDriver *spip, size_t n, const void *txbuf)
Sends data over the SPI bus.
msg_t spiStart(SPIDriver *spip, const SPIConfig *config)
Configures and activates the SPI peripheral.
msg_t spiSend(SPIDriver *spip, size_t n, const void *txbuf)
Sends data over the SPI bus.
msg_t spiStopTransfer(SPIDriver *spip, size_t *sizep)
Stops the ongoing SPI operation, if any.
msg_t spiStartIgnore(SPIDriver *spip, size_t n)
Ignores data on the SPI bus.
msg_t spiStopTransferI(SPIDriver *spip, size_t *sizep)
Stops the ongoing SPI operation.
void spiStop(SPIDriver *spip)
Deactivates the SPI peripheral.
msg_t spiStartReceive(SPIDriver *spip, size_t n, void *rxbuf)
Receives data from the SPI bus.
void spiUnselect(SPIDriver *spip)
Deasserts the slave select signal.
msg_t spiSynchronizeS(SPIDriver *spip, sysinterval_t timeout)
Synchronizes with current transfer completion.
msg_t spiStartExchange(SPIDriver *spip, size_t n, const void *txbuf, void *rxbuf)
Exchanges data on the SPI bus.
msg_t spiSynchronize(SPIDriver *spip, sysinterval_t timeout)
Synchronizes with current transfer completion.
msg_t spiReceive(SPIDriver *spip, size_t n, void *rxbuf)
Receives data from the SPI bus.
bool circular
Enables the circular buffer mode.
Definition hal_spi_v1.h:143
const SPIConfig * config
Current configuration data.
Definition hal_spi_v1.h:190
thread_reference_t sync_transfer
Synchronization point for transfer.
Definition hal_spi_v2.h:227
mutex_t mutex
Mutex protecting the peripheral.
Definition hal_spi_v1.h:201
spistate_t state
Driver state.
Definition hal_spi_v1.h:186