Specifications

Example 6–3. Hello World
#include <stdio.h>
int main ()
{
printf ("Hello world!");
return 0;
}
When using the UNIX-style API, you can use the file descriptors stdin, stdout, and stderr, defined in
unistd.h, to access, respectively, the standard in, standard out, and standard error character I/O streams.
unistd.h is installed with the Nios II EDS as part of the newlib C library package.
General Access to Character Mode Devices
Accessing a character-mode device other than stdin, stdout, or stderr is as easy as opening and writing
to a file.
Example 6–4. Writing Characters to a UART Called uart1
#include <stdio.h>
#include <string.h>
int main (void)
{
char* msg = "hello world";
FILE* fp;
fp = fopen ("/dev/uart1", "w");
if (fp!=NULL)
{
fprintf(fp, "%s",msg);
fclose (fp);
}
return 0;
}
C++ Streams
HAL-based systems can use the C++ streams API for manipulating files from C++.
/dev/null
All systems include the device /dev/null. Writing to /dev/null has no effect, and all data is discarded. /dev/
null is used for safe I/O redirection during system startup. This device can also be useful for applications
that wish to sink unwanted data.
This device is purely a software construct. It does not relate to any physical hardware device in the system.
Lightweight Character-Mode I/O
The HAL offers several methods of reducing the code footprint of character-mode device drivers.
For more information, refer to the “Reducing Code Footprint in Embedded Systems” chapter.
Related Information
Reducing Code Footprint in Embedded Systems on page 6-27
Altera Logging Functions
The Altera logging functions provide a separate channel for sending logging and debugging information
to a character-mode device, supplementing stdout and stderr. The Altera logging information can be
NII5V2
2015.05.14
General Access to Character Mode Devices
6-7
Developing Programs Using the Hardware Abstraction Layer
Altera Corporation
Send Feedback