delay.h 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. /**
  2. *****************************************************************************
  3. * 系统延时相关的函数
  4. * 详细说明请参考《Cortex-M3权威指南(中文)》第133 ~ 134页 第8章 SysTick定时器介绍
  5. *
  6. * (C) Copyright 2000-2020, ***
  7. * All Rights Reserved
  8. *****************************************************************************
  9. *
  10. * @File : delay.h
  11. * @By : 陈桂东
  12. * @Version : V1.0
  13. * @Date : 2012 / 10 / 20
  14. *
  15. *****************************************************************************
  16. * Update
  17. * @Version : V1.0.1
  18. * @By : 陈桂东
  19. * @Date : 2014 / 02 / 26
  20. * @Brief : 增加另外一种延时计算方法
  21. *
  22. * @Version : V1.1
  23. * @By : 陈桂东
  24. * @Date : 2014 / 05 / 24
  25. * @Brief : A、增加对C++环境支持
  26. * B、修改在跑ucos时初始化嘀嗒定时器、延时us和ms函数
  27. *
  28. * @Version : V1.2
  29. * @By : 陈桂东
  30. * @Date : 2015 / 10 / 03
  31. * @Brief : 优化延时函数
  32. *
  33. *****************************************************************************
  34. **/
  35. #ifndef _delay_h
  36. #define _delay_h
  37. /**
  38. ****************************** Support C++ **********************************
  39. **/
  40. #ifdef __cplusplus
  41. extern "C" {
  42. #endif
  43. /**
  44. *****************************************************************************
  45. **/
  46. /******************************************************************************
  47. 外部函数头文件
  48. ******************************************************************************/
  49. #include "sys.h"
  50. /******************************************************************************
  51. 定义延时时基来源
  52. ******************************************************************************/
  53. #define _USER_OtherDelay 0
  54. //0: 使用的是嘀嗒定时器做延时
  55. //1: 使用其他资源进行延时
  56. /******************************************************************************
  57. 定义其他延时计数资源
  58. ******************************************************************************/
  59. #if _USER_OtherDelay == 1
  60. #define DWT_CTRL *(volatile uint32_t*)0xE0001000 //DWT控制寄存器
  61. #define DWT_CYCCNT *(volatile uint32_t*)0xE0001004 //DWT当前PC采样周期计数寄存器
  62. //详细见:周立功《CM3计数参考手册》第129页介绍
  63. #define DWT_CPICNT *(volatile uint32_t*)0xE0001008 //DWT当前CPI计数寄存器
  64. #define DEM_CTRL *(volatile uint32_t*)0xE000EDFC //调试异常和监控控制寄存器
  65. #endif
  66. /******************************************************************************
  67. 外部功能函数
  68. ******************************************************************************/
  69. void delay_init ( void ); //初始化延时函数
  70. void delay_us ( uint32_t nus ); //延时n个us
  71. void delay_ms ( uint16_t nms ); //延时n个ms
  72. /**
  73. ****************************** Support C++ **********************************
  74. **/
  75. #ifdef __cplusplus
  76. }
  77. #endif
  78. /**
  79. *****************************************************************************
  80. **/
  81. #endif /* end delay.h */