ethos.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2015 Kaspar Schleiser <kaspar@schleiser.de>
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 
21 #ifndef ETHOS_H
22 #define ETHOS_H
23 
24 #include <stdbool.h>
25 
26 #include "periph/uart.h"
27 #include "net/netdev.h"
28 #include "tsrb.h"
29 #include "mutex.h"
30 #include "kernel_defines.h"
31 
32 #ifdef __cplusplus
33 extern "C" {
34 #endif
35 
36 /* if using ethos + stdio, use STDIO_UART values unless overridden */
37 #if IS_USED(MODULE_ETHOS_STDIO) || defined(DOXYGEN)
38 #include "stdio_uart.h"
47 #ifndef ETHOS_UART
48 #define ETHOS_UART STDIO_UART_DEV
49 #endif
50 
54 #ifndef ETHOS_BAUDRATE
55 #define ETHOS_BAUDRATE STDIO_UART_BAUDRATE
56 #endif
58 #else
59 #ifndef ETHOS_UART
60 #if IS_USED(MODULE_USBUS_CDC_ACM)
61 #define ETHOS_UART UART_DEV(0)
62 #else
63 #define ETHOS_UART UART_DEV(1)
64 #endif
65 #endif
66 #ifndef ETHOS_BAUDRATE
67 #define ETHOS_BAUDRATE 115200
68 #endif
69 #endif
70 
75 #define ETHOS_FRAME_DELIMITER (0x7E)
76 #define ETHOS_ESC_CHAR (0x7D)
77 #define ETHOS_FRAME_TYPE_DATA (0x0)
78 #define ETHOS_FRAME_TYPE_TEXT (0x1)
79 #define ETHOS_FRAME_TYPE_HELLO (0x2)
80 #define ETHOS_FRAME_TYPE_HELLO_REPLY (0x3)
86 typedef enum {
87  WAIT_FRAMESTART,
88  IN_FRAME,
89  IN_ESCAPE
90 } line_state_t;
91 
96 typedef struct {
99  uint8_t mac_addr[6];
100  uint8_t remote_mac_addr[6];
103  unsigned frametype;
105 } ethos_t;
106 
110 typedef struct {
112  uint32_t baudrate;
114 
131 void ethos_setup(ethos_t *dev, const ethos_params_t *params, uint8_t index,
132  void *inbuf, size_t inbuf_size);
133 
146 void ethos_send_frame(ethos_t *dev, const uint8_t *data, size_t len, unsigned frame_type);
147 
148 #ifdef __cplusplus
149 }
150 #endif
151 #endif /* ETHOS_H */
Definitions low-level network driver interface.
Low-level UART peripheral driver interface definition.
line_state_t
Enum describing line state.
Definition: ethos.h:86
void ethos_send_frame(ethos_t *dev, const uint8_t *data, size_t len, unsigned frame_type)
Send frame over serial port using ethos' framing.
void ethos_setup(ethos_t *dev, const ethos_params_t *params, uint8_t index, void *inbuf, size_t inbuf_size)
Setup an ethos based device state.
uint_fast8_t uart_t
Define default UART type identifier.
Definition: uart.h:77
Common macros and compiler attributes/pragmas configuration.
Mutex for thread synchronization.
Struct containing the needed configuration.
Definition: ethos.h:110
uint32_t baudrate
baudrate to UART device
Definition: ethos.h:112
uart_t uart
UART device to use.
Definition: ethos.h:111
ethos netdev device
Definition: ethos.h:96
tsrb_t inbuf
ringbuffer for incoming data
Definition: ethos.h:101
mutex_t out_mutex
mutex used for locking concurrent sends
Definition: ethos.h:104
unsigned frametype
type of currently incoming frame
Definition: ethos.h:103
netdev_t netdev
extended netdev structure
Definition: ethos.h:97
line_state_t state
Line status variable.
Definition: ethos.h:102
uart_t uart
UART device the to use.
Definition: ethos.h:98
Mutex structure.
Definition: mutex.h:129
Structure to hold driver state.
Definition: netdev.h:361
thread-safe ringbuffer struct
Definition: tsrb.h:39
Thread-safe ringbuffer interface definition.