psu.h
1 /*
2  * EEZ PSU Firmware
3  * Copyright (C) 2015-present, Envox d.o.o.
4  *
5  * This program is free software: you can redistribute it and/or modify
6  * it under the terms of the GNU General Public License as published by
7  * the Free Software Foundation, either version 3 of the License, or
8  * (at your option) any later version.
9 
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  * GNU General Public License for more details.
14 
15  * You should have received a copy of the GNU General Public License
16  * along with this program. If not, see <http://www.gnu.org/licenses/>.
17  */
18 
19 #pragma once
20 
21 #if !defined(EEZ_PSU_ARDUINO) && !defined(EEZ_PSU_SIMULATOR)
22 #define EEZ_PSU_ARDUINO
23 #endif
24 
25 #ifdef EEZ_PSU_SIMULATOR
26 #include "simulator_psu.h"
27 #endif
28 
29 #include "Arduino.h"
30 #include "SPI.h"
31 
32 #include "eez_psu_rev.h"
33 
34 #ifdef EEZ_PSU_ARDUINO
35 #include "arduino_psu.h"
36 #endif
37 
38 #include "conf.h"
39 
40 #ifdef EEZ_PSU_SIMULATOR
41 #include "simulator_conf.h"
42 #endif
43 
44 #include "eez_psu.h"
45 
46 #include <scpi-parser.h>
47 
48 #include "ontime.h"
49 
51 namespace eez {
53 namespace psu {
54 
55 enum TestResult {
56  TEST_FAILED = 0,
57  TEST_OK = 1,
58  TEST_SKIPPED = 2,
59  TEST_WARNING = 3
60 };
61 
62 void boot();
63 
64 extern bool g_isBooted;
65 
66 bool powerUp();
67 void powerDown();
68 bool isPowerUp();
69 bool changePowerState(bool up);
70 void powerDownBySensor();
71 
72 bool reset();
73 
74 bool test();
75 
76 void onProtectionTripped();
77 
78 void tick();
79 void criticalTick();
80 
81 void setEsrBits(int bit_mask);
82 void setQuesBits(int bit_mask, bool on);
83 
84 void generateError(int16_t error);
85 
86 const char *getModelName();
87 const char *getCpuModel();
88 const char *getCpuType();
89 const char *getCpuEthernetType();
90 
91 void enterTimeCriticalMode();
92 bool isTimeCriticalMode();
93 void leaveTimeCriticalMode();
94 
95 enum MaxCurrentLimitCause {
96  MAX_CURRENT_LIMIT_CAUSE_NONE,
97  MAX_CURRENT_LIMIT_CAUSE_FAN,
98  MAX_CURRENT_LIMIT_CAUSE_TEMPERATURE
99 };
100 bool isMaxCurrentLimited();
101 MaxCurrentLimitCause getMaxCurrentLimitCause();
102 void limitMaxCurrent(MaxCurrentLimitCause cause);
103 void unlimitMaxCurrent();
104 
105 extern ontime::Counter g_powerOnTimeCounter;
106 extern volatile bool g_insideInterruptHandler;
107 
108 void SPI_usingInterrupt(uint8_t interruptNumber);
109 void SPI_beginTransaction(SPISettings &settings);
110 void SPI_endTransaction();
111 
112 enum RLState {
113  RL_STATE_LOCAL = 0,
114  RL_STATE_REMOTE = 1,
115  RL_STATE_RW_LOCK = 2
116 };
117 
118 extern RLState g_rlState;
119 
120 bool isFrontPanelLocked();
121 
122 }
123 } // namespace eez::psu
124 
125 #include "debug.h"
126 #include "util.h"
127 #include "channel.h"
128 
129 #define CHANNEL_VALUE_PRECISION powf(10.0f, FLOAT_TO_STR_NUM_DECIMAL_DIGITS)
130 
131 void PSU_boot();
132 void PSU_tick();
Bare minimum implementation of the Arduino SPISettings class.
Definition: SPI.h:42
Namespace for the everything from the EEZ.
Definition: actions.cpp:41