Browse Source

usb: Use magic baud rates as out-of-band commands to Greaseweazle.
Currently we use this to reste communications at script start.
Unlike send_break(), this works on Mac OS too (at least on Mojave)

Keir Fraser 5 years ago
parent
commit
51178ae11d
4 changed files with 17 additions and 3 deletions
  1. 2 0
      inc/cdc_acm_protocol.h
  2. 5 1
      scripts/gw.py
  3. 2 2
      src/floppy.c
  4. 8 0
      src/usb/cdc_acm.c

+ 2 - 0
inc/cdc_acm_protocol.h

@@ -43,6 +43,8 @@
 #define ACK_FLUX_UNDERFLOW  5
 #define ACK_WRPROT          6
 
+#define BAUD_CLEAR_COMMS  10000
+
 struct __packed gw_info {
     uint8_t fw_major;
     uint8_t fw_minor;

+ 5 - 1
scripts/gw.py

@@ -16,6 +16,9 @@ from greaseweazle import version
 # 40MHz
 scp_freq = 40000000
 
+BAUD_CLEAR_COMMS    = 10000
+BAUD_NORMAL         = 9600
+
 CMD_GET_INFO        = 0
 CMD_SEEK            = 1
 CMD_SIDE            = 2
@@ -360,7 +363,8 @@ def _main(argv):
   
   global ser
   ser = serial.Serial(args.device)
-  ser.send_break()
+  ser.baudrate = BAUD_CLEAR_COMMS
+  ser.baudrate = BAUD_NORMAL
   ser.reset_input_buffer()
 
   global sample_freq

+ 2 - 2
src/floppy.c

@@ -839,7 +839,7 @@ bad_command:
     goto out;
 }
 
-static void floppy_configured(void)
+static void floppy_configure(void)
 {
     floppy_state = ST_command_wait;
     u_cons = u_prod = 0;
@@ -915,7 +915,7 @@ void floppy_process(void)
 
 const struct usb_class_ops usb_cdc_acm_ops = {
     .reset = floppy_reset,
-    .configure = floppy_configured
+    .configure = floppy_configure
 };
 
 /*

+ 8 - 0
src/usb/cdc_acm.c

@@ -56,6 +56,14 @@ bool_t cdc_acm_handle_class_request(void)
         struct line_coding *lc = (struct line_coding *)ep0.data;
         TRC("SET_LINE_CODING: ");
         dump_line_coding(lc);
+        if (line_coding.baud != lc->baud) {
+            switch (lc->baud) {
+            case BAUD_CLEAR_COMMS:
+                usb_cdc_acm_ops.configure();
+                printk("Comms Line Cleared\n");
+                break;
+            }
+        }
         line_coding = *lc;
         break;
     }