Part Number: CC2650
Other Parts Discussed in Thread: SYSBIOS
Tool/software: TI-RTOS
Hi TI E2E Community,
Regarding the Timer module I have to questions:
1. I would like to know if every SYSBIOS products (Timer, Clock, Task...) have to be added in the cfg file in order to be available in the c code for dynamic declaration/creation. I ask this because I added the "#include <ti/sysbios/hal/Timer.h>" in my c code, and I was getting "Undefined references" over the Timer functions/variables after compiling. Then I went to the cfg file and I added this, "var Timer = xdc.useModule('ti.sysbios.hal.Timer')". After that my code compiled without errors and I was able to declare/create Timer modules dynamically. To be honest, this is quite confusing, I thought the "#include <ti/sysbios/hal/Timer.h>" was needed in your c code for dynamic declaration only, and the "var Timer = xdc.useModule('ti.sysbios.hal.Timer')" was needed in your cfg file for static declaration only. It seems that is not the way it works, though it would be nice if some help me clarifying that point anyway.
2. I would like to know what is the minimum period in microseconds supported by the Timer module. I need a timer to execute every microsecond to increment a variable which I call timerTick, but if I configure the timer below 8 microseconds my code freezes instantly (after pressing the debug button). It seems like the Timer module can't handle periods below that number. By the way, I won't use the Clock_getTicks() since I need to be able to activate and deactivate the timer (Timer_start and Timer_stop). If I do that with the Clock module, I will mess around with the Task_sleep() function. I will a code below to illustrate how I have configured the Timer.
/* 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>
#include <ti/sysbios/hal/Timer.h>
/* TI-RTOS Header files */
#include <ti/drivers/PIN.h>
/* Board Header files */
#include "Board.h"
#define TASKSTACKSIZE 512
Task_Struct task0Struct;
Char task0Stack[TASKSTACKSIZE];
Timer_Handle timerHandle;
/* Pin driver handle */
static PIN_Handle ledPinHandle;
static PIN_State ledPinState;
PIN_Config ledPinTable[] =
{
Board_LED0 | PIN_GPIO_OUTPUT_EN | PIN_GPIO_LOW | PIN_PUSHPULL | PIN_DRVSTR_MAX,
PIN_TERMINATE
};
uint32_t timerTick = 0;
Void tickFxn(UArg arg0)
{
timerTick++;
}
Void toggleFxn(UArg arg0, UArg arg1)
{
while (1)
{
Task_sleep((UInt)arg0);
PIN_setOutputValue(ledPinHandle, Board_LED0, !PIN_getOutputValue(Board_LED0));
}
}
int main(void)
{
Timer_Params timerParams;
Task_Params taskParams;
/* Call board init functions */
Board_initGeneral();
/* Construct heartBeat Task thread */
Task_Params_init(&taskParams);
taskParams.arg0 = 1000000 / Clock_tickPeriod;
taskParams.stackSize = TASKSTACKSIZE;
taskParams.stack = &task0Stack;
Task_construct(&task0Struct, (Task_FuncPtr)toggleFxn, &taskParams, NULL);
/* Create Timer tick function */
Timer_Params_init(&timerParams);
timerParams.period = 8; // 8 us , if the period is below this number the program freezes instantly (after pressing the debug button)
timerParams.periodType = Timer_PeriodType_MICROSECS;
timerParams.startMode = Timer_StartMode_AUTO;
timerParams.arg = 1;
timerHandle = Timer_create(Timer_ANY, (Timer_FuncPtr)tickFxn, &timerParams, NULL);
if (!timerHandle) System_abort("Timer create failed\n");
/* Open LED pins */
ledPinHandle = PIN_open(&ledPinState, ledPinTable);
if(!ledPinHandle) System_abort("Error initializing board LED pins\n");
/* Start BIOS */
BIOS_start();
return (0);
}