This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

请教网络数据接收的问题



例程中的是通过调用sl_Recv()函数去查询是否有数据到来

请问当有网络数据来的时候 能不能以中断的形式通知。这样就能及时处理每个接收的网络数据并建立消息队列。

  • 或者说我怎样能做到一有消息就能及时处理

    而不是查询,因为调用sl_Recv()只是查到了最新的数据,最新的数据将历史的覆盖了

  • 可以通过NWP-IRO 唤醒M4内核

    参考如下测试代码

    1. //*****************************************************************************
    2. //
    3. // Application Name     - Idle Profile
    1. // Application Overview - Idle profile enables the user to measure current
    2. //                        values, power consumption and other such parameters
    3. //                        for CC3200, when the device is essentially idle(both
    4. //                        NWP and APPS subsystems in low power deep sleep
    1. //                        condition). The other main objective behind this
    1. //                        application is to introduce the user to the easily
    2. //                        configurable power management framework.
    3. // Application Details  -
    4. // http://processors.wiki.ti.com/index.php/CC32xx_Idle_Profile_Application
    5. // or
    1. // docs\examples\CC32xx_Idle_Profile_Application.pdf

     

    1. //*****************************************************************************
    2. //
    1. //! \brief Task Created by main fucntion.This task starts simpleink, set NWP
    1. //!        power policy, connects to an AP. Give Signal to the other task about
    2. //!        the connection.wait for the message form the interrupt handlers and
    3. //!        the other task. Accordingly print the wake up cause from the low
    4. //!        power modes.
    5. //!
    1. //! \param pvParameters is a general void pointer (not used here).
    1. //!
    1. //! \return none
    2. //
    3. //*****************************************************************************
    4. void TimerGPIOTask(void *pvParameters)
    5. {
    6.     cc_hndl tTimerHndl = NULL;
    7.     cc_hndl tGPIOHndl = NULL;

        unsigned char ucQueueMsg = 0;

        unsigned char ucSyncMsg = 0;

        int iRetVal = 0;

        //

        // Displays the Application Banner

        //

        DisplayBanner();

       

        //

        // creating the queue for signalling about connection events

        //

        iRetVal = osi_MsgQCreate(&g_tConnection, NULL, sizeof( unsigned char ), 3);

        if (iRetVal < 0)

        {

            UART_PRINT("unable to create the msg queue\n\r");

            LOOP_FOREVER();

        }

       

        //

        // starting the simplelink

        //

        iRetVal = sl_Start(NULL, NULL, NULL);

        if (iRetVal < 0)

        {

            UART_PRINT("Failed to start the device \n\r");

            LOOP_FOREVER();

        }

     

        //

        // Swtich to STA mode if device is not

        //

        SwitchToStaMode(iRetVal);

       

        //

        // Set the power management policy of NWP

        //

        iRetVal = sl_WlanPolicySet(SL_POLICY_PM, SL_NORMAL_POLICY, NULL, 0);

        if (iRetVal < 0)

        {

            UART_PRINT("unable to configure network power policy\n\r");

            LOOP_FOREVER();

        }

     

        //

        // connecting to the Access Point

        //

        if(-1 == WlanConnect())

        {

            sl_Stop(SL_STOP_TIMEOUT);

            UART_PRINT("Connection to AP failed\n\r");

        }

        else

        {

            UART_PRINT("Connected to AP\n\r");

            //

            //signal the other task about the sl start and connection to the AP

            //

            iRetVal = osi_MsgQWrite(&g_tConnectionFlag, &ucSyncMsg,OSI_WAIT_FOREVER);

            if (iRetVal < 0)

            {

                UART_PRINT("unable to create the msg queue\n\r");

                LOOP_FOREVER();

            }

        }

       

        //

        // Queue management related configurations

        //

        iRetVal = osi_MsgQCreate(&g_tWkupSignalQueue, NULL,

                                 sizeof( unsigned char ), 10);

        if (iRetVal < 0)

        {

            UART_PRINT("unable to create the msg queue\n\r");

            LOOP_FOREVER();

        }

     

        //

        // setting Timer as one of the wakeup source

        //

        tTimerHndl = SetTimerAsWkUp();

       

        //

        // setting some GPIO as one of the wakeup source

        //

        tGPIOHndl = SetGPIOAsWkUp();

       

        /* handles, if required, can be used to stop the timer, but not used here*/

        UNUSED(tTimerHndl);

        UNUSED(tGPIOHndl);

        //

        // setting Apps power policy

        //

        lp3p0_setup_power_policy(POWER_POLICY_STANDBY);      //设置M4内核低功耗模式=LPDS模式 

                                                             //通过空闲回调函数vApplicationIdleHook()将该LPDS参数传递到CPU进入的低功耗模式

        while(FOREVER)                                       //当CPU进入LPDS后通过按键 /Timer /NWP-IRQ唤醒的

        {

            //

            // waits for the message from the various interrupt handlers(GPIO,Timer) and the UDPServerTask.

            //

            osi_MsgQRead(&g_tWkupSignalQueue, &ucQueueMsg, OSI_WAIT_FOREVER);

            switch(ucQueueMsg){

            case 1:

                UART_PRINT("timer\n\r");    //通过定时器定时到后唤醒CPU,进入TimerCallback()回调函数写入队列信息进入该任务读取队列信息,打印该信息

                break;

            case 2:

                UART_PRINT("GPIO\n\r");     //IO产生<中断>后进入gpio_intr_hndlr()入口函数写入队列信息进入该任务读取队列信息,打印该信息

                break;                      //注意在idle_profile_nonos例程中配置的GPIO唤醒源,直接从CPU睡眠的地方进行唤醒的,并未进入中断函数执行!

            case 3:

                UART_PRINT("host irq\n\r"); //通过NWP收到数据后唤醒CPU-执行UDPServerTask写入信号量 Task creation for providing host_irq as a wake up source(LPDS)

                break;

            default:

                UART_PRINT("invalid msg\n\r");

                break;

            }

        }

    }

     

    //*****************************************************************************

    //

    //! \brief Task Created by main fucntion. This task creates a udp server and

    //!        wait for packets. Upon receiving the packet, signals the other task.

    //!

    //! \param pvParameters is a general void pointer (not used here).

    //!

    //! \return none

    //

    //*****************************************************************************

    void UDPServerTask(void *pvParameters)

    {

        unsigned char ucSyncMsg;

        unsigned char ucQueueMsg = 3;                 //信号量为3

        int iSockDesc = 0;

        int iRetVal = 0;

        sockaddr_in sLocalAddr;

        sockaddr_in sClientAddr;

        unsigned int iAddrSize = 0;

          

        //

        // waiting for the other task to start simplelink and connection to the AP

        // Blocked on a message from the Other Task(waiting for simplelink start and connection to AP)

        osi_MsgQRead(&g_tConnectionFlag, &ucSyncMsg, OSI_WAIT_FOREVER);           

        osi_MsgQDelete(&g_tConnectionFlag);

     

    //----------------------------------------建立UDP服务器------------------------------------------   

        //

        // configure the Server

        //

        sLocalAddr.sin_family = SL_AF_INET;

        sLocalAddr.sin_port = sl_Htons((unsigned short)APP_UDP_PORT);  //本机端口号

        sLocalAddr.sin_addr.s_addr = 0;                                //忽略本地IP地址!

       

        iAddrSize = sizeof(sockaddr_in);

       

        //

        // creating a UDP socket

        //

        iSockDesc = sl_Socket(SL_AF_INET,SL_SOCK_DGRAM, 0);

     

        if(iSockDesc < 0)

        {

            UART_PRINT("sock error\n\r");

            LOOP_FOREVER();

        }

       

        //

        // binding the socket

        //

        iRetVal = sl_Bind(iSockDesc, (SlSockAddr_t *)&sLocalAddr, iAddrSize);

        if(iRetVal < 0)

        {

            UART_PRINT("bind error\n\r");

            LOOP_FOREVER();

        }

    //--------------------------------------------------------------------------------------------------   

        while(FOREVER)

        {

            // NWP收到UDP的数据会自动唤醒M4内核

            // waiting on a UDP packet

            // As soon as the NWP subsystem receives any UDP packet, it will bring the APPS subsystem out of LPDS, if not already.

            iRetVal = sl_RecvFrom(iSockDesc, g_cBuffer, BUFF_SIZE, 0,( SlSockAddr_t *)&sClientAddr,(SlSocklen_t*)&iAddrSize );

            if(iRetVal > 0)

            {

                // 收到数据后读取sl_RecvFrom()            // signal the other task about receiving the UDP packet

                //

                osi_MsgQWrite(&g_tWkupSignalQueue, &ucQueueMsg, OSI_WAIT_FOREVER);    //写入队列信号量=3

            }

            else

            {

                UART_PRINT("recv error\n\r");

                LOOP_FOREVER();

            }

        } 

    }

       

    //****************************************************************************

    //                            MAIN FUNCTION

    // 采用USE_FREERTOS

    //****************************************************************************

    void main(void)

    {

        int iRetVal;

        //

        // Board Initialization

        //

        BoardInit();

       

        //

        // Configure the pinmux settings for the peripherals exercised

        //

        PinMuxConfig();

       

        //

        // Initialize the platform

        //

        platform_init();

     

        //

        // Configuring UART

        //

        g_tUartHndl = uart_open(PRCM_UARTA0);

     

    #ifdef DEBUG_GPIO    //打开了,在M4未进入LPDS时,GPIO 9一直点亮RED

        //

        // setting up GPIO for indicating the entry into LPDS

        //

        tGPIODbgHndl = cc_gpio_open(GPIO_09, GPIO_DIR_OUTPUT);   //这个LED灯在lp3p0_back_up_soc_data/lp3p0_restore_soc_data中调用控制

        cc_gpio_write(tGPIODbgHndl, GPIO_09, 1);

    #endif

        //

        // Start the SimpleLink Host

        //

        iRetVal = VStartSimpleLinkSpawnTask(SPAWN_TASK_PRIORITY);

        if(iRetVal < 0)

        {

            UART_PRINT("could not create simplelink task\n\r");

            LOOP_FOREVER();

        }

        //

        // sync object for inter thread communication

        //

        iRetVal = osi_MsgQCreate(&g_tConnectionFlag, NULL, sizeof( unsigned char ), 1);

        if(iRetVal < 0)

        {

            UART_PRINT("could not create msg queue\n\r");

            LOOP_FOREVER();

        }

     

        // 注意M4唤醒后执行恢复寄存器函数resume_from_S3()

        // Task creation for providing host_irq as a wake up source(LPDS)     // 在USR手机网络助手中(1)建立一个UDP client (2)增加CC3200的本机IP (3)向目的IP及端口号发送数据

        iRetVal =  osi_TaskCreate(UDPServerTask,(const signed char *)"UDP Server waiting to recv packets", OSI_STACK_SIZE, NULL, 1, NULL );   //任务优先级=1

        if(iRetVal < 0)

        {

            UART_PRINT("First Task creation failed\n\r");

            LOOP_FOREVER();

        }

     

        //

        // setting up timer and gpio as source for wake up from LPDS

        //

        iRetVal =  osi_TaskCreate(TimerGPIOTask,(const signed char*)"Configuring Timer and GPIO as wake src", OSI_STACK_SIZE, NULL, 1, NULL );//任务优先级=1

        if(iRetVal < 0)

        {

            UART_PRINT("Second Task creation failed\n\r");

            LOOP_FOREVER();

        }

     

        //

        // Start the task scheduler

        //

        osi_start();

     

    }

  • 感谢您的回答,虽然没在其中找到解决方案

    可能是我表述问题不够清晰