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

📄 app.c

📁 从Luminary官方网站下载的LM3S6000系列的UCos+Tcp/IP的源码, 经本人稍微修改后可直接在IAR6.2下编译通过,里面包括了LM3S6000系列的所有外设UART, PWn....
💻 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
*
*                                       Luminary Micro LM3S6965
*                                              with the
*                             Luminary Micro LM3S6965 ENET Development Kit
*
* Filename      : app.c
* Version       : V1.00
* Programmer(s) : Brian Nagel
*********************************************************************************************************
*/

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

#include <includes.h>


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

#define  ROW0_Y          0x00
#define  ROW1_Y          0x10
#define  ROW2_Y          0x20
#define  ROW3_Y          0x30


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

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

static  CPU_INT08U      AppUserIFState;                         /* User I/F state                                           */
static  OS_EVENT       *AppUserIFMbox;
static  CPU_CHAR        AppUserIFLine1[30];
static  CPU_CHAR        AppUserIFLine2[30];
static  CPU_CHAR        AppUserIFLine3[30];
static  CPU_CHAR        AppUserIFLine4[30];

static  CPU_BOOLEAN     Probe_B1;
static  CPU_BOOLEAN     Probe_B2;
static  CPU_BOOLEAN     Probe_B3;
static  CPU_BOOLEAN     Probe_B4;
static  CPU_BOOLEAN     Probe_B5;

static  CPU_INT32U      Probe_B1Counts;
static  CPU_INT32U      Probe_B2Counts;
static  CPU_INT32U      Probe_B3Counts;
static  CPU_INT32U      Probe_B4Counts;
static  CPU_INT32U      Probe_B5Counts;

#if (uC_TCPIP_MODULE > 0)
        NET_IP_ADDR     AppNetIP;
        NET_IP_ADDR     AppNetMsk;
        NET_IP_ADDR     AppNetGateway;
#endif


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

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

static  void            AppDispScr_SignOn               (void);
static  void            AppDispScr_VersionTickRateCPU   (void);
static  void            AppDispScr_CtxSw                (void);
static  void            AppDispScr_Inputs               (void);
static  void            AppDispScr_Tcpip                (void);

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

#if (uC_TCPIP_MODULE > 0)
static  void            AppInitTCPIP                    (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 initialization.
*
* Arguments   : none
*
* Returns     : 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)       */
}


/*
*********************************************************************************************************
*                                          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()'.
*
* Returns     : none
*
* 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.
*********************************************************************************************************
*/

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_TCPIP_MODULE > 0)
    AppInitTCPIP();                                             /* Initialize uC/TCP-IP and associated appliations          */
#endif

    AppUserIFState  = 0;
    AppUserIFMbox   = OSMboxCreate((void *)0);                  /* Create MBOX for communication between Kbd and UserIF     */
    AppTaskCreate();                                            /* Create application tasks                                 */

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

        OSTimeDly(OS_TICKS_PER_SEC / 4);
    }
}


/*
*********************************************************************************************************
*                                      AppInit_TCPIP()
*
* Description : This function is called by AppTaskStart() and is responsible for initializing uC/TCP-IP
*               uC/HTTPs, uC/TFTPs and uC/DHCPc if enabled.
*
* Arguments   : none
*
* Returns     : none
*********************************************************************************************************
*/

#if uC_TCPIP_MODULE > 0
static  void  AppInitTCPIP (void)
{
    NET_ERR  err;


#if (EMAC_CFG_MAC_ADDR_SEL == EMAC_CFG_MAC_ADDR_SEL_CFG)
    NetIF_MAC_Addr[0] = 0x00;
    NetIF_MAC_Addr[1] = 0x50;
    NetIF_MAC_Addr[2] = 0xC2;
    NetIF_MAC_Addr[3] = 0x25;
    NetIF_MAC_Addr[4] = 0x61;
    NetIF_MAC_Addr[5] = 0x33;
#endif

    err             = Net_Init();                               /* Initialize uC/TCP-IP                                     */

    AppNetIP        = NetASCII_Str_to_IP("10.10.1.127",  &err);
    AppNetMsk       = NetASCII_Str_to_IP("255.255.255.0", &err);
    AppNetGateway   = NetASCII_Str_to_IP("10.10.1.1",   &err);

    err             = NetIP_CfgAddrThisHost(AppNetIP, AppNetMsk);
    err             = NetIP_CfgAddrDfltGateway(AppNetGateway);
}
#endif


/*
*********************************************************************************************************
*                                         USER INTERFACE TASK
*
* Description : This task updates the LCD screen based on messages passed to it by AppTaskKbd().
*
* Arguments   : p_arg   is the argument passed to 'AppStartUserIF()' by 'OSTaskCreate()'.
*
* Returns     : none
*********************************************************************************************************
*/

static  void  AppTaskUserIF (void *p_arg)
{
    CPU_INT08U     *msg;
    CPU_INT08U      err;
    CPU_INT32U      nstate;
    CPU_INT32U      pstate;


    (void)p_arg;

    AppDispScr_SignOn();
    OSTimeDly(OS_TICKS_PER_SEC * 2);
    pstate              = 0;
    nstate              = 1;


    while (DEF_TRUE) {                                          /* Task body, always written as an infinite loop.           */
        msg = (CPU_INT08U *)(OSMboxPend(AppUserIFMbox, OS_TICKS_PER_SEC / 10, &err));
        if (err == OS_NO_ERR) {
            if (msg != (CPU_INT08U *)0) {
                nstate = *msg;
            }
        }

        if (nstate != pstate) {
            OSRAM128x64x4Clear();
            pstate  = nstate;
        }

        switch (nstate) {
            case 1:
                 AppDispScr_VersionTickRateCPU();
                 break;

            case 2:
                 AppDispScr_CtxSw();
                 break;

            case 3:
                 AppDispScr_Inputs();
                 break;

            case 4:
                 AppDispScr_Tcpip();
                 break;

            case 0:
            default:
                 AppDispScr_SignOn();
                 break;
        }
    }
}


/*
*********************************************************************************************************
*                                    KEYBOARD RESPONSE TASK
*
* Description : This task monitors the state of the push buttons and passes messages to AppTaskUserIF()
*
* Arguments   : p_arg   is the argument passed to 'AppStartKbd()' by 'OSTaskCreate()'.
*
* Returns     : none
*********************************************************************************************************
*/
static  void  AppTaskKbd (void *p_arg)
{
    CPU_BOOLEAN  b1_prev;
    CPU_BOOLEAN  b2_prev;
    CPU_BOOLEAN  b3_prev;
    CPU_BOOLEAN  b4_prev;
    CPU_BOOLEAN  b5_prev;
    CPU_INT08U   key;


    (void)p_arg;
    key         = 1;
    Probe_B1    = DEF_FALSE;
    Probe_B2    = DEF_FALSE;
    Probe_B3    = DEF_FALSE;
    Probe_B4    = DEF_FALSE;
    Probe_B5    = DEF_FALSE;

    while (DEF_TRUE) {

        Probe_B1    = PB_GetStatus(1);

⌨️ 快捷键说明

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