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

📄 app.c

📁 ucos porting source for samsung sam7x256
💻 C
字号:
/*
*********************************************************************************************************
*                                                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];

#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);

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

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

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


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

int  main (void)
{
    CPU_INT08U 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)
{
    CPU_INT08S i;
    CPU_INT08S j;


    (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
    AppInit_OSView();                               /* Initialize uC/OSView                            */
#endif

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

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

    while (DEF_TRUE) {                              /* Task body, always written as an infinite loop.  */
        for (j = 0; j < 4; j++) {
            for (i = 1; i <= 4; i++) {
                LED_On(i);
                OSTimeDlyHMSM(0, 0, 0, 25);
                LED_Off(i);
                OSTimeDlyHMSM(0, 0, 0, 25);
            }

            for (i = 3; i >= 2; i--) {
                LED_On(i);
                OSTimeDlyHMSM(0, 0, 0, 25);
                LED_Off(i);
                OSTimeDlyHMSM(0, 0, 0, 25);
            }
        }

        for (i = 0; i < 4; i++) {
            LED_On(0);
            OSTimeDlyHMSM(0, 0, 0, 50);
            LED_Off(0);
            OSTimeDlyHMSM(0, 0, 0, 50);
        }
    }
}


/*
*********************************************************************************************************
*                                     uC/OS-View TERMINAL WINDOW CALLBACK
*********************************************************************************************************
*/

#if OS_VIEW_MODULE > 0
static  void  AppTerminalRx (CPU_INT08U rx_data)
{
}
#endif


/*
*********************************************************************************************************
*                                      AppInit_OSView()
*
* Description : This function is called by AppTaskStart() and is responsible for initializing uC/OSView
*
*********************************************************************************************************
*/

#if OS_VIEW_MODULE > 0
static void AppInit_OSView (void)
{
    OSView_Init(38400);
    OSView_TerminalRxSetCallback(AppTerminalRx);
    OSView_RxIntEn();
}
#endif


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

static void AppInit_TCPIP (void)
{
#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] = 0x60;
    NetIF_MAC_Addr[5] = 0x01;
#endif

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

    ip      = NetASCII_Str_to_IP("10.10.1.23",  &err);
    msk     = NetASCII_Str_to_IP("255.255.255.0", &err);
    gateway = NetASCII_Str_to_IP("10.10.1.1",   &err);

    err     = NetIP_CfgAddrThisHost(ip, msk);
    err     = NetIP_CfgAddrDfltGateway(gateway);
}

⌨️ 快捷键说明

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