Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/Duet3D/RepRapFirmware.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/Hardware/ExceptionHandlers.cpp5
-rw-r--r--src/Hardware/SAME70/CanDriver.cpp3
-rw-r--r--src/Platform.cpp8
-rw-r--r--src/RepRap.cpp33
-rw-r--r--src/RepRapFirmware.h6
5 files changed, 39 insertions, 16 deletions
diff --git a/src/Hardware/ExceptionHandlers.cpp b/src/Hardware/ExceptionHandlers.cpp
index 11958f11..eb936130 100644
--- a/src/Hardware/ExceptionHandlers.cpp
+++ b/src/Hardware/ExceptionHandlers.cpp
@@ -142,8 +142,13 @@ void WDT_IRQHandler() noexcept
{
LPC_WDT->MOD &=~((uint32_t)(1<<2)); //SD::clear timout flag before resetting to prevent the Smoothie bootloader going into DFU mode
#else
+# if SAME70 // SAME70 has a separate interrupt line for the RSWDT
+extern "C" [[noreturn]] void RSWDT_Handler() noexcept __attribute__((naked));
+void RSWDT_Handler() noexcept
+# else
extern "C" [[noreturn]] void WDT_Handler() noexcept __attribute__((naked));
void WDT_Handler() noexcept
+# endif
{
#endif
__asm volatile
diff --git a/src/Hardware/SAME70/CanDriver.cpp b/src/Hardware/SAME70/CanDriver.cpp
index d91f1847..fd51480c 100644
--- a/src/Hardware/SAME70/CanDriver.cpp
+++ b/src/Hardware/SAME70/CanDriver.cpp
@@ -732,8 +732,9 @@ bool WaitForTxBufferFree(mcan_module *const module_inst, uint32_t whichTxBuffer,
{
delay(1);
}
+ return true;
}
- return true;
+ return false;
}
// Get a message from a FIFO with timeout. Return true if successful, false if we timed out
diff --git a/src/Platform.cpp b/src/Platform.cpp
index 95a2a423..85ea7158 100644
--- a/src/Platform.cpp
+++ b/src/Platform.cpp
@@ -1573,15 +1573,13 @@ float Platform::GetCpuTemperature() const noexcept
void Platform::InitialiseInterrupts() noexcept
{
-#if SAM4E || SAME70 || SAME5x || defined(__LPC17xx__)
- NVIC_SetPriority(WDT_IRQn, NvicPriorityWatchdog); // set priority for watchdog interrupts
-#endif
+ // Watchdog interrupt priority if applicable has already been set up in RepRap::Init
#if HAS_HIGH_SPEED_SD
- NVIC_SetPriority(SdhcIRQn, NvicPriorityHSMCI); // set priority for SD interface interrupts
+ NVIC_SetPriority(SdhcIRQn, NvicPriorityHSMCI); // set priority for SD interface interrupts
#endif
- // Set PanelDue UART interrupt priority is set in AuxDevioce::Init
+ // Set PanelDue UART interrupt priority is set in AuxDevice::Init
// WiFi UART interrupt priority is now set in module WiFiInterface
#if SUPPORT_TMC22xx && !SAME5x // SAME5x uses a DMA interrupt instead of the UART interrupt
diff --git a/src/RepRap.cpp b/src/RepRap.cpp
index 6b53fba3..63201ade 100644
--- a/src/RepRap.cpp
+++ b/src/RepRap.cpp
@@ -483,9 +483,11 @@ void RepRap::Init() noexcept
// Set up the timeout of the regular watchdog, and set up the backup watchdog if there is one.
#if SAME5x
WatchdogInit();
+ NVIC_SetPriority(WDT_IRQn, NvicPriorityWatchdog); // set priority for watchdog interrupts
+ NVIC_ClearPendingIRQ(WDT_IRQn);
NVIC_EnableIRQ(WDT_IRQn); // enable the watchdog early warning interrupt
#elif defined(__LPC17xx__)
- wdt_init(1); // set wdt to 1 second. reset the processor on a watchdog fault
+ wdt_init(1); // set wdt to 1 second. reset the processor on a watchdog fault
#else
{
// The clock frequency for both watchdogs is about 32768/128 = 256Hz
@@ -493,20 +495,33 @@ void RepRap::Init() noexcept
// The documentation says you mustn't write to the mode register within 3 slow clocks after kicking the watchdog.
// I have a theory that the converse is also true, i.e. after enabling the watchdog you mustn't kick it within 3 slow clocks
// So I've added a delay call before we set 'active' true (which enables kicking the watchdog), and that seems to fix the problem.
- const uint16_t timeout = 32768/128; // set watchdog timeout to 1 second (max allowed value is 4095 = 16 seconds)
- wdt_init(WDT, WDT_MR_WDRSTEN | WDT_MR_WDDBGHLT, timeout, timeout); // reset the processor on a watchdog fault, stop it when debugging
-
# if SAM4E || SAME70
+ const uint16_t mainTimeout = 49152/128; // set main (back stop) watchdog timeout to 1.5s second (max allowed value is 4095 = 16 seconds)
+ WDT->WDT_MR = WDT_MR_WDRSTEN | WDT_MR_WDDBGHLT | WDT_MR_WDV(mainTimeout) | WDT_MR_WDD(mainTimeout); // reset the processor on a watchdog fault, stop it when debugging
+
// The RSWDT must be initialised *after* the main WDT
- const uint16_t rsTimeout = 16384/128; // set secondary watchdog timeout to 0.5 second (max allowed value is 4095 = 16 seconds)
- rswdt_init(RSWDT, RSWDT_MR_WDFIEN | RSWDT_MR_WDDBGHLT, rsTimeout, rsTimeout); // generate an interrupt on a watchdog fault
+ const uint16_t rsTimeout = 32768/128; // set secondary watchdog timeout to 1 second (max allowed value is 4095 = 16 seconds)
+# if SAME70
+ RSWDT->RSWDT_MR = RSWDT_MR_WDFIEN | RSWDT_MR_WDDBGHLT | RSWDT_MR_WDV(rsTimeout) | RSWDT_MR_ALLONES_Msk; // generate an interrupt on a watchdog fault
+ NVIC_SetPriority(RSWDT_IRQn, NvicPriorityWatchdog); // set priority for watchdog interrupts
+ NVIC_ClearPendingIRQ(RSWDT_IRQn);
+ NVIC_EnableIRQ(RSWDT_IRQn); // enable the watchdog interrupt
+# else
+ RSWDT->RSWDT_MR = RSWDT_MR_WDFIEN | RSWDT_MR_WDDBGHLT | RSWDT_MR_WDV(rsTimeout) | RSWDT_MR_WDD(rsTimeout); // generate an interrupt on a watchdog fault
+ NVIC_SetPriority(WDT_IRQn, NvicPriorityWatchdog); // set priority for watchdog interrupts
+ NVIC_ClearPendingIRQ(WDT_IRQn);
NVIC_EnableIRQ(WDT_IRQn); // enable the watchdog interrupt
+# endif
+# else
+ // We don't have a RSWDT so set the main watchdog timeout to 1 second
+ const uint16_t timeout = 32768/128; // set watchdog timeout to 1 second (max allowed value is 4095 = 16 seconds)
+ wdt_init(WDT, WDT_MR_WDRSTEN | WDT_MR_WDDBGHLT, timeout, timeout); // reset the processor on a watchdog fault, stop it when debugging
# endif
delayMicroseconds(200); // 200us is about 6 slow clocks
}
#endif
- active = true; // must do this before we start the network or call Spin(), else the watchdog may time out
+ active = true; // must do this after we initialise the watchdog but before we start the network or call Spin(), else the watchdog may time out
platform->MessageF(UsbMessage, "%s\n", VersionText);
@@ -1169,9 +1184,9 @@ void RepRap::Tick() noexcept
// Kicking the watchdog before it has been initialised may trigger it!
if (active)
{
- WatchdogReset(); // kick the watchdog
+ WatchdogReset(); // kick the watchdog
#if SAM4E || SAME70
- rswdt_restart(RSWDT); // kick the secondary watchdog
+ RSWDT->RSWDT_CR = RSWDT_CR_KEY_PASSWD | RSWDT_CR_WDRSTT; // kick the secondary watchdog
#endif
if (!stopped)
diff --git a/src/RepRapFirmware.h b/src/RepRapFirmware.h
index cfd3b2ca..e83c98e0 100644
--- a/src/RepRapFirmware.h
+++ b/src/RepRapFirmware.h
@@ -71,7 +71,11 @@ const char *SafeStrptime(const char *buf, const char *format, struct tm *timeptr
// Functions needed for builds that use CoreNG. Not needed when using CoreN2G.
void delay(uint32_t ms) noexcept;
-static inline void WatchdogReset() noexcept { return watchdogReset(); }
+
+static inline void WatchdogReset() noexcept
+{
+ WDT->WDT_CR = WDT_CR_KEY_PASSWD | WDT_CR_WDRSTT;
+}
// Optimised version of memcpy for use when the source and destination are known to be 32-bit aligned and a whole number of 32-bit words is to be copied
void memcpyu32(uint32_t *dst, const uint32_t *src, size_t numWords) noexcept;