Commit graph

1,000 commits

Author SHA1 Message Date
Robert Ghilduta
d011a9d09d libbladeRF: fix error in formatting error message 2018-12-26 00:23:14 -08:00
Robert Ghilduta
1416d4918a libbladeRF: update FPGA flash type definitions 2018-12-26 00:21:14 -08:00
Rey Tucker
c0325b9dd8 host: libbladeRF: fix type issues in flash.c
Fixes Windows build warnings.
2018-12-21 17:21:52 -05:00
Rey Tucker
825d986b4e host: libbladeRF: add bladerf_get_fpga_bytes() call
This adds a bladerf_get_fpga_bytes() function, which returns the
expected length of the FPGA image.

This is a dynamic replacement for BLADERF_FLASH_BYTE_LEN_FPGA,
which has been removed.

In particular, this is used in spi_flash_write_fpga_bitstream() and
spi_flash_erase_fpga() to determine the number of blocks to erase
during FPGA flashing operations.

This fixes an issue where xA9 boards were not being adequately
erased before writing.
2018-12-21 01:28:17 -08:00
Brian Glod
55bbfb1537 host: Remove BLADERF_FLASH_EB_FPGA and BLADERF_FLASH_EB_LEN_FPGA
Macros no longer needed:
- Switched to using byte-unit functions.
- Perform any byte->EB calculations internally based on device's flash
  architecture.
2018-12-21 01:28:17 -08:00
Brian Glod
44534c0799 host: Remove BLADERF_FLASH_EB_FIRMWARE and BLADERF_FLASH_EB_LEN_FIRMWARE
Replaced these macros with appropriate calculations using
BLADERF_FLASH_ADDR_FIRMWARE and the page size held in the device's flash
architecture structure. Page size may change depending on the flash
used.
2018-12-21 01:28:17 -08:00
Brian Glod
ae9f8440a1 host: libbladeRF: Remove BLADERF_FLASH_PAGE_FPGA
Replaced this macro with an appropriate calculation using the
BLADERF_FLASH_ADDR_FPGA macro and the page size held in the device's
flash architecture structure. Page size may change depending on the
flash used.
2018-12-21 01:28:17 -08:00
Brian Glod
4caed4e280 host: libbladeRF: Remove BLADERF_FLASH_PAGE_FIRMWARE
Replaced the BLADERF_FLASH_PAGE_FIRMWARE macro with the appropriate
calculation using the page size held in the device's flash architecture
structure.
2018-12-21 01:28:17 -08:00
Brian Glod
048678df98 host: libbladeRF: API changes, BLADERF_FLASH_EB_SIZE usage
API change:
  - bladerf_image_write(): new parameter: bladeRF device handle
      Change is inspired by the pending removal of BLADERF_FLASH_EB_SIZE
      macro. This macro really shouldn't be exposed to the world, nor
      should it be constant as it may change depending on the flash
      used on the board.

API new function:
  - bladerf_erase_flash_bytes(): new function
      Similar to the existing bladerf_erase_flash() function, but
      handles the conversion from bytes to flash erase block pages
      internally. This function is recommended for new designs because
      the erase block size may change depending on the board. This
      function also checks for proper alignment along erase block
      boundaries.

General changes:
  Although the macro still exists (for now), all uses of
  BLADERF_FLASH_EB_SIZE have been replaced with equivalent
  dev->flash_arch->ebsize_bytes because the value may change depending
  on the flash used on the board.
2018-12-21 01:28:17 -08:00
Brian Glod
9292b6ebe9 host: Replace BLADERF_FLASH_PAGE_SIZE and BLADERF_FLASH_TO_PAGES()
The BLADERF_FLASH_PAGE_SIZE macro was replaced with a similar value from
the from the device's flash architecture
structure (e.g. dev->flash_arch->psize_bytes).

The BLADERF_FLASH_TO_PAGES() macro was replaced by using the new(er) API
functions bladerf_{read,write}_flash_bytes(). The conversion from bytes
to pages occurs in those functions, removing the need for the
macro. Going forward, the *_bytes() functions should be preferred
because the flash architecture may change.
2018-12-21 01:28:17 -08:00
Brian Glod
b0c1f750ea host: libbladeRF: API new bladerf_{read,write}_flash_bytes()
New API functions:
  - bladerf_read_flash_bytes()
      This function is nearly identical to the existing
      bladerf_read_flash() function, but takes the address and length in
      units of bytes instead of flash pages. The function performs the
      necessary conversions from bytes to pages internally based on the
      specific flash architecture in use.
  - bladerf_write_flash_bytes()
      Same as above, for writes.

New code is advised to use these byte-unit functions instead of the
older page-unit functions because the page size may not be guaranteed to
be 256 bytes in future bladeRF platforms.
2018-12-21 01:28:17 -08:00
Brian Glod
907994587d host: libbladeRF: Replace BLADERF_FLASH_NUM_EBS
The BLADERF_FLASH_NUM_EBS macro was replaced with data from the device's
flash architecture structure (e.g. dev->flash_arch->num_ebs).

Functions with new parameters include:

- spi_flash.c: check_eb_access() - bladeRF device handle
2018-12-21 01:28:17 -08:00
Brian Glod
bc06d86ea3 host: libbladeRF: Replace BLADERF_FLASH_NUM_PAGES
The BLADERF_FLASH_NUM_PAGES macro was replaced with data from the
device's flash architecture structure (e.g. dev->flash_arch->num_pages).

Functions with new parameters include:
  - spi_flash.c: check_page_access() - bladeRF device handle
2018-12-21 01:28:17 -08:00
Brian Glod
03edb51ee4 host: libbladeRF API changes, BLADERF_FLASH_TOTAL_SIZE usage
API changes:
  - bladerf_alloc_image(): new parameter - bladeRF device handle
  - bladerf_alloc_cal_image(): new parameter - bladeRF device handle

General changes:
  Although the macro still exists (for now), all uses of the
  BLADERF_FLASH_TOTAL_SIZE macro have been replaced with equivalent
  dev->flash_arch->tsize_bytes because the value may change depending on
  teh flash used on the board.

  During this process, some function prototypes were modified so the
  device handle could be passed in, thus allowing flash architecture
  data to be extracted.

    - calibration.c: dc_cal_tbl_image_load()
    - image.c: is_valid_addr_len()
2018-12-21 01:28:17 -08:00
Robert Ghilduta
99087acb6e firmware_common: add shared flash routines 2018-12-21 01:28:17 -08:00
Robert Ghilduta
d0f84f3fc5 flash: remove duplicate shared flash functionality 2018-12-21 01:28:17 -08:00
Robert Ghilduta
0e94a0aedb libbladeRF: board state should be initialized before rfic can be used 2018-12-21 01:28:17 -08:00
Rey Tucker
6bdec2e32b host: libbladeRF: check for null rfic ptr in bladerf2_close
Fixes segfault after flashing FPGA image
2018-12-21 01:28:17 -08:00
Rey Tucker
cdc05b150b host: libbladeRF: show percentage when doing flash ops
Calculate and display the progress percentage when performing
flash erase/read/write operations.
2018-12-21 01:28:17 -08:00
Rey Tucker
9e9d9126a7 host: bladerf2: formatting fix on prev commit
committed and pushed before running clang-format, oops
2018-12-21 01:28:17 -08:00
Rey Tucker
aefd8d3d3c host: bladerf2: move FPGA-tuning bug check ahead of env check
Permit overriding the fallback to host-based tuning by setting
the env variable.
2018-12-21 01:28:17 -08:00
Rey Tucker
2227d110ab Bump FPGA to v0.10.2
host: bladerf2: Disable FPGA tuning mode if using pre-v0.10.2
FPGA.
2018-12-17 20:36:16 -05:00
Rey Tucker
cea114f5bc host: bladerf2/rfic_fpga: fix windows build errors
_rfic_fpga_get_status_wqlen:
	C4267: 'return': conversion from 'size_t' to 'int'

_rfic_fpga_spinwait:
	C2065: 'useconds_t': undeclared identifier
	C2120: 'void' illegal with all types

_rfic_fpga_set_gain:
	C4244: conversion from 'float' to 'int'
2018-12-12 18:44:51 -05:00
Rey Tucker
ac7a017bd9 host: bladerf2: undo double-MUTEX workaround on bladerf_*_rfic_*_fir
After the RFIC control split, we now directly call the rfic
functions to get/set filters when changing the sample rate.
So, we can go back to MUTEXing the API functions.

This undos the changes in 9e8bd237bc

host: bladerf2: remove unneeded pre-declarations
2018-12-12 16:42:52 -05:00
Rey Tucker
ecc9acba8d host: bladerf2: clean up bladerf2_set_tuning_mode
log message levels are now more chill

generally restructure for some efficiency
2018-12-12 16:42:52 -05:00
Rey Tucker
7dab6748b8 host: bladerf2: add get_init_state controller fn 2018-12-12 16:42:52 -05:00
Rey Tucker
663b74420c host: nios_access: don't globally suppress TIMEOUT on response
In most cases, BLADERF_ERR_TIMEOUT should be reported to the user.
So, for the NIOS_PKT_16x64_TARGET_RFIC target, nios_access_quiet
can be used to suppress all the log_errors.
2018-12-12 16:42:52 -05:00
Rey Tucker
9a9eb9f56f host: bladerf2: reset RFIC on close after doing retunes
For expedience, quick retunes directly control the RFIC via SPI.
This works fine as it is, but it puts the RFIC into an unexpected
state, and a reset is needed.

This commit fully de-initializes the RFIC during bladerf_close, if
a bladerf_get_quick_tune is performed sometime during the session.
2018-12-12 16:42:52 -05:00
Rey Tucker
a0c98b4268 host: bladerf2: add FPGA RFIC control
Moves much of the low-level control etc into rfic_{fpga,host}.c

Implements the necessary plumbing to make FPGA RFIC control work,
while still supporting host-based RFIC control.

host: bladerf2: verify that FPGA supports RFIC control before using it

FPGA-based RFIC control is rather memory-heavy, so omitting it
from builds is possible, but the usual capabilities mechanism
won't detect this.

This will throw a couple annoying errors from nios_16x64_read
when checked, but they are ignorable.

host: bladerf2: split bladerf2_get_quick_tune into host/fpga control

also:
common.h: remove vestigial comments

host: bladerf2: support standby state for FPGA RFIC mode

this lets us ensure the RFIC is in a known state when we
call bladerf_close()

host: bladerf2: move rfic_fpga init stuff to FPGA
2018-12-12 16:42:52 -05:00
Rey Tucker
7722e152e0 host: libbladeRF/backend: implement RFIC control messaging 2018-12-12 16:42:52 -05:00
Rey Tucker
9588498576 host: libbladeRF: fpga 0.10.1 support 2018-12-12 16:42:52 -05:00
Rey Tucker
47ca015fd2 host: libbladeRF/board.h: redefine BLADERF_CAP_FPGA_TUNING
BLADERF_CAP_FPGA_TUNING was previously defined to be the same as
BLADERF_CAP_SCHEDULED_RETUNE, but these features are distinct on
the bladeRF 2.
2018-12-12 16:42:52 -05:00
Rey Tucker
f6aae6cbc7 host: libbladeRF: fix missing include in sync.h 2018-12-12 16:42:52 -05:00
Rey Tucker
9e8bd237bc host: bladerf2: fix double-mutexing in low-samplerate-mode
During the recent refactor, the RFIC FIR filter functions got
wrapped in a MUTEX_LOCK.  This is incompatible with their use
by bladerf2_set_sample_rate, which is called within a MUTEX_LOCK.
🤦‍♀️
2018-12-06 14:09:20 -05:00
Rey Tucker
8eade905b1 host: libbladeRF: bladerf2: cleanup sched retune fns, channel iterators
Fixes up new code introduced by scheduled retune support

Also updates a few places to use FOR_EACH_DIRECTION and
FOR_EACH_CHANNEL.
2018-11-26 18:03:45 -05:00
Rey Tucker
05f7fd571a host: refactoring bladerf2.c
General documentation cleanup, function name adjustments, merging of
redundant structures, etc.

fpga_common/ad936x_helpers:
    Contains wrappers for AD936x RFIC functionality.

fpga_common/bladerf2_common:
    Contains bladeRF2-specific helper functions and constants.

fpga_common/ad936x_params:
    Reformat (no more tabs, phew)

    Move ina219 shunt const to bladerf2_common

host/common/range:
    Move functions and macros for handling bladerf_range structs

../libbladeRF/include/bladeRF2.h:
    Explicitly index RX/TX FIR enums

    Update references to ad936x_params.c

../libbladeRF/src/board/bladerf2/common:
    New macros for boilerplate:
        - WITH_MUTEX: wrap around locked blocks
        - CHECK_STATUS: calls function, checks return code
        - CHECK_AD936X: calls function, checks return code, translates
          from AD936x to libbladeRF error codes
        - CHECK_*_LOCKED: above, but unlocks mutex before erroring
        - NULL_CHECK: checks a var for null

    Move helper functions into here

../libbladeRF/src/board/bladerf2/bladerf2.c:
    Use new macros

    Code style fixes

    Remove redundant code
2018-11-26 18:03:45 -05:00
Rey Tucker
1c09cad506 host: bladerf2: use higher-level fns for ad936x TX atten
ad9361_api.h already has good functions for handling TX
attenuation, so use those instead.
2018-11-26 18:03:45 -05:00
Rey Tucker
7939453551 host/fpga_common/thirdparty: move ad936x.h, params.c, config.h
Move these files into more common places, so they can be
used from the FPGA side of the world as well.
2018-11-26 18:03:45 -05:00
Brian Glod
7a83b2da8e host: libbladeRF/bladerf2: cancel scheduled retunes at device open/close
Clear out any scheduled retunes that may exist in the Nios during
bladerf2_open() and bladerf2_close(). This helps prevent unexpected
behavior if the device is (re)opened later.
2018-11-26 16:03:46 -05:00
Brian Glod
d140bbb787 host: libbladeRF/bladeRF2: implement bladerf2_get/set_tuning_mode()
Only valid mode is HOST, but the functions won't blindly return
UNSUPPORTED.
2018-11-26 16:03:46 -05:00
Brian Glod
0f5f09adf3 host: libbladeRF/bladeRF2: implement bladerf2_cancel_scheduled_retunes() 2018-11-26 16:03:46 -05:00
Brian Glod
274d08d4b0 host: libbladeRF/bladeRF2: implement bladerf2_schedule_retune()
Adds schedule retune functionality to bladeRF2.
2018-11-26 16:03:46 -05:00
Brian Glod
6516cfa8e9 host: libbladeRF/bladeRF2: handle quick tune profile numbering
Let libbladeRF handle the quick tune profile numbering for bladeRF2
devices. This makes it so that existing bladeRF1 applications using the
quick tune feature should "just work" with bladeRF2.
2018-11-26 16:03:46 -05:00
Brian Glod
37bd65d9c7 host: libbladeRF/bladeRF2: improve bladerf2_get_quick_tune()
A few changes to the bladerf_quick_tune structure:
  - rename 'profile' to 'rffe_profile' for clarity
  - delete 'data[16]' not needed anymore and preserves ABI compatibility
  - add    'nios_profile' for indexing the profile stored in the BBP
  - add    'port' for storing the RFFE port settings
  - add    'spdt' for storing the external RF switch settings

Improvements to bladerf2_get_quick_tune():
  - Send rffe_fastlock_save packet to instruct Nios to save a copy of
    the RFFE fast lock profile to itself. This means the fast lock
    profile data (16 bytes) no longer needs to be transmitted to/from
    the Nios and the host machine (retune speedup).
  - Save the RFFE port setting to the quick tune structure so it may be
    sent down to the Nios when scheduling a retune.

Saving the 16-bytes of fast lock profile data to the host is no longer
necessary because it is stored on the Nios itself. This has two
additional benefits: quicker retunes (the profile data does not need to
be shuffled across USB), and it preserves ABI compatibility because the
size of the bladerf_quick_tune struct does not increase compared to
previous versions of libbladeRF.
2018-11-26 16:03:46 -05:00
Brian Glod
0658da0424 host: backend: add retune2 packet support
Add retune2 packet support and rffe_fastlock_save packet support to the
backend. These packets are used for bladeRF2 quick tunes.
2018-11-26 16:03:46 -05:00
Brian Glod
b80960643a hdl: nios: bump FPGA version to v0.10.0
Version increase primarily reflects the new quick tune feature for
bladeRF2 devices.
2018-11-26 16:03:46 -05:00
Brian Glod
a8e3e67568 host: libbladeRF/bladeRF2: implement bladerf2_get_quick_tune()
Update bladerf_quick_tune structure for bladeRF2 data. It now contains:
- profile (profile number, integer)
- data    (profile data, 16 bytes)

Fill in the bladerf2_get_quick_tune() function. The bladeRF2's RFIC uses
the concept of fast lock profiles, of which there are 8 for TX and 8 for
RX. These profiles store the VCO information needed to quickly change
frequencies. To use more than 8 profiles, the profiles may be stored
off-chip, which is what we're doing here.

1. It is assumed the RFIC has been tuned to a particular frequency.
2. The profile is created using ad9361_fastlock_store().
3. The profile is read back and stored in host memory using
   ad9361_fastlock_save().
2018-11-26 16:03:46 -05:00
Rey Tucker
90c07051e6 host: bladerf2: fix overeager FIR filter setting in set_sample_rate
If we've already done the FIR filter change for low sample rates,
we don't need to do it again when changing to another low sample
rate.
2018-11-16 16:01:41 -05:00
Rey Tucker
c2d991b09e host: bladerf1: fix apportioning of overall gain
_apportion_gain did not pay heed to the step size of the gain
range, causing it to end up with invalid values for LNA and
RXVGA2.

We now ensure that the allocation mod <stepsize> is 0, so that
other, more flexible gain stages can be used to pick up the
remainder.
2018-11-16 14:34:31 -05:00
Rey Tucker
3211d25f4e libbladeRF: configfile.c: fixup biastee options
Rename configuration keys to "biastee_tx" and "biastee_rx"

Use str2bool for consistency

clang-format

Add documentation
2018-11-12 18:35:04 -05:00