-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMCU_status.h
172 lines (147 loc) · 8.19 KB
/
MCU_status.h
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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
#pragma once
#include <string.h>
#include <stdint.h>
#ifdef HT_DEBUG_EN
#include "Arduino.h"
#endif
enum class MCU_STATE
{
STARTUP = 0,
TRACTIVE_SYSTEM_NOT_ACTIVE = 1,
TRACTIVE_SYSTEM_ACTIVE = 2,
ENABLING_INVERTER = 3,
WAITING_READY_TO_DRIVE_SOUND = 4,
READY_TO_DRIVE = 5
};
enum class INVERTER_STARTUP_STATE
{
WAIT_SYSTEM_READY = 0,
WAIT_QUIT_DC_ON = 1,
WAIT_QUIT_INVERTER_ON = 2
};
#pragma pack(push,1)
// @Parseclass @Custom(parse_mcu_enums)
class MCU_status {
public:
MCU_status() = default;
MCU_status(const uint8_t buf[8]) { load(buf); }
inline void load(const uint8_t buf[]) { memcpy(this, buf, sizeof(*this)); }
inline void write(uint8_t buf[]) const { memcpy(buf, this, sizeof(*this)); }
/* Shutdown system monitoring */
inline uint8_t get_shutdown_inputs() const { return shutdown_states; }
inline bool get_imd_ok_high() const { return shutdown_states & 0x01; }
inline bool get_shutdown_b_above_threshold() const { return shutdown_states & 0x02; }
inline bool get_bms_ok_high() const { return shutdown_states & 0x04; }
inline bool get_shutdown_c_above_threshold() const { return shutdown_states & 0x08; }
inline bool get_bspd_ok_high() const { return shutdown_states & 0x10; }
inline bool get_shutdown_d_above_threshold() const { return shutdown_states & 0x20; }
inline bool get_software_ok_high() const { return shutdown_states & 0x40; }
inline bool get_shutdown_e_above_threshold() const { return shutdown_states & 0x80; }
inline void set_shutdown_inputs(const uint8_t inputs) { shutdown_states = inputs; }
inline void set_imd_ok_high(const bool high) { shutdown_states = (shutdown_states & 0xFE) | (high ); }
inline void set_shutdown_b_above_threshold(const bool above) { shutdown_states = (shutdown_states & 0xFD) | (above << 1); }
inline void set_bms_ok_high(const bool high) { shutdown_states = (shutdown_states & 0xFB) | (high << 2); }
inline void set_shutdown_c_above_threshold(const bool above) { shutdown_states = (shutdown_states & 0xF7) | (above << 3); }
inline void set_bspd_ok_high(const bool high) { shutdown_states = (shutdown_states & 0xEF) | (high << 4); }
inline void set_shutdown_d_above_threshold(const bool above) { shutdown_states = (shutdown_states & 0xDF) | (above << 5); }
inline void set_software_ok_high(const bool high) { shutdown_states = (shutdown_states & 0xBF) | (high << 6); }
inline void set_shutdown_e_above_threshold(const bool above) { shutdown_states = (shutdown_states & 0x7F) | (above << 7); }
/* Pedal system monitoring */
inline uint8_t get_pedal_states() const { return pedal_states; }
inline bool get_mech_brake_active() const { return pedal_states & 0x01; }
inline bool get_no_accel_implausability() const { return pedal_states & 0x04; }
inline bool get_no_brake_implausability() const { return pedal_states & 0x08; }
inline bool get_brake_pedal_active() const { return pedal_states & 0x10; }
inline bool get_bspd_current_high() const { return pedal_states & 0x20; }
inline bool get_bspd_brake_high() const { return pedal_states & 0x40; }
inline bool get_no_accel_brake_implausability() const { return pedal_states & 0x80; }
inline void set_pedal_states(const uint8_t states) { pedal_states = states; }
inline void set_mech_brake_active(const bool active) { pedal_states = (pedal_states & 0xFE) | (active); }
inline void set_no_accel_implausability(const bool implausable) { pedal_states = (pedal_states & 0xFB) | (implausable << 2); }
inline void set_no_brake_implausability(const bool implausable) { pedal_states = (pedal_states & 0xF7) | (implausable << 3); }
inline void set_brake_pedal_active(const bool pressed) { pedal_states = (pedal_states & 0xEF) | (pressed << 4); }
inline void set_bspd_current_high(const bool high) { pedal_states = (pedal_states & 0xDF) | (high << 5); }
inline void set_bspd_brake_high(const bool high) { pedal_states = (pedal_states & 0xBF) | (high << 6); }
inline void set_no_accel_brake_implausability(const bool implausable) { pedal_states = (pedal_states & 0x7F) | (implausable << 7); }
/* ECU state */
inline uint16_t get_ecu_states() const { return (ecu_states); }
inline MCU_STATE get_state() const { return static_cast<MCU_STATE>((ecu_states & 0x07)); }
inline bool get_inverters_error() const { return (ecu_states & 0x008); }
inline bool get_energy_meter_present() const { return (ecu_states & 0x010); }
inline bool get_activate_buzzer() const { return (ecu_states & 0x020); }
inline bool get_software_is_ok() const { return (ecu_states & 0x040); }
inline bool get_launch_ctrl_active() const { return (ecu_states & 0x080); }
inline uint8_t get_pack_charge_critical() const {return (ecu_states & 0x300) >> 8; }
inline void set_ecu_states(const uint16_t states) { ecu_states = states; }
inline void set_state(const MCU_STATE state) { ecu_states = (ecu_states & 0xFFF8) | (static_cast<uint8_t>(state)); }
inline void set_inverters_error(const bool error) { ecu_states = (ecu_states & 0xFFF7) | (error << 3); }
inline void set_energy_meter_present(const bool present) { ecu_states = (ecu_states & 0xFFEF) | (present << 4); }
inline void set_activate_buzzer(const bool activate) { ecu_states = (ecu_states & 0xFFDF) | (activate << 5); }
inline void set_software_is_ok(const bool is_ok) { ecu_states = (ecu_states & 0xFFBF) | (is_ok << 6); }
inline void set_launch_ctrl_active(const bool active) { ecu_states = (ecu_states & 0xFF7F) | (active << 7); }
inline void set_pack_charge_critical(const uint8_t pack_charge_crit) {ecu_states = (ecu_states & 0xFFFF) | (pack_charge_crit << 8);}
inline void toggle_launch_ctrl_active() { ecu_states ^= 0x80; }
/* distance travelled */
inline uint16_t get_distance_travelled() const { return distance_travelled; }
inline void set_distance_travelled(const uint16_t distance) { distance_travelled = distance; }
inline uint8_t get_max_torque() const { return max_torque; }
inline void set_max_torque(const uint8_t max) { max_torque = max; }
inline uint8_t get_torque_mode() const { return torque_mode; }
inline void set_torque_mode(const uint8_t mode) { torque_mode = mode; }
private:
// no free bits
/* @Parse @Flaglist(
imd_ok_high,
shutdown_b_above_threshold,
bms_ok_high,
shutdown_c_above_threshold,
bspd_ok_high,
shutdown_d_above_threshold,
software_ok_high,
shutdown_e_above_threshold
) */
uint8_t shutdown_states;
/*
* torque_mode (2 bits)
* accel_implausability
* brake_implausability
* brake_pressed
* Current high
* brake high
* accel/brake implausability
* mech brake active
*/
/* @Parse @Flaglist(
no_accel_implausability,
no_brake_implausability,
brake_pedal_active,
bspd_current_high,
bspd_brake_high,
no_accel_brake_implausability
) */
uint8_t pedal_states;
/**
* state (3 bits)
* inverter powered
* energy_meter
* activate_buzzer
* software_is_ok
* launch_control_active
* pack charge critical
*/
/* @Parse @Flaglist(
inverters_error,
energy_meter_present,
activate_buzzer,
software_is_ok,
launch_ctrl_active
)*/
uint16_t ecu_states;
// @Parse @Unit(Nm)
uint8_t max_torque;
// @Parse
uint8_t torque_mode;
// @Parse @Unit(m) @Scale(100)
uint16_t distance_travelled;
};
#pragma pack(pop)