If it is only between two tasks then you can also use a direct to task notification.
Hi Murilo,
not sure what you mean with 'manage 2 tasks' with a semaphore?
Have a look at the API and examples here: FreeRTOS semaphore and mutex API functions vSemaphoreCreateBinary, xSemaphoreCreateCounting, xSemaph...
Other then that: semaphore are used more synchronization, and you can use it either for message passing or for locking/unlocking.
I have here an example of using semaphores for task execution control:
tatic void vSlaveTask(void *pvParameters) {
xSemaphoreHandle sem;
sem = (xSemaphoreHandle)pvParameters;
for(;;) {
if (sem != NULL) {
if (xSemaphoreTake(sem, portMAX_DELAY)==pdTRUE) {
LED1_Neg();
}
}
}
}
static void vMasterTask(void *pvParameters) {
/*! \todo Implement functionality */
xSemaphoreHandle sem = NULL;
(void)pvParameters; /* parameter not used */
sem = xSemaphoreCreateBinary();
if (sem==NULL) { /* semaphore creation failed */
for(;;){} /* error */
}
vQueueAddToRegistry(sem, "IPC_Sem");
/* create slave task */
if (xTaskCreate(vSlaveTask, "Slave", configMINIMAL_STACK_SIZE, sem, tskIDLE_PRIORITY+1, NULL) != pdPASS) {
for(;;){} /* error */
}
for(;;) {
if (sem != NULL) { /* valid semaphore? */
(void)xSemaphoreGive(sem); /* give control to other task */
vTaskDelay(1000/portTICK_PERIOD_MS);
}
}
}
I hope this helps,
Erich !