From 69a929422e92500ffd1b5e5f99ba4e94e492a978 Mon Sep 17 00:00:00 2001 From: david gauchard Date: Thu, 26 Apr 2018 23:30:20 +0200 Subject: [PATCH] general core health status: KISS api --- cores/esp8266/Arduino.h | 1 + cores/esp8266/core_health.cpp | 23 ++++++++++++++++++++ cores/esp8266/core_health.h | 34 ++++++++++++++++++++++++++++++ cores/esp8266/core_health_setter.h | 22 +++++++++++++++++++ 4 files changed, 80 insertions(+) create mode 100644 cores/esp8266/core_health.cpp create mode 100644 cores/esp8266/core_health.h create mode 100644 cores/esp8266/core_health_setter.h diff --git a/cores/esp8266/Arduino.h b/cores/esp8266/Arduino.h index 5424d3baf3..d07fd4735f 100644 --- a/cores/esp8266/Arduino.h +++ b/cores/esp8266/Arduino.h @@ -38,6 +38,7 @@ extern "C" { #include "esp8266_peri.h" #include "twi.h" #include "core_esp8266_features.h" +#include "core_health.h" #define HIGH 0x1 #define LOW 0x0 diff --git a/cores/esp8266/core_health.cpp b/cores/esp8266/core_health.cpp new file mode 100644 index 0000000000..03e0e34a8a --- /dev/null +++ b/cores/esp8266/core_health.cpp @@ -0,0 +1,23 @@ + +#include +#include + +static uint32_t health = 0; + +int core_condition_is_fatal (void) +{ + return health > ((((decltype(health))1) << core_warn_last) - 1); +} + +int core_condition_has (core_condition_e disease) +{ + decltype(health) bits = ((decltype(health))1) << disease; + int badmood = !!(health & bits); + health &= ~bits; + return badmood; +} + +void core_condition_got (core_condition_e disease) +{ + health |= ((decltype(health))1) << disease; +} diff --git a/cores/esp8266/core_health.h b/cores/esp8266/core_health.h new file mode 100644 index 0000000000..887b30ab80 --- /dev/null +++ b/cores/esp8266/core_health.h @@ -0,0 +1,34 @@ + +#ifndef __CORE_HEALTH_H +#define __CORE_HEALTH_H + +/* + These 2 functions reflect a general health status + User can check them anytime + */ + +#ifdef __cplusplus +extern "C" { +#endif + +typedef enum { + core_warn_heap = 0, + core_warn_uart = 1, + core_warn_last = 1, + + core_fatal_string = 16, + core_fatal_axtls = 17, +} core_condition_e; + +// returns 0 if condition is not fatal +int core_condition_is_fatal (void); + +// returns 0 if core hasn't got this disease +// returns 1 otherwise, and cure it +int core_condition_has (core_condition_e disease); + +#ifdef __cplusplus +} // extern "C" +#endif + +#endif // __CORE_HEALTH_H diff --git a/cores/esp8266/core_health_setter.h b/cores/esp8266/core_health_setter.h new file mode 100644 index 0000000000..6bad7a6934 --- /dev/null +++ b/cores/esp8266/core_health_setter.h @@ -0,0 +1,22 @@ + +#ifndef __CORE_HEALTH_SETTER_H +#define __CORE_HEALTH_SETTER_H + +/* + this file is intended to be used by core internals + */ + +#include + +#ifdef __cplusplus +extern "C" { +#endif + +// bad or fatal things happened +void core_condition_got (core_condition_e disease); + +#ifdef __cplusplus +} // extern "C" +#endif + +#endif // __CORE_HEALTH_SETTER_H