xSemaphoreHandle xMutexUseInputVal;
...
xMutexUseInputVal = xSemaphoreCreateMutex();
if (xMutexUseInputVal == NULL) {
printf("Error creating xMutexUseInputVal function: %s, line %d\n",
__FUNCTION__, __LINE__);
}
int GetUseInputVal(void) {
int localUseInputVal;
if (xMutexUseInputVal != NULL) {
/* See if we can obtain the semaphore.
* If the semaphore is not available wait 10 ticks to see
* if it becomes free.
*/
if (xSemaphoreTake( xMutexUseInputVal, ( portTickType ) 10 ) == pdTRUE) {
/* We were able to obtain the semaphore and can now
* access the shared resource.
*/
localUseInputVal = UseInputVal;
/* We have finished accessing the shared resource.
* Release the mutex.
*/
xSemaphoreGive( xMutexUseInputVal );
return (localUseInputVal);
} else {
/* We could not obtain the semaphore and can therefore
* not access the shared resource safely.
*/
printf("Error with xMutexUseInputVal function: %s, line %d\n",
__FUNCTION__, __LINE__);
/* we skip further error handling */
}
}
} /* GetUseInputVal */
void SetUseInputVal(int val) {
if (xMutexUseInputVal != NULL) {
/* See if we can obtain the semaphore.
* If the semaphore is not available wait 10 ticks to see
* if it becomes free.
*/
if (xSemaphoreTake( xMutexUseInputVal, ( portTickType ) 10 ) == pdTRUE) {
/* We were able to obtain the semaphore and can now
* access the shared resource.
*/
UseInputVal = val;
/* We have finished accessing the shared resource.
* Release the mutex.
*/
xSemaphoreGive( xMutexUseInputVal );
} else {
/* We could not obtain the semaphore and can therefore
* not access the shared resource safely.
*/
printf("Error with xMutexUseInputVal function: %s, line %d\n",
__FUNCTION__, __LINE__);
/* we skip further error handling */
}
}
} /* SetUseInputVal */
Comments