7#ifndef ZEPHYR_INCLUDE_DRIVERS_PULSE_IO_H_
8#define ZEPHYR_INCLUDE_DRIVERS_PULSE_IO_H_
224struct pulse_io_channel;
278 struct pulse_io_channel **chan);
296 int (*
stop)(
const struct device *dev,
struct pulse_io_channel *chan);
314static inline int z_impl_pulse_io_get_capabilities(
const struct device *dev,
337 struct pulse_io_channel **chan);
339static inline int z_impl_pulse_io_channel_get(
const struct device *dev,
uint8_t channel_idx,
340 struct pulse_io_channel **chan)
342 return DEVICE_API_GET(pulse_io, dev)->channel_get(dev, channel_idx, chan);
350static inline int z_impl_pulse_io_channel_release(
const struct device *dev,
351 struct pulse_io_channel *chan)
369static inline int z_impl_pulse_io_channel_configure(
const struct device *dev,
370 struct pulse_io_channel *chan,
373 return DEVICE_API_GET(pulse_io, dev)->channel_configure(dev, chan, cfg);
386static inline int z_impl_pulse_io_transmit_sync(
const struct device *dev,
387 struct pulse_io_channel *chan,
391 return DEVICE_API_GET(pulse_io, dev)->transmit_sync(dev, chan, req, timeout);
404static inline int z_impl_pulse_io_receive_sync(
const struct device *dev,
405 struct pulse_io_channel *chan,
409 return DEVICE_API_GET(pulse_io, dev)->receive_sync(dev, chan, req, count, timeout);
417static inline int z_impl_pulse_io_stop(
const struct device *dev,
struct pulse_io_channel *chan)
463 size_t nbytes,
struct pulse_symbol *out,
size_t out_cap,
485 struct pulse_symbol *out,
size_t out_cap,
size_t *produced);
511static inline int z_impl_pulse_io_get_encoder(
const struct device *dev,
531static inline int z_impl_pulse_io_get_decoder(
const struct device *dev,
549static inline void pulse_io_iodev_submit(
const struct device *dev,
struct rtio_iodev_sqe *iodev_sqe)
553 if (drv->
submit == NULL) {
557 drv->
submit(dev, iodev_sqe);
580#include <zephyr/syscalls/pulse_io.h>
#define DEVICE_API_GET(_class, _dev)
Expands to the pointer of a device's API for a given class.
Definition device.h:1449
int pulse_io_decode_bytes(const struct pulse_io_bit_template *tmpl, uint32_t tolerance_ticks, const struct pulse_symbol *in, size_t nsyms, uint8_t *out, size_t out_cap, size_t *produced)
Default symbol-stream decoder.
int pulse_io_channel_get(const struct device *dev, uint8_t channel_idx, struct pulse_io_channel **chan)
Reserve a channel for exclusive use.
pulse_io_dir
Direction of a configured channel.
Definition pulse_io.h:63
int pulse_io_receive_sync(const struct device *dev, struct pulse_io_channel *chan, const struct pulse_io_rx_req *req, size_t *count, k_timeout_t timeout)
Blocking receive.
int pulse_io_get_decoder(const struct device *dev, const struct pulse_io_decoder_api **api)
Fetch the backend decoder vtable.
int pulse_io_get_capabilities(const struct device *dev, struct pulse_io_caps *caps)
Query backend capabilities.
int pulse_io_transmit_sync(const struct device *dev, struct pulse_io_channel *chan, const struct pulse_io_tx_req *req, k_timeout_t timeout)
Blocking transmit.
int pulse_io_stop(const struct device *dev, struct pulse_io_channel *chan)
Stop any in-flight transmit or receive on the channel.
pulse_io_mode
Pulse stream submission modes.
Definition pulse_io.h:55
int pulse_io_channel_configure(const struct device *dev, struct pulse_io_channel *chan, const struct pulse_io_config *cfg)
Configure a reserved channel.
int pulse_io_encode_bytes(const struct pulse_io_bit_template *tmpl, const uint8_t *bytes, size_t nbytes, struct pulse_symbol *out, size_t out_cap, size_t *produced)
Expand a byte stream into pulse symbols using a bit template.
int pulse_io_get_encoder(const struct device *dev, const struct pulse_io_encoder_api **api)
Fetch the backend encoder vtable.
int pulse_io_channel_release(const struct device *dev, struct pulse_io_channel *chan)
Release a channel previously obtained via pulse_io_channel_get.
@ PULSE_IO_DIR_RX
Receive (capture edges).
Definition pulse_io.h:67
@ PULSE_IO_DIR_TX
Transmit (generate edges).
Definition pulse_io.h:65
@ PULSE_IO_MODE_SYMBOL
Arbitrary {level, duration} symbol stream.
Definition pulse_io.h:57
@ PULSE_IO_MODE_CELL
Fixed-period cells with per-cell duty or level.
Definition pulse_io.h:59
static void rtio_iodev_sqe_err(struct rtio_iodev_sqe *iodev_sqe, int result)
Inform the executor of a submissions completion with error.
Definition rtio.h:673
#define BIT(n)
Unsigned integer with bit position n set (signed in assembly language).
Definition util_macro.h:44
#define ENOSYS
Function not implemented.
Definition errno.h:83
Real-Time IO device API for moving bytes with low effort.
__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 structure (in ROM) per driver instance.
Definition device.h:513
Kernel timeout type.
Definition clock.h:65
One cell of a fixed-period pulse stream.
Definition pulse_io.h:96
uint16_t duty
High-time within the cell period, in ticks.
Definition pulse_io.h:98
uint16_t rsvd
Reserved; must be zero.
Definition pulse_io.h:102
uint16_t level
Line level for the cell (level-only backends).
Definition pulse_io.h:100
Per-bit template used by pulse_io_encode_bytes.
Definition pulse_io.h:440
bool msb_first
true: MSB first; false: LSB first.
Definition pulse_io.h:446
struct pulse_symbol zero[2]
Symbol pair emitted for a zero bit.
Definition pulse_io.h:442
struct pulse_symbol one[2]
Symbol pair emitted for a one bit.
Definition pulse_io.h:444
Per-instance capability descriptor.
Definition pulse_io.h:112
uint8_t num_channels
Total number of independent channels on this instance.
Definition pulse_io.h:153
uint8_t cell_duty_bits
Width of the duty field in CELL mode; 0 for level-only cells.
Definition pulse_io.h:151
bool supports_rx
Receive is supported.
Definition pulse_io.h:158
bool rx_dma_buffered
RX uses a DMA-backed ring buffer (vs.
Definition pulse_io.h:168
uint32_t tx_channel_mask
Bitmask of channels usable for TX (bit N = channel N).
Definition pulse_io.h:146
bool tx_loop_auto_stop
Hardware stops automatically at end of loop.
Definition pulse_io.h:162
uint32_t tx_loop_max
Maximum loop count for TX.
Definition pulse_io.h:134
uint32_t max_duration_ticks
Maximum duration per symbol in ticks.
Definition pulse_io.h:127
bool rx_streaming
RX supports ping-pong streaming beyond one buffer.
Definition pulse_io.h:170
uint32_t max_tick_ns
Coarsest tick with maximum prescaler, in nanoseconds.
Definition pulse_io.h:125
bool cell_period_per_chunk
Period can change between submissions in CELL mode.
Definition pulse_io.h:172
uint32_t rx_idle_threshold_max
Maximum end-of-frame idle threshold, in ticks.
Definition pulse_io.h:136
uint32_t rx_filter_max_ticks
Maximum glitch-filter width, in ticks; 0 if no filter.
Definition pulse_io.h:138
uint32_t rx_channel_mask
Bitmask of channels usable for RX (bit N = channel N).
Definition pulse_io.h:148
uint32_t min_tick_ns
Finest tick the hardware can produce, in nanoseconds.
Definition pulse_io.h:123
bool tx_sync_multi_channel
Multiple channels can start on the same clock edge.
Definition pulse_io.h:164
uint32_t modes
Bitmask of supported pulse_io_mode.
Definition pulse_io.h:121
bool supports_tx
Transmit is supported.
Definition pulse_io.h:156
bool rx_carrier_demod
Hardware carrier demodulation on RX.
Definition pulse_io.h:166
bool tx_carrier
Hardware carrier modulation on TX.
Definition pulse_io.h:160
size_t tx_min_chunk_symbols
Minimum chunk size for streaming (hardware FIFO depth).
Definition pulse_io.h:116
size_t tx_max_streaming
Maximum size of a single streaming transmit; SIZE_MAX if unbounded.
Definition pulse_io.h:118
Channel configuration.
Definition pulse_io.h:181
uint32_t resolution_hz
Tick rate in Hz.
Definition pulse_io.h:185
uint32_t cell_period_ticks
CELL mode only: cell period in ticks.
Definition pulse_io.h:187
enum pulse_io_mode mode
Submission mode for the channel.
Definition pulse_io.h:196
bool rx_carrier_demod
Enable HW carrier demodulation of the non-idle level on RX.
Definition pulse_io.h:214
bool idle_high
Line state when idle.
Definition pulse_io.h:210
uint32_t carrier_hz
TX carrier frequency in Hz.
Definition pulse_io.h:189
uint8_t carrier_duty_pct
TX carrier duty cycle in percent.
Definition pulse_io.h:201
enum pulse_io_dir dir
Channel direction.
Definition pulse_io.h:198
bool carrier_en
Enable TX carrier modulation on the non-idle level.
Definition pulse_io.h:212
uint32_t rx_idle_threshold_ticks
RX end-of-frame idle threshold in ticks; 0 to disable.
Definition pulse_io.h:191
uint32_t rx_filter_ticks
RX glitch filter width in ticks; 0 to disable.
Definition pulse_io.h:193
Decoder vtable: pulse symbols to protocol bytes.
Definition pulse_io.h:495
int(* decode)(const struct pulse_io_bit_template *tmpl, uint32_t tolerance_ticks, const struct pulse_symbol *in, size_t nsyms, uint8_t *out, size_t out_cap, size_t *produced)
Rebuild a byte stream from captured pulse symbols.
Definition pulse_io.h:497
Driver vtable.
Definition pulse_io.h:272
int(* stop)(const struct device *dev, struct pulse_io_channel *chan)
<span class="op-badge op-req" title="This operation MUST be implemented by the driver....
Definition pulse_io.h:296
int(* channel_release)(const struct device *dev, struct pulse_io_channel *chan)
<span class="op-badge op-req" title="This operation MUST be implemented by the driver....
Definition pulse_io.h:281
int(* receive_sync)(const struct device *dev, struct pulse_io_channel *chan, const struct pulse_io_rx_req *req, size_t *count, k_timeout_t timeout)
<span class="op-badge op-req" title="This operation MUST be implemented by the driver....
Definition pulse_io.h:292
int(* transmit_sync)(const struct device *dev, struct pulse_io_channel *chan, const struct pulse_io_tx_req *req, k_timeout_t timeout)
<span class="op-badge op-req" title="This operation MUST be implemented by the driver....
Definition pulse_io.h:288
int(* channel_configure)(const struct device *dev, struct pulse_io_channel *chan, const struct pulse_io_config *cfg)
<span class="op-badge op-req" title="This operation MUST be implemented by the driver....
Definition pulse_io.h:284
int(* get_capabilities)(const struct device *dev, struct pulse_io_caps *caps)
<span class="op-badge op-opt" title="This operation MAY optionally be implemented by the driver....
Definition pulse_io.h:274
int(* get_encoder)(const struct device *dev, const struct pulse_io_encoder_api **api)
<span class="op-badge op-opt" title="This operation MAY optionally be implemented by the driver....
Definition pulse_io.h:301
int(* get_decoder)(const struct device *dev, const struct pulse_io_decoder_api **api)
<span class="op-badge op-opt" title="This operation MAY optionally be implemented by the driver....
Definition pulse_io.h:303
int(* channel_get)(const struct device *dev, uint8_t channel_idx, struct pulse_io_channel **chan)
<span class="op-badge op-req" title="This operation MUST be implemented by the driver....
Definition pulse_io.h:277
void(* submit)(const struct device *dev, struct rtio_iodev_sqe *iodev_sqe)
<span class="op-badge op-opt" title="This operation MAY optionally be implemented by the driver....
Definition pulse_io.h:299
Encoder vtable: protocol bytes to pulse symbols.
Definition pulse_io.h:482
int(* encode)(const struct pulse_io_bit_template *tmpl, const uint8_t *bytes, size_t nbytes, struct pulse_symbol *out, size_t out_cap, size_t *produced)
Expand a byte stream into pulse symbols.
Definition pulse_io.h:484
RX submission descriptor.
Definition pulse_io.h:253
size_t capacity
Capacity of the destination buffer in entries.
Definition pulse_io.h:262
struct pulse_symbol * symbols
SYMBOL mode destination.
Definition pulse_io.h:257
struct pulse_cell * cells
CELL mode destination.
Definition pulse_io.h:259
TX submission descriptor.
Definition pulse_io.h:236
const struct pulse_cell * cells
CELL mode source.
Definition pulse_io.h:242
const struct pulse_symbol * symbols
SYMBOL mode source.
Definition pulse_io.h:240
uint32_t loop_count
0 = single shot; 1..tx_loop_max = finite; UINT32_MAX = infinite.
Definition pulse_io.h:247
size_t count
Number of entries in the source buffer.
Definition pulse_io.h:245
One symbol of a pulse stream.
Definition pulse_io.h:79
uint32_t duration
Duration in ticks of the configured resolution.
Definition pulse_io.h:81
uint32_t level
Line level for the duration (0 or 1).
Definition pulse_io.h:83
IO device submission queue entry.
Definition sqe.h:394