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.

RTOS/AM5728: Timer configuration issue

Part Number: AM5728
Other Parts Discussed in Thread: SYSBIOS

Tool/software: TI-RTOS

Hi experts.

I am developing DSP RTOS program on IDKAM5728.

I configured a timer interruption. Days ago, I found that it don't interrupt strictly per 2ms when I set it as a 2ms interruption.

So I wrote some code to test it (I have changed the period as 10 ms ).

#include <xdc/std.h>

#include <xdc/runtime/Error.h>
#include <xdc/runtime/System.h>

#include <ti/sysbios/BIOS.h>

#include <ti/sysbios/knl/Task.h>
#include <ti/sysbios/timers/dmtimer/Timer.h>
//#include <ti/sysbios/hal/Timer.h>
#include "c6x.h"

void timerIsr2ms(UArg arg);
Void taskFxn(UArg a0, UArg a1);
Timer_Handle timerHandle;

/*
 *  ======== main ========
 */
Int main()
{ 
    Task_Handle task;
    Error_Block eb;

    System_printf("enter main()\n");

    Error_init(&eb);
    task = Task_create(taskFxn, NULL, &eb);
    if (task == NULL) {
        System_printf("Task_create() failed!\n");
        BIOS_exit(0);
    }

    Timer_Params timerParams;

    Timer_Params_init(&timerParams);
    timerParams.period = 10000;
    timerParams.runMode = Timer_RunMode_CONTINUOUS;
    timerParams.periodType = Timer_PeriodType_MICROSECS;
    timerParams.arg = 0;
    timerParams.extFreq.lo = 1000000;
    timerParams.extFreq.hi = 0;
    timerParams.startMode = Timer_StartMode_USER;
    timerHandle = Timer_create(Timer_ANY, timerIsr2ms, &timerParams, &eb);
    if (timerHandle == NULL)
    {
        System_abort("Timer create failed");
    }

    BIOS_start();    /* does not return */
    return(0);
}

Void taskFxn(UArg a0, UArg a1)
{
    Timer_start(timerHandle);
    int delay;
    while(1)
    {
        Task_sleep(10);
        System_flush();
    };
}

unsigned int start=1, finish=1,time=0;

void timerIsr2ms(UArg arg)
{
    finish = TSCL;
    time = (finish-start);
    start = TSCL;
    System_printf("timer time is %d\n",time);
}

and there is my cfg file:

var Defaults = xdc.useModule('xdc.runtime.Defaults');
var Diags = xdc.useModule('xdc.runtime.Diags');
var Error = xdc.useModule('xdc.runtime.Error');
var Log = xdc.useModule('xdc.runtime.Log');
var LoggerBuf = xdc.useModule('xdc.runtime.LoggerBuf');
var Main = xdc.useModule('xdc.runtime.Main');
var Memory = xdc.useModule('xdc.runtime.Memory')
var SysMin = xdc.useModule('xdc.runtime.SysMin');
var System = xdc.useModule('xdc.runtime.System');
var Text = xdc.useModule('xdc.runtime.Text');

var BIOS = xdc.useModule('ti.sysbios.BIOS');
var Clock = xdc.useModule('ti.sysbios.knl.Clock');
var Swi = xdc.useModule('ti.sysbios.knl.Swi');
var Task = xdc.useModule('ti.sysbios.knl.Task');
var Semaphore = xdc.useModule('ti.sysbios.knl.Semaphore');
var Hwi = xdc.useModule('ti.sysbios.hal.Hwi');
var Timer = xdc.useModule('ti.sysbios.timers.dmtimer.Timer');
//var Timer = xdc.useModule('ti.sysbios.hal.Timer');
//Timer.intFreq.lo = 20000000;
//Timer.intFreq.hi = 0;

/*
 * Minimize exit handler array in System.  The System module includes
 * an array of functions that are registered with System_atexit() to be
 * called by System_exit().
 */
System.maxAtexitHandlers = 4;       

/*
 * The BIOS module will create the default heap for the system.
 * Specify the size of this default heap.
 */
BIOS.heapSize = 0x1000;

/*
 * Build a custom SYS/BIOS library from sources.
 */
BIOS.libType = BIOS.LibType_Custom;

/* System stack size (used by ISRs and Swis) */
Program.stack = 0x2000;

/* Circular buffer size for System_printf() */
SysMin.bufSize = 0x200;

/* 
 * Create and install logger for the whole system
 */
var loggerBufParams = new LoggerBuf.Params();
loggerBufParams.numEntries = 16;
var logger0 = LoggerBuf.create(loggerBufParams);
Defaults.common$.logger = logger0;
Main.common$.diags_INFO = Diags.ALWAYS_ON;

System.SupportProxy = SysMin;

there is some of its output:

  

some time is strange.

And I have tried to configure intfreq as 20M and not to configure extfreq.

It get the similar outcome or even a worse one.

any help will be appreciated.

Regards 

Yx

  • The RTOS team have been notified. They will respond here.
  •  Hi,

    You issue is to run a timer on C66x of AM5728 and how to get an accurate timer interrupt interval. Attached is my example, the key parts:

    In .cfg:

    BIOS.cpuFreq.lo = 600000000; =====>DSP CPU is 600MHz

    var timer0Params = new Timer.Params();

    timer0Params.instance.name = "timerTest";

    timer0Params.period = 100000;  ============>This is every 100 ms

    timer0Params.extFreq.lo = 20000000;  ======> the timer clock is 20MHz

    timer0Params.periodType = xdc.module("ti.sysbios.interfaces.ITimer").PeriodType_MICROSECS;

    Program.global.timerOwn = Timer.create(5, "&TimerFunction", timer0Params); // ok

    The main.c:

    void TimerFunction(void)

    {

    new = TSCL;

    delta[(Counter++)%1000] = new - old;

    old = new;

    }

    I used an array to trace the difference of ISR entrance. I didn't see any issue.  

    Regards, Eric

    #include <xdc/std.h>
    
    #include <ti/sysbios/BIOS.h>
    #include <ti/sysbios/knl/Task.h>
    #include <ti/sysbios/hal/Timer.h>
    //#include <c66x.h>
    unsigned int volatile cregister TSCL;
    
    int Counter = 0;
    int TaskSleepReturned = 0;
    unsigned int taskEntered = 0;
    
    Void taskFxn(UArg a0, UArg a1)
    {
      taskEntered = 1;
      Task_sleep(1000);
    
      // Newer gets here! Why?
      TaskSleepReturned = 1;
    }
    
    unsigned int new, old = 0, delta[1000];
    void TimerFunction(void)
    {
      new = TSCL;
      delta[(Counter++)%1000] = new - old;
      old = new;
    }
    
    Int main()
    { 
    
      BIOS_start();
    
      return(0);
    }
    

    0068.app.cfg

  • Hi Eric
    Thanks for your help.It is works.

    I can get the same outcome with yours on CCS.
    I transplanted this configuration to my project.The project include IPC program so that I can't debug it on CCS. This is my early problem about why I can't debug on CCS : e2e.ti.com/.../671655 .
    I set the period 2ms, in the interrupt function, output a signal via one pin,connect the pin to a scope, then ran it.
    I got a 1ms periodic signal output.Furthermore, whatever period I change,Its output period is 1ms.
    Any suggestion?

    addition: I saw that there is a 1-ms tick generation module of some timer. But I am new to these architecture,and don't know that if something I do enable this module and invalid the timer configuration. refrence:AM572x  Sitara Processor Technical Reference Manual:Page 5590~5591 


    Best Regards
    Yx