- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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; }Link Copied
0 Replies

Reply
Topic Options
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page