Here is my problem:
I'm using FreeRTOS with the Cortex-M3 MCU. I have an ISR called EXTI15_10, which is trigger during a rising edge on the pins EXTI_Line10, EXTI_Line11..etc. Within the ISR I set the variable "status" to some specified value and before leaving the ISR I put the variable status in a queue and send it to my thread. That works fine.
The thread is periodically called and calls the function
xQueuePeek()
to get the item from the queue. Note xQueuePeek()
gets the item from the queue without removing it from the queue.
This works fine too, but I only receive the correct value once.
That means, the interrupt is generated, status is set to a value and put in the
queue, threads reads the correct value. But all the next interrupts
set status correctly(I checked it before putting the item in the queue), but my
thread reads always the old value. Do I have here a problem with compiler
optimization and volatile? xQueueSendFromISR()
, expects as second argument
a const void * and not volatile void *. What I'm doing wrong here?
The ISR:
void EXTI15_10_IRQHandler()
{
portBASE_TYPE xHigherPriorityTaskWoken = pdFALSE;
int status;
if (EXTI_GetITStatus(EXTI_Line10))
status = 100;
else if (EXTI_GetITStatus(EXTI_Line11))
status = 200
else if (EXTI_GetITStatus(EXTI_Line12))
status = 300;
else if (EXTI_GetITStatus(EXTI_Line13))
status = 400;
else if (EXTI_GetITStatus(EXTI_Line14))
status = 500;
else if (EXTI_GetITStatus(EXTI_Line15))
status = 600;
// Clear the pending interrupt bits
EXTI_ClearITPendingBit(EXTI_Lines15_10);
xQueueSendFromISR(queue, &status, &xHigherPriorityTaskWoken);
portEND_SWITCHING_ISR(xHigherPriorityTaskWoken);
}
The thread:
static void thread_xy()
{
portTickType xLastExecutionTime;
xLastExecutionTime = xTaskGetTickCount();
int status_from_queue = 0;
for (;;) {
xLastExecutionTime = xTaskGetTickCount();
vTaskDelayUntil(&xLastExecutionTime, CHECK_AND_ENABLE_LEDS_DELAY);
if (queue != 0) {
if (xQueuePeek(queue, &status_from_queue, portMAX_DELAY))
// Received item from queue...
print("Status from queue = %d\n", status_from_queue);
}
}
}