Skip to content

Commit

Permalink
Add statistics reporting in firmware. improve stability
Browse files Browse the repository at this point in the history
  • Loading branch information
TravisRo committed Jul 5, 2021
1 parent fd587e1 commit 866fe46
Show file tree
Hide file tree
Showing 3 changed files with 90 additions and 4 deletions.
57 changes: 54 additions & 3 deletions BmFW/CYPRESS_FX3/BMFW_IsoSourceSink/cyfxisosrcsink.c
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,15 @@ CyU3PEvent glIsoLpEvent; /* Event group used to signal the thread that the

static volatile uint8_t glBenchmarkMode = 0;

#ifdef BMFW_REPORT_STATISTICS
static volatile uint32_t glStatRxStartTickMS = 0;
static volatile uint64_t glStatRxByteCount = 0;
static volatile uint32_t glStatRxBPS = 0;
static volatile uint32_t glStatTxStartTickMS = 0;
static volatile uint64_t glStatTxByteCount = 0;
static volatile uint32_t glStatTxBPS = 0;
#endif

static volatile CyBool_t glIsApplnActive = CyFalse; /* Whether the loopback application is active or not. */
static volatile CyBool_t glIsDevConfigured = CyFalse; /* Whether the device configuration has been completed. */
static volatile uint32_t glDmaPktsReceived = 0; /* Number of OUT packets received. */
Expand Down Expand Up @@ -217,6 +226,19 @@ CyFxIsoSrcSinkDmaCallback (

if (type == CY_U3P_DMA_CB_PROD_EVENT)
{
#ifdef BMFW_REPORT_STATISTICS
if (glStatRxStartTickMS == 0)
{
glStatRxStartTickMS = CyU3PGetTime();
glStatRxByteCount = 0;
glStatRxBPS = 0;
}
else
{
glStatRxByteCount+=input->buffer_p.count;
glStatRxBPS = (uint32_t)((glStatRxByteCount*1000) / ((uint64_t)CyU3PGetTime() - (uint64_t)glStatRxStartTickMS));
}
#endif
glDmaPktsReceived++;
status = CyU3PDmaChannelDiscardBuffer (chHandle);
if (status == CY_U3P_SUCCESS)
Expand All @@ -227,8 +249,21 @@ CyFxIsoSrcSinkDmaCallback (
}
else if (type == CY_U3P_DMA_CB_CONS_EVENT)
{
glDmaPktsSent++;
status = CyU3PDmaChannelGetBuffer (chHandle, &buffer_p, 0);
glDmaPktsSent++;
status = CyU3PDmaChannelGetBuffer (chHandle, &buffer_p, 0);
#ifdef BMFW_REPORT_STATISTICS
if (glStatTxStartTickMS == 0)
{
glStatTxStartTickMS = CyU3PGetTime();
glStatTxByteCount = 0;
glStatTxBPS = 0;
}
else
{
glStatTxByteCount+=buffer_p.size;
glStatTxBPS = (uint32_t)((glStatTxByteCount*1000) / ((uint64_t)CyU3PGetTime() - (uint64_t)glStatTxStartTickMS));
}
#endif
if (status == CY_U3P_SUCCESS)
{
buffer_p.buffer[0] = 0;
Expand Down Expand Up @@ -446,6 +481,12 @@ CyFxIsoSrcSinkApplnStop (
CyFxAppErrorHandler (apiRetStatus);
}
glPacketCounter = 0;

#ifdef BMFW_REPORT_STATISTICS
glStatTxStartTickMS = 0;
glStatRxStartTickMS = 0;
#endif

CyU3PDebugPrint (8, "App Stopped\r\n");
}

Expand Down Expand Up @@ -812,8 +853,11 @@ IsoSrcSinkAppThread_Entry (

for (;;)
{

#ifdef BMFW_REPORT_STATISTICS
stat = CyU3PEventGet (&glIsoLpEvent, eventMask, CYU3P_EVENT_OR_CLEAR, &eventStat, 1000);
#else
stat = CyU3PEventGet (&glIsoLpEvent, eventMask, CYU3P_EVENT_OR_CLEAR, &eventStat, CYU3P_WAIT_FOREVER);
#endif
if (stat == CY_U3P_SUCCESS)
{
if (glResetDevice)
Expand All @@ -824,6 +868,13 @@ IsoSrcSinkAppThread_Entry (
CyU3PThreadSleep (1000);
}
}
#ifdef BMFW_REPORT_STATISTICS
else if (stat == TX_NO_EVENTS && (glStatTxStartTickMS || glStatRxStartTickMS))
{
CyU3PDebugPrint(1,"RX BPS=%u TX BPS=%u\r\n", glStatRxBPS, glStatTxBPS);
}
#endif

}
}

Expand Down
5 changes: 4 additions & 1 deletion BmFW/CYPRESS_FX3/BMFW_IsoSourceSink/cyfxisosrcsink.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,13 @@

#define BWFW_PID (0x00FD)

// when defined, transfer statistics are reported every 1 second.
#define BMFW_REPORT_STATISTICS

#define CY_FX_ISOSRCSINK_DMA_BUF_COUNT (3) /* Bulk loop channel buffer count */
#define CY_FX_ISOSRCSINK_DMA_TX_SIZE (0) /* DMA transfer size is set to infinite */
#define CY_FX_ISOSRCSINK_THREAD_STACK (0x1000) /* Bulk loop application thread stack size */
#define CY_FX_ISOSRCSINK_THREAD_PRIORITY (8) /* Bulk loop application thread priority */
#define CY_FX_ISOSRCSINK_THREAD_PRIORITY (1) /* Bulk loop application thread priority */
#define CY_FX_ISOSRCSINK_PATTERN (0xAA) /* 8-bit pattern to be loaded to the source buffers. */

/* Endpoint and socket definitions for the bulkloop application */
Expand Down
32 changes: 32 additions & 0 deletions BmFW/CYPRESS_FX3/Readme.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,37 @@
How to build and flash:
-------------------------------------------------------------------------------
1) install the cypress FX3 development kit:
https://www.cypress.com/documentation/software-and-drivers/ez-usb-fx3-software-development-kit

2) Import the sub-folders in this directory into your workspace:
File->Import->Existing Projects into Workspace

Firmware Projects:
-------------------------------------------------------------------------------
All of the BMFW firmware projects are slightly modified version of the Cypress
test firmware.

BMFW_BulkLoopAuto:
- Supports the kBench "Loop" test only
- Loops data from one bulk endpoint to another

BMFW_IsochLoopAuto:
- Supports the kBench "Loop" test only
- Loops data from one isochronous endpoint to another

BMFW_BulkSourceSink:
- Supports the kBench "Loop, Read, and Write" modes
- The IN and OUT endpoints are entirely independent from one another.
IE: When running the "Loop" test, data is not actually looped.
- Data received by the IN endpoint is dicarded
- Data send by the OUT endpoint follows a specific pattern. See the
xfer-iso example documentation for more information.

BMFW_IsoSourceSink:
- Supports the kBench "Loop, Read, and Write" modes
- The IN and OUT endpoints are entirely independent from one another.
IE: When running the "Loop" test, data is not actually looped.
- Data received by the IN endpoint is dicarded
- Data send by the OUT endpoint follows a specific pattern. See the
xfer-iso example documentation for more information.

0 comments on commit 866fe46

Please sign in to comment.