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 "kernel_types.h"
25 #include "periph/uart.h"
26 #include "net/netdev.h"
27 #include "tsrb.h"
28 #include "mutex.h"
29 
30 #ifdef __cplusplus
31 extern "C" {
32 #endif
33 
34 /* if using ethos + stdio, use UART_STDIO values unless overridden */
35 #ifdef USE_ETHOS_FOR_STDIO
36 #include "uart_stdio.h"
37 #ifndef ETHOS_UART
38 #define ETHOS_UART UART_STDIO_DEV
39 #endif
40 #ifndef ETHOS_BAUDRATE
41 #define ETHOS_BAUDRATE UART_STDIO_BAUDRATE
42 #endif
43 #endif
44 
49 #define ETHOS_FRAME_DELIMITER (0x7E)
50 #define ETHOS_ESC_CHAR (0x7D)
51 #define ETHOS_FRAME_TYPE_DATA (0x0)
52 #define ETHOS_FRAME_TYPE_TEXT (0x1)
53 #define ETHOS_FRAME_TYPE_HELLO (0x2)
54 #define ETHOS_FRAME_TYPE_HELLO_REPLY (0x3)
55 
60 typedef enum {
61  WAIT_FRAMESTART,
62  IN_FRAME,
63  IN_ESCAPE
64 } line_state_t;
65 
70 typedef struct {
73  uint8_t mac_addr[6];
74  uint8_t remote_mac_addr[6];
77  size_t framesize;
78  unsigned frametype;
79  size_t last_framesize;
81 } ethos_t;
82 
86 typedef struct {
88  uint32_t baudrate;
89  uint8_t *buf;
90  size_t bufsize;
92 
105 void ethos_setup(ethos_t *dev, const ethos_params_t *params);
106 
117 void ethos_send_frame(ethos_t *dev, const uint8_t *data, size_t len, unsigned frame_type);
118 
119 #ifdef __cplusplus
120 }
121 #endif
122 #endif /* ETHOS_H */
123 
Struct containing the needed configuration.
Definition: ethos.h:86
Types used by the kernel.
Low-level UART peripheral driver interface definition.
uint8_t * buf
buffer for incoming packets
Definition: ethos.h:89
size_t last_framesize
size of last completed frame
Definition: ethos.h:79
unsigned int uart_t
Define default UART type identifier.
Definition: uart.h:65
Definitions low-level network driver interface.
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
tsrb_t inbuf
ringbuffer for incoming data
Definition: ethos.h:75
ethos netdev device
Definition: ethos.h:70
size_t framesize
size of currently incoming frame
Definition: ethos.h:77
uart_t uart
UART device the to use.
Definition: ethos.h:72
uint32_t baudrate
baudrate to UART device
Definition: ethos.h:88
unsigned frametype
type of currently incoming frame
Definition: ethos.h:78
thread-safe ringbuffer struct
Definition: tsrb.h:40
void ethos_setup(ethos_t *dev, const ethos_params_t *params)
Setup an ethos based device state.
Structure to hold driver state.
size_t bufsize
size of ethos_params_t::buf
Definition: ethos.h:90
Thread-safe ringbuffer implementation.
uart_t uart
UART device to use.
Definition: ethos.h:87
RIOT synchronization API.
netdev_t netdev
extended netdev structure
Definition: ethos.h:71
Mutex structure.
Definition: mutex.h:36
line_state_t state
Line status variable.
Definition: ethos.h:76
mutex_t out_mutex
mutex used for locking concurrent sends
Definition: ethos.h:80
line_state_t
enum describing line state
Definition: ethos.h:60