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.

TDA4VM: How to use TI-RTOS Timers to add a periodic function?

Part Number: TDA4VM
Other Parts Discussed in Thread: SYSBIOS

We are working on a Sensor driver for J7 using the TI-RTOS Imaging SDK component.
Currently we have a sensor driver working for our target camera, but we are adding a feature to enable and control an external train pulse signal which will allow the camera to stream in slave mode. Basically we would like to enable a periodic function to constantly switch from HIGH to LOW using a specific duty cycle and we want to collect the timestamps for every positive level switch.

For that we want to use a Timers API to enable and configure the period for a GPIO signal which will be reached by the camera.

I did some research on the documentation about it, but I couldn't find good information about how to use Timers on TI-RTOS, so I was analyzing files on the SDK and I found some interesting APIs.

  • crete-j7-rtos/bios_6_82_01_19/packages/ti/sysbios/knl/Clock.c
  • crete-j7-rtos/bios_6_82_01_19/packages/ti/posix/tirtos/timer.c
  • crete-j7-rtos/pdk_jacinto_07_00_00/packages/ti/osal/src/tirtos/TimerP_tirtos.c

I found an example which uses the "TimerP" API:

  • crete-j7-rtos/pdk_jacinto_07_00_00/packages/ti/diag/sdr/test/sdtf-test/src/sdtf_main.c

I did a quick implementation, adding code to the sensor driver trying to print a message every 1 ms. However, I didn't see the message being printed. I attached the code here:

    
...
    TimerP_Params   periodicTimerParams;
    TimerP_Handle   periodicTimerHandle;
    /* TimerP_Status   timerStatus; */
 
    appLogPrintf("*************** PROBE ***************** \n");

    /* Initialize timer parameters */
    TimerP_Params_init(&periodicTimerParams);

    /* Configure periodic timer for 1 ms*/
    periodicTimerParams.period = 1000;  /*  1 ms */
    periodicTimerParams.periodType = TimerP_PeriodType_MICROSECS;
    periodicTimerParams.arg = &periodicTimerHandle;
    periodicTimerParams.startMode = TimerP_StartMode_USER;
    periodicTimerParams.startMode = TimerP_StartMode_AUTO;
    periodicTimerParams.runMode = TimerP_RunMode_CONTINUOUS;

    /* Create Periodic Timer */
    appLogPrintf("*************** PROBE: Create Timer ***************** \n");
    periodicTimerHandle = TimerP_create(
					TIMER_ID,
					(TimerP_Fxn)&GW5300_PeriodicTests,
					&periodicTimerParams);
    if (periodicTimerHandle == NULL) {
       appLogPrintf("ERR: Timer create failed\n");
       return -1;
    }

    /* Start the Timer */
    appLogPrintf("*************** PROBE: Start Timer ***************** \n");
    timerStatus = TimerP_start(periodicTimerHandle);
    if (timerStatus != TimerP_OK) {
        appLogPrintf("ERR: Could not start the timer %d \n", TIMER_ID);
       return -1;
    }

    appLogWaitMsecs(1000);

    /* Stop the Timer */
    appLogPrintf("*************** PROBE: Stop Timer ***************** \n");
    timerStatus = TimerP_stop(periodicTimerHandle);
    if (timerStatus != TimerP_OK) {
        appLogPrintf("ERR: Could not stop the timer %d \n", TIMER_ID);
       return -1;
    }

    /* Delete the Timer */
    appLogPrintf("*************** PROBE: Delete Timer ***************** \n");
    timerStatus = TimerP_delete(periodicTimerHandle);
    if (timerStatus != TimerP_OK) {
        appLogPrintf("ERR: Could not delete the timer %d \n", TIMER_ID);
       return -1;
    }
    
    appLogPrintf("*************** PROBE END ***************** \n");
    
    ...


I have some questions:

  1. Do you have information about Timer APIs that you can share or tell me where to find it?
  2. What is the best way to implement Timers? Do you have examples?
  3. How can I compile and run the example found on the SDK?
  4. What do you think about my test? Is there something missing? Should I use a different API?

Thanks.

-Enrique

  • Hi Enrique,

    You can look at OSAL_timer_test in  <PDK_INSTALL_PATH>\packages\ti\osal\test\src\main_osal_test.c for reference to use TimerP APIs.

    You can also look at CSL timer example at <PDK_INSTALL_PATH>\packages\ti\csl\test\dmTimerUt

    How can I compile and run the example found on the SDK?

    Please refer to https://software-dl.ti.com/jacinto7/esd/processor-sdk-rtos-jacinto7/08_01_00_13/exports/docs/pdk_jacinto_08_01_00_36/docs/userguide/jacinto/getting_started.html for build steps

    What do you think about my test? Is there something missing? Should I use a different API?

    What is the interrupt number you are using for timer interrupt?

    Regards,
    Parth

  • Hi Parth,

    Thanks for your answer.

    What is the interrupt number you are using for timer interrupt?

    Do you mean the timer ID? I defined TIMER_ID to 1.

    Looking at the main_osal_test.c I came up with some questions in order to get my code working:

    1. Do I need to define an `HwiP_Handle`?

    2. Do I need to create a task? 

  • Hi Enrique,

    Do I need to define an `HwiP_Handle`?

    No you don't need to define this handle.

    Do I need to create a task? 

    You can, depending on your use case. If you have a lot of operations to be taken care by timer ISR, it's better to create a task.

    Regards,
    Parth

  • Hi Parth,

    Related to your first question:

    What is the interrupt number you are using for timer interrupt?

    Do you mean the timer ID? I defined TIMER_ID to 1.

    How should I select/define the interrupt number?

    And regarding this:

    I was able to compile the main_osal_test.c, by running this:

    make -s OSAL_TestApp BOARD=j721e_evm CORE=mpu1_0

    I the following files where generated:

    pdk_jacinto_07_00_00/packages/ti/binary/OSAL_TestApp/
    ├── bin
    │   └── d3_rvp
    │       ├── OSAL_d3_rvp_mpu1_0TestApp_release.appimage
    │       ├── OSAL_d3_rvp_mpu1_0TestApp_release.appimage.signed
    │       ├── OSAL_d3_rvp_mpu1_0TestApp_release_BE.appimage
    │       ├── OSAL_d3_rvp_mpu1_0TestApp_release.rprc
    │       ├── OSAL_d3_rvp_mpu1_0TestApp_release.xa72fg
    │       ├── OSAL_d3_rvp_mpu1_0TestApp_release.xa72fg.map
    │       └── sysbios_a72_pa53fg.rov.xs
    └── obj
        └── d3_rvp
            └── mpu1_0
                └── release
                    ├── configuro
                    │   ├── compiler.opt
                    │   ├── compiler.opt.defs
                    │   ├── config.bld
                    │   ├── custom.mak
                    │   ├── linker_mod.cmd
                    │   ├── package
                    │   │   ├── build.cfg
                    │   │   ├── cfg
                    │   │   │   ├── sysbios_a72_pa53fg.c
                    │   │   │   ├── sysbios_a72_pa53fg.cfg
                    │   │   │   ├── sysbios_a72_pa53fg.cfg.dot
                    │   │   │   ├── sysbios_a72_pa53fg.cfg.mak
                    │   │   │   ├── sysbios_a72_pa53fg.cfg.xml
                    │   │   │   ├── sysbios_a72_pa53fg.dep
                    │   │   │   ├── sysbios_a72_pa53fg.h
                    │   │   │   ├── sysbios_a72_pa53fg.mak
                    │   │   │   ├── sysbios_a72_pa53fg.oa53fg
                    │   │   │   ├── sysbios_a72_pa53fg.rov.xs
                    │   │   │   ├── sysbios_a72_pa53fg.rta.xml
                    │   │   │   ├── sysbios_a72_pa53fg.src
                    │   │   │   │   ├── makefile.libs
                    │   │   │   │   └── sysbios
                    │   │   │   │       ├── a15_TimerSupport.o
                    │   │   │   │       ├── a15_TimerSupport.o.dep
                    │   │   │   │       ├── arm_IntrinsicsSupport_asm_gnu.o
                    │   │   │   │       ├── arm_IntrinsicsSupport.o
                    │   │   │   │       ├── arm_IntrinsicsSupport.o.dep
                    │   │   │   │       ├── _BIOS.o
                    │   │   │   │       ├── _BIOS.o.dep
                    │   │   │   │       ├── dmtimer_Timer_asm_gnu.o
                    │   │   │   │       ├── dmtimer_Timer.o
                    │   │   │   │       ├── dmtimer_Timer.o.dep
                    │   │   │   │       ├── gates_GateHwi.o
                    │   │   │   │       ├── gates_GateHwi.o.dep
                    │   │   │   │       ├── gates_GateMutex.o
                    │   │   │   │       ├── gates_GateMutex.o.dep
                    │   │   │   │       ├── gates_GateSwi.o
                    │   │   │   │       ├── gates_GateSwi.o.dep
                    │   │   │   │       ├── gicv3_Hwi_asm_gnu.o
                    │   │   │   │       ├── gicv3_Hwi_asm_switch_gnu.o
                    │   │   │   │       ├── gicv3_Hwi_asm_vecs_gnu.o
                    │   │   │   │       ├── gicv3_Hwi.o
                    │   │   │   │       ├── gicv3_Hwi.o.dep
                    │   │   │   │       ├── gnu_ReentSupport.o
                    │   │   │   │       ├── gnu_ReentSupport.o.dep
                    │   │   │   │       ├── hal_Cache.o
                    │   │   │   │       ├── hal_Cache.o.dep
                    │   │   │   │       ├── hal_Hwi.o
                    │   │   │   │       ├── hal_Hwi.o.dep
                    │   │   │   │       ├── hal_Hwi_stack.o
                    │   │   │   │       ├── hal_Hwi_stack.o.dep
                    │   │   │   │       ├── hal_Hwi_startup.o
                    │   │   │   │       ├── hal_Hwi_startup.o.dep
                    │   │   │   │       ├── heaps_HeapBuf.o
                    │   │   │   │       ├── heaps_HeapBuf.o.dep
                    │   │   │   │       ├── heaps_HeapMem.o
                    │   │   │   │       ├── heaps_HeapMem.o.dep
                    │   │   │   │       ├── knl_Clock.o
                    │   │   │   │       ├── knl_Clock.o.dep
                    │   │   │   │       ├── knl_Idle.o
                    │   │   │   │       ├── knl_Idle.o.dep
                    │   │   │   │       ├── knl_Intrinsics.o
                    │   │   │   │       ├── knl_Intrinsics.o.dep
                    │   │   │   │       ├── knl_Queue.o
                    │   │   │   │       ├── knl_Queue.o.dep
                    │   │   │   │       ├── knl_Semaphore.o
                    │   │   │   │       ├── knl_Semaphore.o.dep
                    │   │   │   │       ├── knl_Swi.o
                    │   │   │   │       ├── knl_Swi.o.dep
                    │   │   │   │       ├── knl_Task.o
                    │   │   │   │       ├── knl_Task.o.dep
                    │   │   │   │       ├── makefile
                    │   │   │   │       ├── sysbios.aa53fg
                    │   │   │   │       ├── utils_Load_CPU.o
                    │   │   │   │       ├── utils_Load_CPU.o.dep
                    │   │   │   │       ├── utils_Load.o
                    │   │   │   │       ├── utils_Load.o.dep
                    │   │   │   │       ├── v8a_Cache_asm_gnu.o
                    │   │   │   │       ├── v8a_Cache.o
                    │   │   │   │       ├── v8a_Cache.o.dep
                    │   │   │   │       ├── v8a_Core_asm_gnu.o
                    │   │   │   │       ├── v8a_Core.o
                    │   │   │   │       ├── v8a_Core.o.dep
                    │   │   │   │       ├── v8a_Mmu.o
                    │   │   │   │       ├── v8a_Mmu.o.dep
                    │   │   │   │       ├── v8a_TaskSupport_asm_gnu.o
                    │   │   │   │       ├── v8a_TaskSupport.o
                    │   │   │   │       ├── v8a_TaskSupport.o.dep
                    │   │   │   │       ├── v8a_Timer_asm_gnu.o
                    │   │   │   │       ├── v8a_Timer.o
                    │   │   │   │       ├── v8a_Timer.o.dep
                    │   │   │   │       ├── v8a_TimestampProvider_asm_gnu.o
                    │   │   │   │       ├── v8a_TimestampProvider.o
                    │   │   │   │       └── v8a_TimestampProvider.o.dep
                    │   │   │   ├── sysbios_a72_pa53fg.xdc.inc
                    │   │   │   ├── sysbios_a72_pa53fg.xdl
                    │   │   │   └── sysbios_a72.xa53fg.mak
                    │   │   ├── configuro.ccs
                    │   │   ├── configuro.class
                    │   │   ├── configuro.java
                    │   │   ├── configuro.sch
                    │   │   ├── internal
                    │   │   ├── lib
                    │   │   ├── package.bld.xml
                    │   │   ├── package_configuro.c
                    │   │   ├── package.defs.h
                    │   │   ├── package.xdc.dep
                    │   │   ├── package.xdc.inc
                    │   │   └── rel
                    │   │       ├── configuro.xdc.inc
                    │   │       └── configuro.xdc.ninc
                    │   ├── package.bld
                    │   ├── package.mak
                    │   ├── package.xdc
                    │   └── package.xs
                    ├── little
                    └── main_osal_test.oa72fg

    However I'm not sure how to run the application. I tried running the only executable file created, but it showed a "core dummped" message:

    root@j7-evm:~# /tmp/OSAL_TestApp/bin/d3_rvp/OSAL_d3_rvp_mpu1_0TestApp_release.xa72fg 
    Illegal instruction (core dumped)

    Do you know how to run this app?


    Thanks,

    -Enrique

  • Hi Enrique,

    How should I select/define the interrupt number?

    You can refer to the same example  <PDK_INSTALL_PATH>\packages\ti\csl\test\dmTimerUt for reference.

    However I'm not sure how to run the application. I tried running the only executable file created, but it showed a "core dummped" message:

    I am not sure how you are trying to run this binary? Can you please provide details?

    However you can refer to https://software-dl.ti.com/jacinto7/esd/processor-sdk-rtos-jacinto7/07_03_00_07/exports/docs/psdk_rtos/docs/user_guide/ccs_setup_j721e.html for loading binary using CCS.

    Regards,
    Parth