APM:Libraries
stopwatch.h
Go to the documentation of this file.
1 #ifndef _STOPWATCH_H
2 #define _STOPWATCH_H
3 
4 #ifdef __cplusplus
5  extern "C" {
6 #endif
7 
8 extern uint32_t us_ticks;
9 
10 
11 #define DEMCR_TRCENA 0x01000000
12 
13 /* Core Debug registers */
14 #define DEMCR (*((volatile uint32_t *)0xE000EDFC))
15 
16 #define DWT_CTRL (*(volatile uint32_t *)0xe0001000)
17 #define CYCCNTENA (1<<0)
18 #define DWT_CYCCNT ((volatile uint32_t *)0xE0001004)
19 #define CPU_CYCLES *DWT_CYCCNT
20 
21 void stopwatch_init(void);
22 void stopwatch_delay_us(uint32_t us);
23 
24 static inline void stopwatch_reset(void)
25 {
26  /* enable DWT access */
27  DEMCR |= DEMCR_TRCENA;
28  *DWT_CYCCNT = 0;
29  /* enable the CPU cycle counter */
31 }
32 
33 static inline uint32_t stopwatch_getticks()
34 {
35  return CPU_CYCLES;
36 }
37 
38 
39 #ifdef __cplusplus
40  }
41 #endif
42 #endif
43 /*----------------------------------------------------------------------------
44  * end of file
45  *---------------------------------------------------------------------------*/
static uint32_t stopwatch_getticks()
Definition: stopwatch.h:33
void stopwatch_delay_us(uint32_t us)
Definition: stopwatch.c:25
void stopwatch_init(void)
Definition: stopwatch.c:12
#define DEMCR
Definition: stopwatch.h:14
#define CYCCNTENA
Definition: stopwatch.h:17
#define DWT_CTRL
Definition: stopwatch.h:16
#define DWT_CYCCNT
Definition: stopwatch.h:18
#define CPU_CYCLES
Definition: stopwatch.h:19
uint32_t us_ticks
Definition: stopwatch.c:10
#define DEMCR_TRCENA
Definition: stopwatch.h:11
static void stopwatch_reset(void)
Definition: stopwatch.h:24