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

📄 app.c

📁 Micrium提供的专门针对ucos操作系统的TCP/IP协议栈 ucip
💻 C
📖 第 1 页 / 共 2 页
字号:
/*
*********************************************************************************************************
*
*                                             EXAMPLE CODE
*
*                          (c) Copyright 2003-2007; 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
*
* Filename      : app.c
* Version       : V1.91
* Programmer(s) : JDH
*                 ITJ
*********************************************************************************************************
*/

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

#include  <includes.h>

#if APP_TCPIP_EN
#include  <net.h>
#endif

#if APP_TTCP_EN
#include  <ttcp.h>
#endif


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

static  OS_STK       AppStartTaskStk[APP_OS_CFG_START_TASK_STK_SIZE];
static  OS_STK       App1_TaskStk[APP_OS_CFG_1_TASK_STK_SIZE];

#if APP_TCPIP_EN
static  NET_IP_ADDR  App_IP_Addr;
static  NET_IP_ADDR  App_IP_Mask;
static  NET_IP_ADDR  App_IP_DfltGateway;
static  NET_IP_ADDR  App_IP_DNS_Srvr;
static  NET_IP_ADDR  App_IP_NTP_Srvr;
#endif

static  CPU_INT32S   App_Clk_UTC_Offset;

static  CPU_INT08S   OS_CPU_UsageMax;


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

static  void  App_TaskCreate(void);
static  void  App_TaskStart (void  *p_arg);
static  void  App_Task_1    (void  *p_arg);

#if APP_TCPIP_EN
static  void  App_InitTCPIP (void);
#endif



/*
*********************************************************************************************************
*                                             C ENTRY POINT
*********************************************************************************************************
*/

int  main (void)
{
#if (OS_TASK_NAME_SIZE >= 6)
    INT8U  os_err;
#endif


   (void)&App_Clk_UTC_Offset;

    os_err = 0;                                                 /* Warning: With some debuggers the first call is       */
                                                                /* ignored.                                             */

    BSP_Init();                                                 /* Initialize BSP.                                      */
    CPU_Init();                                                 /* Initialize CPU.                                      */

    APP_TRACE_INFO(("\n\n\n\r"));
    APP_TRACE_INFO(("Initialize OS ...\n\r"));
    OSInit();                                                   /* Initialize OS.                                       */

                                                                /* Create start task.                                   */
    os_err = OSTaskCreateExt((void (*)(void *)) App_TaskStart,
                             (void          * ) 0,
                             (OS_STK        * )&AppStartTaskStk[APP_OS_CFG_START_TASK_STK_SIZE - 1],
                             (INT8U           ) APP_OS_CFG_START_TASK_PRIO,
                             (INT16U          ) APP_OS_CFG_START_TASK_PRIO,
                             (OS_STK        * )&AppStartTaskStk[0],
                             (INT32U          ) APP_OS_CFG_START_TASK_STK_SIZE,
                             (void          * ) 0,
                             (INT16U          )(OS_TASK_OPT_STK_CLR | OS_TASK_OPT_STK_CHK));

                                                                /* Give a name to tasks.                                */
#if (OS_TASK_NAME_SIZE >= 6)
    OSTaskNameSet(OS_TASK_IDLE_PRIO,          "Idle",  &os_err);
#if (OS_TASK_STAT_EN > 0)
    OSTaskNameSet(OS_TASK_STAT_PRIO,          "Stat",  &os_err);
#endif
    OSTaskNameSet(APP_OS_CFG_START_TASK_PRIO, "Start", &os_err);
#endif

    APP_TRACE_INFO(("Start OS ...\n\r"));
    OSStart();                                                  /* Start OS.                                            */
}


/*
*********************************************************************************************************
*                                           App_TaskStart()
*
* Description : Startup task example code
*
* Arguments   : p_arg       Argument passed by 'OSTaskCreate'.
*
* Returns     : none.
*
* Note(s)     : (1) As mentioned in the book's text, you MUST initialize the ticker only once multitasking
*                   has started.
*
*               (2) 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  App_TaskStart (void  *p_arg)
{
#if (CPU_CFG_NAME_EN == DEF_ENABLED)
    CPU_ERR   cpu_err;
    CPU_CHAR  cpu_host_name[CPU_CFG_NAME_SIZE];
#endif


   (void)&p_arg;                                                /* Prevent compiler warning.                            */

                                                                /* ------------- INIT APPS / TASKS / BSP -------------- */
    APP_TRACE_INFO(("Initialize OS timer...\n\r"));
    Tmr_Init();                                                 /* Initialize OS timer.                                 */

#if (CPU_CFG_NAME_EN == DEF_ENABLED)                            /* Initialize CPU host name.                            */
    Str_Copy((CPU_CHAR *)&cpu_host_name[0],
             (CPU_CHAR *)"CSB637");
    APP_TRACE_INFO(("Initialize CPU host name ... "));
    CPU_NameSet((CPU_CHAR *)&cpu_host_name[0],
                (CPU_ERR  *)&cpu_err);
    if (cpu_err == CPU_ERR_NONE) {
        APP_TRACE_INFO(("%s\n\r", &cpu_host_name[0]));
    } else {
        APP_TRACE_INFO(("failed!\n\r"));
    }
#endif

#if (OS_TASK_STAT_EN > 0)
    APP_TRACE_INFO(("Initialize OS statistic task ...\n\r"));
    OSStatInit();                                               /* Initialize OS statistic task.                        */
#endif


    APP_TRACE_INFO(("Create application tasks ...\n\r"));
    App_TaskCreate();                                           /* Create application task.                             */

#if APP_TCPIP_EN
    App_InitTCPIP();                                            /* Initialize TCP/IP stack.                             */
#endif

#if APP_TTCP_EN                                                 /* TTCP contains active user input code. It cannot work */
                                                                /* with other code because it takes all the CPU.        */
    APP_TRACE_INFO(("\n\r"));
    APP_TRACE_INFO(("****************************************************************************\n\r"));
    APP_TRACE_INFO(("*                                                                          *\n\r"));
    APP_TRACE_INFO(("*              Micrium uC/TCP-IP TTCP Performance measurement              *\n\r"));
    APP_TRACE_INFO(("*                     AT91RM9200 on Cogent CSB637 SDK                      *\n\r"));
    APP_TRACE_INFO(("*                                                                          *\n\r"));
    APP_TRACE_INFO(("****************************************************************************\n\r"));
    APP_TRACE_INFO(("\n\r"));
    TTCP_Init();                                                /* Initialize TTCP application                          */
#else
    APP_TRACE_INFO(("\n\r"));
    APP_TRACE_INFO(("System ready.\n\r"));
#endif

    LED_Off(1);
    LED_Off(2);
    LED_Off(3);

    while (DEF_YES) {                                           /* Task body, always written as an infinite loop.       */
        OSTimeDlyHMSM(0, 0, 0, 500);
    }
}


#if APP_TCPIP_EN
/*
*********************************************************************************************************
*                                        INITIALIZE TCP/IP STACK
*********************************************************************************************************
*/

static  void  App_InitTCPIP (void)
{
    NET_ERR      err;
    CPU_INT08U  *pmac;


    APP_TRACE_DEBUG(("Initialize TCP/IP stack...\n"));

    pmac = (CPU_INT08U *)mon_getenv("ETHERADD");
    NetASCII_Str_to_MAC(pmac, NetIF_MAC_Addr, &err);

    err = Net_Init();
    if (err != NET_ERR_NONE) {
        APP_TRACE_DEBUG(("Net_Init() failed: error #%d, line #%d.\n", err, __LINE__));

⌨️ 快捷键说明

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