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(¶ms); /* adc is handle name given to the adc port open by following API*/ adc2Handle = ADC_open(Board_ADC2, ¶ms); /* 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(¶ms); /* adc is handle name given to the adc port open by following API*/ adc3Handle = ADC_open(Board_ADC3, ¶ms); /* 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); }
//*********************************************************************************************************************************************