Contiki-NG
uart1-putchar.c
1 /*---------------------------------------------------------------------------*/
2 #include "contiki.h"
3 #include "dev/uart1.h"
4 
5 #include <string.h>
6 /*---------------------------------------------------------------------------*/
7 #define SLIP_END 0300
8 #undef putchar
9 /*---------------------------------------------------------------------------*/
10 int
11 putchar(int c)
12 {
13 #if SLIP_ARCH_CONF_ENABLED
14  static char debug_frame = 0;
15 
16  if(!debug_frame) { /* Start of debug output */
17  uart1_writeb(SLIP_END);
18  uart1_writeb('\r'); /* Type debug line == '\r' */
19  debug_frame = 1;
20  }
21 #endif /* SLIP_ARCH_CONF_ENABLED */
22 
23  /* Need to also print '\n' because for example COOJA will not show
24  any output before line end */
25  uart1_writeb((char)c);
26 
27 #if SLIP_ARCH_CONF_ENABLED
28  /*
29  * Line buffered output, a newline marks the end of debug output and
30  * implicitly flushes debug output.
31  */
32  if(c == '\n') {
33  uart1_writeb(SLIP_END);
34  debug_frame = 0;
35  }
36 #endif /* SLIP_ARCH_CONF_ENABLED */
37  return c;
38 }
39 /*---------------------------------------------------------------------------*/