Files
mips/src/libsys/uart.c
T
jens 5c9c50ebeb - refactored libsys
- added critical section
- added interrupt global enable/disable
- added console::getInstanveByName



git-svn-id: http://moon:8086/svn/mips@76 a8ebac50-d88d-4704-bea3-6648445a41b3
2017-01-12 16:25:20 +00:00

57 lines
1.3 KiB
C

/*
* 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 <assert.h>
#include <board.h>
#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;
}