Here are the steps to merge a Sensor Controller (SC) example into the simple_peripheral example (CC2640R2F / BLE3):
The steps could be reused for all the devices having a Sensor Controller.
Before we start:
- Make sure to review the documentation for the Sensor Controller.
- Make sure to follow our SimpleLink Academy labs about the Sensor Controller.
- If not already done, install Sensor Controller Studio: https://www.ti.com/tool/SENSOR-CONTROLLER-STUDIO
Here is the step by step guide:
- Open Sensor Controller Studio (SCS), open the example LED Blinker for CC2640R2F
- Generate the code – look at the files generated and find the path for the projects
- Open CCS. Import the project generated by SCS for TIRTOS.
- Build and test (use the buttons to turn on and off blinking)
- Import the simple_peripheral example
- Build simple_peripheral (test it if you want)
- Merge the SC example into the simple_peripheral example
Note: We will not use the buttons here – the LEDs will be always blinking.- Copy-paste the files scif.c, scif.h, scif_framework.c, scif_framework.h, scif_osal_tirtos.h into the project. I have kept links to these files (but could be done differently).
Note: if you use a link to the files, CCS will ask you if you wish to add an include path, answer yes (or add the path manually). - Copy-paste the initialization of the SC in the SimplePeripheral_taskFxn.
Copy-paste the enabling of the green led in the SimplePeripheral_taskFxn.static void SimplePeripheral_taskFxn(UArg a0, UArg a1) { // Initialize application SimplePeripheral_init(); //**************************************// // This code for SC initialization // //**************************************// // Initialize and start the Sensor Controller scifOsalInit(); scifOsalRegisterCtrlReadyCallback(scCtrlReadyCallback); scifOsalRegisterTaskAlertCallback(scTaskAlertCallback); scifInit(&scifDriverSetup); scifStartRtcTicksNow(0x00010000 / 10); scifStartTasksNbl(BV(SCIF_LED_BLINKER_TASK_ID)); //*************************************// // This code for GLED initialization // //************************************// // Enable LED pins hLedPins = PIN_open(&ledPinState, pLedPinTable); // Application main loop for (;;) { uint32_t events; // Waits for an event to be posted associated with the calling thread. // Note that an event associated with a thread is posted when a // message is queued to the message receive queue of the thread events = Event_pend(syncEvent, Event_Id_NONE, SBP_ALL_EVENTS, ICALL_TIMEOUT_FOREVER);
- Copy-paste the include required.
Copy-paste the symbols required.
Copy-paste the callback functions (the content of the callback will be modified after).#include "scif.h" PIN_Config pLedPinTable[] = { Board_GLED | PIN_GPIO_OUTPUT_EN | PIN_GPIO_LOW | PIN_PUSHPULL | PIN_DRVSTR_MAX, PIN_TERMINATE }; PIN_State ledPinState; PIN_Handle hLedPins; void scCtrlReadyCallback(void) { } // scCtrlReadyCallback void scTaskAlertCallback(void) { SimplePeripheral_enqueueMsg(SBP_SC_ALERT, NULL, NULL); } // scTaskAlertCallback
- Modify the content of the SC callback functions. The simple_peripheral example uses messages (not semaphore) to pass events to the main loop. We will use the function SimplePeripheral_enqueueMsg() to enqueue the messages. An additional application event (SBP_SC_ALERT) will be defined. The code to execute when this event is raised will be copied from the sensor controller example.
Here is the application event declared:// Application events #define SBP_STATE_CHANGE_EVT 0x0001 #define SBP_CHAR_CHANGE_EVT 0x0002 #define SBP_PAIRING_STATE_EVT 0x0004 #define SBP_PASSCODE_NEEDED_EVT 0x0008 #define SBP_CONN_EVT 0x0010 #define SBP_SC_ALERT 0x0099 // This one get added
Here is the code to handle the SBP_SC_ALERT events (added in SimplePeripheral_processAppMsg):
static void SimplePeripheral_processAppMsg(sbpEvt_t *pMsg) { switch (pMsg->hdr.event) { // ... case SBP_CONN_EVT: { SimplePeripheral_processConnEvt((Gap_ConnEventRpt_t *)(pMsg->pData)); ICall_free(pMsg->pData); break; } //*********************// // This code is added // //*********************// case SBP_SC_ALERT: { // Clear the ALERT interrupt source scifClearAlertIntSource(); // If the LED blinker task has not been stopped ... if (scifGetActiveTaskIds() & BV(SCIF_LED_BLINKER_TASK_ID)) { // Indicate value of the output counter variable on the green LED PIN_setOutputValue(hLedPins, Board_GLED, (scifTaskData.ledBlinker.output.counter & 0x0001) != 0); } // Acknowledge the ALERT event scifAckAlertEvents(); break; } //*********************// // End of added code // //*********************// default: // Do nothing. break; } }
- If it helps, here my diff file for the simple_peripheral.c file (yes, only one file get modified): /cfs-file/__key/communityserver-discussions-components-files/538/simple_5F00_peripheral_5F00_c.diff
- Copy-paste the files scif.c, scif.h, scif_framework.c, scif_framework.h, scif_osal_tirtos.h into the project. I have kept links to these files (but could be done differently).
- Build and test. The example should keep blinking the LEDs and have all the functionalities of the simple_peripheral example.