/* * uart0.c - Implementation of the uart. * Copyright (C) 2013 Milan Babel * * This file is subject to the terms and conditions of the GNU Lesser * General Public License v2.1. See the file LICENSE in the top level * directory for more details. */ #include #include "board.h" #define UART0_TX U0TXBUF #define UART0_WAIT_TXDONE() while( (U0TCTL & TXEPT) == 0 ) { _NOP(); } #include "kernel.h" #include "board_uart0.h" int putchar(int c) { UART0_TX = c; UART0_WAIT_TXDONE(); if (c == 10) { UART0_TX = 13; UART0_WAIT_TXDONE(); } return c; } int getchar(void) { #ifdef MODULE_UART0 return uart0_readc(); #else return U0RXBUF; #endif } void usart0irq(void); /** * \brief the interrupt function */ void __attribute__((interrupt(USART0RX_VECTOR))) usart0irq(void) { volatile int dummy = 0; /* Check status register for receive errors. */ if(U0RCTL & RXERR) { if (U0RCTL & FE) { puts("rx framing error"); } if (U0RCTL & OE) { puts("rx overrun error"); } if (U0RCTL & PE) { puts("rx parity error"); } if (U0RCTL & BRK) { puts("rx break error"); } /* Clear error flags by forcing a dummy read. */ dummy = U0RXBUF; (void)dummy; } #ifdef MODULE_UART0 else if (uart0_handler_pid != KERNEL_PID_UNDEF) { dummy = U0RXBUF; uart0_handle_incoming(dummy); uart0_notify_thread(); } #endif }