Knowledge Base Article

How can I set the UART HAL driver to operate in non-blocking mode with the Nios II processor?

Description

The HAL provides two methods to set the UART HAL driver to operate in non-blocking mode.

UNIX-Style

If using UNIX-style IO function calls you can use the open() function to set a UART to be non-blocking. To do this, open a file descriptor to your UART in the following manner:

fd = open("/dev/<your uart name>",O_NONBLOCK | O_RDWR);

This file descriptor sets the UART to operate in read/write and non-blocking mode. You can then use the file descriptor with the read() and write() functions.

ANSI C

If using ANSI C IO function calls you can set a UART HAL driver to operate in non-blocking mode using fcntl(). To do this you need to reference fcntl.h and unistd.h in your source code. Then you can use fcntl() to set the UART to non-blocking mode. Below is an example that sets the STDIN IO channel to operate in non-blocking mode:

fcntl(STDIN_FILENO, F_SETFL, O_NONBLOCK);

 

    For more information, you can reference the HAL API Reference in the Nios® II Software Developer's Handbook. This document can be found in the following places:

    Nios II installation - <Nios II installation directory>/documents/n2sw_nii5v2.pdf

    Altera® web site - http://www.altera.com/literature/lit-nio2.jsp

    Updated 7 days ago
    Version 2.0
    No CommentsBe the first to comment