use MRI hooks to disable heaters in debug mode
authorMichael Moon <triffid.hunter@gmail.com>
Wed, 23 Jan 2013 02:42:49 +0000 (13:42 +1100)
committerMichael Moon <triffid.hunter@gmail.com>
Wed, 23 Jan 2013 03:09:30 +0000 (14:09 +1100)
src/libs/Watchdog.cpp
src/libs/Watchdog.h
src/main.cpp

index 1cc16cd..7eca206 100644 (file)
@@ -4,6 +4,41 @@
 
 #include <mri.h>
 
+extern "C" {
+    static uint32_t _set_high_on_debug[5] = {
+        (1 << 4) | (1 << 10) | (1 << 19) | (1 << 21),
+        0,
+        0,
+        0,
+        0
+    };
+    static uint32_t _set_low_on_debug[5]  = {
+        0,
+        0,
+        (1 << 4) | (1 << 5) | (1 << 6) | (1 << 7),
+        0,
+        0
+    };
+
+    static LPC_GPIO_TypeDef* io;
+    static int i;
+
+    void __mriPlatform_EnteringDebuggerHook()
+    {
+        for (i = 0; i < 5; i++)
+        {
+            io           = (LPC_GPIO_TypeDef*) (LPC_GPIO_BASE + (0x20 * i));
+            io->FIOMASK &= ~(_set_high_on_debug[i] | _set_low_on_debug[i]);
+            io->FIOSET   = _set_high_on_debug[i];
+            io->FIOCLR   = _set_low_on_debug[i];
+        }
+    }
+
+    void __mriPlatform_LeavingDebuggerHook()
+    {
+    }
+}
+
 Watchdog::Watchdog(uint32_t timeout, WDT_ACTION action)
 {
     WDT_Init(WDT_CLKSRC_IRC, (action == WDT_MRI)?WDT_MODE_INT_ONLY:WDT_MODE_RESET);
@@ -16,9 +51,21 @@ void Watchdog::feed()
     WDT_Feed();
 }
 
+void Watchdog::on_module_loaded()
+{
+    register_for_event(ON_IDLE);
+    feed();
+}
+
+void Watchdog::on_idle(void*)
+{
+    feed();
+}
+
+
 extern "C" void WDT_IRQHandler(void)
 {
     WDT_ClrTimeOutFlag();
     WDT_Feed();
     __debugbreak();
-}
\ No newline at end of file
+}
index 183aa55..2d69a88 100644 (file)
@@ -3,17 +3,27 @@
 
 #include <stdint.h>
 
+#include "Module.h"
+
 typedef enum
 {
     WDT_MRI,
     WDT_RESET,
 } WDT_ACTION;
 
-class Watchdog
+extern "C" {
+    void __mriPlatform_EnteringDebuggerHook();
+    void __mriPlatform_LeavingDebuggerHook();
+}
+
+class Watchdog : public Module
 {
 public:
     Watchdog(uint32_t timeout, WDT_ACTION action);
     void feed();
+
+    void on_module_loaded();
+    void on_idle(void*);
 };
 
 #endif /* _WATCHDOG_H */
index c160c54..a62fe59 100644 (file)
@@ -103,6 +103,7 @@ int main() {
 //     }
 
 //     kernel->add_module( new Laser(p21) );
+//     kernel->add_module( &wd );
     kernel->add_module( new Extruder() );
     kernel->add_module( new SimpleShell() );
     kernel->add_module( new Configurator() );