详细MSPM0库函数之delay_cycles()

[复制链接]
2790|5
 楼主| xyz549040622 发表于 2023-3-22 22:37 | 显示全部楼层 |阅读模式
本帖最后由 xyz549040622 于 2023-3-22 22:40 编辑

MSPM0的库函数中有一个延时函数,delay_cycles(cycles)
这个函数在dl_core.h中进行了宏定义
  1. #define delay_cycles(cycles) DL_Common_delayCycles(cycles)
DL_Common_delayCycles(cycles)这个函数其实在dl_common.c中进行了定义
  1. #include <stdint.h>

  2. #include <ti/driverlib/dl_common.h>

  3. void DL_Common_delayCycles(uint32_t cycles)
  4. {
  5.     /* There will be a 2 cycle delay here to fetch & decode instructions
  6.      * if branch and linking to this function */

  7.     /* Subtract 2 net cycles for constant offset: +2 cycles for entry jump,
  8.      * +2 cycles for exit, -1 cycle for a shorter loop cycle on the last loop,
  9.      * -1 for this instruction */

  10. #ifdef __GNUC__
  11.     __asm(".syntax unified");
  12. #endif
  13.     __asm volatile(
  14.         "SUBS     r0, r0, #2; \n"
  15.         "DL_Common_delayCyclesLoop: \n"
  16.         "SUBS     r0, r0, #4; \n"
  17.         "NOP; \n"
  18.         "BHS     DL_Common_delayCyclesLoop; \n"
  19.         /* Return: 2 cycles */

  20.     );
  21. }
数据手册中对这个函数的介绍如下所示:
QQ浏览器截图20230322223703.png

这个函数的作用是消耗指定的CPU周期数,可以通过这个值进行大概的时间延时。
zwsam 发表于 2023-3-27 09:13 | 显示全部楼层
zerorobert 发表于 2023-4-7 09:53 | 显示全部楼层
延时的CPU周期数 函数功能     
olivem55arlowe 发表于 2023-4-7 18:20 | 显示全部楼层
IAR 中有这样的一个函数 __delay_cycles()
cemaj 发表于 2023-4-8 19:31 | 显示全部楼层
delay_cycles()函数可以用来延时一定的CPU周期数,可以用来控制程序的执行速度,使程序的速度变得稳定,从而达到芯片效率的提高。
 楼主| xyz549040622 发表于 2023-8-27 18:18 | 显示全部楼层
cemaj 发表于 2023-4-8 19:31
delay_cycles()函数可以用来延时一定的CPU周期数,可以用来控制程序的执行速度,使程序的速度变得稳定,从 ...

对,比起自己写的延时函数,这个延时函数的准确率是相当高的,拿逻辑分析仪抓的时间也很准确。
您需要登录后才可以回帖 登录 | 注册

本版积分规则

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

2841

主题

19330

帖子

110

粉丝
快速回复 在线客服 返回列表 返回顶部