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.

Timer on cc1310

Other Parts Discussed in Thread: CC1310

Hi All

When I create a timer from the available products in the configurator I can see the code is added in the cfg.

I would like to run the timer as a one shot.

What I want to do is create a task that executes every so often then when the task executes it must start my one shot timer, When the timer expires it should then toggle a pin.

Now my question,  Do I use hardware timer for this if so, how?  Or do I use the Timer module from the products....  I struggle to find some documentation on this

Kind regards

Ben

Here my main, where can I get the handle for timer0 that was created in the cfg file?

/*
 * Copyright (c) 2015-2016, Texas Instruments Incorporated
 * All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions
 * are met:
 *
 * *  Redistributions of source code must retain the above copyright
 *    notice, this list of conditions and the following disclaimer.
 *
 * *  Redistributions in binary form must reproduce the above copyright
 *    notice, this list of conditions and the following disclaimer in the
 *    documentation and/or other materials provided with the distribution.
 *
 * *  Neither the name of Texas Instruments Incorporated nor the names of
 *    its contributors may be used to endorse or promote products derived
 *    from this software without specific prior written permission.
 *
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
 * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
 * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
 * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
 * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 */

/*
 *  ======== empty.c ========
 */
/* XDCtools Header files */
#include <xdc/std.h>
#include <xdc/runtime/System.h>

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

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

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

#define TASKSTACKSIZE   512

Task_Struct task0Struct;
Char task0Stack[TASKSTACKSIZE];

Task_Struct task2Struct;
Char task2Stack[TASKSTACKSIZE];

Task_Struct task1Struct;
Char task1Stack[TASKSTACKSIZE];

/* Pin driver handle */
static PIN_Handle ledPinHandle;
static PIN_State ledPinState;

uint8_t  g_configPinStatus=0;
uint8_t  g_currentState=0;

/*
 * Application LED pin configuration table:
 *   - All LEDs board LEDs are off.
 */
PIN_Config ledPinTable[] = {
    Board_LED0 | PIN_GPIO_OUTPUT_EN | PIN_GPIO_LOW | PIN_PUSHPULL | PIN_DRVSTR_MAX,
    Board_LED1 | PIN_GPIO_OUTPUT_EN | PIN_GPIO_LOW | PIN_PUSHPULL | PIN_DRVSTR_MAX,
	Board_LED2 | PIN_GPIO_OUTPUT_EN | PIN_GPIO_LOW | PIN_PUSHPULL | PIN_DRVSTR_MAX,
	Board_LED3 | PIN_GPIO_OUTPUT_EN | PIN_GPIO_LOW | PIN_PUSHPULL | PIN_DRVSTR_MAX,
    PIN_TERMINATE
};

/*
 *  ======== heartBeatFxn ========
 *  Toggle the Board_LED0. The Task_sleep is determined by arg0 which
 *  is configured for the heartBeat Task instance.
 */
Void heartBeatFxn(UArg arg0, UArg arg1)
{
    while (1) {
        Task_sleep((UInt)arg0);
        PIN_setOutputValue(ledPinHandle, Board_LED0,
                           !PIN_getOutputValue(Board_LED0));
        System_printf("Now In hearBeat");
    }
}


/*
 *  ======== LedOffTmr0 ========
 *  Switch off LED after time out
 */

Void LedOffTmr0(void)
{
	PIN_setOutputValue(ledPinHandle, TeqconRadioLedState,0);

}

/*
 *  ======== StatusLedOnTask ========
 *  Switch Status LED On
 */
Void LedOnTsk (UArg arg0, UArg arg1)
{
	Task_sleep((UInt)arg0);
	PIN_setOutputValue(ledPinHandle, TeqconRadioLedState,1);
	Timer_start(timer0);
}

/*
 *  ======== CheckCfgPin ========
 *  Check Cfg Pin
 */
Void checkCFGPin(UArg arg0, UArg arg1)
{
    while (1)
    {
    	Task_sleep((UInt)arg0);
    	g_configPinStatus = PIN_getInputValue(EnableConfig);
    	System_printf("Now in checkCfg");
    	if(g_configPinStatus&1 == 1)
    	{
    		PIN_setOutputValue(ledPinHandle, Board_LED2,
    		                           !PIN_getOutputValue(Board_LED2));
    	}
    	else
    	{
    		PIN_setOutputValue(ledPinHandle, Board_LED2,0);
    	}


    }
}

/*
 *  ======== main ========
 */
int main(void)
{
    Task_Params taskParams;
    Task_Params cfgChkTsk;
    Task_Params ledOffTsk;

    /* Call board init functions */
    Board_initGeneral();
    // Board_initI2C();
    // Board_initSPI();
    // Board_initUART();
    // Board_initWatchdog();

    /* Construct heartBeat Task  thread */
    Task_Params_init(&taskParams);
    taskParams.arg0 = 1000000 / Clock_tickPeriod;
    taskParams.stackSize = TASKSTACKSIZE;
    taskParams.stack = &task0Stack;
    Task_construct(&task0Struct, (Task_FuncPtr)heartBeatFxn, &taskParams, NULL);

    //task to check for cfg pin
    Task_Params_init(&cfgChkTsk);
    cfgChkTsk.arg0 = 5000000 / Clock_tickPeriod;
    cfgChkTsk.stackSize = TASKSTACKSIZE;
    cfgChkTsk.stack = &task1Stack;
	Task_construct(&task1Struct, (Task_FuncPtr)checkCFGPin, &cfgChkTsk, NULL);

	//task to check for status set pin
	Task_Params_init(&ledOffTsk);
	ledOffTsk.arg0 = 100000 / Clock_tickPeriod;
	ledOffTsk.stackSize = TASKSTACKSIZE;
	ledOffTsk.stack = &task2Stack;
	Task_construct(&task2Struct, (Task_FuncPtr)checkCFGPin, &cfgChkTsk, NULL);



    /* Open LED pins */
    ledPinHandle = PIN_open(&ledPinState, ledPinTable);
    if(!ledPinHandle) {
        System_abort("Error initializing board LED pins\n");
    }

    //PIN_setOutputValue(ledPinHandle, Board_LED1, 1);

    System_printf("Starting the example\nSystem provider is set to SysMin. "
                  "Halt the target to view any SysMin contents in ROV.\n");
    /* SysMin will only print to the console when you call flush or exit */
    System_flush();

    /* Start BIOS */
    BIOS_start();

    return (0);
}

  • Hi Ben,

    I would suggest using the Clock functions to implement this, you already have it included in your project so implementing it shouldn't be too hard. There is a Clock example included on TI-RTOS which you can reference, that example will show you how to create a one-shot clock and specifying a function once the timer expires. You can then toggle a pin on the function like you wanted.

    If you run into trouble you can reference the Clock API which you can find at:
    <tirtos_install_dir>\products\<bios>\docs\Bios_APIs.html
    Then go to:
    ti->sysbios->knl->Clock

    Thanks,
    Gerardo

  • Hi

    Thank you will give a go and give feedback..

    a bit of topic......just for clarification. 

    If I use a HWI for a timer say Timer 1a with interrupt number 31 for the cc1310 will the configurator generate the interrupt routine in my project or should I then write the code?  I can see in the cfg that the timer is there. but when I want to call Timer_start the handle that was assigned in the cfg file is not available in global scope.  So my question how does the configurator (gui) work to generate the code or is it up to the user?

    Kind regards

    Ben

  • Hi Ben,

    When you use the configurator to generate the HWI you still have to create and specify the function that is called in the interrupt, the rest is generated for you.

    As for accessing the handle declared in your cfg file you need to add the following to your code to access the global namespace:

    #include <xdc/cfg/global.h>

    Thanks,
    Gerardo