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 
56 #ifndef DOSE_H
57 #define DOSE_H
58 
59 #include "periph/uart.h"
60 #include "periph/gpio.h"
61 #include "net/netdev.h"
62 #include "net/ethernet.h"
63 #include "net/eui48.h"
64 #include "bitarithm.h"
65 #include "mutex.h"
66 #include "xtimer.h"
67 
68 #ifdef __cplusplus
69 extern "C" {
70 #endif
71 
76 #define DOSE_OCTET_END (0xFF)
77 #define DOSE_OCTET_ESC (0xFE)
84 typedef enum {
85  DOSE_STATE_INIT = 0x00,
87  DOSE_STATE_IDLE = 0x02,
88  DOSE_STATE_RECV = 0x03,
89  DOSE_STATE_SEND = 0x04,
92  DOSE_STATE_ANY = 0x0F
94 
99 typedef enum {
106  DOSE_SIGNAL_END = 0x60
108 
114 #define DOSE_FLAG_RECV_BUF_DIRTY (BIT0)
115 #define DOSE_FLAG_END_RECEIVED (BIT1)
116 #define DOSE_FLAG_ESC_RECEIVED (BIT2)
124 #define DOSE_OPT_PROMISCUOUS (BIT0)
137 #ifndef CONFIG_DOSE_TIMEOUT_BYTES
138 #define CONFIG_DOSE_TIMEOUT_BYTES (50)
139 #endif
142 #define DOSE_FRAME_CRC_LEN (2)
143 #define DOSE_FRAME_LEN (ETHERNET_FRAME_LEN + DOSE_FRAME_CRC_LEN)
149 typedef struct {
152  uint8_t opts;
155  uint8_t recv_buf[DOSE_FRAME_LEN];
156  size_t recv_buf_ptr;
157 #if !defined(MODULE_PERIPH_UART_RXSTART_IRQ) || DOXYGEN
158  gpio_t sense_pin;
159 #endif
160  gpio_t standby_pin;
162  uint32_t timeout_base;
164  uint8_t uart_octet;
165  uint8_t flags;
166 } dose_t;
167 
171 typedef struct {
173 #if !defined(MODULE_PERIPH_UART_RXSTART_IRQ) || DOXYGEN
174  gpio_t sense_pin;
175 #endif
176  gpio_t standby_pin;
177  uint32_t baudrate;
178 } dose_params_t;
179 
187 void dose_setup(dose_t *dev, const dose_params_t *params, uint8_t index);
188 
189 #ifdef __cplusplus
190 }
191 #endif
192 #endif /* DOSE_H */
Helper functions for bit arithmetic.
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.
dose_signal_t
Definition: dose.h:99
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:84
#define DOSE_FRAME_LEN
dose frame length
Definition: dose.h:143
@ DOSE_SIGNAL_GPIO
Sense GPIO detected a falling edge.
Definition: dose.h:102
@ DOSE_SIGNAL_INIT
Init the state machine.
Definition: dose.h:101
@ DOSE_SIGNAL_XTIMER
Timer timed out.
Definition: dose.h:104
@ DOSE_SIGNAL_UART
Octet has been received.
Definition: dose.h:103
@ DOSE_SIGNAL_NONE
No signal ...
Definition: dose.h:100
@ DOSE_SIGNAL_END
Leave send state.
Definition: dose.h:106
@ DOSE_SIGNAL_SEND
Enter send state.
Definition: dose.h:105
@ DOSE_STATE_STANDBY
Receiver is turned off, but send will wake it up.
Definition: dose.h:90
@ DOSE_STATE_BLOCKED
The driver just listens to incoming frames and blocks outgress frames.
Definition: dose.h:86
@ DOSE_STATE_IDLE
Frames will be received or sent.
Definition: dose.h:87
@ DOSE_STATE_SEND
Currently sending a frame.
Definition: dose.h:89
@ DOSE_STATE_SLEEP
Receiver is turned off and send will be discarded.
Definition: dose.h:91
@ DOSE_STATE_ANY
Special state filter used internally to observe any state transition.
Definition: dose.h:92
@ DOSE_STATE_INIT
Initial state that will never be reentered.
Definition: dose.h:85
@ DOSE_STATE_RECV
Currently receiving a frame.
Definition: dose.h:88
uint_fast8_t uart_t
Define default UART type identifier.
Definition: uart.h:77
Mutex for thread synchronization.
Struct containing the required configuration.
Definition: dose.h:171
uint32_t baudrate
Baudrate to UART device.
Definition: dose.h:177
uart_t uart
UART device to use.
Definition: dose.h:172
gpio_t standby_pin
GPIO to put the CAN transceiver in standby mode.
Definition: dose.h:176
gpio_t sense_pin
GPIO to sense for start bits on the UART's rx line.
Definition: dose.h:174
DOSE netdev device.
Definition: dose.h:149
netdev_t netdev
Extended netdev structure.
Definition: dose.h:150
size_t recv_buf_ptr
Index of the next empty octet of the recveive buffer.
Definition: dose.h:156
xtimer_t timeout
Timeout timer ensuring always to get back to IDLE state.
Definition: dose.h:161
uint8_t uart_octet
Last received octet.
Definition: dose.h:164
uint32_t timeout_base
Base timeout in us.
Definition: dose.h:162
mutex_t state_mtx
Is unlocked every time a state is (re)entered.
Definition: dose.h:154
dose_state_t state
Current state of the driver's state machine.
Definition: dose.h:153
gpio_t standby_pin
GPIO to put the CAN transceiver in standby mode.
Definition: dose.h:160
gpio_t sense_pin
GPIO to sense for start bits on the UART's rx line.
Definition: dose.h:158
uint8_t flags
Several flags.
Definition: dose.h:165
uint8_t opts
Driver options.
Definition: dose.h:152
uart_t uart
UART device to use.
Definition: dose.h:163
eui48_t mac_addr
This device's MAC address.
Definition: dose.h:151
Data type to represent an EUI-48.
Definition: eui48.h:35
Mutex structure.
Definition: mutex.h:123
Structure to hold driver state.
Definition: netdev.h:351
xtimer timer structure
Definition: xtimer.h:81
Low-level UART peripheral driver interface definition.
xtimer interface definitions