打印

详细MSPM0库函数之delay_cycles()

[复制链接]
320|5
手机看帖
扫描二维码
随时随地手机跟帖
跳转到指定楼层
楼主
本帖最后由 xyz549040622 于 2023-3-22 22:40 编辑

MSPM0的库函数中有一个延时函数,delay_cycles(cycles)
这个函数在dl_core.h中进行了宏定义
#define delay_cycles(cycles) DL_Common_delayCycles(cycles)
DL_Common_delayCycles(cycles)这个函数其实在dl_common.c中进行了定义
#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周期数,可以通过这个值进行大概的时间延时。

使用特权

评论回复
沙发
zwsam| | 2023-3-27 09:13 | 只看该作者

使用特权

评论回复
板凳
zerorobert| | 2023-4-7 09:53 | 只看该作者
延时的CPU周期数 函数功能     

使用特权

评论回复
地板
olivem55arlowe| | 2023-4-7 18:20 | 只看该作者
IAR 中有这样的一个函数 __delay_cycles()

使用特权

评论回复
5
cemaj| | 2023-4-8 19:31 | 只看该作者
delay_cycles()函数可以用来延时一定的CPU周期数,可以用来控制程序的执行速度,使程序的速度变得稳定,从而达到芯片效率的提高。

使用特权

评论回复
6
xyz549040622|  楼主 | 2023-8-27 18:18 | 只看该作者
cemaj 发表于 2023-4-8 19:31
delay_cycles()函数可以用来延时一定的CPU周期数,可以用来控制程序的执行速度,使程序的速度变得稳定,从 ...

对,比起自己写的延时函数,这个延时函数的准确率是相当高的,拿逻辑分析仪抓的时间也很准确。

使用特权

评论回复
发新帖 我要提问
您需要登录后才可以回帖 登录 | 注册

本版积分规则

个人签名:qq群: 嵌入式系统arm初学者 224636155←← +→→点击-->小 i 精品课全集,21ic公开课~~←←→→点击-->小 i 精品课全集,给你全方位的技能策划~~←←

2669

主题

19102

帖子

102

粉丝