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++
12603 Discussions

Bug in altera_avalon_uart_read

Altera_Forum
Honored Contributor II
1,359 Views

NOTE: This is not a question, but an information 

************************************ 

 

The call to read for a /dev/uart returns a wrong value when non-blocking and no data available. 

 

This is due to a bug in  

ip\altera\sopc_builder_ip\altera_avalon_uart\HAL\src\altera_avalon_uart_read.c#241 

 

Instead of 

return ~EWOULDBLOCK; 

 

it should be 

return -EWOULDBLOCK; 

 

otherwise the calling program will receive errno 12 (ENOMEM, "Not enough space") instead of the correct number, 11 (EAGAIN, "No more processes"). 

 

(I tried to enter a service request, but was unable to; please forward to the due department in Altera) 

 

Seen in Quartus 11.1 and Quartus 12; did not exist in Quartus 9.0sp2.
0 Kudos
3 Replies
Altera_Forum
Honored Contributor II
583 Views

Thank you. I am suing 9.1 SP2. I have following lines in the .c file 

 

if (!block) 

/* Set errno to indicate the reason we're not returning any data */ 

 

ALT_ERRNO = EWOULDBLOCK; 

break; 

else 

 

... 

... 

 

 

Is this right?
0 Kudos
Altera_Forum
Honored Contributor II
583 Views

Yes, that is correct and was not changed. Quartus 9 returns 0 (no chars received): 

return count; 

 

while Quartus 11 and 12 (and maybe 10) replaced that line by: 

if(read_would_block) { 

return ~EWOULDBLOCK; 

else { 

return count; 

 

The bug appears in Quartus 11 and 12 (and maybe 10 also; I don't have it installed).
0 Kudos
Altera_Forum
Honored Contributor II
583 Views

Hi, 

 

I'm facing the same problem with Quartus Prime 16.0 Lite edition. 

I have made the following changes to make the fgets function Non Blocking : 

_serialPort = fopen("/dev/uart_0", "r+"); 

fd = fileno(_serialPort); 

fcntl(fd, F_SETFL, O_NONBLOCK); 

 

After this it's been set to Non-Blocking, but inside the while loop when I'm passing a "STOP" command (should break out of the while loop) it's not reading the command and goes on continuously.  

I've tried your method but it's still not working. I've also checked that with getc(_serialPort) "-1" is being returned.  

 

Can you please kindly help me with this issue ?
0 Kudos
Reply