123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115 |
- #include "dwt.h"
- #include "bsp.h"
- #define DWT_CYCCNT *(volatile unsigned int *)0xE0001004
- #define DWT_CR *(volatile unsigned int *)0xE0001000
- #define DEM_CR *(volatile unsigned int *)0xE000EDFC
- #define DBGMCU_CR *(volatile unsigned int *)0xE0042004
- #define DEM_CR_TRCENA (1 << 24)
- #define DWT_CR_CYCCNTENA (1 << 0)
- void dwt_init(void)
- {
- DEM_CR |= (unsigned int)DEM_CR_TRCENA;
- DWT_CYCCNT = (unsigned int)0u;
- DWT_CR |= (unsigned int)DWT_CR_CYCCNTENA;
- }
- void us_delay(uint32_t time)
- {
- uint32_t count, tcnt;
- uint32_t tstart;
- tstart = DWT_CYCCNT;
- count = 0;
- tcnt = time * (SystemCoreClock / 1000000);
- while (count < tcnt)
- {
- count = DWT_CYCCNT - tstart;
- }
- }
- void ms_delay(uint32_t time)
- {
- us_delay(1000 * time);
- }
|