Discussion:
Issue working with rtemsTimer
Martínez, Pablo
2014-09-15 20:05:03 UTC
Permalink
Hi guys,

Im trying to implement a single shot timer.

I derive from rtemsTimer class and replace virtual void triggered()=0

#include <rtems++/rtemsTimer.h>
...

class Timer : public rtemsTimer {
public:
Timer(const char* tname);
virtual ~Timer();
private:
void triggered();
};

in timer.cpp

void SynchTimer::triggered(){

printf("hello Timer! \n");

}


Then I have the following task class who creates and fires a Timer object:

class TimerMngr : public rtemsTask{

public:
TimerMngr(const char* tname);
virtual ~TimerMngr();

private:
void body(rtems_task_argument argument);

};


in timerMngr.cpp

TimerMngr::TimerMngr(const char* tname)
: rtemsTask(tname,
1,
RTEMS_MINIMUM_STACK_SIZE,
RTEMS_PREEMPT|RTEMS_TIMESLICE,
0,
RTEMS_NO_FLOATING_POINT,
RTEMS_LOCAL)

{
if(last_status_code()!=RTEMS_SUCCESSFUL)
printf("SynchMngr::error when create()%d \n",
last_status_code());
}



void TimerMngr::body(rtems_task_argument argument){

printf("TimerMngr::body! \n"); [1]

/* Create the Timer
* *****************************/
Timer* timer=new Timer("timer");

printf("SynchMngr, CurrentTime! @ %d \n",getCurrentTime()); [2]


/* start timer
* *****************************/
rtems_status_code status;
status=synch_timer->fire_after(120);
printf("synch_timer->fire_after() status %d \n",status); [3]


wake_after(500);
printf("SynchMngr, CurrentTime @ %d \n",getCurrentTime()); [4]

}

unsigned TimerMngr::getCurrentTime(){
//rtems_unsigned32 time_stamp;
unsigned time_stamp;
time_stamp=0;
rtems_status_code status;

status=rtems_clock_get(RTEMS_CLOCK_GET_SECONDS_SINCE_EPOCH,&time_stamp);
if(status!=RTEMS_SUCCESSFUL)
printf("error with rtems_clock_get %d \n",status);

return time_stamp;
}

When I run the app I get the first and second printf [1] y [2]. But just
"syn" from the 3erd printf [3].

In the conf file:

#define CONFIGURE_APPLICATION_NEEDS_CLOCK_DRIVER
#define CONFIGURE_TICKS_PER_TIMESLICE 30
#define CONFIGURE_MAXIMUM_TIMERS 4

Any suggestion?

Cheers,
Pablo
--
Martínez, Pablo Agustín
Joel Sherrill
2014-09-15 20:12:26 UTC
Permalink
The timer method runs inside the clock tick ISR and you can't call printf() from an interrupt. At least that is what I spot first.

Also easy in C++ to do something in an ISR you shouldn't.
Post by Martínez, Pablo
Hi guys,
Im trying to implement a single shot timer.
I derive from rtemsTimer class and replace virtual void triggered()=0
#include <rtems++/rtemsTimer.h>
...
class Timer : public rtemsTimer {
Timer(const char* tname);
virtual ~Timer();
void triggered();
};
in timer.cpp
void SynchTimer::triggered(){
printf("hello Timer! \n");
}
class TimerMngr : public rtemsTask{
TimerMngr(const char* tname);
virtual ~TimerMngr();
void body(rtems_task_argument argument);
};
in timerMngr.cpp
TimerMngr::TimerMngr(const char* tname)
: rtemsTask(tname,
1,
RTEMS_MINIMUM_STACK_SIZE,
RTEMS_PREEMPT|RTEMS_TIMESLICE,
0,
RTEMS_NO_FLOATING_POINT,
RTEMS_LOCAL)
{
if(last_status_code()!=RTEMS_SUCCESSFUL)
printf("SynchMngr::error when create()%d \n",
last_status_code());
}
void TimerMngr::body(rtems_task_argument argument){
printf("TimerMngr::body! \n"); [1]
/* Create the Timer
* *****************************/
Timer* timer=new Timer("timer");
/* start timer
* *****************************/
rtems_status_code status;
status=synch_timer->fire_after(120);
printf("synch_timer->fire_after() status %d \n",status); [3]
wake_after(500);
}
unsigned TimerMngr::getCurrentTime(){
//rtems_unsigned32 time_stamp;
unsigned time_stamp;
time_stamp=0;
rtems_status_code status;
status=rtems_clock_get(RTEMS_CLOCK_GET_SECONDS_SINCE_EPOCH,&time_stamp);
if(status!=RTEMS_SUCCESSFUL)
printf("error with rtems_clock_get %d \n",status);
return time_stamp;
}
When I run the app I get the first and second printf [1] y [2]. But just
"syn" from the 3erd printf [3].
#define CONFIGURE_APPLICATION_NEEDS_CLOCK_DRIVER
#define CONFIGURE_TICKS_PER_TIMESLICE 30
#define CONFIGURE_MAXIMUM_TIMERS 4
Any suggestion?
Cheers,
Pablo
--
Martínez, Pablo Agustín
Martínez, Pablo
2014-09-15 20:11:51 UTC
Permalink
void SynchTimer::triggered(){
printf("hello Timer! \n");
}

misspelling:

void Timer::triggered(){
printf("hello Timer! \n");
}
--
Martínez, Pablo Agustín
Loading...