训练营PLSR题目
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

91 line
3.1 KiB

  1. #include "includes.h"
  2. #define BSP_REG_DEM_CR (*(CPU_REG32 *)0xE000EDFC) //DEMCR寄存器
  3. #define BSP_REG_DWT_CR (*(CPU_REG32 *)0xE0001000) //DWT控制寄存器
  4. #define BSP_REG_DWT_CYCCNT (*(CPU_REG32 *)0xE0001004) //DWT时钟计数寄存器
  5. #define BSP_REG_DBGMCU_CR (*(CPU_REG32 *)0xE0042004)
  6. //DEMCR寄存器的第24位,如果要使用DWT ETM ITM和TPIU的话DEMCR寄存器的第24位置1
  7. #define BSP_BIT_DEM_CR_TRCENA DEF_BIT_24
  8. //DWTCR寄存器的第0位,当为1的时候使能CYCCNT计数器,使用CYCCNT之前应当先初始化
  9. #define BSP_BIT_DWT_CR_CYCCNTENA DEF_BIT_00
  10. /*
  11. *********************************************************************************************************
  12. * BSP_CPU_ClkFreq()
  13. * Description : Read CPU registers to determine the CPU clock frequency of the chip.
  14. * Argument(s) : none.
  15. * Return(s) : The CPU clock frequency, in Hz.
  16. * Caller(s) : Application.
  17. * Note(s) : none.
  18. *********************************************************************************************************
  19. */
  20. CPU_INT32U BSP_CPU_ClkFreq (void)
  21. {
  22. return HAL_RCC_GetHCLKFreq();//返回HCLK时钟频率
  23. }
  24. /*
  25. *********************************************************************************************************
  26. * BSP_Tick_Init()
  27. * Description : BSP_Tick_Init.
  28. * Argument(s) : none.
  29. * Return(s) : none.
  30. * Note(s) : none.
  31. *********************************************************************************************************
  32. */
  33. void BSP_Tick_Init(void)
  34. {
  35. CPU_INT32U cpu_clk_freq;
  36. CPU_INT32U cnts;
  37. cpu_clk_freq = BSP_CPU_ClkFreq();
  38. #if(OS_VERSION>=3000u)
  39. cnts = cpu_clk_freq/(CPU_INT32U)OSCfg_TickRate_Hz;
  40. #else
  41. cnts = cpu_clk_freq/(CPU_INT32U)OS_TICKS_PER_SEC;
  42. #endif
  43. OS_CPU_SysTickInit(cnts);
  44. }
  45. void BSP_Init(void)
  46. {
  47. BSP_Tick_Init();//此函数会初始化OS系统时钟,如果移植了正点原子的delay文件,则与主函数中的delay_init(168)只需要调用一个即可
  48. }
  49. #if (CPU_CFG_TS_TMR_EN == DEF_ENABLED)
  50. void CPU_TS_TmrInit (void)
  51. {
  52. CPU_INT32U cpu_clk_freq_hz;
  53. BSP_REG_DEM_CR |= (CPU_INT32U)BSP_BIT_DEM_CR_TRCENA; //使用DWT /* Enable Cortex-M4's DWT CYCCNT reg.*/
  54. BSP_REG_DWT_CYCCNT = (CPU_INT32U)0u; //初始化CYCCNT寄存器
  55. BSP_REG_DWT_CR |= (CPU_INT32U)BSP_BIT_DWT_CR_CYCCNTENA; //开启CYCCNT
  56. cpu_clk_freq_hz = BSP_CPU_ClkFreq();
  57. CPU_TS_TmrFreqSet(cpu_clk_freq_hz);
  58. }
  59. #endif
  60. #if (CPU_CFG_TS_TMR_EN == DEF_ENABLED)
  61. CPU_TS_TMR CPU_TS_TmrRd (void)
  62. {
  63. return ((CPU_TS_TMR)BSP_REG_DWT_CYCCNT);
  64. }
  65. #endif
  66. #if (CPU_CFG_TS_32_EN == DEF_ENABLED)
  67. CPU_INT64U CPU_TS32_to_uSec (CPU_TS32 ts_cnts)
  68. {
  69. CPU_INT64U ts_us;
  70. CPU_INT64U fclk_freq;
  71. fclk_freq = BSP_CPU_ClkFreq();
  72. ts_us = ts_cnts / (fclk_freq / DEF_TIME_NBR_uS_PER_SEC);
  73. return (ts_us);
  74. }
  75. #endif
  76. #if (CPU_CFG_TS_64_EN == DEF_ENABLED)
  77. CPU_INT64U CPU_TS64_to_uSec (CPU_TS64 ts_cnts)
  78. {
  79. CPU_INT64U ts_us;
  80. CPU_INT64U fclk_freq;
  81. fclk_freq = BSP_CPU_ClkFreq();
  82. ts_us = ts_cnts / (fclk_freq / DEF_TIME_NBR_uS_PER_SEC);
  83. return (ts_us);
  84. }
  85. #endif