Blame view

RIOT/sys/uart_stdio/uart_stdio.c 1.54 KB
fb11e647   vrobic   reseau statique a...
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
  /*
   * Copyright (C) 2013 INRIA
   *               2015 Kaspar Schleiser <kaspar@schleiser.de>
   *
   * 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.
   */
  
  /**
   * @ingroup sys
   * @{
   *
   * @file
   * @brief UART stdio implementation
   *
   * This file implements a UART callback and read/write functions.
   *
   * @author      Oliver Hahm <oliver.hahm@inria.fr>
   * @author      Ludwig KnΓΌpfer <ludwig.knuepfer@fu-berlin.de>
   * @author      Kaspar Schleiser <kaspar@schleiser.de>
   *
   * @}
   */
  
  #include <stdio.h>
  
  #include "uart_stdio.h"
  
  #include "board.h"
  #include "periph/uart.h"
  #include "isrpipe.h"
  
  #ifdef USE_ETHOS_FOR_STDIO
  #include "ethos.h"
  extern ethos_t ethos;
  #endif
  
  #define ENABLE_DEBUG 0
  #include "debug.h"
  
  static char _rx_buf_mem[UART_STDIO_RX_BUFSIZE];
  isrpipe_t uart_stdio_isrpipe = ISRPIPE_INIT(_rx_buf_mem);
  
  void uart_stdio_init(void)
  {
  #ifndef USE_ETHOS_FOR_STDIO
      uart_init(UART_STDIO_DEV, UART_STDIO_BAUDRATE, (uart_rx_cb_t) isrpipe_write_one, &uart_stdio_isrpipe);
  #else
      uart_init(ETHOS_UART, ETHOS_BAUDRATE, (uart_rx_cb_t) isrpipe_write_one, &uart_stdio_isrpipe);
  #endif
  }
  
  int uart_stdio_read(char* buffer, int count)
  {
      return isrpipe_read(&uart_stdio_isrpipe, buffer, count);
  }
  
  int uart_stdio_write(const char* buffer, int len)
  {
  #ifndef USE_ETHOS_FOR_STDIO
      uart_write(UART_STDIO_DEV, (uint8_t *)buffer, (size_t)len);
  #else
      ethos_send_frame(&ethos, (uint8_t*)buffer, len, ETHOS_FRAME_TYPE_TEXT);
  #endif
      return len;
  }