1、main.c
#include "stm32f10x.h" //使能uint8_t,uint16_t,uint32_t,uint64_t,int8_t,int16_t,int32_t,int64_t
#include "includes.h"
#include "USART1.h"
#include "delay.h"
#include "IWDG.h"
#include "My_Task_Priority.h"
#include "START_TASK.h"
const char CPU_Reset_REG[]="\r\nCPU reset!\r\n";
int main(void)
{
SystemInit(); //系统初始化72M
NVIC_PriorityGroupConfig(NVIC_PriorityGroup_4);
USART1_Serial_Interface_Enable(115200);
printf("%s",CPU_Reset_REG);//调试串口输出"\r\nCPU reset!\r\n"
SysRstSrcRecord();//系统复位记录
delay_init(); //延时函数初始化
OSInit();//初始化UCOS-II函数
OSTaskCreate(START_TASK,(void *)0,(OS_STK *)&START_TASK_STACK[START_TASK_STACK_SIZE-1],START_TASK_PRIORITY );//创建启动任务
OSStart();//启动操作系统,开始对任务进行调度管理
}
2、My_Task_Priority.c
#include "My_Task_Priority.h"
OS_STK START_TASK_STACK[START_TASK_STACK_SIZE]; //START_TASK任务堆栈
OS_STK TEST1_TASK_STACK[TEST1_TASK_STACK_SIZE]; //TEST1_TASK任务堆栈
OS_STK TEST2_TASK_STACK[TEST2_TASK_STACK_SIZE]; //TEST2_TASK任务堆栈
__align(8) OS_STK KEY_TASK_STACK[KEY_TASK_STACK_SIZE];
//KEY_TASK任务堆栈
//如果任务中使用printf来打印浮点数据的话一点要8字节对齐
__align(8) OS_STK CHECK_TASK_STACK[CHECK_TASK_STACK_SIZE];
//CHECK_TASK任务堆栈
//如果任务中使用printf来打印浮点数据的话一点要8字节对齐
3、My_Task_Priority.h
//My_Task_Priority.h
#ifndef __MY_TASK_PRIORITY_H
#define __MY_TASK_PRIORITY_H
#include "includes.h"
//任务的优先级资源由操作系统提供,以μC/OS-II为例,共有64个优先级,优先级的高低按编号从0(最高)到63(最低)排序;
/*
为了保证“启动任务”能够连续运行,必须将“启动任务”的优先级选择为最高。
否则,当“启动任务”创建一个优先级高于自己的任务时,刚刚创建的任务就
会立即进入运行状态,而与这个任务关联的其它任务可能还没有创建,它使
用的通信工具也还没有创建,系统必然出错。
*/
#define START_TASK_PRIORITY 4 //设置START_TASK任务优先级,开始任务的优先级设置为最高
#define START_TASK_STACK_SIZE 192 //设置START_TASK任务堆栈大小,为8的倍数
extern OS_STK START_TASK_STACK[START_TASK_STACK_SIZE]; //START_TASK任务堆栈
#define TEST1_TASK_PRIORITY 5 //设置TEST1_TASK任务优先级为5
#define TEST1_TASK_STACK_SIZE 88 //设置TEST1_TASK任务堆栈大小为88,为8的倍数
extern OS_STK TEST1_TASK_STACK[TEST1_TASK_STACK_SIZE]; //TEST1_TASK任务堆栈
#define TEST2_TASK_PRIORITY 6 //设置TEST2_TASK任务优先级为6
#define TEST2_TASK_STACK_SIZE 96 //设置TEST2_TASK任务堆栈大小为96,为8的倍数
extern OS_STK TEST2_TASK_STACK[TEST2_TASK_STACK_SIZE]; //TEST2_TASK任务堆栈
#define KEY_TASK_PRIORITY 7 //设置KEY_TASK任务优先级为7
#define KEY_TASK_STACK_SIZE 66 //设置KEY_TASK任务堆栈大小为66,为8的倍数
extern OS_STK KEY_TASK_STACK[KEY_TASK_STACK_SIZE]; //KEY_TASK任务堆栈
#define CHECK_TASK_PRIORITY 8 //设置CHECK_TASK任务优先级为8
#define CHECK_TASK_STACK_SIZE 128 //设置CHECK_TASK任务堆栈大小为128
extern OS_STK CHECK_TASK_STACK[CHECK_TASK_STACK_SIZE];//CHECK_TASK任务堆栈
#endif
4、START_TASK.c
#include "START_TASK.h"
#include "stdio.h" //getchar(),putchar(),scanf(),printf(),puts(),gets(),sprintf()
#include "LED.h"
#include "key.h"
#include "My_Task_Priority.h"
#include "TEST1_TASK.h"
#include "TEST2_TASK.h"
void START_TASK(void *pdata);
void CHECK_TASK(void *pdata);
const char START_TASK_rn_REG[]="\r\n";
const char START_TASK_Initialise_REG[]="START_TASK Initialise";
//START_TASK任务
void START_TASK(void *pdata)
{
OS_CPU_SR cpu_sr=0;
pdata = pdata;
printf("%s",START_TASK_rn_REG);
printf("%s",START_TASK_Initialise_REG);
LED0_Init();
LED1_Init();
KEY_Init();
//OSTaskCreate()建立一个新任务.可以在多任务环境启动之前.或者运行任务中建立任务;
//注意:ISR中禁止建立任务,一个任务必须为无限循环结构;\
//OS_TASK_STAT_STK_CHK_EN
OS_ENTER_CRITICAL(); //进入临界区(无法被中断打断),需要定义cpu_sr变量
OSTaskCreateExt( TEST1_TASK,/* 函数指针*/
(void *)0,/* 建立任务时,传递的参数*/
(OS_STK*)&TEST1_TASK_STACK[TEST1_TASK_STACK_SIZE-1],/* 指向堆栈任务栈顶的指针*/
TEST1_TASK_PRIORITY, /* 任务优先级*/
TEST1_TASK_PRIORITY,/* 任务ID,2.52版本,无实际作用,保留作为扩展用 */
(OS_STK*)&TEST1_TASK_STACK[0],/* 指向堆栈底部的指针,用于OSTaskStkChk()函数*/
TEST1_TASK_STACK_SIZE, /* 指定任务堆栈的大小,由OS_STK类型决定*/
(void *)0, /*定义数据结构的指针,作为TCB的扩展*/
(INT16U)(OS_TASK_OPT_STK_CLR | OS_TASK_OPT_STK_CHK)/*允许堆栈检查*/
);
OSTaskCreateExt( TEST2_TASK,/* 函数指针*/
(void *)0,/* 建立任务时,传递的参数*/
(OS_STK*)&TEST2_TASK_STACK[TEST2_TASK_STACK_SIZE-1],/* 指向堆栈任务栈顶的指针*/
TEST2_TASK_PRIORITY, /* 任务优先级*/
TEST2_TASK_PRIORITY,/* 任务ID,2.52版本,无实际作用,保留作为扩展用 */
(OS_STK*)&TEST2_TASK_STACK[0],/* 指向堆栈底部的指针,用于OSTaskStkChk()函数*/
TEST2_TASK_STACK_SIZE, /* 指定任务堆栈的大小,由OS_STK类型决定*/
(void *)0, /*定义数据结构的指针,作为TCB的扩展*/
(INT16U)(OS_TASK_OPT_STK_CLR | OS_TASK_OPT_STK_CHK)/*允许堆栈检查*/
);
OSTaskCreateExt( CHECK_TASK,/* 函数指针*/
(void*)0,/* 建立任务时,传递的参数*/
(OS_STK *)&CHECK_TASK_STACK[CHECK_TASK_STACK_SIZE-1],/* 指向堆栈任务栈顶的指针*/
(INT8U)CHECK_TASK_PRIORITY,/* 任务优先级*/
(INT16U)CHECK_TASK_PRIORITY,/* 任务ID,2.52版本,无实际作用,保留作为扩展用 */
(OS_STK *)&CHECK_TASK_STACK[0],/* 指向堆栈底部的指针,用于OSTaskStkChk()函数*/
(INT32U) CHECK_TASK_STACK_SIZE,/* 指定任务堆栈的大小,由OS_STK类型决定*/
(void*)0, /*定义数据结构的指针,作为TCB的扩展*/
(INT16U)(OS_TASK_OPT_STK_CLR | OS_TASK_OPT_STK_CHK)/*允许堆栈检查*/
);
// OSTaskCreate( CHECK_TASK,/* 函数指针*/
// (void*)0,/* 建立任务时,传递的参数*/
// (OS_STK *)&CHECK_TASK_STACK[CHECK_TASK_STACK_SIZE-1],/* 指向堆栈任务栈顶的指针*/
// (INT8U)CHECK_TASK_PRIORITY/* 任务优先级*/
// );
//OSTaskSuspend(START_TASK_PRIORITY); //挂起起始任务START_TASK()
OSTaskDel (OS_PRIO_SELF); //删除自己
OS_EXIT_CRITICAL(); //退出临界区(可以被中断打断)
}
const char CHECK_TASK_rn_REG[]="\r\n";
const char CHECK_TASK_Initialise_REG[]="CHECK_TASK Initialise";
const char TEST1_TASK_used_Or_free_REG[]="TEST1_TASK used/free:";
const char TEST2_TASK_used_Or_free_REG[]="TEST2_TASK used/free:";
const char KEY_TASK_used_Or_free_REG[]="KEY_TASK used/free:";
const char CHECK_TASK_used_Or_free_REG[]="CHECK_TASK used/free:";
const char Used_REG[]=" used%";
const char Err_REG[]=" err:";
void CHECK_TASK(void *pdata)
{
OS_STK_DATA pTaskStackData;
u8 err1 =0;//1079062528
(void)pdata;
printf("%s",CHECK_TASK_rn_REG);
printf("%s",CHECK_TASK_Initialise_REG);
while(1)
{
err1 = OSTaskStkChk( TEST1_TASK_PRIORITY, &pTaskStackData);
printf("%s",CHECK_TASK_rn_REG);
printf("%s",TEST1_TASK_used_Or_free_REG);printf("%d/",pTaskStackData.OSUsed);printf("%d",pTaskStackData.OSFree);
printf("%s",Used_REG);printf( "%0.2f",(float)(pTaskStackData.OSUsed*100)/(float)(pTaskStackData.OSUsed+pTaskStackData.OSFree) );
printf("%s",Err_REG);printf("%d",err1);
printf("%s",CHECK_TASK_rn_REG);
err1 = OSTaskStkChk( TEST2_TASK_PRIORITY, &pTaskStackData);
printf("%s",TEST2_TASK_used_Or_free_REG);printf("%d/",pTaskStackData.OSUsed);printf("%d",pTaskStackData.OSFree);
printf("%s",Used_REG);printf( "%0.2f",(float)(pTaskStackData.OSUsed*100)/(float)(pTaskStackData.OSUsed+pTaskStackData.OSFree) );
printf("%s",Err_REG);printf("%d",err1);
printf("%s",CHECK_TASK_rn_REG);
// err1 = OSTaskStkChk( KEY_TASK_PRIORITY, &pTaskStackData);
// printf("%s",KEY_TASK_used_Or_free_REG);printf("%d/",pTaskStackData.OSUsed);printf("%d",pTaskStackData.OSFree);
// printf("%s",Used_REG);printf( "%0.2f",(float)(pTaskStackData.OSUsed*100)/(float)(pTaskStackData.OSUsed+pTaskStackData.OSFree) );
// printf("%s",Err_REG);printf("%d",err1);
// printf("%s",CHECK_TASK_rn_REG);
err1 = OSTaskStkChk( CHECK_TASK_PRIORITY, &pTaskStackData);
printf("%s",CHECK_TASK_used_Or_free_REG);printf("%d/",pTaskStackData.OSUsed);printf("%d",pTaskStackData.OSFree);
printf("%s",Used_REG);printf( "%0.2f",(float)(pTaskStackData.OSUsed*100)/(float)(pTaskStackData.OSUsed+pTaskStackData.OSFree) );
printf("%s",Err_REG);printf("%d",err1);
printf("%s",CHECK_TASK_rn_REG);
OSTimeDlyHMSM(0,0,10,0);//10s
}
}
5、TEST1_TASK.c
#include "TEST1_TASK.h"
#include "stdio.h" //getchar(),putchar(),scanf(),printf(),puts(),gets(),sprintf()
void TEST1_TASK(void *pdata);
const char TEST1_TASK_rn_REG[]="\r\n";
const char TEST1_TASK_Initialise_REG[]="TEST1_TASK Initialise";
const char TEST1_TASK_REG[]="TEST1_TASK";
//TEST1_TASK任务
void TEST1_TASK(void *pdata)
{
(void)pdata;
printf("%s",TEST1_TASK_rn_REG);
printf("%s",TEST1_TASK_Initialise_REG);
while(1)
{
printf("%s",TEST1_TASK_rn_REG);
printf("%s",TEST1_TASK_REG);
OSTimeDlyHMSM(0,0,1,0);//延时1秒
}
}
6、TEST2_TASK.c
#include "TEST2_TASK.h"
#include "stdio.h" //getchar(),putchar(),scanf(),printf(),puts(),gets(),sprintf()
void TEST2_TASK(void *pdata);
const char TEST2_TASK_rn_REG[]="\r\n";
const char TEST2_TASK_Initialise_REG[]="TEST2_TASK Initialise";
const char TEST2_TASK_REG[]="TEST2_TASK";
//TEST2_TASK任务
void TEST2_TASK(void *pdata)
{
(void)pdata;
printf("%s",TEST2_TASK_rn_REG);
printf("%s",TEST2_TASK_Initialise_REG);
while(1)
{
printf("%s",TEST2_TASK_rn_REG);
printf("%s",TEST2_TASK_REG);
OSTimeDlyHMSM(0,0,2,0);//延时1秒
}
}
7、KEY.c
#include "KEY.h"
#include "delay.h"
#include "includes.h"
#include "LED.h"
void KEY_Init(void);
void KeyPin_Config(void)
{
GPIO_InitTypeDef GPIO_InitStructure;
//定义一个GPIO_InitTypeDef类型的结构变量为GPIO_InitStructure;
EXTI_InitTypeDef EXTI_InitStructure;
//定义一个EXTI_InitTypeDef类型的结构变量为EXTI_InitStructure;
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOB|RCC_APB2Periph_AFIO,ENABLE);
//使能GPIOB和AFIO的外设时钟;
GPIO_InitStructure.GPIO_Pin=GPIO_Pin_12|GPIO_Pin_13|GPIO_Pin_14|GPIO_Pin_15; //选择第12,13,14和15脚
GPIO_InitStructure.GPIO_Speed=GPIO_Speed_50MHz; //设置引脚的最高输出速率为50MHz
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IPU; //设置GPIO脚的工作模式为输入上拉;
GPIO_Init(GPIOB, &GPIO_InitStructure); //根据GPIO_InitStructure所指向的参数,初始化PB12~PE15
GPIO_EXTILineConfig(GPIO_PortSourceGPIOB,GPIO_PinSource12); //选择PB12脚用作外部中断的输入源
EXTI_InitStructure.EXTI_Line=EXTI_Line12; //选择外部中断线为12
EXTI_InitStructure.EXTI_Mode = EXTI_Mode_Interrupt; //配置外部中断模式为中断请求
EXTI_InitStructure.EXTI_Trigger = EXTI_Trigger_Falling; //配置外部中断触发为下降沿中断请求
EXTI_InitStructure.EXTI_LineCmd = ENABLE; //使能外部中断
EXTI_Init(&EXTI_InitStructure); //根据EXTI_InitStructure所指向的参数设置外设EXTI寄存器
GPIO_EXTILineConfig(GPIO_PortSourceGPIOB,GPIO_PinSource13); //选择PB13脚用作外部中断的输入源
EXTI_InitStructure.EXTI_Line=EXTI_Line13; //选择外部中断线为13
EXTI_InitStructure.EXTI_Mode = EXTI_Mode_Interrupt; //配置外部中断模式为中断请求
EXTI_InitStructure.EXTI_Trigger = EXTI_Trigger_Falling; //配置外部中断触发为下降沿中断请求
EXTI_InitStructure.EXTI_LineCmd = ENABLE; //使能外部中断
EXTI_Init(&EXTI_InitStructure); //根据EXTI_InitStructure所指向的参数设置外设EXTI寄存器
GPIO_EXTILineConfig(GPIO_PortSourceGPIOB,GPIO_PinSource14); //选择PB14脚用作外部中断的输入源
EXTI_InitStructure.EXTI_Line=EXTI_Line14; //选择外部中断线为14
EXTI_InitStructure.EXTI_Mode = EXTI_Mode_Interrupt; //配置外部中断模式为中断请求
EXTI_InitStructure.EXTI_Trigger = EXTI_Trigger_Falling; //配置外部中断触发为下降沿中断请求
EXTI_InitStructure.EXTI_LineCmd = ENABLE; //使能外部中断
EXTI_Init(&EXTI_InitStructure); //根据EXTI_InitStructure所指向的参数设置外设EXTI寄存器
GPIO_EXTILineConfig(GPIO_PortSourceGPIOB,GPIO_PinSource15); //选择PB15脚用作外部中断的输入源
EXTI_InitStructure.EXTI_Line=EXTI_Line15; //选择外部中断线为15
EXTI_InitStructure.EXTI_Mode = EXTI_Mode_Interrupt; //配置外部中断模式为中断请求
EXTI_InitStructure.EXTI_Trigger = EXTI_Trigger_Falling; //配置外部中断触发为下降沿中断请求
EXTI_InitStructure.EXTI_LineCmd = ENABLE; //使能外部中断
EXTI_Init(&EXTI_InitStructure); //根据EXTI_InitStructure所指向的参数设置外设EXTI寄存器
RCC_APB2PeriphClockCmd ( RCC_APB2Periph_GPIOD|RCC_APB2Periph_AFIO,ENABLE);
//使能GPIOD和AFIO的外设时钟;
GPIO_InitStructure.GPIO_Pin=GPIO_Pin_8; //选择第8脚
GPIO_InitStructure.GPIO_Speed=GPIO_Speed_50MHz; //设置引脚的最高输出速率为50MHz
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IPU; //设置GPIO脚的工作模式为输入上拉;
GPIO_Init( GPIOD, &GPIO_InitStructure);
//根据GPIO_InitStructure结构变量指定的参数初始化GPIOD的外设寄存器
GPIO_EXTILineConfig(GPIO_PortSourceGPIOD,GPIO_PinSource8); //选择PD8脚用作外部中断的输入源
EXTI_InitStructure.EXTI_Line=EXTI_Line8; //选择外部中断线为8
EXTI_InitStructure.EXTI_Mode = EXTI_Mode_Interrupt; //配置外部中断模式为中断请求
EXTI_InitStructure.EXTI_Trigger = EXTI_Trigger_Falling; //配置外部中断触发为下降沿中断请求
EXTI_InitStructure.EXTI_LineCmd = ENABLE; //使能外部中断
EXTI_Init(&EXTI_InitStructure); //根据EXTI_InitStructure所指向的参数设置外设EXTI寄存器
}
//函数功能:配置嵌套向量中断控制器NVIC
void KeyPin_NVIC_Configuration(void)
{
NVIC_InitTypeDef NVIC_InitStructure; //声明一个NVIC_InitTypeDef类型的结构变量NVIC_InitStructure;
//NVIC_PriorityGroup_4设置NVIC中断分组4:表示抢占优先级为4位,取值为0~15,没有响应优先级,取值为0
//NVIC_PriorityGroup_3设置NVIC中断分组3:表示抢占优先级为3位,取值为0~7,响应优先级只有1位,取值为0~1
//NVIC_PriorityGroup_2设置NVIC中断分组3:表示抢占优先级为2位,取值为0~3,响应优先级只有2位,取值为0~3
//NVIC_PriorityGroupConfig(NVIC_PriorityGroup_4);//设置系统中断优先级分组4
NVIC_InitStructure.NVIC_IRQChannel = EXTI9_5_IRQn; //设置中断通道为EXTI9_5_IRQn
NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 8; //设置抢占优先级为8
NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0; //设置响应优先级为0
NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE; //使能该中断通道中断
NVIC_Init(&NVIC_InitStructure); //使用NVIC_InitStructure所指向的参数初始化EXTI9_5_IRQn的中断通道
NVIC_InitStructure.NVIC_IRQChannel = EXTI15_10_IRQn; //设置中断通道为EXTI15_10_IRQn
NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 8; //设置抢占优先级为8
NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0; //设置响应优先级为0
NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE; //使能该中断通道中断
NVIC_Init(&NVIC_InitStructure); //使用NVIC_InitStructure所指向的参数初始化EXTI15_10_IRQn的中断通道
}
void KEY_Init(void)
{
KeyPin_Config();
KeyPin_NVIC_Configuration();
}
void EXTI9_5_IRQHandler(void)
{
OSIntEnter();//统计中断嵌套次数,通知UCOS进入中断
if(EXTI_GetITStatus(EXTI_Line8) != RESET)//右
{
LED1_OFF();
EXTI_ClearITPendingBit(EXTI_Line8); //清除EXTI8线路挂起位
}
OSIntExit();//统计中断嵌套次数,通知UCOS退出中断
}
void EXTI15_10_IRQHandler(void)
{
OSIntEnter();//统计中断嵌套次数,通知UCOS进入中断
if(EXTI_GetITStatus(EXTI_Line12) != RESET)
{
LED0=!LED0;
LED1=!LED1;
EXTI_ClearITPendingBit(EXTI_Line12); //清除EXTI12线路挂起位
}
if(EXTI_GetITStatus(EXTI_Line13) != RESET)//上
{
LED0_ON();
EXTI_ClearITPendingBit(EXTI_Line13); //清除EXTI13线路挂起位
}
if(EXTI_GetITStatus(EXTI_Line14) != RESET)
{
LED0_OFF();
EXTI_ClearITPendingBit(EXTI_Line14); //清除EXTI14线路挂起位
}
if(EXTI_GetITStatus(EXTI_Line15) != RESET)//左
{
LED1_ON();
EXTI_ClearITPendingBit(EXTI_Line15); //清除EXTI15线路挂起位
}
OSIntExit();//统计中断嵌套次数,通知UCOS退出中断
}
8、LED.c
#include "LED.h"
void LED0_Init(void)
{
GPIO_InitTypeDef GPIO_InitStructure;
//使用GPIO_InitTypeDef定义一个结构变量GPIO_InitStructure;
RCC_APB2PeriphClockCmd ( RCC_APB2Periph_GPIOE, ENABLE ); //在配置外设之前,必须先使能GPIOE的外设时钟
GPIO_InitStructure.GPIO_Pin=GPIO_Pin_4; //选择第4脚
GPIO_InitStructure.GPIO_Speed=GPIO_Speed_50MHz; //设置引脚的最高输出速率为50MHz
GPIO_InitStructure.GPIO_Mode=GPIO_Mode_Out_PP; //设置引脚工作模式为推挽输出方式
GPIO_Init( GPIOE, &GPIO_InitStructure); //根据GPIO_InitStructure结构变量指定的参数初始化GPIOE的外设寄存器
}
void LED1_Init(void)
{
GPIO_InitTypeDef GPIO_InitStructure;
//使用GPIO_InitTypeDef定义一个结构变量GPIO_InitStructure;
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOE, ENABLE); //使能GPIOE的外设时钟
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_5; //选择第5脚
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP; //设置引脚工作模式为推挽输出方式
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz; //设置引脚的最高输出速率为50MHz
GPIO_Init(GPIOE, &GPIO_InitStructure);
//根据GPIO_InitStructure结构变量指定的参数初始化GPIOE的外设寄存器
}
void LED_Init(void)
{
LED0_Init();
LED1_Init();
}
9、LED.h
#ifndef _LED_H
#define _LED_H
#include "stm32f10x.h"
#include "sys.h"
#define LED0 PEout(4) //PE4
#define LED1 PEout(5) //PE5
#define LED0_OFF() GPIO_SetBits(GPIOE,GPIO_Pin_4) //定义LED0关闭
#define LED0_ON() GPIO_ResetBits(GPIOE,GPIO_Pin_4) //定义LED0点亮
#define LED1_OFF() GPIO_SetBits(GPIOE,GPIO_Pin_5) //定义LED1关闭
#define LED1_ON() GPIO_ResetBits(GPIOE,GPIO_Pin_5) //定义LED1点亮
extern void LED0_Init(void);
extern void LED1_Init(void);
extern void LED_Init(void); /* LED 端口初始化 */
#endif
10、os_cfg.h
#ifndef OS_CFG_H
#define OS_CFG_H
/*
任务的优先级资源由操作系统提供,以μC/OS-II为例,共有64个优先级,优先级的高低按编号从0(最高)到63(最低)排序
*/
/* ---------------------- 混杂的配置MISCELLANEOUS ----------------------- */
#define OS_APP_HOOKS_EN 0u /* Application-defined hooks are called from the uC/OS-II hooks */
#define OS_ARG_CHK_EN 0u /* Enable (1) or Disable (0) argument checking */
#define OS_CPU_HOOKS_EN 1u /* uC/OS-II hooks are found in the processor port files */
#define OS_DEBUG_EN 0u /* Enable(1) debug variables */
#define OS_EVENT_MULTI_EN 0u /* Include code for OSEventPendMulti() */
#define OS_EVENT_NAME_EN 0u /* Enable names for Sem, Mutex, Mbox and Q */
#define OS_LOWEST_PRIO 63u /* Defines the lowest priority that can be assigned ... */
/* ... MUST NEVER be higher than 254! */
#define OS_MAX_EVENTS 10u /*应用中最多事件控制块的数目,Max. number of event control blocks in your application */
#define OS_MAX_FLAGS 5u /*应用中最多事件标志组的数目,Max. number of Event Flag Groups in your application */
#define OS_MAX_MEM_PART 0u /*最大的内存块数,Max. number of memory partitions */
#define OS_MAX_QS 4u /*最大的消息队列数,Max. number of queue control blocks in your application */
#define OS_MAX_TASKS 7u /*最多任务数,Max. number of tasks in your application, MUST be >= 2 */
#define OS_SCHED_LOCK_EN 1u /*使能OSSchedLock()和OSSchedUnlock(),Include code for OSSchedLock() and OSSchedUnlock() */
#define OS_TICK_STEP_EN 1u /* Enable tick stepping feature for uC/OS-View */
#define OS_TICKS_PER_SEC 200u /*设置每秒的节拍数目,Set the number of ticks in one second */
/* --------------------- 任务堆栈大小TASK STACK SIZE ---------------------- */
#define OS_TASK_TMR_STK_SIZE 128u /*计时器任务堆栈大小,Timer task stack size (# of OS_STK wide entries)*/
#define OS_TASK_STAT_STK_SIZE 128u /*统计任务堆栈大小,Statistics task stack size (# of OS_STK wide entries)*/
#define OS_TASK_IDLE_STK_SIZE 128u /*空闲任务堆栈大小,Idle task stack size (# of OS_STK wide entries)*/
/* --------------------- 任务管理TASK MANAGEMENT ---------------------- */
#define OS_TASK_CHANGE_PRIO_EN 1u /*使能"改变任务优先级函数"OSTaskChangePrio(),Include code for OSTaskChangePrio()*/
#define OS_TASK_CREATE_EN 1u /*使能"建立任务函数"OSTaskCreate(),Include code for OSTaskCreate()*/
#define OS_TASK_CREATE_EXT_EN 1u /*使能"建立扩展任务函数"OSTaskCreateExt(),Include code for OSTaskCreateExt()*/
#define OS_TASK_DEL_EN 1u /*使能"删除任务函数"OSTaskDel(),Include code for OSTaskDel()*/
#define OS_TASK_NAME_EN 1u /* Enable task names */
#define OS_TASK_PROFILE_EN 1u /* Include variables in OS_TCB for profiling */
#define OS_TASK_QUERY_EN 1u /*使能"通过调用OSTaskQuery()来获得自身或其它应用任务的信息",Include code for OSTaskQuery()*/
#define OS_TASK_REG_TBL_SIZE 1u /* Size of task variables array (#of INT32U entries) */
#define OS_TASK_STAT_EN 1u /*使能统计任务函数OSTaskStat(),统计任务每秒运行一次,计算当前系统CPU使用率,结果保存在8位变量OSCPUUsage中,Enable (1) or Disable(0) the statistics task*/
#define OS_TASK_STAT_STK_CHK_EN 1u /* Check task stacks from statistic task */
#define OS_TASK_SUSPEND_EN 1u /*使能挂起任务函数OSTaskSuspend()和恢复任务OSTaskResume(),Include code for OSTaskSuspend() and OSTaskResume()*/
#define OS_TASK_SW_HOOK_EN 1u /*使能"任务切换函数OSTaskSwHook()",Include code for OSTaskSwHook() */
/* -----------------------事件标志EVENT FLAGS ------------------------ */
#define OS_FLAG_EN 1u /* Enable (1) or Disable (0) code generation for EVENT FLAGS */
#define OS_FLAG_ACCEPT_EN 1u /*"使能检查事件标志组函数OSFlagAccept()",Include code for OSFlagAccept()*/
#define OS_FLAG_DEL_EN 1u /*"使能删除一个事件标志组函数OSFlagDel()",Include code for OSFlagDel()*/
#define OS_FLAG_NAME_EN 1u /* Enable names for event flag group */
#define OS_FLAG_QUERY_EN 1u /*"使能查询事件标志组的当前事件标志状态OSFlagQuery()",Include code for OSFlagQuery()*/
#define OS_FLAG_WAIT_CLR_EN 1u /* Include code for Wait on Clear EVENT FLAGS */
#define OS_FLAGS_NBITS 16u /* Size in #bits of OS_FLAGS data type (8, 16 or 32) */
/*消息邮箱-------------------- MESSAGE MAILBOXES --------------------- */
#define OS_MBOX_EN 1u /*使能消息邮箱,Enable (1) or Disable (0) code generation for MAILBOXES */
#define OS_MBOX_ACCEPT_EN 1u /*使能"无等待地从邮箱中得到一个消息函数OSMboxAccept()",Include code for OSMboxAccept()*/
#define OS_MBOX_DEL_EN 1u /*使能"删除消息邮箱函数OSMboxDel()"Include code for OSMboxDel()*/
#define OS_MBOX_PEND_ABORT_EN 1u /* Include code for OSMboxPendAbort() */
#define OS_MBOX_POST_EN 1u /*使能"发送一个消息到邮箱中函数OSMboxPost()",Include code for OSMboxPost()*/
#define OS_MBOX_POST_OPT_EN 1u /*使能"依据条件,向邮箱发送一则消息OSMboxPostOpt()",Include code for OSMboxPostOpt()*/
#define OS_MBOX_QUERY_EN 1u /*使能"查询一个邮箱的状态OSMboxQuery()",Include code for OSMboxQuery() */
/* ---------------------内存管理MEMORY MANAGEMENT -------------------- */
#define OS_MEM_EN 1u /*使能"内存控制块",Enable (1) or Disable (0) code generation for MEMORY MANAGER */
#define OS_MEM_NAME_EN 1u /*使能内存分区名称,Enable memory partition names*/
#define OS_MEM_QUERY_EN 1u /*使能"查询一个内存分区的状态OSMemQuery()",Include code for OSMemQuery()*/
/* ----------------互斥型信号量MUTUAL EXCLUSION SEMAPHORES --------------- */
#define OS_MUTEX_EN 1u /* Enable (1) or Disable (0) code generation for MUTEX */
#define OS_MUTEX_ACCEPT_EN 1u /*使能"无等待地获取互斥型信号量函数OSMutexAccept()",Include code for OSMutexAccept()*/
#define OS_MUTEX_DEL_EN 1u /*使能"删除互斥型信号量函数OSMutexDel()",Include code for OSMutexDel()*/
#define OS_MUTEX_QUERY_EN 1u /*使能"查询一个互斥型信号量的当前状态OSMutexQuery()",Include code for OSMutexQuery() */
/* ----------------------消息队列MESSAGE QUEUES ---------------------- */
#define OS_Q_EN 1u /*队列控制块,Enable (1) or Disable (0) code generation for QUEUES*/
#define OS_Q_ACCEPT_EN 1u /*使能"无等待地从一个消息队列中取得消息OSQAccept()",Include code for OSQAccept()*/
#define OS_Q_DEL_EN 1u /*删除一个消息队列OSQDel(),Include code for OSQDel()*/
#define OS_Q_FLUSH_EN 1u /*"清空一个消息队列OSQFlush()",Include code for OSQFlush()*/
#define OS_Q_PEND_ABORT_EN 1u /*Include code for OSQPendAbort()*/
#define OS_Q_POST_EN 1u /*采用FIFO先入先出法方式,向消息队列发送一个消息OSQPost(),Include code for OSQPost()*/
#define OS_Q_POST_FRONT_EN 1u /*采用LIFO后进先出法方式,向消息队列发送一个消息OSQPostFront(),Include code for OSQPostFront()*/
#define OS_Q_POST_OPT_EN 1u /*依据条件,采用LIFO后进先出法方式,向消息队列发送一个消息OSQPostOpt(),Include code for OSQPostOpt()*/
#define OS_Q_QUERY_EN 1u /*查询一个消息队列的状态OSQQuery(),Include code for OSQQuery()*/
/* ------------------------信号量SEMAPHORES ------------------------ */
#define OS_SEM_EN 1u /* Enable (1) or Disable (0) code generation for SEMAPHORES */
#define OS_SEM_ACCEPT_EN 1u /*使能"无等待地请求一个信号量OSSemAccept()",Include code for OSSemAccept()*/
#define OS_SEM_DEL_EN 1u /*使能"删除一个信号OSSemDel()",Include code for OSSemDel()*/
#define OS_SEM_PEND_ABORT_EN 1u /* Include code for OSSemPendAbort() */
#define OS_SEM_QUERY_EN 1u /*使能"查询一个信号量的当前状态OSSemQuery()",Include code for OSSemQuery()*/
#define OS_SEM_SET_EN 1u /*将信号量计数设置为作为参数指定的值,Include code for OSSemSet()*/
/* ---------------------时间管理TIME MANAGEMENT ---------------------- */
#define OS_TIME_DLY_HMSM_EN 1u /*按时分秒延时函数OSTimeDlyHMSM(),Include code for OSTimeDlyHMSM()*/
#define OS_TIME_DLY_RESUME_EN 1u /*让处在延时期的任务结束延时OSTimeDlyResume(),Include code for OSTimeDlyResume()*/
#define OS_TIME_GET_SET_EN 1u /*使能"系统时间函数OSTimeGet()和OSTimeSet()",Include code for OSTimeGet() and OSTimeSet()*/
#define OS_TIME_TICK_HOOK_EN 1u /*OSTaskTimeHook()在每个时钟节拍都会被OSTaskTick()调用,Include code for OSTimeTickHook() */
/* --------------------- TIMER MANAGEMENT --------------------- */
#define OS_TMR_EN 0u /* Enable (1) or Disable (0) code generation for TIMERS */
#define OS_TMR_CFG_MAX 16u /* Maximum number of timers */
#define OS_TMR_CFG_NAME_EN 1u /* Determine timer names */
#define OS_TMR_CFG_WHEEL_SIZE 8u /* Size of timer wheel (#Spokes) */
#define OS_TMR_CFG_TICKS_PER_SEC 10u /* Rate at which timer management task runs (Hz) */
#endif
标签:TASK,中断,InitStructure,OSII,uC,GPIO,OS,EXTI,define From: https://blog.csdn.net/weixin_42550185/article/details/143499168