Loading...
Searching...
No Matches
ethos.h
Go to the documentation of this file.
1/*
2 * SPDX-FileCopyrightText: 2015 Kaspar Schleiser <kaspar@schleiser.de>
3 * SPDX-License-Identifier: LGPL-2.1-only
4 */
5
6#pragma once
7
22
34
35#include <stdbool.h>
36
37#include "periph/uart.h"
38#include "net/netdev.h"
39#include "tsrb.h"
40#include "mutex.h"
41#include "kernel_defines.h"
42
43#ifdef __cplusplus
44extern "C" {
45#endif
46
47/* if using ethos + stdio, use STDIO_UART values unless overridden */
48#if IS_USED(MODULE_ETHOS_STDIO) || defined(DOXYGEN)
49#include "stdio_uart.h"
58#ifndef ETHOS_UART
59#define ETHOS_UART STDIO_UART_DEV
60#endif
61
65#ifndef ETHOS_BAUDRATE
66#define ETHOS_BAUDRATE STDIO_UART_BAUDRATE
67#endif
69#else
70#ifndef ETHOS_UART
71#if IS_USED(MODULE_USBUS_CDC_ACM)
72#define ETHOS_UART UART_DEV(0)
73#else
74#define ETHOS_UART UART_DEV(1)
75#endif
76#endif
77#ifndef ETHOS_BAUDRATE
78#define ETHOS_BAUDRATE 115200
79#endif
80#endif
81
86#define ETHOS_FRAME_DELIMITER (0x7E)
87#define ETHOS_ESC_CHAR (0x7D)
88#define ETHOS_FRAME_TYPE_DATA (0x0)
89#define ETHOS_FRAME_TYPE_TEXT (0x1)
90#define ETHOS_FRAME_TYPE_HELLO (0x2)
91#define ETHOS_FRAME_TYPE_HELLO_REPLY (0x3)
93
97typedef enum {
98 WAIT_FRAMESTART,
99 IN_FRAME,
100 IN_ESCAPE
102
117
121typedef struct {
123 uint32_t baudrate;
125
142void ethos_setup(ethos_t *dev, const ethos_params_t *params, uint8_t index,
143 void *inbuf, size_t inbuf_size);
144
157void ethos_send_frame(ethos_t *dev, const uint8_t *data, size_t len, unsigned frame_type);
158
159#ifdef __cplusplus
160}
161#endif
Definitions low-level network driver interface.
line_state_t
Enum describing line state.
Definition ethos.h:97
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.
struct netdev netdev_t
Forward declaration for netdev struct.
Definition netdev.h:285
uint_fast8_t uart_t
Define default UART type identifier.
Definition uart.h:109
struct tsrb tsrb_t
thread-safe ringbuffer struct
Common macros and compiler attributes/pragmas configuration.
Mutex for thread synchronization.
Struct containing the needed configuration.
Definition ethos.h:121
uint32_t baudrate
baudrate to UART device
Definition ethos.h:123
uart_t uart
UART device to use.
Definition ethos.h:122
ethos netdev device
Definition ethos.h:107
tsrb_t inbuf
ringbuffer for incoming data
Definition ethos.h:112
mutex_t out_mutex
mutex used for locking concurrent sends
Definition ethos.h:115
unsigned frametype
type of currently incoming frame
Definition ethos.h:114
uint8_t remote_mac_addr[6]
this device's MAC address
Definition ethos.h:111
uint8_t mac_addr[6]
this device's MAC address
Definition ethos.h:110
netdev_t netdev
extended netdev structure
Definition ethos.h:108
line_state_t state
Line status variable.
Definition ethos.h:113
uart_t uart
UART device the to use.
Definition ethos.h:109
Mutex structure.
Definition mutex.h:36
Thread-safe ringbuffer interface definition.
Low-level UART peripheral driver interface definition.