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

nonblocking getchar(), getting ENOMEM

Altera_Forum
Honored Contributor II
1,135 Views

I've tried implementing a nonblocking getchar() using two different methods 

 

1) fcntl(fileno(stdin), F_SETFL, (long)O_NONBLOCK); 

2) open("/dev/uart_0, O_RDWR | O_NONBLOCK); 

 

and then use a simple read() on the fd. I would expect to have read() return -1 most times with errno set to EAGAIN. However what I am getting instead is ENOMEM (errno = 12). 

 

I am using a basic NIOS2 on a system with 128kB of memory (implemented in M9K blocks in the EPCS4CE55I8L, no external memory). Did I miss something important either in the SOPC environment or in my BSP settings? 

 

My function is as follows: 

 

/* returns 1 with the character in c if a character was available, 0 otherwise */ 

int getchar_nonblock(int fd, char *c) 

int ret; 

 

ret = read(fd, c, 1); 

if(ret == -1) { 

if(errno == EAGAIN) return 0; 

printf("? read returned -1, errno set to %i\r\n", errno); 

return 0; 

 

return 0; 

}
0 Kudos
0 Replies
Reply