⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 app.c

📁 CSB637 uCOS-II with Visual C
💻 C
字号:
/***********************************************************************************************************                                               uC/TCP-IP*                                       The Embedded TCP/IP Suite**                          (c) Copyright 2003-2005; Micrium, Inc.; Weston, FL**                   All rights reserved.  Protected by international copyright laws.*                   Knowledge of the source code may not be used to write a similar*                   product.  This file may only be used in accordance with a license*                   and should not be redistributed in any way.**********************************************************************************************************//***********************************************************************************************************                                             EXAMPLE CODE** Filename      : app.c* Version       : V1.00* Programmer(s) : CL**********************************************************************************************************/#include  <includes.h>#ifdef  APPs_DEBUG    #define  APP_DEBUG_TRACE(...)  printf(__VA_ARGS__)#else    #define  APP_DEBUG_TRACE(...)#endif/***********************************************************************************************************                                               VARIABLES**********************************************************************************************************/static  OS_STK          AppStartTaskStk[APP_START_TASK_STK_SIZE];static  OS_STK          App1TaskStk[APP_1_TASK_STK_SIZE];static  CPU_INT16U      AppSw0Pressed;static  CPU_INT16U      AppTaskSel;/***********************************************************************************************************                                          FUNCTION PROTOTYPES**********************************************************************************************************/static  void       AppTaskStart        (void            *p_arg);static  void       AppTaskCreate       (void);static  void       AppTask1            (void            *p_arg);static  void       AppDispStat         (void);/***********************************************************************************************************                                             C ENTRY POINT**********************************************************************************************************/int  main (void){    CPU_INT08U  err;    err = 0;                                        /* This dummy line have been added because the     */                                                    /* mpdemon JTAG debugger seems to skip the         */                                                    /* instruction of the main() function.             */    BSP_Init();                                     /* Initialize BSP.                                 */    APP_DEBUG_TRACE("Initialize OS...\n");    OSInit();                                       /* Initialize OS.                                  */                                                    /* Create start task.                              */    OSTaskCreateExt(AppTaskStart,                    NULL,                    (OS_STK *)&AppStartTaskStk[APP_START_TASK_STK_SIZE - 1],                    APP_START_TASK_PRIO,                    APP_START_TASK_PRIO,                    (OS_STK *)&AppStartTaskStk[0],                    APP_START_TASK_STK_SIZE,                    NULL,                    OS_TASK_OPT_STK_CHK | OS_TASK_OPT_STK_CLR);                                                    /* Give a name to tasks.                           */#if OS_TASK_NAME_SIZE > 10    OSTaskNameSet(OS_IDLE_PRIO,        "Idle task",  &err);    OSTaskNameSet(OS_STAT_PRIO,        "Stat task",  &err);    OSTaskNameSet(APP_START_TASK_PRIO, "Start task", &err);#endif    APP_DEBUG_TRACE("Start OS...\n");    OSStart();                                      /* Start OS.                                       */}/***********************************************************************************************************                                             STARTUP TASK** Description : This is an example of a startup task.  As mentioned in the book's text, you MUST*               initialize the ticker only once multitasking has started.** Arguments   : p_arg is the argument passed to 'AppTaskStart()' by 'OSTaskCreate()'.** Notes       : 1) The first line of code is used to prevent a compiler warning because 'p_arg' is not*                  used.  The compiler should not generate any code for this statement.**               2) Interrupts are enabled once the task start because the I-bit of the CCR register was*                  set to 0 by 'OSTaskCreate()'.**********************************************************************************************************/static  void  AppTaskStart (void  *p_arg){    (void)p_arg;                                    /* Prevent compiler warning.                       */    APP_DEBUG_TRACE("Initialize interrupt controller...\n");    BSP_InitIntCtrl();                              /* Initialize interrupt controller.                */    APP_DEBUG_TRACE("Initialize OS timer...\n");    Tmr_Init();                                     /* Initialize OS timer.                            */#if OS_TASK_STAT_EN > 0    APP_DEBUG_TRACE("Initialize OS statistic task...\n");    OSStatInit();                                   /* Initialize OS statistic task.                   */#endif    APP_DEBUG_TRACE("Create application task...\n");    AppTaskCreate();                                /* Create application task.                        */    APP_DEBUG_TRACE("Start demo...\n");    APP_DEBUG_TRACE("Press user switch to toggle user task LED blinking frequency\n");    APP_DEBUG_TRACE("User Task : Red LED - Slow blinking\n");    AppSw0Pressed = 0;    AppTaskSel    = 1;    LED_Off(1);    while (TRUE) {                                  /* Task body, always written as an infinite loop.  */        if (PB_GetStatus(1) == TRUE) {              /* Switch pressed                                  */            if (AppSw0Pressed == 0) {                AppSw0Pressed =  1;                 /* Record switch change of status                  */                switch (AppTaskSel) {                    case 1:                         AppTaskSel = 2;                         APP_DEBUG_TRACE("\nTask Speed : Fast LED blinking\n");                         AppDispStat();                         break;                    case 2:                         AppTaskSel = 1;                         APP_DEBUG_TRACE("\nTask Speed : Slow LED blinking\n");                         AppDispStat();                         break;                }            }        } else {                                    /* Switch unpressed                                */            if (AppSw0Pressed == 1) {                AppSw0Pressed =  0;                 /* Record switch change of status                  */            }        }        OSTimeDlyHMSM(0, 0, 0, 200);    }}/***********************************************************************************************************                                        DISPLAY TASK STATISTICS** Description : This function creates the application tasks.** Arguments   : none**********************************************************************************************************/static  void  AppDispStat (void){    CPU_CHAR    s[80];#if OS_CPU_INT_DIS_MEAS_EN > 0    CPU_INT32U  time_us;    Str_Format_Print(s, 80, "Max Interrupt Disable Cnts = %9d\n",         OS_CPU_IntDisMeasCntsMax);    APP_DEBUG_TRACE(s);    time_us = OS_CPU_IntDisMeasCntsMax * 1000000L / BSP_AT91RM9200_CLK;    Str_Format_Print(s, 80, "Max Interrupt Disable Time = %9d uS\n",      time_us);    APP_DEBUG_TRACE(s);#endif    Str_Format_Print(s, 80, "CPU Usage                  = %9d Percent\n", OSCPUUsage);    APP_DEBUG_TRACE(s);    Str_Format_Print(s, 80, "Run Idle Ctr               = %9u\n",         OSIdleCtrRun);    APP_DEBUG_TRACE(s);    Str_Format_Print(s, 80, "Max Idle Ctr               = %9u\n",         OSIdleCtrMax);    APP_DEBUG_TRACE(s);}/***********************************************************************************************************                                       CREATE APPLICATION TASKS** Description : This function creates the application tasks.** Arguments   : none**********************************************************************************************************/static  void  AppTaskCreate (void){    CPU_INT08U  err;    OSTaskCreateExt(AppTask1,                    NULL,                    (OS_STK *)&App1TaskStk[APP_1_TASK_STK_SIZE - 1],                    APP_1_TASK_PRIO,                    APP_1_TASK_PRIO,                    (OS_STK *)&App1TaskStk[0],                    APP_1_TASK_STK_SIZE,                    NULL,                    OS_TASK_OPT_STK_CHK | OS_TASK_OPT_STK_CLR);#if OS_TASK_NAME_SIZE > 20    OSTaskNameSet(APP_1_TASK_PRIO, "Yellow LED task", &err);#endif}/***********************************************************************************************************                                                TASK #1** Description : This is an example of a task.** Arguments   : p_arg is the argument passed to 'AppTask1()' by 'OSTaskCreate()'.** Notes       : 1) The first line of code is used to prevent a compiler warning because 'p_arg' is not*                  used.  The compiler should not generate any code for this statement.**               2) Interrupts are enabled once the task start because the I-bit of the CCR register was*                  set to 0 by 'OSTaskCreate()'.**               3) This Task uses the LEDs and the switch of the CSB355 board,*                  it blinks user LED 2 on the CSB360.**********************************************************************************************************/static  void  AppTask1 (void  *p_arg){    (void)p_arg;                                    /* Prevent compiler warning.                       */    CPU_BOOLEAN  led;    led = FALSE;    while (TRUE) {                                  /* Task body, always written as an infinite loop.  */        if (led == FALSE) {            led =  TRUE;            LED_On(2);        } else {            led =  FALSE;            LED_Off(2);        }        if (AppTaskSel == 1) {            OSTimeDlyHMSM(0, 0, 0, 200);                /* Delay task execution for 200 ms                 */        } else {            OSTimeDlyHMSM(0, 0, 0, 100);                /* Delay task execution for 100 ms                 */        }        }}

⌨️ 快捷键说明

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