Skip to content

Add the ability to be called back when the device is about to reset #1012

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

Merged
merged 1 commit into from Nov 15, 2015
Merged

Add the ability to be called back when the device is about to reset #1012

merged 1 commit into from Nov 15, 2015

Conversation

cpacey
Copy link

@cpacey cpacey commented Nov 12, 2015

Attempt to address #1011. Feedback is desired, because it's not the cleanest code.

Caveats:

  • Be very careful in your callback.
  • Will only actually get called for Exceptions and Soft WDT resets.

* yield (so pretty much don't call Arduino code). And god help you if
* it crashes.
*/
void installCustomCrashCallback( CrashCallback );
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This was the best place I could find to allow installing the callback.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My suggestion is to install custom crash handler by overriding some weak
function, which defaults to no-op.

On Thu, Nov 12, 2015 at 9:56 PM, Carl Pacey notifications@github.com
wrote:

In cores/esp8266/Esp.h
#1012 (comment):

@@ -131,6 +133,13 @@ class EspClass {
bool eraseConfig();

     inline uint32_t getCycleCount();
  •    /**
    
  •     \* Be very careful in your callback.  Don't call anything that could
    
  •     \*  yield (so pretty much don't call Arduino code).  And god help you if
    
  •     \*  it crashes.
    
  •     */
    
  •    void installCustomCrashCallback( CrashCallback );
    

This was the best place I could find to allow installing the callback.


Reply to this email directly or view it on GitHub
https://github.com/esp8266/Arduino/pull/1012/files#r44698297.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I didn't know about that feature, that's way cleaner. I'll make that change, thanks!

Caveats:
- You have to be very careful in your callback.
- On Adafruit Huzzah, I only actually get called for Exceptions and Soft
   WDT resets.
extern void __custom_crash_callback( struct rst_info * rst_info, uint32_t stack, uint32_t stack_end ) {
}

extern void custom_crash_callback( struct rst_info * rst_info, uint32_t stack, uint32_t stack_end ) __attribute__ ((weak, alias("__custom_crash_callback")));
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've aped the style used elsewhere in this project, though I must admit I don't know the reason for the alias (my guess is that it makes for less confusion when looking at stack dumps).

@cpacey
Copy link
Author

cpacey commented Nov 13, 2015

Apologies for all the churn. I'll try to keep that down in the future.

igrr added a commit that referenced this pull request Nov 15, 2015
Add the ability to be called back when the device is about to reset
@igrr igrr merged commit b31d0ce into esp8266:master Nov 15, 2015
@cpacey cpacey deleted the custom_crash_callback branch November 16, 2015 14:24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants