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 "kernel_types.h"
27 #include "periph/uart.h"
28 #include "net/netdev.h"
29 #include "tsrb.h"
30 #include "mutex.h"
31 #include "kernel_defines.h"
32 
33 #ifdef __cplusplus
34 extern "C" {
35 #endif
36 
37 /* if using ethos + stdio, use STDIO_UART values unless overridden */
38 #if IS_USED(MODULE_STDIO_ETHOS) || defined(DOXYGEN)
39 #include "stdio_uart.h"
48 #ifndef ETHOS_UART
49 #define ETHOS_UART STDIO_UART_DEV
50 #endif
51 
55 #ifndef ETHOS_BAUDRATE
56 #define ETHOS_BAUDRATE STDIO_UART_BAUDRATE
57 #endif
58 
59 #endif
60 
65 #define ETHOS_FRAME_DELIMITER (0x7E)
66 #define ETHOS_ESC_CHAR (0x7D)
67 #define ETHOS_FRAME_TYPE_DATA (0x0)
68 #define ETHOS_FRAME_TYPE_TEXT (0x1)
69 #define ETHOS_FRAME_TYPE_HELLO (0x2)
70 #define ETHOS_FRAME_TYPE_HELLO_REPLY (0x3)
71 
76 typedef enum {
77  WAIT_FRAMESTART,
78  IN_FRAME,
79  IN_ESCAPE
80 } line_state_t;
81 
86 typedef struct {
89  uint8_t mac_addr[6];
90  uint8_t remote_mac_addr[6];
93  size_t framesize;
94  unsigned frametype;
95  size_t last_framesize;
97  bool accept_new;
98 } ethos_t;
99 
103 typedef struct {
105  uint32_t baudrate;
106  uint8_t *buf;
107  size_t bufsize;
109 
122 void ethos_setup(ethos_t *dev, const ethos_params_t *params);
123 
134 void ethos_send_frame(ethos_t *dev, const uint8_t *data, size_t len, unsigned frame_type);
135 
136 #ifdef __cplusplus
137 }
138 #endif
139 #endif /* ETHOS_H */
140 
ethos_params_t::buf
uint8_t * buf
buffer for incoming packets
Definition: ethos.h:106
ethos_t::inbuf
tsrb_t inbuf
ringbuffer for incoming data
Definition: ethos.h:91
stdio_uart.h
kernel_defines.h
Common macros and compiler attributes/pragmas configuration.
ethos_t::last_framesize
size_t last_framesize
size of last completed frame
Definition: ethos.h:95
ethos_send_frame
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.
uart_t
unsigned int uart_t
Define default UART type identifier.
Definition: uart.h:76
ethos_t::frametype
unsigned frametype
type of currently incoming frame
Definition: ethos.h:94
uart.h
Low-level UART peripheral driver interface definition.
ethos_t
ethos netdev device
Definition: ethos.h:86
ethos_params_t::baudrate
uint32_t baudrate
baudrate to UART device
Definition: ethos.h:105
netdev.h
Definitions low-level network driver interface.
ethos_setup
void ethos_setup(ethos_t *dev, const ethos_params_t *params)
Setup an ethos based device state.
ethos_params_t::uart
uart_t uart
UART device to use.
Definition: ethos.h:104
ethos_t::uart
uart_t uart
UART device the to use.
Definition: ethos.h:88
ethos_t::accept_new
bool accept_new
incoming frame can be stored or not
Definition: ethos.h:97
netdev
Structure to hold driver state.
Definition: netdev.h:302
ethos_t::out_mutex
mutex_t out_mutex
mutex used for locking concurrent sends
Definition: ethos.h:96
mutex.h
Mutex for thread synchronization.
ethos_t::netdev
netdev_t netdev
extended netdev structure
Definition: ethos.h:87
ethos_params_t::bufsize
size_t bufsize
size of ethos_params_t::buf
Definition: ethos.h:107
ethos_params_t
Struct containing the needed configuration.
Definition: ethos.h:103
tsrb
thread-safe ringbuffer struct
Definition: tsrb.h:39
ethos_t::state
line_state_t state
Line status variable.
Definition: ethos.h:92
kernel_types.h
Types used by the kernel.
mutex_t
Mutex structure.
Definition: mutex.h:120
tsrb.h
Thread-safe ringbuffer interface definition.
ethos_t::framesize
size_t framesize
size of currently incoming frame
Definition: ethos.h:93
line_state_t
line_state_t
Enum describing line state.
Definition: ethos.h:76