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.

66AK2H14: ARM Cycle Delay

Part Number: 66AK2H14

Hello, I found an example of a cycle delay for and ARM core and the trouble is when I read the cycle count register is returns zero. Here is my code:

#include <ti/csl/csl_tmr.h>

static unsigned int ReadTime32(void)
{
unsigned int timeVal;

__asm__ __volatile__ ("MRC p15,0,%0,c9,c13,0\t\n" : "=r"(timeVal));

return timeVal;


}

void CycleDelay(unsigned int iCount)
{
if(iCount <=0)
{
return;
}
unsigned int start = ReadTime32();

while((ReadTime32() - start) < iCount);
}


#define CSL_GPIO_CFG_REGS 0x0260BF00
#define CSL_GPIO_DIR (*(unsigned int*)(CSL_GPIO_CFG_REGS + 0x010))
#define GPIO_SET_DATA (*(unsigned int*)(CSL_GPIO_CFG_REGS + 0x018))
#define GPIO_CLEAR_DATA (*(unsigned int*)(CSL_GPIO_CFG_REGS + 0x01C))

int main(void)
{
int i;

CSL_GPIO_DIR = 0xFFFE;

while(1)
{
GPIO_SET_DATA = 0x1;
CycleDelay(1000);
GPIO_CLEAR_DATA = 0x1;
for (i=0;i<100;i++);
}

return 0;
}

Here is my design:

8561.test.zip

The example I found did not list the main() so maybe there is some other things I need to do to get things working.

Thank you very much,

Joe

  • Hi Joe,

    It is Eric again. There may be some issue to use it in bare metal environment. I had an old CCS project for bare metal A15, I used it to profiling a function, how many cycles it used. The code looks like:

    void main()
    {
    int i;
    unsigned int start_time, end_time;

    ARM_CCNT_Enable();

    /* ======================================================================== */
    /* PREDEFINED TEST DATA */
    /* ======================================================================== */

    /* Obtain results using predefined test vectors */
    start_time = ARM_CCNT_Read();
     function to test
    end_time = ARM_CCNT_Read();

    }

    At least I knew the  ARM_CCNT_Read(); returns non-zero value. Then you can write a delay function use this.

    The ARM_CCNT_Read() is implemented as:

    .global ARM_CCNT_Read
    ARM_CCNT_Read:
    MRC P15, #0, R0, C9, C13, #0
    BX LR

    I attached the whole CCS project and hope you can find the counter is non-zero. You can ignore the function I tried to profile.

    Regards, Erichttps://e2e.ti.com/cfs-file/__key/communityserver-discussions-components-files/791/log10sp.7z 

  • Thank you very much. I really appreciate you sending the example code.

    Joe