Skip to content

Commit 300e850

Browse files
zeldinzougloub
authored andcommitted
fx2lafw: Support 24 and 32 channel mode
1 parent 4f43f4d commit 300e850

File tree

3 files changed

+31
-10
lines changed

3 files changed

+31
-10
lines changed

src/hardware/fx2lafw/api.c

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ static const struct fx2lafw_profile supported_fx2[] = {
117117
*/
118118
{ 0x04b4, 0x00f3, "Cypress", "SuperSpeed Explorer Kit", NULL,
119119
"fx3lafw-cypress-fx3.fw",
120-
DEV_CAPS_FX3 | DEV_CAPS_16BIT, NULL, NULL },
120+
DEV_CAPS_FX3 | DEV_CAPS_32BIT, NULL, NULL },
121121

122122
ALL_ZERO
123123
};
@@ -309,7 +309,10 @@ static GSList *scan(struct sr_dev_driver *di, GSList *options)
309309
sdi->connection_id = g_strdup(connection_id);
310310

311311
/* Fill in channellist according to this device's profile. */
312-
num_logic_channels = prof->dev_caps & DEV_CAPS_16BIT ? 16 : 8;
312+
num_logic_channels =
313+
prof->dev_caps & DEV_CAPS_32BIT ? 32 :
314+
(prof->dev_caps & DEV_CAPS_24BIT ? 24 :
315+
(prof->dev_caps & DEV_CAPS_16BIT ? 16 : 8));
313316
num_analog_channels = prof->dev_caps & DEV_CAPS_AX_ANALOG ? 1 : 0;
314317

315318
/* Logic channels, all in one channel group. */

src/hardware/fx2lafw/protocol.c

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ static int command_start_acquisition(const struct sr_dev_inst *sdi)
9090

9191
/* Compute the sample rate. */
9292
if (!(devc->profile->dev_caps & DEV_CAPS_FX3) &&
93-
devc->sample_wide && samplerate > MAX_16BIT_SAMPLE_RATE) {
93+
devc->unitsize > 1 && samplerate > MAX_16BIT_SAMPLE_RATE) {
9494
sr_err("Unable to sample at %" PRIu64 "Hz "
9595
"when collecting 16-bit samples.", samplerate);
9696
return SR_ERR;
@@ -131,8 +131,10 @@ static int command_start_acquisition(const struct sr_dev_inst *sdi)
131131
cmd.sample_delay_l = delay & 0xff;
132132

133133
/* Select the sampling width. */
134-
cmd.flags |= devc->sample_wide ? CMD_START_FLAGS_SAMPLE_16BIT :
135-
CMD_START_FLAGS_SAMPLE_8BIT;
134+
cmd.flags |= devc->unitsize == 4 ? CMD_START_FLAGS_SAMPLE_32BIT :
135+
(devc->unitsize == 3 ? CMD_START_FLAGS_SAMPLE_24BIT :
136+
(devc->unitsize == 2 ? CMD_START_FLAGS_SAMPLE_16BIT :
137+
CMD_START_FLAGS_SAMPLE_8BIT));
136138
/* Enable CTL2 clock. */
137139
cmd.flags |= (g_slist_length(devc->enabled_analog_channels) > 0) ? CMD_START_FLAGS_CLK_CTL2 : 0;
138140

@@ -270,7 +272,7 @@ SR_PRIV struct dev_context *fx2lafw_dev_new(void)
270272
devc->limit_frames = 1;
271273
devc->limit_samples = 0;
272274
devc->capture_ratio = 0;
273-
devc->sample_wide = FALSE;
275+
devc->unitsize = 1;
274276
devc->num_frames = 0;
275277
devc->stl = NULL;
276278

@@ -445,7 +447,7 @@ static void LIBUSB_CALL receive_transfer(struct libusb_transfer *transfer)
445447
libusb_error_name(transfer->status), transfer->actual_length);
446448

447449
/* Save incoming transfer before reusing the transfer struct. */
448-
unitsize = devc->sample_wide ? 2 : 1;
450+
unitsize = devc->unitsize;
449451
cur_sample_count = transfer->actual_length / unitsize;
450452
processed_samples = 0;
451453

@@ -486,6 +488,8 @@ static void LIBUSB_CALL receive_transfer(struct libusb_transfer *transfer)
486488
num_samples = cur_sample_count - processed_samples;
487489
if (devc->limit_samples && devc->sent_samples + num_samples > devc->limit_samples)
488490
num_samples = devc->limit_samples - devc->sent_samples;
491+
else
492+
num_samples = cur_sample_count;
489493

490494
devc->send_data_proc(sdi, (uint8_t *)transfer->buffer + processed_samples * unitsize,
491495
num_samples * unitsize, unitsize);
@@ -574,7 +578,9 @@ static int configure_channels(const struct sr_dev_inst *sdi)
574578
* Use wide sampling if either any of the LA channels 8..15 is enabled,
575579
* and/or at least one analog channel is enabled.
576580
*/
577-
devc->sample_wide = channel_mask > 0xff || num_analog > 0;
581+
devc->unitsize = channel_mask > 0xffffff? 4 :
582+
(channel_mask > 0xffff? 3 :
583+
(channel_mask > 0xff || num_analog > 0? 2 : 1));
578584

579585
return SR_OK;
580586
}
@@ -593,6 +599,12 @@ static size_t get_buffer_size(struct dev_context *devc)
593599
* a multiple of 1024.
594600
*/
595601
s = 10 * to_bytes_per_ms(devc->cur_samplerate);
602+
if (devc->unitsize == 3) {
603+
/* Make it a multiple of 3K, to make sure we have an
604+
integral number of samples */
605+
s += 3*1024;
606+
s -= s % (3*1024);
607+
}
596608
return (s + 1023) & ~1023;
597609
}
598610

src/hardware/fx2lafw/protocol.h

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,24 +52,30 @@
5252
#define DEV_CAPS_16BIT_POS 0
5353
#define DEV_CAPS_AX_ANALOG_POS 1
5454
#define DEV_CAPS_FX3_POS 2
55+
#define DEV_CAPS_24BIT_POS 3
56+
#define DEV_CAPS_32BIT_POS 4
5557

5658
#define DEV_CAPS_16BIT (1 << DEV_CAPS_16BIT_POS)
5759
#define DEV_CAPS_AX_ANALOG (1 << DEV_CAPS_AX_ANALOG_POS)
5860
#define DEV_CAPS_FX3 (1 << DEV_CAPS_FX3_POS)
61+
#define DEV_CAPS_24BIT (1 << DEV_CAPS_24BIT_POS)
62+
#define DEV_CAPS_32BIT (1 << DEV_CAPS_32BIT_POS)
5963

6064
/* Protocol commands */
6165
#define CMD_GET_FW_VERSION 0xb0
6266
#define CMD_START 0xb1
6367
#define CMD_GET_REVID_VERSION 0xb2
6468

69+
#define CMD_START_FLAGS_SUPERWIDE_POS 3
6570
#define CMD_START_FLAGS_CLK_CTL2_POS 4
6671
#define CMD_START_FLAGS_WIDE_POS 5
6772
#define CMD_START_FLAGS_CLK_SRC_POS 6
6873

6974
#define CMD_START_FLAGS_CLK_CTL2 (1 << CMD_START_FLAGS_CLK_CTL2_POS)
7075
#define CMD_START_FLAGS_SAMPLE_8BIT (0 << CMD_START_FLAGS_WIDE_POS)
7176
#define CMD_START_FLAGS_SAMPLE_16BIT (1 << CMD_START_FLAGS_WIDE_POS)
72-
77+
#define CMD_START_FLAGS_SAMPLE_24BIT ((0 << CMD_START_FLAGS_WIDE_POS) | (1 << CMD_START_FLAGS_SUPERWIDE_POS))
78+
#define CMD_START_FLAGS_SAMPLE_32BIT ((1 << CMD_START_FLAGS_WIDE_POS) | (1 << CMD_START_FLAGS_SUPERWIDE_POS))
7379
#define CMD_START_FLAGS_CLK_30MHZ (0 << CMD_START_FLAGS_CLK_SRC_POS)
7480
#define CMD_START_FLAGS_CLK_48MHZ (1 << CMD_START_FLAGS_CLK_SRC_POS)
7581
#define CMD_START_FLAGS_CLK_192MHZ (2 << CMD_START_FLAGS_CLK_SRC_POS)
@@ -111,7 +117,7 @@ struct dev_context {
111117

112118
gboolean trigger_fired;
113119
gboolean acq_aborted;
114-
gboolean sample_wide;
120+
uint8_t unitsize;
115121
struct soft_trigger_logic *stl;
116122

117123
uint64_t num_frames;

0 commit comments

Comments
 (0)