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/CC1310: Adding more buttons to Easylink example with shutdown

Part Number: CC1310
Other Parts Discussed in Thread: SYSBIOS

Tool/software: Code Composer Studio

Hello,

I have 2 launchpads. One of them is TX and the ohter one is RX device. TX device have 4 buttons. 2 of them are BTN-1 and BTN-2 and new buttons are  Board_DIO12 and Board_DIO15.

If buttons are not pressed, TX device should be in shutdown mode to save battery. So, I mixtured Easlink RF example and pinShutdown example.

The problem is board behaves as if NEW_BUTTON3 always pressed. How can I eliminate "always button pressed" problem ?

Here is the code:

/*
 *  ======== rfEasyLinkTx.c ========
 */
//#include <unistd.h>
/* XDCtools Header files */
#include <stdlib.h>
#include <xdc/std.h>
#include <xdc/runtime/System.h>
#include <xdc/runtime/Error.h>

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

/* TI-RTOS Header files */
#include <ti/drivers/PIN.h>

//SHUTDOWN WAKEUP
#include <ti/sysbios/knl/Swi.h>
#include <ti/drivers/Power.h>
#include <ti/drivers/power/PowerCC26XX.h>
#include <ti/drivers/pin/PINCC26XX.h>
#ifdef DEVICE_FAMILY
    #undef DEVICE_FAMILY_PATH
    #define DEVICE_FAMILY_PATH(x) <ti/devices/DEVICE_FAMILY/x>
    #include DEVICE_FAMILY_PATH(inc/hw_prcm.h)
    #include DEVICE_FAMILY_PATH(driverlib/sys_ctrl.h)
#else
    #error "You must define DEVICE_FAMILY at the project level as one of cc26x0, cc26x0r2, cc13x0, etc."
#endif


/* Board Header files */
#include "Board.h"

/* EasyLink API Header files */
#include "easylink/EasyLink.h"


#define NEW_BUTTON2   Board_DIO12
#define NEW_BUTTON3   Board_DIO15


/* Undefine to not use async mode */
#define RFEASYLINKTX_ASYNC

#define RFEASYLINKTX_TASK_STACK_SIZE    1024
#define RFEASYLINKTX_TASK_PRIORITY      2

#define RFEASYLINKTX_BURST_SIZE         10
#define RFEASYLINKTXPAYLOAD_LENGTH      30

Task_Struct txTask;    /* not static so you can see in ROV */
static Task_Params txTaskParams;
static uint8_t txTaskStack[RFEASYLINKTX_TASK_STACK_SIZE];

/* Pin driver handle */
static PIN_Handle pinHandle;
static PIN_State pinState;

/*
 * Application LED pin configuration table:
 *   - All LEDs board LEDs are off.
 */
PIN_Config pinTable[] = {
    Board_PIN_LED1 | PIN_GPIO_OUTPUT_EN | PIN_GPIO_LOW | PIN_PUSHPULL | PIN_DRVSTR_MAX,
    Board_PIN_LED2 | PIN_GPIO_OUTPUT_EN | PIN_GPIO_LOW | PIN_PUSHPULL | PIN_DRVSTR_MAX,
    PIN_TERMINATE
};


//SHUTDOWN WAKEUP
/* Wake-up Button pin table */
PIN_Config ButtonTableWakeUp[] = {
    Board_PIN_BUTTON0    | PIN_INPUT_EN | PIN_PULLUP | PINCC26XX_WAKEUP_NEGEDGE,
    Board_PIN_BUTTON1     | PIN_INPUT_EN | PIN_PULLUP | PINCC26XX_WAKEUP_NEGEDGE,
    NEW_BUTTON2    | PIN_INPUT_EN | PIN_PULLUP | PINCC26XX_WAKEUP_NEGEDGE,
    NEW_BUTTON3     | PIN_INPUT_EN | PIN_PULLUP | PINCC26XX_WAKEUP_NEGEDGE,
    PIN_TERMINATE                                 /* Terminate list */
};

static uint16_t seqNumber;

#ifdef RFEASYLINKTX_ASYNC
static Semaphore_Handle txDoneSem;
#endif //RFEASYLINKTX_ASYNC

#ifdef RFEASYLINKTX_ASYNC
void txDoneCb(EasyLink_Status status)
{

    Semaphore_post(txDoneSem);
}
#endif //RFEASYLINKTX_ASYNC

static void rfEasyLinkTxFnx(UArg arg0, UArg arg1)
{
    uint8_t txBurstSize = 0, cntr = 0;

#ifdef RFEASYLINKTX_ASYNC
    /* Create a semaphore for Async */
    Semaphore_Params params;
    Error_Block eb;

    /* Init params */
    Semaphore_Params_init(&params);
    Error_init(&eb);

    /* Create semaphore instance */
    txDoneSem = Semaphore_create(0, &params, &eb);
#endif //TX_ASYNC

    EasyLink_init(EasyLink_Phy_Custom);

    /* Set output power to 12dBm */
    EasyLink_setRfPwr(10);

    //while(1) {
    while(cntr<1) {


        EasyLink_TxPacket txPacket =  { {0}, 0, 0, {0} };
        txPacket.payload[0] = (uint8_t)(seqNumber >> 8);
        txPacket.payload[1] = (uint8_t)(seqNumber++);


        txPacket.len = RFEASYLINKTXPAYLOAD_LENGTH;
        txPacket.dstAddr[0] = 0xaa;
        uint8_t i, sendPacketTrigger = 0;

        if (PIN_getInputValue(Board_PIN_BUTTON0)==0) {
            PIN_setOutputValue(pinHandle, Board_PIN_LED1, 0);
            PIN_setOutputValue(pinHandle, Board_PIN_LED2, 0);
            for (i = 2; i < RFEASYLINKTXPAYLOAD_LENGTH; i++)
            {
                txPacket.payload[i] = 0x01;
            }
            // Set Tx absolute time to current time + 100ms
            txPacket.absTime = EasyLink_getAbsTime() + EasyLink_ms_To_RadioTime(1);
            sendPacketTrigger = 1;
        }


        else if (PIN_getInputValue(Board_PIN_BUTTON1)==0) {
            PIN_setOutputValue(pinHandle, Board_PIN_LED1, 0);
            PIN_setOutputValue(pinHandle, Board_PIN_LED2, 1);
            for (i = 2; i < RFEASYLINKTXPAYLOAD_LENGTH; i++)
            {
                txPacket.payload[i] = 0x02;
            }
            // Set Tx absolute time to current time + 100ms
            txPacket.absTime = EasyLink_getAbsTime() + EasyLink_ms_To_RadioTime(1);
            sendPacketTrigger = 1;
        }
        else if (PIN_getInputValue(NEW_BUTTON2)==0) {
            PIN_setOutputValue(pinHandle, Board_PIN_LED1, 1);
            PIN_setOutputValue(pinHandle, Board_PIN_LED2, 0);
            for (i = 2; i < RFEASYLINKTXPAYLOAD_LENGTH; i++)
            {
                txPacket.payload[i] = 0x03;
            }
            // Set Tx absolute time to current time + 100ms
            txPacket.absTime = EasyLink_getAbsTime() + EasyLink_ms_To_RadioTime(1);
            sendPacketTrigger = 1;
        }
        else if (PIN_getInputValue(NEW_BUTTON3)==0) {
            PIN_setOutputValue(pinHandle, Board_PIN_LED1, 1);
            PIN_setOutputValue(pinHandle, Board_PIN_LED2, 1);
            for (i = 2; i < RFEASYLINKTXPAYLOAD_LENGTH; i++)
            {
                txPacket.payload[i] = 0x04;
            }
            // Set Tx absolute time to current time + 100ms
            txPacket.absTime = EasyLink_getAbsTime() + EasyLink_ms_To_RadioTime(1);
            sendPacketTrigger = 1;
        }
        else{
            PIN_setOutputValue(pinHandle, Board_PIN_LED1, 0);
            PIN_setOutputValue(pinHandle, Board_PIN_LED2, 0);
            sendPacketTrigger = 0;
            cntr++;
        }

        if(sendPacketTrigger == 1)
        {
            EasyLink_transmitAsync(&txPacket, txDoneCb);
            // Wait 300ms for Tx to complete
            if(Semaphore_pend(txDoneSem, (300000 / Clock_tickPeriod)) == FALSE)
            {
                // TX timed out, abort
                if(EasyLink_abort() == EasyLink_Status_Success)
                {

                   Semaphore_pend(txDoneSem, BIOS_WAIT_FOREVER);
                }
            }
            sendPacketTrigger = 0;
            cntr = 0;

        }

    }

    cntr = 0;

    // Configure DIO for wake up from shutdown
    PINCC26XX_setWakeup(ButtonTableWakeUp);

    // Go to shutdown
    Power_shutdown(0, 0);

    // Should never get here, since shutdown will reset.
    while(1);

}

void txTask_init(PIN_Handle inPinHandle) {
    pinHandle = inPinHandle;

    Task_Params_init(&txTaskParams);
    txTaskParams.stackSize = RFEASYLINKTX_TASK_STACK_SIZE;
    txTaskParams.priority = RFEASYLINKTX_TASK_PRIORITY;
    txTaskParams.stack = &txTaskStack;
    txTaskParams.arg0 = (UInt)1000000;

    Task_construct(&txTask, rfEasyLinkTxFnx, &txTaskParams, NULL);
}

/*
 *  ======== main ========
 */
int main(void)
{
    /* Call driver init functions. */
    Board_initGeneral();

    /* Open LED pins */
    pinHandle = PIN_open(&pinState, pinTable);
    if(!pinHandle) {
        System_abort("Error initializing board LED pins\n");
    }

    /* Clear LED pins */
    PIN_setOutputValue(pinHandle, Board_PIN_LED1, 0);
    PIN_setOutputValue(pinHandle, Board_PIN_LED2, 0);

    txTask_init(pinHandle);

    /* Start BIOS */
    BIOS_start();

    return (0);
}


/* *  ======== rfEasyLinkTx.c ======== *///#include <unistd.h>/* XDCtools Header files */#include <stdlib.h>#include <xdc/std.h>#include <xdc/runtime/System.h>#include <xdc/runtime/Error.h>
/* BIOS Header files */#include <ti/sysbios/BIOS.h>#include <ti/sysbios/knl/Task.h>#include <ti/sysbios/knl/Semaphore.h>#include <ti/sysbios/knl/Clock.h>
/* TI-RTOS Header files */#include <ti/drivers/PIN.h>
//SHUTDOWN WAKEUP#include <ti/sysbios/knl/Swi.h>#include <ti/drivers/Power.h>#include <ti/drivers/power/PowerCC26XX.h>#include <ti/drivers/pin/PINCC26XX.h>#ifdef DEVICE_FAMILY    #undef DEVICE_FAMILY_PATH    #define DEVICE_FAMILY_PATH(x) <ti/devices/DEVICE_FAMILY/x>    #include DEVICE_FAMILY_PATH(inc/hw_prcm.h)    #include DEVICE_FAMILY_PATH(driverlib/sys_ctrl.h)#else    #error "You must define DEVICE_FAMILY at the project level as one of cc26x0, cc26x0r2, cc13x0, etc."#endif

/* Board Header files */#include "Board.h"
/* EasyLink API Header files */#include "easylink/EasyLink.h"

#define NEW_BUTTON2   Board_DIO12#define NEW_BUTTON3   Board_DIO15

/* Undefine to not use async mode */#define RFEASYLINKTX_ASYNC
#define RFEASYLINKTX_TASK_STACK_SIZE    1024#define RFEASYLINKTX_TASK_PRIORITY      2
#define RFEASYLINKTX_BURST_SIZE         10#define RFEASYLINKTXPAYLOAD_LENGTH      30
Task_Struct txTask;    /* not static so you can see in ROV */static Task_Params txTaskParams;static uint8_t txTaskStack[RFEASYLINKTX_TASK_STACK_SIZE];
/* Pin driver handle */static PIN_Handle pinHandle;static PIN_State pinState;
/* * Application LED pin configuration table: *   - All LEDs board LEDs are off. */PIN_Config pinTable[] = {    Board_PIN_LED1 | PIN_GPIO_OUTPUT_EN | PIN_GPIO_LOW | PIN_PUSHPULL | PIN_DRVSTR_MAX,    Board_PIN_LED2 | PIN_GPIO_OUTPUT_EN | PIN_GPIO_LOW | PIN_PUSHPULL | PIN_DRVSTR_MAX,    PIN_TERMINATE};


//SHUTDOWN WAKEUP/* Wake-up Button pin table */PIN_Config ButtonTableWakeUp[] = {    //Board_PIN_BUTTON0     | PIN_INPUT_EN | PIN_PULLUP | PINCC26XX_WAKEUP_NEGEDGE,    //Board_PIN_BUTTON1     | PIN_INPUT_EN | PIN_PULLUP | PINCC26XX_WAKEUP_NEGEDGE,    Board_PIN_BUTTON0    | PIN_INPUT_EN | PIN_PULLUP | PINCC26XX_WAKEUP_NEGEDGE,    Board_PIN_BUTTON1     | PIN_INPUT_EN | PIN_PULLUP | PINCC26XX_WAKEUP_NEGEDGE,    NEW_BUTTON2    | PIN_INPUT_EN | PIN_PULLUP | PINCC26XX_WAKEUP_NEGEDGE,    NEW_BUTTON3     | PIN_INPUT_EN | PIN_PULLUP | PINCC26XX_WAKEUP_NEGEDGE,    PIN_TERMINATE                                 /* Terminate list */};


static uint16_t seqNumber;
#ifdef RFEASYLINKTX_ASYNCstatic Semaphore_Handle txDoneSem;#endif //RFEASYLINKTX_ASYNC
#ifdef RFEASYLINKTX_ASYNCvoid txDoneCb(EasyLink_Status status){
    Semaphore_post(txDoneSem);}#endif //RFEASYLINKTX_ASYNC
static void rfEasyLinkTxFnx(UArg arg0, UArg arg1){    uint8_t txBurstSize = 0, cntr = 0;
#ifdef RFEASYLINKTX_ASYNC    /* Create a semaphore for Async */    Semaphore_Params params;    Error_Block eb;
    /* Init params */    Semaphore_Params_init(&params);    Error_init(&eb);
    /* Create semaphore instance */    txDoneSem = Semaphore_create(0, &params, &eb);#endif //TX_ASYNC
    EasyLink_init(EasyLink_Phy_Custom);
    /*     * If you wish to use a frequency other than the default, use     * the following API:     * EasyLink_setFrequency(868000000);     */
    /* Set output power to 12dBm */    EasyLink_setRfPwr(10);
    //while(1) {    while(cntr<20) {

        EasyLink_TxPacket txPacket =  { {0}, 0, 0, {0} };        txPacket.payload[0] = (uint8_t)(seqNumber >> 8);        txPacket.payload[1] = (uint8_t)(seqNumber++);

        txPacket.len = RFEASYLINKTXPAYLOAD_LENGTH;        txPacket.dstAddr[0] = 0xaa;        uint8_t i, sendPacketTrigger = 0;
        if (PIN_getInputValue(Board_PIN_BUTTON0)==0) {            PIN_setOutputValue(pinHandle, Board_PIN_LED1, 0);            PIN_setOutputValue(pinHandle, Board_PIN_LED2, 0);            for (i = 2; i < RFEASYLINKTXPAYLOAD_LENGTH; i++)            {              //txPacket.payload[i] = rand();                txPacket.payload[i] = 0x01;            }            // Set Tx absolute time to current time + 100ms            txPacket.absTime = EasyLink_getAbsTime() + EasyLink_ms_To_RadioTime(1);            sendPacketTrigger = 1;        }

        else if (PIN_getInputValue(Board_PIN_BUTTON1)==0) {            PIN_setOutputValue(pinHandle, Board_PIN_LED1, 0);            PIN_setOutputValue(pinHandle, Board_PIN_LED2, 1);            for (i = 2; i < RFEASYLINKTXPAYLOAD_LENGTH; i++)            {              //txPacket.payload[i] = rand();                txPacket.payload[i] = 0x02;            }            // Set Tx absolute time to current time + 100ms            txPacket.absTime = EasyLink_getAbsTime() + EasyLink_ms_To_RadioTime(1);            sendPacketTrigger = 1;        }        else if (PIN_getInputValue(NEW_BUTTON2)==0) {            PIN_setOutputValue(pinHandle, Board_PIN_LED1, 1);            PIN_setOutputValue(pinHandle, Board_PIN_LED2, 0);            for (i = 2; i < RFEASYLINKTXPAYLOAD_LENGTH; i++)            {              //txPacket.payload[i] = rand();                txPacket.payload[i] = 0x03;            }            // Set Tx absolute time to current time + 100ms            txPacket.absTime = EasyLink_getAbsTime() + EasyLink_ms_To_RadioTime(1);            sendPacketTrigger = 1;        }        else if (PIN_getInputValue(NEW_BUTTON3)==0) {            PIN_setOutputValue(pinHandle, Board_PIN_LED1, 1);            PIN_setOutputValue(pinHandle, Board_PIN_LED2, 1);            for (i = 2; i < RFEASYLINKTXPAYLOAD_LENGTH; i++)            {              //txPacket.payload[i] = rand();                txPacket.payload[i] = 0x04;            }            // Set Tx absolute time to current time + 100ms            txPacket.absTime = EasyLink_getAbsTime() + EasyLink_ms_To_RadioTime(1);            sendPacketTrigger = 1;        }        else{            PIN_setOutputValue(pinHandle, Board_PIN_LED1, 0);            PIN_setOutputValue(pinHandle, Board_PIN_LED2, 0);            sendPacketTrigger = 0;            //sleep(standbyDuration);            cntr++;        }
        if(sendPacketTrigger == 1)        {            EasyLink_transmitAsync(&txPacket, txDoneCb);            // Wait 300ms for Tx to complete            if(Semaphore_pend(txDoneSem, (300000 / Clock_tickPeriod)) == FALSE)            {                // TX timed out, abort                if(EasyLink_abort() == EasyLink_Status_Success)                {
                     // Abort will cause the txDoneCb to be called and the txDoneSem                     // to be released, so we must consume the txDoneSem
                   Semaphore_pend(txDoneSem, BIOS_WAIT_FOREVER);                }            }            sendPacketTrigger = 0;            cntr = 0;
        }
    }//yeni while bitis
    cntr = 0;
    // Configure DIO for wake up from shutdown    PINCC26XX_setWakeup(ButtonTableWakeUp);
    // Go to shutdown    Power_shutdown(0, 0);
    // Should never get here, since shutdown will reset.    while(1);
}
void txTask_init(PIN_Handle inPinHandle) {    pinHandle = inPinHandle;
    Task_Params_init(&txTaskParams);    txTaskParams.stackSize = RFEASYLINKTX_TASK_STACK_SIZE;    txTaskParams.priority = RFEASYLINKTX_TASK_PRIORITY;    txTaskParams.stack = &txTaskStack;    txTaskParams.arg0 = (UInt)1000000;
    Task_construct(&txTask, rfEasyLinkTxFnx, &txTaskParams, NULL);}
/* *  ======== main ======== */int main(void){    /* Call driver init functions. */    Board_initGeneral();
    /* Open LED pins */    pinHandle = PIN_open(&pinState, pinTable);    if(!pinHandle) {        System_abort("Error initializing board LED pins\n");    }
    /* Clear LED pins */    PIN_setOutputValue(pinHandle, Board_PIN_LED1, 0);    PIN_setOutputValue(pinHandle, Board_PIN_LED2, 0);
    txTask_init(pinHandle);
    /* Start BIOS */    BIOS_start();
    return (0);}