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

📄 app.c

📁 ucosII在DRAGONBALL MX21上的移植 开发环境为IAR
💻 C
📖 第 1 页 / 共 2 页
字号:
/*
*********************************************************************************************************
*                                                uC/OS-II
*                                          The Real-Time Kernel
*
*                                 (c) Copyright 2004, Micrium, Weston, FL
*                                          All Rights Reserved
*
*                                            Freescale i.MX21ADS
*                                              Sample code
* File : APP.C
* By   : Eric Shufro
*********************************************************************************************************
*/

#include <includes.h>

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

static  OS_STK        AppTaskStartStk[APP_TASK_START_STK_SIZE];
static  OS_STK        EricSocketSendTestStack[APP_TASK_START_STK_SIZE];

        INT8S         OSCPUUsageMax;

#if uC_TCPIP_MODULE > 0
        NET_IP_ADDR   ip;
        NET_IP_ADDR   msk;
        NET_IP_ADDR   gateway;
        NET_ERR       err;
#endif

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

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

#if OS_VIEW_MODULE > 0
static  void  AppTerminalRx(INT8U rx_data);
#endif

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

int  main (void)
{
    INT8U err;


    BSP_IntDisAll();                            /* Disable ALL interrupts to the interrupt controller  */

    OSInit();                                   /* Initialize uC/OS-II                                 */

                                                /* Create start task                                   */
    OSTaskCreateExt(AppTaskStart,
                    NULL,
                    (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,
                    NULL,
                    OS_TASK_OPT_STK_CHK | OS_TASK_OPT_STK_CLR);

                                                /* Assign names to created tasks                       */
#if OS_TASK_NAME_SIZE > 11
    OSTaskNameSet(APP_TASK_START_PRIO, "Start Task", &err);
#endif

    OSStart();                                  /* Start uC/OS-II                                      */
}

/*$PAGE*/
/*
*********************************************************************************************************
*                                              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 'AppStartTask()' 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.
*               2) Interrupts are enabled once the task start because the I-bit of the CCR register was
*                  set to 0 by 'OSTaskCreate()'.
*********************************************************************************************************
*/

static  void  AppTaskStart (void *p_arg)
{
    INT8U   createTaskErr;
    INT8U   userDefinedMACAddress[6];
#if uC_DHCPc_MODULE == 1                           /* If DHCP is enabled, declare a few variables      */
    INT8U   ParamRequestList[1];
    INT8U  *opt;
#endif

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

    BSP_Init();                                     /* Initialize the BSP                              */

#if OS_TASK_STAT_EN > 0
    OSStatInit();                                   /* Start stats task                                */
#endif

#if OS_VIEW_MODULE > 0
    OSView_Init(38400);                             /* OSView Init, baud rate = 38400                  */
    OSView_TerminalRxSetCallback(AppTerminalRx);
    OSView_RxIntEn();                               /* Enable Rx Interrupts                            */
#endif

#if uC_TCPIP_MODULE > 0
    err = Net_Init();                               /* Initialize uC/TCP-IP                            */

                                                    /* Initialize the MAC address via software         */
#if CS8900A_CFG_MAC_ADDR_SEL == CS8900A_MAC_ADDR_SEL_CFG
    userDefinedMACAddress[0] = 0x00;
    userDefinedMACAddress[1] = 0x50;
    userDefinedMACAddress[2] = 0xC2;
    userDefinedMACAddress[3] = 0x25;
    userDefinedMACAddress[4] = 0x60;
    userDefinedMACAddress[5] = 0x01;
    NetIF_MAC_AddrSet(userDefinedMACAddress, &err); /* Configure the stack to use this MAC Address     */
    NetNIC_MAC_AddrSet(userDefinedMACAddress, &err);/* Configure the NIC registers for this MAC Address*/
#endif
                                                    /* Set the target's IP address and mask            */
#if uC_DHCPc_MODULE == 0                            /* If DHCP is disabled, use a static IP address    */
    ip      = NetASCII_Str_to_IP("192.168.0.60",  &err);
    msk     = NetASCII_Str_to_IP("255.255.255.0", &err);
    gateway = NetASCII_Str_to_IP("192.168.1",     &err);
    err     = NetIP_CfgAddrThisHost(ip, msk);
    err     = NetIP_CfgAddrDfltGateway(gateway);
#else                                               /* If DHCP is enabled, configure the host for DHCP */
     NetIP_CfgAddrThisHost(NET_IP_ADDR_THIS_HOST, NET_IP_ADDR_NONE);
     NetIP_CfgAddrDfltGateway(NET_IP_ADDR_NONE);
     DHCPc_SetMacAddr(NetIF_MAC_Addr);              /* Configure DHCP                                  */
     DHCPc_SetClientID(0x01, NetIF_MAC_Addr, NET_IF_ADDR_SIZE);
     DHCPc_SetVendorClassID("Micrium", 7);
     ParamRequestList[0] = DHCP_OPT_DOMAIN_NAME_SERVER;
     DHCPc_SetParamRequestList(ParamRequestList,    sizeof(ParamRequestList) / sizeof(ParamRequestList[0]));

     err = DHCPc_Start();                           /* Obtain an IP address from DHCP server           */
     if (err != DHCPc_ERR_NONE) {
         while (1) {
         }
     }

     DHCPc_CfgStack();                              /* Configure uC/TCP-IP with the dhcp addresses     */

     Mem_Copy ((void*)&ip, (void*)&(DHCPc_GetHdr()->yiaddr), sizeof (DHCPc_GetHdr()->yiaddr));
     ip = htonl(ip);

     opt = DHCPc_GetOpt(DHCP_OPT_SUBNET_MASK);      /* Get subnet mask                                 */
     if (opt != (void *)0) {
         Mem_Copy ((void*)&msk, (void*)(opt + 2), *(CPU_INT08U*)(opt + 1));
         msk = htonl(msk);
     }

     opt = DHCPc_GetOpt(DHCP_OPT_ROUTER);           /* Get gateway address                             */
     if (opt != (void *)0) {
         Mem_Copy ((void*)&gateway, (void*)(opt + 2), *(CPU_INT08U*)(opt + 1));
         gateway = htonl(gateway);
     }
#endif                                              /* DHCPc Module                                    */
#endif                                              /* TCP/IP Module                                   */


#if uC_FS_MODULE > 0
    FS_Init();                                      /* Initialize uC/FS                                */
#if FS_USE_RAMDISK_DRIVER > 0
    FS_IoCtl("ram:", FS_CMD_FORMAT_MEDIA, FS_MEDIA_RAM_512KB, 0);
#endif
#endif

#if uC_TCPIP_HTTPs_MODULE > 0
    HTTPs_Init();                                   /* Initialize uC/HTTPs                             */
#endif

#if uC_TFTP_MODULE > 0
    TFTPs_Init(OS_TICKS_PER_SEC);                   /* Initialize the uC/TFTPs                         */
#endif

   OSTaskCreateExt(EricSocketSendTestTask,
                NULL,
                (OS_STK *)&EricSocketSendTestStack[APP_TASK_START_STK_SIZE - 1],
                6,
                6,
                (OS_STK *)&EricSocketSendTestStack[0],
                APP_TASK_START_STK_SIZE,
                NULL,
                OS_TASK_OPT_STK_CHK | OS_TASK_OPT_STK_CLR);

#if OS_TASK_NAME_SIZE > 11
    OSTaskNameSet(6, "Socket Test Task", &createTaskErr);
#endif

    LED_Off(0);                                     /* Turn on ALL the LEDs                            */

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

        if (OSCPUUsageMax < OSCPUUsage) {
            OSCPUUsageMax = OSCPUUsage;
        }

        OSTimeDlyHMSM(0, 0, 0, 500);
    }
}

⌨️ 快捷键说明

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