/* * To change this license header, choose License Headers in Project Properties. * To change this template file, choose Tools | Templates * and open the template in the editor. */ #include #include #include "uart.h" // --------------------------------------------------------------------------------- // Globals // --------------------------------------------------------------------------------- uart_if_t uart_if[2] = { {(uint32_t*)SYS_UART0_STAT, (uint32_t*)SYS_UART0_DATA, (uint32_t*)SYS_UART0_BAUD}, {(uint32_t*)SYS_UART1_STAT, (uint32_t*)SYS_UART1_DATA, (uint32_t*)SYS_UART1_BAUD} }; // ------------------------------------ // Low-level I/O // ------------------------------------ #define CALC_BAUD(b) \ ((uint32_t)((float)CPU_FREQ_HZ/(16*b) + 0.5f) - 1); void UART_setbaud(void const *pInst, uint32_t baudrate) { assert(pInst); uart_if_t *pReg = (uart_if_t*)pInst; *pReg->pBAUD = CALC_BAUD(baudrate); } int UART_readchar(void const *pInst) { assert(pInst); uart_if_t *pReg = (uart_if_t*)pInst; if (SYS_UART_BIT_RX_AVAIL & *pReg->pCTRL) return (*pReg->pDATA & 0xFF); return -1; } void UART_writechar(void const *pInst, char c) { assert(pInst); uart_if_t *pReg = (uart_if_t*)pInst; while((SYS_UART_BIT_TX_HALFFULL & *pReg->pCTRL) != 0); *pReg->pDATA = (uint32_t)c; }