added more UART low-level functions
Committed on the Free edition of March Hare Software CVSNT Server. Upgrade to CVS Suite for more features and support: http://march-hare.com/cvsnt/ git-svn-id: http://moon:8086/svn/vhdl/trunk@512 cc03376c-175c-47c8-b038-4cd826a8556b
This commit is contained in:
@@ -150,27 +150,88 @@ void DCACHE_invalidate_at(UINT32* pPtr)
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------------
|
||||
char readchar(void)
|
||||
int UART0_readchar(void)
|
||||
{
|
||||
volatile UINT32 *pUART_stat = (UINT32*)sys_uart_stat;
|
||||
volatile UINT32 *pUART_data = (UINT32*)sys_uart_data;
|
||||
volatile UINT32 *pUART_stat = (UINT32*)sys_uart0_stat;
|
||||
volatile UINT32 *pUART_data = (UINT32*)sys_uart0_data;
|
||||
|
||||
while(!(0x10 & *pUART_stat));
|
||||
if (0x10 & *pUART_stat)
|
||||
return (*pUART_data & 0xFF);
|
||||
|
||||
return (char)*pUART_data;
|
||||
return -1;
|
||||
}
|
||||
|
||||
void writechar(char c)
|
||||
void UART0_writechar(char c)
|
||||
{
|
||||
volatile UINT32 *pUART_stat = (UINT32*)sys_uart_stat;
|
||||
volatile UINT32 *pUART_data = (UINT32*)sys_uart_data;
|
||||
volatile UINT32 *pUART_stat = (UINT32*)sys_uart0_stat;
|
||||
volatile UINT32 *pUART_data = (UINT32*)sys_uart0_data;
|
||||
|
||||
while((0x01 & *pUART_stat) != 0);
|
||||
|
||||
*pUART_data = (UINT32)c;
|
||||
}
|
||||
|
||||
void _putchar(char c)
|
||||
int UART1_readchar(void)
|
||||
{
|
||||
volatile UINT32 *pUART_stat = (UINT32*)sys_uart1_stat;
|
||||
volatile UINT32 *pUART_data = (UINT32*)sys_uart1_data;
|
||||
|
||||
if (0x10 & *pUART_stat)
|
||||
return (*pUART_data & 0xFF);
|
||||
|
||||
return -1;
|
||||
}
|
||||
|
||||
void UART1_writechar(char c)
|
||||
{
|
||||
volatile UINT32 *pUART_stat = (UINT32*)sys_uart1_stat;
|
||||
volatile UINT32 *pUART_data = (UINT32*)sys_uart1_data;
|
||||
|
||||
while((0x01 & *pUART_stat) != 0);
|
||||
|
||||
*pUART_data = (UINT32)c;
|
||||
}
|
||||
|
||||
int UART2_readchar(void)
|
||||
{
|
||||
volatile UINT32 *pUART_stat = (UINT32*)sys_uart2_stat;
|
||||
volatile UINT32 *pUART_data = (UINT32*)sys_uart2_data;
|
||||
|
||||
if (0x10 & *pUART_stat)
|
||||
return (*pUART_data & 0xFF);
|
||||
|
||||
return -1;
|
||||
}
|
||||
|
||||
void UART2_writechar(char c)
|
||||
{
|
||||
volatile UINT32 *pUART_stat = (UINT32*)sys_uart2_stat;
|
||||
volatile UINT32 *pUART_data = (UINT32*)sys_uart2_data;
|
||||
|
||||
while((0x01 & *pUART_stat) != 0);
|
||||
|
||||
*pUART_data = (UINT32)c;
|
||||
}
|
||||
|
||||
char readchar(void)
|
||||
{
|
||||
int c;
|
||||
|
||||
do
|
||||
{
|
||||
c = UART0_readchar();
|
||||
|
||||
} while(c < 0);
|
||||
|
||||
return (char)c;
|
||||
}
|
||||
|
||||
void writechar(char c)
|
||||
{
|
||||
UART0_writechar(c);
|
||||
}
|
||||
|
||||
void _ser_putchar(char c)
|
||||
{
|
||||
if (c == 0x0A)
|
||||
{
|
||||
|
||||
@@ -17,6 +17,8 @@
|
||||
#define FLOAT32 float
|
||||
#define FLOAT64 double
|
||||
|
||||
#define NO_ERROR LSYS_SUCCESS
|
||||
#define ERROR LSYS_ERR_BASE
|
||||
#define LSYS_SUCCESS 0
|
||||
#define LSYS_ERR_BASE 0x80000000
|
||||
|
||||
@@ -40,9 +42,18 @@
|
||||
#define sys_itim2_cmp 0xA0000038
|
||||
#define sys_itim3_cmp 0xA000003C
|
||||
|
||||
#define sys_uart_data 0xA0010000
|
||||
#define sys_uart_stat 0xA0010004
|
||||
#define sys_uart_baud 0xA0010008
|
||||
#define sys_uart_data sys_uart0_data
|
||||
#define sys_uart_stat sys_uart0_stat
|
||||
#define sys_uart_baud sys_uart0_baud
|
||||
#define sys_uart0_data 0xA0010000
|
||||
#define sys_uart0_stat 0xA0010004
|
||||
#define sys_uart0_baud 0xA0010008
|
||||
#define sys_uart1_data 0xA0010100
|
||||
#define sys_uart1_stat 0xA0010104
|
||||
#define sys_uart1_baud 0xA0010108
|
||||
#define sys_uart2_data 0xA0010200
|
||||
#define sys_uart2_stat 0xA0010204
|
||||
#define sys_uart2_baud 0xA0010208
|
||||
#define sys_usb_data 0xA0020000
|
||||
#define sys_usb_mbx 0xA0020004
|
||||
#define sys_usb_addr 0xA0020008
|
||||
@@ -68,13 +79,18 @@
|
||||
//#define STDOUT_FUNCTION _cg_putchar // Video character
|
||||
//#define STDERR_FUNCTION _putchar // Serial output
|
||||
|
||||
#ifndef _putchar
|
||||
#define _putchar _ser_putchar // Serial output
|
||||
#endif
|
||||
|
||||
#ifndef STDOUT_FUNCTION
|
||||
#define STDOUT_FUNCTION _putchar // Serial output
|
||||
#define STDOUT_FUNCTION _ser_putchar // Serial output
|
||||
#endif
|
||||
#ifndef STDERR_FUNCTION
|
||||
#define STDERR_FUNCTION _putchar // Serial output
|
||||
#define STDERR_FUNCTION _ser_putchar // Serial output
|
||||
#endif
|
||||
|
||||
|
||||
UINT32 CP0_SR_read(void);
|
||||
void CP0_SR_write(UINT32 val);
|
||||
UINT32 CP0_CR_read(void);
|
||||
@@ -89,6 +105,18 @@ void ICACHE_invalidate_at(UINT32* pPtr);
|
||||
void DCACHE_invalidate_all(void);
|
||||
void DCACHE_invalidate_at(UINT32* pPtr);
|
||||
|
||||
#define CALC_BAUD(b) \
|
||||
((UINT32)((float)CPU_FREQ_HZ/(16*b) + 0.5f) - 1);
|
||||
|
||||
#define UART0_setbaud(b) \
|
||||
*((UINT32*)sys_uart0_baud) = CALC_BAUD(b);
|
||||
|
||||
#define UART1_setbaud(b) \
|
||||
*((UINT32*)sys_uart1_baud) = CALC_BAUD(b);
|
||||
|
||||
#define UART2_setbaud(b) \
|
||||
*((UINT32*)sys_uart2_baud) = CALC_BAUD(b);
|
||||
|
||||
char readchar(void);
|
||||
void writechar(char c);
|
||||
int write(int file, char *ptr, int len);
|
||||
|
||||
Reference in New Issue
Block a user