Forum Discussion

Altera_Forum's avatar
Altera_Forum
Icon for Honored Contributor rankHonored Contributor
18 years ago

Reading from files in Nios II simulation

Hi,

I've created a simulation setup for a Nios II cpu design using SOPC Buillder and Nios II IDE to generate all of the required simulation files, converted everything to run using NCSim on a UNIX environment. I've had no trouble with the simulations or setup up to this point.

The trouble started when I wanted to write a simple test script to run on the Nios processor to read a input command file and act on the commands with that file, and then write out a log file. However, when it tries to access the file, it prints "Cannot open command input file" to the console window. Below is the C code I'm using to access the HAL file I/O:

# include <stdio.h>

# include <stdlib.h>

# include <string.h>

# include <system.h>

int main ()

{

FILE *infile = NULL;

FILE *logfile = NULL;

/***************************************************/

/* Open files for access */

/***************************************************/

infile=fopen("Nios_II_cpu_model.in","r");

if (infile == NULL)

{

printf ("Cannot open input command file!\n");

exit(1);

}

logfile=fopen("Nios_II_cpu_model.log","w");

if (logfile == NULL)

{

printf ("Cannot open output log file!\n");

exit(1);

}

/***************************************************/

/* Close the files */

/***************************************************/

fclose(infile);

fclose(logfile);

return 0;

}

Anyone have any ideas???

Thanks,

Tony
No RepliesBe the first to reply