2767 Commits

Author SHA1 Message Date
Martin Ling
837b5ee9c8 Use a lock to prevent transfers being restarted during cancellation.
Fixes bug #916.

Previously, there was a race which could lead to a transfer being left
active after cancel_transfers() completed. This would then cause the
next prepare_transfers() call to fail, because libusb_submit_transfer()
would return an error due to the transfer already being in use.

The sequence of events that could cause this was:

1. Main thread calls hackrf_stop_rx(), which calls cancel_transfers(),
   which iterates through the 4 transfers in use and cancels them one
   by one with libusb_cancel_transfer().

2. During this time, a transfer is completed. The transfer thread calls
   hackrf_libusb_transfer_callback(), which handles the data and then
   calls libusb_submit_transfer() to resubmit that transfer.

3. Now, cancel_transfers() and hackrf_stop_rx() are completed but one
   transfer is still active.

4. The next hackrf_start_rx() call fails, because prepare_transfers()
   tries to submit a transfer which is already in use.

To fix this, we add a lock which must be held to either cancel transfers
or restart them. This ensures that only one of these actions can happen
for a given transfer; it's no longer possible for a transfer to be
cancelled and then immediately restarted.
2022-02-03 06:44:19 +00:00
Martin Ling
308ddeca8a New block diagram (#1039) 2022-01-28 01:48:17 -05:00
gozu42
4d0ea285b1 keep clkout state over general clock reconfiguration 2022-01-26 18:36:09 +01:00
Mike Walters
8660e44575 Merge pull request #1018 from greatscottgadgets/oc-bugs
Fix Opera Cake bugs
2022-01-12 17:37:58 +00:00
Martin Ling
60cfd0fe74 Merge pull request #1022 from martinling/sgpio-cleanup
M0 SGPIO code cleanup & optimisation
2022-01-11 12:55:24 +00:00
schneider
8a013172b2 rad1o: apply Linux kernel style clang-format 2022-01-10 23:42:52 +01:00
schneider
7bf55dc983 rad1o: Don't update the UI during sweeps
Updating the UI during sweeps significantly increases the time needed to
complete a sweep. Instead simply show "SWEEP" on the display.
2022-01-10 23:26:19 +01:00
schneider
9404226c6a rad1o: UI code cleanup 2022-01-10 23:26:19 +01:00
Radoslav Gerganov
aec108be46 Add project mention for the APRS tracker (#1033)
APRS tracker which uses the HTML Geolocation API to retrieve the
device's position and WebUSB to communicate with the HackRF. The source
code is available at https://github.com/rgerganov/aprs-sdr
2022-01-10 15:10:35 -05:00
schneider
0c514839ca hack: add rad1o ui code 2022-01-09 23:27:00 +01:00
Martin Ling
98df8c23be Fix a typo. 2022-01-03 18:48:04 +00:00
Martin Ling
42a7c5ede9 Add a label at the end of the code to indicate the literal pool.
This makes objdump disassembly of the code a bit clearer, by separating
the constants from code following the last label.
2022-01-03 18:48:04 +00:00
Martin Ling
59be1fef5a Add pseudocode for all instructions.
This is intended to make the code possible to follow without knowledge
of the ARM instruction set.
2022-01-03 18:48:04 +00:00
Martin Ling
030898315d Remove unused constants.
Neither of these constants was used in the code.
2022-01-03 18:48:04 +00:00
Martin Ling
14065bb69d Initialise M0 state at startup.
This is not currently essential, since the current M4 code will not
trigger an SGPIO interrupt until the offset and tx fields are set.

In future though, we want to explicitly set up the M0 state here.
2022-01-03 18:48:04 +00:00
Martin Ling
5df28efb3f Assign names to registers used for temporary purposes.
This is just to improve readability; there is no change to the code.
2022-01-03 18:48:04 +00:00
Martin Ling
e531fb507b Use faster way to calculate buffer pointer.
One of the few instructions that can use the high registers (r8-r14) is
the add instruction, which can add any two registers, as long as one of
them is also used as the destination register.

By using this form of add , we can add buf_base (in a high register) to
the offset within the buffer (in a low register), to get the desired
pointer value (buf_ptr) which we want to access.

This saves one cycle by eliminating the need to move buf_base to a low
register first.
2022-01-03 18:48:04 +00:00
Martin Ling
c1c665d5b8 Stash which interrupt bits were set, and use them to clear.
The lsr instruction here shifts the value in r0 right by one bit,
putting the LSB into the carry flag.

By setting the destination register to r1, we can retain the original
unshifted value in r0, and later write this to the INT_CLEAR register in
order to clear all bits that were set.

This saves two cycles by avoiding the need to load an 0xFFFF value to
write to INT_CLEAR.
2022-01-03 18:48:04 +00:00
Martin Ling
bd7d0b9194 Correct a misleading comment.
The effect of the lsr instruction here is to shift the LSB of r0 into
the processor's carry flag. The subsequent bcc instruction ("branch if
carry clear") will then branch if this bit was zero.

The LSB corresponds to the exchange interrupt flag for slice A only. The
other interrupt flag bits are not checked here, contrary to the comment.
2022-01-03 18:48:04 +00:00
Martin Ling
f8ea1e8e56 Use stack pointer to hold base address of state structure.
Keeping the base address of this structure in a register allows us to
use offsets to load individual fields from it, without needing their
individual addresses.

However, the ldr instruction can only use immediate offsets relative to
the low registers (r0-r7), or the stack pointer (r13).

Low registers are in short supply and are needed for other instructions
which can only use r0-r7, so we use the stack pointer here.

It's safe to do this because we do not use the stack. There are no
function calls, interrupt handlers or push/pop instructions in the M0
code.

This change saves four cycles by eliminating loads of the addresses for
the offset & tx registers, plus a further two by eliminating the need to
stash one of these addresses in r8.
2022-01-03 18:48:04 +00:00
Martin Ling
2f26ebffd4 Keep buffer base & size mask in high registers.
The high registers (r8-r14) cannot be used directly by most of the
instructions in the Cortex-M0 instruction set.

One of the few instructions that can use them is mov, which can use
any pair of registers.

This allows saving two cycles, by replacing two loads (2 cycles each)
with moves (1 cycle each), after stashing the required values in high
registers at startup.
2022-01-03 18:48:04 +00:00
Martin Ling
8f43dc1be5 Use a register to hold base address of SGPIO interrupt registers.
This allows us to use ldr/str with an immediate offset to access the
SGPIO interrupt registers, rather than first having to load a register
with the specific address we want to access.

This change saves a total of 6 cycles, by eliminating two loads (2
cycles each), one of which could be executed twice.
2022-01-03 18:48:04 +00:00
Martin Ling
9206a8b752 Free up two registers by accessing SGPIO in two 16-byte chunks.
The current code does reads and writes in two chunks: one of
6 words, followed by one of 2.

Instead, use two chunks of 4 words each. This takes the same number of
total cycles, but frees up two registers for other uses.

Note that we can't do things in one chunk, because we'd need eight
registers to hold the data, plus a ninth to hold the buffer pointer. The
ldm/stm instructions can only use the eight low registers, r0-r7.

So we have to use two chunks, and the most register-efficient way to do
that is to use two equal chunks.
2022-01-03 18:48:04 +00:00
Martin Ling
c6362381d1 Initialise register with a constant value before SGIO loop.
Previously this register was reloaded with the same value during each loop.
Initialising it once, outside the loop, saves two cycles.

Note the separation of the loop start ("loop") from the entry point ("main").
Code between these labels will be run once, at startup.
2022-01-03 18:48:04 +00:00
Martin Ling
f61a03dead Assign names to registers which are used for a single purpose.
This is just to improve readability; there is no change to the code.
2022-01-03 18:48:04 +00:00
Martin Ling
dc0f8f48c5 Use defines for offsets into SGPIO shadow registers.
This is just to make the SGPIO code less cryptic, and to place
the explanation of the offsets closer to where they are defined.
2022-01-03 18:48:04 +00:00
Martin Ling
5b2a390728 Move M0 offset and tx variables into a state struct.
These variables are already placed together; this commit just groups
them into a struct and declares this in a new header.

This commit should not result in any change to the firmware binary.
Only the names of symbols are changed.
2022-01-03 18:47:58 +00:00
Martin Ling
39c6f3385e Remove usb_bulk_buffer.c containing unused variable definition.
This removes the definition of the offset variable,

volatile uint32_t usb_bulk_buffer_offset = 0;

which is actually superfluous. This variable, along with its neighbour
usb_bulk_buffer_tx, is placed explicitly by the linker script. Its type
is defined by the declaration in usb_bulk_buffer.h.

There is no need to define it here, and doing so gives the misleading
impression that its initial value can be changed by modifying this line!

The initialization to zero never actually takes effect, because the
variable is not placed in the .data or .bss sections which are
initialised by the startup code.

The offset and tx variables are both set in set_transceiver_mode
before SGPIO streaming is started, so the M0 code does not use
them uninitialised.
2022-01-03 18:47:33 +00:00
Martin Ling
3d9802260e Document purpose and timing of existing M0 code.
This commit does not modify the code; it only updates comments.
2022-01-03 18:47:24 +00:00
straithe
4da1792792 Add doc files for reproducibility 2021-12-29 17:57:02 -05:00
Michael Ossmann
bf84a3a9ba Merge pull request #1025 from straithe/updateDocs
Update docs
2021-12-29 15:18:11 -07:00
Michael Ossmann
471defd545 avoid incorrect syntax highlighting
also remove spaces before '::'s
2021-12-29 15:09:40 -07:00
straithe
4002fb2f8b Update docs 2021-12-28 18:27:01 -05:00
Ievgen Glinchuk
0002e2d391 Fix double hyphen (--) rendered as en dash (#1023) 2021-12-28 17:36:21 -05:00
Mike Walters
4df805c85f Merge pull request #1015 from greatscottgadgets/subdirectory-build-actions
add subdirectory builds to GitHub Actions
2021-12-13 10:58:32 +00:00
Michael Ossmann
b1b11e6269 update Opera Cake documentation (#1017) 2021-12-12 17:06:53 -05:00
Michael Ossmann
8cd5d682b8 default to the last specified frequency range
This was supposed to be the default, but there was a bug that looked
past the last range.
2021-12-12 13:29:25 -07:00
Michael Ossmann
d0c0270b9c clear frequency ranges before adding new ones 2021-12-12 13:25:44 -07:00
Michael Ossmann
66de65e6b4 start Opera Cake frequency mode correctly
When switching to frequency mode or modifying the frequency ranges,
ensure that the Opera Cake is switched to the correct port on the very
next tuning.
2021-12-12 13:18:29 -07:00
Michael Ossmann
e25096b17a firmware: add operacake_activate_ports()
Fixes frequency mode which had been broken by operacake_set_ports() only
activating the selected ports when in manual mode (at my suggestion).
2021-12-12 11:56:57 -07:00
Michael Ossmann
083f502413 mirror Opera Cake port selection in frequency mode 2021-12-11 17:51:51 -07:00
Michael Ossmann
3b8c317800 hackrf_operacake: fix long options with arguments 2021-12-11 17:37:36 -07:00
Michael Ossmann
39c829e499 add subdirectory builds to GitHub Actions
Build in the libhackrf and hackrf-tools subdirectories in addtion to the
top host directory.
2021-12-08 18:10:38 -07:00
Michael Ossmann
d46c8e14d5 Merge pull request #1014 from greatscottgadgets/revert-664-cmake_cleanup
Revert "Cleanup of host software CMake build system"
2021-12-08 17:06:36 -07:00
Michael Ossmann
aa0485d4df Revert "Cleanup of host software CMake build system (#664)"
This reverts commit d60fb83320cea49fd20305f22838f948557f1b81.
2021-12-08 16:59:05 -07:00
Straithe
113a870c4d Create CODE_OF_CONDUCT.md (#1009) 2021-12-06 13:38:23 -05:00
Jamie Smith
d60fb83320 Cleanup of host software CMake build system (#664)
* Clean up the CMake build system and improve the FindFFTW3 module.

* Fixes for Linux build

* Include winsock.h to get struct timeval

* Couple more fixes for MSVC, also add new FindMath module

* Update host build README for new CMake changes (esp. Windows)

* Try to fix Travis OS X build error

* Add docs about pthread-win32

* Whoops, AppVeyor caught a bug in FindFFTW where the includes not being found weren't generating a fatal error.

* Travis rebuild bump

* One more fix: replace hardcoded include paths with a PATH_SUFFIX to standard include paths

* Invert Windows preprocessor flag so it's only needed when using a static build.  This preserves compatibility with the previous system.

* Fix copy-paste error

* Update cmake modules from amber-cmake upstream, incorporate TryLinkLibrary into FindUSB1

* Fix missing include
2021-12-03 14:11:04 -05:00
Martin Ling
e9dd7eb291 Merge pull request #1004 from gibbi/AG-FixRateChange
fix stream glitch on rate change
2021-12-02 16:34:41 +00:00
Andreas Gibhardt
fc8b3c18d6 fix stream glitch on rate change 2021-12-02 16:27:43 +01:00
Michael Ossmann
22267f3b8e Merge pull request #996 from straithe/updateDocumentation
Update docs
2021-11-19 20:05:41 -07:00