I use the Nios 2 IDE from Altera with the Altera DE2. I add a file Functions.c
with code that needs a timer e.g.
int main ()
{
int w[8192];
int a, b;
int size = M;
printf("Working Set\n\n");
printf("Information about the system:\n");
printf("\n");
printf("Processor Type: %s\n", NIOS2_CPU_IMPLEMENTATION);
printf("Size Instruction Cache: %d\n", NIOS2_ICACHE_SIZE);
printf("Line Size Instruction Cache: %d\n", NIOS2_ICACHE_LINE_SIZE);
printf("Size Data Cache: %d\n", NIOS2_DCACHE_SIZE);
printf("Line Size Data Cache: %d\n\n\n", NIOS2_DCACHE_LINE_SIZE);
/* Check if timer available */
if (alt_timestamp_start() < 0)
printf("No timestamp device available!");
else
{
/* Print Information about the system */
printf("Information about the system:\n");
printf("\n");
/* Print frequency and period */
printf("Timestamp frequency: %3.1f MHz\n", (float)alt_timestamp_freq()/1000000.0);
printf("Timestamp period: %f ms\n\n", 1000.0/(float)alt_timestamp_freq());
/* Calculate Timer Overhead */
// Average of 10 measurements */
int i;
timer_overhead = 0;
for (i = 0; i < 10; i++) {
start_measurement();
stop_measurement();
timer_overhead = timer_overhead + time_2 - time_1;
}
timer_overhead = timer_overhead / 10;
printf("Timer overhead in ticks: %d\n", (int) timer_overhead);
printf("Timer overhead in ms: %f\n",
1000.0 * (float)timer_overhead/(float)alt_timestamp_freq());
// === Task 1 : Block Sizes ===
// Function 1.1
initArray(w, 8192);
printf("Function 1.1: ");
start_measurement();
for (i = 0; i < 128; i++)
w[i]++;
stop_measurement();
printf("%5.2f us", (float) microseconds(ticks - timer_overhead));
printf("(%d ticks)\n", (int) (ticks - timer_overhead));
printf("Done!\n");
}
return 0;
}
But I get build errors when trying with different timers in the system properties time. Can you tell me how I should connect the timers?
I suppose that I should not build with no system timer and adding the file requires a timer. When I add the file I get these errors.
make -s all includes
Compiling Functions.c...
../Functions.c: In function `microseconds':
../Functions.c:20: warning: implicit declaration of function `alt_timestamp_freq'
../Functions.c: In function `start_measurement':
../Functions.c:35: warning: implicit declaration of function `alt_dcache_flush_all'
../Functions.c:36: warning: implicit declaration of function `alt_icache_flush_all'
../Functions.c:38: warning: implicit declaration of function `alt_timestamp_start'
../Functions.c:39: warning: implicit declaration of function `alt_timestamp'
../Functions.c: In function `main':
../Functions.c:58: error: `NIOS2_CPU_IMPLEMENTATION' undeclared (first use in this function)
../Functions.c:58: error: (Each undeclared identifier is reported only once
../Functions.c:58: error: for each function it appears in.)
../Functions.c:59: error: `NIOS2_ICACHE_SIZE' undeclared (first use in this function)
../Functions.c:60: error: `NIOS2_ICACHE_LINE_SIZE' undeclared (first use in this function)
../Functions.c:61: error: `NIOS2_DCACHE_SIZE' undeclared (first use in this function)
../Functions.c:62: error: `NIOS2_DCACHE_LINE_SIZE' undeclared (first use in this function)
../Functions.c:52: warning: unused variable `a'
../Functions.c:52: warning: unused variable `b'
../Functions.c:53: warning: unused variable `size'
make: *** [obj/Functions.o] Error 1
Build completed in 2.3 seconds
Best Answer
NIOS2_CPU_IMPLEMENTATION
and other undeclared identifiers are defined insystem.h
file, generated with BSP. It looks like you forgot to include this library in your code.Problems with implicit declarations are caused by not included
sys/alt_timestamp.h
library.