Add USB requests and host support to set TX/RX sho...
by Martin Ling 3 years 10 months
Add USB requests and host support to set TX/RX shortfall limits.

This adds `-T` and `-R` options to `hackrf_debug`, which set the TX
underrun and RX overrun limits in bytes.
5abc39c5
hackrf_debug: allow parse_int() to handle 32-bit p...
by Martin Ling 3 years 10 months
hackrf_debug: allow parse_int() to handle 32-bit parameters.
2f79c03b
Add a shortfall length limit.
by Martin Ling 3 years 10 months
Add a shortfall length limit.

This limit allows implementing a timeout: if a TX underrun or RX overrun
continues for the specified number of bytes, the M0 will revert to idle.

A setting of zero disables the limit.

This change adds 5 cycles to the TX & RX shortfall paths, to check if a
limit is set and to check the shortfall length against the limit.
f0bc6eda
Keep track of longest shortfall.
by Martin Ling 3 years 10 months
Keep track of longest shortfall.

This adds six cycles to the TX and RX shortfall paths.
2c86f493
Keep count of number of shortfalls.
by Martin Ling 3 years 10 months
Keep count of number of shortfalls.

To enable this, we keep a count of the current shortfall length. Each
time an SGPIO read/write cannot be completed due to a shortfall, we
increase this length. Each time an SGPIO read/write is completed
successfully, we reset the shortfall length to zero.

When a shortfall occurs and the existing shortfall length is zero, this
indicates a new shortfall, and the shortfall count is incremented.

This change adds one cycle to the normal RX & TX paths, to zero the
shortfall count. To enable this to be done in a single cycle, we keep a
zero handy in a high register.

The extra accounting adds 10 cycles to the TX and RX shortfall paths,
plus an additional 3 cycles to the RX shortfall path since there are
now two branches involved: one to the shortfall handler, and another
back to the main loop.
a7bd1e3e
Move resetting of byte counts to the M0.
by Martin Ling 3 years 10 months
Move resetting of byte counts to the M0.

Previously, these counts were zeroed by the M4 when leaving the OFF
transceiver mode. Instead, do this on the M0 at the point where the M0
leaves IDLE mode.

This avoids a potential race in which the M4 zeroes the M0 count after
the M0 has already started incrementing it.
0f3069ee
Set M0 mode to IDLE when transceiver mode is OFF.
by Martin Ling 3 years 10 months
Set M0 mode to IDLE when transceiver mode is OFF.

At this point, streaming has been stopped, so there will be no further
SGPIO interrupts. However, the M0 will still be spinning on the interrupt
flag, waiting to proceed.

To ensure that the M0 actually reaches its idle loop, we set the SGPIO
interrupt flag once. The M0 will then finish spinning on the flag, clear
the flag, see the new mode setting, and jump to the idle loop.
3fd3c778
Add an idle mode for the M0.
by Martin Ling 3 years 10 months
Add an idle mode for the M0.

In the idle mode, the M0 simply waits for a different mode to be set.
No SGPIO access is done.

One extra cycle is added to both TX code paths, to check whether the
M0 should return to the idle loop based on the mode setting. The RX
paths are unaffected as the branch to RX is handled first.
32c725dd
Replace TX flag with a mode setting.
by Martin Ling 3 years 10 months
Replace TX flag with a mode setting.

This is to let us start adding new operatin modes for the M0.
5b50b2df
Check for sufficient bytes, or space in buffer, be...
by Martin Ling 3 years 10 months
Check for sufficient bytes, or space in buffer, before proceeding.

In TX, check if there are sufficient bytes in the buffer to write a
block to SGPIO. If not, write zeros to SGPIO instead.

In RX, check if there is sufficent space in the buffer to store a block
read from SGPIO. If not, do nothing, which discards the data.

In both of these shortfall cases, the M0 count is not incremented.

This ensures that in TX, old data is never repeated. The M0 will not
resume writing TX samples to SGPIO until the M4 count advances,
indicating new data being ready in the buffer. This fixes bug #180.

Similarly, in RX, old data is never overwritten. The M0 will not resume
writing RX samples to the buffer until the M4 count advances, indicating
new space being available in the buffer.
c0d0cd2a
Report a bug