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 
9 #pragma once
10 
38 #include <stdbool.h>
39 
40 #include "periph/uart.h"
41 #include "net/netdev.h"
42 #include "tsrb.h"
43 #include "mutex.h"
44 #include "kernel_defines.h"
45 
46 #ifdef __cplusplus
47 extern "C" {
48 #endif
49 
50 /* if using ethos + stdio, use STDIO_UART values unless overridden */
51 #if IS_USED(MODULE_ETHOS_STDIO) || defined(DOXYGEN)
52 #include "stdio_uart.h"
61 #ifndef ETHOS_UART
62 #define ETHOS_UART STDIO_UART_DEV
63 #endif
64 
68 #ifndef ETHOS_BAUDRATE
69 #define ETHOS_BAUDRATE STDIO_UART_BAUDRATE
70 #endif
72 #else
73 #ifndef ETHOS_UART
74 #if IS_USED(MODULE_USBUS_CDC_ACM)
75 #define ETHOS_UART UART_DEV(0)
76 #else
77 #define ETHOS_UART UART_DEV(1)
78 #endif
79 #endif
80 #ifndef ETHOS_BAUDRATE
81 #define ETHOS_BAUDRATE 115200
82 #endif
83 #endif
84 
89 #define ETHOS_FRAME_DELIMITER (0x7E)
90 #define ETHOS_ESC_CHAR (0x7D)
91 #define ETHOS_FRAME_TYPE_DATA (0x0)
92 #define ETHOS_FRAME_TYPE_TEXT (0x1)
93 #define ETHOS_FRAME_TYPE_HELLO (0x2)
94 #define ETHOS_FRAME_TYPE_HELLO_REPLY (0x3)
100 typedef enum {
101  WAIT_FRAMESTART,
102  IN_FRAME,
103  IN_ESCAPE
104 } line_state_t;
105 
110 typedef struct {
113  uint8_t mac_addr[6];
114  uint8_t remote_mac_addr[6];
117  unsigned frametype;
119 } ethos_t;
120 
124 typedef struct {
126  uint32_t baudrate;
128 
145 void ethos_setup(ethos_t *dev, const ethos_params_t *params, uint8_t index,
146  void *inbuf, size_t inbuf_size);
147 
160 void ethos_send_frame(ethos_t *dev, const uint8_t *data, size_t len, unsigned frame_type);
161 
162 #ifdef __cplusplus
163 }
164 #endif
Definitions low-level network driver interface.
line_state_t
Enum describing line state.
Definition: ethos.h:100
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:84
Common macros and compiler attributes/pragmas configuration.
Mutex for thread synchronization.
Struct containing the needed configuration.
Definition: ethos.h:124
uint32_t baudrate
baudrate to UART device
Definition: ethos.h:126
uart_t uart
UART device to use.
Definition: ethos.h:125
ethos netdev device
Definition: ethos.h:110
tsrb_t inbuf
ringbuffer for incoming data
Definition: ethos.h:115
mutex_t out_mutex
mutex used for locking concurrent sends
Definition: ethos.h:118
unsigned frametype
type of currently incoming frame
Definition: ethos.h:117
netdev_t netdev
extended netdev structure
Definition: ethos.h:111
line_state_t state
Line status variable.
Definition: ethos.h:116
uart_t uart
UART device the to use.
Definition: ethos.h:112
Mutex structure.
Definition: mutex.h:39
Structure to hold driver state.
Definition: netdev.h:364
thread-safe ringbuffer struct
Definition: tsrb.h:38
Thread-safe ringbuffer interface definition.
Low-level UART peripheral driver interface definition.