Contiki 2.6
|
00001 /** 00002 * \file 00003 * 00004 * uart1 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/uart1.h" 00016 00017 #if UART_ONE_ENABLE 00018 /*---------------------------------------------------------------------------*/ 00019 /* UART1 initialization */ 00020 void 00021 uart1_init() 00022 { 00023 #ifdef UART1_ALTERNATIVE_1 00024 PERCFG &= ~U1CFG; /*alternative port 1 = P0.5-2*/ 00025 #ifdef UART1_RTSCTS 00026 P0SEL |= 0x3C; /*peripheral select for TX and RX, RTS, CTS*/ 00027 #else 00028 P0SEL |= 0x30; /*peripheral select for TX and RX*/ 00029 P0 &= ~0x08; /*RTS down*/ 00030 #endif 00031 P0DIR |= 0x18; /*RTS, TX out*/ 00032 P0DIR &= ~0x24; /*CTS, RX in*/ 00033 #else 00034 PERCFG |= U1CFG; /*alternative port 2 = P1.7-4*/ 00035 #ifdef UART1_RTSCTS 00036 P1SEL |= 0xF0; /*peripheral select for TX and RX*/ 00037 #else 00038 P1SEL |= 0xC0; /*peripheral select for TX and RX*/ 00039 P1 &= ~0x20; /*RTS down*/ 00040 #endif 00041 P1DIR |= 0x60; /*RTS, TX out*/ 00042 P1DIR &= ~0x90; /*CTS, RX in*/ 00043 #endif 00044 00045 #if UART_ONE_CONF_HIGH_SPEED 00046 UART_SET_SPEED(1, UART_460_M, UART_460_E); 00047 #else 00048 UART_SET_SPEED(1, UART_115_M, UART_115_E); 00049 #endif 00050 00051 #ifdef UART1_RTSCTS 00052 U1UCR = 0x42; /*defaults: 8N1, RTS/CTS, high stop bit*/ 00053 #else 00054 U1UCR = 0x02; /*defaults: 8N1, no flow control, high stop bit*/ 00055 #endif 00056 00057 U1CSR = U_MODE | U_RE; /* UART mode, receiver enable */ 00058 00059 /*set priority group of group 3 to highest, so the UART won't miss bytes*/ 00060 IP1 |= IP1_3; 00061 IP0 |= IP0_3; 00062 } 00063 /*---------------------------------------------------------------------------*/ 00064 /* Write one byte over the UART. */ 00065 void 00066 uart1_writeb(uint8_t byte) 00067 { 00068 IRCON2_UTX1IF = 0; 00069 U1BUF = byte; 00070 while(!IRCON2_UTX1IF); /* Wait until byte has been transmitted. */ 00071 IRCON2_UTX1IF = 0; 00072 } 00073 /*---------------------------------------------------------------------------*/ 00074 #endif