56 #include "dev/msb430-uart1.h"
64 volatile unsigned char uart_lockcnt = 0;
65 volatile uint8_t uart_edge = 0;
74 uart_configure(
unsigned mode)
88 U1ME |= UTXE1 | URXE1;
92 UCTL1 = SWRST | CHAR | SYNC | MM;
97 UTCTL1 |= CKPH | SSEL1 | SSEL0 | STC;
102 UBR01 = uart_speed_br0[mode];
103 UBR11 = uart_speed_br1[mode];
104 UMCTL1 = uart_speed_bmn[mode];
111 uart_set_speed(
unsigned mode,
unsigned ubr0,
112 unsigned ubr1,
unsigned umctl)
115 uart_speed_br0[mode] = ubr0;
116 uart_speed_br1[mode] = ubr1;
117 uart_speed_bmn[mode] = umctl;
121 uart_configure(mode);
126 uart_set_handler(
unsigned mode, uart_handler_t handler)
129 uart_handler[mode] = handler;
131 if(handler ==
NULL) {
140 uart_lock(
unsigned mode)
143 if(
uart_mode != mode && uart_lockcnt > 0) {
155 uart_lock_wait(
unsigned mode)
157 while(UART_WAIT_LOCK(mode)) {
160 return uart_lock(mode);
164 uart_unlock(
unsigned mode)
166 if((uart_lockcnt == 0) || (mode !=
uart_mode)) {
168 uart_set_mode(UART_MODE_DEFAULT);
173 if(uart_lockcnt > 0) {
176 if(uart_lockcnt == 0) {
177 uart_set_mode(UART_MODE_DEFAULT);
185 uart_set_mode(
unsigned mode)
192 IE2 &= ~(URXIE1 | UTXIE1);
193 uart_configure(mode);
196 if(uart_handler[mode] !=
NULL) {
207 interrupt(UART1RX_VECTOR)
210 uart_handler_t handler = uart_handler[
uart_mode];
213 if(!(IFG2 & URXIFG1)) {
218 _BIC_SR_IRQ(LPM3_bits);
222 if(!(URCTL1 & RXERR)) {
225 _BIC_SR_IRQ(LPM3_bits);