2016-11-19 02:50 PM
Hey guys,
I'm having some problems with mutexes. I'd like to take a mutex but could never obtain it. Not even directly at startup. my function looks like this
USB_ERROR_LIST create_usb_write_request(USB_TOTAL_PACKET_T data)
{
if
(mutex_send_queue != NULL)
{
BaseType_t mutex_received = xSemaphoreTake(mutex_send_queue, timeout);
if
(mutex_received == pdTRUE)
{
//Mutex received.... do stuff
//return mutex
xSemaphoreGive(mutex_send_queue);
}
else
{
usb_error = USB_ERROR_MUTEX_NOT_RECEIVED;
}
else
{
usb_error = USB_ERROR_MUTEX_NULL;
}
The return value is always Mutex not received.
Now I've checked the usual suspects.
The Mutex is requested only in this function. I did set a breakpoint after
xSemaphoreTake() but this function always returns 0. I even tried to increase the timeout to 2s but no change.
It seams the is something wrong with my mutex.
The mutex is initialised in another thread with
void
USB_init_task(
void
* pvParameters)
{
mutex_send_queue = xSemaphoreCreateBinary();
for
(;;)
{
//all init done, we can go to sleep....
vTaskSuspend(NULL);
}
}
This is the correct way to initialise a mutex right?
2016-11-21 02:03 PM