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