Zephyr API Documentation  3.5.0
A Scalable Open Source RTOS
3.5.0
All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Modules Pages
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
275#if defined(CONFIG_SPI_EXTENDED_MODES)
277#else
279#endif
280
315};
316
330#define SPI_CONFIG_DT(node_id, operation_, delay_) \
331 { \
332 .frequency = DT_PROP(node_id, spi_max_frequency), \
333 .operation = (operation_) | \
334 DT_PROP(node_id, duplex) | \
335 DT_PROP(node_id, frame_format), \
336 .slave = DT_REG_ADDR(node_id), \
337 .cs = SPI_CS_CONTROL_INIT(node_id, delay_), \
338 }
339
351#define SPI_CONFIG_DT_INST(inst, operation_, delay_) \
352 SPI_CONFIG_DT(DT_DRV_INST(inst), operation_, delay_)
353
361 const struct device *bus;
363};
364
383#define SPI_DT_SPEC_GET(node_id, operation_, delay_) \
384 { \
385 .bus = DEVICE_DT_GET(DT_BUS(node_id)), \
386 .config = SPI_CONFIG_DT(node_id, operation_, delay_) \
387 }
388
400#define SPI_DT_SPEC_INST_GET(inst, operation_, delay_) \
401 SPI_DT_SPEC_GET(DT_DRV_INST(inst), operation_, delay_)
402
411struct spi_buf {
412 void *buf;
413 size_t len;
414};
415
423 const struct spi_buf *buffers;
424 size_t count;
425};
426
427#if defined(CONFIG_SPI_STATS)
429STATS_SECT_ENTRY32(rx_bytes)
430STATS_SECT_ENTRY32(tx_bytes)
431STATS_SECT_ENTRY32(transfer_error)
433
435STATS_NAME(spi, rx_bytes)
436STATS_NAME(spi, tx_bytes)
437STATS_NAME(spi, transfer_error)
438STATS_NAME_END(spi);
439
443struct spi_device_state {
444 struct device_state devstate;
445 struct stats_spi stats;
446};
447
451#define Z_SPI_GET_STATS(dev_) \
452 CONTAINER_OF(dev_->state, struct spi_device_state, devstate)->stats
453
459#define SPI_STATS_RX_BYTES_INCN(dev_, n) \
460 STATS_INCN(Z_SPI_GET_STATS(dev_), rx_bytes, n)
461
467#define SPI_STATS_TX_BYTES_INCN(dev_, n) \
468 STATS_INCN(Z_SPI_GET_STATS(dev_), tx_bytes, n)
469
477#define SPI_STATS_TRANSFER_ERROR_INC(dev_) \
478 STATS_INC(Z_SPI_GET_STATS(dev_), transfer_error)
479
483#define Z_SPI_DEVICE_STATE_DEFINE(dev_id) \
484 static struct spi_device_state Z_DEVICE_STATE_NAME(dev_id) \
485 __attribute__((__section__(".z_devstate")));
486
493#define Z_SPI_INIT_FN(dev_id, init_fn) \
494 static inline int UTIL_CAT(dev_id, _init)(const struct device *dev) \
495 { \
496 struct spi_device_state *state = \
497 CONTAINER_OF(dev->state, struct spi_device_state, devstate); \
498 stats_init(&state->stats.s_hdr, STATS_SIZE_32, 3, \
499 STATS_NAME_INIT_PARMS(spi)); \
500 stats_register(dev->name, &(state->stats.s_hdr)); \
501 return init_fn(dev); \
502 }
503
523#define SPI_DEVICE_DT_DEFINE(node_id, init_fn, pm_device, \
524 data_ptr, cfg_ptr, level, prio, \
525 api_ptr, ...) \
526 Z_SPI_DEVICE_STATE_DEFINE(Z_DEVICE_DT_DEV_ID(node_id)); \
527 Z_SPI_INIT_FN(Z_DEVICE_DT_DEV_ID(node_id), init_fn) \
528 Z_DEVICE_DEFINE(node_id, Z_DEVICE_DT_DEV_ID(node_id), \
529 DEVICE_DT_NAME(node_id), \
530 &UTIL_CAT(Z_DEVICE_DT_DEV_ID(node_id), _init), \
531 pm_device, \
532 data_ptr, cfg_ptr, level, prio, \
533 api_ptr, \
534 &(Z_DEVICE_STATE_NAME(Z_DEVICE_DT_DEV_ID(node_id)).devstate), \
535 __VA_ARGS__)
536
537static inline void spi_transceive_stats(const struct device *dev, int error,
538 const struct spi_buf_set *tx_bufs,
539 const struct spi_buf_set *rx_bufs)
540{
541 uint32_t tx_bytes;
542 uint32_t rx_bytes;
543
544 if (error) {
546 }
547
548 if (tx_bufs) {
549 tx_bytes = tx_bufs->count ? tx_bufs->buffers->len : 0;
550 SPI_STATS_TX_BYTES_INCN(dev, tx_bytes);
551 }
552
553 if (rx_bufs) {
554 rx_bytes = rx_bufs->count ? rx_bufs->buffers->len : 0;
555 SPI_STATS_RX_BYTES_INCN(dev, rx_bytes);
556 }
557}
558
559#else /*CONFIG_SPI_STATS*/
560
561#define SPI_DEVICE_DT_DEFINE(node_id, init_fn, pm, \
562 data, config, level, prio, \
563 api, ...) \
564 Z_DEVICE_STATE_DEFINE(Z_DEVICE_DT_DEV_ID(node_id)); \
565 Z_DEVICE_DEFINE(node_id, Z_DEVICE_DT_DEV_ID(node_id), \
566 DEVICE_DT_NAME(node_id), init_fn, pm, data, config, \
567 level, prio, api, \
568 &Z_DEVICE_STATE_NAME(Z_DEVICE_DT_DEV_ID(node_id)), \
569 __VA_ARGS__)
570
571#define SPI_STATS_RX_BYTES_INC(dev_)
572#define SPI_STATS_TX_BYTES_INC(dev_)
573#define SPI_STATS_TRANSFER_ERROR_INC(dev_)
574
575#define spi_transceive_stats(dev, error, tx_bufs, rx_bufs)
576
577#endif /*CONFIG_SPI_STATS*/
578
584typedef int (*spi_api_io)(const struct device *dev,
585 const struct spi_config *config,
586 const struct spi_buf_set *tx_bufs,
587 const struct spi_buf_set *rx_bufs);
588
596typedef void (*spi_callback_t)(const struct device *dev, int result, void *data);
597
603typedef int (*spi_api_io_async)(const struct device *dev,
604 const struct spi_config *config,
605 const struct spi_buf_set *tx_bufs,
606 const struct spi_buf_set *rx_bufs,
608 void *userdata);
609
610#if defined(CONFIG_SPI_RTIO) || defined(DOXYGEN)
611
616typedef void (*spi_api_iodev_submit)(const struct device *dev,
617 struct rtio_iodev_sqe *iodev_sqe);
618#endif /* CONFIG_SPI_RTIO */
619
625typedef int (*spi_api_release)(const struct device *dev,
626 const struct spi_config *config);
627
628
633__subsystem struct spi_driver_api {
635#ifdef CONFIG_SPI_ASYNC
636 spi_api_io_async transceive_async;
637#endif /* CONFIG_SPI_ASYNC */
638#ifdef CONFIG_SPI_RTIO
639 spi_api_iodev_submit iodev_submit;
640#endif /* CONFIG_SPI_RTIO */
642};
643
651static inline bool spi_cs_is_gpio(const struct spi_config *config)
652{
653 return config->cs.gpio.port != NULL;
654}
655
663static inline bool spi_cs_is_gpio_dt(const struct spi_dt_spec *spec)
664{
665 return spi_cs_is_gpio(&spec->config);
666}
667
676__deprecated
677static inline bool spi_is_ready(const struct spi_dt_spec *spec)
678{
679 /* Validate bus is ready */
680 if (!device_is_ready(spec->bus)) {
681 return false;
682 }
683 /* Validate CS gpio port is ready, if it is used */
684 if (spi_cs_is_gpio_dt(spec) &&
685 !gpio_is_ready_dt(&spec->config.cs.gpio)) {
686 return false;
687 }
688 return true;
689}
690
699static inline bool spi_is_ready_dt(const struct spi_dt_spec *spec)
700{
701 /* Validate bus is ready */
702 if (!device_is_ready(spec->bus)) {
703 return false;
704 }
705 /* Validate CS gpio port is ready, if it is used */
706 if (spi_cs_is_gpio_dt(spec) &&
707 !gpio_is_ready_dt(&spec->config.cs.gpio)) {
708 return false;
709 }
710 return true;
711}
712
731__syscall int spi_transceive(const struct device *dev,
732 const struct spi_config *config,
733 const struct spi_buf_set *tx_bufs,
734 const struct spi_buf_set *rx_bufs);
735
736static inline int z_impl_spi_transceive(const struct device *dev,
737 const struct spi_config *config,
738 const struct spi_buf_set *tx_bufs,
739 const struct spi_buf_set *rx_bufs)
740{
741 const struct spi_driver_api *api =
742 (const struct spi_driver_api *)dev->api;
743 int ret;
744
745 ret = api->transceive(dev, config, tx_bufs, rx_bufs);
746 spi_transceive_stats(dev, ret, tx_bufs, rx_bufs);
747
748 return ret;
749}
750
766static inline int spi_transceive_dt(const struct spi_dt_spec *spec,
767 const struct spi_buf_set *tx_bufs,
768 const struct spi_buf_set *rx_bufs)
769{
770 return spi_transceive(spec->bus, &spec->config, tx_bufs, rx_bufs);
771}
772
789static inline int spi_read(const struct device *dev,
790 const struct spi_config *config,
791 const struct spi_buf_set *rx_bufs)
792{
793 return spi_transceive(dev, config, NULL, rx_bufs);
794}
795
808static inline int spi_read_dt(const struct spi_dt_spec *spec,
809 const struct spi_buf_set *rx_bufs)
810{
811 return spi_read(spec->bus, &spec->config, rx_bufs);
812}
813
830static inline int spi_write(const struct device *dev,
831 const struct spi_config *config,
832 const struct spi_buf_set *tx_bufs)
833{
834 return spi_transceive(dev, config, tx_bufs, NULL);
835}
836
849static inline int spi_write_dt(const struct spi_dt_spec *spec,
850 const struct spi_buf_set *tx_bufs)
851{
852 return spi_write(spec->bus, &spec->config, tx_bufs);
853}
854
855#if defined(CONFIG_SPI_ASYNC) || defined(__DOXYGEN__)
856
883static inline int spi_transceive_cb(const struct device *dev,
884 const struct spi_config *config,
885 const struct spi_buf_set *tx_bufs,
886 const struct spi_buf_set *rx_bufs,
887 spi_callback_t callback,
888 void *userdata)
889{
890 const struct spi_driver_api *api =
891 (const struct spi_driver_api *)dev->api;
892
893 return api->transceive_async(dev, config, tx_bufs, rx_bufs, callback, userdata);
894}
895
896#if defined(CONFIG_POLL) || defined(__DOXYGEN__)
897
899void z_spi_transfer_signal_cb(const struct device *dev, int result, void *userdata);
927static inline int spi_transceive_signal(const struct device *dev,
928 const struct spi_config *config,
929 const struct spi_buf_set *tx_bufs,
930 const struct spi_buf_set *rx_bufs,
931 struct k_poll_signal *sig)
932{
933 const struct spi_driver_api *api =
934 (const struct spi_driver_api *)dev->api;
935 spi_callback_t cb = (sig == NULL) ? NULL : z_spi_transfer_signal_cb;
936
937 return api->transceive_async(dev, config, tx_bufs, rx_bufs, cb, sig);
938}
939
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
990__deprecated static inline int spi_read_async(const struct device *dev,
991 const struct spi_config *config,
992 const struct spi_buf_set *rx_bufs,
993 struct k_poll_signal *sig)
994{
995 return spi_read_signal(dev, config, rx_bufs, sig);
996}
997
1021static inline int spi_write_signal(const struct device *dev,
1022 const struct spi_config *config,
1023 const struct spi_buf_set *tx_bufs,
1024 struct k_poll_signal *sig)
1025{
1026 return spi_transceive_signal(dev, config, tx_bufs, NULL, sig);
1027}
1028
1034__deprecated static inline int spi_write_async(const struct device *dev,
1035 const struct spi_config *config,
1036 const struct spi_buf_set *tx_bufs,
1037 struct k_poll_signal *sig)
1038{
1039 return spi_write_signal(dev, config, tx_bufs, sig);
1040}
1041
1042#endif /* CONFIG_POLL */
1043
1044#endif /* CONFIG_SPI_ASYNC */
1045
1046
1047#if defined(CONFIG_SPI_RTIO) || defined(__DOXYGEN__)
1048
1056static inline void spi_iodev_submit(struct rtio_iodev_sqe *iodev_sqe)
1057{
1058 const struct spi_dt_spec *dt_spec = iodev_sqe->sqe.iodev->data;
1059 const struct device *dev = dt_spec->bus;
1060 const struct spi_driver_api *api = (const struct spi_driver_api *)dev->api;
1061
1062 api->iodev_submit(dt_spec->bus, iodev_sqe);
1063}
1064
1065extern const struct rtio_iodev_api spi_iodev_api;
1066
1078#define SPI_DT_IODEV_DEFINE(name, node_id, operation_, delay_) \
1079 const struct spi_dt_spec _spi_dt_spec_##name = \
1080 SPI_DT_SPEC_GET(node_id, operation_, delay_); \
1081 RTIO_IODEV_DEFINE(name, &spi_iodev_api, (void *)&_spi_dt_spec_##name)
1082
1091static inline bool spi_is_ready_iodev(const struct rtio_iodev *spi_iodev)
1092{
1093 struct spi_dt_spec *spec = spi_iodev->data;
1094
1095 return spi_is_ready_dt(spec);
1096}
1097
1110static inline int spi_rtio_copy(struct rtio *r,
1111 struct rtio_iodev *iodev,
1112 const struct spi_buf_set *tx_bufs,
1113 const struct spi_buf_set *rx_bufs,
1114 struct rtio_sqe **last_sqe)
1115{
1116 int ret = 0;
1117 size_t tx_count = tx_bufs ? tx_bufs->count : 0;
1118 size_t rx_count = rx_bufs ? rx_bufs->count : 0;
1119
1120 uint32_t tx = 0, tx_len = 0;
1121 uint32_t rx = 0, rx_len = 0;
1122 uint8_t *tx_buf, *rx_buf;
1123
1124 struct rtio_sqe *sqe = NULL;
1125
1126 if (tx < tx_count) {
1127 tx_buf = tx_bufs->buffers[tx].buf;
1128 tx_len = tx_bufs->buffers[tx].len;
1129 } else {
1130 tx_buf = NULL;
1131 tx_len = rx_bufs->buffers[rx].len;
1132 }
1133
1134 if (rx < rx_count) {
1135 rx_buf = rx_bufs->buffers[rx].buf;
1136 rx_len = rx_bufs->buffers[rx].len;
1137 } else {
1138 rx_buf = NULL;
1139 rx_len = tx_bufs->buffers[tx].len;
1140 }
1141
1142
1143 while ((tx < tx_count || rx < rx_count) && (tx_len > 0 || rx_len > 0)) {
1144 sqe = rtio_sqe_acquire(r);
1145
1146 if (sqe == NULL) {
1147 ret = -ENOMEM;
1149 goto out;
1150 }
1151
1152 ret++;
1153
1154 /* If tx/rx len are same, we can do a simple transceive */
1155 if (tx_len == rx_len) {
1156 if (tx_buf == NULL) {
1158 rx_buf, rx_len, NULL);
1159 } else if (rx_buf == NULL) {
1161 tx_buf, tx_len, NULL);
1162 } else {
1164 tx_buf, rx_buf, rx_len, NULL);
1165 }
1166 tx++;
1167 rx++;
1168 if (rx < rx_count) {
1169 rx_buf = rx_bufs->buffers[rx].buf;
1170 rx_len = rx_bufs->buffers[rx].len;
1171 } else {
1172 rx_buf = NULL;
1173 rx_len = 0;
1174 }
1175 if (tx < tx_count) {
1176 tx_buf = tx_bufs->buffers[tx].buf;
1177 tx_len = tx_bufs->buffers[tx].len;
1178 } else {
1179 tx_buf = NULL;
1180 tx_len = 0;
1181 }
1182 } else if (tx_len == 0) {
1184 (uint8_t *)rx_buf,
1185 (uint32_t)rx_len,
1186 NULL);
1187 rx++;
1188 if (rx < rx_count) {
1189 rx_buf = rx_bufs->buffers[rx].buf;
1190 rx_len = rx_bufs->buffers[rx].len;
1191 } else {
1192 rx_buf = NULL;
1193 rx_len = 0;
1194 }
1195 } else if (rx_len == 0) {
1197 (uint8_t *)tx_buf,
1198 (uint32_t)tx_len,
1199 NULL);
1200 tx++;
1201 if (tx < tx_count) {
1202 tx_buf = rx_bufs->buffers[rx].buf;
1203 tx_len = rx_bufs->buffers[rx].len;
1204 } else {
1205 tx_buf = NULL;
1206 tx_len = 0;
1207 }
1208 } else if (tx_len > rx_len) {
1210 (uint8_t *)tx_buf,
1211 (uint8_t *)rx_buf,
1212 (uint32_t)rx_len,
1213 NULL);
1214 tx_len -= rx_len;
1215 tx_buf += rx_len;
1216 rx++;
1217 if (rx < rx_count) {
1218 rx_buf = rx_bufs->buffers[rx].buf;
1219 rx_len = rx_bufs->buffers[rx].len;
1220 } else {
1221 rx_buf = NULL;
1222 rx_len = tx_len;
1223 }
1224 } else if (rx_len > tx_len) {
1226 (uint8_t *)tx_buf,
1227 (uint8_t *)rx_buf,
1228 (uint32_t)tx_len,
1229 NULL);
1230 rx_len -= tx_len;
1231 rx_buf += tx_len;
1232 tx++;
1233 if (tx < tx_count) {
1234 tx_buf = tx_bufs->buffers[tx].buf;
1235 tx_len = tx_bufs->buffers[tx].len;
1236 } else {
1237 tx_buf = NULL;
1238 tx_len = rx_len;
1239 }
1240 } else {
1241 __ASSERT_NO_MSG("Invalid spi_rtio_copy state");
1242 }
1243
1245 }
1246
1247 if (sqe != NULL) {
1248 sqe->flags = 0;
1249 *last_sqe = sqe;
1250 }
1251
1252out:
1253 return ret;
1254}
1255
1256#endif /* CONFIG_SPI_RTIO */
1257
1278__syscall int spi_release(const struct device *dev,
1279 const struct spi_config *config);
1280
1281static inline int z_impl_spi_release(const struct device *dev,
1282 const struct spi_config *config)
1283{
1284 const struct spi_driver_api *api =
1285 (const struct spi_driver_api *)dev->api;
1286
1287 return api->release(dev, config);
1288}
1289
1301static inline int spi_release_dt(const struct spi_dt_spec *spec)
1302{
1303 return spi_release(spec->bus, &spec->config);
1304}
1305
1306#ifdef __cplusplus
1307}
1308#endif
1309
1314#include <syscalls/spi.h>
1315
1316#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:831
#define RTIO_SQE_TRANSACTION
The next request in the queue is part of a transaction.
Definition: rtio.h:106
#define RTIO_PRIO_NORM
Normal priority.
Definition: rtio.h:68
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:599
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:490
static struct rtio_sqe * rtio_sqe_acquire(struct rtio *r)
Acquire a single submission queue event if available.
Definition: rtio.h:884
static void rtio_sqe_drop_all(struct rtio *r)
Drop all previously acquired sqe.
Definition: rtio.h:902
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:530
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:603
uint16_t spi_operation_t
Opaque type to hold the SPI operation flags.
Definition: spi.h:278
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:596
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:849
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:699
static int spi_write_async(const struct device *dev, const struct spi_config *config, const struct spi_buf_set *tx_bufs, struct k_poll_signal *sig)
Alias for spi_write_signal for backwards compatibility.
Definition: spi.h:1034
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:927
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:789
static int spi_read_async(const struct device *dev, const struct spi_config *config, const struct spi_buf_set *rx_bufs, struct k_poll_signal *sig)
Alias for spi_read_signal for backwards compatibility.
Definition: spi.h:990
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:766
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:883
#define SPI_STATS_TRANSFER_ERROR_INC(dev_)
Definition: spi.h:573
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:808
static bool spi_is_ready(const struct spi_dt_spec *spec)
Validate that SPI bus is ready.
Definition: spi.h:677
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:830
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:1110
static int spi_release_dt(const struct spi_dt_spec *spec)
Release the SPI device specified in spi_dt_spec.
Definition: spi.h:1301
int(* spi_api_release)(const struct device *dev, const struct spi_config *config)
Callback API for unlocking SPI device.
Definition: spi.h:625
static void spi_iodev_submit(struct rtio_iodev_sqe *iodev_sqe)
Submit a SPI device with a request.
Definition: spi.h:1056
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:977
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:584
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:663
static int spi_transceive_async(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)
Alias for spi_transceive_signal for backwards compatibility.
Definition: spi.h:945
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:575
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:1021
static bool spi_cs_is_gpio(const struct spi_config *config)
Check if SPI CS is controlled using a GPIO.
Definition: spi.h:651
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:1091
#define ENOMEM
Not enough core.
Definition: errno.h:51
Public kernel APIs.
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:354
Runtime device structure (in ROM) per driver instance.
Definition: device.h:381
void * data
Address of the device instance private data.
Definition: device.h:391
const void * api
Address of the API structure exposed by the device instance.
Definition: device.h:387
Container for GPIO pin information specified in devicetree.
Definition: gpio.h:286
const struct device * port
GPIO device controlling the pin.
Definition: gpio.h:288
Definition: kernel.h:5627
API that an RTIO IO device should implement.
Definition: rtio.h:429
Compute the mempool block index for a given pointer.
Definition: rtio.h:419
struct rtio_sqe sqe
Definition: rtio.h:420
An IO device with a function table for submitting requests.
Definition: rtio.h:444
void * data
Definition: rtio.h:452
A submission queue event.
Definition: rtio.h:230
uint8_t * tx_buf
Definition: rtio.h:275
uint8_t * rx_buf
Definition: rtio.h:276
const struct rtio_iodev * iodev
Device to operation on.
Definition: rtio.h:241
uint16_t flags
Op Flags.
Definition: rtio.h:235
An RTIO context containing what can be viewed as a pair of queues.
Definition: rtio.h:323
SPI buffer array structure.
Definition: spi.h:422
const struct spi_buf * buffers
Definition: spi.h:423
size_t count
Definition: spi.h:424
SPI buffer structure.
Definition: spi.h:411
size_t len
Definition: spi.h:413
void * buf
Definition: spi.h:412
SPI controller configuration structure.
Definition: spi.h:284
uint16_t slave
Slave number from 0 to host controller slave limit.
Definition: spi.h:309
struct spi_cs_control cs
GPIO chip-select line (optional, must be initialized to zero if not used).
Definition: spi.h:314
spi_operation_t operation
Operation flags.
Definition: spi.h:307
uint32_t frequency
Bus frequency in Hertz.
Definition: spi.h:286
SPI Chip Select control structure.
Definition: spi.h:148
uint32_t delay
Delay in microseconds to wait before starting the transmission and before releasing the CS line.
Definition: spi.h:161
struct gpio_dt_spec gpio
GPIO devicetree specification of CS GPIO.
Definition: spi.h:156
SPI driver API This is the mandatory API any SPI driver needs to expose.
Definition: spi.h:633
spi_api_io transceive
Definition: spi.h:634
spi_api_release release
Definition: spi.h:641
Complete SPI DT information.
Definition: spi.h:360
const struct device * bus
Definition: spi.h:361
struct spi_config config
Definition: spi.h:362