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

watchdog.cpp 2.3KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. /**
  2. * Marlin 3D Printer Firmware
  3. * Copyright (C) 2019 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
  4. *
  5. * Based on Sprinter and grbl.
  6. * Copyright (C) 2011 Camiel Gubbels / Erik van der Zalm
  7. *
  8. * This program is free software: you can redistribute it and/or modify
  9. * it under the terms of the GNU General Public License as published by
  10. * the Free Software Foundation, either version 3 of the License, or
  11. * (at your option) any later version.
  12. *
  13. * This program is distributed in the hope that it will be useful,
  14. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. * GNU General Public License for more details.
  17. *
  18. * You should have received a copy of the GNU General Public License
  19. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  20. *
  21. */
  22. #ifdef TARGET_LPC1768
  23. #include "../../inc/MarlinConfig.h"
  24. #if ENABLED(USE_WATCHDOG)
  25. #include "lpc17xx_wdt.h"
  26. #include "watchdog.h"
  27. void watchdog_init(void) {
  28. #if ENABLED(WATCHDOG_RESET_MANUAL)
  29. // We enable the watchdog timer, but only for the interrupt.
  30. // Configure WDT to only trigger an interrupt
  31. // Disable WDT interrupt (just in case, to avoid triggering it!)
  32. NVIC_DisableIRQ(WDT_IRQn);
  33. // We NEED memory barriers to ensure Interrupts are actually disabled!
  34. // ( https://dzone.com/articles/nvic-disabling-interrupts-on-arm-cortex-m-and-the )
  35. __DSB();
  36. __ISB();
  37. // Configure WDT to only trigger an interrupt
  38. // Initialize WDT with the given parameters
  39. WDT_Init(WDT_CLKSRC_IRC, WDT_MODE_INT_ONLY);
  40. // Configure and enable WDT interrupt.
  41. NVIC_ClearPendingIRQ(WDT_IRQn);
  42. NVIC_SetPriority(WDT_IRQn, 0); // Use highest priority, so we detect all kinds of lockups
  43. NVIC_EnableIRQ(WDT_IRQn);
  44. #else
  45. WDT_Init(WDT_CLKSRC_IRC, WDT_MODE_RESET);
  46. #endif
  47. WDT_Start(WDT_TIMEOUT);
  48. }
  49. void HAL_clear_reset_source(void) {
  50. WDT_ClrTimeOutFlag();
  51. }
  52. uint8_t HAL_get_reset_source(void) {
  53. if (TEST(WDT_ReadTimeOutFlag(), 0)) return RST_WATCHDOG;
  54. return RST_POWER_ON;
  55. }
  56. void watchdog_reset() {
  57. WDT_Feed();
  58. #if DISABLED(PINS_DEBUGGING) && PIN_EXISTS(LED)
  59. TOGGLE(LED_PIN); // heartbeat indicator
  60. #endif
  61. }
  62. #else
  63. void HAL_clear_reset_source(void) {}
  64. uint8_t HAL_get_reset_source(void) { return RST_POWER_ON; }
  65. #endif // USE_WATCHDOG
  66. #endif // TARGET_LPC1768