FreeRTOS two queues for accessing one variable.
Posted: Wed Oct 20, 2021 9:20 am
Hello. I am new in FreeRTOS and would like to clarify whether my it is correct to use the Queue in the method described above:
I have 2 methods in my program:
As you can see from the 2 functions above, one fuction is used for setting the required bits by performing some bit operation, and another function is used for clearing certain bit
And I have my Alarm_manager_task :
As you can see from my alarm_manager task, it is waiting on 2 queues. One queue is for setting an alarm bits , and the other queue is for clearing the alarm bits.
I could not figure out a way to handle everything in a single queue hence I have came up with this solution. I would like to get some assistance from someone who know more about FreeRTOS than myself.
The variable ALARMS is very important because it will be accessed from other tasks in my programs.
I have 2 methods in my program:
Code: Select all
QueueHandle_t alarm_set_queue;
QueueHandle_t alarm_clear_queue;
alarm_set_queue = xQueueCreate(5, sizeof(uint8_t));
alarm_clear_queue = xQueueCreate(5, sizeof(uint8_t));
void set_alarm(uint8_t alarm){
printf("Setting alarm\n");
uint8_t DataToSend = alarm;
if (xQueueSend(alarm_set_queue, (void *)&DataToSend, 10) != pdTRUE)
{
printf("ERROR: Could not put item on delay queue.");
}
}
void clear_alarm(uint8_t alarm){
printf("Clearing alarm\n");
uint8_t DataToSend = alarm;
if (xQueueSend(alarm_clear_queue, (void *)&DataToSend, 10) != pdTRUE)
{
printf("ERROR: Could not put item on delay queue.");
}
}
And I have my Alarm_manager_task :
Code: Select all
static void alarm_handler(void* param){
printf("ALARM handling task \n");
static int active_alarm_number = 0;
uint8_t Data_to_receive;
while(1)
{
if (xQueueReceive(alarm_set_queue, (void *)&Data_to_receive, 0) == pdTRUE) {
printf("data received to set = %u \n",Data_to_receive);
ALARMS = ALARMS | (1<<Data_to_receive);
active_alarm_number++;
}
if (xQueueReceive(alarm_clear_queue, (void *)&Data_to_receive, 0) == pdTRUE) {
printf("data received to clear = %u \n",Data_to_receive);
ALARMS = ALARMS & ~(1<<Data_to_receive);
active_alarm_number--;
}
}
vTaskDelay(1000/portTICK_RATE_MS);
}
}
I could not figure out a way to handle everything in a single queue hence I have came up with this solution. I would like to get some assistance from someone who know more about FreeRTOS than myself.
The variable ALARMS is very important because it will be accessed from other tasks in my programs.