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.

[FAQ] CC2640R2F: How to merge a Sensor Controller example with simple_peripheral? (step-by-step guide)

Part Number: CC2640R2F

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:

Here is the step by step guide:

  1. Open Sensor Controller Studio (SCS), open the example LED Blinker for CC2640R2F
  2. Generate the code – look at the files generated and find the path for the projects
  3. Open CCS. Import the project generated by SCS for TIRTOS.
  4. Build and test (use the buttons to turn on and off blinking)
  5. Import the simple_peripheral example
  6. Build simple_peripheral (test it if you want)
  7. 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
        //  This code for SC initialization     //
        // Initialize and start the Sensor Controller
        scifStartRtcTicksNow(0x00010000 / 10);
        //  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,
    • 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[] = {
      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));
          // This code is added  //
      	case SBP_SC_ALERT:
              // Clear the ALERT interrupt source
              // 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
          // End of added code   //
            // Do nothing.

    • 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

  1. Build and test. The example should keep blinking the LEDs and have all the functionalities of the simple_peripheral example.