Forum Discussion
Altera_Forum
Honored Contributor
19 years agoKira,
I do it like this: # include "system.h"# include "alt_types.h"# include "sys/alt_irq.h"# include "altera_avalon_uart_regs.h" void serial_init(unsigned int baud) { /* inhibit all UART IRQ sources */ IOWR(UART_1_BASE, 3, 0x00); /* set Baud rate */ IOWR(UART_1_BASE, 4, baud); /* flush any characters sitting in the holding register */ IORD(UART_1_BASE, 0); IORD(UART_1_BASE, 0); /* reset most of the status register bits */ IOWR(UART_1_BASE, 2, 0x00); /* install IRQ service routine */ alt_irq_register(UART_1_IRQ, 0, serial_irq_0); /* enable irq for Rx. */ IOWR(UART_1_BASE, 3, 0x0080); } static void serial_irq_0(void* context, alt_u32 id) { unsigned int stat, chr; /* get serial status */ stat = IORD(UART_1_BASE, 2); /* character Rx */ if (stat & 0x0080) { chr = IORD(UART_1_BASE, 0); } } Banx.