]> sigrok.org Git - sigrok-firmware-fx2lafw.git/blobdiff - fx2lafw.c
Corrected EP2FIFOCFG setup
[sigrok-firmware-fx2lafw.git] / fx2lafw.c
index 8d891d61e30ff573243114c3fcabd84b6e7070c9..e6c79e41a7f7a6db9377376e969866ac699571c7 100644 (file)
--- a/fx2lafw.c
+++ b/fx2lafw.c
 #include <eputils.h>
 #include <gpif.h>
 
+#include <command.h>
 #include <fx2lafw.h>
 #include <gpif-acquisition.h>
 
-/* Protocol commands */
-#define CMD_START              0xb0
-#define CMD_STOP               0xb1
-#define CMD_GET_FW_VERSION     0xb2
-
 /* ... */
 volatile bit got_sud;
+BYTE vendor_command;
 
 static void setup_endpoints(void)
 {
@@ -93,13 +90,14 @@ static void setup_endpoints(void)
        /* EP2: Reset the FIFOs. */
        /* Note: RESETFIFO() gets the EP number WITHOUT bit 7 set/cleared. */
        RESETFIFO(0x02)
+
 #ifdef DEBUG
        /* Reset the FIFOs of EP6 when in debug mode. */
        RESETFIFO(0x06)
 #endif
 
        /* EP2: Enable AUTOIN mode. Set FIFO width to 8bits. */
-       EP2FIFOCFG = bmAUTOIN | ~bmWORDWIDE;
+       EP2FIFOCFG = bmAUTOIN;
        SYNCDELAY();
 
        /* EP2: Auto-commit 512 (0x200) byte packets (due to AUTOIN = 1). */
@@ -116,19 +114,13 @@ static void setup_endpoints(void)
 BOOL handle_vendorcommand(BYTE cmd)
 {
        /* Protocol implementation */
-
        switch (cmd) {
        case CMD_START:
-               gpif_acquisition_start();
-               return TRUE;
-       case CMD_STOP:
-               GPIFABORT = 0xff;
-               /* TODO */
-               return TRUE;
-               break;
+               /* There is data to receive - arm EP0 */
+               EP0BCL = 0;
        case CMD_GET_FW_VERSION:
-               /* TODO */
-               break;
+               vendor_command = cmd;
+               return TRUE;
        default:
                /* Unimplemented command. */
                break;
@@ -218,6 +210,7 @@ void fx2lafw_init(void)
        REVCTL = bmNOAUTOARM | bmSKIPCOMMIT;
 
        got_sud = FALSE;
+       vendor_command = 0;
 
        /* Renumerate. */
        RENUMERATE_UNCOND();
@@ -242,10 +235,39 @@ void fx2lafw_init(void)
        gpif_init_la();
 }
 
-void fx2lafw_run(void)
+void fx2lafw_poll(void)
 {
        if (got_sud) {
                handle_setupdata();
                got_sud = FALSE;
        }
+
+       if (vendor_command) {
+               switch (vendor_command) {
+               case CMD_GET_FW_VERSION:
+                       /* TODO */
+
+                       /* Acknowledge the vendor command. */
+                       vendor_command = 0;
+                       break;
+
+               case CMD_START:
+                       if((EP0CS & bmEPBUSY) != 0)
+                               break;
+
+                       if(EP0BCL == 2) {
+                               gpif_acquisition_start(
+                                       (const struct cmd_start_acquisition*)EP0BUF);
+                       }
+
+                       /* Acknowledge the vendor command. */
+                       vendor_command = 0;
+                       break;
+
+               default:
+                       /* Unimplemented command. */
+                       vendor_command = 0;
+                       break;
+               }
+       }
 }