Nios® V/II Embedded Design Suite (EDS)
Support for Embedded Development Tools, Processors (SoCs and Nios® V/II processor), Embedded Development Suites (EDSs), Boot and Configuration, Operating Systems, C and C++
12600 Discussions

How to use the Uart driver with interrupts

Altera_Forum
Honored Contributor II
1,678 Views

Hi, 

 

I'm kind of confused, I'm more of an embedded guy, I rarely used drivers before except for the XMEGA and the drivers were much simpler, with better examples. I was wondering, how can I use the Uart driver with the driver? I tried to find some kind of tutorial but I couldn't find any.
0 Kudos
5 Replies
Altera_Forum
Honored Contributor II
649 Views

The core manual is pretty explainable. You just register interrupt function to the driver and it works.

0 Kudos
Altera_Forum
Honored Contributor II
649 Views

Ok, Interrupts should be enabled in alt_sys_init function which is automatically called?  

 

Then I use printf("Hello from Nios II"). I should expect printf to be non-blocking since I use interrupts, but printf is blocking why is that? 

 

How can I make printf non-blocking? I double-checked everywhere, interrupts are properly connected, I can see interrupts raising in simulation but it seems that printf is implemented using a while loop... 

 

I'm confused
0 Kudos
Altera_Forum
Honored Contributor II
649 Views

First of all You need to set up hardware side correctly: 

1) Add interrupt signal for Avalon interconnect. 

2) Add write interface to Your Avalon interconnect (will tell You why later). 

 

The hardware fires interrupt, which must be held at least for 30-50 clk cycles, but the usual practice is to set interrupt_done flag through the write interface I've mentioned in (2). 

 

You assert interrupt signal in hardware and leave it high. When the Nios fires interrupt, the first thing inside interrupt You must do is to write to that interface signal (mentioned in (2)) and deassert interrupt signal. 

 

Then in software, You firstly initialize UART: 

IOWR_ALTERA_AVALON_UART_STATUS(UART_BASE,0); 

IOWR_ALTERA_AVALON_UART_CONTROL(UART_BASE, ALTERA_AVALON_UART_CONTROL_RRDY_MSK); 

alt_irq_register(uart_irq_interface, NULL, uart_interrupt_procedure);
0 Kudos
Altera_Forum
Honored Contributor II
649 Views

To make printf non-blocking needs a fifo somewhere - this could be software (using interrupts) or could be hardware. Both need the memory somewhere, and when the fifo is full will block. 

 

With a small hardware fifo and a larger sw fifo you don't necessarily need interrupts - the embeded schedule loop could refill the hw fifo. 

 

Dunno what the altera library code you might be using actually tries to do though!
0 Kudos
Altera_Forum
Honored Contributor II
649 Views

I understand what you're trying to tell me, but from the documentation, the Altera Uart driver should be able to work with interrupts even when using standard I/O functions like printf. 

 

I tried modifying STDOUT like this 

 

int flags = fcntl(STDOUT_FILENO, F_GETFL); fcntl(STDOUT_FILENO, F_SETFL,flags | O_NONBLOCK); printf( "Not the stylo venimeux");  

 

But in my simulation waveform the interrupts are not serviced, thus the uart is still working in polling mode even though the Altera driver is supposed to work in non-blocking mode (i.e. using interrupts). 

 

What am I doing wrong?
0 Kudos
Reply