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 
55 #ifndef DOSE_H
56 #define DOSE_H
57 
58 #include "periph/uart.h"
59 #include "periph/gpio.h"
60 #include "net/netdev.h"
61 #include "net/ethernet.h"
62 #include "net/eui48.h"
63 #include "bitarithm.h"
64 #include "mutex.h"
65 #include "xtimer.h"
66 
67 #ifdef __cplusplus
68 extern "C" {
69 #endif
70 
75 #define DOSE_OCTET_END (0xFF)
76 #define DOSE_OCTET_ESC (0xFE)
83 typedef enum {
84  DOSE_STATE_INIT = 0x00,
86  DOSE_STATE_IDLE = 0x02,
87  DOSE_STATE_RECV = 0x03,
88  DOSE_STATE_SEND = 0x04,
90 } dose_state_t;
91 
92 
97 typedef enum {
105 } dose_signal_t;
106 
107 
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_USEC
138 #define CONFIG_DOSE_TIMEOUT_USEC (5000)
139 #endif
140 
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 flags;
156  uint8_t recv_buf[DOSE_FRAME_LEN];
157  size_t recv_buf_ptr;
159  uint8_t uart_octet;
160  gpio_t sense_pin;
162  uint32_t timeout_base;
163 } dose_t;
164 
168 typedef struct {
170  gpio_t sense_pin;
171  uint32_t baudrate;
172 } dose_params_t;
173 
181 void dose_setup(dose_t *dev, const dose_params_t *params, uint8_t index);
182 
183 #ifdef __cplusplus
184 }
185 #endif
186 #endif /* DOSE_H */
187 
DOSE_STATE_IDLE
@ DOSE_STATE_IDLE
Frames will be received or sent.
Definition: dose.h:86
xtimer
xtimer timer structure
Definition: xtimer.h:81
dose_t
DOSE netdev device.
Definition: dose.h:149
DOSE_STATE_INIT
@ DOSE_STATE_INIT
Initial state that will never be reentered.
Definition: dose.h:84
dose_t::sense_pin
gpio_t sense_pin
GPIO to sense for start bits on the UART's rx line.
Definition: dose.h:160
DOSE_SIGNAL_SEND
@ DOSE_SIGNAL_SEND
Enter send state.
Definition: dose.h:103
ethernet.h
Definitions for Ethernet.
DOSE_SIGNAL_GPIO
@ DOSE_SIGNAL_GPIO
Sense GPIO detected a falling edge.
Definition: dose.h:100
eui48_t
Data type to represent an EUI-48.
Definition: eui48.h:35
dose_t::opts
uint8_t opts
Driver options.
Definition: dose.h:152
DOSE_STATE_SEND
@ DOSE_STATE_SEND
Currently sending a frame.
Definition: dose.h:88
uart_t
unsigned int uart_t
Define default UART type identifier.
Definition: uart.h:76
DOSE_SIGNAL_INIT
@ DOSE_SIGNAL_INIT
Init the state machine.
Definition: dose.h:99
uart.h
Low-level UART peripheral driver interface definition.
DOSE_STATE_ANY
@ DOSE_STATE_ANY
Special state filter used internally to observe any state transition.
Definition: dose.h:89
dose_setup
void dose_setup(dose_t *dev, const dose_params_t *params, uint8_t index)
Setup a DOSE based device state.
netdev.h
Definitions low-level network driver interface.
DOSE_SIGNAL_UART
@ DOSE_SIGNAL_UART
Octet has been received.
Definition: dose.h:101
dose_t::uart
uart_t uart
UART device to use.
Definition: dose.h:158
dose_signal_t
dose_signal_t
Definition: dose.h:97
dose_t::netdev
netdev_t netdev
Extended netdev structure.
Definition: dose.h:150
dose_t::state
dose_state_t state
Current state of the driver's state machine.
Definition: dose.h:153
bitarithm.h
Helper functions for bit arithmetic.
dose_t::uart_octet
uint8_t uart_octet
Last received octet.
Definition: dose.h:159
netdev
Structure to hold driver state.
Definition: netdev.h:302
dose_t::timeout_base
uint32_t timeout_base
Base timeout in us.
Definition: dose.h:162
dose_t::timeout
xtimer_t timeout
Timeout timer ensuring always to get back to IDLE state.
Definition: dose.h:161
mutex.h
Mutex for thread synchronization.
dose_t::mac_addr
eui48_t mac_addr
This device's MAC address.
Definition: dose.h:151
gpio.h
Low-level GPIO peripheral driver interface definitions.
dose_params_t::baudrate
uint32_t baudrate
Baudrate to UART device.
Definition: dose.h:171
DOSE_SIGNAL_NONE
@ DOSE_SIGNAL_NONE
No signal ...
Definition: dose.h:98
DOSE_STATE_RECV
@ DOSE_STATE_RECV
Currently receiving a frame.
Definition: dose.h:87
DOSE_FRAME_LEN
#define DOSE_FRAME_LEN
dose frame length
Definition: dose.h:143
DOSE_STATE_BLOCKED
@ DOSE_STATE_BLOCKED
The driver just listens to incoming frames and blocks outgress frames.
Definition: dose.h:85
DOSE_SIGNAL_XTIMER
@ DOSE_SIGNAL_XTIMER
Timer timed out.
Definition: dose.h:102
DOSE_SIGNAL_END
@ DOSE_SIGNAL_END
Leave send state.
Definition: dose.h:104
dose_params_t
Struct containing the required configuration.
Definition: dose.h:168
dose_t::flags
uint8_t flags
Several flags.
Definition: dose.h:155
dose_params_t::sense_pin
gpio_t sense_pin
GPIO to sense for start bits on the UART's rx line.
Definition: dose.h:170
dose_state_t
dose_state_t
Definition: dose.h:83
dose_t::state_mtx
mutex_t state_mtx
Is unlocked every time a state is (re)entered.
Definition: dose.h:154
xtimer.h
xtimer interface definitions
mutex_t
Mutex structure.
Definition: mutex.h:120
dose_t::recv_buf_ptr
size_t recv_buf_ptr
Index of the next empty octet of the recveive buffer.
Definition: dose.h:157
dose_params_t::uart
uart_t uart
UART device to use.
Definition: dose.h:169
eui48.h
Definition and IPv6 IID conversion for IEEE EUI-48 identifiers.