DIY Auto-Correlator 1.0
Auto-Correlator Card implementation using Teensy 4.x microcontrollers.
perf_counter.hpp
Go to the documentation of this file.
1#pragma once
2#include <imxrt.h>
3
4#ifdef CORR_SIMULATOR
5 #include "./../software/pseudoSerial.hpp"
6#else
7 #include <Arduino.h>
8#endif
9
13{
14public:
15
16 uint32_t Stack = 0;
17 uint32_t Count = 0;
18 uint32_t Cycles = 0;
19 uint32_t StartTime = 0;
20
24 void static init() __attribute__((always_inline))
25 {
26 ARM_DEMCR |= ARM_DEMCR_TRCENA; //Enable Trace
27 ARM_DWT_CTRL |= ARM_DWT_CTRL_CYCCNTENA; //Enable Cycle counting
28 }
29
31 void start() __attribute__((always_inline))
32 {
33 StartTime = ARM_DWT_CYCCNT;
34 }
35
37 void end() __attribute__((always_inline))
38 {
39 volatile uint32_t now = ARM_DWT_CYCCNT;
40 Cycles = now - StartTime;
41 Stack += Cycles;
42 Count++;
43 }
44
46 float inline mean()
47 {
48 return float(Stack)/float(Count);
49 }
50
52 uint32_t inline last_duration()
53 {
54 return Cycles;
55 }
56
57 void reset() __attribute__((always_inline))
58 {
59 Count = 0;
60 Stack = 0;
61 Cycles = 0;
62 }
63
64 void output() __attribute__((always_inline))
65 {
66 float_t mean_ = mean(); //Mean
67 Serial.write((char8cast_t*)&(mean_), sizeof(float_t));
68
69 //Serial.write((char8cast_t*)(last_duration()), sizeof(uint32_t)); //Last Cycles
70
71 }
72};
Performance Counter class for teensy 4.1 microcontrollers.
Definition: perf_counter.hpp:13
void output() __attribute__((always_inline))
Definition: perf_counter.hpp:64
uint32_t last_duration()
Returns the last recorded duration.
Definition: perf_counter.hpp:52
float mean()
Returns the mean number of cycles between start() and stop().
Definition: perf_counter.hpp:46
void start() __attribute__((always_inline))
Start Measurement.
Definition: perf_counter.hpp:31
uint32_t Cycles
Last recorded duration (difference in clock cycles recorded)
Definition: perf_counter.hpp:18
void reset() __attribute__((always_inline))
Definition: perf_counter.hpp:57
uint32_t Count
Count for mean calculation.
Definition: perf_counter.hpp:17
void end() __attribute__((always_inline))
End measurement.
Definition: perf_counter.hpp:37
uint32_t Stack
Stack for mean calculation.
Definition: perf_counter.hpp:16
uint32_t StartTime
Stored starting time of the measurement.
Definition: perf_counter.hpp:19
static void init() __attribute__((always_inline))
Set up the debug module for clock cycle counting.
Definition: perf_counter.hpp:24