Nios® V/II Embedded Design Suite (EDS)
Support for Embedded Development Tools, Processors (SoCs and Nios® V/II processor), Embedded Development Suites (EDSs), Boot and Configuration, Operating Systems, C and C++
12648 Discussions

Nios-ll Interval Timer is not enabled

ZKhan1
Novice
8,497 Views

Hi there ,

 

I have been trying to run Nios-ll interval timer using the code given in Embedded IP core document the code gets stuck at ""No timestamp device available\n".

 

I did included Interval Timer for both sys clk timer and time stamp timer in BSP Editor . But it dosent have any effect .

 

see below timer declaration in system.h

 

 

/* * Interval_Timer configuration * */   #define ALT_MODULE_CLASS_Interval_Timer altera_avalon_timer #define INTERVAL_TIMER_ALWAYS_RUN 0 #define INTERVAL_TIMER_BASE 0x10002000 #define INTERVAL_TIMER_COUNTER_SIZE 32 #define INTERVAL_TIMER_FIXED_PERIOD 0 #define INTERVAL_TIMER_FREQ 50000000 #define INTERVAL_TIMER_IRQ 0 #define INTERVAL_TIMER_IRQ_INTERRUPT_CONTROLLER_ID 0 #define INTERVAL_TIMER_LOAD_VALUE 6249999 #define INTERVAL_TIMER_MULT 0.001 #define INTERVAL_TIMER_NAME "/dev/Interval_Timer" #define INTERVAL_TIMER_PERIOD 125.0 #define INTERVAL_TIMER_PERIOD_UNITS "ms" #define INTERVAL_TIMER_RESET_OUTPUT 0 #define INTERVAL_TIMER_SNAPSHOT 1 #define INTERVAL_TIMER_SPAN 32 #define INTERVAL_TIMER_TICKS_PER_SEC 8 #define INTERVAL_TIMER_TIMEOUT_PULSE_OUTPUT 0 #define INTERVAL_TIMER_TYPE "altera_avalon_timer"

also HAL

/* * hal configuration * */   #define ALT_INCLUDE_INSTRUCTION_RELATED_EXCEPTION_API #define ALT_MAX_FD 32 #define ALT_SYS_CLK INTERVAL_TIMER #define ALT_TIMESTAMP_CLK INTERVAL_TIMER

 see below C code i have been trying to run :

#include <stdio.h> #include "E:\FPGA_VGA\NIOS_Basic_Comp_timer\verilog\software\Timer_interval_bsp\HAL\inc\sys\alt_timestamp.h" #include "E:\FPGA_VGA\NIOS_Basic_Comp_timer\verilog\software\Timer_interval_bsp\drivers\inc\altera_avalon_timer.h" #include "E:\FPGA_VGA\NIOS_Basic_Comp_timer\verilog\software\Timer_interval_bsp\drivers\inc\altera_avalon_timer_regs.h" #include "alt_types.h" #include "system.h"   int main() { alt_u32 time1; alt_u32 time2; alt_u32 time3; alt_u32 TimerStatus; alt_u32 *Timerptr = INTERVAL_TIMER_BASE; unsigned short TimerStatusreg; unsigned short TimerCtrlreg; unsigned short TimerPrdLreg = 0x0001; unsigned short TimerPrdHreg = 0x00ff; unsigned short TimerStop = 0x0008; unsigned short TimerSnapLreg; unsigned short TimerSnapHreg; ///////////// TimerStatusreg = *Timerptr; TimerCtrlreg = *Timerptr + 0x4; *(Timerptr + 0x4) = TimerStop; *(Timerptr + 0x8) = TimerPrdLreg; *(Timerptr + 0xC) = TimerPrdHreg; TimerCtrlreg = *Timerptr + 0x4; TimerSnapLreg = *Timerptr + 0x10; TimerSnapHreg = *Timerptr + 0x14;   if (alt_timestamp_start() < 0) { printf ("No timestamp device available\n"); } else { time1 = alt_timestamp(); func1(); /* first function to monitor */ time2 = alt_timestamp(); func2(); /* second function to monitor */ time3 = alt_timestamp(); printf ("time in func1 = %u ticks\n",(unsigned int) (time2 - time1)); printf ("time in func2 = %u ticks\n",(unsigned int) (time3 - time2)); printf ("Number of ticks per second = %u\n",(unsigned int)alt_timestamp_freq()); } return 0; } /////////////////// void func1(void) { printf (" Calling Function 1 ...."); } ///////// void func2(void) { printf (" Calling Function 2 ...."); }

 

0 Kudos
10 Replies
Abe
Valued Contributor II
4,926 Views

Hi,

Can you post the entire NIOS-2 HW & SW project here so that we can take a look. Have you included the Timer in the NIOS-2 hW build ?

0 Kudos
ZKhan1
Novice
4,926 Views

Hello ,

 

Its actually DE2-115 Basic Computer example that i am working on , see attached .

0 Kudos
dsmirnov
New Contributor I
4,926 Views

I guess the problem is that you declared this timer as system.

Let us first check the alt_timestamp_start function:

int alt_timestamp_start(void) { void* base = altera_avalon_timer_ts_base;   if (!altera_avalon_timer_ts_freq) { return -1; } else { . . . }

That means that you get the zero value of altera_avalon_timer_ts_freq. But why? As we can find in the altera_avalon_timer.h there is a definition for timer initialization, which is basicly looks like this:

#define ALTERA_AVALON_TIMER_INIT(name, dev) if (name##_BASE == ALT_SYS_CLK_BASE) { . . . . . . else if (name##_BASE == ALT_TIMESTAMP_CLK_BASE) { if (name##_SNAPSHOT) { altera_avalon_timer_ts_base = (void*) name##_BASE; altera_avalon_timer_ts_freq = name##_FREQ; } . . . }

The value of altera_avalon_timer_ts_freq is getting right frequency is only when during the definition we don't have a sys_clk. Since you have it, we don't visit the else branch and we don't initialize it.

You can don't use it as a sys_clk, or create new interval timer.

 

ZKhan1
Novice
4,927 Views

Hi dsmirnov ,

 

your answer has confused me even more ,..... i have read various posts and the instructions in Embedded Ip core doc , all suggest that i have to specify in BSP editor that sys clk and timer stamp clk should be assigned to interval timer ???

 

Tell me step by step what i have to do to make it work , if i have to add another timer then which clk will derive it and how to set the old timer .

 

Thanks ,

0 Kudos
ZKhan1
Novice
4,927 Views

According to your solution , you are suggesting that i assign "NONE" for sys_clk_timer see screen shot attached .

 

I have also attached the previous setting pic .

0 Kudos
ZKhan1
Novice
4,926 Views

previous setting

0 Kudos
ZKhan1
Novice
4,926 Views

Hi ,

 

It worked by assigning sys_clk_timer to NONE and timestamp_timer to interval_timer , in BSP editor .

 

dsmirnov
New Contributor I
4,926 Views

Dear ZKhan1,

 

I just had checked the sources of BSP library so they tell's that it should be different timers imho

It all depends if you need sys_clk or not, since we can change architecture of our system the developers provides us

the ability to control everything. I'm glad it worked!

It would be useful if you will mark the answer as a solution)

 

Since after the answer is marked as right I have no ability to add more messages, so I will comment here:

 

Well, it is only software part, so, technically, it shouldn't has an impact on the other peripheral. When you make this step in BSP Editor you just change part of system.h file:

/* * hal configuration * */   #define ALT_INCLUDE_INSTRUCTION_RELATED_EXCEPTION_API #define ALT_MAX_FD 32 #define ALT_SYS_CLK SYS_TMR #define ALT_TIMESTAMP_CLK none

Basicly by BSP Editor you just change some parts of the libraries and add ability of use such files like usleep.h

0 Kudos
ZKhan1
Novice
4,926 Views

Thanks dsmirnov

ZKhan1
Novice
4,926 Views

hmmm, i gets me thinking if sys_clk is left NONE will it effect other peripherals ???? i will test other peripherals and give you feed back .

0 Kudos
Reply