Skip to content

Commit

Permalink
Cleanup command processing, and add extension flags
Browse files Browse the repository at this point in the history
  • Loading branch information
zeldin committed Apr 15, 2018
1 parent e53890a commit 93614d5
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 15 deletions.
29 changes: 29 additions & 0 deletions command.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
#define CMD_GET_FW_VERSION 0xb0
#define CMD_START 0xb1
#define CMD_GET_REVID_VERSION 0xb2

#define CMD_START_FLAGS_SUPERWIDE_POS 3
#define CMD_START_FLAGS_CLK_CTL2_POS 4
#define CMD_START_FLAGS_WIDE_POS 5
#define CMD_START_FLAGS_CLK_SRC_POS 6

#define CMD_START_FLAGS_CLK_CTL2 (1 << CMD_START_FLAGS_CLK_CTL2_POS)
#define CMD_START_FLAGS_SAMPLE_8BIT (0 << CMD_START_FLAGS_WIDE_POS)
#define CMD_START_FLAGS_SAMPLE_16BIT (1 << CMD_START_FLAGS_WIDE_POS)
#define CMD_START_FLAGS_SAMPLE_24BIT ((0 << CMD_START_FLAGS_WIDE_POS) | (1 << CMD_START_FLAGS_SUPERWIDE_POS))
#define CMD_START_FLAGS_SAMPLE_32BIT ((1 << CMD_START_FLAGS_WIDE_POS) | (1 << CMD_START_FLAGS_SUPERWIDE_POS))

#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)
#define CMD_START_FLAGS_CLK_192MHZ (2 << CMD_START_FLAGS_CLK_SRC_POS)

struct version_info {
uint8_t major;
uint8_t minor;
};

struct cmd_start_acquisition {
uint8_t flags;
uint8_t sample_delay_h;
uint8_t sample_delay_l;
};
33 changes: 18 additions & 15 deletions main.c
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,7 @@

#include "descriptors.h"
#include "acquisition.h"

#define CMD_GET_FW_VERSION 0xb0
#define CMD_START 0xb1
#define CMD_GET_REVID_VERSION 0xb2
#include "command.h"

#define CLOCK_DIVISOR_X2_FOR(f) ((SYS_CLK + (f)/4) / ((f)/2))

Expand All @@ -29,26 +26,31 @@ static void VendorCommand(uint8_t request_type, uint8_t request, uint16_t value,
if (request_type !=
(FX3_USB_REQTYPE_OUT | FX3_USB_REQTYPE_TYPE_VENDOR | FX3_USB_REQTYPE_TGT_DEVICE))
goto stall;
if (value != 0 || index != 0 || length != 3)
if (value != 0 || index != 0 || length != sizeof(struct cmd_start_acquisition))
goto stall;
Fx3UartTxString("CMD_START\n");
Fx3UsbUnstallEp0();
Fx3UsbDmaDataOut(0, DmaBuf, 3);
Fx3UsbDmaDataOut(0, DmaBuf, sizeof(struct cmd_start_acquisition));
Fx3CacheInvalidateDCacheEntry(DmaBuf);
volatile struct cmd_start_acquisition *cmd = (volatile struct cmd_start_acquisition *)DmaBuf;
{
char buf[64];
snprintf(buf, sizeof(buf), "flags=%02x, sample_delay_h=%02x, sample_delay_l=%02x\n",
(unsigned)DmaBuf[0], (unsigned)DmaBuf[1], (unsigned)DmaBuf[2]);
(unsigned)cmd->flags, (unsigned)cmd->sample_delay_h, (unsigned)cmd->sample_delay_l);
Fx3UartTxString(buf);
}

uint8_t flags = DmaBuf[0];
uint16_t sample_delay = (DmaBuf[1]<<8)|DmaBuf[2];
uint8_t flags = cmd->flags;
uint16_t sample_delay = (cmd->sample_delay_h<<8)|cmd->sample_delay_l;
uint8_t bits = 8;
if (flags & (1<<5))
if (flags & (1<<CMD_START_FLAGS_WIDE_POS))
bits = 16;
if (flags & (1<<CMD_START_FLAGS_SUPERWIDE_POS))
bits += 16;
uint16_t clock_divisor_x2;
if (flags & (1<<6))
if (flags & CMD_START_FLAGS_CLK_192MHZ)
clock_divisor_x2 = CLOCK_DIVISOR_X2_FOR(192000000); /* 192 MHz */
else if (flags & CMD_START_FLAGS_CLK_48MHZ)
clock_divisor_x2 = CLOCK_DIVISOR_X2_FOR(48000000); /* 48 MHz */
else
clock_divisor_x2 = CLOCK_DIVISOR_X2_FOR(30000000); /* 30 MHz */
Expand All @@ -60,14 +62,15 @@ static void VendorCommand(uint8_t request_type, uint8_t request, uint16_t value,
if (request_type !=
(FX3_USB_REQTYPE_IN | FX3_USB_REQTYPE_TYPE_VENDOR | FX3_USB_REQTYPE_TGT_DEVICE))
goto stall;
if (value != 0 || index != 0 || length != 2)
if (value != 0 || index != 0 || length != sizeof(struct version_info))
goto stall;
Fx3UartTxString("CMD_GET_FW_VERSION\n");
DmaBuf[0] = 1;
DmaBuf[1] = 3;
volatile struct version_info *vinfo = (volatile struct version_info *)DmaBuf;
vinfo->major = 1;
vinfo->minor = 3;
Fx3CacheCleanDCacheEntry(DmaBuf);
Fx3UsbUnstallEp0();
Fx3UsbDmaDataIn(0, DmaBuf, 2);
Fx3UsbDmaDataIn(0, DmaBuf, sizeof(struct version_info));
return;
case CMD_GET_REVID_VERSION:
if (request_type !=
Expand Down

0 comments on commit 93614d5

Please sign in to comment.