forked from gary/BCU
2
0
Fork 0
BCU/library/core/drv_dwt.c

25 lines
570 B
C
Raw Normal View History

2024-11-26 15:52:49 +08:00
#include "drv_dwt.h"
#include "drv_clk.h"
#define DWT_CR *(uint32_t *)0xE0001000
#define DWT_CYCCNT *(uint32_t *)0xE0001004
#define DEM_CR *(uint32_t *)0xE000EDFC
#define DEM_CR_TRCENA (1 << 24)
#define DWT_CR_CYCCNTENA (1 << 0)
void drv_dwt_start(void)
{
//使能DWT外设
DEM_CR |= (uint32_t)DEM_CR_TRCENA;
//DWT CYCCNT寄存器计数清0
DWT_CYCCNT = (uint32_t)0u;
//使能Cortex-M3 DWT CYCCNT寄存器
DWT_CR |= (uint32_t)DWT_CR_CYCCNTENA;
}
uint32_t drv_dwt_end(void)
{
return (uint64_t)DWT_CYCCNT * 1000000 / CLOCK_SYS_FREQ;
}