Skip to content

Commit f03ce5d

Browse files
fixes to state machine
1 parent 8e3329f commit f03ce5d

2 files changed

Lines changed: 9 additions & 29 deletions

File tree

Core/Src/u_statemachine.c

Lines changed: 1 addition & 21 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_closed(),
57+
(),
5858
pedals_getTorqueLimitPercentage(),
5959
(cerberus_state.functional != F_REVERSE),
6060
pedals_getRegenLimit(),
@@ -331,25 +331,5 @@ void statemachine_process(state_req_t new_state_req) {
331331
else if(new_state_req.id == FUNCTIONAL) { transition_functional_state(new_state_req.state.functional); }
332332
}
333333

334-
if (!is_ts_rising && is_shutdown_closed()) {
335-
is_ts_rising = true;
336-
337-
/* Restart TS Rising timer. */
338-
int status = timer_restart(&ts_rising_timer);
339-
if(status != U_SUCCESS) {
340-
PRINTLN_ERROR("Failed to restart TS Rising timer in `if (!ts_rising && !is_shutdown_closed())` (Status: %d).", status);
341-
return;
342-
}
343-
344-
} else if (!is_shutdown_closed()) {
345-
/* Stop the TS Rising timer. */
346-
int status = timer_stop(&ts_rising_timer);
347-
if(status != U_SUCCESS) {
348-
PRINTLN_ERROR("Failed to stop TS Rising timer in `else if (!is_shutdown_closed())` (Status: %d).", status);
349-
return;
350-
}
351-
is_ts_rising = false;
352-
enter_drive_enabled = false;
353-
}
354334
send_carstate_msg();
355335
}

Core/Src/u_threads.c

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -268,18 +268,20 @@ static thread_t statemachine_thread = {
268268
.threshold = 0, /* Preemption Threshold */
269269
.time_slice = TX_NO_TIME_SLICE, /* Time Slice */
270270
.auto_start = TX_AUTO_START, /* Auto Start */
271-
.sleep = 0, /* Sleep (in ticks) */
271+
.sleep = 200, /* Sleep (in ticks) */
272272
.function = vStatemachine /* Thread Function */
273273
};
274274
void vStatemachine(ULONG thread_input) {
275275

276276
while(1) {
277277
state_req_t new_state_req;
278-
while(queue_receive(&state_transition_queue, &new_state_req, TX_WAIT_FOREVER) == U_SUCCESS) {
279-
statemachine_process(new_state_req);
280-
}
281-
282-
/* No sleep. Thread timing is controlled completely by the queue timeout. */
278+
279+
// check if there is a transition in the queue, if not skip processing
280+
UINT status = queue_receive(&state_transition_queue, &new_state_req, statemachine_thread.sleep);
281+
if (status == U_SUCCESS) statemachine_process(new_state_req);
282+
283+
// send state periodically whether receiving a transition or not
284+
send_carstate_msg();
283285
}
284286
}
285287

@@ -934,8 +936,6 @@ uint8_t threads_init(TX_BYTE_POOL *byte_pool) {
934936
CATCH_ERROR(create_thread(byte_pool, &efuses_thread), U_SUCCESS); // Create eFuses thread.
935937
CATCH_ERROR(create_thread(byte_pool, &mux_thread), U_SUCCESS); // Create Mux thread.
936938
CATCH_ERROR(create_thread(byte_pool, &peripherals_thread), U_SUCCESS); // Create Peripherals thread.
937-
// CATCH_ERROR(create_thread(byte_pool, &test_thread), U_SUCCESS); // Create Test thread.
938-
CATCH_ERROR(create_thread(byte_pool, &misc_telemetry_thread), U_SUCCESS); // Create RTDS Telemetry thread.
939939

940940
// add more threads here if need
941941

0 commit comments

Comments
 (0)