FreeRTOS Support Archive
The FreeRTOS support forum is used to obtain active support directly from Real
Time Engineers Ltd. In return for using our top quality software and services for
free, we request you play fair and do your bit to help others too! Sign up
to receive notifications of new support topics then help where you can.
This is a read only archive of threads posted to the FreeRTOS support forum.
The archive is updated every week, so will not always contain the very latest posts.
Use these archive pages to search previous posts. Use the Live FreeRTOS Forum
link to reply to a post, or start a new support thread.
[FreeRTOS Home] [Live FreeRTOS Forum] [FAQ] [Archive Top] [August 2015 Threads]
I made an error as I was taking a mutex from one task and giving it back in another task. This is not the correct way to signal tasks, so I replaced the mutex with a binary sempaphore:
for(;;)
{
//wait forever for a message. This updates the global variable "device"
xQueueReceive(calibrationQueue, &calDev, portMAX_DELAY);
//wait forever for the resource
xSemaphoreTake(calibrationSmphr, portMAX_DELAY);
//now update the public device
memcpy(&calibrateDevice, calDev, sizeof(_calibration_type_t));
//call the calibrate task
xEventGroupSetBits(xCalibrationGroup, calibrateDevice.calType);
}
The problem is the xSempahoreTake never returns on the first call to the function, so my system never gets started. Basically this task queues requests and waits for the semaphore to be available, before setting another event. When the calibration event is complete it gives back the semaphore. What am I doing wrong? I checked the semaphore has been properly allocated from CreateBinarySemaphore. When I substiture the mutex rather than binary semaphore, everything works.
Which function are you using to create the semaphore? If you are using xSemaphoreCreateMutex() (which is the correct function to use in newer versions of FreeRTOS), then the semaphore is created empty. Whereas if you create a mutex, then the mutrex is created full. Hence the difference in the behaviour you observed.
If you want the semaphore to be available the first time you call the function, then give the semaphore immediately after you have created it. Then, inside the function where it is used, the first 'take' operation will pass.
See the comments in the source code example at the bottom of the following page:
http://www.freertos.org/xSemaphoreCreateBinary.html
Regards.
Thanks, I missed the part about giving before using the semaphore...!
Tx
Copyright (C) Amazon Web Services, Inc. or its affiliates. All rights reserved.