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

📄 app.c

📁 嵌入式的tcpip协议栈
💻 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 LPC2468
*                                                on the
*                                  Embedded Artists LPC2468 OEM Board
*
* Filename      : app.c
* Version       : V1.00
* Programmer(s) : BAN
*********************************************************************************************************
*/

/*
*********************************************************************************************************
*                                             INCLUDE FILES
*********************************************************************************************************
*/
#include <includes.h>

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


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


                /* ----------------- APPLICATION GLOBALS ------------------ */

static  OS_STK       AppTaskStartStk[APP_TASK_START_STK_SIZE];
static  OS_STK       AppTaskIRD1sStk[APP_TASK_IRD1s_STK_SIZE];
static  OS_STK       AppTaskKbdStk[APP_TASK_KBD_STK_SIZE];
static  OS_STK       AppTaskDaliStk[APP_TASK_DALI_STK_SIZE];

/*Insert the AppTaskHeartbeat  stack definition*/


        CPU_INT08U   OSCPUUsageMax;

static  void        *AppKbdQStorage[16];
        OS_EVENT    *AppKbdQ;
        
static  void        *AppKeyQStorage[16];
        OS_EVENT    *AppKeyQ;
                                                                /* -------------- uC/TCP-IP RELATED GLOBALS --------------- */
#if (uC_TCPIP_MODULE > 0)
        NET_IP_ADDR  AppNetIP;
        NET_IP_ADDR  AppNetMsk;
        NET_IP_ADDR  AppNetGateway;
#endif





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

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




#if (uC_TCPIP_MODULE > 0)
static  void  AppInitTCPIP    (void);
#endif





/*
*********************************************************************************************************
*                                      GLOBAL FUNCTION PROTOTYPES
*********************************************************************************************************
*/ 
extern  void  AppTaskKbd      (void  *p_arg);
extern  void AppIRD1s(void *p_arg);
#if (DALI_APP_MODULE > 0)
extern  void  AppTaskDali (void  *p_arg);  
#endif 
/*Insert the AppTaskHeartbeat prototype here */


  
    CPU_INT08U TempMetricType;
    CPU_INT08U TempInputType; 
    CPU_INT08U DateTimeOption;    
    CPU_INT08U DisableMainMenu;

    OS_EVENT   *DispUpdadteSem;                /* Semaphore used to access display functions              */
    
#if (uC_PROBE_OS_PLUGIN  > 0) || \
    (uC_PROBE_COM_MODULE > 0)
extern  void  AppInitProbe    (void);
#endif
/*
*********************************************************************************************************
*                                                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 C 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 */

#ifndef LPC24XX_XRAM
    BSP_Init();
#endif

    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, (CPU_CHAR *)"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)
{
    CPU_INT08U   i;
    CPU_INT08U   j;
    void        *msg;
    CPU_INT08U   err;
    CPU_INT08U   led;
    CPU_INT32U   leds;
    CPU_INT32U   delay0;
    CPU_INT32U   delay1;


    (void)p_arg;

                             

    Tmr_TickInit();                                             /* Initialize uC/OS-II tick.                            */
    I2C_Init();                                                 /* Initialize I2C.                                      */
    Keypad_Init();                                              /* Initialize the Keypad Decoding functions*/
    EINT_Init();                                                /* Enable the Keypad external interrupt*/
    
#if (OS_TASK_STAT_EN > 0)
    OSStatInit();                                               /* Determine CPU capacity                                   */
#endif

    DispInit (4 , 140);                                         /*The Display initialization should come before the tasks are created */
    DispClrScr(); 

 
   
#if (uC_TCPIP_MODULE > 0)
    AppInitTCPIP();                                             /* Initialize uC/TCP-IP and associated appliations          */
#endif

#if (uC_PROBE_OS_PLUGIN  > 0) || \
    (uC_PROBE_COM_MODULE > 0)
    AppInitProbe();
#endif


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


    AppKbdQ = OSQCreate(AppKbdQStorage, 16);                    /* Create Q for communication between Kbd and Ser           */
    
    AppKeyQ = OSQCreate(AppKeyQStorage, 16);                    /* Create Q for communication between Keypad                */
    
    DispUpdadteSem  = OSSemCreate(1);                           /* Create display access semaphore                         */
    
#if (OS_EVENT_NAME_SIZE > 1)
    OSEventNameSet(AppKbdQ, "Kbd Q", &err);
#endif
   
    TempMetricType=1; /* Fahrenheit selection*/ 
    DateTimeOption = 0; /*Show the Date in the second line in the VFD*/
    TempInputType=INTERNAL; /* External Temperature Reading*/
    
    AppTaskCreate();                                            /* Create application tasks                                 */
  
      
     while (DEF_TRUE) {                                          /* Task body, always written as an infinite loop.           */
        for (i = 1; i <= 4; i++) {                              /* Turn on each LED, one by one, delaying between           */
            LED_On(i);
            delay0 =  ADC_GetStatus(2) + 32;
            OSTimeDlyHMSM(0, 0, (CPU_INT08U)(delay0 / 1000), (CPU_INT16U)(delay0 % 1000));
        }

        LED_Off(0);                                             /* Turn off all LEDs                                        */
        delay0 = ADC_GetStatus(2) + 32;
                                                                /* Delay                                                    */
        OSTimeDlyHMSM(0, 0, (CPU_INT08U)(delay0 / 1000), (CPU_INT16U)(delay0 % 1000));

                                                                /* Determine what buttons have been pressed                 */
        leds = 0;
        while (1) {
            msg  = OSQAccept(AppKbdQ, &err);

            if ((err == OS_Q_EMPTY) || (msg == (void *)0)) {
                break;
            }

            led  = (CPU_INT32U)msg;

            if (led > 4) {
                break;
            }

            leds |= (1 << led);
        }

                                                                /* If buttons have been pressed.                            */
        if (leds != 0) {
                                                                /* Otherwise, blink LEDs that were pressed 20 times         */
            for (j = 0; j < 20; j++) {

⌨️ 快捷键说明

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