BlinkenArea - GitList
Repositories
Blog
Wiki
mips_sys
Code
Commits
Branches
Tags
Search
Tree:
3586a31
Branches
Tags
master
mips_sys
fw
uart.c
add UART error check to FW
Stefan Schuermans
commited
3586a31
at 2012-02-20 16:03:28
uart.c
Blame
History
Raw
#include "uart.h" static volatile unsigned char *const uart_ptr = (volatile unsigned char *)0x80000300; /** * @brief configure baudrate scaler * @param[in] scale baudrate scaler (1 = 7.143 Mhz) */ void uart_cfg_scale(unsigned short scale) { *(unsigned short *)(uart_ptr + 0) = scale; } /** * @brief configure number of data bits * @param[in] bits number of data bits */ void uart_cfg_bits(unsigned char bits) { *(uart_ptr + 2) = bits; } /** * @brief configure number of stop bits * @param[in] stop number of stop bits */ void uart_cfg_stop(unsigned char stop) { *(uart_ptr + 3) = stop; } /** * @brief check if transmitting a character is possible * @return if transmitting a character is possible */ int uart_can_tx(void) { return *(uart_ptr + 4); } /** * @brief transmit a character * @param[in] chr character to transmit */ void uart_tx(unsigned short chr) { while (!*(uart_ptr + 4)); /* wait for ready */ *(unsigned short *)(uart_ptr + 8) = chr; /* write data */ } /** * @brief check if receiving a character is possible * @return if receiving a character is possible */ int uart_can_rx(void) { return *(uart_ptr + 5); } /** * @brief receive a character * @return character received */ unsigned short uart_rx(void) { while (!*(uart_ptr + 5)); /* wait for data */ unsigned short chr = *(unsigned short *)(uart_ptr + 12); /* read data */ *(unsigned short *)(uart_ptr + 12) = 0; /* remove data from FIFO */ return chr; } /** * @brief determine if character is an error character * @param[in] chr character to check * @return if error */ int uart_is_err(unsigned short chr) { return chr >> 15; }