Forum Discussion
Altera_Forum
Honored Contributor
20 years ago --- Quote Start --- originally posted by yangroot@Oct 7 2005, 09:23 PM why it give me this message "undefined reference to `fopen'","undefined reference to `fclose'" , when i use fopen and fclose to uart
if i miss any incluse file ? --- Quote End --- Maybe# include <strings.h> These are all the headers I used:
#include <stdio.h># include <string.h># include <alt_types.h># include <io.h>
/* Design-specific headers */# include "system.h" system.h seems to know about all the peripherals in my design, but I didn't use interrupts. Also, weird stuff happens when I try to use the small C libraries. IO works differently, things like that. And another thing: I have had problems using // for comments. <div class='quotetop'>QUOTE </div> --- Quote Start --- #include "system.h"# include "io.h"# include "stdio.h"# include "altera_avalon_lcd_16207_regs.h"# include "altera_avalon_timer.h"# include "altera_avalon_timer_regs.h"# include "sys/alt_irq.h"# include "altera_avalon_uart_regs.h"# include "altera_avalon_uart.h"# include "alt_types.h"# include "stdlib.h"# include "unistd.h"# include "fcntl.h"# include "sys/alt_alarm.h"# include "string.h"# include "sys/ioctl.h"# include "fcntl.h"# include "string.h"# include "stddef.h"# include "priv/alt_file.h" int main() { FILE *fp ; fp=fopen("/dev/UART_PC_NAME","r+"); //UART_PC_NAME is my uart name if(fp) { fprintf(fp,"close the uart.\n"); fclose(fp); } }[/b] --- Quote End --- Looks very much like what's in the book. I don't think it's the code itself. --- Quote Start --- originally posted by tns1@Oct 12 2005, 04:53 PM 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. --- Quote End --- I had a similar problem. I think it has something to do with the jtag uart's input buffer and how the HAL handles carriage returns or EOF. I'd like to see a solution to this. Programs that work on the jtag_uart don't work when I change stdio to UART. Can the ferror be a data overrun?