Rleg  2
 All Data Structures Files Functions Variables Typedefs Macros Groups Pages
Functions
taskScheduler.c File Reference
#include <string.h>
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#include <pthread.h>
#include <unistd.h>
#include <signal.h>
#include <sys/time.h>
#include "taskScheduler.h"
Include dependency graph for taskScheduler.c:

Go to the source code of this file.

Functions

void timer_new_task (TASK_S *task, void(*runFunction)(void))
 Create a task. More...
 
void timer_start_task (TASK_S *task, void(*alertFunction)(int), int period_us)
 Start some task. More...
 
void timer_function_task (TASK_S *task)
 
void timer_stop_task (TASK_S *task)
 Stop some task. More...
 

Function Documentation

void timer_function_task ( TASK_S task)
Todo:
make a function to set all times to zero

Definition at line 76 of file taskScheduler.c.

References TASK_S::run, and status.

Referenced by control_hook(), and ui_hook().

77 {
78  int status = 0;
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;
85 
86  gettimeofday(&time_exec_start, NULL);
87 
88  // Time calculation
89  if((*task).isFirstExecution)
90  {
91  gettimeofday(&timereset, NULL);
93  }
94 
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;
99 
100  if((*task).isFirstExecution)
101  {
102  T_task_mean = T_task;
103  T_task_min = 1e200;
104  T_task_max = 0.0;
105  //t0 = t_task;
106  }
107  else
108  {
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;
112  }
113 
114  // Run the thread
115  task->run();
116 
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);
119 
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;
125 
126  (*task).isFirstExecution = 0;
127 }
int status
Definition: communication.c:10
void(* run)()
hook to the action
Definition: taskScheduler.h:30

Here is the caller graph for this function: