Zephyr Project API  3.4.0
A Scalable Open Source RTOS
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
22#include <zephyr/types.h>
23#include <stddef.h>
24#include <zephyr/device.h>
26#include <zephyr/drivers/gpio.h>
27#include <zephyr/kernel.h>
28#include <zephyr/sys/__assert.h>
29#include <zephyr/rtio/rtio.h>
30#include <zephyr/stats/stats.h>
31
32#ifdef __cplusplus
33extern "C" {
34#endif
35
40#define SPI_OP_MODE_MASTER 0U
41#define SPI_OP_MODE_SLAVE BIT(0)
42#define SPI_OP_MODE_MASK 0x1U
43#define SPI_OP_MODE_GET(_operation_) ((_operation_) & SPI_OP_MODE_MASK)
56#define SPI_MODE_CPOL BIT(1)
57
65#define SPI_MODE_CPHA BIT(2)
66
72#define SPI_MODE_LOOP BIT(3)
73
74#define SPI_MODE_MASK (0xEU)
75#define SPI_MODE_GET(_mode_) \
76 ((_mode_) & SPI_MODE_MASK)
77
84#define SPI_TRANSFER_MSB (0U)
85#define SPI_TRANSFER_LSB BIT(4)
92#define SPI_WORD_SIZE_SHIFT (5U)
93#define SPI_WORD_SIZE_MASK (0x3FU << SPI_WORD_SIZE_SHIFT)
94#define SPI_WORD_SIZE_GET(_operation_) \
95 (((_operation_) & SPI_WORD_SIZE_MASK) >> SPI_WORD_SIZE_SHIFT)
96
97#define SPI_WORD_SET(_word_size_) \
98 ((_word_size_) << SPI_WORD_SIZE_SHIFT)
105/* Requests - if possible - to keep CS asserted after the transaction */
106#define SPI_HOLD_ON_CS BIT(12)
107/* Keep the device locked after the transaction for the current config.
108 * Use this with extreme caution (see spi_release() below) as it will
109 * prevent other callers to access the SPI device until spi_release() is
110 * properly called.
111 */
112#define SPI_LOCK_ON BIT(13)
113
114/* Active high logic on CS - Usually, and by default, CS logic is active
115 * low. However, some devices may require the reverse logic: active high.
116 * This bit will request the controller to use that logic. Note that not
117 * all controllers are able to handle that natively. In this case deferring
118 * the CS control to a gpio line through struct spi_cs_control would be
119 * the solution.
120 */
121#define SPI_CS_ACTIVE_HIGH BIT(14)
133#define SPI_LINES_SINGLE (0U << 16)
134#define SPI_LINES_DUAL (1U << 16)
135#define SPI_LINES_QUAD (2U << 16)
136#define SPI_LINES_OCTAL (3U << 16)
137
138#define SPI_LINES_MASK (0x3U << 16)
162};
163
201#define SPI_CS_GPIOS_DT_SPEC_GET(spi_dev) \
202 GPIO_DT_SPEC_GET_BY_IDX_OR(DT_BUS(spi_dev), cs_gpios, \
203 DT_REG_ADDR(spi_dev), {})
204
214#define SPI_CS_GPIOS_DT_SPEC_INST_GET(inst) \
215 SPI_CS_GPIOS_DT_SPEC_GET(DT_DRV_INST(inst))
216
249#define SPI_CS_CONTROL_INIT(node_id, delay_) \
250 { \
251 .gpio = SPI_CS_GPIOS_DT_SPEC_GET(node_id), \
252 .delay = (delay_), \
253 }
254
268#define SPI_CS_CONTROL_INIT_INST(inst, delay_) \
269 SPI_CS_CONTROL_INIT(DT_DRV_INST(inst), delay_)
270
299#if defined(CONFIG_SPI_EXTENDED_MODES)
302 uint16_t _unused;
303#else
306#endif /* CONFIG_SPI_EXTENDED_MODES */
307
309};
310
328#define SPI_CONFIG_DT(node_id, operation_, delay_) \
329 { \
330 .frequency = DT_PROP(node_id, spi_max_frequency), \
331 .operation = (operation_) | \
332 DT_PROP(node_id, duplex) | \
333 DT_PROP(node_id, frame_format), \
334 .slave = DT_REG_ADDR(node_id), \
335 .cs = SPI_CS_CONTROL_INIT(node_id, delay_), \
336 }
337
349#define SPI_CONFIG_DT_INST(inst, operation_, delay_) \
350 SPI_CONFIG_DT(DT_DRV_INST(inst), operation_, delay_)
351
359 const struct device *bus;
361};
362
381#define SPI_DT_SPEC_GET(node_id, operation_, delay_) \
382 { \
383 .bus = DEVICE_DT_GET(DT_BUS(node_id)), \
384 .config = SPI_CONFIG_DT(node_id, operation_, delay_) \
385 }
386
398#define SPI_DT_SPEC_INST_GET(inst, operation_, delay_) \
399 SPI_DT_SPEC_GET(DT_DRV_INST(inst), operation_, delay_)
400
409struct spi_buf {
410 void *buf;
411 size_t len;
412};
413
421 const struct spi_buf *buffers;
422 size_t count;
423};
424
425#if defined(CONFIG_SPI_STATS)
427STATS_SECT_ENTRY32(rx_bytes)
428STATS_SECT_ENTRY32(tx_bytes)
429STATS_SECT_ENTRY32(transfer_error)
431
433STATS_NAME(spi, rx_bytes)
434STATS_NAME(spi, tx_bytes)
435STATS_NAME(spi, transfer_error)
436STATS_NAME_END(spi);
437
441struct spi_device_state {
442 struct device_state devstate;
443 struct stats_spi stats;
444};
445
449#define Z_SPI_GET_STATS(dev_) \
450 CONTAINER_OF(dev_->state, struct spi_device_state, devstate)->stats
451
457#define SPI_STATS_RX_BYTES_INCN(dev_, n) \
458 STATS_INCN(Z_SPI_GET_STATS(dev_), rx_bytes, n)
459
465#define SPI_STATS_TX_BYTES_INCN(dev_, n) \
466 STATS_INCN(Z_SPI_GET_STATS(dev_), tx_bytes, n)
467
475#define SPI_STATS_TRANSFER_ERROR_INC(dev_) \
476 STATS_INC(Z_SPI_GET_STATS(dev_), transfer_error)
477
481#define Z_SPI_DEVICE_STATE_DEFINE(dev_id) \
482 static struct spi_device_state Z_DEVICE_STATE_NAME(dev_id) \
483 __attribute__((__section__(".z_devstate")));
484
491#define Z_SPI_INIT_FN(dev_id, init_fn) \
492 static inline int UTIL_CAT(dev_id, _init)(const struct device *dev) \
493 { \
494 struct spi_device_state *state = \
495 CONTAINER_OF(dev->state, struct spi_device_state, devstate); \
496 stats_init(&state->stats.s_hdr, STATS_SIZE_32, 3, \
497 STATS_NAME_INIT_PARMS(spi)); \
498 stats_register(dev->name, &(state->stats.s_hdr)); \
499 return init_fn(dev); \
500 }
501
521#define SPI_DEVICE_DT_DEFINE(node_id, init_fn, pm_device, \
522 data_ptr, cfg_ptr, level, prio, \
523 api_ptr, ...) \
524 Z_SPI_DEVICE_STATE_DEFINE(Z_DEVICE_DT_DEV_ID(node_id)); \
525 Z_SPI_INIT_FN(Z_DEVICE_DT_DEV_ID(node_id), init_fn) \
526 Z_DEVICE_DEFINE(node_id, Z_DEVICE_DT_DEV_ID(node_id), \
527 DEVICE_DT_NAME(node_id), \
528 &UTIL_CAT(Z_DEVICE_DT_DEV_ID(node_id), _init), \
529 pm_device, \
530 data_ptr, cfg_ptr, level, prio, \
531 api_ptr, \
532 &(Z_DEVICE_STATE_NAME(Z_DEVICE_DT_DEV_ID(node_id)).devstate), \
533 __VA_ARGS__)
534
535static inline void spi_transceive_stats(const struct device *dev, int error,
536 const struct spi_buf_set *tx_bufs,
537 const struct spi_buf_set *rx_bufs)
538{
539 uint32_t tx_bytes;
540 uint32_t rx_bytes;
541
542 if (error) {
544 }
545
546 if (tx_bufs) {
547 tx_bytes = tx_bufs->count ? tx_bufs->buffers->len : 0;
548 SPI_STATS_TX_BYTES_INCN(dev, tx_bytes);
549 }
550
551 if (rx_bufs) {
552 rx_bytes = rx_bufs->count ? rx_bufs->buffers->len : 0;
553 SPI_STATS_RX_BYTES_INCN(dev, rx_bytes);
554 }
555}
556
557#else /*CONFIG_SPI_STATS*/
558
559#define SPI_DEVICE_DT_DEFINE(node_id, init_fn, pm, \
560 data, config, level, prio, \
561 api, ...) \
562 Z_DEVICE_STATE_DEFINE(Z_DEVICE_DT_DEV_ID(node_id)); \
563 Z_DEVICE_DEFINE(node_id, Z_DEVICE_DT_DEV_ID(node_id), \
564 DEVICE_DT_NAME(node_id), init_fn, pm, data, config, \
565 level, prio, api, \
566 &Z_DEVICE_STATE_NAME(Z_DEVICE_DT_DEV_ID(node_id)), \
567 __VA_ARGS__)
568
569#define SPI_STATS_RX_BYTES_INC(dev_)
570#define SPI_STATS_TX_BYTES_INC(dev_)
571#define SPI_STATS_TRANSFER_ERROR_INC(dev_)
572
573#define spi_transceive_stats(dev, error, tx_bufs, rx_bufs)
574
575#endif /*CONFIG_SPI_STATS*/
576
582typedef int (*spi_api_io)(const struct device *dev,
583 const struct spi_config *config,
584 const struct spi_buf_set *tx_bufs,
585 const struct spi_buf_set *rx_bufs);
586
594typedef void (*spi_callback_t)(const struct device *dev, int result, void *data);
595
601typedef int (*spi_api_io_async)(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,
606 void *userdata);
607
608#if defined(CONFIG_SPI_RTIO) || defined(DOXYGEN)
609
614typedef void (*spi_api_iodev_submit)(const struct device *dev,
615 struct rtio_iodev_sqe *iodev_sqe);
616#endif /* CONFIG_SPI_RTIO */
617
623typedef int (*spi_api_release)(const struct device *dev,
624 const struct spi_config *config);
625
626
631__subsystem struct spi_driver_api {
633#ifdef CONFIG_SPI_ASYNC
635#endif /* CONFIG_SPI_ASYNC */
636#ifdef CONFIG_SPI_RTIO
637 spi_api_iodev_submit iodev_submit;
638#endif /* CONFIG_SPI_RTIO */
640};
641
649static inline bool spi_cs_is_gpio(const struct spi_config *config)
650{
651 return config->cs.gpio.port != NULL;
652}
653
661static inline bool spi_cs_is_gpio_dt(const struct spi_dt_spec *spec)
662{
663 return spi_cs_is_gpio(&spec->config);
664}
665
674__deprecated
675static inline bool spi_is_ready(const struct spi_dt_spec *spec)
676{
677 /* Validate bus is ready */
678 if (!device_is_ready(spec->bus)) {
679 return false;
680 }
681 /* Validate CS gpio port is ready, if it is used */
682 if (spi_cs_is_gpio_dt(spec) &&
684 return false;
685 }
686 return true;
687}
688
697static inline bool spi_is_ready_dt(const struct spi_dt_spec *spec)
698{
699 /* Validate bus is ready */
700 if (!device_is_ready(spec->bus)) {
701 return false;
702 }
703 /* Validate CS gpio port is ready, if it is used */
704 if (spi_cs_is_gpio_dt(spec) &&
706 return false;
707 }
708 return true;
709}
710
729__syscall int spi_transceive(const struct device *dev,
730 const struct spi_config *config,
731 const struct spi_buf_set *tx_bufs,
732 const struct spi_buf_set *rx_bufs);
733
734static inline int z_impl_spi_transceive(const struct device *dev,
735 const struct spi_config *config,
736 const struct spi_buf_set *tx_bufs,
737 const struct spi_buf_set *rx_bufs)
738{
739 const struct spi_driver_api *api =
740 (const struct spi_driver_api *)dev->api;
741 int ret;
742
743 ret = api->transceive(dev, config, tx_bufs, rx_bufs);
744 spi_transceive_stats(dev, ret, tx_bufs, rx_bufs);
745
746 return ret;
747}
748
764static inline int spi_transceive_dt(const struct spi_dt_spec *spec,
765 const struct spi_buf_set *tx_bufs,
766 const struct spi_buf_set *rx_bufs)
767{
768 return spi_transceive(spec->bus, &spec->config, tx_bufs, rx_bufs);
769}
770
787static inline int spi_read(const struct device *dev,
788 const struct spi_config *config,
789 const struct spi_buf_set *rx_bufs)
790{
791 return spi_transceive(dev, config, NULL, rx_bufs);
792}
793
806static inline int spi_read_dt(const struct spi_dt_spec *spec,
807 const struct spi_buf_set *rx_bufs)
808{
809 return spi_read(spec->bus, &spec->config, rx_bufs);
810}
811
828static inline int spi_write(const struct device *dev,
829 const struct spi_config *config,
830 const struct spi_buf_set *tx_bufs)
831{
832 return spi_transceive(dev, config, tx_bufs, NULL);
833}
834
847static inline int spi_write_dt(const struct spi_dt_spec *spec,
848 const struct spi_buf_set *tx_bufs)
849{
850 return spi_write(spec->bus, &spec->config, tx_bufs);
851}
852
853/* Doxygen defines this so documentation is generated. */
854#ifdef CONFIG_SPI_ASYNC
855
882static inline int spi_transceive_cb(const struct device *dev,
883 const struct spi_config *config,
884 const struct spi_buf_set *tx_bufs,
885 const struct spi_buf_set *rx_bufs,
886 spi_callback_t callback,
887 void *userdata)
888{
889 const struct spi_driver_api *api =
890 (const struct spi_driver_api *)dev->api;
891
892 return api->transceive_async(dev, config, tx_bufs, rx_bufs, callback, userdata);
893}
894
895#ifdef CONFIG_POLL
896
898void z_spi_transfer_signal_cb(const struct device *dev, int result, void *userdata);
926static inline int spi_transceive_signal(const struct device *dev,
927 const struct spi_config *config,
928 const struct spi_buf_set *tx_bufs,
929 const struct spi_buf_set *rx_bufs,
930 struct k_poll_signal *sig)
931{
932 const struct spi_driver_api *api =
933 (const struct spi_driver_api *)dev->api;
934 spi_callback_t cb = (sig == NULL) ? NULL : z_spi_transfer_signal_cb;
935
936 return api->transceive_async(dev, config, tx_bufs, rx_bufs, cb, sig);
937}
938
945__deprecated static inline int spi_transceive_async(const struct device *dev,
946 const struct spi_config *config,
947 const struct spi_buf_set *tx_bufs,
948 const struct spi_buf_set *rx_bufs,
949 struct k_poll_signal *sig)
950{
951 return spi_transceive_signal(dev, config, tx_bufs, rx_bufs, sig);
952}
953
977static inline int spi_read_signal(const struct device *dev,
978 const struct spi_config *config,
979 const struct spi_buf_set *rx_bufs,
980 struct k_poll_signal *sig)
981{
982 return spi_transceive_signal(dev, config, NULL, rx_bufs, sig);
983}
984
991__deprecated static inline int spi_read_async(const struct device *dev,
992 const struct spi_config *config,
993 const struct spi_buf_set *rx_bufs,
994 struct k_poll_signal *sig)
995{
996 return spi_read_signal(dev, config, rx_bufs, sig);
997}
998
1022static inline int spi_write_signal(const struct device *dev,
1023 const struct spi_config *config,
1024 const struct spi_buf_set *tx_bufs,
1025 struct k_poll_signal *sig)
1026{
1027 return spi_transceive_signal(dev, config, tx_bufs, NULL, sig);
1028}
1029
1036__deprecated static inline int spi_write_async(const struct device *dev,
1037 const struct spi_config *config,
1038 const struct spi_buf_set *tx_bufs,
1039 struct k_poll_signal *sig)
1040{
1041 return spi_write_signal(dev, config, tx_bufs, sig);
1042}
1043
1044#endif /* CONFIG_POLL */
1045
1046#endif /* CONFIG_SPI_ASYNC */
1047
1048
1049#if defined(CONFIG_SPI_RTIO) || defined(DOXYGEN)
1050
1062static inline void spi_iodev_submit(struct rtio_iodev_sqe *iodev_sqe)
1063{
1064 const struct spi_dt_spec *dt_spec = iodev_sqe->sqe.iodev->data;
1065 const struct device *dev = dt_spec->bus;
1066 const struct spi_driver_api *api = (const struct spi_driver_api *)dev->api;
1067
1068 api->iodev_submit(dt_spec->bus, iodev_sqe);
1069}
1070
1071extern const struct rtio_iodev_api spi_iodev_api;
1072
1081#define SPI_DT_IODEV_DEFINE(name, node_id, operation_, delay_) \
1082 const struct spi_dt_spec _spi_dt_spec_##name = \
1083 SPI_DT_SPEC_GET(node_id, operation_, delay_); \
1084 RTIO_IODEV_DEFINE(name, &spi_iodev_api, (void *)&_spi_dt_spec_##name)
1085
1094static inline bool spi_is_ready_iodev(const struct rtio_iodev *spi_iodev)
1095{
1096 struct spi_dt_spec *spec = spi_iodev->data;
1097
1098 return spi_is_ready_dt(spec);
1099}
1100
1113static inline int spi_rtio_copy(struct rtio *r,
1114 struct rtio_iodev *iodev,
1115 const struct spi_buf_set *tx_bufs,
1116 const struct spi_buf_set *rx_bufs,
1117 struct rtio_sqe **last_sqe)
1118{
1119 int ret = 0;
1120 size_t tx_count = tx_bufs ? tx_bufs->count : 0;
1121 size_t rx_count = rx_bufs ? rx_bufs->count : 0;
1122
1123 uint32_t tx = 0, tx_len = 0;
1124 uint32_t rx = 0, rx_len = 0;
1125 uint8_t *tx_buf, *rx_buf;
1126
1127 struct rtio_sqe *sqe = NULL;
1128
1129 if (tx < tx_count) {
1130 tx_buf = tx_bufs->buffers[tx].buf;
1131 tx_len = tx_bufs->buffers[tx].len;
1132 } else {
1133 tx_buf = NULL;
1134 tx_len = rx_bufs->buffers[rx].len;
1135 }
1136
1137 if (rx < rx_count) {
1138 rx_buf = rx_bufs->buffers[rx].buf;
1139 rx_len = rx_bufs->buffers[rx].len;
1140 } else {
1141 rx_buf = NULL;
1142 rx_len = tx_bufs->buffers[tx].len;
1143 }
1144
1145
1146 while ((tx < tx_count || rx < rx_count) && (tx_len > 0 || rx_len > 0)) {
1147 sqe = rtio_sqe_acquire(r);
1148
1149 if (sqe == NULL) {
1150 ret = -ENOMEM;
1152 goto out;
1153 }
1154
1155 ret++;
1156
1157 /* If tx/rx len are same, we can do a simple transceive */
1158 if (tx_len == rx_len) {
1159 if (tx_buf == NULL) {
1161 rx_buf, rx_len, NULL);
1162 } else if (rx_buf == NULL) {
1164 tx_buf, tx_len, NULL);
1165 } else {
1167 tx_buf, rx_buf, rx_len, NULL);
1168 }
1169 tx++;
1170 rx++;
1171 if (rx < rx_count) {
1172 rx_buf = rx_bufs->buffers[rx].buf;
1173 rx_len = rx_bufs->buffers[rx].len;
1174 } else {
1175 rx_buf = NULL;
1176 rx_len = 0;
1177 }
1178 if (tx < tx_count) {
1179 tx_buf = tx_bufs->buffers[tx].buf;
1180 tx_len = tx_bufs->buffers[tx].len;
1181 } else {
1182 tx_buf = NULL;
1183 tx_len = 0;
1184 }
1185 } else if (tx_len == 0) {
1187 (uint8_t *)rx_buf,
1188 (uint32_t)rx_len,
1189 NULL);
1190 rx++;
1191 if (rx < rx_count) {
1192 rx_buf = rx_bufs->buffers[rx].buf;
1193 rx_len = rx_bufs->buffers[rx].len;
1194 } else {
1195 rx_buf = NULL;
1196 rx_len = 0;
1197 }
1198 } else if (rx_len == 0) {
1200 (uint8_t *)tx_buf,
1201 (uint32_t)tx_len,
1202 NULL);
1203 tx++;
1204 if (tx < tx_count) {
1205 tx_buf = rx_bufs->buffers[rx].buf;
1206 tx_len = rx_bufs->buffers[rx].len;
1207 } else {
1208 tx_buf = NULL;
1209 tx_len = 0;
1210 }
1211 } else if (tx_len > rx_len) {
1213 (uint8_t *)tx_buf,
1214 (uint8_t *)rx_buf,
1215 (uint32_t)rx_len,
1216 NULL);
1217 tx_len -= rx_len;
1218 tx_buf += rx_len;
1219 rx++;
1220 if (rx < rx_count) {
1221 rx_buf = rx_bufs->buffers[rx].buf;
1222 rx_len = rx_bufs->buffers[rx].len;
1223 } else {
1224 rx_buf = NULL;
1225 rx_len = tx_len;
1226 }
1227 } else if (rx_len > tx_len) {
1229 (uint8_t *)tx_buf,
1230 (uint8_t *)rx_buf,
1231 (uint32_t)tx_len,
1232 NULL);
1233 rx_len -= tx_len;
1234 rx_buf += tx_len;
1235 tx++;
1236 if (tx < tx_count) {
1237 tx_buf = tx_bufs->buffers[tx].buf;
1238 tx_len = tx_bufs->buffers[tx].len;
1239 } else {
1240 tx_buf = NULL;
1241 tx_len = rx_len;
1242 }
1243 } else {
1244 __ASSERT_NO_MSG("Invalid spi_rtio_copy state");
1245 }
1246
1248 }
1249
1250 if (sqe != NULL) {
1251 sqe->flags = 0;
1252 *last_sqe = sqe;
1253 }
1254
1255out:
1256 return ret;
1257}
1258
1259#endif /* CONFIG_SPI_RTIO */
1260
1281__syscall int spi_release(const struct device *dev,
1282 const struct spi_config *config);
1283
1284static inline int z_impl_spi_release(const struct device *dev,
1285 const struct spi_config *config)
1286{
1287 const struct spi_driver_api *api =
1288 (const struct spi_driver_api *)dev->api;
1289
1290 return api->release(dev, config);
1291}
1292
1304static inline int spi_release_dt(const struct spi_dt_spec *spec)
1305{
1306 return spi_release(spec->bus, &spec->config);
1307}
1308
1309#ifdef __cplusplus
1310}
1311#endif
1312
1317#include <syscalls/spi.h>
1318
1319#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.
struct result result[2]
Definition: errno.c:42
bool device_is_ready(const struct device *dev)
Verify that a device is ready for use.
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:594
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:485
static struct rtio_sqe * rtio_sqe_acquire(struct rtio *r)
Acquire a single submission queue event if available.
Definition: rtio.h:883
static void rtio_sqe_drop_all(struct rtio *r)
Drop all previously acquired sqe.
Definition: rtio.h:901
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:525
#define RTIO_SQE_TRANSACTION
The next request in the queue is part of a transaction.
Definition: rtio.h:114
#define RTIO_PRIO_NORM
Normal priority.
Definition: rtio.h:76
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:601
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:594
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:847
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:697
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:787
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:764
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:882
#define SPI_STATS_TRANSFER_ERROR_INC(dev_)
Definition: spi.h:571
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:806
static bool spi_is_ready(const struct spi_dt_spec *spec)
Validate that SPI bus is ready.
Definition: spi.h:675
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:828
static int spi_release_dt(const struct spi_dt_spec *spec)
Release the SPI device specified in spi_dt_spec.
Definition: spi.h:1304
int(* spi_api_release)(const struct device *dev, const struct spi_config *config)
Callback API for unlocking SPI device. See spi_release() for argument descriptions.
Definition: spi.h:623
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:582
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:661
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:573
static bool spi_cs_is_gpio(const struct spi_config *config)
Check if SPI CS is controlled using a GPIO.
Definition: spi.h:649
#define ENOMEM
Definition: errno.h:51
Public kernel APIs.
static ZTEST_BMEM volatile int ret
Definition: k_float_disable.c:29
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:353
Runtime device structure (in ROM) per driver instance.
Definition: device.h:380
const void * api
Definition: device.h:386
Container for GPIO pin information specified in devicetree.
Definition: gpio.h:286
const struct device * port
Definition: gpio.h:288
Definition: kernel.h:5517
Definition: errno.c:37
API that an RTIO IO device should implement.
Definition: rtio.h:421
Compute the mempool block index for a given pointer.
Definition: rtio.h:411
struct rtio_sqe sqe
Definition: rtio.h:412
An IO device with a function table for submitting requests.
Definition: rtio.h:439
void * data
Definition: rtio.h:447
A submission queue event.
Definition: rtio.h:238
uint8_t * tx_buf
Definition: rtio.h:283
uint8_t * rx_buf
Definition: rtio.h:284
const struct rtio_iodev * iodev
Definition: rtio.h:249
uint16_t flags
Definition: rtio.h:243
An RTIO context containing what can be viewed as a pair of queues.
Definition: rtio.h:338
SPI buffer array structure.
Definition: spi.h:420
const struct spi_buf * buffers
Definition: spi.h:421
size_t count
Definition: spi.h:422
SPI buffer structure.
Definition: spi.h:409
size_t len
Definition: spi.h:411
void * buf
Definition: spi.h:410
SPI controller configuration structure.
Definition: spi.h:297
uint16_t slave
Definition: spi.h:305
struct spi_cs_control cs
Definition: spi.h:308
uint32_t frequency
Definition: spi.h:298
uint16_t operation
Definition: spi.h:304
SPI Chip Select control structure.
Definition: spi.h:148
uint32_t delay
Definition: spi.h:161
struct gpio_dt_spec gpio
Definition: spi.h:156
SPI driver API This is the mandatory API any SPI driver needs to expose.
Definition: spi.h:631
spi_api_io transceive
Definition: spi.h:632
spi_api_release release
Definition: spi.h:639
spi_api_io_async transceive_async
Definition: spi.h:634
Complete SPI DT information.
Definition: spi.h:358
const struct device * bus
Definition: spi.h:359
struct spi_config config
Definition: spi.h:360
static fdata_t data[2]
Definition: test_fifo_contexts.c:15