当前位置:网站首页>[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);
}
}

边栏推荐
- ETCD数据库源码分析——etcdserver bootstrap初始化存储
- Implementation of knowledge consolidation source code 1: epoll implementation of TCP server
- MySQL learning record 13 database connection pool, pooling technology, DBCP, c3p0
- 2/13 review Backpack + monotonic queue variant
- Complete list of common functions of turtle module
- 729. My schedule I (set or dynamic open point segment tree)
- Slow SQL fetching and analysis of MySQL database
- CADD course learning (8) -- virtual screening of Compound Library
- 也算是學習中的小總結
- P2022 interesting numbers (binary & digit DP)
猜你喜欢

Slow SQL fetching and analysis of MySQL database

Uva1592 Database

Overturn your cognition? The nature of get and post requests

食品行业仓储条码管理系统解决方案

Visio draws Tai Chi

Unity screen coordinates ugui coordinates world coordinates conversion between three coordinate systems

Easyrecovery reliable and toll free data recovery computer software

In depth MySQL transactions, stored procedures and triggers

8. Static file

Vulnerability discovery - vulnerability probe type utilization and repair of web applications
随机推荐
View 工作流程
Deep learning framework installation (tensorflow & pytorch & paddlepaddle)
MLAPI系列 - 04 - 网络变量和网络序列化【网络同步】
Crawler notes: improve data collection efficiency! Use of proxy pool and thread pool
SharedPreferences source code analysis
coreldraw2022新版本新功能介绍cdr2022
Ue5 small knowledge freezerendering view rendered objects in the cone
729. My schedule I (set or dynamic open point segment tree)
Canal synchronizes MySQL data changes to Kafka (CentOS deployment)
JVM garbage collector concept
Solve the compilation problem of "c2001: line breaks in constants"
HotSpot VM
Dry goods collection | Vulkan game engine video tutorial
2/13 review Backpack + monotonic queue variant
[05-1, 05-02, 05-03] network protocol
Understanding of processes, threads, coroutines, synchronization, asynchrony, blocking, non blocking, concurrency, parallelism, and serialization
Mysql database storage engine
题解:《单词覆盖还原》、《最长连号》、《小玉买文具》、《小玉家的电费》
拉格朗日插值法
[network] channel attention network and spatial attention network