]> sigrok.org Git - sigrok-firmware-fx2lafw.git/commitdiff
Implemented sample rate control
authorJoel Holdsworth <redacted>
Sun, 4 Mar 2012 14:13:27 +0000 (14:13 +0000)
committerJoel Holdsworth <redacted>
Sun, 4 Mar 2012 14:13:27 +0000 (14:13 +0000)
fx2lafw.c
gpif-acquisition.c
include/command.h
include/gpif-acquisition.h

index 18d31f6265365429016fed7ed9b9f4cf74ed745f..574e09109b1e7bcc86ce16e6fa1b3619e63e5fb5 100644 (file)
--- a/fx2lafw.c
+++ b/fx2lafw.c
@@ -51,6 +51,7 @@
 
 /* ... */
 volatile bit got_sud;
+BYTE vendor_command;
 
 static void setup_endpoints(void)
 {
@@ -112,13 +113,12 @@ static void setup_endpoints(void)
 BOOL handle_vendorcommand(BYTE cmd)
 {
        /* Protocol implementation */
-
        switch (cmd) {
-       case CMD_GET_FW_VERSION:
-               /* TODO */
-               break;
        case CMD_START:
-               gpif_acquisition_start();
+               /* There is data to receive - arm EP0 */
+               EP0BCL = 0;
+       case CMD_GET_FW_VERSION:
+               vendor_command = cmd;
                return TRUE;
        default:
                /* Unimplemented command. */
@@ -209,6 +209,7 @@ void fx2lafw_init(void)
        REVCTL = bmNOAUTOARM | bmSKIPCOMMIT;
 
        got_sud = FALSE;
+       vendor_command = 0;
 
        /* Renumerate. */
        RENUMERATE_UNCOND();
@@ -239,4 +240,33 @@ void fx2lafw_run(void)
                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;
+               }
+       }
 }
index 44adc26ea846c9e28def27e1893bd38259fd53f4..65b44bf9c72da3cb4574d4cf23f130a2ce163f7f 100644 (file)
@@ -124,10 +124,13 @@ void gpif_init_la(void)
        gpif_init_flowstates();
 }
 
-void gpif_acquisition_start(void)
+void gpif_acquisition_start(const struct cmd_start_acquisition *cmd)
 {
        xdata volatile BYTE *pSTATE;
 
+       IFCONFIG = (IFCONFIG & ~bm3048MHZ) |
+               ((cmd->flags & CMD_START_FLAGS_CLK_48MHZ) ? bm3048MHZ : 0);
+
        /* GPIF terminology: DP = decision point, NDP = non-decision-point */
 
        /* Populate WAVEDATA
@@ -147,7 +150,7 @@ void gpif_acquisition_start(void)
 
        /* Populate S0 */
        pSTATE = &GPIF_WAVE_DATA;
-       pSTATE[0] = 0x01;
+       pSTATE[0] = cmd->sample_delay;
        pSTATE[8] = 0x02;
        pSTATE[16] = 0x00;
        pSTATE[24] = 0x00;
index a75cbde0acbf8574b22750a31509cfbafb58ce41..d238195d5041319078a85b6c28af13457673d86f 100644 (file)
  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301 USA
  */
 
+#include <stdint.h>
+
 /* Protocol commands */
 #define CMD_GET_FW_VERSION     0xb0
 #define CMD_START              0xb1
+
+#define CMD_START_FLAGS_CLK_SRC_POS    6
+
+#define CMD_START_FLAGS_CLK_30MHZ      (0 << CMD_START_FLAGS_CLK_SRC_POS)
+#define CMD_START_FLAGS_CLK_48MHZ      (1 << CMD_START_FLAGS_CLK_SRC_POS)
+
+struct cmd_start_acquisition
+{
+       uint8_t flags;
+       uint8_t sample_delay;
+};
index 6ccdc616b322781a7271f2d886e83d392028b37c..77cf8484b15f983e45103ac0aacac420ce957158 100644 (file)
@@ -18,6 +18,8 @@
  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301 USA
  */
 
+#include <command.h>
+
 void gpif_init_la(void);
 
-void gpif_acquisition_start(void);
+void gpif_acquisition_start(const struct cmd_start_acquisition *cmd);