Contiki 2.6

uart0.c

Go to the documentation of this file.
00001 /**
00002  * \file
00003  *
00004  *   uart0 write routines
00005  *
00006  * \author
00007  *
00008  *   Anthony "Asterisk" Ambuehl
00009  *
00010  */
00011 #include <stdlib.h>
00012 #include <string.h>
00013 
00014 #include "cc253x.h"
00015 #include "sfr-bits.h"
00016 #include "dev/uart0.h"
00017 
00018 #if UART0_ENABLE
00019 /*---------------------------------------------------------------------------*/
00020 void
00021 uart0_init()
00022 {
00023 #if UART0_CONF_HIGH_SPEED
00024   UART_SET_SPEED(0, UART_460_M, UART_460_E);
00025 #else
00026   UART_SET_SPEED(0, UART_115_M, UART_115_E);
00027 #endif
00028 
00029 #ifdef UART0_ALTERNATIVE_2
00030   PERCFG |= PERCFG_U0CFG;  / *alternative port 2 = P1.5-2 */
00031 #ifdef UART0_RTSCTS
00032   P1SEL |= 0x3C;    /* peripheral select for TX and RX, RTS, CTS */
00033 #else
00034   P1SEL |= 0x30;    /* peripheral select for TX and RX */
00035   P1 &= ~0x08;      /* RTS down */
00036 #endif
00037   P1DIR |= 0x28;    /* RTS, TX out */
00038   P1DIR &= ~0x14;   /* CTS & RX in */
00039 #else
00040   PERCFG &= ~PERCFG_U0CFG; /* alternative port 1 = P0.5-2 */
00041 #ifdef UART0_RTSCTS
00042   P0SEL |= 0x20 | 0x10;    /* peripheral select for TX and RX */
00043 #else
00044   P0SEL |= 0x0C;    /* peripheral select for TX and RX */
00045   P0 &= ~0x20;    /* RTS down */
00046 #endif
00047   P0DIR |= 0x28;    /* RTS, TX out */
00048   P0DIR &= ~0x14;   /* CTS, RX in */
00049 #endif
00050 
00051 
00052 #ifdef UART0_RTSCTS
00053   U0UCR = 0x42; /*defaults: 8N1, RTS/CTS, high stop bit*/
00054 #else
00055   U0UCR = 0x02; /*defaults: 8N1, no flow control, high stop bit*/
00056 #endif
00057 
00058   U0CSR = UCSR_MODE; /* UART mode */
00059   U0UCR |= 0x80; /* Flush */
00060   UART0_RX_EN();
00061 
00062   UART0_RX_INT(1);
00063 }
00064 /*---------------------------------------------------------------------------*/
00065 /* Write one byte over the UART. */
00066 void
00067 uart0_writeb(uint8_t byte)
00068 {
00069   UTX0IF = 0;
00070   U0DBUF = byte;
00071   while(!UTX0IF); /* Wait until byte has been transmitted. */
00072   UTX0IF = 0;
00073 }
00074 #endif