cancel
Showing results for 
Search instead for 
Did you mean: 

Mutex never received

juliuscaesar
Associate III
Posted on November 19, 2016 at 23:50

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?
1 REPLY 1
Chris1
Senior III
Posted on November 21, 2016 at 23:03

Have you read your RTOS manual?  That should tell you the correct way to initialize a semaphore. 

It may say that a binary semaphore is initially in the ''empty'' state, and must be given before it can be taken. 

There may also be a different function and behavior for mutexes.