Loading...
Searching...
No Matches
dose.h
Go to the documentation of this file.
1/*
2 * SPDX-FileCopyrightText: 2019 Juergen Fitschen <me@jue.yt>
3 * SPDX-License-Identifier: LGPL-2.1-only
4 */
5
6#pragma once
7
72
73#include "chunked_ringbuffer.h"
74#include "periph/uart.h"
75#include "periph/gpio.h"
76#include "net/netdev.h"
77#include "net/ethernet.h"
78#include "net/eui48.h"
79#include "bitarithm.h"
80#include "mutex.h"
81#include "ztimer.h"
82
83#ifdef __cplusplus
84extern "C" {
85#endif
86
91#define DOSE_OCTET_END (0xFF)
92#define DOSE_OCTET_ESC (0xFE)
94
109
123
129#define DOSE_FLAG_RECV_BUF_DIRTY (BIT0)
130#define DOSE_FLAG_END_RECEIVED (BIT1)
131#define DOSE_FLAG_ESC_RECEIVED (BIT2)
132#define DOSE_FLAG_SEND_PENDING (BIT3)
134
140#define DOSE_OPT_PROMISCUOUS (BIT0)
142
153#ifndef CONFIG_DOSE_TIMEOUT_BYTES
154#define CONFIG_DOSE_TIMEOUT_BYTES (50)
155#endif
157
158#define DOSE_FRAME_CRC_LEN (2)
159
164#ifndef CONFIG_DOSE_RX_BUF_LEN
165#define CONFIG_DOSE_RX_BUF_LEN (ETHERNET_FRAME_LEN + DOSE_FRAME_CRC_LEN)
166#endif
167
174#if DOXYGEN
175#define DOSE_TIMER_DEV TIMER_DEV(…)
176#endif
177
182typedef struct {
185 uint8_t opts;
190 /* Written to from interrupts (with irq_disable */
191 /* to prevent any simultaneous writes), */
192 /* consumed exclusively in the network stack's */
193 /* loop at _isr. */
194#if defined(MODULE_DOSE_WATCHDOG) || DOXYGEN
196#endif
197#if !defined(MODULE_PERIPH_UART_RXSTART_IRQ) || DOXYGEN
198 gpio_t sense_pin;
199#endif
200 gpio_t standby_pin;
202 uint32_t timeout_base;
204 uint8_t uart_octet;
205 uint8_t flags;
206} dose_t;
207
211typedef struct {
213#if !defined(MODULE_PERIPH_UART_RXSTART_IRQ) || DOXYGEN
214 gpio_t sense_pin;
215#endif
216 gpio_t standby_pin;
217 uint32_t baudrate;
219
227void dose_setup(dose_t *dev, const dose_params_t *params, uint8_t index);
228
229#ifdef __cplusplus
230}
231#endif
Helper functions for bit arithmetic.
Chunked Ringbuffer.
Definitions low-level network driver interface.
Definitions for Ethernet.
Definition and IPv6 IID conversion for IEEE EUI-48 identifiers.
Low-level GPIO peripheral driver interface definitions.
#define CONFIG_DOSE_RX_BUF_LEN
DOSE RX buffer length Should be large enough to fit at least one Ethernet frame.
Definition dose.h:165
dose_signal_t
Definition dose.h:114
void dose_setup(dose_t *dev, const dose_params_t *params, uint8_t index)
Setup a DOSE based device state.
dose_state_t
Definition dose.h:99
@ DOSE_SIGNAL_GPIO
Sense GPIO detected a falling edge.
Definition dose.h:117
@ DOSE_SIGNAL_INIT
Init the state machine.
Definition dose.h:116
@ DOSE_SIGNAL_UART
Octet has been received.
Definition dose.h:118
@ DOSE_SIGNAL_ZTIMER
Timer timed out.
Definition dose.h:119
@ DOSE_SIGNAL_NONE
No signal ...
Definition dose.h:115
@ DOSE_SIGNAL_END
Leave send state.
Definition dose.h:121
@ DOSE_SIGNAL_SEND
Enter send state.
Definition dose.h:120
@ DOSE_STATE_STANDBY
Receiver is turned off, but send will wake it up.
Definition dose.h:105
@ DOSE_STATE_BLOCKED
The driver just listens to incoming frames and blocks outgress frames.
Definition dose.h:101
@ DOSE_STATE_IDLE
Frames will be received or sent.
Definition dose.h:102
@ DOSE_STATE_SEND
Currently sending a frame.
Definition dose.h:104
@ DOSE_STATE_SLEEP
Receiver is turned off and send will be discarded.
Definition dose.h:106
@ DOSE_STATE_ANY
Special state filter used internally to observe any state transition.
Definition dose.h:107
@ DOSE_STATE_INIT
Initial state that will never be reentered.
Definition dose.h:100
@ DOSE_STATE_RECV
Currently receiving a frame.
Definition dose.h:103
struct netdev netdev_t
Forward declaration for netdev struct.
Definition netdev.h:285
uint_fast8_t uart_t
Define default UART type identifier.
Definition uart.h:109
Mutex for thread synchronization.
A chunked ringbuffer.
Struct containing the required configuration.
Definition dose.h:211
uint32_t baudrate
Baudrate to UART device.
Definition dose.h:217
uart_t uart
UART device to use.
Definition dose.h:212
gpio_t standby_pin
GPIO to put the CAN transceiver in standby mode.
Definition dose.h:216
gpio_t sense_pin
GPIO to sense for start bits on the UART's rx line.
Definition dose.h:214
DOSE netdev device.
Definition dose.h:182
netdev_t netdev
Extended netdev structure.
Definition dose.h:183
ztimer_t timeout
Timeout timer ensuring always to get back to IDLE state.
Definition dose.h:201
void * recv_buf_ptr_last
Last value of recv_buf_ptr when the watchdog visited.
Definition dose.h:195
uint8_t uart_octet
Last received octet.
Definition dose.h:204
uint32_t timeout_base
Base timeout in us.
Definition dose.h:202
mutex_t state_mtx
Is unlocked every time a state is (re)entered.
Definition dose.h:187
dose_state_t state
Current state of the driver's state machine.
Definition dose.h:186
gpio_t standby_pin
GPIO to put the CAN transceiver in standby mode.
Definition dose.h:200
gpio_t sense_pin
GPIO to sense for start bits on the UART's rx line.
Definition dose.h:198
uint8_t flags
Several flags.
Definition dose.h:205
uint8_t recv_buf[CONFIG_DOSE_RX_BUF_LEN]
Receive buffer for incoming frames.
Definition dose.h:188
uint8_t opts
Driver options.
Definition dose.h:185
uart_t uart
UART device to use.
Definition dose.h:203
chunk_ringbuf_t rb
Ringbuffer to store received frames.
Definition dose.h:189
eui48_t mac_addr
This device's MAC address.
Definition dose.h:184
Data type to represent an EUI-48.
Definition eui48.h:34
Mutex structure.
Definition mutex.h:36
ztimer structure
Definition ztimer.h:319
Low-level UART peripheral driver interface definition.
ztimer API