[mw_shl_code=c,true]#include "includes.h"
OS_STK App_TaskStartStk[APP_TASK_START_STK_SIZE]; // TaskStart 任务堆栈
void App_TaskStart(void* p_arg); // 声明 TaskStart 函数
//static OS_STK App_TaskFLICKERStk[APP_TASK_FLICKER_STK_SIZE]; // TaskFLICKER 任务堆栈
//static void App_TaskFLICKER(void* p_arg);
OS_STK App_TaskMAINStk[APP_TASK_MAIN_STK_SIZE]; // 声明 TaskFLICKER 函数
void App_TaskMAIN(void* p_arg);
OS_STK App_TaskKEYStk[APP_TASK_KEY_STK_SIZE];
void App_TaskKEY(void* p_arg);
OS_EVENT *msg_key;
//void LED1234_ON_OFF(CPU_INT08U Num); // 声明流水灯函数
/*
*********************************************************************************************************
main()
*********************************************************************************************************
*/
INT8U ChkKey(void)
{
if(GPIO_ReadInputDataBit(GPIOD, GPIO_Pin_0) == 0){return(4);} // 确定
if(GPIO_ReadInputDataBit(GPIOD, GPIO_Pin_4) == 0){return(0);} // 上
if(GPIO_ReadInputDataBit(GPIOD, GPIO_Pin_1) == 0){return(1);} // 下
if(GPIO_ReadInputDataBit(GPIOD, GPIO_Pin_3) == 0){return(2);} // 左
if(GPIO_ReadInputDataBit(GPIOD, GPIO_Pin_2) == 0){return(3);} // 右
return(5); // 没有按下
}
int main(void)
{
OSInit();
SysClock_Init(); /* 初始化系统外设、 CPU 时钟,仅此而已 */
msg_key=OSMboxCreate((void*)0);
/* 建立系统的第一个任务 */
OSTaskCreate(App_TaskStart,(void *)0,&App_TaskStartStk[APP_TASK_START_STK_SIZE-1],APP_TASK_START_PRIO);
OSStart(); /* 开始任务调度 */
return (0);
}
/*
*********************************************************************************************************
系统的第一个任务,负责开OS时钟,建立其他任务
*********************************************************************************************************
*/
void App_TaskStart(void* p_arg)
{
p_arg = p_arg;
/* 初始化 OS 时钟 */
OS_CPU_SysTickInit();
/* 统计任务 */
#if (OS_TASK_STAT_EN > 0)
OSStatInit();
#endif
//OSTaskCreateExt(App_TaskFLICKER, (void *) 0, (OS_STK *) &App_TaskFLICKERStk[APP_TASK_FLICKER_STK_SIZE - 1], APP_TASK_FLICKER_PRIO,
// APP_TASK_FLICKER_PRIO, (OS_STK *) &App_TaskFLICKERStk[0], APP_TASK_FLICKER_STK_SIZE , (void *) 0, OS_TASK_OPT_STK_CHK | OS_TASK_OPT_STK_CLR
// ); // 建立流水灯线程
OSTaskCreate(App_TaskMAIN,(void *)0,&App_TaskMAINStk[APP_TASK_MAIN_STK_SIZE-1],APP_TASK_MAIN_PRIO);
OSTaskCreate(App_TaskKEY,(void *)0,&App_TaskKEYStk[APP_TASK_KEY_STK_SIZE-1],APP_TASK_KEY_PRIO);
/* 初始化外设 */
BSP_Init(); // 开启CPU外设
while (1) {
OSTaskSuspend(OS_PRIO_SELF); // 挂起任务
}
}
void App_TaskMAIN(void* p_arg)
{ p_arg = p_arg;
{ INT8U* Num;
INT8U err;
while(1)
{
Num=(INT8U*)OSMboxPend(msg_key,0,&err);
switch (*Num) {
case 0:
GPIO_SetBits(GPIOD, GPIO_Pin_8);
GPIO_ResetBits(GPIOD, GPIO_Pin_9);
GPIO_ResetBits(GPIOD, GPIO_Pin_10);
GPIO_ResetBits(GPIOD, GPIO_Pin_11);
break;
case 1:
GPIO_ResetBits(GPIOD, GPIO_Pin_8);
GPIO_SetBits(GPIOD, GPIO_Pin_9);
GPIO_ResetBits(GPIOD, GPIO_Pin_10);
GPIO_ResetBits(GPIOD, GPIO_Pin_11);
break;
case 2:
GPIO_ResetBits(GPIOD, GPIO_Pin_8);
GPIO_ResetBits(GPIOD, GPIO_Pin_9);
GPIO_SetBits(GPIOD, GPIO_Pin_10);
GPIO_ResetBits(GPIOD, GPIO_Pin_11);
break;
case 3:
GPIO_ResetBits(GPIOD, GPIO_Pin_8);
GPIO_ResetBits(GPIOD, GPIO_Pin_9);
GPIO_ResetBits(GPIOD, GPIO_Pin_10);
GPIO_SetBits(GPIOD, GPIO_Pin_11);
break;
case 4:
GPIO_SetBits(GPIOD, GPIO_Pin_8);
GPIO_SetBits(GPIOD, GPIO_Pin_9);
GPIO_SetBits(GPIOD, GPIO_Pin_10);
GPIO_SetBits(GPIOD, GPIO_Pin_11);
break;
case 5:
GPIO_ResetBits(GPIOD, GPIO_Pin_8);
GPIO_ResetBits(GPIOD, GPIO_Pin_9);
GPIO_ResetBits(GPIOD, GPIO_Pin_10);
GPIO_ResetBits(GPIOD, GPIO_Pin_11);
break;
default:
break;}
}
}
}
void App_TaskKEY(void* p_arg)
{
p_arg=p_arg;
//u32 key=key_scan(void);
while(1)
{ INT8U JZ;
JZ=ChkKey();
// if(JZ)
OSMboxPost(msg_key,&JZ);
}
}
/*
*********************************************************************************************************
流水灯线程
*********************************************************************************************************
*/
/*static void App_TaskFLICKER(void* p_arg)
{
INT8U i;
p_arg = p_arg;
while (1) {
for(i = 0 ; i < 4; i++){
LED1234_ON_OFF(i);
OSTimeDlyHMSM(0,0,1,0); // 延时一秒
}
}
}*/
/*
*********************************************************************************************************
*********************************************************************************************************
* uC/OS-II APP HOOKS
*********************************************************************************************************
*********************************************************************************************************
*/
#if (OS_APP_HOOKS_EN > 0)
/*
*********************************************************************************************************
* TASK CREATION HOOK (APPLICATION)
*
* Description : This function is called when a task is created.
*
* Argument : ptcb is a pointer to the task control block of the task being created.
*
* Note : (1) Interrupts are disabled during this call.
*********************************************************************************************************
*/
void App_TaskCreateHook(OS_TCB* ptcb)
{
}
/*
*********************************************************************************************************
* TASK DELETION HOOK (APPLICATION)
*
* Description : This function is called when a task is deleted.
*
* Argument : ptcb is a pointer to the task control block of the task being deleted.
*
* Note : (1) Interrupts are disabled during this call.
*********************************************************************************************************
*/
void App_TaskDelHook(OS_TCB* ptcb)
{
(void) ptcb;
}
/*
*********************************************************************************************************
* IDLE TASK HOOK (APPLICATION)
*
* Description : This function is called by OSTaskIdleHook(), which is called by the idle task. This hook
* has been added to allow you to do such things as STOP the CPU to conserve power.
*
* Argument : none.
*
* Note : (1) Interrupts are enabled during this call.
*********************************************************************************************************
*/
#if OS_VERSION >= 251
void App_TaskIdleHook(void)
{
}
#endif
/*
*********************************************************************************************************
* STATISTIC TASK HOOK (APPLICATION)
*
* Description : This function is called by OSTaskStatHook(), which is called every second by uC/OS-II's
* statistics task. This allows your application to add functionality to the statistics task.
*
* Argument : none.
*********************************************************************************************************
*/
void App_TaskStatHook(void)
{
}
/*
*********************************************************************************************************
* TASK SWITCH HOOK (APPLICATION)
*
* Description : This function is called when a task switch is performed. This allows you to perform other
* operations during a context switch.
*
* Argument : none.
*
* Note : 1 Interrupts are disabled during this call.
*
* 2 It is assumed that the global pointer 'OSTCBHighRdy' points to the TCB of the task that
* will be 'switched in' (i.e. the highest priority task) and, 'OSTCBCur' points to the
* task being switched out (i.e. the preempted task).
*********************************************************************************************************
*/
#if OS_TASK_SW_HOOK_EN > 0
void App_TaskSwHook(void)
{
}
#endif
/*
*********************************************************************************************************
* OS_TCBInit() HOOK (APPLICATION)
*
* Description : This function is called by OSTCBInitHook(), which is called by OS_TCBInit() after setting
* up most of the TCB.
*
* Argument : ptcb is a pointer to the TCB of the task being created.
*
* Note : (1) Interrupts may or may not be ENABLED during this call.
*********************************************************************************************************
*/
#if OS_VERSION >= 204
void App_TCBInitHook(OS_TCB* ptcb)
{
(void) ptcb;
}
#endif
#endif
/******************************************
*
* LED 流水灯
*
****************************************/
void LED1234_ON_OFF(CPU_INT08U Num)
{
switch (Num) {
case 0:
GPIO_SetBits(GPIOD, GPIO_Pin_8);
GPIO_ResetBits(GPIOD, GPIO_Pin_9);
GPIO_ResetBits(GPIOD, GPIO_Pin_10);
GPIO_ResetBits(GPIOD, GPIO_Pin_11);
break;
case 1:
GPIO_ResetBits(GPIOD, GPIO_Pin_8);
GPIO_SetBits(GPIOD, GPIO_Pin_9);
GPIO_ResetBits(GPIOD, GPIO_Pin_10);
GPIO_ResetBits(GPIOD, GPIO_Pin_11);
break;
case 2:
GPIO_ResetBits(GPIOD, GPIO_Pin_8);
GPIO_ResetBits(GPIOD, GPIO_Pin_9);
GPIO_SetBits(GPIOD, GPIO_Pin_10);
GPIO_ResetBits(GPIOD, GPIO_Pin_11);
break;
case 3:
GPIO_ResetBits(GPIOD, GPIO_Pin_8);
GPIO_ResetBits(GPIOD, GPIO_Pin_9);
GPIO_ResetBits(GPIOD, GPIO_Pin_10);
GPIO_SetBits(GPIOD, GPIO_Pin_11);
break;
default:
break;
}
}
为什么我想跟进程序中的OSMboxCreate函数,却出现以上截图,进不去这个函数,为什么呢?[/mw_shl_code]