uart1-putchar.c

00001 #include <stdio.h>
00002 #include "dev/uart1.h"
00003 
00004 
00005 #include PLATFORM_HEADER
00006 #include "hal/micro/micro-common.h"
00007 #include "hal/micro/cortexm3/micro-common.h"
00008 //#include "uart.h"
00009 
00010 #ifdef __GNUC__
00011 # define _LLIO_STDIN ((int) stdin)
00012 # define _LLIO_STDOUT ((int) stdout)
00013 # define _LLIO_STDERR ((int) stderr)
00014 # define _LLIO_ERROR  (-1)
00015 #else
00016 # ifdef __ICCARM__
00017 # include <yfuns.h>
00018 # endif
00019 #endif
00020 
00021 #undef putchar
00022 
00023 int __attribute__(( weak )) putchar(int c)
00024 {
00025   uart1_writeb(c);
00026   return c;
00027 }
00028 
00029 void __io_putchar(char c)
00030 {
00031   putchar(c);
00032 }
00033 
00034 size_t _write(int handle, const unsigned char * buffer, size_t size)
00035 {
00036   size_t nChars = 0;
00037 
00038   if (handle != _LLIO_STDOUT && handle != _LLIO_STDERR) {
00039     return _LLIO_ERROR;
00040   }
00041 
00042   if (buffer == 0) {
00043     // This means that we should flush internal buffers.  
00044     //spin until TX complete (TX is idle)
00045     while ((SC1_UARTSTAT&SC_UARTTXIDLE)!=SC_UARTTXIDLE) {}
00046     return 0;
00047   }
00048   
00049   // ensure port is configured for UART
00050   if(SC1_MODE != SC1_MODE_UART) {
00051     return _LLIO_ERROR;
00052   }
00053 
00054   while(size--) {
00055     __io_putchar(*buffer++);
00056     ++nChars;
00057   }
00058 
00059   return nChars;
00060 }
00061 
00062 
00063 size_t _read(int handle, unsigned char * buffer, size_t size)
00064 {
00065         return 0;
00066 }
00067 

Generated on Mon Apr 11 14:23:39 2011 for Contiki 2.5 by  doxygen 1.6.1