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 "cc2430_sfr.h"
00015 #include "dev/uart0.h"
00016 
00017 #if UART_ZERO_ENABLE
00018 /*---------------------------------------------------------------------------*/
00019 void
00020 uart0_init()
00021 {
00022   UART_SET_SPEED(0, UART_115_M, UART_115_E);
00023 
00024 #ifdef UART0_ALTERNATIVE_2
00025   PERCFG |= U0CFG;  /*alternative port 2 = P1.5-2*/
00026 #ifdef UART0_RTSCTS
00027   P1SEL |= 0x3C;    /*peripheral select for TX and RX, RTS, CTS*/
00028 #else
00029   P1SEL |= 0x30;    /*peripheral select for TX and RX*/
00030   P1 &= ~0x08;    /*RTS down*/
00031 #endif
00032   P1DIR |= 0x28;    /*RTS, TX out*/
00033   P1DIR &= ~0x14;   /*CTS & RX in*/
00034 #else
00035   PERCFG &= ~U0CFG; /*alternative port 1 = P0.5-2*/
00036 #ifdef UART0_RTSCTS
00037   P0SEL |= 0x3C;    /*peripheral select for TX and RX, RTS, CTS*/
00038 #else
00039   P0SEL |= 0x0C;    /*peripheral select for TX and RX*/
00040   P0 &= ~0x20;    /*RTS down*/
00041 #endif
00042   P0DIR |= 0x28;    /*RTS & TX out*/
00043   P0DIR &= ~0x14;   /*CTS & RX in*/
00044 #endif
00045 
00046 
00047 #ifdef UART0_RTSCTS
00048   U0UCR = 0x42;   /*defaults: 8N1, RTS/CTS, high stop bit*/
00049 #else
00050   U0UCR = 0x02;   /*defaults: 8N1, no flow control, high stop bit*/
00051 #endif
00052 
00053   U0CSR = U_MODE | U_RE | U_TXB;  /*UART mode, receiver enable, TX done*/
00054 
00055   /*set priority group of group 3 to highest, so the UART won't miss bytes*/
00056   IP1 |= IP1_3;
00057   IP0 |= IP0_3;
00058 }
00059 /*---------------------------------------------------------------------------*/
00060 /* Write one byte over the UART. */
00061 void
00062 uart0_writeb(uint8_t byte)
00063 {
00064   IRCON2_UTX0IF = 0;
00065   U0BUF = byte;
00066   while(!IRCON2_UTX0IF); /* Wait until byte has been transmitted. */
00067   IRCON2_UTX0IF = 0;
00068 }
00069 #endif