Programmable Devices
CPLDs, FPGAs, SoC FPGAs, Configuration, and Transceivers
20705 Discussions

UART Interrupt Mode

Altera_Forum
Honored Contributor II
1,570 Views

I'm trying to use a Nios II system to send and receive messages over RS232 UART. My applications requires a non-blocking read operation, so I am trying to configure the UART to work in interrupt mode so I don't lose any characters. All I need to do is have an ISR that buffers received characters, so when I call the read method, I can read characters from that buffer or immediately return 0 if the buffer is empty. I know that the HAL drivers provide an interrupt handler for the UART and I think this will be sufficient for my purposes.  

 

I am having problems getting the UART to work in interrupt mode and I haven't been able to find any good example software for Nios II interrupt mode using the provide HAL ISR. 

 

1. Does my code need to explicitly enable interrupts? Should this be done before or after opening the UART in nonblocking mode with fd = open(uart_path, O_RDWR | O_NONBLOCK | O_NOCTTY);? 

 

2. How can I read from the circular buffer used by the HAL ISR? In polling mode, I use read(fd, data_byte, 1), will this also work in interrupt mode? 

 

3. Does interrupt mode affect writing to the UART? Can I still use the write(fd, &data_byte, 1) function for writes? 

 

My basic code structure is 

 

while (1) {while (no data to read) {//do work } //process read message //send response message }
0 Kudos
1 Reply
Altera_Forum
Honored Contributor II
734 Views

I have the same issue. Im surprised no one has answered your post. 

Reading the documentation the UART driver should operate in interrupt mode so long as small driver is disabled in BSP. Using open,read write and ioctl should then control UART functions and automatically be handled by circular buffers in the background (default size ALT_AVALON_UART_BUF_LEN), but in my case it seems it is still in polling mode and wont respond to interrupts. I am now writing my own driver because of this issue.
0 Kudos
Reply