Sorry to still bother on this. I got the binary semaphore working with following. Hopefully it is correctly done:
//Definitions
xSemaphoreHandle DisplayUpdate_sem;
xSemaphoreHandle ADC_sem;
// Create semaphores
vSemaphoreCreateBinary(DisplayUpdate_sem);
vSemaphoreCreateBinary(ADC_sem);
// Display update Task
void Start_Task_Display_Up(void *argument)
{
for(;;)
{
if (xSemaphoreTake(DisplayUpdate_sem, portMAX_DELAY))
{
// Do stuff
}
}
}
// ADC Read Task
void Start_Task_Read_ADC(void *argument)
{
for(;;)
{
if (xSemaphoreTake(ADC_sem, portMAX_DELAY))
{
// Do stuff
}
}
}
// Timer ISR
void HAL_TIM_PeriodElapsedCallback(TIM_HandleTypeDef *htim)
{
long task_woken = 0;
if (htim->Instance == TIM6) {
HAL_IncTick();
}
if (htim->Instance == TIM16) {
// 0,25 second timer
xSemaphoreGiveFromISR(DisplayUpdate_sem, &task_woken);
}
if (htim->Instance == TIM17) {
// 0,004 second timer
xSemaphoreGiveFromISR(ADC_sem, &task_woken);
}
portYIELD_FROM_ISR(task_woken);
}
However I got tempted to try the notify task as it is said in documentation that it is not that heavy than Semaphore. However I didn’t get it to work, it just blocked whole MCU. I assume create somehow the notify task, but I didn’t understand how it’s done. I’m not sure either whether it is suitable for two different tasks and different times like this Semaphore is. Anyhow, here is the ripped code:
#include "task.h"
static TaskHandle_t xHandlingTask;
// Display update Task
void Start_Task_Display_Up(void *argument)
{
for(;;)
{
xTaskNotifyTake(pdFALSE,portMAX_DELAY);
// Do something
}
}
// Timer interrupt handler
void HAL_TIM_PeriodElapsedCallback(TIM_HandleTypeDef *htim)
{
if (htim->Instance == TIM17) {
// 0,004 second timer
xHigherPriorityTaskWoken = pdFALSE;
vTaskNotifyGiveFromISR(xHandlingTask, &xHigherPriorityTaskWoken);
portYIELD_FROM_ISR(xHigherPriorityTaskWoken);
}
}
What am I missing?