Definition des threads, des mutex, semaphores et messagequeue

This commit is contained in:
Nabil Moukhlis 2021-03-15 10:20:40 +01:00
parent cdf4ce64e9
commit f76171f0b3
2 changed files with 29 additions and 3 deletions

View file

@ -28,6 +28,8 @@
#define PRIORITY_TCAMERA 21
#define PRIORITY_TBATTERY 31
/*
* Some remarks:
* 1- This program is mostly a template. It shows you how to create tasks, semaphore
@ -137,8 +139,21 @@ void Tasks::Init() {
cerr << "Error msg queue create: " << strerror(-err) << endl << flush;
exit(EXIT_FAILURE);
}
cout << "Queues created successfully" << endl << flush;
if ((err = rt_queue_create(&q_messageComRobot, "q_messageComRobot", sizeof (Message*)*50, Q_UNLIMITED, Q_FIFO)) < 0) {
cerr << "Error messageComRobot queue create: " << strerror(-err) << endl << flush;
exit(EXIT_FAILURE);
}
if ((err = rt_queue_create(&q_messageControlRobot, "q_messageControlRobot", sizeof (Message*)*50, Q_UNLIMITED, Q_FIFO)) < 0) {
cerr << "Error messageControlRobot queue create: " << strerror(-err) << endl << flush;
exit(EXIT_FAILURE);
}
if ((err = rt_queue_create(&q_messageControlCam, "q_messageControlCam", sizeof (Message*)*50, Q_UNLIMITED, Q_FIFO)) < 0) {
cerr << "Error messageControlCam queue create: " << strerror(-err) << endl << flush;
exit(EXIT_FAILURE);
}
cout << "Queues created successfully" << endl << flush;
}
/**
@ -455,7 +470,6 @@ void Tasks::ReadBattery(void *arg){
monitor.Write(msg);
rt_mutex_release(&mutex_monitor);
}
}
cout << endl << flush;

View file

@ -77,6 +77,9 @@ private:
RT_TASK th_startRobot;
RT_TASK th_move;
RT_TASK th_getBattery;
RT_TASK th_watchDog;
RT_TASK th_controlCamera;
RT_TASK th_picture;
/**********************************************************************/
/* Mutex */
@ -86,6 +89,9 @@ private:
RT_MUTEX mutex_robotStarted;
RT_MUTEX mutex_move;
RT_MUTEX mutex_camera;
RT_MUTEX mutex_controlStruct;
/**********************************************************************/
/* Semaphores */
/**********************************************************************/
@ -94,12 +100,18 @@ private:
RT_SEM sem_serverOk;
RT_SEM sem_startRobot;
/**********************************************************************/
/* Message queues */
/**********************************************************************/
int MSG_QUEUE_SIZE;
RT_QUEUE q_messageToMon;
RT_QUEUE q_messageComRobot;
RT_QUEUE q_messageControlRobot;
RT_QUEUE q_messageControlCam;
/**********************************************************************/
/* Tasks' functions */
/**********************************************************************/