2024-07-12
한어Русский языкEnglishFrançaisIndonesianSanskrit日本語DeutschPortuguêsΕλληνικάespañolItalianoSuomalainenLatina
Timer interrupt (judgment) Time parameter Key interrupt (modification)
DCD SysTick_Handler ; SysTick Handler
- void SysTick_Handler(void)
- {
-
- HAL_IncTick();//增加计数值,
-
- extern void check_timer(void);
- check_timer();
-
- }
- __weak void HAL_IncTick(void)
- {
- uwTick += uwTickFreq;
- }
-
- __weak uint32_t HAL_GetTick(void)
- {
- return uwTick;
- }
Pointer time and clock time
pTimer structureFunctions that contain time and count values
In the systemClock processing functionAdd a clock check function, and the if statement in check_timer limits the pointer time to be less than or equal to the clock time.
If interrupted,Interrupt callback functionLet your pointer time increase by 10ms,If another interruption occurs during this period, the pointer time will be increased by 10.
When no interrupt occurs or the interrupt is within (n*10) ms, the condition to enter the if function body in check_timer is not met;
Until there is no jitter, enter the if function body.Call the function in the structure through the timer function and check_timer function,makeCount valueIncrease
- struct soft_timer {
- uint32_t timeout;
- void * args;
- void (*func)(void *);
- };
-
- int g_key_cnt = 0;
-
- void key_timeout_func(void *args);
- struct soft_timer key_timer = {~0, NULL, key_timeout_func};
- void key_timeout_func(void *args)
- {
- g_key_cnt++;
- key_timer.timeout = ~0;
- }
-
- void mod_timer(struct soft_timer *pTimer, uint32_t timeout)
- {
- pTimer->timeout = HAL_GetTick() + timeout;
- }
-
- void check_timer(void)
- {
- if (key_timer.timeout <= HAL_GetTick())
- {
- key_timer.func(key_timer.args);
- }
- }
-
- 、、数据处理的源头,发生中断
- void HAL_GPIO_EXTI_Callback(uint16_t GPIO_Pin)
- {
- if (GPIO_Pin == GPIO_PIN_14)
- {
- mod_timer(&key_timer, 10);
- }
- }
- int main(){
- OLED_Init();
- OLED_Clear();
- OLED_PrintString(0, 4, "Key ISR cnt = ");
- while (1)
- {
- OLED_PrintSignedVal(0, 6, g_key_cnt);
-
- }
-
- }
DCD EXTI15_10_IRQHandler ; EXTI Line 15..10
- void EXTI15_10_IRQHandler(void)
- {
- /* USER CODE BEGIN EXTI15_10_IRQn 0 */
-
- /* USER CODE END EXTI15_10_IRQn 0 */
- HAL_GPIO_EXTI_IRQHandler(GPIO_PIN_14);
- /* USER CODE BEGIN EXTI15_10_IRQn 1 */
-
- /* USER CODE END EXTI15_10_IRQn 1 */
- }
The source of data processing, an interruption occurs
- void HAL_GPIO_EXTI_IRQHandler(uint16_t GPIO_Pin)
- {
- /* EXTI line interrupt detected */
- if (__HAL_GPIO_EXTI_GET_IT(GPIO_Pin) != 0x00u)
- {
- __HAL_GPIO_EXTI_CLEAR_IT(GPIO_Pin);
- HAL_GPIO_EXTI_Callback(GPIO_Pin);
- }
- }