Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

general core health status: KISS api #4687

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions cores/esp8266/Arduino.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
23 changes: 23 additions & 0 deletions cores/esp8266/core_health.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@

#include <stdint.h>
#include <core_health_setter.h>

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;
}
34 changes: 34 additions & 0 deletions cores/esp8266/core_health.h
Original file line number Diff line number Diff line change
@@ -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
22 changes: 22 additions & 0 deletions cores/esp8266/core_health_setter.h
Original file line number Diff line number Diff line change
@@ -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 <core_health.h>

#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