My Marlin configs for Fabrikator Mini and CTC i3 Pro B
Nevar pievienot vairāk kā 25 tēmas Tēmai ir jāsākas ar burtu vai ciparu, tā var saturēt domu zīmes ('-') un var būt līdz 35 simboliem gara.

watchdog.pde 1.8KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  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<<WDIF)|(1<<WDIE)| (1<<WDCE )|(1<<WDE )| (1<<WDP2 )|(1<<WDP1)|(0<<WDP0);
  18. }
  19. /// reset watchdog. MUST be called every 1s after init or avr will reset.
  20. void wd_reset()
  21. {
  22. wdt_reset();
  23. timeout_seconds=0; //reset counter for resets
  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_MESSAGE("Please Reset!");
  35. SERIAL_ERRORLN("Something is wrong, please turn off the printer.");
  36. #else
  37. LCD_MESSAGE("Timeout, resetting!");
  38. #endif
  39. //disable watchdog, it will survife reboot.
  40. WDTCSR |= (1<<WDCE) | (1<<WDE);
  41. WDTCSR = 0;
  42. #ifdef RESET_MANUAL
  43. kill(); //kill blocks
  44. while(1); //wait for user or serial reset
  45. #else
  46. ctrlaltdelete();
  47. #endif
  48. }
  49. }
  50. #endif /* USE_WATCHDOG */