| 本帖最后由 xyz549040622 于 2023-3-22 22:40 编辑 
 MSPM0的库函数中有一个延时函数,delay_cycles(cycles)
 这个函数在dl_core.h中进行了宏定义
 
 DL_Common_delayCycles(cycles)这个函数其实在dl_common.c中进行了定义#define delay_cycles(cycles) DL_Common_delayCycles(cycles)
 数据手册中对这个函数的介绍如下所示:#include <stdint.h>
#include <ti/driverlib/dl_common.h>
void DL_Common_delayCycles(uint32_t cycles)
{
    /* There will be a 2 cycle delay here to fetch & decode instructions
     * if branch and linking to this function */
    /* Subtract 2 net cycles for constant offset: +2 cycles for entry jump,
     * +2 cycles for exit, -1 cycle for a shorter loop cycle on the last loop,
     * -1 for this instruction */
#ifdef __GNUC__
    __asm(".syntax unified");
#endif
    __asm volatile(
        "SUBS     r0, r0, #2; \n"
        "DL_Common_delayCyclesLoop: \n"
        "SUBS     r0, r0, #4; \n"
        "NOP; \n"
        "BHS     DL_Common_delayCyclesLoop; \n"
        /* Return: 2 cycles */
    );
}
   
 这个函数的作用是消耗指定的CPU周期数,可以通过这个值进行大概的时间延时。
 
 |