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.

TMDXIDK5718: M4 task execution time

Part Number: TMDXIDK5718

Hi,

I was trying to calculate the execution time of a task running inside M4 with bare-metal code(No- OS), how I can do that.

I tried with example provided in C:\ti\pdk_am57xx_1_0_15\packages\ti\csl\example\timer\timer_app\main_m4.c  by using timers, but I am getting huge time period values. And I am getting 120 clock ticks for 2 successive TIMERCounterGet calls, why this much of huge values? Is any thing I am doing wrong?

SYS_CLK1 is the clock signal for the timer and in IDK board it's 20 MHz.

Below are the steps I have followed:

1. Started a timer4 with 60 sec timeout in interrupt mode

2. Reading the TIMERCounterGet before and after the task  execution, and calculating the number of clock ticks for executing the task

3. Calculating the time period from the difference in clock ticks,

time period = (clock ticks * 0.05 Micro sec)

As frequency is 20 Mhz, one clock tick will be 0.05 Micro Sec.

main_m4.c
/*
 *  Copyright (C) 2013-2017 Texas Instruments Incorporated - http://www.ti.com/
 *
 *  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.
 *
*/

/**
 *  \file   main_m4.c
 *
 *  \brief This file demonstrates TIMER dal.
 *
**/

/* ========================================================================== */
/*                             Include Files                                  */
/* ========================================================================== */
#include <ti/csl/example/utils/uart_console/inc/uartConfig.h>
#include "stdint.h"
#include "stdio.h"
#include <ti/csl/soc.h>
#include <ti/csl/csl_timer.h>
#include "sample.h"
#include <ti/csl/csl_types.h>
#include <ti/csl/arch/csl_arch.h>
#if defined (SOC_AM574x) || defined (SOC_AM572x) || defined (SOC_AM571x)
#include <ti/board/board.h>
#endif

/* ========================================================================== */
/*                           Macros & Typedefs                                */
/* ========================================================================== */
#if defined (SOC_AM574x) || defined (SOC_AM572x) || defined (SOC_AM571x)
uint32_t INP_CLK_FREQ           =        20000000U;
uint32_t TIMER_INITIAL_COUNT    =        0U;
uint32_t TIMER_RLD_COUNT        =        0U;
void Timer_val(uint32_t inp_clk, uint32_t delay, uint32_t prescl_val);
#else
#define TIMER_INITIAL_COUNT             (0xFFF00000U)
#define TIMER_RLD_COUNT                 (0xFFF00000U)
#endif

#if defined (SOC_AM574x) || defined (SOC_AM572x) || defined (SOC_AM571x)
uint32_t irq_count = CSL_IPU_IRQ_XBAR_COUNT;
uint32_t uartBaseAddr = CSL_MPU_UART3_REGS;
#endif
#if defined (SOC_TDA2XX) || defined (SOC_TDA2PX) || defined (SOC_TDA2EX) || defined (SOC_DRA72x) || defined (SOC_DRA75x)
uint32_t irq_count = CSL_IPU1_IRQ_XBAR_COUNT;
uint32_t uartBaseAddr = SOC_UART1_BASE;
#endif
#if defined (SOC_TDA3XX) || defined (SOC_DRA78x)
uint32_t irq_count = CSL_IPU1_IRQ_XBAR_COUNT;
uint32_t uartBaseAddr = SOC_UART3_BASE;
#endif

/* ========================================================================== */
/*                   Internal Varialbes Definitions                           */
/* ========================================================================== */
static volatile uint32_t gCntValue     = 10;
static volatile uint32_t gIsrSemaphore = 0;
static volatile uint32_t gXbarInst     = 1;
static volatile uint32_t gNumSuccess   = 0;

/* ========================================================================== */
/*                   Internal Function Declarations                           */
/* ========================================================================== */
static void TimerPRCMConfigure(void);
static void TimerIntcInit(void);
static void TimerIntcDeInit(void);
static void TimerSetUp(void);
static void TimerIsr(void *handle);
static void TimerRun(void);

/* ========================================================================== */
/*                          Function Definitions                              */
/* ========================================================================== */
void padConfig_prcmEnable()
{
#if defined (SOC_AM574x) || defined (SOC_AM572x) || defined (SOC_AM571x)
    /*Pad configurations */
    Board_initCfg boardCfg;
    boardCfg = BOARD_INIT_UNLOCK_MMR | BOARD_INIT_UART_STDIO | 
               BOARD_INIT_MODULE_CLOCK | BOARD_INIT_PINMUX_CONFIG;
    Board_init(boardCfg);
#endif
#if defined (SOC_TDA2XX) || defined (SOC_TDA2PX) || defined (SOC_TDA2EX) || defined (SOC_DRA72x) || defined (SOC_DRA75x)
    /*Pad configurations */
    HW_WR_REG32(SOC_CORE_PAD_IO_REGISTERS_BASE+CTRL_CORE_PAD_UART1_RXD,0x00040000);
    HW_WR_REG32(SOC_CORE_PAD_IO_REGISTERS_BASE+CTRL_CORE_PAD_UART1_TXD,0x00000000);
    /* Initialize the UART Instance */
    UARTConfigInit(uartBaseAddr, BAUD_RATE_115200, UART_WORD_LENGTH_8, UART_STOP_BIT_1, UART_NO_PARITY,
                    UART_16x_MODE);
#endif
#if defined (SOC_TDA3XX) || defined (SOC_DRA78x)
    /*Pad configurations */
    HW_WR_REG32(SOC_CORE_PAD_IO_REGISTERS_BASE+CTRL_CORE_PAD_IO_SPI1_SCLK,0x00040001);
    HW_WR_REG32(SOC_CORE_PAD_IO_REGISTERS_BASE+CTRL_CORE_PAD_IO_SPI1_CS0,0x00000001);
    /* Initialize the UART Instance */
    UARTConfigInit(uartBaseAddr, BAUD_RATE_115200, UART_WORD_LENGTH_8, UART_STOP_BIT_1, UART_NO_PARITY,
                    UART_16x_MODE);
#endif
}

int main(void)
{
    /* Do Pad Config for UART */
    padConfig_prcmEnable();

    /*Set PRCM for Timer4 */
    /*This is done in SBL, adding here to make the app standalone */
    TimerPRCMConfigure();

#if defined (SOC_AM574x) || defined (SOC_AM572x) || defined (SOC_AM571x)
    /*Set the timer reload count value */
    Timer_val(INP_CLK_FREQ, 50000U,1U);
#endif

    UARTConfigPuts(uartBaseAddr,"\nTimer Application Running", -1);

    /* Run the Timer irq_count times,
     * increment gXbarInst in each iteration */
    for (gXbarInst = 1; gXbarInst <= irq_count; gXbarInst++)
    {
        TimerRun();
    }

    if (gNumSuccess == irq_count)
    {
        UARTConfigPuts(uartBaseAddr,"\nAll Xbar instances for M4 are verified successfully", -1);
    }
    return 0;
}

static void TimerRun(void)
{
    /* Register Timer4 interrupts on to INTC */
    TimerIntcInit();

    /* Perform the necessary configurations for Timer4 */
    TimerSetUp();

    /* Enable the Timer4 interrupts */
    TIMERIntEnable(SOC_TIMER4_BASE, TIMER_INT_OVF_EN_FLAG);

    /* Start the Timer */
    TIMEREnable(SOC_TIMER4_BASE);

    UARTConfigPuts(uartBaseAddr,"\ncntValue:", -1);

    while (gCntValue)
    {
        if (gIsrSemaphore)
        {
            gIsrSemaphore--;
            UARTConfigPuts(uartBaseAddr," ", -1);
            UARTConfigPutNum(uartBaseAddr,(int32_t)gCntValue);
        }
    }

    /* Stop the Timer */
    TIMERDisable(SOC_TIMER4_BASE);

    if (gCntValue == 0)
    {
        UARTConfigPuts(uartBaseAddr,"\n|RESULT|SUCCESS|", -1);
    }
    else
    {
        UARTConfigPuts(uartBaseAddr,"\n|RESULT|FAIL|", -1);
    }

    /* Unregister Timer4 interrupts */
    TimerIntcDeInit();
}

/*
** Do the necessary Timer configurations on to INTC.
*/
static void TimerIntcInit(void)
{
    CSL_xbarIrqConfigure(CSL_XBAR_IRQ_CPU_ID_IPU1,gXbarInst,CSL_XBAR_TIMER4_IRQ);

    UARTConfigPuts(uartBaseAddr,"\nXBar is sucessfully connected to inst:", -1);
    UARTConfigPutNum(uartBaseAddr,(int32_t)gXbarInst);

    /* Initialize the interrupt control */
    Intc_Init();

    /* Enable the interrupt */
    Intc_IntEnable(0);

    /* Registering TimerIsr */
    Intc_IntRegister(intrM4[gXbarInst - 1], (IntrFuncPtr) TimerIsr, NULL);

    /* Set the priority */
    Intc_IntPrioritySet(intrM4[gXbarInst - 1], 1, 0);

    /* Enable the system interrupt */
    Intc_SystemEnable(intrM4[gXbarInst - 1]);
}

/*
** Disable the interrupt configurations on INTC.
*/
static void TimerIntcDeInit(void)
{
    /* Restore the initial state of gCntValue */
    gCntValue = 10;

    /* Disconnect the XBar */
    CSL_xbarIrqConfigure(CSL_XBAR_IRQ_CPU_ID_IPU1,gXbarInst,CSL_XBAR_IRQ_MIN);

    /* Disable the timer interrupt */
    Intc_SystemDisable(intrM4[gXbarInst - 1]);

    /* Unregister the interrupt */
    Intc_IntUnregister(intrM4[gXbarInst - 1]);
}

/*
** Setup the timer for one-shot and compare mode.
*/
static void TimerSetUp(void)
{
    /*Reset the timer module */
    TIMERReset(SOC_TIMER4_BASE);

    /* Enable free run in emulation mode */
    TIMEREmuModeConfigure(SOC_TIMER4_BASE, TIMER_FREE);

    /* Load the counter with the initial count value */
    TIMERCounterSet(SOC_TIMER4_BASE, TIMER_INITIAL_COUNT);

    /* Load the load register with the reload count value */
    TIMERReloadSet(SOC_TIMER4_BASE, TIMER_RLD_COUNT);

    /* Configure the Timer for Auto-reload and compare mode */
    TIMERModeConfigure(SOC_TIMER4_BASE, TIMER_AUTORLD_NOCMP_ENABLE);

    /* Configure the posted mode of TIMER */
    TIMERPostedModeConfig(SOC_TIMER4_BASE, TIMER_NONPOSTED);

    /* Configure the read mode of TIMER */
    TIMERReadModeConfig(SOC_TIMER4_BASE, TIMER_READ_MODE_NONPOSTED);
}

/*
** Timer interrupt service routine. This will send a character to serial
** console.
*/
static void TimerIsr(void *handle)
{
    /* Disable the Timer interrupts */
    TIMERIntDisable(SOC_TIMER4_BASE, TIMER_INT_OVF_EN_FLAG);

    /* Clear the status of the interrupt flags */
    TIMERIntStatusClear(SOC_TIMER4_BASE, TIMER_INT_OVF_IT_FLAG);

    gIsrSemaphore++;
    gCntValue--;

    if (gCntValue == 0)
    {
        UARTConfigPuts(uartBaseAddr," ", -1);
        UARTConfigPutNum(uartBaseAddr,(int32_t) (gCntValue));
        gIsrSemaphore = 0;
        gNumSuccess++;
    }

    /* Enable the Timer interrupts */
    TIMERIntEnable(SOC_TIMER4_BASE, TIMER_INT_OVF_EN_FLAG);
}

/*
** Timer4 PRCM configuration. This will explicitly enable the Timer4 module.
*/
static void TimerPRCMConfigure(void)
{
    HW_WR_REG32(SOC_L4PER_CM_CORE_BASE + CM_L4PER_TIMER4_CLKCTRL, 0x2);

    while ((HW_RD_REG32(SOC_L4PER_CM_CORE_BASE +
                        CM_L4PER_TIMER4_CLKCTRL) & (0x00030000)) != 0x0) ;
}

/*
** This function is used to find the timer count value 
** required for the provided delay
** inp_clk is the input clock source of the timer.
** time unit is always micro seconds.
** prescl_val defines the timer prescale value.
*/
#if defined (SOC_AM574x) || defined (SOC_AM572x) || defined (SOC_AM571x)
void Timer_val(uint32_t inp_clk, uint32_t delay, uint32_t prescl_val)
{
   uint32_t divisor = 1000000U, count = 0U;
   
   divisor = divisor * prescl_val;
   count = (inp_clk / divisor) * delay;
   if(count <= 0xffffffffU)
   {
        TIMER_INITIAL_COUNT = 0xffffffff - count;
        TIMER_RLD_COUNT = 0xffffffff - count;
   }
   else
   {
        TIMER_INITIAL_COUNT = 0U;
        TIMER_RLD_COUNT = 0U;
   }
}
#endif

/********************************* End of file ******************************/

And one more doubt, as M4 is not supporting Hardware FPU's what is the added delay if I use software FPU library in the application execution time. 

Regards,

Naveen.

  • Hi Naveen,

    I think it's OK to use a timer for profiling M4 code. I need to check the M4 bare-metal timer example to see how it operates.

    I have a few question for you:

    • How are you configuring the IPU SS clock? Are you using a GEL file?
    • How are you configuring the IPU SS MMUs (IPUx_UNICACHE_MMU & IPUx_MMU)? Are you relying on CSL startup code, or are you explicitly configuring these MMUs?
    • What do you mean by "task" in a bare-metal (non-OS) context? Are you profiling a function, or a smaller piece of code (e.g. a loop)?
    • Are you profiling code which reads/write peripheral registers?
    • What leads you to conclude the timer counts are too high for the code you're profiling? Do you have an expected upper bound for the timer count?

    I don't have any information on M4 floating-point performance without an FPU. I'll investigate this further internally to see if can locate any data. Does your application require floating-point data? Can you use the DSP extensions for your calculations?

    Regards,
    Frank

  • Dear Frank,

    Below are my answers to your questions.

    1. I was using the bare-metal application with CSL timer drivers. I am using CCS to test the code, first connecting to A15 then DDR memory config followed by enabling all cores from scripts tab in CCS, then I am connecting and loading the code onto M4.

    In M4 I was initializing the uart, pinmux conf, module clock. Then I am initializing the Timers and trying to capture the execution time.

                               boardCfg = BOARD_INIT_MODULE_CLOCK |
                                                  BOARD_INIT_PINMUX_CONFIG |
                                                  BOARD_INIT_UART_STDIO |
                                                  BOARD_INIT_UNLOCK_MMR;

                              status = Board_init(boardCfg);

    I was using the Example file as attached in , 

    6087.main_m4.c
    /*
     *  Copyright (C) 2013-2017 Texas Instruments Incorporated - http://www.ti.com/
     *
     *  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.
     *
    */
    
    /**
     *  \file   main_m4.c
     *
     *  \brief This file demonstrates TIMER dal.
     *
    **/
    
    /* ========================================================================== */
    /*                             Include Files                                  */
    /* ========================================================================== */
    #include <ti/csl/example/utils/uart_console/inc/uartConfig.h>
    #include "stdint.h"
    #include "stdio.h"
    #include <ti/csl/soc.h>
    #include <ti/csl/csl_timer.h>
    #include "sample.h"
    #include <ti/csl/csl_types.h>
    #include <ti/csl/arch/csl_arch.h>
    #if defined (SOC_AM574x) || defined (SOC_AM572x) || defined (SOC_AM571x)
    #include <ti/board/board.h>
    #endif
    
    /* ========================================================================== */
    /*                           Macros & Typedefs                                */
    /* ========================================================================== */
    #if defined (SOC_AM574x) || defined (SOC_AM572x) || defined (SOC_AM571x)
    uint32_t INP_CLK_FREQ           =        20000000U;
    uint32_t TIMER_INITIAL_COUNT    =        0U;
    uint32_t TIMER_RLD_COUNT        =        0U;
    void Timer_val(uint32_t inp_clk, uint32_t delay, uint32_t prescl_val);
    #else
    #define TIMER_INITIAL_COUNT             (0xFFF00000U)
    #define TIMER_RLD_COUNT                 (0xFFF00000U)
    #endif
    
    #if defined (SOC_AM574x) || defined (SOC_AM572x) || defined (SOC_AM571x)
    uint32_t irq_count = CSL_IPU_IRQ_XBAR_COUNT;
    uint32_t uartBaseAddr = CSL_MPU_UART3_REGS;
    #endif
    #if defined (SOC_TDA2XX) || defined (SOC_TDA2PX) || defined (SOC_TDA2EX) || defined (SOC_DRA72x) || defined (SOC_DRA75x)
    uint32_t irq_count = CSL_IPU1_IRQ_XBAR_COUNT;
    uint32_t uartBaseAddr = SOC_UART1_BASE;
    #endif
    #if defined (SOC_TDA3XX) || defined (SOC_DRA78x)
    uint32_t irq_count = CSL_IPU1_IRQ_XBAR_COUNT;
    uint32_t uartBaseAddr = SOC_UART3_BASE;
    #endif
    
    /* ========================================================================== */
    /*                   Internal Varialbes Definitions                           */
    /* ========================================================================== */
    static volatile uint32_t gCntValue     = 10;
    static volatile uint32_t gIsrSemaphore = 0;
    static volatile uint32_t gXbarInst     = 1;
    static volatile uint32_t gNumSuccess   = 0;
    
    /* ========================================================================== */
    /*                   Internal Function Declarations                           */
    /* ========================================================================== */
    static void TimerPRCMConfigure(void);
    static void TimerIntcInit(void);
    static void TimerIntcDeInit(void);
    static void TimerSetUp(void);
    static void TimerIsr(void *handle);
    static void TimerRun(void);
    
    /* ========================================================================== */
    /*                          Function Definitions                              */
    /* ========================================================================== */
    void padConfig_prcmEnable()
    {
    #if defined (SOC_AM574x) || defined (SOC_AM572x) || defined (SOC_AM571x)
        /*Pad configurations */
        Board_initCfg boardCfg;
        boardCfg = BOARD_INIT_UNLOCK_MMR | BOARD_INIT_UART_STDIO | 
                   BOARD_INIT_MODULE_CLOCK | BOARD_INIT_PINMUX_CONFIG;
        Board_init(boardCfg);
    #endif
    #if defined (SOC_TDA2XX) || defined (SOC_TDA2PX) || defined (SOC_TDA2EX) || defined (SOC_DRA72x) || defined (SOC_DRA75x)
        /*Pad configurations */
        HW_WR_REG32(SOC_CORE_PAD_IO_REGISTERS_BASE+CTRL_CORE_PAD_UART1_RXD,0x00040000);
        HW_WR_REG32(SOC_CORE_PAD_IO_REGISTERS_BASE+CTRL_CORE_PAD_UART1_TXD,0x00000000);
        /* Initialize the UART Instance */
        UARTConfigInit(uartBaseAddr, BAUD_RATE_115200, UART_WORD_LENGTH_8, UART_STOP_BIT_1, UART_NO_PARITY,
                        UART_16x_MODE);
    #endif
    #if defined (SOC_TDA3XX) || defined (SOC_DRA78x)
        /*Pad configurations */
        HW_WR_REG32(SOC_CORE_PAD_IO_REGISTERS_BASE+CTRL_CORE_PAD_IO_SPI1_SCLK,0x00040001);
        HW_WR_REG32(SOC_CORE_PAD_IO_REGISTERS_BASE+CTRL_CORE_PAD_IO_SPI1_CS0,0x00000001);
        /* Initialize the UART Instance */
        UARTConfigInit(uartBaseAddr, BAUD_RATE_115200, UART_WORD_LENGTH_8, UART_STOP_BIT_1, UART_NO_PARITY,
                        UART_16x_MODE);
    #endif
    }
    
    int main(void)
    {
        /* Do Pad Config for UART */
        padConfig_prcmEnable();
    
        /*Set PRCM for Timer4 */
        /*This is done in SBL, adding here to make the app standalone */
        TimerPRCMConfigure();
    
    #if defined (SOC_AM574x) || defined (SOC_AM572x) || defined (SOC_AM571x)
        /*Set the timer reload count value */
        Timer_val(INP_CLK_FREQ, 50000U,1U);
    #endif
    
        UARTConfigPuts(uartBaseAddr,"\nTimer Application Running", -1);
    
        /* Run the Timer irq_count times,
         * increment gXbarInst in each iteration */
        for (gXbarInst = 1; gXbarInst <= irq_count; gXbarInst++)
        {
            TimerRun();
        }
    
        if (gNumSuccess == irq_count)
        {
            UARTConfigPuts(uartBaseAddr,"\nAll Xbar instances for M4 are verified successfully", -1);
        }
        return 0;
    }
    
    static void TimerRun(void)
    {
        /* Register Timer4 interrupts on to INTC */
        TimerIntcInit();
    
        /* Perform the necessary configurations for Timer4 */
        TimerSetUp();
    
        /* Enable the Timer4 interrupts */
        TIMERIntEnable(SOC_TIMER4_BASE, TIMER_INT_OVF_EN_FLAG);
    
        /* Start the Timer */
        TIMEREnable(SOC_TIMER4_BASE);
    
        UARTConfigPuts(uartBaseAddr,"\ncntValue:", -1);
    
        while (gCntValue)
        {
            if (gIsrSemaphore)
            {
                gIsrSemaphore--;
                UARTConfigPuts(uartBaseAddr," ", -1);
                UARTConfigPutNum(uartBaseAddr,(int32_t)gCntValue);
            }
        }
    
        /* Stop the Timer */
        TIMERDisable(SOC_TIMER4_BASE);
    
        if (gCntValue == 0)
        {
            UARTConfigPuts(uartBaseAddr,"\n|RESULT|SUCCESS|", -1);
        }
        else
        {
            UARTConfigPuts(uartBaseAddr,"\n|RESULT|FAIL|", -1);
        }
    
        /* Unregister Timer4 interrupts */
        TimerIntcDeInit();
    }
    
    /*
    ** Do the necessary Timer configurations on to INTC.
    */
    static void TimerIntcInit(void)
    {
        CSL_xbarIrqConfigure(CSL_XBAR_IRQ_CPU_ID_IPU1,gXbarInst,CSL_XBAR_TIMER4_IRQ);
    
        UARTConfigPuts(uartBaseAddr,"\nXBar is sucessfully connected to inst:", -1);
        UARTConfigPutNum(uartBaseAddr,(int32_t)gXbarInst);
    
        /* Initialize the interrupt control */
        Intc_Init();
    
        /* Enable the interrupt */
        Intc_IntEnable(0);
    
        /* Registering TimerIsr */
        Intc_IntRegister(intrM4[gXbarInst - 1], (IntrFuncPtr) TimerIsr, NULL);
    
        /* Set the priority */
        Intc_IntPrioritySet(intrM4[gXbarInst - 1], 1, 0);
    
        /* Enable the system interrupt */
        Intc_SystemEnable(intrM4[gXbarInst - 1]);
    }
    
    /*
    ** Disable the interrupt configurations on INTC.
    */
    static void TimerIntcDeInit(void)
    {
        /* Restore the initial state of gCntValue */
        gCntValue = 10;
    
        /* Disconnect the XBar */
        CSL_xbarIrqConfigure(CSL_XBAR_IRQ_CPU_ID_IPU1,gXbarInst,CSL_XBAR_IRQ_MIN);
    
        /* Disable the timer interrupt */
        Intc_SystemDisable(intrM4[gXbarInst - 1]);
    
        /* Unregister the interrupt */
        Intc_IntUnregister(intrM4[gXbarInst - 1]);
    }
    
    /*
    ** Setup the timer for one-shot and compare mode.
    */
    static void TimerSetUp(void)
    {
        /*Reset the timer module */
        TIMERReset(SOC_TIMER4_BASE);
    
        /* Enable free run in emulation mode */
        TIMEREmuModeConfigure(SOC_TIMER4_BASE, TIMER_FREE);
    
        /* Load the counter with the initial count value */
        TIMERCounterSet(SOC_TIMER4_BASE, TIMER_INITIAL_COUNT);
    
        /* Load the load register with the reload count value */
        TIMERReloadSet(SOC_TIMER4_BASE, TIMER_RLD_COUNT);
    
        /* Configure the Timer for Auto-reload and compare mode */
        TIMERModeConfigure(SOC_TIMER4_BASE, TIMER_AUTORLD_NOCMP_ENABLE);
    
        /* Configure the posted mode of TIMER */
        TIMERPostedModeConfig(SOC_TIMER4_BASE, TIMER_NONPOSTED);
    
        /* Configure the read mode of TIMER */
        TIMERReadModeConfig(SOC_TIMER4_BASE, TIMER_READ_MODE_NONPOSTED);
    }
    
    /*
    ** Timer interrupt service routine. This will send a character to serial
    ** console.
    */
    static void TimerIsr(void *handle)
    {
        /* Disable the Timer interrupts */
        TIMERIntDisable(SOC_TIMER4_BASE, TIMER_INT_OVF_EN_FLAG);
    
        /* Clear the status of the interrupt flags */
        TIMERIntStatusClear(SOC_TIMER4_BASE, TIMER_INT_OVF_IT_FLAG);
    
        gIsrSemaphore++;
        gCntValue--;
    
        if (gCntValue == 0)
        {
            UARTConfigPuts(uartBaseAddr," ", -1);
            UARTConfigPutNum(uartBaseAddr,(int32_t) (gCntValue));
            gIsrSemaphore = 0;
            gNumSuccess++;
        }
    
        /* Enable the Timer interrupts */
        TIMERIntEnable(SOC_TIMER4_BASE, TIMER_INT_OVF_EN_FLAG);
    }
    
    /*
    ** Timer4 PRCM configuration. This will explicitly enable the Timer4 module.
    */
    static void TimerPRCMConfigure(void)
    {
        HW_WR_REG32(SOC_L4PER_CM_CORE_BASE + CM_L4PER_TIMER4_CLKCTRL, 0x2);
    
        while ((HW_RD_REG32(SOC_L4PER_CM_CORE_BASE +
                            CM_L4PER_TIMER4_CLKCTRL) & (0x00030000)) != 0x0) ;
    }
    
    /*
    ** This function is used to find the timer count value 
    ** required for the provided delay
    ** inp_clk is the input clock source of the timer.
    ** time unit is always micro seconds.
    ** prescl_val defines the timer prescale value.
    */
    #if defined (SOC_AM574x) || defined (SOC_AM572x) || defined (SOC_AM571x)
    void Timer_val(uint32_t inp_clk, uint32_t delay, uint32_t prescl_val)
    {
       uint32_t divisor = 1000000U, count = 0U;
       
       divisor = divisor * prescl_val;
       count = (inp_clk / divisor) * delay;
       if(count <= 0xffffffffU)
       {
            TIMER_INITIAL_COUNT = 0xffffffff - count;
            TIMER_RLD_COUNT = 0xffffffff - count;
       }
       else
       {
            TIMER_INITIAL_COUNT = 0U;
            TIMER_RLD_COUNT = 0U;
       }
    }
    #endif
    
    /********************************* End of file ******************************/
    

    So I suppose the IPU SS Clock and IPU SS MMU initialization are  done by CCS from GEL script files during initialization. 

    2.  I am not configuring any unicache inside the M4 code, could you please suggest the required changes inside the code.

    3.  I am trying to calculate the execution time of a function.

    4. No, I am not doing any peripheral read/write operations.

    5. Yes, when I calculated time delay b/w 2 successive TIMERCounterGet calls, it's 6 Micro Sec. As M4 is running with 212 Mhz, each instruction will only take 4.7 Nano sec, with in 6 micro sec it can execute almost 1200 instructions,  so why I am reading this much high values?

    The input clock for timer is configured for SYSCLK1 and I suppose it's 20 MHZ external source on the AM5718IDK board.

    Please suggest me what are the changes required to calculate the execution time of a task, we have to take the architectural decision so please reply me asap. 

    Regards,

    Naveen.

  • Dear Frank,

    I am waiting for your reply, have tested the code I have shared with you?

    Regards,

    Naveen.

  • Naveen,

    I've received the code. I'll take a look as soon as possible.

    Regards,
    Frank

  • HI Naveen,

    Sorry for the delayed response on this. I've started looking at the example code on M4. Before proceeding, though, I want to make sure this is still a concern for you. Are you still facing this issue?

    Thanks,
    Frank

  • Dear Frank,

    After enabling the M4 IPU_UNICACHE the time periods reduced drastically from 210 micro sec to 20 micro, but we are not OK with that time periods. As M4 doesn't support FPU and seeing these time periods, we are thinking how to proceed.further.

    And by enabling MMU will reduce duration any further? or is any other configurations I have missed?

    Regards,

    Naveen.

  • Hi Naveen,

    Are your updated IPU_UNICACHE settings contained in the code you shared? If not, can you please provide an update?

    What is your time period budget?

    Regards,
    Frank

  • Dear Frank,

    I enabled the uni cache from CCS,

    Connect to M4 core -> IPU1_UNICAHE_CFG -> CACHE_CONFIG -> BYPASS -> BYPASS_1

    Enabling inside the M4 code will not work I suppose, we have to configure from A15 or boot-loader. If it's possible inside the M4 core, kindly share it the code.

    We want a 10 to 20 micro sec range for doing a some conditional checks, what is the through put of the M4 core.

    Regards,

    Naveen.

  • Naveen,

    This thread concerning UNICACHE configuration for reducing code cycle counts may be of help: https://e2e.ti.com/support/processors/f/791/t/711906

    Regards,
    Frank