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.

CC1310: RTOS:Clock module reconfigure to new period on fly

Part Number: CC1310

I am sampling some sensor data and transmitting it through RF, now to control the sampling time ,I have configured a clock instance which times out periodically at 10 seconds. Now to reconfigure the clock period of the instance, I send a RF command from another CC1310(Gateway) to the CC1310 (node )which is connected to sensors, I  want to set the time period of clock to a new period on the fly (during runtime).

I use the  RF received packet to reassign or reconfigure the period of clock, but as I stop the clock instance and start it with new time period, I get an error intialising ADC channels and I2C which were working fine before reconfiguration. The function where I stop the clock instance and restart it with new time period is called from txTaskFunction  the program freezes after giving error in intialisation of ADC and I2C. 

I would appreciate any help regarding   this issue.

Following is brief code snippet of the application.

//*******************************************************************************************************
void TimeIntervalSet()
{
    if(boolTimeIntervalChange)
    {

             ui32NewPeriod=ui32Time_Interval*100000;
            // key = Hwi_disable();
            Clock_stop(clk1Handle);
            Clock_setTimeout(clk1Handle,ui32NewPeriod);
            Clock_setPeriod(clk1Handle,ui32NewPeriod);
            Clock_start(clk1Handle);
            //   key=Hwi_enable();
            //    Hwi_restore(key);
            boolTimeIntervalChange=false;
        
    }
}
//*******************************************************************************************
void SensorDataGet()
{

        /* Initialisation of ADC*/
    ADC_Params_init(&params);
    /* adc is handle name given to the adc port open by following API*/
    adc2Handle  = ADC_open(Board_ADC2, &params);
    /* Loop if there is error opening while ADC*/
    if (adc2Handle == NULL)
    {
        Display_print0(display, 0, 0, "Error initializing ADC channel 2\n");

    }
    else
    {
        Display_print0(display, 0, 0, "ADC channel 2 intialized \n");
    }
    /* Loop for sampling for the n number of samples count defined by macro ADC_SAMPLE_COUNT */
      //      
        else
        {
            Display_print0(display, 0, 0, "ADC channel 2 convert failed \n");
        }


    /* close the adc handle*/
    ADC_close(adc2Handle);

    /*****************Second ADC working starts here***************/


    /* Initialisation of ADC*/
    ADC_Params_init(&params);

    /* adc is handle name given to the adc port open by following API*/
    adc3Handle = ADC_open(Board_ADC3, &params);
    /* Loop if there is error opening while ADC*/
    if (adc3Handle == NULL)
    {
        Display_print0(display, 0, 0, "Error initializing ADC channel 3\n");

    }
    else
    {
        Display_print0(display, 0, 0, "ADC channel 3 intialized \n");
    }
    /* Loop for sampling for the n number of samples count defined by macro ADC_SAMPLE_COUNT */
           
        else
        {
            Display_print0(display, 0, 0, "ADC channel 3 convert failed \n");

        }
   

    /* close the adc handle*/
    ADC_close(adc3Handle);

    I2C_init();

    /* Create I2C for usage */
    I2C_Params_init(&i2cParams);
    i2cParams.bitRate = I2C_400kHz;
    i2cHandle = I2C_open(Board_I2C0, &i2cParams);

    if (i2cHandle == NULL)
    {
        Display_print0(display, 0, 0, "Error initializing I2C");

    }
    else
    {
        Display_print0(display, 0, 0, "I2C Initialized");

    }
     //  Loop for Getting sensor values via I2C interface
    //     boolpacketsend=true;


    I2C_close(i2cHandle);

}
//******************************************************************************************


/* TX task initialization function. Runs once from main() */
void txTaskInit()
{


    /* Initialize and create TX task */
    Task_Params_init(&txTaskParams);
    txTaskParams.stackSize = TX_TASK_STACK_SIZE;
    txTaskParams.priority = TX_TASK_PRIORITY;
    txTaskParams.stack = &txTaskStack;
    Task_construct(&txTask, txTaskFunction, &txTaskParams, NULL);
}

/* TX task function. Executed in Task context by TI-RTOS when the scheduler starts. */
static void txTaskFunction(UArg arg0, UArg arg1)
{
    /* Initialize the display and try to open both UART and LCD types of display. */
    /* Initialize the radio */
    RF_Params rfParams;
    RF_Params_init(&rfParams);

    /* Initialize TX_ADV command from TX command */
    initializeTxAdvCmdFromTxCmd(&RF_cmdPropTxAdv, &RF_cmdPropTx);

    /* Set application specific fields */
    RF_cmdPropTxAdv.pktLen = PAYLOAD_LENGTH +1; /* +1 for length byte */
    RF_cmdPropTxAdv.pPkt = packet;
    RF_cmdPropTxAdv.preTrigger.triggerType = TRIG_REL_START;
    RF_cmdPropTxAdv.preTime = WOR_PREAMBLE_TIME_RAT_TICKS(WOR_WAKEUPS_PER_SECOND);

    /* Enter main TX loop */
    while(1)
    {
        /* Wait for a button press */
        Semaphore_pend(txSemaphoreHandle, BIOS_WAIT_FOREVER);

        if(boolTimeIntervalChange)
         {
            TimeIntervalSet();
          }

        SensorDataGet();
        if(boolpacketsend==true)
        {
            /* Create packet with incrementing sequence number and random payload */
            packet[0] = PAYLOAD_LENGTH;
            packet[1] = (uint8_t)(seqNumber >> 8);
            packet[2] = (uint8_t)(seqNumber++);
            uint8_t i;
            for (i = 3; i < PAYLOAD_LENGTH +3; i++)
            {
                packet[i] = CharArray[i-3];
            }
            /* Send packet */
            ui32TerminationVar= RF_runCmd(rfHandle, (RF_Op*)&RF_cmdPropTxAdv, RF_PriorityNormal, NULL, 0);
            boolpacketsend=false;
            //            for (i = 0; i < PAYLOAD_LENGTH +1; i++)
            //                       {
            //
            //                           packet[i] = 0;
            //                           CharArray[i]=0;
            //                           ADC2ValueArray[i]=0;
            //                           ADC3ValueArray[i]=0;
            //                       }

        }
    }
}
//****************************************************************************************
/*
 *  ======== main ========
 */
int main(void)
{

    Clock_Params clkParams;


    Board_initGeneral();
    Board_initADC();

    /* Initialize TX semaphore */
    Semaphore_construct(&txSemaphore, 0, NULL);
    txSemaphoreHandle = Semaphore_handle(&txSemaphore);

    Clock_Params_init(&clkParams);
    clkParams.period = 800000;
    clkParams.startFlag = TRUE;

    /* Construct a periodic Clock Instance */
    Clock_construct(&clk1Struct, (Clock_FuncPtr)clk1Fxn,
                    500000, &clkParams);

    clk1Handle = Clock_handle(&clk1Struct);


    txTaskInit();
    rxTaskInit();

    BIOS_start();

    return (0);
}
//**************************************************************************************************************************************** Void clk1Fxn(UArg arg0) { Semaphore_post(txSemaphoreHandle); }
//*********************************************************************************************************************************************

  • Hi Prachi,

    Is this a problem when re-configuring the Clock in general, would "re-configure" it to still be 10s also crash the program?
    When you say the program freezes after giving the ADC and I2C errors, do you mean the timer has stopped or are you hitting any exception handler?

    Also, I'm I correct to assume the ADC and I2C errors are that you get null handles returned when performing the X_open call?
    If this is the case, can you step into the I2C and ADC open calls and see if you can figure out where in the open function the null handle is returned. Easiest way of doing this is to add the ADCCC26XX.c and I2CCC26XX.c driver source files (located in <SDK DIR>/source/ti/drivers/(i2c / adc)) to your project and add break points inside the open function.
  • Hello M-W,

    Thanks for your elaborate reply!

    I tried to review my application code and found that the clock instance ,ADC,I2C were working fine till the code uses sscanf function which is used to retrieve new clock period to be configured ,from the RF packet received. The sscanf function were executing well..but the ADC and I2C initialization were not executing and not returning a NULL handle. So I used strtok to retrieve data from packet...so now I'm able to reconfigure the clock on the fly. Also One more to mention the sprintf was also causing problem while working with TM4C123 Launchpad. I could not find out the reason why it caused the issue.

    Best Regards,
    Prachi
  • Hi Prachi,

    Glad you managed to work it out!

    Interesting what was causing the problem, thanks for coming back with your solution! I will need to look into how these functions and see how they work.