TI中文支持网
TI专业的中文技术问题搜集分享网站

请教网络接收函数的问题

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

请问当有网络数据来的时候 能不能以中断的形式通知。

gaoyang9992006:

好像是不可以的,不过有的资料写的是可以通过网络唤醒的。

http://www.deyisupport.com/question_answer/wireless_connectivity/wifi/f/105/t/74877.aspx

但是没试过怎么实现数据触发中断来接收。不知道你是不是没数据的时候就休眠

Terry Han:

参考如下测试代码

//*****************************************************************************
//
// Application Name     – Idle Profile

// Application Overview – Idle profile enables the user to measure current
//                        values, power consumption and other such parameters
//                        for CC3200, when the device is essentially idle(both
//                        NWP and APPS subsystems in low power deep sleep

//                        condition). The other main objective behind this

//                        application is to introduce the user to the easily
//                        configurable power management framework.
// Application Details  –
// http://processors.wiki.ti.com/index.php/CC32xx_Idle_Profile_Application
// or

// docs\examples\CC32xx_Idle_Profile_Application.pdf

 

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

//! \brief Task Created by main fucntion.This task starts simpleink, set NWP

//!        power policy, connects to an AP. Give Signal to the other task about
//!        the connection.wait for the message form the interrupt handlers and
//!        the other task. Accordingly print the wake up cause from the low
//!        power modes.
//!

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

//!

//! \return none
//
//*****************************************************************************
void TimerGPIOTask(void *pvParameters)
{
    cc_hndl tTimerHndl = NULL;
    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();

 

}

赞(0)
未经允许不得转载:TI中文支持网 » 请教网络接收函数的问题
分享到: 更多 (0)