Jump to content


Timing your Nios II designs from software


  • You cannot reply to this topic
1 reply to this topic

#1 RalphBodenner

    Advanced Member

  • Admin
  • PipPipPip
  • 348 posts

Posted 06 February 2005 - 01:33 AM

Altera's HAL library for Nios II comes with an API for a timestamp facility, which you can use to measure the performance of your Impulse C applications. For example, to measure the running time of an entire application, you might include this code in your software source files:

CODE
#include <stdio.h>
#include "co.h"

#ifdef IMPULSE_C_TARGET         // If we're building on the target platform,
#include "system.h"             // include Nios II-specific header files in order
#include "sys/alt_timestamp.h"  // to use the timestamp facility.
#endif

int main(int argc, char ** argv)
{
   // ...
#ifdef IMPULSE_C_TARGET
   alt_u32 elapsed_time;
   if ( -1 == alt_timestamp_start() ) {
       printf("Error initializing timestamp facility\n");
   }
   elapsed_time = alt_timestamp();
#endif

   my_arch = co_initialize(NULL);
   co_execute(my_arch);

#ifdef IMPULSE_C_TARGET
   elapsed_time = alt_timestamp() - elapsed_time;
   printf("Elapsed time: %lu ms\n", elapsed_time/(alt_timestamp_freq()/1000));
#endif
   // ...
}


alt_timestamp_start() resets the timestamp counter and should be called before using alt_timestamp().

alt_timestamp() returns the current timestamp count (in clock ticks).

alt_timestamp_freq() returns the number of ticks per second.

To use the timestamp functions, your hardware system will need to include a timer to generate timestamps. Normally, an SOPC Builder system will include a periodic system timer (named "system_timer"), but you will need to a second "Interval timer" peripheral for use as a timestamp timer (let's call it "timestamp_timer").

Once you've generated the SOPC Builder system with both timers, you must specify which timer to use for timestamping when building the software system library. Create a Nios II IDE software project as usual and make sure you're in the C/C++ Projects perspective. Right-click your project's system library and select "Properties" from the context menu. Select "System Library" from the tree on the left side of dialog box that appears. In the section of the dialog marked "System Library Contents", open the drop-down box next to "Timestamp timer" and choose the name of your timestamp peripheral ("TIMESTAMP_TIMER").

Now you can build and run the software project as usual.

The simple timer described here is a good way to easily gather performance information as you iteratively refine your Impulse C design.
Ralph Bodenner
Impulse Accelerated Technologies, Inc.

#2 cls_egr

    Advanced Member

  • Members
  • PipPipPip
  • 78 posts

Posted 03 March 2008 - 02:09 PM

Hi,

Is there a similar library for xilinx platforms? Or what other options can I use to time an Impulse C application?

Thank you
cls





1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users