My Marlin configs for Fabrikator Mini and CTC i3 Pro B
Du kan inte välja fler än 25 ämnen Ämnen måste starta med en bokstav eller siffra, kan innehålla bindestreck ('-') och vara max 35 tecken långa.

watchdog.pde 1.9KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. #ifdef USE_WATCHDOG
  2. #include "watchdog.h"
  3. #include <avr/wdt.h>
  4. #include <avr/interrupt.h>
  5. //===========================================================================
  6. //=============================private variables ============================
  7. //===========================================================================
  8. static volatile uint8_t timeout_seconds=0;
  9. void(* ctrlaltdelete) (void) = 0; //does not work on my atmega2560
  10. //===========================================================================
  11. //=============================functinos ============================
  12. //===========================================================================
  13. /// intialise watch dog with a 1 sec interrupt time
  14. void wd_init()
  15. {
  16. WDTCSR |= (1<<WDCE )|(1<<WDE ); //allow changes
  17. WDTCSR = (1<<WDCE )|(1<<WDE )|(1<<WDP3 )|(1<<WDP0); // Reset after 8 sec.
  18. // WDTCSR = (1<<WDIF)|(1<<WDIE)| (1<<WDCE )|(1<<WDE )| (1<<WDP3) | (1<<WDP0);
  19. }
  20. /// reset watchdog. MUST be called every 1s after init or avr will reset.
  21. void wd_reset()
  22. {
  23. wdt_reset();
  24. }
  25. //===========================================================================
  26. //=============================ISR ============================
  27. //===========================================================================
  28. //Watchdog timer interrupt, called if main program blocks >1sec
  29. ISR(WDT_vect)
  30. {
  31. if(timeout_seconds++ >= WATCHDOG_TIMEOUT)
  32. {
  33. #ifdef RESET_MANUAL
  34. LCD_MESSAGEPGM("Please Reset!");
  35. LCD_STATUS;
  36. SERIAL_ERROR_START;
  37. SERIAL_ERRORLNPGM("Something is wrong, please turn off the printer.");
  38. #else
  39. LCD_MESSAGEPGM("Timeout, resetting!");
  40. LCD_STATUS;
  41. #endif
  42. //disable watchdog, it will survife reboot.
  43. WDTCSR |= (1<<WDCE) | (1<<WDE);
  44. WDTCSR = 0;
  45. #ifdef RESET_MANUAL
  46. kill(); //kill blocks
  47. while(1); //wait for user or serial reset
  48. #else
  49. ctrlaltdelete();
  50. #endif
  51. }
  52. }
  53. #endif /* USE_WATCHDOG */