Skip to content

Commit 3abffd5

Browse files
Changed is_shutdown_active() to is_shutdown_closed() (#196)
1 parent 2e4e03e commit 3abffd5

5 files changed

Lines changed: 23 additions & 24 deletions

File tree

Core/Inc/u_shutdown.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ void update_bms_shutdown(bool new_state);
1414
void shutdown_process(void);
1515

1616
/**
17-
* @brief Indicates if shutdown is active or not.
18-
* @return The current shutdown state. `false` means that shutdown is NOT active, indicating normal operation. `true` means that shutdown IS active, which is bad.
17+
* @brief Indicates if shutdown is closed or not.
18+
* @return `true` if shutdown is closed, or `false` if otherwise. Shutdown has to be closed for us to drive.
1919
*/
20-
bool is_shutdown_active(void);
20+
bool is_shutdown_closed(void);

Core/Inc/u_statemachine.h

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -134,10 +134,6 @@ int fault();
134134
*/
135135
void send_carstate_msg(void);
136136

137-
/* BMS-Reported Shutdown! */
138-
void update_shutdown(bool new_shutdown);
139-
bool is_shutdown_active(void);
140-
141137
/* Process the state machine */
142138
void statemachine_process(state_req_t new_state_req);
143139
int init_statemachine(void);

Core/Src/u_rtds.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,9 +32,9 @@ static timer_t reverse_sound_timer = {
3232

3333
/* Sets (i.e. turns on) the RTDS pin. */
3434
static void _set_rtds_pin(void) {
35-
/* If shutdown is active, make it impossible to sound RTDS. */
36-
if(!is_shutdown_active()) {
37-
return; // Return early. Never ever have RTDS be high when shutdown is open.
35+
/* If shutdown isn't closed, we can't drive. So, make it impossible to sound RTDS. */
36+
if(!is_shutdown_closed()) {
37+
return; // Return early so RTDS doesn't sound.
3838
}
3939

4040
HAL_GPIO_WritePin(RTDS_GPIO_GPIO_Port, RTDS_GPIO_Pin, GPIO_PIN_SET); // Turn on RTDS pin.

Core/Src/u_shutdown.c

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
#include "can_messages_tx.h"
1111

1212
/* Bool to track the BMS shutdown state. */
13-
static _Atomic bool bms_shutdown = false; // We should assume that we are shutdown is open until BMS confirms that shutdown is active.
13+
static _Atomic bool bms_shutdown = false; // We should assume that we are shutdown is open (`false`) until BMS confirms that shutdown is open (`true`).
1414
// BMS periodically sends out a CAN message reporting the shutdown state. That state is tracked here.
1515
// When this bool is `false`, BMS is indicating that shutdown is open, which is bad.
1616
// When this bool is `true`, BMS is indicating that shutdown is closed, meaning that we are in normal operation and everything is good
@@ -25,8 +25,11 @@ void update_bms_shutdown(bool new_state) {
2525
bms_shutdown = new_state;
2626
}
2727

28-
/* Indicates if shutdown is active. */
29-
bool is_shutdown_active(void) {
28+
/* Indicates if shutdown is closed or not.
29+
* When shutdown is closed, this function returns `true`. Otherwise, this function returns `false`.
30+
* Shutdown has to be closed for us to drive. When shutdown isn't closed, we are not allowed to drive.
31+
*/
32+
bool is_shutdown_closed(void) {
3033
return bms_shutdown;
3134
}
3235

Core/Src/u_statemachine.c

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ void send_carstate_msg(void)
5454
get_nero_state().home_mode,
5555
get_nero_state().nero_index,
5656
dti_get_mph(),
57-
is_shutdown_active(),
57+
is_shutdown_closed(),
5858
pedals_getTorqueLimitPercentage(),
5959
(cerberus_state.functional != F_REVERSE),
6060
pedals_getRegenLimit(),
@@ -128,7 +128,7 @@ static int transition_functional_state(func_state_t new_state)
128128

129129
brake_state = pedals_getBrakeState();
130130
#ifdef TSMS_OVERRIDE
131-
if (!is_shutdown_active() && (!brake_state || cerberus_state.functional == FAULTED)) { // only enforce brake / fault if tsms is actually on
131+
if (!is_shutdown_closed() && (!brake_state || cerberus_state.functional == FAULTED)) { // only enforce brake / fault if tsms is actually on
132132
return 3;
133133
}
134134
printf("Ignoring tsms\n\n");
@@ -143,13 +143,13 @@ static int transition_functional_state(func_state_t new_state)
143143
return 3;
144144
}
145145

146-
/* Only turn on motor if brakes engaged and shutdown active */
147-
if (!brake_state || !is_shutdown_active()) {
146+
/* Only turn on motor if brakes engaged and shutdown is closed */
147+
if (!brake_state || !is_shutdown_closed()) {
148148
return 3;
149149
}
150150
#endif
151151

152-
if (is_shutdown_active()) {
152+
if (is_shutdown_closed()) {
153153
rtds_soundRTDS();
154154
}
155155

@@ -189,10 +189,10 @@ static int transition_nero_state(nero_state_t new_state)
189189
}
190190
}
191191

192-
/* TSMS OFF and MPH = 0 to enter games */
192+
/* Shutdown = Open and MPH = 0 to enter games */
193193
if (new_state.nero_index == GAMES) {
194194
#ifndef TSMS_OVERRIDE
195-
if (is_shutdown_active() || dti_get_mph() >= 1) {
195+
if (is_shutdown_closed() || dti_get_mph() >= 1) {
196196
return 1;
197197
}
198198
#endif
@@ -322,21 +322,21 @@ void statemachine_process(state_req_t new_state_req) {
322322
else if(new_state_req.id == FUNCTIONAL) { transition_functional_state(new_state_req.state.functional); }
323323
}
324324

325-
if (!is_ts_rising && is_shutdown_active()) {
325+
if (!is_ts_rising && is_shutdown_closed()) {
326326
is_ts_rising = true;
327327

328328
/* Restart TS Rising timer. */
329329
int status = timer_restart(&ts_rising_timer);
330330
if(status != U_SUCCESS) {
331-
PRINTLN_ERROR("Failed to restart TS Rising timer (in !ts_rising && !is_shutdown_active()) (Status: %d).", status);
331+
PRINTLN_ERROR("Failed to restart TS Rising timer in `if (!ts_rising && !is_shutdown_closed())` (Status: %d).", status);
332332
return;
333333
}
334334

335-
} else if (!is_shutdown_active()) {
335+
} else if (!is_shutdown_closed()) {
336336
/* Stop the TS Rising timer. */
337337
int status = timer_stop(&ts_rising_timer);
338338
if(status != U_SUCCESS) {
339-
PRINTLN_ERROR("Failed to stop TS Rising timer (in is_shutdown_active()) (Status: %d).", status);
339+
PRINTLN_ERROR("Failed to stop TS Rising timer in `else if (!is_shutdown_closed())` (Status: %d).", status);
340340
return;
341341
}
342342
is_ts_rising = false;

0 commit comments

Comments
 (0)