FreeRTOS (interrupt management)

1. Interrupt definition

An interrupt is an event in a computer system that interrupts the normal program execution flow and causes the processor (CPU) to temporarily transfer to other tasks or handle special events. Interrupts are usually generated by hardware devices or operating systems to deliver urgent or high-priority information to the processor.

2. Interrupt priority

In our operating system, interrupts also have priority, and we can also set its priority, but its priority is not from 0-15. By default, it is from 5-15, 0~4. The 5 interrupt priorities are not controlled by FreeRTOS (5 is determined by configMAX_SYSCALL_INTERRUPT_PRIORITY).

Related Notes

1. Interrupt-related functions must be used in interrupts;

2. The shorter the interrupt service function running time, the better.

3. Experimental operation

Experimental requirements

Create a queue and a task, press the key KEY1 to trigger an interrupt, send data to the queue in the interrupt service function, and the task blocks receiving queue data.

cubeMX configuration

 Code

stm32f1xx_it.c

#include "cmsis_os.h"
extern osMessageQId myQueue01Handle;
void HAL_GPIO_EXTI_Callback(uint16_t GPIO_Pin)
{
uint32_t snd = 1;
xQueueSendFromISR(myQueue01Handle, &snd, NULL);
}

freertos.c

void StartDefaultTask(void const * argument)
{
/* USER CODE BEGIN StartDefaultTask */
uint32_t rev = 0;
/* Infinite loop */
for(;;)
{
    if (xQueueReceive(myQueue01Handle, &rev, portMAX_DELAY) == pdTRUE)
    printf("rev = %d\r\n", rev);
    osDelay(1);
}
/* USER CODE END StartDefaultTask */
}

 

 

Guess you like

Origin blog.csdn.net/m0_70987863/article/details/131928092