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.

Limitations with timers and CC3000?



I am using the following software:
Release Pack ver: 1.11.1
System Pack ver: 5.14.7.13
Service Pack ver: 1.24
I have it kind of working if I put it in a separate function call, my main problem now is that I want to use a timer that will check or send information every second or so but none of the functions related to the CC3000 API works when they are used in a timer function, by that I mean that recvfrom or sendto does not work. Or am I missing something here?

Does anyone here have any idee to why there is a direct problem when using timers? The system always ends up spi.c line 651, the following code:

// Due to the fact that we are currently implementing a blocking situation
// here we will wait till end of transaction
while (eSPI_STATE_IDLE != sSpiInformation. ulSpiState )
{
 ;
}
return(0);



Here is my code for setting up the timer:
// Enable processor interrupts.
IntMasterEnable ();

// Configure 32-bit periodic timers.
TimerConfigure (TIMER0_BASE, TIMER_CFG_PERIODIC);
TimerLoadSet (TIMER0_BASE, TIMER_A, SysCtlClockGet ());

// Setup the interrupts for the timer timeouts.
IntEnable (INT_TIMER0A);
TimerIntEnable (TIMER0_BASE, TIMER_TIMA_TIMEOUT);
ROM_TimerLoadSet( TIMER0_BASE, TIMER_A, ROM_SysCtlClockGet()*2);
TimerEnable (TIMER0_BASE, TIMER_A);

This is the timer function:
void Timer0IntHandler( void )
{
        // Clear the timer interrupt.
       TimerIntClear (TIMER0_BASE, TIMER_TIMA_TIMEOUT);
       pcData = "C" ;
       ulDataLength = 1;
       sendto(Client_Socket, pcData, ulDataLength, 0, &addrClient, sizeof (sockaddr ));
}
  •  Hi Martin,

    I have not tried APIs directly in timer/interrupt context. Since most of the APIs are blocking in your case, I'm not sure if the platform allows you to do that. Can you please try with 'SOCKOPT_RECV_NONBLOCK' flag set to '1' in setsockopt?

    Thanks & Regards,

    Raghavendra

  • Thank you for starting a conversation so fast Raghavendra!

     setsockopt

    //!  @Note   On this version the following two socket options are enabled:
    //!              The only protocol level supported in this version
    //!          is SOL_SOCKET (level).
    //!            1. SOCKOPT_RECV_TIMEOUT ( optname)
    //!               SOCKOPT_RECV_TIMEOUT configures recv and recvfrom timeout
    //!           in milliseconds.
    //!             In that case optval should be pointer to unsigned long.
    //!            2. SOCKOPT_NONBLOCK ( optname). sets the socket non-blocking mode on
    //!           or off.
    //!             In that case optval should be SOCK_ON or SOCK_OFF (optval).
    //!
    //!  @sa getsockopt
    //
    //----------- Socket Options -----------
    #define  SOL_SOCKET             0xffff      //  socket level
    #define  SOCKOPT_RECV_TIMEOUT   1           //  optname to configure recv and recvfromtimeout
    #define  SOCKOPT_NONBLOCK       2           // accept non block mode set SOCK_ON or SOCK_OFF (default block mode )
    #define  SOCK_ON                0           // socket non-blocking mode is enabled
    #define  SOCK_OFF               1           // socket blocking mode is enabled
    Your writing "SOCKOPT_RECV_NONBLOCK" but I am guessing that I should use "SOCKOPT_NONBLOCK", correct? I am not sure what you mean by setting the flag to "1" 
    This is how I have configured setsockopt:
    int nonBlocking = SOCK_ON;
    setsockopt(iReturnSOCKETServer, SOL_SOCKET, SOCKOPT_NONBLOCK, &nonBlocking, sizeof (nonBlocking));
    Here is the entire code I would like to use in the timer:
    struct timeval timeout;
    timeout. tv_sec = 0;
    timeout. tv_usec = 5000;
    fd_set fdSet;
    FD_ZERO(&fdSet);
    memset (&addrServer.sa_data [2], 0, 4);
    int i;
    for (i=0; i<24; i++)
         ucRx_Buffer[i] = 0;
    iReturnBINDServer = bind(iReturnSOCKETServer, &addrServer, sizeof (sockaddr ));

    int nonBlocking = SOCK_ON;
    setsockopt(iReturnSOCKETServer, SOL_SOCKET, SOCKOPT_NONBLOCK, &nonBlocking, sizeof (nonBlocking));

    FD_SET(iReturnSOCKETServer, &fdSet);
    select(iReturnSOCKETServer+1, &fdSet, NULL, NULL, &timeout);

    iReturnREQUESTServer = recvfrom(iReturnSOCKETServer, ucRx_Buffer, CC3000_APP_BUFFER_SIZE, 0, &addrServer, &tRxPacketLength);
    UARTprintf ("Command: %c\n" ,ucRx_Buffer[0]);
  • Hi Martin,

    Which version of the SDK are you using? I'm using 1.11. Hence, I mentioned "SOCKOPT_RECV_NONBLOCK", which should be equivalent to "SOCKOPT_NONBLOCK". However, I would suggest you to get the latest SDK.

    The code looks alright, as long as you don't have problem working from timer context. By flag '1' I mean SOCK_ON.

    Thanks & Regards,

    Raghavendra