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

📄 app.c

📁 GNU环境下uC/OS-II的移植代码:BSP & OS部分
💻 C
📖 第 1 页 / 共 4 页
字号:
/*
*********************************************************************************************************
*
*                                             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
*
* Filename      : app.c
* Version       : V1.88
* Programmer(s) : Jean-Denis Hatier
*********************************************************************************************************
*/

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

#include  <includes.h>
#include  <app_cfg.h>

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

#if APP_CLK_EN
#include  <clk.h>
#endif

#if APP_FS_EN
#include  <fs_api.h>
#endif

#if APP_DHCPc_EN
#include  <dhcp-c.h>
#endif

#if APP_DNSc_EN
#include  <dns-c.h>
#endif

#if APP_FTPc_EN
#include  <ftp-c.h>
#endif

#if APP_FTPs_EN
#include  <ftp-s.h>
#endif

#if APP_HTTPs_EN
#include  <http-s.h>
#endif

#if APP_POP3c_EN
#include  <pop3-c.h>
#endif

#if APP_SMTPc_EN
#include  <smtp-c.h>
#endif

#if APP_SNTPc_EN
#include  <sntp-c.h>
#endif

#if APP_TFTPs_EN
#include  <tftp-s.h>
#endif

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


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

static  OS_STK       App_StartTaskStk[APP_START_OS_CFG_TASK_STK_SIZE];
static  OS_STK       App_1_TaskStk[APP_1_OS_CFG_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  /* APP_TCPIP_EN */

static  CPU_INT32S   App_Clk_UTC_Offset;

static  CPU_INT08S   OSCPUUsageMax;


/*
*********************************************************************************************************
*                                          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  /* APP_TCPIP_EN */

#if APP_FS_EN
static  void       App_InitFS          (void);
#endif  /* APP_FS_EN */

#if APP_DHCPc_EN
static  void       App_InitDHCPc       (void);
static  void       DHCPc_Print         (DHCP_HDR    *d);
static  void       DHCPc_PrintOptions  (CPU_INT08U  *options);
static  CPU_CHAR  *DHCPc_GetOperStr    (CPU_INT32U   op);
static  CPU_CHAR  *DHCPc_GetOptStr     (CPU_INT32U   op);
#endif  /* APP_DHCPc_EN */

#if APP_DNSc_EN
static  void       App_TestDNSc        (void);
#endif  /* APP_DNSc_EN */

#if APP_FTPc_EN
static  void       App_TestFTPc        (void);
#endif  /* APP_FTPc_EN */

#if APP_POP3c_EN
static  void       App_TestPOP3c       (void);
#endif  /* APP_POP3c_EN */

#if APP_SMTPc_EN
static  void       App_TestSMTPc       (void);
#endif  /* APP_SMTPc_EN */

#if APP_SNTPc_EN
static  void       App_TestSNTPc       (void);
#endif  /* APP_SNTPc_EN */


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

int  main (void)
{
#if (OS_TASK_NAME_SIZE >= 16)
    CPU_INT08U  os_err;
#endif  /* (OS_TASK_NAME_SIZE >= 16) */


   (void)&App_Clk_UTC_Offset;

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

    BSP_Init();                                                 /* Initialize BSP.                                      */

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

                                                                /* Create start task.                                   */
    OSTaskCreateExt( App_TaskStart,
                    (void *)0,
                    (OS_STK *)&App_StartTaskStk[APP_START_OS_CFG_TASK_STK_SIZE - 1],
                     APP_START_OS_CFG_TASK_PRIO,
                     APP_START_OS_CFG_TASK_PRIO,
                    (OS_STK *)&App_StartTaskStk[0],
                     APP_START_OS_CFG_TASK_STK_SIZE,
                    (void *)0,
                     OS_TASK_OPT_STK_CHK | OS_TASK_OPT_STK_CLR);

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

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


/*
*********************************************************************************************************
*                                             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       argument passed to 'AppTaskStart()' 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.
*********************************************************************************************************
*/

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


    APP_TRACE_DEBUG(("Initialize OS timer...\n"));
    Tmr_Init();                                                 /* Initialize OS timer.                                 */

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

    APP_TRACE_DEBUG(("Create application task...\n"));
    App_TaskCreate();                                           /* Create application task.                             */

#if APP_FS_EN
    App_InitFS();                                               /* Initialize file system.                              */
#endif  /* APP_FS_EN */

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

#if APP_DHCPc_EN
    App_InitDHCPc();                                            /* Initialize DHCP client.                              */
#endif  /* APP_DHCPc_EN */

#if APP_HTTPs_EN
    APP_TRACE_DEBUG(("Initialize HTTP server...\n"));
    HTTPs_Init();                                               /* Initialize HTTP server.                              */
#endif  /* APP_HTTPs_EN */

#if APP_FTPs_EN
    APP_TRACE_DEBUG(("Initialize FTP server...\n"));
    FTPs_Init(App_IP_Addr, FTPs_CFG_DTP_IPPORT);                /* Initialize FTP server.                               */
#endif  /* APP_FTPs_EN */

#if APP_TFTPs_EN
    APP_TRACE_DEBUG(("Initialize TFTP server...\n"));
    TFTPs_Init();                                               /* Initialize TFTP server.                              */
#endif  /* APP_TFTPs_EN */

#if APP_DNSc_EN
    DNSc_Init(App_IP_DNS_Srvr);                                 /* Initialize DNS client.                               */

    App_TestDNSc();                                             /* Test DNS client.                                     */
#endif  /* APP_DNSc_EN */

#if APP_FTPc_EN
    App_TestFTPc();                                             /* Test FTP client.                                     */
#endif  /* APP_FTPc_EN */

#if APP_POP3c_EN
    App_TestPOP3c();                                            /* Test POP3 client.                                    */
#endif  /* APP_POP3c_EN */

#if APP_SMTPc_EN
    App_TestSMTPc();                                            /* Test SMTP client.                                    */
#endif  /* APP_SMTPc_EN */

#if APP_SNTPc_EN
    App_TestSNTPc();                                            /* Test SNTP client.                                    */
#endif  /* APP_SNTPc_EN */

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

    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_TFTPs_EN
#if (TFTPs_TRACE_LEVEL >= TRACE_LEVEL_INFO)
        TFTPs_Disp();
        TFTPs_DispTrace();
#endif  /* (TFTPs_TRACE_LEVEL >= TRACE_LEVEL_INFO) */
#endif  /* APP_TFTPs_EN */
    }
}


#if APP_FS_EN
/*
*********************************************************************************************************
*                                        INITIALIZE FILE SYSTEM
*********************************************************************************************************
*/

static  void  App_InitFS (void)
{
    CPU_INT32U  rtn_val;


    APP_TRACE_DEBUG(("Initialize filesystem...\n"));
    FS_Init();
    rtn_val = FS_IoCtl("ram:", FS_CMD_REQUIRES_FORMAT, 0, 0);
    if (rtn_val != 0) {
        APP_TRACE_DEBUG(("Cannot format RAM disk.\n"));
    }
}

⌨️ 快捷键说明

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