My Marlin configs for Fabrikator Mini and CTC i3 Pro B
Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.

watchdog.cpp 1.9KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. #include "Marlin.h"
  2. #ifdef 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. {
  15. #ifdef WATCHDOG_RESET_MANUAL
  16. //We enable the watchdog timer, but only for the interrupt.
  17. //Take care, as this requires the correct order of operation, with interrupts disabled. See the datasheet of any AVR chip for details.
  18. wdt_reset();
  19. _WD_CONTROL_REG = _BV(_WD_CHANGE_BIT) | _BV(WDE);
  20. _WD_CONTROL_REG = _BV(WDIE) | WDTO_4S;
  21. #else
  22. wdt_enable(WDTO_4S);
  23. #endif
  24. }
  25. /// reset watchdog. MUST be called every 1s after init or avr will reset.
  26. void watchdog_reset()
  27. {
  28. wdt_reset();
  29. }
  30. //===========================================================================
  31. //=================================== ISR ===================================
  32. //===========================================================================
  33. //Watchdog timer interrupt, called if main program blocks >1sec and manual reset is enabled.
  34. #ifdef WATCHDOG_RESET_MANUAL
  35. ISR(WDT_vect)
  36. {
  37. //TODO: This message gets overwritten by the kill() call
  38. LCD_ALERTMESSAGEPGM("ERR:Please Reset");//16 characters so it fits on a 16x2 display
  39. lcd_update();
  40. SERIAL_ERROR_START;
  41. SERIAL_ERRORLNPGM("Something is wrong, please turn off the printer.");
  42. kill(); //kill blocks
  43. while(1); //wait for user or serial reset
  44. }
  45. #endif//RESET_MANUAL
  46. #endif//USE_WATCHDOG