beautypg.com

Altera Embedded Peripherals IP User Manual

Page 64

background image

Table 7-2: Example: Transmitting Characters to a JTAG UART Core

/* 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/jtag_uart", "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 JTAG UART.
if (prompt == 't')
{ // Print a message if character is 't'.
fwrite (msg, strlen (msg), 1, fp);
}
if (ferror(fp)) // Check if an error occurred with the file

pointer clearerr(fp); // If so, clear it.
}
fprintf(fp, "Closing the JTAG UART file handle.\n");
fclose (fp);
}
return 0;
}

In this example, the

ferror(fp)

is used to check if an error occurred on the JTAG UART connection,

such as a disconnected JTAG connection. In this case, the driver detects that the JTAG connection is

disconnected, reports an error (

EIO

), and discards data for subsequent transactions. If this error ever

occurs, the C library latches the value until you explicitly clear it with the

clearerr()

function.

Nios II Software Developer's Handbook

For complete details of the HAL system library, refer to the Nios II Software Developer's Handbook.
The Nios II Embedded Design Suite (EDS) provides a number of software example designs that use the

JTAG UART core.

UG-01085

2014.24.07

HAL System Library Support

7-7

JTAG UART Core

Altera Corporation

Send Feedback