#include "alt_types.h"
#include
#include
#include "system.h"
#include "altera_avalon_uart_regs.h"
#include "altera_avalon_pio_regs.h"
#include "sys/alt_irq.h"
#ifdef UART_BASE
void uart_handle(void *context,alt_u32 interrupt)
{
unsigned short int data,status;
status = IORD_ALTERA_AVALON_UART_STATUS(UART_BASE);
while (!(status & ALTERA_AVALON_UART_STATUS_RRDY_MSK))
status = IORD_ALTERA_AVALON_UART_STATUS(UART_BASE);
data =IORD_ALTERA_AVALON_UART_RXDATA(UART_BASE);
//write status reg;
status = ALTERA_AVALON_UART_STATUS_TRDY_MSK;
IOWR_ALTERA_AVALON_UART_STATUS(UART_BASE, status);
IOWR_ALTERA_AVALON_UART_TXDATA(UART_BASE, data);
IOWR_ALTERA_AVALON_UART_STATUS(UART_BASE, 0);
}
void uart_init()
{
alt_u32 control;
int divisor;
control = ALTERA_AVALON_UART_CONTROL_TRDY_MSK |
ALTERA_AVALON_UART_CONTROL_RRDY_MSK |
ALTERA_AVALON_UART_CONTROL_E_MSK;
IOWR_ALTERA_AVALON_UART_CONTROL(UART_BASE, control);
divisor = (int)(50000000/9600+0.5);
IOWR_ALTERA_AVALON_UART_DIVISOR(UART_BASE, divisor);
if (alt_irq_register(UART_IRQ, NULL, uart_handle))
{
IOWR_ALTERA_AVALON_PIO_DATA(PIO_OUT_BASE, 0x0);
}
}
#endif
{
/* declare var used by uart;*/
IOWR_ALTERA_AVALON_PIO_DATA(PIO_OUT_BASE, 0x4079);
uart_init();
while(1);
return 0;
}