Community
cancel
Showing results for 
Search instead for 
Did you mean: 
LucasM
Novice
1,386 Views

How to read from stdin in NIOSII with the small_c_library

Jump to solution

whithout the small_c_library checked, i am unable to read from standard input.

unless there's some sort of alt_fopen, how do i read from the standard character streams whithout gets,scanf and fopen?

Tags (4)
0 Kudos
1 Solution
LucasM
Novice
366 Views

It seems that with the small c library enabled stdin,stdou and stderr are "preopened" files, so i can interact with them as files whithout opening them, can't find right now exactly where i saw this info.

View solution in original post

4 Replies
AnandRaj_S_Intel
Employee
366 Views

Hi,

 

Are you saying that, using normal c libraries you are able to read write but not able to read using small c libraries ?

 

  1. If simple console read write ->use alt_printf, alt_putstr, alt_putchar & alt_getchar. Refer table 34 gives you the comparison between libraries https://www.intel.com/content/altera-www/global/en_us/index/documentation/mwh1416947091611.html#mwh1... OR
  2. If Read, write to from FPGA peripherals? use  IORD and IOWR functions.

 

Let me know if this has helped resolve the issue you are facing or if you need any further assistance.

 

Best Regards,

Anand

 

LucasM
Novice
366 Views
I haven't been able to test it yet, but knowing which functions to use helps, I've tried alt_scanf() which didn't work. Also I was unaware of the new library documentation, that is a huge help. I will test it ASAP (Monday) and give feedback. Thanks, Lucas M
LucasM
Novice
366 Views

Yes, i am able to read incoming data (from the uart) with the full C library, using:

#include <stdio.h> #include <stdlib.h>   FILE * fp;   char msg[255]; fp = fopen("/dev/uart_0","r"); if(fp) { fscanf(fp,"%s",msg); }

I've tried using the alt library, but it fails with:

home/user/project_name/software/nios_project_name_bsp/HAL/src/alt_getchar.c:67: undefined reference to `getc'//source snippet int alt_getchar(void) { #ifdef ALT_SEMIHOSTING char c; read(STDIN_FILENO,&c,1); return c; #else #ifdef ALT_USE_DIRECT_DRIVERS ALT_DRIVER_READ_EXTERNS(ALT_STDIN_DEV); char c;   if (ALT_DRIVER_READ(ALT_STDIN_DEV, &c, 1, alt_fd_list[STDIN_FILENO].fd_flags) <= 0) { return -1; } return c; #else return getchar(); #endif #endif }

 

It seems that the direct device drivers aren't available, and neither is getc.

is it some header missing or something similar?

 

 

 

LucasM
Novice
367 Views

It seems that with the small c library enabled stdin,stdou and stderr are "preopened" files, so i can interact with them as files whithout opening them, can't find right now exactly where i saw this info.

View solution in original post

Reply