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

Where is fcntl

Altera_Forum
Honored Contributor II
1,099 Views

alt_avalon_uart_read() and alt_avalon_uart_write() routines support a 'O_NONBLOCK' parameter. I'd like to control this flag from my code using the following function: 

 

static void set_block_mode(bool block_mode) {        int cntl = fcntl(STDIN_FILENO, F_GETFL);        if (cntl & O_NONBLOCK)        {                if (block_mode)                        fcntl(STDIN_FILENO, F_SETFL, cntl & ~O_NONBLOCK);        }        else        {                if (! block_mode)                        fcntl(STDIN_FILENO, F_SETFL, cntl | O_NONBLOCK);        } } 

 

 

I included <fcntl.h> and compiled my code, but I was not able to link it successfully because fcntl() is not defined in libc. 

 

I found another potential way of doing this from the thread entitled "Nios II UART Troubles", but would prefer to handle things with the above routine. Where did the fcntl routine go? 

 

Thanks, 

-Mark
0 Kudos
1 Reply
Altera_Forum
Honored Contributor II
373 Views

Unfortunately the function fcntl() is not implemented by the Altera HAL. The Altera HAL is a minimal C runtime environment, and so doesn&#39;t support the complete POSIX spec. If you want to use functions like this you will need to use an environment that provides a more comprehensive POSIX implementation. For example both the ucLinux and eCos operating systems contain this function. Both of these are available for download through this forum. 

 

If you want a single-threaded C runtime environment that includes POSIX file I/O then eCos can be configured in this way (i.e. without a scheduler). That may be an option to consider, depending on your memory budget.  

 

With the Altera HAL, you will need to set a file descriptor into non-blocking mode at open time.
0 Kudos
Reply