beautypg.com

Driver options: fast vs small implementations – Altera Embedded Peripherals IP User Manual

Page 78

background image

Table 8-3: Example: Sending and Receiving Characters

/* A simple program that recognizes the characters 't' and 'v' */
#include
#include
int main ()
{
char* msg = "Detected the character 't'.\n";
FILE* fp;
char prompt = 0;
fp = fopen ("/dev/uart1", "r+"); //Open file for reading and writing
if (fp)
{
while (prompt != 'v')
{ // Loop until we receive a 'v'.
prompt = getc(fp); // Get a character from the UART.
if (prompt == 't')
{ // Print a message if character is 't'.
fwrite (msg, strlen (msg), 1, fp);
}
}
fprintf(fp, "Closing the UART file.\n");
fclose (fp);
}
return 0;
}

For more information about the HAL system library, refer to the

Nios II Software Developer's

Handbook

.

Driver Options: Fast vs Small Implementations

To accommodate the requirements of different types of systems, the UART driver provides two variants: a

fast version and a small version. The fast version is the default. Both fast and small drivers fully support

the C standard library functions and the HAL API.
The fast driver is an interrupt-driven implementation, which allows the processor to perform other tasks

when the device is not ready to send or receive data. Because the UART data rate is slow compared to the

processor, the fast driver can provide a large performance benefit for systems that could be performing

other tasks in the interim.

UG-01085

2014.24.07

Driver Options: Fast vs Small Implementations

8-9

UART Core

Altera Corporation

Send Feedback