APIs, concepts, guides, and more
SyncInterrupt.h
1#pragma once
2#if !defined(__SYNC_INTERRUPT_H)
3#define __SYNC_INTERRUPT_H
4
5#include <cstdint>
6#include <atomic>
7
8// Constants
9constexpr int32_t Hz_4000 = 4000;
10constexpr int32_t Hz_1000 = 1000;
11constexpr int32_t sync_1 = 1;
12constexpr int32_t sync_150 = 150;
13constexpr int32_t sync_250 = 250;
14constexpr int32_t threshold_250 = 250;
15constexpr int32_t threshold_65 = 65;
16
17
18// Time conversions
19constexpr double MILLISECONDS_PER_SECOND = 1.0e3;
20constexpr double MICROSECONDS_PER_SECOND = 1.0e6;
21constexpr double MICROSECONDS_PER_MILLISECOND = 1.0e3;
22
23
24
25template<typename DataType>
26class StatisticsBufferTemplate
27{
28public:
29 DataType min, max;
30 StatisticsBufferTemplate() :
31 min(std::numeric_limits<DataType>::max()),
32 max(std::numeric_limits<DataType>::lowest())
33 { }
34 virtual void Init() = 0;
35 virtual void Reset() = 0;
36 virtual void AddData(const DataType& datum)
37 {
38 if (max < datum)
39 {
40 max = datum;
41 }
42 if (datum < min)
43 {
44 min = datum;
45 }
46 }
47};
48using StatisticsBuffer = StatisticsBufferTemplate<double>;
49
50
51// Forward Declarations //
52// Shared Variables
53extern uint32_t cpuFrequency;
54extern int32_t currentPerformanceCounter;
55extern int32_t previousPerformanceCounter;
56extern int32_t deltaPerformanceCounter;
57extern int32_t syncInterruptIterations;
58extern double deltaMicroseconds;
59extern int32_t syncInterruptSampleCounter;
60extern int32_t lastSyncInterruptSampleCounter;
61
62extern int32_t returnCode;
63extern std::atomic_bool readyToCleanup;
64
65// Configurable Variables
66extern int32_t sampleRate; // hz
67extern int32_t syncPeriod; // interrupt every MotionController SYNC_PERIOD samples
68extern int32_t printFrequency;
69extern bool print;
70extern int32_t timeout_mS;
71extern int32_t syncPeriodThreshold_uS;
72
73// Statistics variable + Functions
74extern StatisticsBuffer& buffered_stats; // microseconds
75void printTimingHeaderString();
76void PrintTimingInfo();
77void StatisticsThread();
78
79
80
81
82
83#endif