mathias3 wrote on Friday, July 10, 2009:
Hi,
In my application I have several tasks which need to share data. So far I have just defined some global variables (e.g. byte, word or long size variables and structures) without considering about MUTEX. In the different C files I have referenced the variables with the key word external.
Since I know that this is no proper way for a multitasking system I would like to clean up my design. The resources should be accessed exclusively. Of course I would like to avoid priority inversion or dead locks. Do you think it could be a possible solution to write "setter" and "getter" functions for each resource? Example:
static xSemaphoreHandle xMyTaskMutex = xSemaphoreCreateMutex();
static unsigned long ulMyTaskSharedLong = 0;
void ulMyTaskSetSharedLong(unsigned long param) {
xSemaphoreTake(xMyTaskMutex, portMAX_DELAY) {
ulMyTaskSharedLong = param;
}
xSemaphoreGive(xMyTaskMutex);
}
unsigned long ulMyTaskGetSharedLong() {
return ulMyTaskSharedLong;
}
Do you think this could work? Any better (simpler, saver) solutions? Thanks!
Regards, M.