MCU
Loading...
Searching...
No Matches
Public Member Functions | Private Member Functions | Private Attributes | List of all members
MCUInterface Class Reference

#include <MCUInterface.h>

Collaboration diagram for MCUInterface:
Collaboration graph

Public Member Functions

 MCUInterface (CANBufferType *msg_output_queue, const MainECUHardwareReadPins &pins)
 
 MCUInterface (CANBufferType *msg_output_queue)
 
void init ()
 
void read_mcu_status ()
 
void set_brake_light (bool brake_pedal_is_active)
 
void enable_inverters_pin ()
 
void disable_inverters_pin ()
 
bool bms_ok_is_high ()
 
bool imd_ok_is_high ()
 
bool brb_ok_is_high ()
 
bool get_bots_ok ()
 
void update_mcu_status_CAN_fsm (int fsm_state)
 
void update_mcu_status_CAN_drivetrain (bool has_error)
 
void update_mcu_status_CAN_safety (bool is_ok)
 
void update_mcu_status_CAN_TCMux (int drive_mode, int torque_mode, float max_torque)
 
void update_mcu_status_CAN_buzzer (bool is_on)
 
void update_mcu_status_CAN_pedals (const PedalsSystemData_s &pedals)
 
void update_mcu_status_CAN_ams (bool is_critical)
 
void update_mcu_status_CAN_dashboard (bool is_active)
 
void update_brake_pressure_CAN ()
 
void enqueue_CAN_mcu_status ()
 
void tick (int fsm_state, bool inv_has_error, bool software_is_ok, const TorqueControllerMuxStatus &tc_mux_status, bool buzzer_is_on, const PedalsSystemData_s &pedals_data, bool pack_charge_is_critical, bool button_is_pressed)
 
 MCUInterface ()
 
void enable_inverters_pin ()
 
void disable_inverters_pin ()
 

Private Member Functions

void measure_shutdown_circuit_input ()
 
void measure_shutdown_circuit_voltage ()
 
void update_mcu_status_CAN ()
 

Private Attributes

CANBufferTypemsg_queue_
 
MainECUHardwareReadPins pins_
 
MCU_STATUS_t mcu_status_
 
bool bms_ok_high
 
bool imd_ok_high
 
bool bspd_ok_high
 
bool software_ok_high
 
bool brb_ok_high
 
bool shutdown_b_above_threshold
 
bool shutdown_c_above_threshold
 
bool shutdown_d_above_threshold
 
bool shutdown_e_above_threshold
 
bool shutdown_g_above_threshold
 

Detailed Description

Definition at line 47 of file MCUInterface.h.

Constructor & Destructor Documentation

◆ MCUInterface() [1/3]

MCUInterface::MCUInterface ( CANBufferType msg_output_queue,
const MainECUHardwareReadPins pins 
)
inline

Definition at line 81 of file MCUInterface.h.

81 :
82 // Member initialization list
83 msg_queue_(msg_output_queue),
84 pins_(pins){};
MainECUHardwareReadPins pins_
Definition: MCUInterface.h:52
CANBufferType * msg_queue_
Definition: MCUInterface.h:50

◆ MCUInterface() [2/3]

MCUInterface::MCUInterface ( CANBufferType msg_output_queue)
inline

Definition at line 87 of file MCUInterface.h.

87 :
88 MCUInterface(msg_output_queue, DEFAULT_PINS)
89 {};

◆ MCUInterface() [3/3]

MCUInterface::MCUInterface ( )
inline

Definition at line 11 of file MCUInterface.h.

12 {
13 };

Member Function Documentation

◆ bms_ok_is_high()

bool MCUInterface::bms_ok_is_high ( )

Definition at line 73 of file MCUInterface.cpp.

74{
75 return bms_ok_high;
76}
bool bms_ok_high
Definition: MCUInterface.h:58

◆ brb_ok_is_high()

bool MCUInterface::brb_ok_is_high ( )

Definition at line 84 of file MCUInterface.cpp.

85{
86 return brb_ok_high;
87}
bool brb_ok_high
Definition: MCUInterface.h:62

◆ disable_inverters_pin() [1/2]

void MCUInterface::disable_inverters_pin ( )

Definition at line 66 of file MCUInterface.cpp.

67{
68 digitalWrite(pins_.pin_inv_en, LOW);
69 digitalWrite(pins_.pin_inv_24V_en, LOW);
70}

◆ disable_inverters_pin() [2/2]

void MCUInterface::disable_inverters_pin ( )
inline

Definition at line 16 of file MCUInterface.h.

16{};

◆ enable_inverters_pin() [1/2]

void MCUInterface::enable_inverters_pin ( )

Definition at line 61 of file MCUInterface.cpp.

62{
63 digitalWrite(pins_.pin_inv_en, HIGH);
64 digitalWrite(pins_.pin_inv_24V_en, HIGH);
65}

◆ enable_inverters_pin() [2/2]

void MCUInterface::enable_inverters_pin ( )
inline

Definition at line 15 of file MCUInterface.h.

15{};

◆ enqueue_CAN_mcu_status()

void MCUInterface::enqueue_CAN_mcu_status ( )

Definition at line 96 of file MCUInterface.cpp.

97{
98 CAN_message_t msg;
99
100 msg.id = Pack_MCU_STATUS_hytech(&mcu_status_, msg.buf, &msg.len, (uint8_t*) &msg.flags.extended);
101
102 uint8_t buf[sizeof(CAN_message_t)] = {};
103 memmove(buf, &msg, sizeof(CAN_message_t));
104 msg_queue_->push_back(buf, sizeof(CAN_message_t));
105}
MCU_STATUS_t mcu_status_
Definition: MCUInterface.h:55
CAN_message_t msg

◆ get_bots_ok()

bool MCUInterface::get_bots_ok ( )

Definition at line 89 of file MCUInterface.cpp.

90{
92}
bool shutdown_b_above_threshold
Definition: MCUInterface.h:64

◆ imd_ok_is_high()

bool MCUInterface::imd_ok_is_high ( )

Definition at line 78 of file MCUInterface.cpp.

79{
80 return imd_ok_high;
81}
bool imd_ok_high
Definition: MCUInterface.h:59

◆ init()

void MCUInterface::init ( )

Definition at line 6 of file MCUInterface.cpp.

7{
8 // Set pin mode
9 pinMode(pins_.pin_inv_en, OUTPUT);
10 pinMode(pins_.pin_inv_24V_en, OUTPUT);
11 pinMode(pins_.pin_brake_light_ctrl, OUTPUT);
12
13 // Set initial shutdown circuit readings
14 bms_ok_high = false;
15 imd_ok_high = false;
16 brb_ok_high = false;
17
18 // Enable inverters (?)
19 // Should be called from drivetrain
20}

◆ measure_shutdown_circuit_input()

void MCUInterface::measure_shutdown_circuit_input ( )
private

Definition at line 31 of file MCUInterface.cpp.

32{
33 // TODO: change these back to pins from constructor
36
37 bspd_ok_high = digitalRead(pins_.pin_bspd_ok_read);
39 brb_ok_high = digitalRead(pins_.pin_brb_ok_read);
40
41}
bool bspd_ok_high
Definition: MCUInterface.h:60
bool software_ok_high
Definition: MCUInterface.h:61
const int DEFAULT_BMS_SENSE_PIN
Definition: MCUInterface.h:13
const int DEFAULT_IMD_SENSE_PIN
Definition: MCUInterface.h:15

◆ measure_shutdown_circuit_voltage()

void MCUInterface::measure_shutdown_circuit_voltage ( )
private

◆ read_mcu_status()

void MCUInterface::read_mcu_status ( )

Definition at line 23 of file MCUInterface.cpp.

24{
25
28}
void measure_shutdown_circuit_input()
void measure_shutdown_circuit_voltage()

◆ set_brake_light()

void MCUInterface::set_brake_light ( bool  brake_pedal_is_active)

Definition at line 55 of file MCUInterface.cpp.

56{
57
58 digitalWrite(pins_.pin_brake_light_ctrl, brake_pedal_is_active);
59}

◆ tick()

void MCUInterface::tick ( int  fsm_state,
bool  inv_has_error,
bool  software_is_ok,
const TorqueControllerMuxStatus tc_mux_status,
bool  buzzer_is_on,
const PedalsSystemData_s pedals_data,
bool  pack_charge_is_critical,
bool  button_is_pressed 
)

Definition at line 199 of file MCUInterface.cpp.

208{
209 // State machine
210 update_mcu_status_CAN_fsm(fsm_state);
211 // Systems
213 update_mcu_status_CAN_safety(software_is_ok);
214
215 auto drive_mode = static_cast<int>(tc_mux_status.active_controller_mode);
216 auto torque_mode = static_cast<int>(tc_mux_status.active_torque_limit_enum);
217 auto max_torque = tc_mux_status.active_torque_limit_value;
218
219 update_mcu_status_CAN_TCMux(drive_mode, torque_mode, max_torque);
220 update_mcu_status_CAN_buzzer(buzzer_is_on);
221 update_mcu_status_CAN_pedals(pedals_data);
222 // External Interfaces
223 update_mcu_status_CAN_ams(pack_charge_is_critical);
224 update_mcu_status_CAN_dashboard(button_is_pressed);
226 // Internal values
228 // Push into buffer
230 set_brake_light(pedals_data.brakePressed);
231}
void update_mcu_status_CAN_pedals(const PedalsSystemData_s &pedals)
void update_mcu_status_CAN_drivetrain(bool has_error)
void update_mcu_status_CAN_fsm(int fsm_state)
void enqueue_CAN_mcu_status()
void update_mcu_status_CAN_buzzer(bool is_on)
void update_mcu_status_CAN_ams(bool is_critical)
void update_brake_pressure_CAN()
void set_brake_light(bool brake_pedal_is_active)
void update_mcu_status_CAN_TCMux(int drive_mode, int torque_mode, float max_torque)
void update_mcu_status_CAN_safety(bool is_ok)
void update_mcu_status_CAN()
void update_mcu_status_CAN_dashboard(bool is_active)
TorqueLimit_e active_torque_limit_enum
ControllerMode_e active_controller_mode

◆ update_brake_pressure_CAN()

void MCUInterface::update_brake_pressure_CAN ( )

Definition at line 185 of file MCUInterface.cpp.

186{
187 BRAKE_PRESSURE_SENSOR_t brake_sensor_msg;
188 brake_sensor_msg.brake_sensor_analog_read = analogRead(pins_.pin_brake_pressure_sensor_read);
189
190 CAN_message_t msg;
191
192 msg.id = Pack_BRAKE_PRESSURE_SENSOR_hytech(&brake_sensor_msg, msg.buf, &msg.len, (uint8_t*) &msg.flags.extended);
193
194 uint8_t buf[sizeof(CAN_message_t)] = {};
195 memmove(buf, &msg, sizeof(CAN_message_t));
196 msg_queue_->push_back(buf, sizeof(CAN_message_t));
197}

◆ update_mcu_status_CAN()

void MCUInterface::update_mcu_status_CAN ( )
private

Definition at line 109 of file MCUInterface.cpp.

110{
111 // Shutdown circuit input
112 mcu_status_.bms_ok_high = bms_ok_high;
113 mcu_status_.imd_ok_high = imd_ok_high;
114 mcu_status_.bspd_ok_high = bspd_ok_high;
115 mcu_status_.software_ok_high = software_ok_high;
116 // Shutdown circuit voltage
117 mcu_status_.shutdown_b_above_threshold = shutdown_b_above_threshold;
118 mcu_status_.shutdown_c_above_threshold = shutdown_c_above_threshold;
119 mcu_status_.shutdown_d_above_threshold = shutdown_d_above_threshold;
120 mcu_status_.shutdown_e_above_threshold = shutdown_e_above_threshold;
121
122}

◆ update_mcu_status_CAN_ams()

void MCUInterface::update_mcu_status_CAN_ams ( bool  is_critical)

Definition at line 145 of file MCUInterface.cpp.

146{
147 // AMSInterface returns struct in main loop
148 // ams_interface.pack_charge_is_critical()
149 mcu_status_.pack_charge_critical = is_critical;
150}

◆ update_mcu_status_CAN_buzzer()

void MCUInterface::update_mcu_status_CAN_buzzer ( bool  is_on)

Definition at line 168 of file MCUInterface.cpp.

169{
170 // Buzzer returns struct in main loop
171 // buzzer.buzzer_is_on()
172 mcu_status_.drive_buzzer = is_on;
173}

◆ update_mcu_status_CAN_dashboard()

void MCUInterface::update_mcu_status_CAN_dashboard ( bool  is_active)

Definition at line 161 of file MCUInterface.cpp.

162{
163 // DashboardInterface (?) returns struct in main loop
164 // dash.lauchControlButtonPressed()
165 mcu_status_.launch_control_active = is_active;
166}

◆ update_mcu_status_CAN_drivetrain()

void MCUInterface::update_mcu_status_CAN_drivetrain ( bool  has_error)

Definition at line 131 of file MCUInterface.cpp.

132{
133 // Drivetrain returns struct in main loop
134 // drivetrain.drive_error_occured()
135 mcu_status_.inverter_error = has_error; // could also be called has_error
136}

◆ update_mcu_status_CAN_fsm()

void MCUInterface::update_mcu_status_CAN_fsm ( int  fsm_state)

Definition at line 126 of file MCUInterface.cpp.

127{
128 mcu_status_.ecu_state = fsm_state_enum_val;
129}

◆ update_mcu_status_CAN_pedals()

void MCUInterface::update_mcu_status_CAN_pedals ( const PedalsSystemData_s pedals)

Definition at line 176 of file MCUInterface.cpp.

177{
178 // PedalSystem returns struct in main loop
179 mcu_status_.brake_pedal_active = pedals.brakePressed;
180 // mcu_status_.set_mech_brake_active();
181 mcu_status_.no_accel_implausibility = !pedals.accelImplausible;
182 mcu_status_.no_brake_implausibility = !pedals.brakeImplausible;
183 mcu_status_.no_accel_or_brake_implausibility = !(pedals.brakeAndAccelPressedImplausibility);
184}
bool brakeAndAccelPressedImplausibility

◆ update_mcu_status_CAN_safety()

void MCUInterface::update_mcu_status_CAN_safety ( bool  is_ok)

Definition at line 138 of file MCUInterface.cpp.

139{
140 // SafetySystem returns struct in main loop
141 // safety_system.get_software_is_ok()
142 mcu_status_.software_ok = is_ok;
143}

◆ update_mcu_status_CAN_TCMux()

void MCUInterface::update_mcu_status_CAN_TCMux ( int  drive_mode,
int  torque_mode,
float  max_torque 
)

Definition at line 153 of file MCUInterface.cpp.

154{
155 // TorqueControllerMux returns struct in main loop
156 mcu_status_.drive_mode = drive_mode;
157 mcu_status_.torque_mode = torque_mode;
158 mcu_status_.max_torque = static_cast<uint8_t>(max_torque);
159}

Member Data Documentation

◆ bms_ok_high

bool MCUInterface::bms_ok_high
private

Definition at line 58 of file MCUInterface.h.

◆ brb_ok_high

bool MCUInterface::brb_ok_high
private

Definition at line 62 of file MCUInterface.h.

◆ bspd_ok_high

bool MCUInterface::bspd_ok_high
private

Definition at line 60 of file MCUInterface.h.

◆ imd_ok_high

bool MCUInterface::imd_ok_high
private

Definition at line 59 of file MCUInterface.h.

◆ mcu_status_

MCU_STATUS_t MCUInterface::mcu_status_
private

Definition at line 55 of file MCUInterface.h.

◆ msg_queue_

CANBufferType* MCUInterface::msg_queue_
private

Definition at line 50 of file MCUInterface.h.

◆ pins_

MainECUHardwareReadPins MCUInterface::pins_
private

Definition at line 52 of file MCUInterface.h.

◆ shutdown_b_above_threshold

bool MCUInterface::shutdown_b_above_threshold
private

Definition at line 64 of file MCUInterface.h.

◆ shutdown_c_above_threshold

bool MCUInterface::shutdown_c_above_threshold
private

Definition at line 65 of file MCUInterface.h.

◆ shutdown_d_above_threshold

bool MCUInterface::shutdown_d_above_threshold
private

Definition at line 66 of file MCUInterface.h.

◆ shutdown_e_above_threshold

bool MCUInterface::shutdown_e_above_threshold
private

Definition at line 67 of file MCUInterface.h.

◆ shutdown_g_above_threshold

bool MCUInterface::shutdown_g_above_threshold
private

Definition at line 68 of file MCUInterface.h.

◆ software_ok_high

bool MCUInterface::software_ok_high
private

Definition at line 61 of file MCUInterface.h.


The documentation for this class was generated from the following files: