DIY Auto-Correlator 1.0
Auto-Correlator Card implementation using Teensy 4.x microcontrollers.
errors.hpp
Go to the documentation of this file.
1
5#pragma once
6#include "pins.hpp"
7#include "./../types.hpp"
8#include "ledpanel.hpp"
9#include <Arduino.h>
10
11#define TEENSY_MAX_ALLOCATION 125000
12
13
14
16enum class Error_t
17{
18 Success = 0,
21 Precision,
24};
25
27class Errors{
28public:
31 void static Validate(const Error_t error)
32 {
33 if(error == Error_t::Success)
34 return;
35 else if(error == Error_t::Counter_Underflow || error == Error_t::Counter_Overflow)
36 { LEDPanel.error(ER_OVERFLOW_PIN); }
37 else if(error == Error_t::Precision)
38 { LEDPanel.error(ER_PRECISION_PIN); }
39 else if(error == Error_t::Input_Validation)
41 }
42
44 Error_t static Precison_Threshold(double error_val, double error_limit)
45 {
46 if(error_val <= error_limit)
47 { return Error_t::Success; }
48 else
49 { return Error_t::Precision; }
50 }
51
52
55 template <unsigned int Lin_channels, index_t Series_size, unsigned int Bin_Ratio>
57 {
58 bool input_ok = (Series_size * Lin_channels <= TEENSY_MAX_ALLOCATION);
59
60 input_ok = input_ok && (Bin_Ratio >= 1);
61
62 input_ok = input_ok && (Series_size % Bin_Ratio == 0); //Multiple
63
64 input_ok = input_ok && (Lin_channels > 0);
65
66 return static_cast<Error_t>
67 (
68 static_cast<unsigned int>(Error_t::Success) * input_ok +
69 !input_ok * static_cast<unsigned int>(Error_t::Input_Validation)
70 );
71 }
72
75 #ifndef NDEBUG
76
80 void static _assert_(bool expression, const char* __attribute__((unused)) message = "") //__attribute__((noreturn, flatten))
81 {
82 if(!expression)
83 {
84 LEDPanel.set_all(); //Set all LED Pins to High
85 abort(); //Call abort
86 }
87
88 }
89
90 #elif
92 void _assert_(bool expression)
93 {
94 return;
95 }
96
97 #endif
98};
99
100
101
Definition: errors.hpp:27
static Error_t Precison_Threshold(double error_val, double error_limit)
Receives error value and error threshold and returns an appropriate error state.
Definition: errors.hpp:44
static void _assert_(bool expression, const char *__attribute__((unused)) message="")
Custom assertion function.
Definition: errors.hpp:80
static Error_t Auto_MultiTau_Input_Validator()
Input Validator for MultiTau auto-correlator.
Definition: errors.hpp:56
static void Validate(const Error_t error)
Receives an error state and sets up the corresponding LED indicator.
Definition: errors.hpp:31
#define TEENSY_MAX_ALLOCATION
This file contain the Common Error Codes for Software-Hardware Interface. It defines the Error_t and ...
Definition: errors.hpp:11
Error_t
Enumarates the error codes thrown by the different modules.
Definition: errors.hpp:17
@ Counter_Underflow
Passed Value caused a counter underflow.
@ Success
No error.
@ Input_Validation
Input validation failed.
@ Counter_Overflow
Passed Value caused a counter overflow.
@ Precision
Error generated when difference due to finite resolution is greater than acceptable.
@ Generic_Error
Only here for development and debugging.
LEDSet< 5 > LEDPanel({LED_BUILTIN, LED_RED, LED_GREEN, LED_WHITE, LED_BLUE})
const int ER_PRECISION_PIN
Definition: pins.hpp:23
const int ER_INPUT_VALIDATION
Definition: pins.hpp:25
const int ER_OVERFLOW_PIN
Definition: pins.hpp:24