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

📄 app.c

📁 lpc2378 iar开发环境 嵌入系统程序
💻 C
字号:
/*
*********************************************************************************************************
*                                               uC/OS-II
*                                         The Real-Time Kernel
*
*                         (c) Copyright 1998-2003, Jean J. Labrosse, Weston, FL
*                                          All Rights Reserved
*
*
*                                               Sample code
* File : app.c
* By   : Eric Shufro
*********************************************************************************************************
*/

#include    <includes.h>

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

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

static  OS_STK  AppStartTaskStk[START_TASK_STK_SIZE];
static  OS_STK  LCD_TestTaskStk[LCD_TASK_STK_SIZE];

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

static  void  AppStartTask(void *p_arg);
static  void  AppTaskCreate(void);

#if OS_VIEW_MODULE > 0
static  void  AppTerminalRx(INT8U rx_data);
#endif

/*
*********************************************************************************************************
*                                                main()
*
* Description : This is the standard application entry point for C code.
* Arguments   : none
*********************************************************************************************************
*/

void  main (void)
{
    CPU_INT08U   err;


    BSP_IntDisAll();                                                    /* Disable interrupts                                       */

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

    OSTaskCreateExt(AppStartTask,
                    (void *)0,
                    (OS_STK *)&AppStartTaskStk[START_TASK_STK_SIZE-1],
                    TASK_START_PRIO,
                    TASK_START_PRIO,
                    (OS_STK *)&AppStartTaskStk[0],
                    START_TASK_STK_SIZE,
                    (void *)0,
                    OS_TASK_OPT_STK_CHK | OS_TASK_OPT_STK_CLR);

#if OS_TASK_NAME_SIZE > 15
    OSTaskNameSet(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  AppStartTask (void *p_arg)
{
    CPU_INT32U  i;
    CPU_INT32U  j;


    (void)p_arg;

    BSP_Init();                                                         /* Initialize the ticker, and other BSP related functions   */

#if OS_TASK_STAT_EN > 0
    OSStatInit();
#endif

#if OS_VIEW_MODULE > 0
    OSView_Init(38400);                                                 /* OSView Init, baud rate = 38400                           */
    OSView_TerminalRxSetCallback(AppTerminalRx);
    OSView_RxIntEn();                                                   /* Enable Rx Interrupts                                     */
#endif

#ifdef  DISP_MODULE_PRESENT
    DispInit(2, 16);                                                    /* Initialize the LCD module                                */
#endif

    AppTaskCreate();

    while (TRUE) {                                                      /* Task body, always written as an infinite loop            */
        for (j = 0; j < 4; j++) {
            for (i = 1; i <= 8; i++) {
                LED_On(i);
                OSTimeDlyHMSM(0, 0, 0, 10);
                LED_Off(i);
                OSTimeDlyHMSM(0, 0, 0, 10);
            }

            for (i = 7; i >= 2; i--) {
                LED_On(i);
                OSTimeDlyHMSM(0, 0, 0, 10);
                LED_Off(i);
                OSTimeDlyHMSM(0, 0, 0, 10);
            }
        }

        for (i = 0; i < 4; i++) {
            LED_On(0);
            OSTimeDlyHMSM(0, 0, 0, 40);
            LED_Off(0);
            OSTimeDlyHMSM(0, 0, 0, 40);
        }
    }
}

/*$PAGE*/
/*
*********************************************************************************************************
*                                             LCD Test Task
*
* Description: This task displays messages on the Keil MC2300 EVB (16x2) LCD screen
*********************************************************************************************************
*/

#ifdef  DISP_MODULE_PRESENT
static  void  LCD_TestTask (void *p_arg)
{
    CPU_INT08S  i;
    CPU_INT32U  CPUFrq;
    CPU_INT08U  tempStr[17];

    CPU_INT08U  WelcomeMsg[7][17]  = {{"   Welcome to   "},
                                      {"     Micrium    "},
                                      {"This demo runs: "},
                                      {"uC/OS-II,       "},
                                      {"uC/OS-View and, "},
                                      {"uC/LCD on a NXP "},
         						      {"LPC2378 CPU.    "}};

    CPU_INT08U  aboutStr[]         =  {"Did you know that uC/OS-II is a "
                                       "real-time pre-emptive "
                                       "multitasking kernel that provides "
                                       "services such as task delay "
                                       "functionality, semaphores, message "
                                       "mailbox's, timers, event flags, "
                                       "memory management, mutex's, and "
                                       "queues. Visit Micrium online by "
                                       "browsing to www.micrium.com for "
                                       "more information."};

    CPU_INT08U  *aboutStrPtr;                                           /* Declare a pointer to aboutStr, used for scroll effect    */


    while (TRUE) {                                                      /* All tasks bodies include an infinite loop                */
        DispClrScr();                                                   /* Start by clearing the screen                             */

        DispStr(0, 0, WelcomeMsg[0]);                                   /* Display "Welcome to" on line 0 of the LCD                */
        DispStr(1, 0, WelcomeMsg[1]);                                   /* Display "Micrium" on line 1 of the LCD                   */
        OSTimeDlyHMSM(0, 0, 3, 0);                                      /* Wait a while before proceeding                           */

        DispStr(0, 0, WelcomeMsg[2]);                                   /* Display "This demo runs:"  on line 0 of the LCD          */

        for (i = 3; i <= 5; i++) {
            DispStr(1, 0, WelcomeMsg[i]);                               /* Display Messages 3-5 on line 1 of the lCD                */
            OSTimeDlyHMSM(0, 0, 3, 0);                                  /* Wait a while before proceeding                           */
        }

        DispClrScr();                                                   /* Clear the screen                                         */
        DispStr(1, 0, WelcomeMsg[6]);                                   /* Display Messages 6 on line 1 of the lCD                  */
        OSTimeDlyHMSM(0, 0, 3, 0);                                      /* Wait a while before proceeding                           */

        OSTimeDlyHMSM(0, 0, 3, 0);                                      /* Wait a while before proceeding                           */

        DispClrScr();                                                   /* Clear the screen                                         */

        DispStr(0, 0, "Clock Config:");                                 /* Display "System Settings:" on line 0 of the LCD          */
        CPUFrq   = BSP_CPU_ClkFreq();                                   /* Get the CPU Frequency in Hz                              */
        CPUFrq  /= 1000000;                                             /* Convert the CPU Frequency to MHz                         */
        sprintf((char *)tempStr, "CPU Frq: %ldMHz", CPUFrq);            /* Create the string "CPU Frq: xxMHz"                       */
        DispStr(1, 0, tempStr);                                         /* Display "CPU Frq: xxMHz" on line 1 of the LCD            */
        OSTimeDlyHMSM(0, 0, 3, 0);                                      /* Wait a while before proceeding                           */

        DispClrScr();                                                   /* Clear the screen                                         */

        aboutStrPtr = aboutStr;                                         /* Point to the start of the about message string           */

																		/* Start scrolling from right to left. This involves        */
        																/* starting from the last column and working toward the     */
                                                                        /* first column until the screen fills up. The remaining    */
                                                                        /* characters may start from position 0.                    */
        for (i = 15; i >= 0; i--) {										/* For the first 16 characters...                           */
            if (*aboutStrPtr != '\0') {						            /* If we have not reached the end of the string             */
                DispStr(0, i, aboutStrPtr);                             /* Display (col i - distance to end of lcd line) # of chars */
                OSTimeDlyHMSM(0, 0, 0, 200);                            /* Delay before updating the screen with the shifted msg    */
            }
        }

        while ((aboutStr + sizeof(aboutStr) - aboutStrPtr) >  16) {     /* While there are greater than 16 chars left to display    */
            DispStr(0, 0, aboutStrPtr++);                               /* Display 16 chars and increment (shift) message by 1 char */
            OSTimeDlyHMSM(0, 0, 0, 200);                                /* Delay before displaying the shifted message              */
        }

        for (i = 15; i >= 0; i--) {										/* For the last 16 characters                               */
            if (*aboutStrPtr != '\0') {						            /* If we have not reached the end of the string             */
                DispStr(0, 0, aboutStrPtr++);                           /* Display (col i - distance to end of lcd line) # of chars */
                DispChar(0, i, ' ');                                    /* Leave spaces chars behind as the str scrolls off screen  */
                OSTimeDlyHMSM(0, 0, 0, 200);                            /* Delay before updating the screen with the shifted msg    */
            }
        }
    }
}
#endif

/*$PAGE*/
/*
*********************************************************************************************************
*                                     CREATE APPLICATION TASKS
*
* Description : none
* Arguments   : none
* Notes       : none
*********************************************************************************************************
*/

static  void  AppTaskCreate (void)
{
    INT8U  err;

#ifdef  DISP_MODULE_PRESENT
    OSTaskCreateExt(LCD_TestTask,
                    (void *)0,
                    (OS_STK *)&LCD_TestTaskStk[LCD_TASK_STK_SIZE-1],
                    LCD_TEST_TASK_PRIO,
                    LCD_TEST_TASK_PRIO,
                    (OS_STK *)&LCD_TestTaskStk[0],
                    LCD_TASK_STK_SIZE,
                    (void *)0,
                    OS_TASK_OPT_STK_CHK | OS_TASK_OPT_STK_CLR);
    OSTaskNameSet(LCD_TEST_TASK_PRIO, "LCD Test Task", &err);
#endif
}

/*
*********************************************************************************************************
*                                     uC/OS-View TERMINAL WINDOW CALLBACK
*********************************************************************************************************
*/

#if OS_VIEW_MODULE > 0
static  void  AppTerminalRx (INT8U rx_data)
{
}
#endif


⌨️ 快捷键说明

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