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
9#pragma once
10
75
76#include "chunked_ringbuffer.h"
77#include "periph/uart.h"
78#include "periph/gpio.h"
79#include "net/netdev.h"
80#include "net/ethernet.h"
81#include "net/eui48.h"
82#include "bitarithm.h"
83#include "mutex.h"
84#include "ztimer.h"
85
86#ifdef __cplusplus
87extern "C" {
88#endif
89
94#define DOSE_OCTET_END (0xFF)
95#define DOSE_OCTET_ESC (0xFE)
97
112
126
132#define DOSE_FLAG_RECV_BUF_DIRTY (BIT0)
133#define DOSE_FLAG_END_RECEIVED (BIT1)
134#define DOSE_FLAG_ESC_RECEIVED (BIT2)
135#define DOSE_FLAG_SEND_PENDING (BIT3)
137
143#define DOSE_OPT_PROMISCUOUS (BIT0)
145
156#ifndef CONFIG_DOSE_TIMEOUT_BYTES
157#define CONFIG_DOSE_TIMEOUT_BYTES (50)
158#endif
160
161#define DOSE_FRAME_CRC_LEN (2)
162
167#ifndef CONFIG_DOSE_RX_BUF_LEN
168#define CONFIG_DOSE_RX_BUF_LEN (ETHERNET_FRAME_LEN + DOSE_FRAME_CRC_LEN)
169#endif
170
177#if DOXYGEN
178#define DOSE_TIMER_DEV TIMER_DEV(…)
179#endif
180
185typedef struct {
188 uint8_t opts;
193 /* Written to from interrupts (with irq_disable */
194 /* to prevent any simultaneous writes), */
195 /* consumed exclusively in the network stack's */
196 /* loop at _isr. */
197#if defined(MODULE_DOSE_WATCHDOG) || DOXYGEN
199#endif
200#if !defined(MODULE_PERIPH_UART_RXSTART_IRQ) || DOXYGEN
201 gpio_t sense_pin;
202#endif
203 gpio_t standby_pin;
205 uint32_t timeout_base;
207 uint8_t uart_octet;
208 uint8_t flags;
209} dose_t;
210
214typedef struct {
216#if !defined(MODULE_PERIPH_UART_RXSTART_IRQ) || DOXYGEN
217 gpio_t sense_pin;
218#endif
219 gpio_t standby_pin;
220 uint32_t baudrate;
222
230void dose_setup(dose_t *dev, const dose_params_t *params, uint8_t index);
231
232#ifdef __cplusplus
233}
234#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:168
dose_signal_t
Definition dose.h:117
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:102
@ DOSE_SIGNAL_GPIO
Sense GPIO detected a falling edge.
Definition dose.h:120
@ DOSE_SIGNAL_INIT
Init the state machine.
Definition dose.h:119
@ DOSE_SIGNAL_UART
Octet has been received.
Definition dose.h:121
@ DOSE_SIGNAL_ZTIMER
Timer timed out.
Definition dose.h:122
@ DOSE_SIGNAL_NONE
No signal ...
Definition dose.h:118
@ DOSE_SIGNAL_END
Leave send state.
Definition dose.h:124
@ DOSE_SIGNAL_SEND
Enter send state.
Definition dose.h:123
@ DOSE_STATE_STANDBY
Receiver is turned off, but send will wake it up.
Definition dose.h:108
@ DOSE_STATE_BLOCKED
The driver just listens to incoming frames and blocks outgress frames.
Definition dose.h:104
@ DOSE_STATE_IDLE
Frames will be received or sent.
Definition dose.h:105
@ DOSE_STATE_SEND
Currently sending a frame.
Definition dose.h:107
@ DOSE_STATE_SLEEP
Receiver is turned off and send will be discarded.
Definition dose.h:109
@ DOSE_STATE_ANY
Special state filter used internally to observe any state transition.
Definition dose.h:110
@ DOSE_STATE_INIT
Initial state that will never be reentered.
Definition dose.h:103
@ DOSE_STATE_RECV
Currently receiving a frame.
Definition dose.h:106
struct netdev netdev_t
Forward declaration for netdev struct.
Definition netdev.h:288
uint_fast8_t uart_t
Define default UART type identifier.
Definition uart.h:84
Mutex for thread synchronization.
A chunked ringbuffer.
Struct containing the required configuration.
Definition dose.h:214
uint32_t baudrate
Baudrate to UART device.
Definition dose.h:220
uart_t uart
UART device to use.
Definition dose.h:215
gpio_t standby_pin
GPIO to put the CAN transceiver in standby mode.
Definition dose.h:219
gpio_t sense_pin
GPIO to sense for start bits on the UART's rx line.
Definition dose.h:217
DOSE netdev device.
Definition dose.h:185
netdev_t netdev
Extended netdev structure.
Definition dose.h:186
ztimer_t timeout
Timeout timer ensuring always to get back to IDLE state.
Definition dose.h:204
void * recv_buf_ptr_last
Last value of recv_buf_ptr when the watchdog visited.
Definition dose.h:198
uint8_t uart_octet
Last received octet.
Definition dose.h:207
uint32_t timeout_base
Base timeout in us.
Definition dose.h:205
mutex_t state_mtx
Is unlocked every time a state is (re)entered.
Definition dose.h:190
dose_state_t state
Current state of the driver's state machine.
Definition dose.h:189
gpio_t standby_pin
GPIO to put the CAN transceiver in standby mode.
Definition dose.h:203
gpio_t sense_pin
GPIO to sense for start bits on the UART's rx line.
Definition dose.h:201
uint8_t flags
Several flags.
Definition dose.h:208
uint8_t recv_buf[CONFIG_DOSE_RX_BUF_LEN]
Receive buffer for incoming frames.
Definition dose.h:191
uint8_t opts
Driver options.
Definition dose.h:188
uart_t uart
UART device to use.
Definition dose.h:206
chunk_ringbuf_t rb
Ringbuffer to store received frames.
Definition dose.h:192
eui48_t mac_addr
This device's MAC address.
Definition dose.h:187
Data type to represent an EUI-48.
Definition eui48.h:34
Mutex structure.
Definition mutex.h:39
ztimer structure
Definition ztimer.h:319
Low-level UART peripheral driver interface definition.
ztimer API