Contiki 3.x
uart1.c
Go to the documentation of this file.
1 /**
2  * \file
3  *
4  * uart1 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 "dev/uart1.h"
16 
17 #if UART1_ENABLE
18 /*---------------------------------------------------------------------------*/
19 /* UART1 initialization */
20 void
21 uart1_init()
22 {
23 #ifdef UART1_ALTERNATIVE_1
24  PERCFG &= ~PERCFG_U1CFG; /*alternative port 1 = P0.5-2*/
25 #ifdef UART1_RTSCTS
26  P0SEL |= 0x3C; /*peripheral select for TX and RX, RTS, CTS*/
27 #else
28  P0SEL |= 0x30; /*peripheral select for TX and RX*/
29  P0 &= ~0x08; /*RTS down*/
30 #endif
31  P0DIR |= 0x18; /*RTS, TX out*/
32  P0DIR &= ~0x24; /*CTS, RX in*/
33 #else
34  PERCFG |= PERCFG_U1CFG; /*alternative port 2 = P1.7-4*/
35 #ifdef UART1_RTSCTS
36  P1SEL |= 0xF0; /*peripheral select for TX and RX*/
37 #else
38  P1SEL |= 0xC0; /*peripheral select for TX and RX*/
39  P1 &= ~0x20; /*RTS down*/
40 #endif
41  P1DIR |= 0x60; /*RTS, TX out*/
42  P1DIR &= ~0x90; /*CTS, RX in*/
43 #endif
44 
45 #if UART_ONE_CONF_HIGH_SPEED
46  UART_SET_SPEED(1, UART_460_M, UART_460_E);
47 #else
48  UART_SET_SPEED(1, UART_115_M, UART_115_E);
49 #endif
50 
51 #ifdef UART1_RTSCTS
52  U1UCR = 0x42; /*defaults: 8N1, RTS/CTS, high stop bit*/
53 #else
54  U1UCR = 0x02; /*defaults: 8N1, no flow control, high stop bit*/
55 #endif
56 
57  U1CSR = UCSR_MODE; /* UART mode */
58  U1UCR |= 0x80; /* Flush */
59 
60  UART1_RX_INT(1);
61  U0DBUF = 0;
62 }
63 /*---------------------------------------------------------------------------*/
64 /* Write one byte over the UART. */
65 void
66 uart1_writeb(uint8_t byte)
67 {
68  UTX1IF = 0;
69  U1DBUF = byte;
70  while(!UTX1IF); /* Wait until byte has been transmitted. */
71  UTX1IF = 0;
72 }
73 /*---------------------------------------------------------------------------*/
74 #endif
void uart1_init(unsigned long ubr)
Initalize the RS232 port.
Definition: uart1.c:143
Definitions for TI/Chipcon cc2530, cc2531 and cc2533 SFR registers.