Hi,
I wanted to use sigrok with the fx2lafw firmware on my Lcsoft mini board
with Cypress FX2 chip. I have encountered a problem with higher sampling
rates (>=12MHz). The device started streaming say in 1/10 cases when i
hit the "start" button. Lower speeds worked fine. I was disappointed...
I am using HP ProBook 430 with Ubuntu 16.04.
I have started digging how the libsigrok driver works with fx2lafw and
discovered the problem. The FX2 stops streaming data automatically when
the PC stops receiving it (via stopping sending IN requests over USB).
This is done on the FX2 side by detecting that the endpoint FIFO is
full. For high sample rates the FX2 FIFO fills up before the PC starts
to send IN requests which makes the FX2 terminate acquisition. The
libsigrok then gets a timeout error from libusb as the start command was
send and no data was received.
My solution to the problem is adding a delay on the FX2 side between
receiving the CMD_START command and triggering the GPIF interface. This
gives the PC enough time to start sending IN requests upon sending the
CMD_START command. I have implemented the delay in the fx2lafw code. The
delay is based on counting SOF packets (8 per millisecond for USB HS). I
have set the delay to 200 SOFs which is about 2.6ms. Works for me
flawlessly :)
I have also noticed a very crude implementation of LED control ;) So
i've added led.h file with LED control macros and a possibility to
define LED polarity (on the Lcsoft mini board the LED is active low).
Please find the patch file in the attachment. I'd like it to be merged
with the fxlafw.
Best regards
Maciej
>From 53de2a15ff68a7f045b437c7c885ef5d93be8fea Mon Sep 17 00:00:00 2001
From: Maciej Kurc <mkurc1...@gmail.com>
Date: Sun, 24 Dec 2017 21:55:36 +0100
Subject: [PATCH 1/3] Added a delay between receiving START command and actual
GPIF acquisition start.
---
fx2lafw.c | 17 ++++++++++++++++-
gpif-acquisition.c | 1 +
2 files changed, 17 insertions(+), 1 deletion(-)
diff --git a/fx2lafw.c b/fx2lafw.c
index 1949a7c..f7f0a7b 100644
--- a/fx2lafw.c
+++ b/fx2lafw.c
@@ -47,10 +47,14 @@
#include <fx2lafw.h>
#include <gpif-acquisition.h>
+#define START_DELAY 80 // Acquisition start delay in SOFs
+
/* ... */
volatile __bit got_sud;
BYTE vendor_command;
+volatile BYTE delay_sof_count = 0; // SOF counter
+
volatile WORD ledcounter = 1000;
extern __bit gpif_acquiring;
@@ -127,6 +131,7 @@ BOOL handle_vendorcommand(BYTE cmd)
/* Protocol implementation */
switch (cmd) {
case CMD_START:
+ delay_sof_count = START_DELAY;
vendor_command = cmd;
EP0BCL = 0;
return TRUE;
@@ -198,6 +203,11 @@ void sudav_isr(void) __interrupt SUDAV_ISR
void sof_isr(void) __interrupt SOF_ISR __using 1
{
+ // Decrease delay counter
+ if (delay_sof_count) {
+ delay_sof_count--;
+ }
+
CLEAR_SOF();
}
@@ -219,7 +229,7 @@ void timer2_isr(void) __interrupt TF2_ISR
if (gpif_acquiring) {
if (--ledcounter == 0) {
PA1 = !PA1;
- ledcounter = 1000;
+ ledcounter = 500;
}
} else {
PA1 = 1; /* LED on. */
@@ -284,6 +294,11 @@ void fx2lafw_poll(void)
break;
if (EP0BCL == sizeof(struct cmd_start_acquisition)) {
+
+ if (delay_sof_count) {
+ break;
+ }
+
gpif_acquisition_start(
(const struct cmd_start_acquisition *)EP0BUF);
}
diff --git a/gpif-acquisition.c b/gpif-acquisition.c
index 7d3dcb6..85ce432 100644
--- a/gpif-acquisition.c
+++ b/gpif-acquisition.c
@@ -246,6 +246,7 @@ bool gpif_acquisition_start(const struct cmd_start_acquisition *cmd)
/* Update the status. */
gpif_acquiring = TRUE;
+ PA1 = 0; // LED off
return true;
}
--
2.7.4
>From 66fbaddddead06f3b0b221e8f33fccd0ddd1024c Mon Sep 17 00:00:00 2001
From: Maciej Kurc <mkurc1...@gmail.com>
Date: Sun, 24 Dec 2017 22:21:34 +0100
Subject: [PATCH 2/3] Refactored LED control.
---
fx2lafw.c | 13 +++++++------
gpif-acquisition.c | 9 ++++++++-
led.h | 14 ++++++++++++++
3 files changed, 29 insertions(+), 7 deletions(-)
create mode 100644 led.h
diff --git a/fx2lafw.c b/fx2lafw.c
index f7f0a7b..fadd6c6 100644
--- a/fx2lafw.c
+++ b/fx2lafw.c
@@ -47,6 +47,8 @@
#include <fx2lafw.h>
#include <gpif-acquisition.h>
+#include "led.h"
+
#define START_DELAY 80 // Acquisition start delay in SOFs
/* ... */
@@ -228,11 +230,11 @@ void timer2_isr(void) __interrupt TF2_ISR
/* Blink LED during acquisition, keep it on otherwise. */
if (gpif_acquiring) {
if (--ledcounter == 0) {
- PA1 = !PA1;
+ led_toggle();
ledcounter = 500;
}
} else {
- PA1 = 1; /* LED on. */
+ led_on();
}
TF2 = 0;
}
@@ -258,10 +260,9 @@ void fx2lafw_init(void)
ENABLE_HISPEED();
ENABLE_USBRESET();
- /* PA1 (LED) is an output. */
- PORTACFG = 0;
- OEA = (1 << 1);
- PA1 = 1; /* LED on. */
+ /* Init LED */
+ led_initialize();
+ led_on();
/* Init timer2. */
RCAP2L = -500 & 0xff;
diff --git a/gpif-acquisition.c b/gpif-acquisition.c
index 85ce432..a5e6222 100644
--- a/gpif-acquisition.c
+++ b/gpif-acquisition.c
@@ -26,6 +26,8 @@
#include <fx2lafw.h>
#include <gpif-acquisition.h>
+#include "led.h"
+
__bit gpif_acquiring;
static void gpif_reset_waveforms(void)
@@ -246,7 +248,9 @@ bool gpif_acquisition_start(const struct cmd_start_acquisition *cmd)
/* Update the status. */
gpif_acquiring = TRUE;
- PA1 = 0; // LED off
+
+ // Turn off LED
+ led_off();
return true;
}
@@ -276,5 +280,8 @@ void gpif_poll(void)
SYNCDELAY();
gpif_acquiring = FALSE;
+
+ // Turn on LED
+ led_on();
}
}
diff --git a/led.h b/led.h
new file mode 100644
index 0000000..349019c
--- /dev/null
+++ b/led.h
@@ -0,0 +1,14 @@
+#ifndef LED_H
+#define LED_H
+
+// LED polarity. 1 - Active H, 0 - Active L
+#define LED_POLARITY 0
+
+// LED control macros
+#define led_initialize() {PORTACFG = 0; OEA = (1 << 1);}
+#define led_toggle() {PA1 ^= 1;}
+
+#define led_on() {PA1 = LED_POLARITY;}
+#define led_off() {PA1 = !LED_POLARITY;}
+
+#endif // LED_H
--
2.7.4
>From 869c29261a2b6bf92dd5d1f25c9480ba0f8a6ae9 Mon Sep 17 00:00:00 2001
From: Maciej Kurc <mkurc1...@gmail.com>
Date: Wed, 27 Dec 2017 15:44:02 +0100
Subject: [PATCH 3/3] Increased start delay to 2.6ms (200 SOFs)
---
fx2lafw.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/fx2lafw.c b/fx2lafw.c
index fadd6c6..60cc33b 100644
--- a/fx2lafw.c
+++ b/fx2lafw.c
@@ -49,7 +49,7 @@
#include "led.h"
-#define START_DELAY 80 // Acquisition start delay in SOFs
+#define START_DELAY 200 // Acquisition start delay in SOFs
/* ... */
volatile __bit got_sud;
--
2.7.4
------------------------------------------------------------------------------
Check out the vibrant tech community on one of the world's most
engaging tech sites, Slashdot.org! http://sdm.link/slashdot
_______________________________________________
sigrok-devel mailing list
sigrok-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/sigrok-devel