CC3200中1us延时的实现

首先,CC3200 系统延时函数 utils.c定义如下:

#include "utils.h"

//*****************************************************************************
//
//! Provides a small delay.
//!
//! \param ulCount is the number of delay loop iterations to perform.
//!
//! This function provides a means of generating a constant length delay.  It
//! is written in assembly to keep the delay consistent across tool chains,
//! avoiding the need to tune the delay based on the tool chain in use.
//!
//! The loop takes 3 cycles/loop.
//!
//! \return None.
//
//*****************************************************************************
#if defined(ewarm) || defined(DOXYGEN)
void
UtilsDelay(unsigned long ulCount)
{
    __asm("    subs    r0, #1\n"
          "    bne.n   UtilsDelay\n");
}
#endif


#if defined(gcc)
void __attribute__((naked))
UtilsDelay(unsigned long ulCount)
{
    __asm("    subs    r0, #1\n"
          "    bne     UtilsDelay\n"
          "    bx      lr");
}
#endif


//
// For CCS implement this function in pure assembly.  This prevents the TI
// compiler from doing funny things with the optimizer.
//
#if defined(ccs)
    __asm("    .sect \".text:UtilsDelay\"\n"
          "    .clink\n"
          "    .thumbfunc UtilsDelay\n"
          "    .thumb\n"
          "    .global UtilsDelay\n"
          "UtilsDelay:\n"
          "    subs r0, #1\n"
          "    bne.n UtilsDelay\n"
          "    bx lr\n");

#endif

一、 utils.c函数“The loop takes 3 cycles/loop”,主晶振为80MHz时,delaytime=填充的数值*3*(1/80000000)=1us,所以填充的数值=27。

二、需要较大的延时时也可以用示波器查看,先写一个延时翻转电平的小程序,然后用示波器查看方波的频率,从而计算出周期,然后可以知道自己的延时时间。

你可能感兴趣的:(延时函数,cc3200,1us延时函数)