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.

CCS/LAUNCHXL-CC1310: Adapting the TI 15.4 Stack Sensor example

Part Number: LAUNCHXL-CC1310
Other Parts Discussed in Thread: CC1350

Tool/software: Code Composer Studio

Hello guys,

I am struggling to make some changes to the TI 15.4 Stack Sensor (&collector) example code. I am trying to get the TIDA 00489 code to work in framework of this example, because in the end the code has to run on the TIDA Board!. Therefor I try to make as few changes as possible to get it work and afterwards I wanna "clean up" the code. Hence I only had to change the sensor.c file to get all the functionality. Here is what I changed. Note, that I deleted most of the original code in this code snipped for better comprehensibility, this is indicated by "...deleted".

/******************************************************************************
 Includes
 *****************************************************************************/
//_______________MY CHANGE START__________________

#include <ti/sysbios/family/arm/cc26xx/Power.h>
#include <ti/sysbios/family/arm/cc26xx/PowerCC2650.h>
#include <ti/drivers/I2C.h>
#include <ti/drivers/PIN.h>
#include <ti/drivers/pin/PINCC26XX.h>
#include <driverlib/sys_ctrl.h>
#include <TIDA-00489_Board.h>  <--- not sure if I better copy the relevant stuff into the provided board_gpio.c file (same for the TIDA-00489_Board.c).

#include <ti/sysbios/BIOS.h>
#include <ti/sysbios/knl/Task.h>
#include <ti/sysbios/knl/Clock.h>
#include <ti/sysbios/knl/Semaphore.h>

//_______________MY CHANGE END__________________

#include <string.h>
#include <stdint.h>
#include "util.h"
#include "api_mac.h"
#include "jdllc.h"
#include "ssf.h"
#include "smsgs.h"
#include "sensor.h"
#include "config.h"
#include "board_led.h"
#include "icall.h"

#ifdef FEATURE_NATIVE_OAD
#include "oad_client.h"
#ifdef DeviceFamily_CC13X2
#include <common/cc26xx/flash_interface/flash_interface.h>
#endif /* DeviceFamily_CC13X2 */
#endif /* FEATURE_NATIVE_OAD */

#ifdef MBEDTLS_CLIENT_NODE
#include "keymsg.h"
#include "tls_event.h"
#endif

/******************************************************************************
 Constants and definitions
 *****************************************************************************/

//_______________MY CHANGE START__________________

#define PIR_SETTLE_TIME      5000    //  5 seconds

//_______________MY CHANGE END__________________

...deleted

/******************************************************************************
 Global variables
 *****************************************************************************/
//_______________MY CHANGE START__________________
/* move counter */
extern uint8_t move;
 //_______________MY CHANGE END__________________


/* Task pending events */
uint16_t Sensor_events = 0;

/*! Sensor statistics */
Smsgs_msgStatsField_t Sensor_msgStats =
    { 0 };
extern bool initBroadcastMsg;
extern bool parentFound;
#ifdef POWER_MEAS
/*! Power Meas Stats fields */
Smsgs_powerMeastatsField_t Sensor_pwrMeasStats =
    { 0 };
#endif
/******************************************************************************
 Local variables
 *****************************************************************************/

//_______________MY CHANGE START__________________

static Semaphore_Struct radioSyncTxSem;
static Semaphore_Handle radioSyncTxSemHandle;
static Clock_Struct radioSyncTxClock;
static Clock_Handle radioSyncTxClockHandle;

/* Wake-up pin table (NOT IN USE, because no deep_sleep)
PIN_Config PinTableWakeUp[] = {
    Board_PIR_Out_Lo   | PIN_INPUT_EN | PIN_PULLDOWN | PINCC26XX_WAKEUP_POSEDGE,
    Board_PIR_Out_Hi   | PIN_INPUT_EN | PIN_PULLDOWN | PINCC26XX_WAKEUP_POSEDGE,
    PIN_TERMINATE                                 // Terminate list
}; */

/* Pin interrupt */ // Die genannten Pins werden Input enabled, kein Pull Up oder Down, und aufwachen bei positiver Flanke
PIN_Config intrPinTable[] = {
    Board_PIR_Out_Lo   | PIN_INPUT_EN | PIN_NOPULL | PIN_HYSTERESIS,
    Board_PIR_Out_Hi   | PIN_INPUT_EN | PIN_NOPULL | PIN_HYSTERESIS,
    PIN_TERMINATE
};
PIN_Handle intr_handle; // Pin_State benötigt ein "Handle" und dieses wird hier definiert
PIN_State  intr_state;

//_______________MY CHANGE END__________________

...deleted

/******************************************************************************
 Local function prototypes
 *****************************************************************************/

//_______________MY CHANGE START__________________

/* Static TIDA Functions */
static void initializeTIDATask(void)
static void radioSyncTxClockCallback(UArg a0)
void intr_HwiFxn(PIN_Handle hPin, PIN_Id pinId)

//_______________MY CHANGE END__________________

static void initializeClocks(void);
static void dataCnfCB(ApiMac_mcpsDataCnf_t *pDataCnf);
static void dataIndCB(ApiMac_mcpsDataInd_t *pDataInd);
static uint8_t getMsduHandle(Smsgs_cmdIds_t msgType);
static void processSensorMsgEvt(void);
#if SENSOR_TEST_RAMP_DATA_SIZE
static void processSensorRampMsgEvt(void);
#endif
static bool sendSensorMessage(ApiMac_sAddr_t *pDstAddr,
                              Smsgs_sensorMsg_t *pMsg);
static void processConfigRequest(ApiMac_mcpsDataInd_t *pDataInd);
static void processBroadcastCtrlMsg(ApiMac_mcpsDataInd_t *pDataInd);
static bool sendConfigRsp(ApiMac_sAddr_t *pDstAddr, Smsgs_configRspMsg_t *pMsg);
static uint16_t validateFrameControl(uint16_t frameControl);

static void jdllcJoinedCb(ApiMac_deviceDescriptor_t *pDevInfo,
                          Llc_netInfo_t  *pStartedInfo);
static void jdllcDisassocIndCb(ApiMac_sAddrExt_t *extAddress,
                               ApiMac_disassocateReason_t reason);
static void jdllcDisassocCnfCb(ApiMac_sAddrExt_t *extAddress,
                               ApiMac_status_t status);
static void jdllcStateChangeCb(Jdllc_states_t state);
static void readSensors(void);

/******************************************************************************
 Callback tables
 *****************************************************************************/
...deleted

/******************************************************************************
 Public Functions
 *****************************************************************************/
//_______________MY CHANGE START__________________

static void initializeTIDATask(void) // sollte man so lassen können
{
    /* Setup clock used for TIDA */
    Clock_Params radioSyncTxClockParams;
    Clock_Params_init(&radioSyncTxClockParams);
    radioSyncTxClockParams.startFlag = 0;
    radioSyncTxClockParams.period = 0; /* One-off clock */
    Clock_construct(&radioSyncTxClock, radioSyncTxClockCallback, 0, &radioSyncTxClockParams);
    radioSyncTxClockHandle = Clock_handle(&radioSyncTxClock);

    /* Create semaphore for TIDA */ //
    Semaphore_Params radioSyncTxParams;
    Semaphore_Params_init(&radioSyncTxParams);
    Semaphore_construct(&radioSyncTxSem, 0, &radioSyncTxParams);
    radioSyncTxSemHandle = Semaphore_handle(&radioSyncTxSem);
}


/* Callback Function of the clock, continuing the pended task */
static void radioSyncTxClockCallback(UArg a0)
{
    Semaphore_post(radioSyncTxSemHandle);
}

/* Interrupt Function!!! */
void intr_HwiFxn(PIN_Handle hPin, PIN_Id pinId)
{
    if(pinId == Board_PIR_Out_Lo || pinId == Board_PIR_Out_Hi)
    {
        move = move + 1;   //Instead of resetting the clock, add to the move variable
    }
}

//_______________MY CHANGE END__________________

/*!
 Initialize this application.

 Public function defined in sensor.h
 */
void Sensor_init(void)
{

//_______________MY CHANGE START__________________

    /* TIDA specific Sempahore and Clock initialize */
    initializeTIDATask();

    /* Backdoor access */
    uint8_t modeValue = PIN_getInputValue(Board_Mode); // Der Wert am Pin wird eingelesen, ist er 1 = high, so wird das Modul in den Shutdown Modus gefahren

    if(modeValue == 1)
    {
        Power_shutdown(NULL);

        //Trap code here
        while(1);
    }

    while(1)
    {

    //Wait for sensor to start up and settle
    Clock_setTimeout(radioSyncTxClockHandle, PIR_SETTLE_TIME);
    Clock_start(radioSyncTxClockHandle);
    Semaphore_pend(radioSyncTxSemHandle, BIOS_WAIT_FOREVER);

    //Check value of comparators. If not low, wait for more time
    uint8_t pirLowValue  = PIN_getInputValue(Board_PIR_Out_Lo);
    uint8_t pirHighValue = PIN_getInputValue(Board_PIR_Out_Hi);

        if(pirLowValue == 0 && pirHighValue == 0)   // Wenn beide low sind, sende das "Testpacket"
        {
            break;
        }
    }


    /*** Pin interrupt ***/
    // Configure GPIO interrupt
    intr_handle = PIN_open(&intr_state, intrPinTable);
    PIN_registerIntCb(intr_handle, &intr_HwiFxn);
    PIN_setConfig(intr_handle, PIN_BM_IRQ, Board_PIR_Out_Lo | PIN_IRQ_POSEDGE); // IRQ bei positiver Flanke ausgelöst
    PIN_setConfig(intr_handle, PIN_BM_IRQ, Board_PIR_Out_Hi | PIN_IRQ_POSEDGE); // IRQ bei positiver Flanke ausgelöst

//_______________MY CHANGE END__________________

    /********** Original Function of Sensor Example from now on********/
    uint32_t frameCounter = 0;

    /* Initialize the sensor's structures */
    memset(&configSettings, 0, sizeof(Smsgs_configReqMsg_t));
#if defined(TEMP_SENSOR)
    configSettings.frameControl |= Smsgs_dataFields_tempSensor;
#endif

...deleted

/*!
 * @brief   Manually read the sensors
 */
static void readSensors(void)
{
//_______________MY CHANGE START__________________

/* #if defined(TEMP_SENSOR)
    // Read the temp sensor values
    tempSensor.ambienceTemp = Ssf_readTempSensor();
    tempSensor.objectTemp =  tempSensor.ambienceTemp;
#endif */

    tempSensor.objectTemp = move;

    /* Reset move counter */
    move = 0;
}
//_______________MY CHANGE END_________________

I now wanna know, if

  1. How and whereshould I adapt the GPIO settings from the TIDA-Board.c looking like
    1. Board_PIR_Out_Lo                      IOID_16
    2. Board_PIR_Out_Hi                       IOID_17
    3. Board_Mode                                 IOID_3 into the correct syntax?
    4. -> In the Sensor example it is #include "boards/CC13X0_LAUNCHXL/Board.h" used, e.g. #define Board_DIO16_TDO         CC1350_LAUNCHXL_DIO16_TDO

In the Main.c file there is a line: PIN_init(BoardGpioInitTable); I defined a global function in board_gpio.h: extern PIN_Config BoardGpioInitTable[]; and the table itsself is defined in board_gpio.c

//______________MY CODE START______________

PIN_Config BoardGpioInitTable[] =
{
    Board_PIR_Out_Lo | PIN_INPUT_EN  | PIN_NOPULL | PIN_HYSTERESIS,                             /* PIR low                       */
    Board_PIR_Out_Hi | PIN_INPUT_EN  | PIN_NOPULL | PIN_HYSTERESIS,                             /* PIR high                      */
    Board_Mode       | PIN_INPUT_EN  | PIN_NOPULL | PIN_HYSTERESIS,                             /* Backdoor to prevent shutdown  */
    //Board_TEST26     | PIN_GPIO_OUTPUT_EN | PIN_GPIO_LOW   | PIN_PUSHPULL,                        /* Testpoint, DIO_26             */
    //Board_TEST27     | PIN_GPIO_OUTPUT_EN | PIN_GPIO_LOW   | PIN_PUSHPULL,                        /* Testpoint, DIO_27             */
    //Board_TEST28     | PIN_GPIO_OUTPUT_EN | PIN_GPIO_LOW   | PIN_PUSHPULL,                        /* Testpoint, DIO_28             */
    //Board_TEST29     | PIN_GPIO_OUTPUT_EN | PIN_GPIO_LOW   | PIN_PUSHPULL,                        /* Testpoint, DIO_29             */
    PIN_TERMINATE                                                                               /* Terminate list                */
};

//______________MY CODE END______________

3. What else do I have to do, to assign and define the PINs correctly?!

4. Is the timer and the semaphore transferred correctly?

5. Is the HWi set and configured correctly? In the callback function I only want to count up the "move" variable, which will later be substituting the "temperature" value.

I hope you guys can help me out once again. Thank you for the support!

Kind regards

Stefan

 

  • UPDATE:

    I think I was able to figure out Point 1:

    • I think the pin assignment is kind a interleaved, but from the board.h file in the Application-folder of the sensor project you can get to "CC13x0_LaunchXL\Board.h" here you will find the next "makro stage". Digging deeper, you get to the "CC13x0_LaunchXL\CC13x0_LaunchXL.h", here the PINs are assigned to the IOID_X values. Thus, I think I can leave the makro for Board_PIR_Out_Lo  --->  IOID_16 etc.

    I have to comment out the Board_Mode-PIN because another function is already assigned to that pin in the CC13x0_LaunchXL.c in line 537 you find the BoardGpioInitTable[], I also added two lines:

    const PIN_Config BoardGpioInitTable[] = {
    
        CC1350_LAUNCHXL_PIN_RLED | PIN_GPIO_OUTPUT_EN | PIN_GPIO_LOW | PIN_PUSHPULL | PIN_DRVSTR_MAX,          /* LED initially off             */
        CC1350_LAUNCHXL_PIN_GLED | PIN_GPIO_OUTPUT_EN | PIN_GPIO_LOW | PIN_PUSHPULL | PIN_DRVSTR_MAX,          /* LED initially off             */
        CC1350_LAUNCHXL_PIN_BTN1 | PIN_INPUT_EN | PIN_PULLUP | PIN_IRQ_BOTHEDGES | PIN_HYSTERESIS,             /* Button is active low          */
        CC1350_LAUNCHXL_PIN_BTN2 | PIN_INPUT_EN | PIN_PULLUP | PIN_IRQ_BOTHEDGES | PIN_HYSTERESIS,             /* Button is active low          */
        CC1350_LAUNCHXL_SPI_FLASH_CS | PIN_GPIO_OUTPUT_EN | PIN_GPIO_HIGH | PIN_PUSHPULL | PIN_DRVSTR_MIN,     /* External flash chip select    */
        CC1350_LAUNCHXL_UART_RX | PIN_INPUT_EN | PIN_PULLDOWN,                                                 /* UART RX via debugger back channel */
        CC1350_LAUNCHXL_UART_TX | PIN_GPIO_OUTPUT_EN | PIN_GPIO_HIGH | PIN_PUSHPULL,                           /* UART TX via debugger back channel */
    #ifndef FREQ_2_4G
        CC1350_LAUNCHXL_DIO1_RF_SUB1GHZ   | PIN_GPIO_OUTPUT_EN | PIN_GPIO_HIGH | PIN_PUSHPULL | PIN_DRVSTR_MAX,/* RF SW Switch defaults to sub GHz path*/
    #else
        CC1350_LAUNCHXL_DIO1_RF_SUB1GHZ   | PIN_GPIO_OUTPUT_EN | PIN_GPIO_LOW | PIN_PUSHPULL | PIN_DRVSTR_MAX, /* RF SW Switch defaults to 2.4 GHz path*/
    #endif
        CC1350_LAUNCHXL_DIO30_RF_POWER | PIN_GPIO_OUTPUT_EN | PIN_GPIO_LOW | PIN_PUSHPULL | PIN_DRVSTR_MAX,    /* External RF Switch is powered off by default */
        CC1350_LAUNCHXL_SPI0_MOSI | PIN_INPUT_EN | PIN_PULLDOWN,                                               /* SPI master out - slave in */
        CC1350_LAUNCHXL_SPI0_MISO | PIN_INPUT_EN | PIN_PULLDOWN,                                               /* SPI master in - slave out */
        CC1350_LAUNCHXL_SPI0_CLK | PIN_INPUT_EN | PIN_PULLDOWN,                                                /* SPI clock */
        CC1350_LAUNCHXL_DIO16_TDO | PIN_INPUT_EN  | PIN_NOPULL | PIN_HYSTERESIS,                             /* PIR low                       */
        CC1350_LAUNCHXL_DIO17_TDI | PIN_INPUT_EN  | PIN_NOPULL | PIN_HYSTERESIS,                             /* PIR high                      */
        //Board_Mode       | PIN_INPUT_EN  | PIN_NOPULL | PIN_HYSTERESIS, // IOID_3 is already used for UART
        PIN_TERMINATE
    };	

    all changes to board_gpio.C are reverted and the following lines are added to board_gpio.h(since this is included in sensor.c):

    //______________MY CODE START______________
    
    
    #define Board_PIR_Out_Lo                    IOID_16
    #define Board_PIR_Out_Hi                    IOID_17
    //#define Board_Mode                          IOID_3 // is already in use
    
    //______________MY CODE END_______________


    Hope this is right and helps someone else, too.



  • Any further thoughts on my questions?

    I am also thankful for suggestions like links, tutorials or stuff like that.

  • The thread can be closed, since all issues have been solved!!

     


    Regarding Point 3: Definition of the PIN IDs (e.g. IOID_17), the PIN handle and state, as well as the PIN_Table should be done in the same c-File where it is later initialized and used (e.g. for interrupt handling)

    Regarding Point 4: The semaphore code can be transferred by just copying it. The clock might be easily transferable too, but I used the timer_structure and functions explained in timer.c, which are actually basing on the general System Clock Manager: http://dev.ti.com/tirex/content/tirtos_tivac_2_16_00_08/products/bios_6_45_01_29/docs/cdoc/ti/sysbios/knl/Clock.html#per-instance_creation

    Regarding Point 5: Yes it is.