Altera_Forum
Honored Contributor
19 years agoClever UARTs (Interrupt Driven)
Hello all,
By this time I know that everybody is tired of this topic, but I can't seem to find a clear answer anywhere. Firstly, I am not using a RTOS but am wanting to use the RX & TX of a UART in an interrupt driven fashion, not polling it. My RX portion works great using a ringbuffer to receive and read the characters out, but the problem is when I try to use the TX interrupt. Now before I get to using the ISR, setting up my UART is doing strange things. The exact code that I use is: (Note I have quite a few UARTs in my system (26). Now do you understand why I need to have them interrupt driven???)void uart_init(unsigned int uart_number, unsigned int baudrate)
{
// disable all the interrupts for this uart
iowr_altera_avalon_uart_control(uart_25_base, 0);
// set the baud rate
iowr_altera_avalon_uart_divisor(uart_25_base, baudrate);
// enable the interrupts required for this uart
// rx & tx interrupt
iowr_altera_avalon_uart_control(uart_25_base, (altera_avalon_uart_control_trdy_msk | altera_avalon_uart_control_rrdy_msk));
// setup the isr reference
alt_irq_register(uart_25_irq ,(void*) &uart_context,uart25_isr);
// init the ringbuffers
memset(&uart[uart_number].rx_ringbuffer[0],0x00,uart_rx_ringbuffer_size);
uart[uart_number].rx_counter = 0;
uart[uart_number].rx_rd_index = 0;
uart[uart_number].rx_wr_index = 0;
uart[uart_number].rx_buffer_overflow = 0;
memset(&uart[uart_number].tx_ringbuffer[0],0x00,uart_tx_ringbuffer_size);
uart[uart_number].tx_counter = 0;
uart[uart_number].tx_rd_index = 0;
uart[uart_number].tx_wr_index = 0;
uart_service(uart_number);
uart_flush(uart_number);
} // void uart_init(unsigned int uart_number, unsigned int baudrate)
Now at this stage what happens is, if I read the control register after every step, then all goes well up until I set the Control register flags. If I set them and I read the control register directly after that, all seems fine, but as soon as I just write anything arbitrary using printf (basically just waiting some time) and then read the control register again, I get a result of 0x0880 (expecting 0x00C0). This is where my confusion point is. http://forum.niosforum.com/work2/style_emoticons/<#EMO_DIR#>/huh.gif Can any of you Nios gods share your wisdom please? If you need anything else regarding the code please request it. I don't want to bombard this post with too much at once! Regards, Tyrone