Contiki 2.5
uart1-putchar.c
1 #include <stdio.h>
2 #include "dev/uart1.h"
3 
4 
5 #include PLATFORM_HEADER
6 #include "hal/micro/micro-common.h"
8 //#include "uart.h"
9 
10 #ifdef __GNUC__
11 # define _LLIO_STDIN ((int) stdin)
12 # define _LLIO_STDOUT ((int) stdout)
13 # define _LLIO_STDERR ((int) stderr)
14 # define _LLIO_ERROR (-1)
15 #else
16 # ifdef __ICCARM__
17 # include <yfuns.h>
18 # endif
19 #endif
20 
21 #undef putchar
22 
23 int __attribute__(( weak )) putchar(int c)
24 {
25  uart1_writeb(c);
26  return c;
27 }
28 
29 void __io_putchar(char c)
30 {
31  putchar(c);
32 }
33 
34 size_t _write(int handle, const unsigned char * buffer, size_t size)
35 {
36  size_t nChars = 0;
37 
38  if (handle != _LLIO_STDOUT && handle != _LLIO_STDERR) {
39  return _LLIO_ERROR;
40  }
41 
42  if (buffer == 0) {
43  // This means that we should flush internal buffers.
44  //spin until TX complete (TX is idle)
45  while ((SC1_UARTSTAT&SC_UARTTXIDLE)!=SC_UARTTXIDLE) {}
46  return 0;
47  }
48 
49  // ensure port is configured for UART
50  if(SC1_MODE != SC1_MODE_UART) {
51  return _LLIO_ERROR;
52  }
53 
54  while(size--) {
55  __io_putchar(*buffer++);
56  ++nChars;
57  }
58 
59  return nChars;
60 }
61 
62 
63 size_t _read(int handle, unsigned char * buffer, size_t size)
64 {
65  return 0;
66 }
67