Zephyr Project API 3.7.0
A Scalable Open Source RTOS
Loading...
Searching...
No Matches
spi.h
Go to the documentation of this file.
1/*
2 * Copyright (c) 2015 Intel Corporation
3 *
4 * SPDX-License-Identifier: Apache-2.0
5 */
6
12#ifndef ZEPHYR_INCLUDE_DRIVERS_SPI_H_
13#define ZEPHYR_INCLUDE_DRIVERS_SPI_H_
14
24#include <zephyr/types.h>
25#include <stddef.h>
26#include <zephyr/device.h>
28#include <zephyr/drivers/gpio.h>
29#include <zephyr/kernel.h>
30#include <zephyr/sys/__assert.h>
31#include <zephyr/rtio/rtio.h>
32#include <zephyr/stats/stats.h>
33
34#ifdef __cplusplus
35extern "C" {
36#endif
37
42#define SPI_OP_MODE_MASTER 0U
43#define SPI_OP_MODE_SLAVE BIT(0)
45#define SPI_OP_MODE_MASK 0x1U
48#define SPI_OP_MODE_GET(_operation_) ((_operation_) & SPI_OP_MODE_MASK)
61#define SPI_MODE_CPOL BIT(1)
62
70#define SPI_MODE_CPHA BIT(2)
71
77#define SPI_MODE_LOOP BIT(3)
79#define SPI_MODE_MASK (0xEU)
82#define SPI_MODE_GET(_mode_) \
83 ((_mode_) & SPI_MODE_MASK)
84
91#define SPI_TRANSFER_MSB (0U)
92#define SPI_TRANSFER_LSB BIT(4)
100#define SPI_WORD_SIZE_SHIFT (5U)
101#define SPI_WORD_SIZE_MASK (0x3FU << SPI_WORD_SIZE_SHIFT)
104#define SPI_WORD_SIZE_GET(_operation_) \
105 (((_operation_) & SPI_WORD_SIZE_MASK) >> SPI_WORD_SIZE_SHIFT)
107#define SPI_WORD_SET(_word_size_) \
108 ((_word_size_) << SPI_WORD_SIZE_SHIFT)
116#define SPI_HOLD_ON_CS BIT(12)
122#define SPI_LOCK_ON BIT(13)
123
131#define SPI_CS_ACTIVE_HIGH BIT(14)
143#define SPI_LINES_SINGLE (0U << 16)
144#define SPI_LINES_DUAL (1U << 16)
145#define SPI_LINES_QUAD (2U << 16)
146#define SPI_LINES_OCTAL (3U << 16)
148#define SPI_LINES_MASK (0x3U << 16)
174
212#define SPI_CS_GPIOS_DT_SPEC_GET(spi_dev) \
213 GPIO_DT_SPEC_GET_BY_IDX_OR(DT_BUS(spi_dev), cs_gpios, \
214 DT_REG_ADDR(spi_dev), {})
215
225#define SPI_CS_GPIOS_DT_SPEC_INST_GET(inst) \
226 SPI_CS_GPIOS_DT_SPEC_GET(DT_DRV_INST(inst))
227
266#define SPI_CS_CONTROL_INIT(node_id, delay_) \
267 { \
268 .gpio = SPI_CS_GPIOS_DT_SPEC_GET(node_id), \
269 .delay = (delay_), \
270 }
271
285#define SPI_CS_CONTROL_INIT_INST(inst, delay_) \
286 SPI_CS_CONTROL_INIT(DT_DRV_INST(inst), delay_)
287
292#if defined(CONFIG_SPI_EXTENDED_MODES)
294#else
296#endif
297
333
347#define SPI_CONFIG_DT(node_id, operation_, delay_) \
348 { \
349 .frequency = DT_PROP(node_id, spi_max_frequency), \
350 .operation = (operation_) | \
351 DT_PROP(node_id, duplex) | \
352 DT_PROP(node_id, frame_format) | \
353 COND_CODE_1(DT_PROP(node_id, spi_cpol), SPI_MODE_CPOL, (0)) | \
354 COND_CODE_1(DT_PROP(node_id, spi_cpha), SPI_MODE_CPHA, (0)) | \
355 COND_CODE_1(DT_PROP(node_id, spi_hold_cs), SPI_HOLD_ON_CS, (0)), \
356 .slave = DT_REG_ADDR(node_id), \
357 .cs = SPI_CS_CONTROL_INIT(node_id, delay_), \
358 }
359
371#define SPI_CONFIG_DT_INST(inst, operation_, delay_) \
372 SPI_CONFIG_DT(DT_DRV_INST(inst), operation_, delay_)
373
379 const struct device *bus;
382};
383
401#define SPI_DT_SPEC_GET(node_id, operation_, delay_) \
402 { \
403 .bus = DEVICE_DT_GET(DT_BUS(node_id)), \
404 .config = SPI_CONFIG_DT(node_id, operation_, delay_) \
405 }
406
418#define SPI_DT_SPEC_INST_GET(inst, operation_, delay_) \
419 SPI_DT_SPEC_GET(DT_DRV_INST(inst), operation_, delay_)
420
424struct spi_buf {
426 void *buf;
431 size_t len;
432};
433
439 const struct spi_buf *buffers;
441 size_t count;
442};
443
444#if defined(CONFIG_SPI_STATS)
446STATS_SECT_ENTRY32(rx_bytes)
447STATS_SECT_ENTRY32(tx_bytes)
448STATS_SECT_ENTRY32(transfer_error)
450
452STATS_NAME(spi, rx_bytes)
453STATS_NAME(spi, tx_bytes)
454STATS_NAME(spi, transfer_error)
455STATS_NAME_END(spi);
456
460struct spi_device_state {
461 struct device_state devstate;
462 struct stats_spi stats;
463};
464
468#define Z_SPI_GET_STATS(dev_) \
469 CONTAINER_OF(dev_->state, struct spi_device_state, devstate)->stats
470
476#define SPI_STATS_RX_BYTES_INCN(dev_, n) \
477 STATS_INCN(Z_SPI_GET_STATS(dev_), rx_bytes, n)
478
484#define SPI_STATS_TX_BYTES_INCN(dev_, n) \
485 STATS_INCN(Z_SPI_GET_STATS(dev_), tx_bytes, n)
486
494#define SPI_STATS_TRANSFER_ERROR_INC(dev_) \
495 STATS_INC(Z_SPI_GET_STATS(dev_), transfer_error)
496
500#define Z_SPI_DEVICE_STATE_DEFINE(dev_id) \
501 static struct spi_device_state Z_DEVICE_STATE_NAME(dev_id) \
502 __attribute__((__section__(".z_devstate")));
503
510#define Z_SPI_INIT_FN(dev_id, init_fn) \
511 static inline int UTIL_CAT(dev_id, _init)(const struct device *dev) \
512 { \
513 struct spi_device_state *state = \
514 CONTAINER_OF(dev->state, struct spi_device_state, devstate); \
515 stats_init(&state->stats.s_hdr, STATS_SIZE_32, 3, \
516 STATS_NAME_INIT_PARMS(spi)); \
517 stats_register(dev->name, &(state->stats.s_hdr)); \
518 return init_fn(dev); \
519 }
520
540#define SPI_DEVICE_DT_DEFINE(node_id, init_fn, pm_device, \
541 data_ptr, cfg_ptr, level, prio, \
542 api_ptr, ...) \
543 Z_SPI_DEVICE_STATE_DEFINE(Z_DEVICE_DT_DEV_ID(node_id)); \
544 Z_SPI_INIT_FN(Z_DEVICE_DT_DEV_ID(node_id), init_fn) \
545 Z_DEVICE_DEFINE(node_id, Z_DEVICE_DT_DEV_ID(node_id), \
546 DEVICE_DT_NAME(node_id), \
547 &UTIL_CAT(Z_DEVICE_DT_DEV_ID(node_id), _init), \
548 pm_device, \
549 data_ptr, cfg_ptr, level, prio, \
550 api_ptr, \
551 &(Z_DEVICE_STATE_NAME(Z_DEVICE_DT_DEV_ID(node_id)).devstate), \
552 __VA_ARGS__)
553
554static inline void spi_transceive_stats(const struct device *dev, int error,
555 const struct spi_buf_set *tx_bufs,
556 const struct spi_buf_set *rx_bufs)
557{
558 uint32_t tx_bytes;
559 uint32_t rx_bytes;
560
561 if (error) {
563 }
564
565 if (tx_bufs) {
566 tx_bytes = tx_bufs->count ? tx_bufs->buffers->len : 0;
567 SPI_STATS_TX_BYTES_INCN(dev, tx_bytes);
568 }
569
570 if (rx_bufs) {
571 rx_bytes = rx_bufs->count ? rx_bufs->buffers->len : 0;
572 SPI_STATS_RX_BYTES_INCN(dev, rx_bytes);
573 }
574}
575
576#else /*CONFIG_SPI_STATS*/
577
578#define SPI_DEVICE_DT_DEFINE(node_id, init_fn, pm, \
579 data, config, level, prio, \
580 api, ...) \
581 Z_DEVICE_STATE_DEFINE(Z_DEVICE_DT_DEV_ID(node_id)); \
582 Z_DEVICE_DEFINE(node_id, Z_DEVICE_DT_DEV_ID(node_id), \
583 DEVICE_DT_NAME(node_id), init_fn, pm, data, config, \
584 level, prio, api, \
585 &Z_DEVICE_STATE_NAME(Z_DEVICE_DT_DEV_ID(node_id)), \
586 __VA_ARGS__)
587
588#define SPI_STATS_RX_BYTES_INC(dev_)
589#define SPI_STATS_TX_BYTES_INC(dev_)
590#define SPI_STATS_TRANSFER_ERROR_INC(dev_)
591
592#define spi_transceive_stats(dev, error, tx_bufs, rx_bufs)
593
594#endif /*CONFIG_SPI_STATS*/
595
601typedef int (*spi_api_io)(const struct device *dev,
602 const struct spi_config *config,
603 const struct spi_buf_set *tx_bufs,
604 const struct spi_buf_set *rx_bufs);
605
613typedef void (*spi_callback_t)(const struct device *dev, int result, void *data);
614
620typedef int (*spi_api_io_async)(const struct device *dev,
621 const struct spi_config *config,
622 const struct spi_buf_set *tx_bufs,
623 const struct spi_buf_set *rx_bufs,
625 void *userdata);
626
627#if defined(CONFIG_SPI_RTIO) || defined(DOXYGEN)
628
633typedef void (*spi_api_iodev_submit)(const struct device *dev,
634 struct rtio_iodev_sqe *iodev_sqe);
635#endif /* CONFIG_SPI_RTIO */
636
642typedef int (*spi_api_release)(const struct device *dev,
643 const struct spi_config *config);
644
645
650__subsystem struct spi_driver_api {
652#ifdef CONFIG_SPI_ASYNC
653 spi_api_io_async transceive_async;
654#endif /* CONFIG_SPI_ASYNC */
655#ifdef CONFIG_SPI_RTIO
656 spi_api_iodev_submit iodev_submit;
657#endif /* CONFIG_SPI_RTIO */
659};
660
668static inline bool spi_cs_is_gpio(const struct spi_config *config)
669{
670 return config->cs.gpio.port != NULL;
671}
672
680static inline bool spi_cs_is_gpio_dt(const struct spi_dt_spec *spec)
681{
682 return spi_cs_is_gpio(&spec->config);
683}
684
693static inline bool spi_is_ready_dt(const struct spi_dt_spec *spec)
694{
695 /* Validate bus is ready */
696 if (!device_is_ready(spec->bus)) {
697 return false;
698 }
699 /* Validate CS gpio port is ready, if it is used */
700 if (spi_cs_is_gpio_dt(spec) &&
701 !gpio_is_ready_dt(&spec->config.cs.gpio)) {
702 return false;
703 }
704 return true;
705}
706
725__syscall int spi_transceive(const struct device *dev,
726 const struct spi_config *config,
727 const struct spi_buf_set *tx_bufs,
728 const struct spi_buf_set *rx_bufs);
729
730static inline int z_impl_spi_transceive(const struct device *dev,
731 const struct spi_config *config,
732 const struct spi_buf_set *tx_bufs,
733 const struct spi_buf_set *rx_bufs)
734{
735 const struct spi_driver_api *api =
736 (const struct spi_driver_api *)dev->api;
737 int ret;
738
739 ret = api->transceive(dev, config, tx_bufs, rx_bufs);
740 spi_transceive_stats(dev, ret, tx_bufs, rx_bufs);
741
742 return ret;
743}
744
760static inline int spi_transceive_dt(const struct spi_dt_spec *spec,
761 const struct spi_buf_set *tx_bufs,
762 const struct spi_buf_set *rx_bufs)
763{
764 return spi_transceive(spec->bus, &spec->config, tx_bufs, rx_bufs);
765}
766
784static inline int spi_read(const struct device *dev,
785 const struct spi_config *config,
786 const struct spi_buf_set *rx_bufs)
787{
788 return spi_transceive(dev, config, NULL, rx_bufs);
789}
790
803static inline int spi_read_dt(const struct spi_dt_spec *spec,
804 const struct spi_buf_set *rx_bufs)
805{
806 return spi_read(spec->bus, &spec->config, rx_bufs);
807}
808
825static inline int spi_write(const struct device *dev,
826 const struct spi_config *config,
827 const struct spi_buf_set *tx_bufs)
828{
829 return spi_transceive(dev, config, tx_bufs, NULL);
830}
831
844static inline int spi_write_dt(const struct spi_dt_spec *spec,
845 const struct spi_buf_set *tx_bufs)
846{
847 return spi_write(spec->bus, &spec->config, tx_bufs);
848}
849
850#if defined(CONFIG_SPI_ASYNC) || defined(__DOXYGEN__)
851
878static inline int spi_transceive_cb(const struct device *dev,
879 const struct spi_config *config,
880 const struct spi_buf_set *tx_bufs,
881 const struct spi_buf_set *rx_bufs,
882 spi_callback_t callback,
883 void *userdata)
884{
885 const struct spi_driver_api *api =
886 (const struct spi_driver_api *)dev->api;
887
888 return api->transceive_async(dev, config, tx_bufs, rx_bufs, callback, userdata);
889}
890
891#if defined(CONFIG_POLL) || defined(__DOXYGEN__)
892
894void z_spi_transfer_signal_cb(const struct device *dev, int result, void *userdata);
922static inline int spi_transceive_signal(const struct device *dev,
923 const struct spi_config *config,
924 const struct spi_buf_set *tx_bufs,
925 const struct spi_buf_set *rx_bufs,
926 struct k_poll_signal *sig)
927{
928 const struct spi_driver_api *api =
929 (const struct spi_driver_api *)dev->api;
930 spi_callback_t cb = (sig == NULL) ? NULL : z_spi_transfer_signal_cb;
931
932 return api->transceive_async(dev, config, tx_bufs, rx_bufs, cb, sig);
933}
934
959static inline int spi_read_signal(const struct device *dev,
960 const struct spi_config *config,
961 const struct spi_buf_set *rx_bufs,
962 struct k_poll_signal *sig)
963{
964 return spi_transceive_signal(dev, config, NULL, rx_bufs, sig);
965}
966
990static inline int spi_write_signal(const struct device *dev,
991 const struct spi_config *config,
992 const struct spi_buf_set *tx_bufs,
993 struct k_poll_signal *sig)
994{
995 return spi_transceive_signal(dev, config, tx_bufs, NULL, sig);
996}
997
998#endif /* CONFIG_POLL */
999
1000#endif /* CONFIG_SPI_ASYNC */
1001
1002
1003#if defined(CONFIG_SPI_RTIO) || defined(__DOXYGEN__)
1004
1012static inline void spi_iodev_submit(struct rtio_iodev_sqe *iodev_sqe)
1013{
1014 const struct spi_dt_spec *dt_spec = iodev_sqe->sqe.iodev->data;
1015 const struct device *dev = dt_spec->bus;
1016 const struct spi_driver_api *api = (const struct spi_driver_api *)dev->api;
1017
1018 api->iodev_submit(dt_spec->bus, iodev_sqe);
1019}
1020
1021extern const struct rtio_iodev_api spi_iodev_api;
1022
1034#define SPI_DT_IODEV_DEFINE(name, node_id, operation_, delay_) \
1035 const struct spi_dt_spec _spi_dt_spec_##name = \
1036 SPI_DT_SPEC_GET(node_id, operation_, delay_); \
1037 RTIO_IODEV_DEFINE(name, &spi_iodev_api, (void *)&_spi_dt_spec_##name)
1038
1047static inline bool spi_is_ready_iodev(const struct rtio_iodev *spi_iodev)
1048{
1049 struct spi_dt_spec *spec = spi_iodev->data;
1050
1051 return spi_is_ready_dt(spec);
1052}
1053
1066static inline int spi_rtio_copy(struct rtio *r,
1067 struct rtio_iodev *iodev,
1068 const struct spi_buf_set *tx_bufs,
1069 const struct spi_buf_set *rx_bufs,
1070 struct rtio_sqe **last_sqe)
1071{
1072 int ret = 0;
1073 size_t tx_count = tx_bufs ? tx_bufs->count : 0;
1074 size_t rx_count = rx_bufs ? rx_bufs->count : 0;
1075
1076 uint32_t tx = 0, tx_len = 0;
1077 uint32_t rx = 0, rx_len = 0;
1078 uint8_t *tx_buf, *rx_buf;
1079
1080 struct rtio_sqe *sqe = NULL;
1081
1082 if (tx < tx_count) {
1083 tx_buf = tx_bufs->buffers[tx].buf;
1084 tx_len = tx_bufs->buffers[tx].len;
1085 } else {
1086 tx_buf = NULL;
1087 tx_len = rx_bufs->buffers[rx].len;
1088 }
1089
1090 if (rx < rx_count) {
1091 rx_buf = rx_bufs->buffers[rx].buf;
1092 rx_len = rx_bufs->buffers[rx].len;
1093 } else {
1094 rx_buf = NULL;
1095 rx_len = tx_bufs->buffers[tx].len;
1096 }
1097
1098
1099 while ((tx < tx_count || rx < rx_count) && (tx_len > 0 || rx_len > 0)) {
1100 sqe = rtio_sqe_acquire(r);
1101
1102 if (sqe == NULL) {
1103 ret = -ENOMEM;
1105 goto out;
1106 }
1107
1108 ret++;
1109
1110 /* If tx/rx len are same, we can do a simple transceive */
1111 if (tx_len == rx_len) {
1112 if (tx_buf == NULL) {
1114 rx_buf, rx_len, NULL);
1115 } else if (rx_buf == NULL) {
1117 tx_buf, tx_len, NULL);
1118 } else {
1120 tx_buf, rx_buf, rx_len, NULL);
1121 }
1122 tx++;
1123 rx++;
1124 if (rx < rx_count) {
1125 rx_buf = rx_bufs->buffers[rx].buf;
1126 rx_len = rx_bufs->buffers[rx].len;
1127 } else {
1128 rx_buf = NULL;
1129 rx_len = 0;
1130 }
1131 if (tx < tx_count) {
1132 tx_buf = tx_bufs->buffers[tx].buf;
1133 tx_len = tx_bufs->buffers[tx].len;
1134 } else {
1135 tx_buf = NULL;
1136 tx_len = 0;
1137 }
1138 } else if (tx_len == 0) {
1140 (uint8_t *)rx_buf,
1141 (uint32_t)rx_len,
1142 NULL);
1143 rx++;
1144 if (rx < rx_count) {
1145 rx_buf = rx_bufs->buffers[rx].buf;
1146 rx_len = rx_bufs->buffers[rx].len;
1147 } else {
1148 rx_buf = NULL;
1149 rx_len = 0;
1150 }
1151 } else if (rx_len == 0) {
1153 (uint8_t *)tx_buf,
1154 (uint32_t)tx_len,
1155 NULL);
1156 tx++;
1157 if (tx < tx_count) {
1158 tx_buf = rx_bufs->buffers[rx].buf;
1159 tx_len = rx_bufs->buffers[rx].len;
1160 } else {
1161 tx_buf = NULL;
1162 tx_len = 0;
1163 }
1164 } else if (tx_len > rx_len) {
1166 (uint8_t *)tx_buf,
1167 (uint8_t *)rx_buf,
1168 (uint32_t)rx_len,
1169 NULL);
1170 tx_len -= rx_len;
1171 tx_buf += rx_len;
1172 rx++;
1173 if (rx < rx_count) {
1174 rx_buf = rx_bufs->buffers[rx].buf;
1175 rx_len = rx_bufs->buffers[rx].len;
1176 } else {
1177 rx_buf = NULL;
1178 rx_len = tx_len;
1179 }
1180 } else if (rx_len > tx_len) {
1182 (uint8_t *)tx_buf,
1183 (uint8_t *)rx_buf,
1184 (uint32_t)tx_len,
1185 NULL);
1186 rx_len -= tx_len;
1187 rx_buf += tx_len;
1188 tx++;
1189 if (tx < tx_count) {
1190 tx_buf = tx_bufs->buffers[tx].buf;
1191 tx_len = tx_bufs->buffers[tx].len;
1192 } else {
1193 tx_buf = NULL;
1194 tx_len = rx_len;
1195 }
1196 } else {
1197 __ASSERT_NO_MSG("Invalid spi_rtio_copy state");
1198 }
1199
1201 }
1202
1203 if (sqe != NULL) {
1204 sqe->flags = 0;
1205 *last_sqe = sqe;
1206 }
1207
1208out:
1209 return ret;
1210}
1211
1212#endif /* CONFIG_SPI_RTIO */
1213
1234__syscall int spi_release(const struct device *dev,
1235 const struct spi_config *config);
1236
1237static inline int z_impl_spi_release(const struct device *dev,
1238 const struct spi_config *config)
1239{
1240 const struct spi_driver_api *api =
1241 (const struct spi_driver_api *)dev->api;
1242
1243 return api->release(dev, config);
1244}
1245
1257static inline int spi_release_dt(const struct spi_dt_spec *spec)
1258{
1259 return spi_release(spec->bus, &spec->config);
1260}
1261
1262#ifdef __cplusplus
1263}
1264#endif
1265
1270#include <zephyr/syscalls/spi.h>
1271
1272#endif /* ZEPHYR_INCLUDE_DRIVERS_SPI_H_ */
workaround assembler barfing for ST r
Definition asm-macro-32-bit-gnu.h:24
Public APIs for GPIO drivers.
bool device_is_ready(const struct device *dev)
Verify that a device is ready for use.
static bool gpio_is_ready_dt(const struct gpio_dt_spec *spec)
Validate that GPIO port is ready.
Definition gpio.h:835
#define RTIO_SQE_TRANSACTION
The next request in the queue is part of a transaction.
Definition rtio.h:108
#define RTIO_PRIO_NORM
Normal priority.
Definition rtio.h:70
static void rtio_sqe_prep_transceive(struct rtio_sqe *sqe, const struct rtio_iodev *iodev, int8_t prio, uint8_t *tx_buf, uint8_t *rx_buf, uint32_t buf_len, void *userdata)
Prepare a transceive op submission.
Definition rtio.h:605
static void rtio_sqe_prep_read(struct rtio_sqe *sqe, const struct rtio_iodev *iodev, int8_t prio, uint8_t *buf, uint32_t len, void *userdata)
Prepare a read op submission.
Definition rtio.h:496
static struct rtio_sqe * rtio_sqe_acquire(struct rtio *r)
Acquire a single submission queue event if available.
Definition rtio.h:901
static void rtio_sqe_drop_all(struct rtio *r)
Drop all previously acquired sqe.
Definition rtio.h:919
static void rtio_sqe_prep_write(struct rtio_sqe *sqe, const struct rtio_iodev *iodev, int8_t prio, uint8_t *buf, uint32_t len, void *userdata)
Prepare a write op submission.
Definition rtio.h:536
int(* spi_api_io_async)(const struct device *dev, const struct spi_config *config, const struct spi_buf_set *tx_bufs, const struct spi_buf_set *rx_bufs, spi_callback_t cb, void *userdata)
Definition spi.h:620
uint16_t spi_operation_t
Opaque type to hold the SPI operation flags.
Definition spi.h:295
int spi_release(const struct device *dev, const struct spi_config *config)
Release the SPI device locked on and/or the CS by the current config.
void(* spi_callback_t)(const struct device *dev, int result, void *data)
SPI callback for asynchronous transfer requests.
Definition spi.h:613
static int spi_write_dt(const struct spi_dt_spec *spec, const struct spi_buf_set *tx_bufs)
Write data to a SPI bus specified in spi_dt_spec.
Definition spi.h:844
static bool spi_is_ready_dt(const struct spi_dt_spec *spec)
Validate that SPI bus (and CS gpio if defined) is ready.
Definition spi.h:693
static int spi_transceive_signal(const struct device *dev, const struct spi_config *config, const struct spi_buf_set *tx_bufs, const struct spi_buf_set *rx_bufs, struct k_poll_signal *sig)
Read/write the specified amount of data from the SPI driver.
Definition spi.h:922
static int spi_read(const struct device *dev, const struct spi_config *config, const struct spi_buf_set *rx_bufs)
Read the specified amount of data from the SPI driver.
Definition spi.h:784
static int spi_transceive_dt(const struct spi_dt_spec *spec, const struct spi_buf_set *tx_bufs, const struct spi_buf_set *rx_bufs)
Read/write data from an SPI bus specified in spi_dt_spec.
Definition spi.h:760
static int spi_transceive_cb(const struct device *dev, const struct spi_config *config, const struct spi_buf_set *tx_bufs, const struct spi_buf_set *rx_bufs, spi_callback_t callback, void *userdata)
Read/write the specified amount of data from the SPI driver.
Definition spi.h:878
#define SPI_STATS_TRANSFER_ERROR_INC(dev_)
Definition spi.h:590
static int spi_read_dt(const struct spi_dt_spec *spec, const struct spi_buf_set *rx_bufs)
Read data from a SPI bus specified in spi_dt_spec.
Definition spi.h:803
static int spi_write(const struct device *dev, const struct spi_config *config, const struct spi_buf_set *tx_bufs)
Write the specified amount of data from the SPI driver.
Definition spi.h:825
static int spi_rtio_copy(struct rtio *r, struct rtio_iodev *iodev, const struct spi_buf_set *tx_bufs, const struct spi_buf_set *rx_bufs, struct rtio_sqe **last_sqe)
Copy the tx_bufs and rx_bufs into a set of RTIO requests.
Definition spi.h:1066
static int spi_release_dt(const struct spi_dt_spec *spec)
Release the SPI device specified in spi_dt_spec.
Definition spi.h:1257
int(* spi_api_release)(const struct device *dev, const struct spi_config *config)
Callback API for unlocking SPI device.
Definition spi.h:642
static void spi_iodev_submit(struct rtio_iodev_sqe *iodev_sqe)
Submit a SPI device with a request.
Definition spi.h:1012
static int spi_read_signal(const struct device *dev, const struct spi_config *config, const struct spi_buf_set *rx_bufs, struct k_poll_signal *sig)
Read the specified amount of data from the SPI driver.
Definition spi.h:959
int(* spi_api_io)(const struct device *dev, const struct spi_config *config, const struct spi_buf_set *tx_bufs, const struct spi_buf_set *rx_bufs)
Callback API for I/O See spi_transceive() for argument descriptions.
Definition spi.h:601
static bool spi_cs_is_gpio_dt(const struct spi_dt_spec *spec)
Check if SPI CS in spi_dt_spec is controlled using a GPIO.
Definition spi.h:680
const struct rtio_iodev_api spi_iodev_api
int spi_transceive(const struct device *dev, const struct spi_config *config, const struct spi_buf_set *tx_bufs, const struct spi_buf_set *rx_bufs)
Read/write the specified amount of data from the SPI driver.
#define spi_transceive_stats(dev, error, tx_bufs, rx_bufs)
Definition spi.h:592
static int spi_write_signal(const struct device *dev, const struct spi_config *config, const struct spi_buf_set *tx_bufs, struct k_poll_signal *sig)
Write the specified amount of data from the SPI driver.
Definition spi.h:990
static bool spi_cs_is_gpio(const struct spi_config *config)
Check if SPI CS is controlled using a GPIO.
Definition spi.h:668
static bool spi_is_ready_iodev(const struct rtio_iodev *spi_iodev)
Validate that SPI bus (and CS gpio if defined) is ready.
Definition spi.h:1047
#define ENOMEM
Not enough core.
Definition errno.h:50
Public kernel APIs.
static ZTEST_BMEM int ret
Definition main.c:16
Real-Time IO device API for moving bytes with low effort.
Statistics.
#define STATS_NAME_END(name__)
Definition stats.h:391
#define STATS_NAME(name__, entry__)
Definition stats.h:390
#define STATS_SECT_END
Ends a stats group struct definition.
Definition stats.h:89
#define STATS_SECT_ENTRY32(var__)
Definition stats.h:359
#define STATS_NAME_START(name__)
Definition stats.h:389
#define STATS_SECT_START(group__)
Definition stats.h:354
__UINT32_TYPE__ uint32_t
Definition stdint.h:90
__UINT8_TYPE__ uint8_t
Definition stdint.h:88
__UINT16_TYPE__ uint16_t
Definition stdint.h:89
Runtime device dynamic structure (in RAM) per driver instance.
Definition device.h:371
Runtime device structure (in ROM) per driver instance.
Definition device.h:403
const void * api
Address of the API structure exposed by the device instance.
Definition device.h:409
Container for GPIO pin information specified in devicetree.
Definition gpio.h:288
const struct device * port
GPIO device controlling the pin.
Definition gpio.h:290
Definition kernel.h:5691
Definition errno.c:37
API that an RTIO IO device should implement.
Definition rtio.h:433
Compute the mempool block index for a given pointer.
Definition rtio.h:423
struct rtio_sqe sqe
Definition rtio.h:424
An IO device with a function table for submitting requests.
Definition rtio.h:448
void * data
Definition rtio.h:453
A submission queue event.
Definition rtio.h:232
uint8_t * tx_buf
Definition rtio.h:277
uint8_t * rx_buf
Definition rtio.h:278
const struct rtio_iodev * iodev
Device to operation on.
Definition rtio.h:243
uint16_t flags
Op Flags.
Definition rtio.h:237
An RTIO context containing what can be viewed as a pair of queues.
Definition rtio.h:327
SPI buffer array structure.
Definition spi.h:437
const struct spi_buf * buffers
Pointer to an array of spi_buf, or NULL.
Definition spi.h:439
size_t count
Length of the array pointed by buffers.
Definition spi.h:441
SPI buffer structure.
Definition spi.h:424
size_t len
Length of the buffer buf.
Definition spi.h:431
void * buf
Valid pointer to a data buffer, or NULL otherwise.
Definition spi.h:426
SPI controller configuration structure.
Definition spi.h:301
uint16_t slave
Slave number from 0 to host controller slave limit.
Definition spi.h:326
struct spi_cs_control cs
GPIO chip-select line (optional, must be initialized to zero if not used).
Definition spi.h:331
spi_operation_t operation
Operation flags.
Definition spi.h:324
uint32_t frequency
Bus frequency in Hertz.
Definition spi.h:303
SPI Chip Select control structure.
Definition spi.h:159
uint32_t delay
Delay in microseconds to wait before starting the transmission and before releasing the CS line.
Definition spi.h:172
struct gpio_dt_spec gpio
GPIO devicetree specification of CS GPIO.
Definition spi.h:167
SPI driver API This is the mandatory API any SPI driver needs to expose.
Definition spi.h:650
spi_api_io transceive
Definition spi.h:651
spi_api_release release
Definition spi.h:658
Complete SPI DT information.
Definition spi.h:377
const struct device * bus
SPI bus.
Definition spi.h:379
struct spi_config config
Slave specific configuration.
Definition spi.h:381
static fdata_t data[2]
Definition test_fifo_contexts.c:15