重构BSP架构
This commit is contained in:
@@ -0,0 +1,64 @@
|
||||
#include "Bsp.h"
|
||||
|
||||
#define DEM_CR *(volatile u32 *)0xE000EDFC
|
||||
#define DWT_CR *(volatile u32 *)0xE0001000
|
||||
#define DWT_CYCCNT *(volatile u32 *)0xE0001004
|
||||
|
||||
#define DEM_CR_TRCENA (1 << 24)
|
||||
#define DWT_CR_CYCCNTENA (1 << 0)
|
||||
|
||||
/**
|
||||
* @brief 初始化延时函数
|
||||
* @param void
|
||||
* @retval void
|
||||
* @note void
|
||||
* @example void
|
||||
*/
|
||||
void SystemDelayConfig(void)
|
||||
{
|
||||
DEM_CR |= DEM_CR_TRCENA;
|
||||
DWT_CR |= DWT_CR_CYCCNTENA;
|
||||
DWT_CYCCNT = 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief 读取DWT计数器的值
|
||||
* @param void
|
||||
* @retval void
|
||||
* @note void
|
||||
* @example void
|
||||
*/
|
||||
uint32_t SystemGetDwtCnt(void)
|
||||
{
|
||||
return((uint32_t)DWT_CYCCNT);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief 微秒级延时函数
|
||||
* @param void
|
||||
* @retval void
|
||||
* @note void
|
||||
* @example void
|
||||
*/
|
||||
void SystemDelayUs(uint32_t Us)
|
||||
{
|
||||
uint32_t Start = 0,End = 0,Ts = 0;
|
||||
Start = SystemGetDwtCnt();
|
||||
|
||||
Ts = Us * (SystemCoreClock / 1000000U);
|
||||
|
||||
End = Start + Ts;
|
||||
|
||||
while(SystemGetDwtCnt() < End){;}
|
||||
}
|
||||
/**
|
||||
* @brief 毫秒级延时函数
|
||||
* @param void
|
||||
* @retval void
|
||||
* @note void
|
||||
* @example void
|
||||
*/
|
||||
void SystemDelayMs(uint32_t Ms)
|
||||
{
|
||||
SystemDelayUs(Ms * 1000);
|
||||
}
|
||||
Reference in New Issue
Block a user