Rleg  2
 All Data Structures Files Functions Variables Typedefs Macros Groups Pages
Functions
Scheduler for tasks

Implentation of Scheduler for tasks: More...

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_stop_task (TASK_S *task)
 Stop some task. More...
 

Detailed Description

Implentation of Scheduler for tasks:

Author
Rafael Lima
Todo:
test it

Function Documentation

void timer_new_task ( TASK_S task,
void(*)(void)  runFunction 
)

Create a task.

Parameters
*task
*voidFunctionPointer to the function called to execute

Definition at line 16 of file taskScheduler.c.

Referenced by main().

16  {
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;
23 
24  (*task).run = runFunction;
25 }

Here is the caller graph for this function:

void timer_start_task ( TASK_S task,
void(*)(int)  alertFunction,
int  period_us 
)

Start some task.

Parameters
*taskStruct whith task data
period_usPeriod Value to repeat the task
Todo:
verify how use two tasks

Definition at line 27 of file taskScheduler.c.

References TASK_S::isFirstExecution, TASK_S::period_us, and TASK_S::timer.

Referenced by main().

27  {
28  struct itimerspec itimer;
29  struct sigevent evp;
30  int erno = 0;
31 
32  task->isFirstExecution = 1;
33  task->period_us = period_us;
34 
35  /*evp.sigev_value.sival_ptr = &(task->timer);
36  evp.sigev_notify = SIGEV_SIGNAL;
37  evp.sigev_signo = SIGUSR1;*/
38 
39  //memset (&evp, 0, sizeof (struct sigevent));
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;
44 
45  if(timer_create( CLOCK_REALTIME, &evp, &(task->timer))<0)
46  {
47  fprintf(stderr, "[%d]: %s\n", __LINE__, strerror(erno));
48  exit(erno);
49  }
50 
51  /*/ Signal handler configuration
52  struct sigaction satimer;
53  satimer.sa_handler = task->run;
54  sigemptyset( &satimer.sa_mask );
55  satimer.sa_flags = SA_RESTART;*/
56 
57  //if ( sigaction( SIGUSR1, &satimer, NULL ) < 0)
58  if(timer_create(CLOCK_REALTIME, &evp, task->timer) < 0)
59  {
60  //printf( "ERROR: sigaction.\n" );
61  fprintf(stderr, "[%d]: %s\n", __LINE__, strerror(erno));
62  exit(erno);
63  }
64 
65  itimer.it_interval.tv_sec = 0;
66  itimer.it_interval.tv_nsec= task->period_us*1000;
67  itimer.it_value = itimer.it_interval;
68 
69  if(timer_settime(task->timer,0,&itimer,NULL) < 0)
70  {
71  fprintf(stderr,"[%d]: %s\n", __LINE__, strerror(erno));
72  exit(erno);
73  }
74 }
volatile int isFirstExecution
Flag to sign first Exec.
Definition: taskScheduler.h:28
timer_t timer
Definition: taskScheduler.h:21
volatile int period_us
Definition: taskScheduler.h:27

Here is the caller graph for this function:

void timer_stop_task ( TASK_S task)

Stop some task.

Todo:
verify use of variable 'erno'

Definition at line 129 of file taskScheduler.c.

Referenced by main().

129  {
130  int erno = 0;
131  if(timer_delete((*task).timer)<0){
132  fprintf(stderr,"[%d]:%s\n",__LINE__,strerror(erno));
133  exit(erno);
134  }
135 }

Here is the caller graph for this function: