MRI Hooks: remember previous state, programmatically construct pin lists from Tempera...
authorMichael Moon <triffid.hunter@gmail.com>
Sun, 3 Feb 2013 02:16:11 +0000 (13:16 +1100)
committerMichael Moon <triffid.hunter@gmail.com>
Sun, 3 Feb 2013 02:16:11 +0000 (13:16 +1100)
src/libs/MRI_Hooks.cpp [new file with mode: 0644]
src/libs/MRI_Hooks.h [new file with mode: 0644]
src/libs/StepperMotor.cpp
src/libs/Watchdog.cpp
src/libs/Watchdog.h
src/modules/tools/switch/Switch.cpp
src/modules/tools/temperaturecontrol/TemperatureControl.cpp

diff --git a/src/libs/MRI_Hooks.cpp b/src/libs/MRI_Hooks.cpp
new file mode 100644 (file)
index 0000000..c16a8eb
--- /dev/null
@@ -0,0 +1,71 @@
+#include "MRI_Hooks.h"
+
+#include <sLPC17xx.h>
+#include <mri.h>
+
+extern "C" {
+    static uint32_t _set_high_on_debug[5] = {
+//         (1 << 4) | (1 << 10) | (1 << 19) | (1 << 21), // smoothieboard stepper EN pins
+        0,
+        0,
+        0,
+        0,
+        0
+    };
+    static uint32_t _set_low_on_debug[5]  = {
+        0,
+        0,
+//         (1 << 4) | (1 << 5) | (1 << 6) | (1 << 7), // smoothieboard heater outputs
+        0,
+        0,
+        0
+    };
+
+    static uint32_t _previous_state[5];
+
+    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]);
+
+            _previous_state[i] = io->FIOPIN;
+
+            io->FIOSET   = _set_high_on_debug[i];
+            io->FIOCLR   = _set_low_on_debug[i];
+        }
+    }
+
+    void __mriPlatform_LeavingDebuggerHook()
+    {
+        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   =   _previous_state[i]  & (_set_high_on_debug[i] | _set_low_on_debug[i]);
+            io->FIOCLR   = (~_previous_state[i]) & (_set_high_on_debug[i] | _set_low_on_debug[i]);
+        }
+    }
+
+    void set_high_on_debug(int port, int pin)
+    {
+        if ((port >= 5) || (port < 0))
+            return;
+        if ((pin >= 32) || (pin < 0))
+            return;
+        _set_high_on_debug[port] |= (1<<pin);
+    }
+
+    void set_low_on_debug(int port, int pin)
+    {
+        if ((port >= 5) || (port < 0))
+            return;
+        if ((pin >= 32) || (pin < 0))
+            return;
+        _set_low_on_debug[port] |= (1<<pin);
+    }
+}
diff --git a/src/libs/MRI_Hooks.h b/src/libs/MRI_Hooks.h
new file mode 100644 (file)
index 0000000..cb0f2ce
--- /dev/null
@@ -0,0 +1,12 @@
+#ifndef _MRI_HOOKS_H
+#define _MRI_HOOKS_H
+
+extern "C" {
+    void __mriPlatform_EnteringDebuggerHook();
+    void __mriPlatform_LeavingDebuggerHook();
+
+    void set_high_on_debug(int port, int pin);
+    void set_low_on_debug(int port, int pin);
+}
+
+#endif /* _MRI_HOOKS_H */
index 316311f..4ab8f63 100644 (file)
@@ -7,6 +7,7 @@
 #include "mri.h"
 #include "libs/Kernel.h"
 #include "StepperMotor.h"
+#include "MRI_Hooks.h"
 
 StepperMotor::StepperMotor(){
     this->moving = false;
@@ -34,6 +35,8 @@ StepperMotor::StepperMotor(Pin* step, Pin* dir, Pin* en) : step_pin(step), dir_p
     this->is_move_finished = false;
     this->signal_step = false;
     this->step_signal_hook = new Hook();
+
+    set_high_on_debug(en->port_number, en->pin);
 }
 
 // Called a great many times per second, to step if we have to now
index 7eca206..4aa414a 100644 (file)
@@ -4,41 +4,6 @@
 
 #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);
index 2d69a88..20f0bec 100644 (file)
@@ -11,11 +11,6 @@ typedef enum
     WDT_RESET,
 } WDT_ACTION;
 
-extern "C" {
-    void __mriPlatform_EnteringDebuggerHook();
-    void __mriPlatform_LeavingDebuggerHook();
-}
-
 class Watchdog : public Module
 {
 public:
index a6f805e..f0bf46a 100644 (file)
@@ -11,6 +11,8 @@
 #include "Switch.h"
 #include "libs/Pin.h"
 
+#include "MRI_Hooks.h"
+
 Switch::Switch(){}
 
 Switch::Switch(uint16_t name){
@@ -34,6 +36,8 @@ void Switch::on_config_reload(void* argument){
     this->off_m_code    = this->kernel->config->value(switch_checksum, this->name_checksum, off_m_code_checksum    )->required()->as_number();
     this->output_pin    = this->kernel->config->value(switch_checksum, this->name_checksum, output_pin_checksum    )->required()->as_pwm()->as_output();
     this->output_pin->set(this->kernel->config->value(switch_checksum, this->name_checksum, startup_state_checksum )->by_default(0)->as_number() );
+
+    set_low_on_debug(output_pin->pin->port_number, output_pin->pin->pin);
 }
 
 // Turn pin on and off
index 0edc63b..109a39f 100644 (file)
@@ -15,6 +15,8 @@
 #include "libs/Pin.h"
 #include "libs/Median.h"
 
+#include "MRI_Hooks.h"
+
 TemperatureControl::TemperatureControl(){}
 
 TemperatureControl::TemperatureControl(uint16_t name){
@@ -92,6 +94,8 @@ void TemperatureControl::on_config_reload(void* argument){
     this->heater_pin     =  this->kernel->config->value(temperature_control_checksum, this->name_checksum, heater_pin_checksum)->required()->as_pwm()->as_output();
     this->heater_pin->set(0);
 
+    set_low_on_debug(heater_pin->pin->port_number, heater_pin->pin->pin);
+
     // activate SD-DAC timer
     this->kernel->slow_ticker->attach(1000, this->heater_pin, &Pwm::on_tick);
 
@@ -288,5 +292,5 @@ int TemperatureControl::new_thermistor_reading()
 void TemperatureControl::on_second_tick(void* argument)
 {
     if (waiting)
-        kernel->streams->printf("%s:%3.1f /%3.1f @%d\n", designator.c_str(), get_temperature(), ((target_temperature == UNDEFINED)?0.0:target_temperature), o, waiting);
+        kernel->streams->printf("%s:%3.1f /%3.1f @%d\n", designator.c_str(), get_temperature(), ((target_temperature == UNDEFINED)?0.0:target_temperature), o);
 }