2023-05-10 06:15 PM
I'm using a mutex to share the I2C bus between an OLED display and an EEPROM. I'm using the IDE to generate the FreeRTOS configuration and tasks initialization (freertos.c file). I have an external file where all the LCD writing occurs. How could I access the mutexes handle generated on freertos.c file from this other file?
...
/* Private variables ---------------------------------------------------------*/
/* USER CODE BEGIN Variables */
/* USER CODE END Variables */
/* Definitions for defaultTask */
osThreadId_t defaultTaskHandle;
const osThreadAttr_t defaultTask_attributes = {
.name = "defaultTask",
.stack_size = 128 * 4,
.priority = (osPriority_t) osPriorityNormal,
};
/* Definitions for modbusTask */
osThreadId_t modbusTaskHandle;
const osThreadAttr_t modbusTask_attributes = {
.name = "modbusTask",
.stack_size = 64 * 4,
.priority = (osPriority_t) osPriorityNormal,
};
/* Definitions for dispTask */
osThreadId_t dispTaskHandle;
const osThreadAttr_t dispTask_attributes = {
.name = "dispTask",
.stack_size = 300 * 4,
.priority = (osPriority_t) osPriorityLow,
};
/* Definitions for taskButton */
osThreadId_t taskButtonHandle;
const osThreadAttr_t taskButton_attributes = {
.name = "taskButton",
.stack_size = 256 * 4,
.priority = (osPriority_t) osPriorityLow,
};
/* Definitions for i2cmutex */
osMutexId_t i2cmutexHandle;
const osMutexAttr_t i2cmutex_attributes = {
.name = "i2cmutex"
};
/* Private function prototypes -----------------------------------------------*/
/* USER CODE BEGIN FunctionPrototypes */
/* USER CODE END FunctionPrototypes */
void StartDefaultTask(void *argument);
void StartModbus(void *argument);
void StartDisp(void *argument);
void StartTaskButton(void *argument);
void MX_FREERTOS_Init(void); /* (MISRA C 2004 rule 8.1) */
/* Hook prototypes */
void configureTimerForRunTimeStats(void);
unsigned long getRunTimeCounterValue(void);
void vApplicationStackOverflowHook(xTaskHandle xTask, signed char *pcTaskName);
/* USER CODE BEGIN 1 */
/* Functions needed when configGENERATE_RUN_TIME_STATS is on */
__weak void configureTimerForRunTimeStats(void)
{
}
__weak unsigned long getRunTimeCounterValue(void)
{
return 0;
}
/* USER CODE END 1 */
/* USER CODE BEGIN 4 */
void vApplicationStackOverflowHook(xTaskHandle xTask, signed char *pcTaskName)
{
/* Run time stack overflow checking is performed if
configCHECK_FOR_STACK_OVERFLOW is defined to 1 or 2. This hook function is
called if a stack overflow is detected. */
}
/* USER CODE END 4 */
/**
* @brief FreeRTOS initialization
* @param None
* @retval None
*/
void MX_FREERTOS_Init(void) {
/* USER CODE BEGIN Init */
/* USER CODE END Init */
/* Create the mutex(es) */
/* creation of i2cmutex */
i2cmutexHandle = osMutexNew(&i2cmutex_attributes); // <- I WANT TO ACCESS THIS HANDLER FROM OUTSIDE THIS FILE
...
Solved! Go to Solution.
2023-05-10 11:50 PM
From your external file use the storage class extern:
extern osMutexId_t i2cmutexHandle;
2023-05-10 11:50 PM
From your external file use the storage class extern:
extern osMutexId_t i2cmutexHandle;