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

📄 app.c

📁 基于 Luminary Micro 公司的 Cortex-M3 (ARM)内核使用之 uC/OS-II 作业系统,此例程是移植于 LM3S811 上的应用,于 IAR EWARM V4.41A 工程编
💻 C
字号:
/*
*********************************************************************************************************
*                                              EXAMPLE CODE
*
*                          (c) Copyright 2003-2006; Micrium, Inc.; Weston, FL
*
*               All rights reserved.  Protected by international copyright laws.
*               Knowledge of the source code may NOT be used to develop a similar product.
*               Please help us continue to provide the Embedded community with the finest
*               software available.  Your honesty is greatly appreciated.
*********************************************************************************************************
*/

/*
*********************************************************************************************************
*
*                                             EXAMPLE CODE
*
*                                       Luminary Micro LM3S811
*                                              with the
*                                       LM3S811 Evaluation Kit
*
* Filename      : app.c
* Version       : V1.00
* Programmer(s) : Brian Nagel
*********************************************************************************************************
*/

#include <includes.h>

void  __error__(char *pcFilename, unsigned long ulLine)
{
    ;
}

/*
*********************************************************************************************************
*                                                CONSTANTS
*********************************************************************************************************
*/

#define  APP_TASK_OLED_WIDTH  20

/*
*********************************************************************************************************
*                                                VARIABLES
*********************************************************************************************************
*/

static  OS_STK          AppTaskStartStk[APP_TASK_START_STK_SIZE];
static  OS_STK          AppTaskUserIFStk[APP_TASK_USER_IF_STK_SIZE];

static  CPU_INT16U      AppUserIF_Scroll;


/*
*********************************************************************************************************
*                                            FUNCTION PROTOTYPES
*********************************************************************************************************
*/

static  void        AppTaskCreate               (void);
static  void        AppTaskStart                (void *p_arg);
static  void        AppTaskUserIF               (void *p_arg);

static  void        AppDispScr_SignOn           (void);
static  void        AppDispScr_VersionTickRate  (void);
static  void        AppDispScr_CPU              (void);
static  void        AppDispScr_CtxSw            (void);

static  void        AppFormatDec                (CPU_INT08U *s, CPU_INT32U value, CPU_INT08U digits);

/*
*********************************************************************************************************
*                                                main()
*
* Description : This is the standard entry point for C code.  It is assumed that your code will call
*               main() once you have performed all necessary CPU and C initialization.
* Arguments   : none
*********************************************************************************************************
*/

void  main (void)
{
    CPU_INT08U  err;


    BSP_IntDisAll();                                            /* Disable all interrupts until we are ready to accept them */

    OSInit();                                                   /* Initialize "uC/OS-II, The Real-Time Kernel"              */

    OSTaskCreateExt(AppTaskStart,                               /* Create the start task                                    */
                    (void *)0,
                    (OS_STK *)&AppTaskStartStk[APP_TASK_START_STK_SIZE - 1],
                    APP_TASK_START_PRIO,
                    APP_TASK_START_PRIO,
                    (OS_STK *)&AppTaskStartStk[0],
                    APP_TASK_START_STK_SIZE,
                    (void *)0,
                    OS_TASK_OPT_STK_CHK | OS_TASK_OPT_STK_CLR);

#if OS_TASK_NAME_SIZE > 13
    OSTaskNameSet(APP_TASK_START_PRIO, "Start Task", &err);
#endif

    OSStart();                                                  /* Start multitasking (i.e. give control to uC/OS-II)       */
}
/*$PAGE*/
/*
*********************************************************************************************************
*                                          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 'AppStartTask()' 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;

    BSP_Init();                                                 /* Initialize BSP functions                                 */

#if OS_TASK_STAT_EN > 0
    OSStatInit();                                               /* Determine CPU capacity                                   */
#endif

    AppUserIF_Scroll    = 0;

    AppTaskCreate();                                            /* Create application tasks                                 */

    while (DEF_TRUE) {                                          /* Task body, always written as an infinite loop.           */
        LED_Toggle(1);

        OSTimeDly(OS_TICKS_PER_SEC / 4);
    }
}
/*
*********************************************************************************************************
*                                         USER INTERFACE TASK
*********************************************************************************************************
*/

static  void  AppTaskUserIF (void *p_arg)
{
    CPU_INT32U      state;


    (void)p_arg;

    AppDispScr_SignOn();                                        /* Display 'sign on' message                      */
    OSTimeDly(OS_TICKS_PER_SEC);
    state               = 1;


    while (DEF_TRUE) {                                          /* Task body, always written as an infinite loop. */
        AppUserIF_Scroll    = ADC_GetStatus(1) >> 5;

        if (PB_GetStatus(1) == DEF_TRUE) {
            if (state == 3) {
                state = 0;
            } else {
                state++;
            }
        }

        switch (state) {
            case 1:
                 AppDispScr_VersionTickRate();
                 break;

            case 2:
                 AppDispScr_CPU();
                 break;

            case 3:
                 AppDispScr_CtxSw();
                 break;

            case 0:
            default:
                 AppDispScr_SignOn();
                 break;
        }
        OSTimeDlyHMSM(0, 0, 0, 200);
    }
}


/*$PAGE*/
/*
*********************************************************************************************************
*                                      CREATE APPLICATION TASKS
*********************************************************************************************************
*/

static  void  AppTaskCreate (void)
{
    CPU_INT08U  err;


    OSTaskCreateExt(AppTaskUserIF,
                    (void *)0,
                    (OS_STK *)&AppTaskUserIFStk[APP_TASK_USER_IF_STK_SIZE - 1],
                    APP_TASK_USER_IF_PRIO,
                    APP_TASK_USER_IF_PRIO,
                    (OS_STK *)&AppTaskUserIFStk[0],
                    APP_TASK_USER_IF_STK_SIZE,
                    (void *)0,
                    OS_TASK_OPT_STK_CHK | OS_TASK_OPT_STK_CLR);

#if OS_TASK_NAME_SIZE > 13
    OSTaskNameSet(APP_TASK_USER_IF_PRIO, "User I/F", &err);
#endif
}


/*
*********************************************************************************************************
*                                            DISPLAY SCREENS
*********************************************************************************************************
*/

static  void  AppDispScr_SignOn (void)
{
    CPU_INT08U      s1[APP_TASK_OLED_WIDTH + 1];
    CPU_INT08U      s2[20];
    CPU_INT08U      i;



    OS_StrCopy(s1, "Micrium uC/OS-II    ");

    for (i = 0; i < 16; i++) {
        s2[i] = s1[(i + AppUserIF_Scroll) % APP_TASK_OLED_WIDTH];
    }

    OSRAMStringDraw((char const *)s2, 0, 0);

    OS_StrCopy(s1, " ARM  Cortex-M3     ");

    for (i = 0; i < 16; i++) {
        s2[i] = s1[(i + AppUserIF_Scroll) % APP_TASK_OLED_WIDTH];
    }

    OSRAMStringDraw((char const *)s2, 0, 1);
}

static  void  AppDispScr_VersionTickRate (void)
{
    CPU_INT08U      s1[APP_TASK_OLED_WIDTH + 1];
    CPU_INT08U      s2[20];
    CPU_INT08U      i;
    CPU_INT32U      value;


    OS_StrCopy(s1, "uC/OS-II:  Vx.yy    ");
    value = (CPU_INT32U)OSVersion();
    s1[12] = value / 100 + '0';
    s1[14] = (value % 100) / 10 + '0';
    s1[15] = (value %  10) + '0';
    for (i = 0; i < 16; i++) {
        s2[i] = s1[(i + AppUserIF_Scroll) % APP_TASK_OLED_WIDTH];
    }
    OSRAMStringDraw((char const *)s2, 0, 0);

    OS_StrCopy(s1, "TickRate: xxx Hz    ");
    value = (CPU_INT32U)OS_TICKS_PER_SEC;
    AppFormatDec(&s1[10], value, 3);
    s1[13] = ' ';                                               /* Account for behavior of AppFormatDec                     */
    for (i = 0; i < 16; i++) {
        s2[i] = s1[(i + AppUserIF_Scroll) % APP_TASK_OLED_WIDTH];
    }

    OSRAMStringDraw((char const *)s2, 0, 1);
}

static  void  AppDispScr_CPU (void)
{
    CPU_INT08U      s1[APP_TASK_OLED_WIDTH + 1];
    CPU_INT08U      s2[20];
    CPU_INT08U      i;
    CPU_INT32U      value;


#if OS_TASK_STAT_EN > 0
    OS_StrCopy(s1, "CPU Usage: xx %     ");
    value = (CPU_INT32U)OSCPUUsage;
    s1[11] = (value / 10) + '0';
    s1[12] = (value % 10) + '0';
    for (i = 0; i < 16; i++) {
        s2[i] = s1[(i + AppUserIF_Scroll) % APP_TASK_OLED_WIDTH];
    }
    OSRAMStringDraw((char const *)s2, 0, 0);
#endif

    OS_StrCopy(s1, "CPU Speed: xxMHz    ");
    value = (CPU_INT32U)SysCtlClockGet() / 1000000L;
    s1[11] = (value / 10) + '0';
    s1[12] = (value % 10) + '0';
    for (i = 0; i < 16; i++) {
        s2[i] = s1[(i + AppUserIF_Scroll) % APP_TASK_OLED_WIDTH];
    }
    OSRAMStringDraw((char const *)s2, 0, 1);
}

static  void  AppDispScr_CtxSw (void)
{
    CPU_INT08U      s1[APP_TASK_OLED_WIDTH + 1];
    CPU_INT08U      s2[20];
    CPU_INT08U      i;
    CPU_INT32U    value;


#if OS_TIME_GET_SET_EN > 0
    OS_StrCopy(s1, "#Ticks: xxxxxxxx    ");
    value = (CPU_INT32U)OSTime;
    AppFormatDec(&s1[8], value, 8);
    s1[16] = ' ';                                               /* Account for behavior of AppFormatDec                     */
    for (i = 0; i < 16; i++) {
        s2[i] = s1[(i + AppUserIF_Scroll) % APP_TASK_OLED_WIDTH];
    }

    OSRAMStringDraw((char const *)s2, 0, 0);
#endif

    OS_StrCopy(s1, "#CtxSw: xxxxxxxx    ");
    value = (CPU_INT32U)OSCtxSwCtr;
    AppFormatDec(&s1[8], value, 8);
    s1[16] = ' ';                                               /* Account for behavior of AppFormatDec                     */
    for (i = 0; i < 16; i++) {
        s2[i] = s1[(i + AppUserIF_Scroll) % APP_TASK_OLED_WIDTH];
    }

    OSRAMStringDraw((char const *)s2, 0, 1);
}

/*
*********************************************************************************************************
*                                      FORMAT A DECIMAL VALUE
*
* Description: This function converts a decimal value to ASCII (with leading zeros)
*
* Arguments  : s       is a pointer to the destination ASCII string
*              value   is the value to convert (assumes an unsigned value)
*              digits  is the desired number of digits
*********************************************************************************************************
*/

static  void  AppFormatDec (CPU_INT08U *s, CPU_INT32U value, CPU_INT08U digits)
{
    CPU_INT08U   i;
    CPU_INT32U   mult;


    mult = 1;
    for (i = 0; i < (digits - 1); i++) {
        mult *= 10;
    }
    while (mult > 0) {
        *s++   = value / mult + '0';
        value %= mult;
        mult  /= 10;
    }
    *s = 0;
}

⌨️ 快捷键说明

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