Skip to content

Commit

Permalink
gw.py reset: Reset to Power-On Defaults
Browse files Browse the repository at this point in the history
  • Loading branch information
keirf committed Mar 10, 2020
1 parent 88b3af0 commit 0bf525c
Show file tree
Hide file tree
Showing 5 changed files with 74 additions and 13 deletions.
4 changes: 3 additions & 1 deletion inc/cdc_acm_protocol.h
Original file line number Diff line number Diff line change
Expand Up @@ -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


/*
Expand Down
36 changes: 36 additions & 0 deletions scripts/greaseweazle/tools/reset.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
# greaseweazle/tools/rset.py
#
# Greaseweazle control script: Reset to power-on defaults.
#
# Written & released by Keir Fraser <[email protected]>
#
# 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:
10 changes: 9 additions & 1 deletion scripts/greaseweazle/usb.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ class Cmd:
Deselect = 13
SetBusType = 14
SetPin = 15
Reset = 16
str = {
GetInfo: "GetInfo",
Update: "Update",
Expand All @@ -49,7 +50,8 @@ class Cmd:
Select: "Select",
Deselect: "Deselect",
SetBusType: "SetBusType",
SetPin: "SetPin"
SetPin: "SetPin",
Reset: "Reset"
}


Expand Down Expand Up @@ -187,6 +189,12 @@ def set_pin(self, pin, level):
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):
Expand Down
2 changes: 1 addition & 1 deletion scripts/gw.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
35 changes: 25 additions & 10 deletions src/floppy.c
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -114,23 +115,27 @@ 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++) {
unit[i].cyl = -1;
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;
}
Expand Down Expand Up @@ -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 = {
Expand Down Expand Up @@ -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))
Expand Down

0 comments on commit 0bf525c

Please sign in to comment.