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

📄 app.c

📁 NXPLPC2138 平台下使用UC/0S-II 操作系統. 在IAR工工程環境下的源代碼.帶有一此驅動程序,LCD驅動,還有原開發板的BSP包.
💻 C
📖 第 1 页 / 共 2 页
字号:
/*
*********************************************************************************************************
*                                              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
*
*                                              NXP LPC2138
*                                                on the
*                                     IAR LPC2138-SK Evaluation Board
*
* Filename      : app.c
* Version       : V1.00
* Programmer(s) : JJL
*********************************************************************************************************
*/

/*
*********************************************************************************************************
*                                             INCLUDE FILES
*********************************************************************************************************
*/

#include <includes.h>


/*
*********************************************************************************************************
*                                            LOCAL DEFINES
*********************************************************************************************************
*/

#define  APP_USERIF_STATE_MAX   5

/*
*********************************************************************************************************
*                                       LOCAL GLOBAL VARIABLES
*********************************************************************************************************
*/

                                                                /* ----------------- APPLICATION GLOBALS ------------------ */
static  OS_STK       AppTaskStartStk[APP_TASK_START_STK_SIZE];

#if (uC_LCD_MODULE > 0)
static  OS_STK       AppTaskUserIFStk[APP_TASK_USER_IF_STK_SIZE];
static  OS_STK       AppTaskKbdStk[APP_TASK_KBD_STK_SIZE];

static  OS_EVENT    *AppUserIF_Mbox;

static  CPU_CHAR     AppUserIFLine1[17];
static  CPU_CHAR     AppUserIFLine2[17];

static  CPU_INT32U   AppB1Counts;
static  CPU_INT32U   AppB2Counts;
static  CPU_INT16U   AppADC;
#endif

                                                                /* -------------- uC/PROBE RELATED GLOBALS ---------------- */
#if (uC_PROBE_COM_MODULE   > 0) && \
    (PROBE_COM_SUPPORT_STR > 0)
static  OS_STK       AppTaskProbeStrStk[APP_TASK_PROBE_STR_STK_SIZE];
#endif

#if (uC_PROBE_OS_PLUGIN    > 0) && \
    (uC_PROBE_COM_MODULE   > 0) && \
    (PROBE_COM_SUPPORT_STR > 0) && \
    (PROBE_COM_STAT_EN     > 0)
static  CPU_FP32     Probe_RS232RxSpd;
static  CPU_FP32     Probe_RS232TxSpd;
static  CPU_FP32     Probe_ComRxPktSpd;
static  CPU_FP32     Probe_ComTxPktSpd;
static  CPU_FP32     Probe_ComTxSymSpd;
static  CPU_FP32     Probe_ComTxSymByteSpd;

static  CPU_INT32U   Probe_RS232RxLast;
static  CPU_INT32U   Probe_RS232TxLast;
static  CPU_INT32U   Probe_ComRxPktLast;
static  CPU_INT32U   Probe_ComTxPktLast;
static  CPU_INT32U   Probe_ComTxSymLast;
static  CPU_INT32U   Probe_ComTxSymByteLast;

static  CPU_INT32U   Probe_ComCtrLast;
#endif


#if (uC_PROBE_OS_PLUGIN > 0)
static  CPU_INT32U   Probe_Counts;
static  CPU_BOOLEAN  Probe_B1;
static  CPU_BOOLEAN  Probe_B2;
static  CPU_INT16U   Probe_ADC;
#endif

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

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

#if (uC_LCD_MODULE > 0)
static  void  AppTaskUserIF             (void        *p_arg);
static  void  AppTaskKbd                (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  AppDispScr_Inputs         (void);
#endif

#if (uC_PROBE_OS_PLUGIN > 0)
static  void  AppProbeCallback          (void);
#endif

#if (uC_PROBE_COM_MODULE   > 0) && \
    (PROBE_COM_SUPPORT_STR > 0)
static  void  AppTaskProbeStr           (void        *p_arg);
#endif

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 initialization.
*
* Argument(s) : none
*
* Return(s)   : 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 > 11)
    OSTaskNameSet(APP_TASK_START_PRIO, "Start Task", &err);
#endif

    OSStart();                                                  /* Start multitasking (i.e. give control to uC/OS-II)       */
}


/*
*********************************************************************************************************
*                                          AppTaskStart()
*
* Description : The startup task.  The uC/OS-II ticker should only be initialize once multitasking starts.
*
* Argument(s) : p_arg       Argument passed to 'AppTaskStart()' by 'OSTaskCreate()'.
*
* Return(s)   : none.
*
* Note(s)     : (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 starts 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

#if (uC_PROBE_OS_PLUGIN > 0)
    (void)Probe_Counts;
    (void)Probe_B1;
    (void)Probe_B2;
    (void)Probe_ADC;

#if (uC_PROBE_COM_MODULE   > 0) && \
    (PROBE_COM_STAT_EN     > 0)
    (void)Probe_RS232RxSpd;
    (void)Probe_RS232TxSpd;
    (void)Probe_ComRxPktSpd;
    (void)Probe_ComTxPktSpd;
    (void)Probe_ComTxSymSpd;
    (void)Probe_ComTxSymByteSpd;

    (void)Probe_RS232RxLast;
    (void)Probe_RS232TxLast;
    (void)Probe_ComRxPktLast;
    (void)Probe_ComTxPktLast;
    (void)Probe_ComTxSymLast;
    (void)Probe_ComTxSymByteLast;

    (void)Probe_ComCtrLast;
#endif

    OSProbe_Init();
    OSProbe_SetCallback(AppProbeCallback);
    OSProbe_SetDelay(50);
#endif

#if (uC_PROBE_COM_MODULE > 0)
    ProbeCom_Init();                                            /* Initialize the uC/Probe communications module            */
    ProbeRS232_Init(115200);
    ProbeRS232_RxIntEn();
#endif

    LED_Off(0);                                                 /* Turn OFF all the LEDs                                    */

#if (uC_LCD_MODULE > 0)
    AppUserIF_Mbox = OSMboxCreate((void *)0);                   /* Create MBOX for communication between Kbd and UserIF     */
#endif

    AppTaskCreate();                                            /* Create application tasks                                 */

    while (DEF_TRUE) {                                          /* Task body, always written as an infinite loop.           */
        OSTimeDlyHMSM(0, 0, 1, 0);
        AppADC = ADC_GetStatus(1);
    }
}


/*
*********************************************************************************************************
*                                      AppTaskCreate()
*
* Description :  Create the application tasks.
*
* Argument(s) :  none.
*
* Return(s)   :  none.
*********************************************************************************************************
*/

static  void  AppTaskCreate (void)
{
    CPU_INT08U  err;


#if (uC_LCD_MODULE > 0)
    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 > 9)
    OSTaskNameSet(APP_TASK_USER_IF_PRIO, "User I/F", &err);
#endif

    OSTaskCreateExt(AppTaskKbd,
                    (void *)0,
                    (OS_STK *)&AppTaskKbdStk[APP_TASK_KBD_STK_SIZE - 1],
                    APP_TASK_KBD_PRIO,
                    APP_TASK_KBD_PRIO,
                    (OS_STK *)&AppTaskKbdStk[0],
                    APP_TASK_KBD_STK_SIZE,
                    (void *)0,
                    OS_TASK_OPT_STK_CHK | OS_TASK_OPT_STK_CLR);

#if (OS_TASK_NAME_SIZE > 9)
    OSTaskNameSet(APP_TASK_KBD_PRIO, "Keyboard", &err);
#endif
#endif

#if (uC_PROBE_COM_MODULE > 0) && (PROBE_COM_SUPPORT_STR > 0)
    OSTaskCreateExt(AppTaskProbeStr,
                    (void *)0,
                    (OS_STK *)&AppTaskProbeStrStk[APP_TASK_PROBE_STR_STK_SIZE - 1],
                    APP_TASK_PROBE_STR_PRIO,
                    APP_TASK_PROBE_STR_PRIO,
                    (OS_STK *)&AppTaskProbeStrStk[0],
                    APP_TASK_PROBE_STR_STK_SIZE,
                    (void *)0,
                    OS_TASK_OPT_STK_CHK | OS_TASK_OPT_STK_CLR);

#if (OS_TASK_NAME_SIZE > 9)
    OSTaskNameSet(APP_TASK_PROBE_STR_PRIO, "Probe Str", &err);
#endif
#endif
}


/*
*********************************************************************************************************
*                                    AppTaskKbd()
*
* Description : Monitor the state of the push buttons and passes messages to AppTaskUserIF()
*
* Argument(s) : p_arg       Argument passed to 'AppTaskKbd()' by 'OSTaskCreate()'.
*
* Return(s)   : none.
*
* Note(s)     : (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.
*********************************************************************************************************
*/

#if (uC_LCD_MODULE > 0)
static  void  AppTaskKbd (void *p_arg)
{
    CPU_BOOLEAN  b1;                                            /* State of Push Button #1                        */
    CPU_BOOLEAN  b1_prev;
    CPU_BOOLEAN  b2;                                            /* State of Push Button #2                        */
    CPU_BOOLEAN  b2_prev;
    CPU_INT08U   key;


    (void)p_arg;

    key     = 1;
    b1_prev = DEF_FALSE;
    b2_prev = DEF_FALSE;

    while (DEF_TRUE) {

        b1 = PB_GetStatus(1);
        b2 = PB_GetStatus(2);

        if (b1 == DEF_TRUE && b1_prev == DEF_FALSE) {
            AppB1Counts++;

            if (key == APP_USERIF_STATE_MAX) {
                key = 1;
            } else {
                key++;
            }
            OSMboxPost(AppUserIF_Mbox, (void *)key);
        }

        if (b2 == DEF_TRUE && b2_prev == DEF_FALSE) {
            AppB2Counts++;
            LED_Toggle(1);
        }

        b1_prev = b1;
        b2_prev = b2;

        OSTimeDlyHMSM(0, 0, 0, 50);
    }
}
#endif


/*
*********************************************************************************************************
*                                    AppTaskUserIF()
*
* Description : Updates LCD.
*
* Argument(s) : p_arg       Argument passed to 'AppTaskUserIF()' by 'OSTaskCreate()'.
*
* Return(s)   : none.
*
* Note(s)     : (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.
*********************************************************************************************************
*/

#if (uC_LCD_MODULE > 0)
static  void  AppTaskUserIF (void *p_arg)
{
    CPU_INT32U   pstate;
    CPU_INT32U   nstate;
    CPU_INT32U  *msg;
    CPU_INT08U   err;


    (void)p_arg;

    DispInit(2, 16);                                            /* Initialize the LCD module                            */

    LED_On(1);                                                  /* Turn ON    the LCD Backlight                         */

    AppDispScr_SignOn();                                        /* Display 'sign on' message                            */
    OSTimeDlyHMSM(0, 0, 1, 0);
    pstate = 1;

⌨️ 快捷键说明

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