当前位置:网站首页>[FreeRTOS interrupt experiment]
[FreeRTOS interrupt experiment]
2022-07-06 04:36:00 【Struggling little Yin】
FreeRTOS- Interrupt the experiment
This experiment simply verifies the priority problem
Timer 3 And timers 4 Priority is configured separately 4 and 5 Lower in priority 5 When FreeRTOS Interrupts cannot be masked and are greater than or equal to 5 Priority of will be masked

FreeRTOS The switch interrupt function is portENABLE_INTERRUPTS () and portDISABLE_INTERRUPTS(), These two functions are actually macro definitions , stay portmacro.h There are definitions. ,
#define portDISABLE_INTERRUPTS() vPortRaiseBASEPRI() // Turn off interrupt
#define portENABLE_INTERRUPTS() vPortSetBASEPRI(0) // Open interrupt
time.h
#ifndef _TIME_H_
#define _TIME_H_
#include "stm32f10x.h"
void Init_TIM3(void);
void Init_TIM4(void);
#endif
timc.c
#include "time.h"
#include "usart.h"
void Init_TIM3(void)
{
TIM_TimeBaseInitTypeDef TIME3_InitStructure;
NVIC_InitTypeDef TIM3_NVICStructure;
RCC_APB1PeriphClockCmd(RCC_APB1Periph_TIM3,ENABLE);
TIME3_InitStructure.TIM_ClockDivision = TIM_CKD_DIV1;
TIME3_InitStructure.TIM_CounterMode = TIM_CounterMode_Up;
TIME3_InitStructure.TIM_Period = 10000 - 1;
TIME3_InitStructure.TIM_Prescaler = 3600 - 1;
TIM_TimeBaseInit(TIM3,&TIME3_InitStructure);
TIM_ITConfig(TIM3,TIM_IT_Update,ENABLE);
TIM3_NVICStructure.NVIC_IRQChannel = TIM3_IRQn;
TIM3_NVICStructure.NVIC_IRQChannelCmd = ENABLE;
TIM3_NVICStructure.NVIC_IRQChannelPreemptionPriority = 4;
TIM3_NVICStructure.NVIC_IRQChannelSubPriority = 0;
NVIC_Init(&TIM3_NVICStructure);
TIM_Cmd(TIM3,ENABLE);
}
void Init_TIM4(void)
{
TIM_TimeBaseInitTypeDef TIME4_InitStructure;
NVIC_InitTypeDef TIM4_NVICStructure;
RCC_APB1PeriphClockCmd(RCC_APB1Periph_TIM4,ENABLE);
TIME4_InitStructure.TIM_ClockDivision = TIM_CKD_DIV1;
TIME4_InitStructure.TIM_CounterMode = TIM_CounterMode_Up;
TIME4_InitStructure.TIM_Period = 10000 - 1;
TIME4_InitStructure.TIM_Prescaler = 3600 - 1;
TIM_TimeBaseInit(TIM4,&TIME4_InitStructure);
TIM_ITConfig(TIM4,TIM_IT_Update,ENABLE);
TIM4_NVICStructure.NVIC_IRQChannel = TIM4_IRQn;
TIM4_NVICStructure.NVIC_IRQChannelCmd = ENABLE;
TIM4_NVICStructure.NVIC_IRQChannelPreemptionPriority = 5;
TIM4_NVICStructure.NVIC_IRQChannelSubPriority = 0;
NVIC_Init(&TIM4_NVICStructure);
TIM_Cmd(TIM4,ENABLE);
}
void TIM3_IRQHandler(void)
{
if(TIM_GetITStatus(TIM3,TIM_IT_Update) != RESET)
{
printf("time3 interrupt\r\n");
}
TIM_ClearITPendingBit(TIM3,TIM_IT_Update);
}
void TIM4_IRQHandler(void)
{
if(TIM_GetITStatus(TIM4,TIM_IT_Update) != RESET)
{
printf("time4 interrupt\r\n");
}
TIM_ClearITPendingBit(TIM4,TIM_IT_Update);
}
main.c
#include "sys.h"
#include "delay.h"
#include "usart.h"
#include "led.h"
#include "FreeRTOS.h"
#include "task.h"
#include "time.h"
/*-------------------------------------------------------------------- *FreeRTOS Interrupt the experiment *Date:2022-2-13 *Author: Xiao Yin *--------------------------------------------------------------------*/
// Task priority
#define START_TASK_PRIO 1
// Task stack size
#define START_STK_SIZE 128
// Task to handle
TaskHandle_t StartTask_Handler;
// Task function
void start_task(void *pvParameters);
// Task priority
#define INTERRUPT_TASK_PRIO 2
// Task stack size
#define INTERRUPT_STK_SIZE 50
// Task to handle
TaskHandle_t INTERRUPTTask_Handler;
// Task function
void interrupt_task(void *pvParameters);
int main(void)
{
NVIC_PriorityGroupConfig(NVIC_PriorityGroup_4);// Set system interrupt priority group 4
delay_init(); // Delay function initialization
uart_init(115200); // Initialize serial port
LED_Init(); // initialization LED
Init_TIM3();
Init_TIM4();
// Create start task
xTaskCreate((TaskFunction_t )start_task, // Task function
(const char* )"start_task", // The name of the task
(uint16_t )START_STK_SIZE, // Task stack size
(void* )NULL, // Parameters passed to the task function
(UBaseType_t )START_TASK_PRIO, // Task priority
(TaskHandle_t* )&StartTask_Handler); // Task to handle
vTaskStartScheduler(); // Turn on task scheduling
}
// Start task task function
void start_task(void *pvParameters)
{
taskENTER_CRITICAL(); // Enter the critical area
// establish LED0 Mission
xTaskCreate((TaskFunction_t )interrupt_task,
(const char* )"interrupt_task",
(uint16_t )INTERRUPT_STK_SIZE,
(void* )NULL,
(UBaseType_t )INTERRUPT_TASK_PRIO,
(TaskHandle_t* )&INTERRUPTTask_Handler);
vTaskDelete(StartTask_Handler); // Delete start task
taskEXIT_CRITICAL(); // Exit critical region
}
//LED0 Task function
void interrupt_task(void *pvParameters)
{
char task_num = 0;
while(1)
{
task_num++;
// lower than 5 The interrupt priority of will not be masked TIM3 Interrupt priority configuration 4 The normal operation
if(task_num == 5)
{
printf(" Turn off interrupt \r\n");
portDISABLE_INTERRUPTS();
delay_xms(5000);
printf(" Open interrupt \r\n");
portENABLE_INTERRUPTS();
}
LED0 = ~LED0;
vTaskDelay(1000);
}
}

边栏推荐
- The implementation of the maize negotiable digital warehouse receipt standard will speed up the asset digitization process of the industry
- [Zhao Yuqiang] deploy kubernetes cluster with binary package
- How to estimate the population with samples? (mean, variance, standard deviation)
- Crawler notes: improve data collection efficiency! Use of proxy pool and thread pool
- CADD course learning (8) -- virtual screening of Compound Library
- 729. My schedule I (set or dynamic open point segment tree)
- word封面下划线
- Knowledge consolidation source code implementation 3: buffer ringbuffer
- MIT CMS. 300 session 8 – immersion / immersion
- One question per day (Mathematics)
猜你喜欢

Meet diverse needs: jetmade creates three one-stop development packages to help efficient development

Stable Huawei micro certification, stable Huawei cloud database service practice

Deep learning framework installation (tensorflow & pytorch & paddlepaddle)

Case of Jiecode empowerment: professional training, technical support, and multiple measures to promote graduates to build smart campus completion system

How to solve the problem of slow downloading from foreign NPM official servers—— Teach you two ways to switch to Taobao NPM image server

Basic use of MySQL (it is recommended to read and recite the content)

Certbot failed to update certificate solution

MLAPI系列 - 04 - 网络变量和网络序列化【网络同步】

CADD course learning (8) -- virtual screening of Compound Library

Dry goods collection | Vulkan game engine video tutorial
随机推荐
Lombok原理和同时使⽤@Data和@Builder 的坑
P2102 地砖铺设(dfs&贪心)
Certbot failed to update certificate solution
729. My schedule I (set or dynamic open point segment tree)
Platformio create libopencm3 + FreeRTOS project
Unity screen coordinates ugui coordinates world coordinates conversion between three coordinate systems
Mysql database storage engine
11. Intranet penetration and automatic refresh
Solutions: word coverage restoration, longest serial number, Xiaoyu buys stationery, Xiaoyu's electricity bill
How does computer nail adjust sound
Slow SQL fetching and analysis of MySQL database
Dry goods collection | Vulkan game engine video tutorial
MLAPI系列 - 04 - 网络变量和网络序列化【网络同步】
HotSpot VM
CADD课程学习(7)-- 模拟靶点和小分子相互作用 (柔性对接 AutoDock)
ue5 小知识 FreezeRendering 查看视锥内渲染的物体
How to estimate the population with samples? (mean, variance, standard deviation)
Yyds dry goods inventory OSI & tcp/ip
Lambda expression learning
Understanding of processes, threads, coroutines, synchronization, asynchrony, blocking, non blocking, concurrency, parallelism, and serialization