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.

【原创】TIVA 中关于SysCtlDelay()函数的解析


我们知道,在TIVA中,延时函数用的是SysCtlDelay(),那么这个函数的参数是如何设置的呢?
首先找到这个函数的原型,在sysctl.c中,该函数的定义如下:

#if defined(ewarm) || defined(DOXYGEN)
void
SysCtlDelay(uint32_t ui32Count)
{
    __asm("    subs    r0, #1\n"
          "    bne.n   SysCtlDelay\n"
          "    bx      lr");
}
#endif
#if defined(codered) || defined(gcc) || defined(sourcerygxx)
void __attribute__((naked))
SysCtlDelay(uint32_t ui32Count)
{
    __asm("    subs    r0, #1\n"
          "    bne     SysCtlDelay\n"
          "    bx      lr");
}
#endif
#if defined(rvmdk) || defined(__ARMCC_VERSION)
__asm void
SysCtlDelay(uint32_t ui32Count)
{
    subs    r0, #1;
    bne     SysCtlDelay;
    bx      lr;
}
#endif
//

不管哪种环境下,都用了三条汇编指令。那么这个函数的延时时间为uint32_t ui32Count*3*(1/系统主时钟).
我们一般在程序中的写法为 SysCtlDelay(SysCtlClockGet() / M / 3);那么延时时间的计算为(SysCtlClockGet()/3M)*3/系统主时钟=1/M(s)
即不管系统主时钟为多少,函数SysCtlDelay(SysCtlClockGet() / M / 3)的延时时间都为1/M(s).