My Marlin configs for Fabrikator Mini and CTC i3 Pro B
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

watchdog.cpp 1.8KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. #include "Marlin.h"
  2. #if ENABLED(USE_WATCHDOG)
  3. #include <avr/wdt.h>
  4. #include "watchdog.h"
  5. #include "ultralcd.h"
  6. //===========================================================================
  7. //============================ private variables ============================
  8. //===========================================================================
  9. //===========================================================================
  10. //================================ functions ================================
  11. //===========================================================================
  12. /// intialise watch dog with a 4 sec interrupt time
  13. void watchdog_init() {
  14. #if ENABLED(WATCHDOG_RESET_MANUAL)
  15. //We enable the watchdog timer, but only for the interrupt.
  16. //Take care, as this requires the correct order of operation, with interrupts disabled. See the datasheet of any AVR chip for details.
  17. wdt_reset();
  18. _WD_CONTROL_REG = _BV(_WD_CHANGE_BIT) | _BV(WDE);
  19. _WD_CONTROL_REG = _BV(WDIE) | WDTO_4S;
  20. #else
  21. wdt_enable(WDTO_4S);
  22. #endif
  23. }
  24. /// reset watchdog. MUST be called every 1s after init or avr will reset.
  25. void watchdog_reset() {
  26. wdt_reset();
  27. }
  28. //===========================================================================
  29. //=================================== ISR ===================================
  30. //===========================================================================
  31. //Watchdog timer interrupt, called if main program blocks >1sec and manual reset is enabled.
  32. #if ENABLED(WATCHDOG_RESET_MANUAL)
  33. ISR(WDT_vect) {
  34. SERIAL_ERROR_START;
  35. SERIAL_ERRORLNPGM("Something is wrong, please turn off the printer.");
  36. kill(PSTR("ERR:Please Reset")); //kill blocks //16 characters so it fits on a 16x2 display
  37. while (1); //wait for user or serial reset
  38. }
  39. #endif//RESET_MANUAL
  40. #endif//USE_WATCHDOG