Contiki 3.x
uart0.c
Go to the documentation of this file.
1 /**
2  * \file
3  *
4  * uart0 write routines
5  *
6  * \author
7  *
8  * Anthony "Asterisk" Ambuehl
9  *
10  */
11 #include <stdlib.h>
12 #include <string.h>
13 
14 #include "cc253x.h"
15 #include "sfr-bits.h"
16 #include "dev/uart0.h"
17 
18 #if UART0_ENABLE
19 /*---------------------------------------------------------------------------*/
20 void
21 uart0_init()
22 {
23 #if UART0_CONF_HIGH_SPEED
24  UART_SET_SPEED(0, UART_460_M, UART_460_E);
25 #else
26  UART_SET_SPEED(0, UART_115_M, UART_115_E);
27 #endif
28 
29 #ifdef UART0_ALTERNATIVE_2
30  PERCFG |= PERCFG_U0CFG; /* alternative port 2 = P1.5-2 */
31 #ifdef UART0_RTSCTS
32  P1SEL |= 0x3C; /* peripheral select for TX and RX, RTS, CTS */
33 #else
34  P1SEL |= 0x30; /* peripheral select for TX and RX */
35  P1 &= ~0x08; /* RTS down */
36 #endif
37  P1DIR |= 0x28; /* RTS, TX out */
38  P1DIR &= ~0x14; /* CTS & RX in */
39 #else
40  PERCFG &= ~PERCFG_U0CFG; /* alternative port 1 = P0.5-2 */
41 #ifdef UART0_RTSCTS
42  P0SEL |= 0x20 | 0x10; /* peripheral select for TX and RX */
43 #else
44  P0SEL |= 0x0C; /* peripheral select for TX and RX */
45  P0 &= ~0x20; /* RTS down */
46 #endif
47  P0DIR |= 0x28; /* RTS, TX out */
48  P0DIR &= ~0x14; /* CTS, RX in */
49 #endif
50 
51 
52 #ifdef UART0_RTSCTS
53  U0UCR = 0x42; /*defaults: 8N1, RTS/CTS, high stop bit*/
54 #else
55  U0UCR = 0x02; /*defaults: 8N1, no flow control, high stop bit*/
56 #endif
57 
58  U0CSR = UCSR_MODE; /* UART mode */
59  U0UCR |= 0x80; /* Flush */
60  UART0_RX_EN();
61 
62  UART0_RX_INT(1);
63 }
64 /*---------------------------------------------------------------------------*/
65 /* Write one byte over the UART. */
66 void
67 uart0_writeb(uint8_t byte)
68 {
69  UTX0IF = 0;
70  U0DBUF = byte;
71  while(!UTX0IF); /* Wait until byte has been transmitted. */
72  UTX0IF = 0;
73 }
74 #endif
void uart0_init(unsigned long ubr)
Initalize the RS232 port.
Definition: uart0.c:111
Definitions for TI/Chipcon cc2530, cc2531 and cc2533 SFR registers.
Header file with definitions of bit masks for some cc2530 SFRs