379 Commits

Author SHA1 Message Date
Sojus07
c744337311 kekl
Some checks failed
Build / host (macos-latest) (push) Has been cancelled
Build / host (ubuntu-latest) (push) Has been cancelled
Build / host (windows-latest) (push) Has been cancelled
Build / firmware (HACKRF_ONE, macos-latest) (push) Has been cancelled
Build / firmware (HACKRF_ONE, ubuntu-latest) (push) Has been cancelled
Build / firmware (JAWBREAKER, macos-latest) (push) Has been cancelled
Build / firmware (JAWBREAKER, ubuntu-latest) (push) Has been cancelled
Build / firmware (RAD1O, macos-latest) (push) Has been cancelled
Build / firmware (RAD1O, ubuntu-latest) (push) Has been cancelled
Check code style / clang-format (map[check:firmware/common exclude:firmware/common/xapp058]) (push) Has been cancelled
Check code style / clang-format (map[check:firmware/hackrf_usb exclude:]) (push) Has been cancelled
Check code style / clang-format (map[check:host/hackrf-tools/src exclude:]) (push) Has been cancelled
Check code style / clang-format (map[check:host/libhackrf/src exclude:]) (push) Has been cancelled
2025-08-04 16:45:01 +02:00
Michael Ossmann
db884152dc Merge pull request #1513 from martinling/sgpio-doc-fix
Update SGPIO code documentation
2024-12-05 11:31:16 -05:00
Martin Ling
8b5a10c26c Update SGPIO code documentation. 2024-12-04 16:10:07 +00:00
Martin Ling
03551cb1fd Detect whether the M0 missed its deadline.
Counter-intuitively, this actually saves us two cycles because we unroll
the first iteration of the loop that spins on the interrupt flag, saving
a branch in the case that the flag is clear the first time.
2024-11-26 19:34:29 +00:00
Martin Ling
d21f01f7b4 In conditional branch table, list one destination per line, in order. 2024-11-26 19:04:42 +00:00
Martin Ling
72a0a01190 Revert "Reduce firmware USB transfer size from 16KB to 8KB."
This reverts commit fefa4f0e4592b8fb235d38e60fb5daea4974ff95.
2024-02-08 01:07:11 +00:00
Jonathan Suite
dab548bf29 Firmware updates to allow fine-grained control of biast from command line (#1314)
* Initial commit of hackrf_biast

* Cleaned up hackrf_biast

* Cleaned up usage info

* Include getopt.h for non-GNU systems

* Add support for overriding HackRF's default antenna power behavior in firmware.  Add support for specifying antenna power behavior in libhackrf.

* Moved bias tee config routines into user_config.c, cleaned up operation of hackrf_biast

* hackrf_biast now calls usage() and exits when invoked with no arguments

* Fixed minor documentation error in usage()

* minor syntax cleanup

* Add some documentation to the host API call

* Add proper declaration magic in hackrf.h to hackrf_set_user_bias_t_opts() to appease Visual Studio

* Documentation changes suggested by @martinling

* Moved bias t setting above switch statement, removed line that explicit turned bias t off when entering OFF mode

* Change hackrf_set_user_bias_t_opts() to use a friendly struct() instead of a bitmask.  User friendliness fixes to hackrf_biast options.  More clang-format appeasement.

* Removed support for integer mode args from hackrf_biast

* clang-format error fixes

* Tweaked position of comment for clang-format v14

* Reformat files with clang-format v14 instead of 16

* Remove internal numeric modes for bias T settings

Co-authored-by: Martin Ling <martin-github@earth.li>

* Fix documentation error in hackrf_biast.c

---------

Co-authored-by: Martin Ling <martin-github@earth.li>
2023-09-13 11:15:30 -04:00
Jacob Graves
189b5bf693 wrap clkin init in r9 board check (#1307) 2023-04-19 13:32:32 -04:00
Michael Ossmann
c19f85ef24 h1r9: use single SSP configuration for MAX283x
During r9 hardware development it was thought that the MAX2839 would use
a different GPIO pin for chip select, but it ended up being the same pin
as is used for MAX2837 on other hardware revisions.

This takes the MAX283x abstraction a bit further and fixes a bug with
hackrf_debug -m.
2023-01-08 08:21:27 -05:00
Mike Walters
bfe882a2fa h1r9: add MAX283x abstraction layer 2023-01-06 14:33:53 +00:00
Michael Ossmann
7a0aec00ef h1r9: fix usb_vendor_request_reset()
The bootloader is configured by pin straps on certain pins. We use some
of those for other purposes in r9 which causes the bootloader to
misbehave if the device is reset from software. By switching these pins
from outputs to inputs just before reset this problem is avoided.
2023-01-06 14:33:53 +00:00
Michael Ossmann
edd0a80812 h1r9: stop writing MAX2837 registers to MAX2839 2023-01-06 14:33:53 +00:00
Michael Ossmann
8aa79e9fe5 h1r9: use timer to detect external clock frequency 2023-01-06 12:45:46 +00:00
Mike Walters
060d9cbd8a Add firmware_info structure 2023-01-05 15:13:06 +00:00
Michael Ossmann
173612ac77 add --led option to hackrf_debug
and corresponding changes to libhackrf and firmware
2022-12-18 07:22:17 -05:00
Michael Ossmann
b106495042 Merge pull request #1235 from stevefalco/correct_register_definition
Make definition of "prev" consistent
2022-12-01 13:08:35 -05:00
Michael Ossmann
956492fb65 Merge pull request #1212 from schneider42/schneider/m0_reset
m0: reset M0 before starting it
2022-12-01 12:42:15 -05:00
Steven A. Falco
7dbf6d65b6 Make definition of "prev" consistent 2022-11-30 16:53:11 -05:00
schneider
d8d3dc039d m0: reset M0 before starting it
The rad1o was not starting the M0 when powered up by inserting a USB
cable. Interestingly the M0 does start when toggling the power switch.

Resetting the M0 before starting it in `main()` solves this issue.
2022-10-26 20:03:39 +02:00
Martin Ling
fefa4f0e45 Reduce firmware USB transfer size from 16KB to 8KB. 2022-10-22 13:47:06 +01:00
Michael Ossmann
06b9d7bee0 Clean up source code copyright notices. 2022-09-23 14:46:52 -04:00
Martin Ling
767db9f06c Don't start baseband streaming until TX buffer is first filled. 2022-09-20 11:13:25 +01:00
Martin Ling
44511c6c3b Move RFFC5072 setup before enabling RF power. 2022-09-19 13:02:29 +01:00
Martin Ling
6d57709000 Move delay after enabling RF power to rad1o-specific code. 2022-09-19 10:46:01 +01:00
Michael Ossmann
9329c5e44e Detect hardware platform at run-time.
Firmware now detects the hardware it is running on at startup and
refuses to run if it is compiled for the wrong platform. The board ID
returned by firmware to the host is now derived from run-time detection
rather than a compile-time value. A separate method to retrieve
compile-time supported platform is added.

On HackRF One, pin straps are checked to determine hardware revision.
This is informational to aid troubleshooting and does not affect any
function.
2022-09-14 07:08:47 -04:00
grvvy
5d7b203058 operacake: disable the usage of time mode when a portapack is installed 2022-09-01 14:03:18 -06:00
Martin Ling
ba148ee047 Add a simpler way to check CLKIN status. 2022-08-05 09:37:38 +01:00
Martin Ling
c0d13de598 Add braces to all control statements without them. 2022-08-03 23:46:46 +01:00
Martin Ling
c3fdf402d7 Reformat all code to new clang-format standard. 2022-08-03 23:46:44 +01:00
Martin Ling
dbcc46d221 Mark code sections to be left alone by clang-format. 2022-08-03 23:03:15 +01:00
Martin Ling
b4c828915a Use an empty block for empty while loops. 2022-08-03 23:03:15 +01:00
Martin Ling
445253be1e usb_descriptor: Realign descriptor comments. 2022-08-03 23:03:15 +01:00
Martin Ling
3418f6e249 Use a #define for USB transfer size. 2022-07-25 10:54:07 +01:00
Martin Ling
a943610cd4 Simpify TX loop in the same way as RX loop. 2022-07-25 10:44:15 +01:00
Martin Ling
0175c2e84e Simplify rx_mode loop and prevent it stalling.
On rad1o, the UI update could block this loop from running for long
enough that it could stall in a state where neither of the conditions
was met.

Fix this by removing the 'phase' variable, in favour of a counter
tracking the number of bytes that have been scheduled for USB transfer.
Whenever there are enough bytes to schedule the next transfer, do so.

Meanwhile, the M0 count is prevented from wrapping around and clobbering
data not yet sent, because the M0 code monitors the m4_count variable
which is updated as each transfer completes.
2022-07-25 10:35:05 +01:00
Martin Ling
bc0fbc3184 Merge pull request #1072 from martinling/fix-stack-variables
Fix USB requests that were responding with data from the stack.
2022-06-13 23:03:20 +01:00
Veloman Yunkan
3157111d08 Bugfix in retuning rate
In sweep mode, frequency switching (retuning) must occur only
AFTER the requested number of samples has been received.
2022-04-13 18:36:12 +04:00
Martin Ling
c2509e7c4d Fix USB requests that were responding with data from the stack. 2022-03-20 13:51:13 +00:00
Martin Ling
ad3216435a Fix overlapping register allocations. 2022-02-28 23:02:34 +00:00
Martin Ling
1fe06b425a Rename m0_state.{c,h} to usb_api_m0_state.{c,h} 2022-02-13 17:53:34 +00:00
Martin Ling
f3633e285f Replace direct setting of M0 mode with a request/ack mechanism.
This change avoids various possible races in which an autonomous mode
change by the M0 might clobber a mode change made from the M4, as well
as related races on other state fields that can be written by the M4.

The previous mode field is replaced by two separate ones:

- active_mode, which is written only by the M0, and indicates the
  current operating mode.

- requested_mode, which is written by the M4 to request a change.
  This field includes both the requested mode, and a flag bit. The M4
  writes the field with the flag bit set, and must then wait for the
  M0 to signal completion of the request by clearing the flag bit.

Whilst the M4 is blocked waiting for the flag bit to be cleared, the
M0 can safely make all the required changes to the state that are
needed for the transition to the requested mode. Once the transition
is complete, the M0 clears the flag bit and the M4 continues execution.

Request handling is implemented in the idle loop. To handle requests,
mode-specific loops simply need to check the request flag and branch to
idle if it is set.

A request from the M4 to change modes will always require passing
through the idle loop, and is not subject to timing guarantees. Only
transitions made autonomously by the M0 have guaranteed timing
constraints.

The work previously done in reset_counts is now implemented as part of
the request handling, so the tx_start, rx_start and wait_start labels
are no longer required.

An extra two cycles are required in the TX shortfall path because we
must now load the active mode to check whether we are in TX_START.

Two cycles are saved in the normal TX path because updating the active
mode to TX_RUN can now be done without checking the previous value.
2022-02-13 17:53:34 +00:00
Martin Ling
137f2481e5 Make an error code available when a shortfall limit is hit.
Previously, finding the M0 in IDLE mode was ambiguous; it could indicate
either a normal outcome, or a shortfall limit having being hit.

To disambiguate, we add an error field to the M0 state. The errors
currently possible are an RX timeout or a TX timeout, both of which
can be obtained efficiently from the current operating mode due to
the values used.

This adds 3 cycles to both shortfall paths, in order to shift down
the mode to obtain the error code, and store it to the M0 state.
2022-02-13 17:53:34 +00:00
Martin Ling
8bd3745253 Add some additional commentary. 2022-02-13 17:53:34 +00:00
Martin Ling
9f79a16b26 Rewrite sweep mode using timed operations.
The previous implementation of sweep mode had the M0 continuing to
receive and buffer samples during retuning. To avoid using data affected
by retuning, the code discarded two 16K blocks of samples after
retuning, before transferring one 16K block to the host.

However, retuning has to be done with the USB IRQ masked. The M4 byte
count cannot be advanced by the bulk transfer completion callback whilst
retuning is ongoing. This makes an RX buffer overrun likely, and
overruns now stall the M0, causing sweep timing to become inconsistent.

It makes much more sense to stop the M0 receiving data during retuning.
Using scheduled M0 mode changes between the RX and WAIT modes, it's now
possible to do this whilst retaining consistent sweep timing. The
comment block added to the start of the `sleep_mode()` function explains
the new implementation.

The new scheme substantially reduces the timing constraints on the host
retrieving the data. Previously, the host had to retrieve each sample
block before the M0 overwrote it, which would occur midway through
retuning for the next sweep, with samples that were going to be
discarded anyway.

With the new scheme, buffer space is used efficiently. No data is
written to the buffer which will be discarded. The host does not need to
finish retrieving each 16K block until its buffer space is due to be
reused, which is not until two sweep steps later. A great deal more
jitter in the bulk transfer timing can therefore now be tolerated,
without affecting sweep timing.

If the host does delay the retrieval of a block enough that its buffer
space is about to be reused, the M0 now stalls. This in turn will stall
the M4 sweep loop, causing the sweep to be paused until there is enough
buffer space to continue. Previously, sweeping continued regardless, and
the host received corrupted data if it did not keep up.
2022-02-13 17:53:34 +00:00
Martin Ling
cca7320fe4 Add a wait mode for the M0.
In wait mode, the byte counter is advanced, but no SGPIO read/writes are
done. This mode is intended to be used for implementing timed operations.
2022-02-13 16:46:12 +00:00
Martin Ling
3618a5352f Add a counter threshold at which the M0 will change to a new mode.
This lays the groundwork for implementing timed operations (#86). The M0
can be configured to automatically change modes when its byte count
reaches a specific value.

Checking the counter against the threshold and dispatching to the next
mode is handled by a new `jump_next_mode` macro, which replaces the
unconditional branches back to the start of the TX and RX loops.

Making this change work requires some rearrangement of the code, such
that the destinations of all conditional branch instructions are within
reach. These branch instructions (`b[cond] label`) have a range of -256
to +254 bytes from the current program counter.

For this reason, the TX shortfall handling is moved earlier in the file,
and branches in the idle loop are restructured to use an unconditional
branch to rx_start, which is furthest away.

The additional code for switching modes adds 9 cycles to the normal RX
path, and 10 to the TX path (the difference is because the dispatch in
`jump_next_mode` is optimised for the longer RX path).
2022-02-13 16:46:12 +00:00
Martin Ling
7124b7192b Roll back shortfall stats if switched to idle in a shortfall.
During shutdown of TX or RX, the host may stop supplying or retrieving
sample data some time before a stop request causes the M0 to be set back
to idle mode.

This makes it common for a spurious shortfall to occur during shutdown,
giving the misleading impression that there has been a throughput
problem. In fact, the final shortfall is simply an artifact.

This commit detects when this happens, and excludes the spurious
shortfall from the stats.

To implement this, we back up the shortfall stats whenever a new
shortfall begins. If the new shortfall later turns out to be spurious,
as indicated by a transition to IDLE while it is ongoing, then we roll
back the stats to their previous values.

We actually only need to back up previous longest shortfall length. To
get a previous shortfall count, can simply to subtract one from the
current shortfall count.

This change adds four cycles to the two shortfall paths - a load and
store to back up the previous longest shortfall length.
2022-02-13 16:46:12 +00:00
Martin Ling
a5e1521535 Don't update buffer pointer until after checking for shortfall.
The buffer pointer is not needed in the shortfall paths. Moving this
update after the shortfall checks saves 3 cycles in each shortfall path.
2022-02-13 16:46:12 +00:00
Martin Ling
0e99419be2 Don't load M0 byte count from memory.
This count is only written by the M0, so there's no need to reload it
when the current value is already retained in a register.

Removing this load saves two cycles in all code paths.
2022-02-13 16:46:12 +00:00
Martin Ling
4e205994e3 Use separate loops for RX and TX modes.
Using our newly-defined macros, it's now straightforward to write
separate loops for RX and TX, with the idle loop dispatching to them
when a new mode setting is written by the M4.

This saves some cycles by reducing branches needed within each loop, and
makes it simpler to add new modes.

For macros which use internal labels, a name parameter is added. This
parameter is prefixed to the labels used, so that each mode's use of
that macro produces its own label names.

Similarly, where branches were taken in the handle_shortfall macro to
the "loop" label, these are replaced with the appropriate tx_loop or
rx_loop label.

The syntax `\name\()_suffix` is necessary to perform concatenation in
the GNU assembler.
2022-02-13 16:46:12 +00:00