17 (*task).t_global = 0.0;
18 (*task).T_exec_global = 0.0;
19 (*task).T_mean_global = 0.0;
20 (*task).T_max_global = 0.0;
21 (*task).period_us = 0.0;
22 (*task).isFirstExecution = 1;
24 (*task).run = runFunction;
28 struct itimerspec itimer;
40 evp.sigev_value.sival_int = 0;
41 evp.sigev_notify = SIGEV_THREAD;
42 evp.sigev_notify_attributes = NULL;
43 evp.sigev_notify_function = alertFunction;
45 if(timer_create( CLOCK_REALTIME, &evp, &(task->
timer))<0)
47 fprintf(stderr,
"[%d]: %s\n", __LINE__, strerror(erno));
58 if(timer_create(CLOCK_REALTIME, &evp, task->
timer) < 0)
61 fprintf(stderr,
"[%d]: %s\n", __LINE__, strerror(erno));
65 itimer.it_interval.tv_sec = 0;
66 itimer.it_interval.tv_nsec= task->
period_us*1000;
67 itimer.it_value = itimer.it_interval;
69 if(timer_settime(task->
timer,0,&itimer,NULL) < 0)
71 fprintf(stderr,
"[%d]: %s\n", __LINE__, strerror(erno));
79 static struct timeval timereset;
80 static struct timeval time;
81 static struct timeval time_exec_start;
82 static struct timeval time_exec_end;
83 static double T_task,t_task,t_task_previous;
84 static double T_task_mean,T_task_min,T_task_max,T_task_exec;
86 gettimeofday(&time_exec_start, NULL);
89 if((*task).isFirstExecution)
91 gettimeofday(&timereset, NULL);
95 gettimeofday(&time, NULL);
96 t_task = ((time.tv_sec - timereset.tv_sec) + (time.tv_usec - timereset.tv_usec)*1e-6);
97 T_task = t_task - t_task_previous;
98 t_task_previous = t_task;
100 if((*task).isFirstExecution)
102 T_task_mean = T_task;
109 T_task_mean = 0.05*T_task + 0.95*T_task_mean;
110 if(T_task < T_task_min) T_task_min = T_task;
111 if(T_task > T_task_max) T_task_max = T_task;
117 gettimeofday(&time_exec_end, NULL);
118 T_task_exec = ((time_exec_end.tv_sec - time_exec_start.tv_sec) + (time_exec_end.tv_usec - time_exec_start.tv_usec)*1e-6);
120 (*task).t_global = t_task;
121 (*task).T_mean_global = T_task_mean;
122 (*task).T_min_global = T_task_min;
123 (*task).T_max_global = T_task_max;
124 (*task).T_exec_global = T_task_exec;
126 (*task).isFirstExecution = 0;
131 if(timer_delete((*task).timer)<0){
132 fprintf(stderr,
"[%d]:%s\n",__LINE__,strerror(erno));
void timer_function_task(TASK_S *task)
volatile int isFirstExecution
Flag to sign first Exec.
void timer_stop_task(TASK_S *task)
Stop some task.
void timer_start_task(TASK_S *task, void(*alertFunction)(int), int period_us)
Start some task.
void timer_new_task(TASK_S *task, void(*runFunction)(void))
Create a task.
Task to schedule definition.
void(* run)()
hook to the action