Rleg  2
 All Data Structures Files Functions Variables Typedefs Macros Groups Pages
Macros | Functions
main2.h File Reference
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Macros

#define SUCCESS   1
 
#define FAILURE   -1
 

Functions

int main (void)
 
int periodic_task_1 (void)
 
int periodic_task_2 (void)
 
void timer_start_task_1 (void)
 
void timer_start_task_2 (void)
 
void timer_stop_task_1 (void)
 
void timer_stop_task_2 (void)
 
void timer_function_task_1 (void)
 
void timer_function_task_2 (void)
 
int reset_timer (void)
 
int get_time (double *time_control_task_s, double *Ts_control_task_s, double *mean_time_control_task_s, double *t0_control_task_s)
 Review of this function: More...
 
void exit_program (void)
 Internal function to end program. More...
 

Macro Definition Documentation

#define FAILURE   -1

Definition at line 6 of file main2.h.

#define SUCCESS   1

Definition at line 5 of file main2.h.

Function Documentation

void exit_program ( void  )

Internal function to end program.

Definition at line 180 of file main.c.

180  {
181  quittask = 1;
182  return;
183 }
int quittask
Definition: main.c:39
int get_time ( double *  time_control_task_s,
double *  Ts_control_task_s,
double *  mean_time_control_task_s,
double *  t0_control_task_s 
)

Review of this function:

Definition at line 167 of file main.c.

References TASK_S::period_us, SUCCESS, t0, TASK_S::t_global, TASK_S::T_mean_global, t_task_1_global, T_task_1_mean_global, and task_1_period_us.

Referenced by ui_overview_data().

168 {
169  *time_control_task_s = task1.t_global;
170  *Ts_control_task_s = (task1.period_us)/1e6;
171  *mean_time_control_task_s = task1.T_mean_global;
172  *t0_control_task_s = t0;
173 
174  return SUCCESS;
175 }
volatile double T_mean_global
Definition: taskScheduler.h:24
int t0
Definition: main.c:40
#define SUCCESS
Definition: calibration.h:6
TASK_S task1
Main rotine for control:
Definition: main.c:18
volatile int period_us
Definition: taskScheduler.h:27
volatile double t_global
Definition: taskScheduler.h:22

Here is the caller graph for this function:

int main ( void  )

Definition at line 42 of file main.c.

References IMU_PARAM_STRUCT::acc, IMU_PARAM_STRUCT::param_gyr::act, IMU_PARAM_STRUCT::param_gyr::clk_source, control_hook(), control_task(), SPI_PARAM_STRUCT::cs, datalogger_close(), datalogger_init(), DATALOGGER_RUNNING, datalogger_status(), datalogger_stop(), DATALOGGER_SUCCESS, datalogger_write_file(), devices_close(), devices_init(), FAILURE, IMU_PARAM_STRUCT::param_acc::full_res, IMU_PARAM_STRUCT::gyr, IMU_PARAM_STRUCT::param_gyr::lpf_bw, IMU_PARAM_STRUCT::mag, IMU_PARAM_STRUCT::param_mag::meas_mode, SPI_PARAM_STRUCT::mode, IMU_PARAM_STRUCT::param_mag::op_mode, quittask, IMU_PARAM_STRUCT::param_acc::range, IMU_PARAM_STRUCT::param_mag::range, IMU_PARAM_STRUCT::param_acc::rate, IMU_PARAM_STRUCT::param_gyr::rate, IMU_PARAM_STRUCT::param_mag::rate, IMU_PARAM_STRUCT::param_mag::samples_avg, SPI_PARAM_STRUCT::speed, status, SUCCESS, TASK1_PERIOD_US, TASK2_PERIOD_US, task_1_period_us, TASK_CONTROL_PERIOD, TASK_UI_PERIOD, timer_new_task(), timer_start_task(), timer_start_task_1(), timer_start_task_2(), timer_stop_task(), timer_stop_task_1(), timer_stop_task_2(), ui_close(), ui_hook(), ui_init(), and ui_task().

42  {
43  int return_value = SUCCESS;
44 
45 /*Setting config values:*/
46  // Parameters for IMU
48  imu_param.acc.rate=100;
49  imu_param.acc.range=16;
50  imu_param.gyr.rate=100;
51  imu_param.gyr.lpf_bw=188;
53  imu_param.gyr.act="XYZ";
54  imu_param.mag.rate=75;
59 
60  // Parameters for SPI
61  spi_param.mode=0;
62  spi_param.speed=375000;
63  spi_param.cs=0;
64 
65  // Periodic task :
68 
69 /*Initialization:*/
71  perror("Unsuccesful devices initialization");
72  return FAILURE;
73  }
74 
75  if(ui_init()!=SUCCESS){
76  perror("Unsuccesful user interface initialization");
77  return FAILURE;
78  }
79 
80  //timer_start_task(&task1,TASK1_PERIOD);
83 
84 /* Main loop: */
85  while(quittask == 0){
86  //ui_task(0);
87  }
88 
89 /*Shutting Down:*/
92  usleep(2000);
93 
94  if(ui_close()==FAILURE){
95  return_value = FAILURE;
96  }
97 
99 
100  return return_value;
101 }
MRA_DATA_STRUCT mra_data
Definition: main.c:32
int quittask
Definition: main.c:39
struct IMU_PARAM_STRUCT::param_mag mag
static void control_task()
Definition: main.c:127
int ui_close(void)
Close UI.
Definition: ui.c:41
#define TASK_CONTROL_PERIOD
Definition: main.c:22
SPI_PARAM_STRUCT spi_param
Definition: main.c:26
#define FAILURE
Definition: calibration.h:7
IMU_PARAM_STRUCT imu_param
Definition: main.c:25
TASK_S task_control
Definition: main.c:18
void timer_stop_task(TASK_S *task)
Stop some task.
struct IMU_PARAM_STRUCT::param_gyr gyr
struct IMU_PARAM_STRUCT::param_acc acc
#define TASK_UI_PERIOD
Definition: main.c:21
static void ui_task()
Definition: main.c:118
void timer_start_task(TASK_S *task, void(*alertFunction)(int), int period_us)
Start some task.
Definition: taskScheduler.c:27
#define SUCCESS
Definition: calibration.h:6
TASK_S task_ui
Definition: main.c:18
int devices_init(IMU_PARAM_STRUCT *imu_param, SPI_PARAM_STRUCT *spi_param, MRA_DATA_STRUCT *mra_data)
INITIALIZATION OF SENSORS AND DEVICES.
Definition: communication.c:12
static void ui_hook(int signo)
Definition: main.c:108
void timer_new_task(TASK_S *task, void(*runFunction)(void))
Create a task.
Definition: taskScheduler.c:16
int ui_init(void)
Initialize UI.
Definition: ui.c:26
int devices_close(IMU_PARAM_STRUCT *imu_param, SPI_PARAM_STRUCT *spi_param, MRA_DATA_STRUCT *mra_data)
Fuction to close all communication with the sensors and devices.
Definition: communication.c:82
static void control_hook(int signo)
Definition: main.c:113

Here is the call graph for this function:

int periodic_task_1 ( void  )

Definition at line 190 of file main2.c.

References actuate(), calibrate_all(), DATALOGGER_NOT_RUNNING, DATALOGGER_RUNNING, datalogger_set_Ts(), datalogger_status(), datalogger_update(), failure, IMU_PARAM_STRUCT::i2c_dev, read_all_data(), reset_timer(), SPI_PARAM_STRUCT::spi_dev, SUCCESS, t0, T_task_1_exec_global, t_task_1_global, T_task_2_exec_global, task_1_period_us, total, and MRA_DATA_STRUCT::v_ctl.

Referenced by timer_function_task_1().

191 {
192  //static int previous_calibration_status = CALIBRATION_NOT_RUNNING;
193  //int current_calibration_status; // Used to detect lowering edge
194  static int previous_datalogger_status = DATALOGGER_NOT_RUNNING;
195  int current_datalogger_status; // Used to detect rising edge
196  char user =0;
197  /* int buff_i=0; //i of buffer
198  int i, j, k, equal=0;
199  short int buff[3][3][3]; //{acc,gyr,mag}{x,y,z}{i=1,2,3}
200 */
201 
202  // Main communication/control thread
203 
204  //Acquire
205  total++;
207  failure++;
208 
209  // Calibrate and Estimate
211  //calibration_calibrate_all(&pwm_read_data, &scp1000_data, &battery_data, &gps_data, &imu_data, &pitot_data, &sonar_data, &calibration_local_coordinate_system_data, &calibration_altimeter_data, &calibration_local_fields_data, &gps_measure, &imu_measure, &magnetometer_measure);
212  //estimation_update_state_estimate(&estimation_data, &gps_measure, &imu_measure, &magnetometer_measure, &sonar_measure, &calibration_local_fields_data, task_1_period_us/(double)1e6);
213 
214  // Control
215  mra_data.v_ctl=1275+(uint8_t)(800*cosf(t_task_1_global*1000));
216  //control_main_task(t_task_1_global, &pwm_write_data, &pwm_read_data, &control_data, &estimation_data);
217 
218  // Actuate
220  //protocol_send_actuation_data(&pwm_write_data);
221 
222  // Log
223  /*user=getch();
224  switch(user){
225  case 'e':
226  exit_program();
227  break;
228  case 'a':
229  acquire=1;
230  break;
231  case 's':
232  acquire=0;
233  break;
234  default:
235  break;
236  }*/
237  current_datalogger_status = datalogger_status();
238  if( (current_datalogger_status == DATALOGGER_RUNNING))
239  {
240  if(previous_datalogger_status == DATALOGGER_NOT_RUNNING) // Rising edge
241  {
243  reset_timer();
244  }
245  datalogger_update(t_task_1_global, T_task_1_exec_global, T_task_2_exec_global, t0, &imu_data, &eff_data, &mra_data /*&imu_measure, &magnetometer_measure, &estimation_data, &control_data*/);
246  //printf("\n %d\t|",i);
247  /* printw("%d\t|",eff_data.F.x);
248  printw("\t%d\t%d\t%d\t|",imu_data.acc.x,imu_data.acc.y,imu_data.acc.z);
249  printw("\t%d\t%d\t%d\t|",imu_data.mag.x,imu_data.mag.y,imu_data.mag.z);
250  printw("\t%d\t%d\t%d\t%d",imu_data.gyr.x,imu_data.gyr.y,imu_data.gyr.z, imu_data.temp);
251  printw("\t%d\t%d",eff_data.new_data,imu_data.new_data);
252  printw("\t%d\t%d",mra_data.Out_0, mra_data.Read_0);
253  printw("\n");
254  refresh();*/
255  }
256  previous_datalogger_status = current_datalogger_status;
257 
258 /* current_calibration_status = calibration_get_status();
259  if(current_calibration_status == CALIBRATION_RUNNING)
260  {
261  calibration_imu_add_sample_bias_estimate(&imu_data);
262  calibration_altimeter_add_sample_initial_pressure(&scp1000_data, &calibration_altimeter_data);
263  }
264  else // Calibration not running
265  {
266  if(previous_calibration_status == CALIBRATION_RUNNING) // Lowering edge
267  {
268  calibration_imu_finish_bias_estimate(&imu_data);
269  calibration_altimeter_finish_initial_pressure_estimate(&calibration_altimeter_data);
270  }
271  }
272  previous_calibration_status = current_calibration_status;
273 */
274  return SUCCESS;
275 }
IMU_DATA_STRUCT imu_data
Definition: main2.c:74
void actuate(int spi_dev, MRA_DATA_STRUCT *mra_data)
Applies the control signal to the actuator.
int datalogger_set_Ts(double Ts)
Definition: datalogger.c:540
int reset_timer(void)
Definition: main2.c:539
#define DATALOGGER_RUNNING
Definition: datalogger.h:30
int total
Definition: main2.c:41
void calibrate_all(IMU_DATA_STRUCT *imu_data)
Calibrate all sensors.
Definition: calibration.c:8
volatile int task_1_period_us
Definition: main2.c:51
SPI_PARAM_STRUCT spi_param
Definition: main2.c:73
volatile double T_task_2_exec_global
Definition: main2.c:59
volatile double t_task_1_global
Definition: main2.c:46
int datalogger_update(double t_s, double t_control_exec_s, double t_ui_exec_s, double t0_s, IMU_DATA_STRUCT *pimu_data, EFF_DATA_STRUCT *peff_data, MRA_DATA_STRUCT *pmra_data)
Definition: datalogger.c:272
volatile double t0
Definition: main2.c:53
MRA_DATA_STRUCT mra_data
Definition: main2.c:76
int failure
Definition: main2.c:42
#define SUCCESS
Definition: calibration.h:6
#define DATALOGGER_NOT_RUNNING
Definition: datalogger.h:29
volatile double T_task_1_exec_global
Definition: main2.c:47
int read_all_data(int i2c_dev, int spi_dev, IMU_DATA_STRUCT *imu_data, EFF_DATA_STRUCT *eff_data, MRA_DATA_STRUCT *mra_data, ENC_DATA_STRUCT *enc_data)
READ ALL DATA FROM SENSORS AND ADC.
Definition: communication.c:94
ENC_DATA_STRUCT enc_data
Definition: main2.c:77
EFF_DATA_STRUCT eff_data
Definition: main2.c:75
IMU_PARAM_STRUCT imu_param
Definition: main2.c:72
short int v_ctl
Voltage level for control output.
int datalogger_status(void)
Definition: datalogger.c:571

Here is the call graph for this function:

Here is the caller graph for this function:

int periodic_task_2 ( void  )

Definition at line 277 of file main2.c.

References IMU_DATA_STRUCT::acc, buff, buff_i, devices_init(), failure, IMU_DATA_STRUCT::gyr, IMU_PARAM_STRUCT::i2c_dev, IMU_DATA_STRUCT::mag, SPI_PARAM_STRUCT::spi_dev, SUCCESS, telemetry_mode, total, UI_NCURSES_MODE, ui_update(), DATA_XYZ::x, DATA_XYZ::y, and DATA_XYZ::z.

Referenced by timer_function_task_2().

278 {
279 
280  int i, j, k, equal=0;
281 
282  // UI thread
284  {
286  }
287 
288  buff_i=buff_i%5;
289  buff[0][0][buff_i]=imu_data.acc.x;
290  buff[0][1][buff_i]=imu_data.acc.y;
291  buff[0][2][buff_i]=imu_data.acc.z;
292  buff[1][0][buff_i]=imu_data.gyr.x;
293  buff[1][0][buff_i]=imu_data.gyr.x;
294  buff[1][1][buff_i]=imu_data.gyr.y;
295  buff[1][2][buff_i]=imu_data.gyr.z;
296  buff[2][0][buff_i]=imu_data.mag.x;
297  buff[2][1][buff_i]=imu_data.mag.y;
298  buff[2][2][buff_i]=imu_data.mag.z;
299  buff_i++;
300 
301  for( i=0; i<3; i++)
302  {
303 
304  for( j=0; j<3; j++)
305  for( k=1; k<3; k++)
306  {
307  if( buff[i][j][k]==buff[i][j][0] )
308  equal=1;
309  else
310  equal=0;
311  }
312  if( equal==1)
313  i=3;
314  }
315  if( equal==1 )
316  {
317  close(imu_param.i2c_dev);
318  close(spi_param.spi_dev);
320  equal=0;
321  }
322  /*if(telemetry_mode == UI_MAVLINK_MODE)
323  {
324  mavlink_module_update(t_task_1_global, t0, &battery_data, &gps_data, &imu_data, &pitot_data, &pwm_read_data, &pwm_write_data, &scp1000_data, &sonar_data, &gps_measure, &imu_measure, &magnetometer_measure, &estimation_data, &control_data);
325  }*/
326 
327  return SUCCESS;
328 }
IMU_DATA_STRUCT imu_data
Definition: main2.c:74
int total
Definition: main2.c:41
short int y
Definition: communication.h:77
SPI_PARAM_STRUCT spi_param
Definition: main2.c:73
int buff_i
Definition: main2.c:67
DATA_XYZ mag
Magnetormeter Vector.
Definition: communication.h:96
short int buff[3][3][3]
Definition: main2.c:68
unsigned int telemetry_mode
Definition: main2.c:65
MRA_DATA_STRUCT mra_data
Definition: main2.c:76
DATA_XYZ acc
Accel Vector.
Definition: communication.h:94
int failure
Definition: main2.c:42
#define SUCCESS
Definition: calibration.h:6
int devices_init(IMU_PARAM_STRUCT *imu_param, SPI_PARAM_STRUCT *spi_param, MRA_DATA_STRUCT *mra_data)
INITIALIZATION OF SENSORS AND DEVICES.
Definition: communication.c:12
short int z
Definition: communication.h:78
#define UI_NCURSES_MODE
Definition: ui.h:5
ENC_DATA_STRUCT enc_data
Definition: main2.c:77
EFF_DATA_STRUCT eff_data
Definition: main2.c:75
DATA_XYZ gyr
Gyrometer Vector.
Definition: communication.h:95
int ui_update(IMU_DATA_STRUCT *pimu_data, EFF_DATA_STRUCT *peff_data, MRA_DATA_STRUCT *pmra_data, ENC_DATA_STRUCT *enc_data, int total, int failure)
Update Screen with new data of sensors.
Definition: ui.c:53
IMU_PARAM_STRUCT imu_param
Definition: main2.c:72
short int x
Definition: communication.h:76

Here is the call graph for this function:

Here is the caller graph for this function:

int reset_timer ( void  )

Definition at line 160 of file main.c.

References SUCCESS, t0, TASK_S::t_global, and t_task_1_global.

Referenced by control_task(), and periodic_task_1().

161 {
163  return SUCCESS;
164 }
int t0
Definition: main.c:40
TASK_S task_control
Definition: main.c:18
#define SUCCESS
Definition: calibration.h:6
volatile double t_global
Definition: taskScheduler.h:22

Here is the caller graph for this function:

void timer_function_task_1 ( void  )

Definition at line 426 of file main2.c.

References flag_task_1_firstexecution, periodic_task_1(), status, t0, T_task_1_exec_global, t_task_1_global, T_task_1_max_global, T_task_1_mean_global, and T_task_1_min_global.

Referenced by f_timer_task_1().

427 {
428  int status = 0;
429  static struct timeval timereset;
430  static struct timeval time;
431  static struct timeval time_exec_start;
432  static struct timeval time_exec_end;
433  static double T_task,t_task,t_task_previous;
434  static double T_task_mean,T_task_min,T_task_max,T_task_exec;
435 
436  gettimeofday(&time_exec_start, NULL);
437 
438  // Time calculation
440  {
441  gettimeofday(&timereset, NULL);
442  t_task = 0.0;
443  T_task_mean = 0.0;
444  T_task_min = 0.0;
445  T_task_max = 0.0;
446  T_task_exec = 0.0;
447  }
448 
449  gettimeofday(&time, NULL);
450  t_task = ((time.tv_sec - timereset.tv_sec) + (time.tv_usec - timereset.tv_usec)*1e-6);
451  T_task = t_task - t_task_previous;
452  t_task_previous = t_task;
453 
455  {
456  T_task_mean = T_task;
457  T_task_min = 1e200;
458  T_task_max = 0.0;
459  t0 = t_task;
460  }
461  else
462  {
463  T_task_mean = 0.05*T_task + 0.95*T_task_mean;
464  if(T_task < T_task_min) T_task_min = T_task;
465  if(T_task > T_task_max) T_task_max = T_task;
466  }
467 
468  // Run the thread
469  status = periodic_task_1();
470 
471  gettimeofday(&time_exec_end, NULL);
472  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);
473 
474  t_task_1_global = t_task;
475  T_task_1_mean_global = T_task_mean;
476  T_task_1_min_global = T_task_min;
477  T_task_1_max_global = T_task_max;
478  T_task_1_exec_global = T_task_exec;
479 
481 }
volatile double T_task_1_mean_global
Definition: main2.c:48
volatile int flag_task_1_firstexecution
Definition: main2.c:52
volatile double T_task_1_min_global
Definition: main2.c:49
volatile double t_task_1_global
Definition: main2.c:46
volatile double t0
Definition: main2.c:53
int status
Definition: communication.c:10
int periodic_task_1(void)
Definition: main2.c:190
volatile double T_task_1_exec_global
Definition: main2.c:47
volatile double T_task_1_max_global
Definition: main2.c:50

Here is the call graph for this function:

Here is the caller graph for this function:

void timer_function_task_2 ( void  )

Definition at line 483 of file main2.c.

References flag_task_2_firstexecution, periodic_task_2(), status, T_task_2_exec_global, t_task_2_global, T_task_2_max_global, T_task_2_mean_global, and T_task_2_min_global.

Referenced by f_timer_task_2().

484 {
485  int status = 0;
486  static struct timeval timereset;
487  static struct timeval time;
488  static struct timeval time_exec_start;
489  static struct timeval time_exec_end;
490  static double T_task,t_task,t_task_previous;
491  static double T_task_mean,T_task_min,T_task_max,T_task_exec;
492 
493  gettimeofday(&time_exec_start, NULL);
494 
495  // Time calculation
497  {
498  gettimeofday(&timereset, NULL);
499  t_task = 0.0;
500  T_task_mean = 0.0;
501  T_task_min = 0.0;
502  T_task_max = 0.0;
503  T_task_exec = 0.0;
504  }
505 
506  gettimeofday(&time, NULL);
507  t_task = ((time.tv_sec - timereset.tv_sec) + (time.tv_usec - timereset.tv_usec)*1e-6);
508  T_task = t_task - t_task_previous;
509  t_task_previous = t_task;
510 
512  {
513  T_task_mean = T_task;
514  T_task_min = 1e200;
515  T_task_max = 0.0;
516  }
517  else
518  {
519  T_task_mean = 0.05*T_task + 0.95*T_task_mean;
520  if(T_task < T_task_min) T_task_min = T_task;
521  if(T_task > T_task_max) T_task_max = T_task;
522  }
523 
524  // Run the thread
525  status = periodic_task_2();
526 
527  gettimeofday(&time_exec_end, NULL);
528  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);
529 
530  t_task_2_global = t_task;
531  T_task_2_mean_global = T_task_mean;
532  T_task_2_min_global = T_task_min;
533  T_task_2_max_global = T_task_max;
534  T_task_2_exec_global = T_task_exec;
535 
537 }
volatile int flag_task_2_firstexecution
Definition: main2.c:64
volatile double T_task_2_max_global
Definition: main2.c:62
volatile double t_task_2_global
Definition: main2.c:58
volatile double T_task_2_exec_global
Definition: main2.c:59
int periodic_task_2(void)
Definition: main2.c:277
int status
Definition: communication.c:10
volatile double T_task_2_mean_global
Definition: main2.c:60
volatile double T_task_2_min_global
Definition: main2.c:61

Here is the call graph for this function:

Here is the caller graph for this function:

void timer_start_task_1 ( void  )

Definition at line 342 of file main2.c.

References f_timer_task_1(), flag_task_1_firstexecution, task_1_period_us, and timer_task_1.

Referenced by main().

343 {
344  struct itimerspec itimer;
345  struct sigevent sigev;
346  int erno = 0;
347 
349 
350  itimer.it_interval.tv_sec=0;
351  itimer.it_interval.tv_nsec=task_1_period_us * 1000;
352  itimer.it_value=itimer.it_interval;
353 
354  memset(&sigev, 0, sizeof (struct sigevent));
355 
356  sigev.sigev_value.sival_int = 0;
357  sigev.sigev_notify = SIGEV_THREAD;
358  sigev.sigev_notify_attributes = NULL;
359  sigev.sigev_notify_function = f_timer_task_1;
360 
361  if (timer_create(CLOCK_REALTIME, &sigev, &timer_task_1) < 0)
362  {
363  fprintf(stderr, "[%d]: %s\n", __LINE__, strerror(erno));
364  exit(erno);
365  }
366 
367  if(timer_settime(timer_task_1, 0, &itimer, NULL) < 0)
368  {
369  fprintf(stderr, "[%d]: %s\n", __LINE__, strerror(erno));
370  exit(erno);
371  }
372 
373 }
volatile int flag_task_1_firstexecution
Definition: main2.c:52
volatile int task_1_period_us
Definition: main2.c:51
void f_timer_task_1(union sigval sigval)
Definition: main2.c:330
timer_t timer_task_1
Definition: main2.c:45

Here is the call graph for this function:

Here is the caller graph for this function:

void timer_start_task_2 ( void  )

Definition at line 375 of file main2.c.

References f_timer_task_2(), flag_task_2_firstexecution, task_2_period_us, and timer_task_2.

Referenced by main().

376 {
377  struct itimerspec itimer;
378  struct sigevent sigev;
379  int erno = 0;
380 
382 
383  itimer.it_interval.tv_sec=0;
384  itimer.it_interval.tv_nsec=task_2_period_us * 1000;
385  itimer.it_value=itimer.it_interval;
386 
387  memset (&sigev, 0, sizeof (struct sigevent));
388  sigev.sigev_value.sival_int = 0;
389  sigev.sigev_notify = SIGEV_THREAD;
390  sigev.sigev_notify_attributes = NULL;
391  sigev.sigev_notify_function = f_timer_task_2;
392 
393  if(timer_create(CLOCK_REALTIME, &sigev, &timer_task_2) < 0)
394  {
395  fprintf(stderr, "[%d]: %s\n", __LINE__, strerror(erno));
396  exit(erno);
397  }
398 
399  if(timer_settime(timer_task_2, 0, &itimer, NULL) < 0)
400  {
401  fprintf(stderr, "[%d]: %s\n", __LINE__, strerror(erno));
402  exit(erno);
403  }
404 }
volatile int flag_task_2_firstexecution
Definition: main2.c:64
timer_t timer_task_2
Definition: main2.c:57
void f_timer_task_2(union sigval sigval)
Definition: main2.c:336
volatile int task_2_period_us
Definition: main2.c:63

Here is the call graph for this function:

Here is the caller graph for this function:

void timer_stop_task_1 ( void  )

Definition at line 406 of file main2.c.

References timer_task_1.

Referenced by main().

407 {
408  int erno = 0;
409  if(timer_delete(timer_task_1) < 0)
410  {
411  fprintf(stderr, "[%d]: %s\n", __LINE__, strerror(erno));
412  exit(erno);
413  }
414 }
timer_t timer_task_1
Definition: main2.c:45

Here is the caller graph for this function:

void timer_stop_task_2 ( void  )

Definition at line 416 of file main2.c.

References timer_task_2.

Referenced by main().

417 {
418  int erno = 0;
419  if(timer_delete(timer_task_2) < 0)
420  {
421  fprintf(stderr, "[%d]: %s\n", __LINE__, strerror(erno));
422  exit(erno);
423  }
424 }
timer_t timer_task_2
Definition: main2.c:57

Here is the caller graph for this function: