Complexity: medium
What do you need:
- two CC1310 LaunchPads
- Code Composer Studio
- TI RTOS
- Sensor Controller Studio
Sensor Controller Engine: WSN Node example (cont.)
The previous article showed how the Sensor Controller Engine (SCE) integrates with TI-RTOS.
It also explained how the SCE wakes up the ARM Cortex core and how that core then wakes up the Radio.
This time we check out when the SCE decides to wake up the application.
The application will have to wake up at a defined-by-us time, or faster if the analog input value changed beyond a threshold.
The code in the Sensor Controller Studio defines the mechanism for the two decisions.
In Code Composer Studio we set the configurations at the start of the program.
Sensor Controller Studio
The SCE code has a data structure to hold the configuration items.
There's a wizard to set up that structure.
In our Execution code, we make decisions based on the settings.
changes outside our sample value changeMask window
If the sampled value is inside our 'window of expected values' we just update a counter and continue to the next decision point.
If the analog value changed outside the window, we wake up the application and reset our counter
// Alert the driver if outside of change mask U16 adcMaskedBits = adcValue & cfg.changeMask; if (adcMaskedBits != state.oldAdcMaskedBits) { fwGenAlertInterrupt(); state.samplesSinceLastReport = 0; } else { state.samplesSinceLastReport = state.samplesSinceLastReport + 1; }
changes inside our sample value changeMask window
The next part of the code executes every time the samplesSinceLastReport reaches minReportInterval.
//Alert driver if minimum report interval has expired if(cfg.minReportInterval != 0) { if(state.samplesSinceLastReport >= cfg.minReportInterval) { fwGenAlertInterrupt(); state.samplesSinceLastReport = 0; } }
These two chunks define that the code wakes up the RTOS if we move the ADC with more delta than defined in the mask, else after a certain number of ticks.
What it doesn't say is what that mask is or how many ticks to wait. That happens in TI-RTOS.
Code Composer Studio
The parameters are set in NodeTask.c. In an RTOS program, it's common to define the configurations at the start of an RTOS task, before it starts looping.
/* A change mask of 0xFF0 means that changes in the lower 4 bits does not trigger a wakeup. */ #define NODE_ADCTASK_CHANGE_MASK 0xFF0 /* Minimum slow Report interval is 50s (in units of samplingTime)*/ #define NODE_ADCTASK_REPORTINTERVAL_SLOW 50 /* Minimum fast Report interval is 1s (in units of samplingTime) for 30s*/ #define NODE_ADCTASK_REPORTINTERVAL_FAST 1 #define NODE_ADCTASK_REPORTINTERVAL_FAST_DURIATION_MS 30000
When the RTOS runs our NodeTaskFunction() for he first time, it will prime the SCE.
static void nodeTaskFunction(UArg arg0, UArg arg1) { // ... /* Start the SCE ADC task with 1s sample period and reacting to change in ADC value. */ SceAdc_init(0x00010000, NODE_ADCTASK_REPORTINTERVAL_FAST, NODE_ADCTASK_CHANGE_MASK); SceAdc_registerAdcCallback(adcCallback); SceAdc_start(); /* setup timeout for fast report timeout */ Clock_setTimeout(fastReportTimeoutClockHandle, NODE_ADCTASK_REPORTINTERVAL_FAST_DURIATION_MS * 1000 / Clock_tickPeriod); /* start fast report and timeout */ Clock_start(fastReportTimeoutClockHandle); // ... while(1) { // we have seen this code in the previous blog // ... }
The SceAdc_xxx() functions are helpers defined in SceAdc.c.
Check them out in that file. Here's SceAdc_init() as example:
void SceAdc_init(uint32_t samplingTime, uint32_t minReportInterval, uint16_t adcChangeMask) { // Initialize the Sensor Controller scifOsalInit(); scifOsalRegisterCtrlReadyCallback(ctrlReadyCallback); scifOsalRegisterTaskAlertCallback(taskAlertCallback); scifInit(&scifDriverSetup); scifStartRtcTicksNow(samplingTime); SCIF_ADC_SAMPLE_CFG_T* pCfg = scifGetTaskStruct(SCIF_ADC_SAMPLE_TASK_ID, SCIF_STRUCT_CFG); pCfg->changeMask = adcChangeMask; //Set minimum report interval in units of samplingTime pCfg->minReportInterval = minReportInterval; }
There's more than the things I show in this blog - in particular some nice TI-RTOS and clock techniques.
It's worth digging trough both NodeTask.c and SceAdc.c until you fully understand each line in them.
It'll up your expertise in RTOS based application development.
SimpleLink Sub-1 GHz Wireless Microcontroller - Check Received Signal Strength |
SimpleLink Sub-1 GHz Wireless Microcontroller - Use SmartRF to Try Radio Configs |
SimpleLink Sub-1 GHz Wireless Microcontroller - Debug 2 LaunchPads at the Same Time |
SimpleLink Sub-1 GHz Wireless Microcontroller - Side Note: Recognise your PuTTY Sessions |
SimpleLink Sub-1 GHz Wireless Microcontroller - Side Note: Recognise your Code Composer Studio Sessions |
SimpleLink Sub-1 GHz Wireless Microcontroller - Debug a Sender to Receiver Conversation |
SimpleLink Sub-1 GHz Wireless Microcontroller - Side Note: Start a Fresh Project |
SimpleLink Sub-1 GHz Wireless Microcontroller - Create a Transmitter with SmartRF Studio Part 1 |
SimpleLink Sub-1 GHz Wireless Microcontroller - Create a Transmitter with SmartRF Studio Part 2 |
SimpleLink Sub-1 GHz Wireless Microcontroller - Sensor Controller Engine Part 1: Dry Run |
SimpleLink Sub-1 GHz Wireless Microcontroller - Sensor Controller Engine Part 2: RTOS Integration |
SimpleLink Sub-1 GHz Wireless Microcontroller - Sensor Controller Engine Part 3: Wake Up Options |
SimpleLink Sub-1 GHz Wireless Microcontroller - Side Note : Measure Power Use of Sensor Controller Engine |
SimpleLink Sub-1 GHz Wireless Microcontroller - ToolKit for Range Testing |
on TI E2E community: How to connect a CC1310 LaunchPad to the SIGFOX network |
Top Comments