From: Joel Holdsworth Date: Sun, 4 Mar 2012 14:13:27 +0000 (+0000) Subject: Implemented sample rate control X-Git-Tag: sigrok-firmware-fx2lafw-0.1.0~54 X-Git-Url: https://sigrok.org/gitaction?a=commitdiff_plain;h=2846a114f69c29a64dc7e6ae9d12195f8c4c18ab;p=sigrok-firmware-fx2lafw.git Implemented sample rate control --- diff --git a/fx2lafw.c b/fx2lafw.c index 18d31f62..574e0910 100644 --- 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; + } + } } diff --git a/gpif-acquisition.c b/gpif-acquisition.c index 44adc26e..65b44bf9 100644 --- a/gpif-acquisition.c +++ b/gpif-acquisition.c @@ -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; diff --git a/include/command.h b/include/command.h index a75cbde0..d238195d 100644 --- a/include/command.h +++ b/include/command.h @@ -18,6 +18,19 @@ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */ +#include + /* 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; +}; diff --git a/include/gpif-acquisition.h b/include/gpif-acquisition.h index 6ccdc616..77cf8484 100644 --- a/include/gpif-acquisition.h +++ b/include/gpif-acquisition.h @@ -18,6 +18,8 @@ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */ +#include + void gpif_init_la(void); -void gpif_acquisition_start(void); +void gpif_acquisition_start(const struct cmd_start_acquisition *cmd);