From 133e3feda9223adf1e4758bc32a61e01838b021c Mon Sep 17 00:00:00 2001 From: Vincent Pelletier Date: Sat, 29 Oct 2022 01:31:43 +0000 Subject: [PATCH] Cart_Reader.ino: New variants of print_Error Tagged with noreturn so the compiler knows about the effect of forceReset=true. Ideally, print_Error should lose its forceReset argument so that: - print_Error never resets - print_FatalError always resets (and hosts the code doing so) so the compiler is more accurately aware of the execution flow. --- Cart_Reader/Cart_Reader.ino | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/Cart_Reader/Cart_Reader.ino b/Cart_Reader/Cart_Reader.ino index 91da0a1..85963bc 100644 --- a/Cart_Reader/Cart_Reader.ino +++ b/Cart_Reader/Cart_Reader.ino @@ -490,7 +490,7 @@ byte sdBuffer[512]; // soft reset Arduino: jumps to 0 // using the watchdog timer would be more elegant but some Mega2560 bootloaders are buggy with it -void (*resetArduino)(void) = 0; +void (*resetArduino)(void) __attribute__ ((noreturn)) = 0; // Progressbar void draw_progressbar(uint32_t processedsize, uint32_t totalsize); @@ -2005,6 +2005,22 @@ void print_Error(byte errorMessage, boolean forceReset) { } } +void print_FatalError(const __FlashStringHelper* errorMessage) __attribute__ ((noreturn)); +void print_FatalError(const __FlashStringHelper* errorMessage) { + print_Error(errorMessage, true); + // Redundant as print_Error already calls it, but makes gcc understand that + // this in fact does not return. + resetArduino(); +} + +void print_FatalError(byte errorMessage) __attribute__ ((noreturn)); +void print_FatalError(byte errorMessage){ + print_Error(errorMessage, true); + // Redundant as print_Error already calls it, but makes gcc understand that + // this in fact does not return. + resetArduino(); +} + void wait() { // Switch status LED off statusLED(false);