Loading...
Searching...
No Matches
dose.h
Go to the documentation of this file.
1/*
2 * Copyright (C) 2019 Juergen Fitschen <me@jue.yt>
3 *
4 * This file is subject to the terms and conditions of the GNU Lesser General
5 * Public License v2.1. See the file LICENSE in the top level directory for more
6 * details.
7 */
8
74#ifndef DOSE_H
75#define DOSE_H
76
77#include "chunked_ringbuffer.h"
78#include "periph/uart.h"
79#include "periph/gpio.h"
80#include "net/netdev.h"
81#include "net/ethernet.h"
82#include "net/eui48.h"
83#include "bitarithm.h"
84#include "mutex.h"
85#include "ztimer.h"
86
87#ifdef __cplusplus
88extern "C" {
89#endif
90
95#define DOSE_OCTET_END (0xFF)
96#define DOSE_OCTET_ESC (0xFE)
113
127
133#define DOSE_FLAG_RECV_BUF_DIRTY (BIT0)
134#define DOSE_FLAG_END_RECEIVED (BIT1)
135#define DOSE_FLAG_ESC_RECEIVED (BIT2)
136#define DOSE_FLAG_SEND_PENDING (BIT3)
144#define DOSE_OPT_PROMISCUOUS (BIT0)
157#ifndef CONFIG_DOSE_TIMEOUT_BYTES
158#define CONFIG_DOSE_TIMEOUT_BYTES (50)
159#endif
162#define DOSE_FRAME_CRC_LEN (2)
168#ifndef CONFIG_DOSE_RX_BUF_LEN
169#define CONFIG_DOSE_RX_BUF_LEN (ETHERNET_FRAME_LEN + DOSE_FRAME_CRC_LEN)
170#endif
171
178#if DOXYGEN
179#define DOSE_TIMER_DEV TIMER_DEV(…)
180#endif
181
186typedef struct {
189 uint8_t opts;
192 uint8_t recv_buf[CONFIG_DOSE_RX_BUF_LEN];
194 /* Written to from interrupts (with irq_disable */
195 /* to prevent any simultaneous writes), */
196 /* consumed exclusively in the network stack's */
197 /* loop at _isr. */
198#if defined(MODULE_DOSE_WATCHDOG) || DOXYGEN
200#endif
201#if !defined(MODULE_PERIPH_UART_RXSTART_IRQ) || DOXYGEN
202 gpio_t sense_pin;
203#endif
204 gpio_t standby_pin;
206 uint32_t timeout_base;
208 uint8_t uart_octet;
209 uint8_t flags;
210} dose_t;
211
215typedef struct {
217#if !defined(MODULE_PERIPH_UART_RXSTART_IRQ) || DOXYGEN
218 gpio_t sense_pin;
219#endif
220 gpio_t standby_pin;
221 uint32_t baudrate;
223
231void dose_setup(dose_t *dev, const dose_params_t *params, uint8_t index);
232
233#ifdef __cplusplus
234}
235#endif
236#endif /* DOSE_H */
Helper functions for bit arithmetic.
Chunked Ringbuffer.
Definitions low-level network driver interface.
Low-level GPIO peripheral driver interface definitions.
Low-level UART peripheral driver interface definition.
Definitions for Ethernet.
Definition and IPv6 IID conversion for IEEE EUI-48 identifiers.
#define CONFIG_DOSE_RX_BUF_LEN
DOSE RX buffer length Should be large enough to fit at least one Ethernet frame.
Definition dose.h:169
dose_signal_t
Definition dose.h:118
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:103
@ DOSE_SIGNAL_GPIO
Sense GPIO detected a falling edge.
Definition dose.h:121
@ DOSE_SIGNAL_INIT
Init the state machine.
Definition dose.h:120
@ DOSE_SIGNAL_UART
Octet has been received.
Definition dose.h:122
@ DOSE_SIGNAL_ZTIMER
Timer timed out.
Definition dose.h:123
@ DOSE_SIGNAL_NONE
No signal ...
Definition dose.h:119
@ DOSE_SIGNAL_END
Leave send state.
Definition dose.h:125
@ DOSE_SIGNAL_SEND
Enter send state.
Definition dose.h:124
@ DOSE_STATE_STANDBY
Receiver is turned off, but send will wake it up.
Definition dose.h:109
@ DOSE_STATE_BLOCKED
The driver just listens to incoming frames and blocks outgress frames.
Definition dose.h:105
@ DOSE_STATE_IDLE
Frames will be received or sent.
Definition dose.h:106
@ DOSE_STATE_SEND
Currently sending a frame.
Definition dose.h:108
@ DOSE_STATE_SLEEP
Receiver is turned off and send will be discarded.
Definition dose.h:110
@ DOSE_STATE_ANY
Special state filter used internally to observe any state transition.
Definition dose.h:111
@ DOSE_STATE_INIT
Initial state that will never be reentered.
Definition dose.h:104
@ DOSE_STATE_RECV
Currently receiving a frame.
Definition dose.h:107
uint_fast8_t uart_t
Define default UART type identifier.
Definition uart.h:85
Mutex for thread synchronization.
A chunked ringbuffer.
Struct containing the required configuration.
Definition dose.h:215
uint32_t baudrate
Baudrate to UART device.
Definition dose.h:221
uart_t uart
UART device to use.
Definition dose.h:216
gpio_t standby_pin
GPIO to put the CAN transceiver in standby mode.
Definition dose.h:220
gpio_t sense_pin
GPIO to sense for start bits on the UART's rx line.
Definition dose.h:218
DOSE netdev device.
Definition dose.h:186
netdev_t netdev
Extended netdev structure.
Definition dose.h:187
ztimer_t timeout
Timeout timer ensuring always to get back to IDLE state.
Definition dose.h:205
void * recv_buf_ptr_last
Last value of recv_buf_ptr when the watchdog visited.
Definition dose.h:199
uint8_t uart_octet
Last received octet.
Definition dose.h:208
uint32_t timeout_base
Base timeout in us.
Definition dose.h:206
mutex_t state_mtx
Is unlocked every time a state is (re)entered.
Definition dose.h:191
dose_state_t state
Current state of the driver's state machine.
Definition dose.h:190
gpio_t standby_pin
GPIO to put the CAN transceiver in standby mode.
Definition dose.h:204
gpio_t sense_pin
GPIO to sense for start bits on the UART's rx line.
Definition dose.h:202
uint8_t flags
Several flags.
Definition dose.h:209
uint8_t opts
Driver options.
Definition dose.h:189
uart_t uart
UART device to use.
Definition dose.h:207
chunk_ringbuf_t rb
Ringbuffer to store received frames.
Definition dose.h:193
eui48_t mac_addr
This device's MAC address.
Definition dose.h:188
Data type to represent an EUI-48.
Definition eui48.h:35
Mutex structure.
Definition mutex.h:146
Structure to hold driver state.
Definition netdev.h:363
ztimer structure
Definition ztimer.h:318
ztimer API