Skip to content

Commit

Permalink
add assert_fatal function (commaai#1976)
Browse files Browse the repository at this point in the history
* add assert function

* fix

* flip

* rename

* assert fatal
  • Loading branch information
adeebshihadeh authored Jun 26, 2024
1 parent cac94e3 commit ee1d5ce
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 14 deletions.
5 changes: 1 addition & 4 deletions board/jungle/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -156,10 +156,7 @@ int main(void) {
print("\n\n\n************************ MAIN START ************************\n");

// check for non-supported board types
if (hw_type == HW_TYPE_UNKNOWN) {
print("Unsupported board type\n");
while (1) { /* hang */ }
}
assert_fatal(hw_type != HW_TYPE_UNKNOWN, "Unsupported board type\n");

print("Config:\n");
print(" Board type: 0x"); puth(hw_type); print("\n");
Expand Down
10 changes: 10 additions & 0 deletions board/libc.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,16 @@ void delay(uint32_t a) {
for (i = 0; i < a; i++);
}

void assert_fatal(bool condition, const char *msg) {
if (!condition) {
print("ASSERT FAILED\n");
print(msg);
while (1) {
// hang
}
}
}

// cppcheck-suppress misra-c2012-21.2
void *memset(void *str, int c, unsigned int n) {
uint8_t *s = str;
Expand Down
13 changes: 3 additions & 10 deletions board/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -67,12 +67,8 @@ void set_safety_mode(uint16_t mode, uint16_t param) {
print("Error: safety set mode failed. Falling back to SILENT\n");
mode_copy = SAFETY_SILENT;
err = set_safety_hooks(mode_copy, 0U);
if (err == -1) {
print("Error: Failed setting SILENT mode. Hanging\n");
while (true) {
// TERMINAL ERROR: we can't continue if SILENT safety mode isn't succesfully set
}
}
// TERMINAL ERROR: we can't continue if SILENT safety mode isn't succesfully set
assert_fatal(err == 0, "Error: Failed setting SILENT mode. Hanging\n");
}
safety_tx_blocked = 0;
safety_rx_invalid = 0;
Expand Down Expand Up @@ -314,10 +310,7 @@ int main(void) {
print("\n\n\n************************ MAIN START ************************\n");

// check for non-supported board types
if(hw_type == HW_TYPE_UNKNOWN){
print("Unsupported board type\n");
while (1) { /* hang */ }
}
assert_fatal(hw_type != HW_TYPE_UNKNOWN, "Unsupported board type");

print("Config:\n");
print(" Board type: 0x"); puth(hw_type); print("\n");
Expand Down

0 comments on commit ee1d5ce

Please sign in to comment.