Explorar o código

gw.py reset: Reset to Power-On Defaults

Keir Fraser %!s(int64=5) %!d(string=hai) anos
pai
achega
0bf525c3a5
Modificáronse 5 ficheiros con 74 adicións e 13 borrados
  1. 3 1
      inc/cdc_acm_protocol.h
  2. 36 0
      scripts/greaseweazle/tools/reset.py
  3. 9 1
      scripts/greaseweazle/usb.py
  4. 1 1
      scripts/gw.py
  5. 25 10
      src/floppy.c

+ 3 - 1
inc/cdc_acm_protocol.h

@@ -51,7 +51,9 @@
 #define CMD_SET_BUS_TYPE   14
 /* CMD_SET_PIN, length=4, pin#, level. */
 #define CMD_SET_PIN        15
-#define CMD_MAX            15
+/* CMD_RESET, length=2. Reset all state to initial (power on) values. */
+#define CMD_RESET          16
+#define CMD_MAX            16
 
 
 /*

+ 36 - 0
scripts/greaseweazle/tools/reset.py

@@ -0,0 +1,36 @@
+# greaseweazle/tools/rset.py
+#
+# Greaseweazle control script: Reset to power-on defaults.
+#
+# Written & released by Keir Fraser <keir.xen@gmail.com>
+#
+# This is free and unencumbered software released into the public domain.
+# See the file COPYING for more details, or visit <http://unlicense.org>.
+
+import sys, argparse
+
+from greaseweazle.tools import util
+from greaseweazle import usb as USB
+
+def main(argv):
+
+    parser = argparse.ArgumentParser(
+        formatter_class=argparse.ArgumentDefaultsHelpFormatter)
+    parser.add_argument("device", nargs="?", default="auto",
+                        help="serial device")
+    parser.prog += ' ' + argv[1]
+    args = parser.parse_args(argv[2:])
+
+    try:
+        usb = util.usb_open(args.device)
+        usb.power_on_reset()
+    except USB.CmdError as error:
+        print("Command Failed: %s" % error)
+
+
+if __name__ == "__main__":
+    main(sys.argv)
+
+# Local variables:
+# python-indent: 4
+# End:

+ 9 - 1
scripts/greaseweazle/usb.py

@@ -33,6 +33,7 @@ class Cmd:
     Deselect        = 13
     SetBusType      = 14
     SetPin          = 15
+    Reset           = 16
     str = {
         GetInfo: "GetInfo",
         Update: "Update",
@@ -49,7 +50,8 @@ class Cmd:
         Select: "Select",
         Deselect: "Deselect",
         SetBusType: "SetBusType",
-        SetPin: "SetPin"
+        SetPin: "SetPin",
+        Reset: "Reset"
     }
 
 
@@ -187,6 +189,12 @@ class Unit:
         self._send_cmd(struct.pack("4B", Cmd.SetPin, 4, pin, int(level)))
 
 
+    ## power_on_reset:
+    ## Re-initialise to power-on defaults.
+    def power_on_reset(self):
+        self._send_cmd(struct.pack("2B", Cmd.Reset, 2))
+
+
     ## drive_select:
     ## Select the specified drive unit.
     def drive_select(self, unit):

+ 1 - 1
scripts/gw.py

@@ -12,7 +12,7 @@
 import sys
 import importlib
 
-actions = [ 'read', 'write', 'delays', 'update', 'pin' ]
+actions = [ 'read', 'write', 'delays', 'update', 'pin', 'reset' ]
 argv = sys.argv
 
 if len(argv) < 2 or argv[1] not in actions:

+ 25 - 10
src/floppy.c

@@ -34,7 +34,8 @@ static struct {
     bool_t motor;
 } unit[3];
 
-static struct gw_delay delay_params = {
+static struct gw_delay delay_params;
+static const struct gw_delay factory_delay_params = {
     .select_delay = 10,
     .step_delay = 3000,
     .seek_settle = 15,
@@ -114,16 +115,9 @@ static void step_one_in(void)
     delay_us(delay_params.step_delay);
 }
 
-static bool_t set_bus_type(uint8_t type)
+static void _set_bus_type(uint8_t type)
 {
     int i;
-
-    if (type == bus_type)
-        return TRUE;
-
-    if (type > BUS_SHUGART)
-        return FALSE;
-
     bus_type = type;
     unit_nr = -1;
     for (i = 0; i < ARRAY_SIZE(unit); i++) {
@@ -131,6 +125,17 @@ static bool_t set_bus_type(uint8_t type)
         unit[i].motor = FALSE;
     }
     reset_bus();
+}
+
+static bool_t set_bus_type(uint8_t type)
+{
+    if (type == bus_type)
+        return TRUE;
+
+    if (type > BUS_SHUGART)
+        return FALSE;
+
+    _set_bus_type(type);
 
     return TRUE;
 }
@@ -240,7 +245,9 @@ void floppy_init(void)
     IRQx_set_prio(irq_index, INDEX_IRQ_PRI);
     IRQx_enable(irq_index);
 
-    set_bus_type(BUS_NONE);
+    delay_params = factory_delay_params;
+
+    _set_bus_type(BUS_NONE);
 }
 
 static struct gw_info gw_info = {
@@ -866,6 +873,14 @@ static void process_command(void)
         gpio_write_pin(gpio_densel, pin_densel, level);
         break;
     }
+    case CMD_RESET: {
+        if (len != 2)
+            goto bad_command;
+        delay_params = factory_delay_params;
+        _set_bus_type(BUS_NONE);
+        write_pin(densel, FALSE);
+        break;
+    }
     case CMD_SWITCH_FW_MODE: {
         uint8_t mode = u_buf[2];
         if ((len != 3) || (mode & ~1))