app.c

来自「stm32 ucos 精简移殖版本 不需作任何修改直接便可运行。包含串口 定时器」· C语言 代码 · 共 509 行 · 第 1/2 页

C
509
字号
                         );
	printf("Creat App_TaskUart!\r\n");
#if (OS_TASK_NAME_SIZE >= 9)
    OSTaskNameSet(APP_TASK_UART_PRIO, "USART", &os_err);
#endif


    os_err = OSTaskCreate((void (*)(void *)) App_TaskKbd,
                          (void          * ) 0,
                          (OS_STK        * )&App_TaskKbdStk[APP_TASK_KBD_STK_SIZE - 1],
                          (INT8U           ) APP_TASK_KBD_PRIO
                          );
	printf("Creat App_TaskKbd!\r\n");
		
#if (OS_TASK_NAME_SIZE >= 9)
    OSTaskNameSet(APP_TASK_KBD_PRIO, "KeyBoard", &os_err);
#endif

}
/*
*********************************************************************************************************
*                                            App_TaskLCD()
*
* Description : The LCD Task
*
* Argument(s) : p_arg       Argument passed to 'App_TaskLCD()' by 'OSTaskCreate()'.
*
* Return(s)   : none.
*
* Caller(s)   : This is a task.
*
* Note(s)     : none.
*********************************************************************************************************
*/
static  void  App_TaskLED (void *p_arg)
{
	while(1)
		{
	  OSTimeDlyHMSM(0, 0, 0, 800);	
	  BSP_LED_On(1);
	  OSTimeDlyHMSM(0, 0, 0, 800);
	  BSP_LED_Off(1);	 
	  //USART_SendData(USART2, 'O');
   // while(USART_GetFlagStatus(USART2, USART_FLAG_TXE) == RESET); 
    }
}

/*
*********************************************************************************************************
*                                            App_TaskKbd()
*
* Description : Monitor the state of the push buttons
*
* Argument(s) : p_arg       Argument passed to 'App_TaskKbd()' by 'OSTaskCreate()'.
*
* Return(s)   : none.
*
* Caller(s)   : This is a task.
*
* Note(s)     : none.
*********************************************************************************************************
*/

static  void  App_TaskKbd (void *p_arg)
{
    INT8U  b1,b2;
	//INT8U  err;
    (void)p_arg;
	 
    while (DEF_TRUE) {
	    //OSSemPend(InfoSem,0,&err);
        b1 = BSP_PB_GetStatus(BSP_PB_ID_KEY1);
		b2 = BSP_PB_GetStatus(BSP_PB_ID_KEY2);
		if (b1 == 1)	{
		App_DispScr_SignOn();
		} 
		if (b2 == 2)	{
		App_DispScr_SignOn();//OSMboxPost(Disp_Box,(void*)0);
		}
		OSTimeDlyHMSM(0, 0, 0, 20); 
    }
}

/*
*********************************************************************************************************
*                                            App_TaskJoystick()
*
* Description : Monitor the state of the Joystick
*
* Argument(s) : p_arg       Argument passed to 'App_TaskKbd()' by 'OSTaskCreate()'.
*
* Return(s)   : none.
*
* Caller(s)   : This is a task.
*
* Note(s)     : none.
*********************************************************************************************************
*/


/*
*********************************************************************************************************
*                                          App_DispScr_SignOn()
*
* Description : Display uC/OS-II system information on the USART.
*
* Argument(s) : none.
*
* Return(s)   : none.
*
* Caller(s)   : App_TaskKbd().
*
* Note(s)     : none.
*********************************************************************************************************
*/

static  void  App_DispScr_SignOn (void)
{


    printf("\r\n  Micrium uC/OS-II  \r\n");
    printf("  ST STM32 (Cortex-M3)\r\n\r\n");

    printf("  uC/OS-II:  V%ld.%ld%ld\r\n",OSVersion()/100,(OSVersion() % 100) / 10,(OSVersion() % 10));
    printf("  TickRate: %ld  \r\n",OS_TICKS_PER_SEC);
    printf("  CPU Usage: %ld%    \r\n",OSCPUUsage);
    printf("  CPU Speed:%ld MHz  \r\n",BSP_CPU_ClkFreq() / 1000000L);
    printf("  #Ticks: %ld  \r\n",OSTime);
    printf("  #CtxSw: %ld  \r\n\r\n",OSCtxSwCtr);

}
/*
*********************************************************************************************************
*********************************************************************************************************
*                                          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(s) : ptcb   is a pointer to the task control block of the task being created.
*
* Note(s)     : (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(s) : ptcb   is a pointer to the task control block of the task being deleted.
*
* Note(s)     : (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(s) : none.
*
* Note(s)     : (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(s) : 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(s) : none.
*
* Note(s)     : (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(s) : ptcb    is a pointer to the TCB of the task being created.
*
* Note(s)     : (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

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?