]> Joshua Wise's Git repositories - fpgaboy.git/blobdiff - binwire.c
Add an interrupt ack, so that interrupts are cleared automatically. This fixes APOCAL...
[fpgaboy.git] / binwire.c
index ed6b98c90a7aac056b2e4807a679e022cbf4c286..101b5c10bf172d7d90d399f3d59fba7ee8872306 100644 (file)
--- a/binwire.c
+++ b/binwire.c
@@ -23,29 +23,33 @@ int waitchar(int timeout)
   return poll(&pfd, 1, timeout) == 1;
 }
 
   return poll(&pfd, 1, timeout) == 1;
 }
 
-void expect(char *s, int len)
+int expect(char *s, int len)
 {
   int i;
   char c;
   for (i=0; i < len; i++)
   {
 {
   int i;
   char c;
   for (i=0; i < len; i++)
   {
-    if (waitchar(100) == 0)
+    if (waitchar(1000) == 0)
     {
       fprintf(stderr, "Timeout reached in expect (expected %c)\n", s[i]);
     {
       fprintf(stderr, "Timeout reached in expect (expected %c)\n", s[i]);
-      return;
+      return 1;
     }
     while (read(0, &c, 1) == 0)
       fprintf(stderr, "Short read...\n");
     if (c != s[i])
     }
     while (read(0, &c, 1) == 0)
       fprintf(stderr, "Short read...\n");
     if (c != s[i])
+    {
       fprintf(stderr, "Expect failed: expected %d, got %d (pos %d)\n", s[i], c, i);
       fprintf(stderr, "Expect failed: expected %d, got %d (pos %d)\n", s[i], c, i);
+      return 1;
+    }
   }
   }
+  return 0;
 }
 
 void expect_no_chars()
 {
   int cs = 0;
   
 }
 
 void expect_no_chars()
 {
   int cs = 0;
   
-  while (waitchar(10) == 1)
+  while (waitchar(100) == 1)
   {
     char c;
     if (read(0, &c, 1) == 0)
   {
     char c;
     if (read(0, &c, 1) == 0)
@@ -55,8 +59,6 @@ void expect_no_chars()
   }
   if (cs)
     fprintf(stderr, "Expect no chars failed: got %d chars\n", cs);
   }
   if (cs)
     fprintf(stderr, "Expect no chars failed: got %d chars\n", cs);
-  
-  
 }
 
 void main(int argc, char **argv)
 }
 
 void main(int argc, char **argv)
@@ -64,6 +66,7 @@ void main(int argc, char **argv)
   unsigned char buf[259];
   int sz;
   int rfd;
   unsigned char buf[259];
   int sz;
   int rfd;
+  int tc = 0;
   
   if (argc < 2)
   {
   
   if (argc < 2)
   {
@@ -77,18 +80,38 @@ void main(int argc, char **argv)
     exit(1);
   }
   
     exit(1);
   }
   
-  dowrite("\x1B" "A\x00\x00\x00...", 8);
+  dowrite("\x1B" "A\x00\x00\x00", 5);
   fprintf(stderr, "Address sent\n");
   fprintf(stderr, "Address sent\n");
-  expect("A...", 4);
-  while ((sz = read(rfd, buf+3, 128)) > 0)
+  expect("A", 1);
+  expect_no_chars();
+  while ((sz = read(rfd, buf+3, 255)) > 0)
   {
   {
+    int rv;
+    char abuf[5];
     buf[0] = 0x1B;
     buf[1] = 'D';
     buf[2] = sz+1;
     buf[0] = 0x1B;
     buf[1] = 'D';
     buf[2] = sz+1;
+    abuf[0] = 0x1B;
+    abuf[1] = 'A';
+    abuf[2] = (tc >> 16) & 0xFF;
+    abuf[3] = (tc >> 8) & 0xFF;
+    abuf[4] = tc & 0xFF;
+    tc += sz;
+    retry:
+    dowrite(abuf, 5);
+    rv = expect("A", 1);
     dowrite(buf, sz + 3);
     dowrite(buf, sz + 3);
-    fprintf(stderr, "Data sent\n");
-    expect("D", 1);
+    fprintf(stderr, "Data sent (%d)\n", tc);
+    rv |= expect("D", 1);
     expect_no_chars();
     expect_no_chars();
+    if (rv)
+    {
+      printf("Failure to ack... retrying\n");
+      dowrite("...", 3);
+      rv = expect("...", 3);
+      expect_no_chars();
+      goto retry;
+    }
   }
   exit(0);
 }
\ No newline at end of file
   }
   exit(0);
 }
\ No newline at end of file
This page took 0.018478 seconds and 4 git commands to generate.