Blame view

RIOT/drivers/include/slipdev.h 2.63 KB
a752c7ab   elopes   add first test an...
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
  /*
   * Copyright (C) 2015-17 Freie Universitรคt Berlin
   *
   * This file is subject to the terms and conditions of the GNU Lesser
   * General Public License v2.1. See the file LICENSE in the top level
   * directory for more details.
   */
  
  /**
   * @defgroup    drivers_slipdev SLIP network device
   * @ingroup     drivers_netdev
   * @brief       SLIP network device over @ref drivers_periph_uart
   * @see         [RFC 1055](https://github.com/RIOT-OS/RIOT/pull/6487)
   * @{
   *
   * @file
   * @brief   SLIP device definitions
   *
   * @author  Martine Lenders <m.lenders@fu-berlin.de>
   */
  #ifndef SLIPDEV_H
  #define SLIPDEV_H
  
  #include <stdint.h>
  
  #include "cib.h"
  #include "net/netdev.h"
  #include "periph/uart.h"
  #include "ringbuffer.h"
  
  #ifdef __cplusplus
  extern "C" {
  #endif
  
  /**
   * @brief   UART buffer size used for TX and RX buffers
   *
   * Reduce this value if your expected traffic does not include full IPv6 MTU
   * sized packets
   */
  #ifndef SLIPDEV_BUFSIZE
  #define SLIPDEV_BUFSIZE (1500U)
  #endif
  
  /**
   * @brief   Packet FIFO size
   *
   * @note    For GNRC it is recommended to have it the same size as the link-layer
   *          thread's message queue, but it MUST be of power of 2
   */
  #ifndef SLIPDEV_PKTFIFO_SIZE
  #define SLIPDEV_PKTFIFO_SIZE    (8U)
  #endif
  
  /**
   * @brief   Configuration parameters for a slipdev
   */
  typedef struct {
      uart_t uart;        /**< UART interface the device is connected to */
      uint32_t baudrate;  /**< baudrate to use with slipdev_params_t::uart */
  } slipdev_params_t;
  
  /**
   * @brief   Device descriptor for slipdev
   *
   * @extends netdev_t
   */
  typedef struct {
      netdev_t netdev;                        /**< parent class */
      slipdev_params_t config;                /**< configuration parameters */
      ringbuffer_t inbuf;                     /**< RX buffer */
      char rxmem[SLIPDEV_BUFSIZE];            /**< memory used by RX buffer */
      uint16_t pktfifo[SLIPDEV_PKTFIFO_SIZE]; /**< FIFO of sizes of fully received
                                               *   packets */
      cib_t pktfifo_idx;                      /**< CIB for slipdev_t::pktfifo */
      uint16_t inbytes;                       /**< the number of bytes received of
                                               *   a currently incoming packet */
      uint16_t inesc;                         /**< device previously received an escape
                                               *   byte */
  } slipdev_t;
  
  /**
   * @brief   Setup a slipdev device state
   *
   * @param[in] dev       device descriptor
   * @param[in] params    parameters for device initialization
   */
  void slipdev_setup(slipdev_t *dev, const slipdev_params_t *params);
  
  #ifdef __cplusplus
  }
  #endif
  
  #endif /* SLIPDEV_H */
  /** @} */