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++
Announcements
FPGA community forums and blogs on community.intel.com are migrating to the new Altera Community and are read-only. For urgent support needs during this transition, please visit the FPGA Design Resources page or contact an Altera Authorized Distributor.
12748 Discussions

file handling problems with jtag uart

Altera_Forum
Honored Contributor II
1,087 Views

I have some nios2 test code below that uses the jtag_uart. It should do non-blocking read & write of the jtag uart when fed from the nios2-terminal. The code behaves as expected when using uart0, but not when using the jtag uart.  

 

When using the jtag uart, the feof() and ferror calls() behave as though they have been swapped! feof() is never true. ferror() is set true (err=1) when no chars are read, and false when a char is read.  

 

This looks like a bug. 

 

 

int tch,count,err; 

char DataIn[3]; 

int jtagfdi,jtagfdo; 

FILE * JtagPortI, *JtagPortO; 

 

//non-blocking IO with streams 

jtagfdi = open("/dev/jtag_uart", O_RDONLY|O_NONBLOCK|O_NOCTTY); 

jtagfdo = open("/dev/jtag_uart", O_WRONLY|O_NONBLOCK|O_NOCTTY); 

JtagPortI = fdopen(jtagfdi,"r"); 

JtagPortO = fdopen(jtagfdo,"w"); 

 

while(1){ 

if(feof(JtagPortI)) 

clearerr(JtagPortI);//must clear feof condition 

else //may have chars waiting 

count = (int) fread(&tch,1,1,JtagPortI);//read 1 char.  

 

if((err = ferror(JtagPortI)) != 0) 

printf("Read ferror: %d \r\n", err);  

clearerr(JtagPortI); //must clear ferror condition 

else //no ferror 

if ( (tch != EOF) && (count == 1) ) 

DataIn[0] = toupper((char)tch); 

fwrite(DataIn, 1, 1, JtagPortO); 

}  

}//endif(ferror()) 

}//endif(feof()) 

}//endwhile(1)
0 Kudos
0 Replies
Reply