blob: 754f4d698109c69fdb288ca095ebc4874f8d17dc (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
|
#ifndef COUNTER_H
#define COUNTER_H
extern "C" {
#include "osapi.h"
#include "user_interface.h"
}
#include "c_types.h"
class Counter {
private:
Counter(const Counter ©);
uint32_t start_cycles;
public:
Counter() : start_cycles(0) {}
uint32_t overflowed;
inline void start() {
asm volatile ("esync; rsr %0,ccount":"=a" (start_cycles));
}
inline uint32_t stop() {
uint32_t stop_cycles;
asm volatile ("esync; rsr %0,ccount":"=a" (stop_cycles));
if (stop_cycles > start_cycles) {
return stop_cycles - start_cycles;
} else {
return 0;
}
}
};
extern Counter counter;
#endif
|