mirror of
https://github.com/portapack-mayhem/mayhem-firmware.git
synced 2026-08-10 18:03:40 +00:00
39424632bb
* Initial commit and pr for HackRF Pro (praline) arch-port to mayhem-firmware. Please see https://github.com/portapack-mayhem/mayhem-firmware/issues/2957. Added flash specifics for -DBOARD=PRALINE. This firmware only builds with toolchain v9.2.1 if hackrf codebase has -B arm in firmware/hackrf_usb/CMakeLists.txt. * Updated CMakeLists.txt per coordination with @HtoToo. For -DBOARD=PRALINE FLASH_MB_SIZE and FLASH_MB_LIMIT_SIZE are now 4. Removed praline specific variable for FLASH limits. * Updated chibios-portapack's board.cpp to support initialization of the HachRF-Pro (praline) FPGA. Added append_fpga_bitstream.py tool to ensure that praline_fgpa.bin bitstream can be appended to -DBOARD=PRALINE produced firmware. In order to ensure successful execution of append_fpga_bitstream.py to append the fpga bitstream we should expect that the bistsream will be located at 0x180000 in flash. This requires that FLASH_MB_LIMIT_SIZE must be 1.5, and FLASH_BYTES_LIMIT_SIZE must be 1535 * 1024. If we want to allow more or less space for the base firmware image sans the fpga bitstream the location of the bistream must be moved to a location other than 0x180000. * Updated location of praline_fpga.bin bitstream to 0x380000 to allow more room for firmware. Firmware now has 3.5MB, or 2MB more available than before as coordinated with @HTotoo. * Expanded #ifndef PRALINE to include og and r9 gpio and pin setup as coordinated with @HTotoo. * Added note for PRALINE FLASH_MB_LIMIT_SIZE and FLASH_BYTES_LIMIT_SIZE to explain why we are using the 3.5 and 3584 values respectively as coordinated with @HTotoo. * Next round of modifications derived heavily, if not entirely from work done by @banandana at https://github.com/Banandana/mayhem-firmware. This commit should power on the HackRF Pro (praline) display, power on the fpga, and enable gpio, and provide debug utilties. There is still a lot of work to be done to fully enable the new praline board with this build and firmware architectural porting effort. However, hackrf-one boards do not seem to be adversely impacted by the #ifdef PRALINE statements, and CMakeLists updates, as far as I have been able to test. * Ran format-code.sh. Updates for this commit are only due to formatting. Tested builds and they seem to work as exptected. * Addressed fixes in firmware/application and firmware/baseband. Stream now flows to capture and looking glass. Issues were related to thread management. Issues were originally addressed by @banandana. * Ran format-code.sh to allow for consistency with autoamted clang checks. * Update hackrf ref repo to mayhem-portapack-hackrf next from https://github.com/portapack-mayhem/hackrf * Addressed format edits necessary to pass clang-format check. * Starting addressing Si5351 Clocks for radio sampling. These updates correctly set the Si5351 clock at start up. There appears to be an issue during runtime when testing with RX Test Init, Capture and Looking glass. * Updated clock_manager.cpp to restore correct function introduced by @banandana when testing with Rx Test Init. * Switched to using decimation for setting the sample rate without changing the Si5351 clock. This assumes that for the praline board Si5351 CLK0 runs at fixed 8 MHz (constant) and the FPGA decimates to get the desired sample rate. For example, for a 1 MHz sample rate -> Si5351 outputs 8 MHz, FPGA decimates by 8. There is still more work needed here, and potential verification that this is the correct way to operate with this new archteitecture. * After deliberating on hackrf_usb hackrf_core.c and radio.c, and reviewing firmware/application/hw/si5351.cpp the original approach of using the aproach detailed in hackrf_core.c sample_rate_frac_set() lines 580-582, via the implementation in firmware/application/hw/si5351.cpp seems like the best place to continue testing efforts. * Tested at ~2.4GHz (2.3 - 2.5) with lookgin glass and was able to receive signals. Added a Signal Path debug app to test gains, and readio mode (receive/transmit). * Added two debug apps for the RFFC507x. Status View and Tuning View. This helped debug some of the potential issues with tuning. * update submodule * format code * Small touch up merging latest next and ensuring build for HackRF One. * Reverted edits to re: firmware/baseband/sd_over_usb/scsi.c and firmware/application/portapack.cpp. Source now builds, had to pull latest hackrf submodule. * Skipped detect hardware for praline board to avoid backscreen in HackRF Pro praline board. --------- Co-authored-by: gullradriel <gullradriel@users.noreply.github.com>
541 lines
17 KiB
C++
541 lines
17 KiB
C++
/*
|
|
* Copyright (C) 2014 Jared Boone, ShareBrained Technology, Inc.
|
|
*
|
|
* This file is part of PortaPack.
|
|
*
|
|
* This program is free software; you can redistribute it and/or modify
|
|
* it under the terms of the GNU General Public License as published by
|
|
* the Free Software Foundation; either version 2, or (at your option)
|
|
* any later version.
|
|
*
|
|
* This program is distributed in the hope that it will be useful,
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
* GNU General Public License for more details.
|
|
*
|
|
* You should have received a copy of the GNU General Public License
|
|
* along with this program; see the file COPYING. If not, write to
|
|
* the Free Software Foundation, Inc., 51 Franklin Street,
|
|
* Boston, MA 02110-1301, USA.
|
|
*/
|
|
|
|
#include "radio.hpp"
|
|
|
|
#include "rf_path.hpp"
|
|
|
|
#include "rffc507x.hpp"
|
|
#include "max2837.hpp"
|
|
#include "max2839.hpp"
|
|
|
|
#ifdef PRALINE
|
|
#include "max2831.hpp"
|
|
extern "C" {
|
|
#include "fpga_bridge.h"
|
|
}
|
|
#endif
|
|
|
|
#include "max5864.hpp"
|
|
#include "baseband_cpld.hpp"
|
|
|
|
#include "tuning.hpp"
|
|
|
|
#include "spi_arbiter.hpp"
|
|
|
|
#include "hackrf_hal.hpp"
|
|
#include "hackrf_gpio.hpp"
|
|
using namespace hackrf::one;
|
|
|
|
#include "cpld_update.hpp"
|
|
|
|
#include "portapack.hpp"
|
|
#include "portapack_persistent_memory.hpp"
|
|
|
|
#include "hal.h" // For LPC_SGPIO
|
|
|
|
#include <array>
|
|
|
|
/* Direct access to the radio. Setting values incorrectly can damage
|
|
* the device. Applications should use ReceiverModel or TransmitterModel
|
|
* instead of calling these functions directly. */
|
|
namespace radio {
|
|
|
|
static constexpr uint32_t ssp1_cpsr = 2;
|
|
|
|
static constexpr uint32_t ssp_scr(
|
|
const float pclk_f,
|
|
const uint32_t cpsr,
|
|
const float spi_f) {
|
|
return static_cast<uint8_t>(pclk_f / cpsr / spi_f - 1);
|
|
}
|
|
|
|
#ifdef PRALINE
|
|
/* MAX2831 uses 9-bit SPI transfers */
|
|
static constexpr SPIConfig ssp_config_max283x = {
|
|
.end_cb = NULL,
|
|
.ssport = gpio_max283x_select.port(),
|
|
.sspad = gpio_max283x_select.pad(),
|
|
.cr0 =
|
|
CR0_CLOCKRATE(ssp_scr(ssp1_pclk_f, ssp1_cpsr, max283x_spi_f) + 3) | CR0_FRFSPI | CR0_DSS9BIT,
|
|
.cpsr = ssp1_cpsr,
|
|
};
|
|
#else
|
|
/* MAX2837/MAX2839 use 16-bit SPI transfers */
|
|
static constexpr SPIConfig ssp_config_max283x = {
|
|
.end_cb = NULL,
|
|
.ssport = gpio_max283x_select.port(),
|
|
.sspad = gpio_max283x_select.pad(),
|
|
.cr0 =
|
|
CR0_CLOCKRATE(ssp_scr(ssp1_pclk_f, ssp1_cpsr, max283x_spi_f) + 3) | CR0_FRFSPI | CR0_DSS16BIT,
|
|
.cpsr = ssp1_cpsr,
|
|
};
|
|
#endif
|
|
|
|
static constexpr SPIConfig ssp_config_max5864 = {
|
|
.end_cb = NULL,
|
|
.ssport = gpio_max5864_select.port(),
|
|
.sspad = gpio_max5864_select.pad(),
|
|
.cr0 =
|
|
CR0_CLOCKRATE(ssp_scr(ssp1_pclk_f, ssp1_cpsr, max5864_spi_f)) | CR0_FRFSPI | CR0_DSS8BIT,
|
|
.cpsr = ssp1_cpsr,
|
|
};
|
|
|
|
static spi::arbiter::Arbiter ssp1_arbiter(portapack::ssp1);
|
|
|
|
static spi::arbiter::Target ssp1_target_max283x{
|
|
ssp1_arbiter,
|
|
ssp_config_max283x};
|
|
|
|
static spi::arbiter::Target ssp1_target_max5864{
|
|
ssp1_arbiter,
|
|
ssp_config_max5864};
|
|
|
|
static rf::path::Path rf_path;
|
|
rffc507x::RFFC507x first_if;
|
|
max283x::MAX283x* second_if;
|
|
max2837::MAX2837 second_if_max2837{ssp1_target_max283x};
|
|
max2839::MAX2839 second_if_max2839{ssp1_target_max283x};
|
|
#ifdef PRALINE
|
|
max2831::MAX2831 second_if_max2831{ssp1_target_max283x};
|
|
#endif
|
|
static max5864::MAX5864 baseband_codec{ssp1_target_max5864};
|
|
static baseband::CPLD baseband_cpld;
|
|
|
|
// load_sram() is called at boot in portapack.cpp, including verify CPLD part, so default direction is Receive
|
|
static rf::Direction direction{rf::Direction::Receive};
|
|
static bool baseband_invert = false;
|
|
static bool mixer_invert = false;
|
|
|
|
#ifdef PRALINE
|
|
static rf::Direction cached_direction = rf::Direction::Receive;
|
|
static bool cached_rf_amp = false;
|
|
static int_fast8_t cached_lna_gain = 0;
|
|
static int_fast8_t cached_vga_gain = 0;
|
|
#endif
|
|
|
|
void init() {
|
|
#ifdef PRALINE
|
|
/* PRALINE uses MAX2831 transceiver */
|
|
second_if = (max283x::MAX283x*)&second_if_max2831;
|
|
#else
|
|
if (hackrf_r9) {
|
|
gpio_r9_not_ant_pwr.write(1);
|
|
gpio_r9_not_ant_pwr.output();
|
|
}
|
|
second_if = hackrf_r9
|
|
? (max283x::MAX283x*)&second_if_max2839
|
|
: (max283x::MAX283x*)&second_if_max2837;
|
|
#endif
|
|
rf_path.init();
|
|
first_if.init();
|
|
second_if->init();
|
|
baseband_codec.init();
|
|
#ifndef PRALINE
|
|
/* HackRF One uses CPLD for Q inversion control.
|
|
* PRALINE uses FPGA and the pin (P2_3) is used for LCD_TE on H4M. */
|
|
baseband_cpld.init();
|
|
#else
|
|
/* Initialize FPGA registers - DC_BLOCK must be enabled for RX */
|
|
// debug::fpga::init();
|
|
fpga_debug_register_write(1, 0x01); // DC_BLOCK=1, QUARTER_SHIFT=0, Q_INVERT=0
|
|
fpga_debug_register_write(2, 0x00); // RX_DECIM=0 (no decimation for testing)
|
|
fpga_debug_register_write(3, 0x00); // TX_CTRL=0
|
|
fpga_debug_register_write(4, 0x00); // TX_INTRP=0
|
|
fpga_debug_register_write(5, 0x00); // TX_PSTEP=0
|
|
|
|
ssp1_arbiter.invalidate();
|
|
chThdSleepMilliseconds(10); // Let FPGA registers settle
|
|
#endif
|
|
}
|
|
|
|
void set_direction(const rf::Direction new_direction) {
|
|
/* TODO: Refactor all the various "Direction" enumerations into one. */
|
|
/* TODO: Only make changes if direction changes, but beware of clock enabling. */
|
|
|
|
// That below code line , was used to prevent RX interf ghosting when switching back to RX from any TX mode, but in recent code. it seems not necessary.
|
|
// Deleting that load_sram_no_verify() (or the original , load_sram() ), solves random TX swap I/Q problem in H1R1 , others OK- (and no side effects to all).
|
|
// hackrf::cpld::load_sram_no_verify(); // After commit "removed the use of the hackrf cpld eeprom #1732", in a H1R1, Mic App wrong SSB TX with random USB/LSB change.
|
|
|
|
#ifdef PRALINE
|
|
cached_direction = new_direction; // Track state for debug and potentially other purposes.
|
|
#endif
|
|
|
|
direction = new_direction;
|
|
|
|
if (hackrf_r9) {
|
|
/*
|
|
* HackRF One r9 inverts analog baseband only for RX. Previous hardware
|
|
* revisions inverted analog baseband for neither direction because of
|
|
* compensation in the CPLD. If we ever simplify the CPLD to handle RX
|
|
* and TX the same way, we will need to update this baseband_invert
|
|
* logic.
|
|
*/
|
|
baseband_invert = (direction == rf::Direction::Receive);
|
|
} else {
|
|
/*
|
|
* Analog baseband is inverted in RX but not TX. The RX inversion is
|
|
* corrected by the CPLD, but future hardware or CPLD changes may
|
|
* change this for either or both directions. For a given hardware+CPLD
|
|
* platform, baseband inversion is set here for RX and/or TX. Spectrum
|
|
* inversion resulting from the mixer is tracked separately according
|
|
* to the tuning configuration. We ask the CPLD to apply a correction
|
|
* for the total inversion.
|
|
*/
|
|
baseband_invert = false;
|
|
}
|
|
#ifndef PRALINE
|
|
baseband_cpld.set_invert(mixer_invert ^ baseband_invert);
|
|
#else
|
|
// Praline: Control Q inversion via FPGA register
|
|
// Assuming register 1 bit 1 controls Q inversion
|
|
uint8_t ctrl_reg = 0x01; // DC_BLOCK enabled
|
|
if (mixer_invert ^ baseband_invert) {
|
|
ctrl_reg |= 0x02; // Set Q_INVERT bit
|
|
}
|
|
fpga_debug_register_write(1, ctrl_reg);
|
|
ssp1_arbiter.invalidate();
|
|
#endif
|
|
|
|
second_if->set_mode((direction == rf::Direction::Transmit) ? max283x::Mode::Transmit : max283x::Mode::Receive);
|
|
rf_path.set_direction(direction);
|
|
|
|
baseband_codec.set_mode((direction == rf::Direction::Transmit) ? max5864::Mode::Transmit : max5864::Mode::Receive);
|
|
|
|
if (direction == rf::Direction::Receive)
|
|
led_rx.on();
|
|
else
|
|
led_tx.on();
|
|
|
|
// #ifdef PRALINE
|
|
// Try with Q inversion OFF
|
|
// fpga_debug_register_write(1, 0x01); // DC_BLOCK=1, Q_INVERT=0
|
|
// ssp1_arbiter.invalidate();
|
|
|
|
// If no signals, try with Q inversion ON
|
|
// fpga_debug_register_write(1, 0x03); // DC_BLOCK=1, Q_INVERT=1
|
|
// ssp1_arbiter.invalidate();
|
|
// #endif
|
|
}
|
|
|
|
bool set_tuning_frequency(const rf::Frequency frequency) {
|
|
rf::Frequency final_frequency = frequency;
|
|
// if converter feature is enabled
|
|
if (portapack::persistent_memory::config_converter()) {
|
|
// downconvert
|
|
if (portapack::persistent_memory::config_updown_converter()) {
|
|
final_frequency = frequency - portapack::persistent_memory::config_converter_freq();
|
|
} else // upconvert
|
|
{
|
|
final_frequency = frequency + portapack::persistent_memory::config_converter_freq();
|
|
}
|
|
}
|
|
// apply frequency correction
|
|
if (direction == rf::Direction::Transmit) {
|
|
if (portapack::persistent_memory::config_freq_tx_correction_updown()) // tx freq correction down
|
|
final_frequency = final_frequency - portapack::persistent_memory::config_freq_tx_correction();
|
|
else // tx freq correction up
|
|
final_frequency = final_frequency + portapack::persistent_memory::config_freq_tx_correction();
|
|
} else {
|
|
if (portapack::persistent_memory::config_freq_rx_correction_updown()) // rx freq correction down
|
|
final_frequency = final_frequency - portapack::persistent_memory::config_freq_rx_correction();
|
|
else // rx freq correction up
|
|
final_frequency = final_frequency + portapack::persistent_memory::config_freq_rx_correction();
|
|
}
|
|
|
|
const auto tuning_config = tuning::config::create(final_frequency);
|
|
if (tuning_config.is_valid()) {
|
|
first_if.disable();
|
|
|
|
// Program first local oscillator frequency (if there is one) into RFFC507x
|
|
if (tuning_config.first_lo_frequency) {
|
|
first_if.set_frequency(tuning_config.first_lo_frequency);
|
|
first_if.enable();
|
|
}
|
|
|
|
// Program second local oscillator frequency into MAX283x
|
|
const auto result_second_if = second_if->set_frequency(tuning_config.second_lo_frequency);
|
|
|
|
rf_path.set_band(tuning_config.rf_path_band);
|
|
mixer_invert = tuning_config.mixer_invert;
|
|
#ifndef PRALINE
|
|
baseband_cpld.set_invert(mixer_invert ^ baseband_invert);
|
|
#endif
|
|
|
|
return result_second_if;
|
|
} else {
|
|
return false;
|
|
}
|
|
}
|
|
|
|
void set_rf_amp(const bool rf_amp) {
|
|
#ifdef PRALINE
|
|
cached_rf_amp = rf_amp; // Track state for debug and potentialy other purposes.
|
|
#endif
|
|
rf_path.set_rf_amp(rf_amp);
|
|
}
|
|
|
|
void set_lna_gain(const int_fast8_t db) {
|
|
#ifdef PRALINE
|
|
cached_lna_gain = db; // Track state for debug and potentially other purposes.
|
|
#endif
|
|
second_if->set_lna_gain(db);
|
|
}
|
|
|
|
void set_vga_gain(const int_fast8_t db) {
|
|
#ifdef PRALINE
|
|
cached_vga_gain = db; // Track state for debug and potentially other purposes.
|
|
#endif
|
|
second_if->set_vga_gain(db);
|
|
}
|
|
|
|
void set_tx_gain(const int_fast8_t db) {
|
|
second_if->set_tx_vga_gain(db);
|
|
}
|
|
|
|
void set_baseband_filter_bandwidth_rx(const uint32_t bandwidth_minimum) {
|
|
second_if->set_lpf_rf_bandwidth_rx(bandwidth_minimum);
|
|
}
|
|
|
|
void set_baseband_filter_bandwidth_tx(const uint32_t bandwidth_minimum) {
|
|
second_if->set_lpf_rf_bandwidth_tx(bandwidth_minimum);
|
|
}
|
|
|
|
void set_baseband_rate(const uint32_t rate) {
|
|
portapack::clock_manager.set_sampling_frequency(rate);
|
|
// TODO: actually set baseband too?
|
|
}
|
|
|
|
void set_antenna_bias(const bool on) {
|
|
/* Pull MOSFET gate low to turn on antenna bias. */
|
|
#ifdef PRALINE
|
|
// Praline: P2_12 = GPIO1[12], ANT_BIAS_EN_N (active LOW)
|
|
LPC_GPIO->CLR[1] = on ? (1 << 12) : 0;
|
|
LPC_GPIO->SET[1] = on ? 0 : (1 << 12);
|
|
#else
|
|
if (hackrf_r9) {
|
|
gpio_r9_not_ant_pwr.write(on ? 0 : 1);
|
|
} else {
|
|
first_if.set_gpo1(on ? 0 : 1);
|
|
}
|
|
#endif
|
|
}
|
|
|
|
void set_tx_max283x_iq_phase_calibration(const size_t v) {
|
|
second_if->set_tx_LO_iq_phase_calibration(v);
|
|
}
|
|
|
|
void set_rx_max283x_iq_phase_calibration(const size_t v) {
|
|
second_if->set_rx_LO_iq_phase_calibration(v);
|
|
}
|
|
|
|
/*void enable(Configuration configuration) {
|
|
configure(configuration);
|
|
}
|
|
|
|
void configure(Configuration configuration) {
|
|
set_tuning_frequency(configuration.tuning_frequency);
|
|
set_rf_amp(configuration.rf_amp);
|
|
set_lna_gain(configuration.lna_gain);
|
|
set_vga_gain(configuration.vga_gain);
|
|
set_baseband_rate(configuration.baseband_rate);
|
|
set_baseband_filter_bandwidth(configuration.baseband_filter_bandwidth);
|
|
set_direction(configuration.direction);
|
|
}*/
|
|
|
|
void disable() {
|
|
set_antenna_bias(false);
|
|
baseband_codec.set_mode(max5864::Mode::Shutdown);
|
|
second_if->set_mode(max2837::Mode::Standby);
|
|
first_if.disable();
|
|
set_rf_amp(false);
|
|
|
|
led_rx.off();
|
|
led_tx.off();
|
|
}
|
|
|
|
#ifdef PRALINE
|
|
void invalidate_spi_config() {
|
|
ssp1_arbiter.invalidate();
|
|
}
|
|
#endif
|
|
|
|
namespace debug {
|
|
|
|
#ifdef PRALINE
|
|
rf::Direction get_cached_direction() {
|
|
return cached_direction;
|
|
}
|
|
|
|
bool get_cached_rf_amp() {
|
|
return cached_rf_amp;
|
|
}
|
|
|
|
int_fast8_t get_cached_lna_gain() {
|
|
return cached_lna_gain;
|
|
}
|
|
|
|
int_fast8_t get_cached_vga_gain() {
|
|
return cached_vga_gain;
|
|
}
|
|
#endif
|
|
|
|
namespace first_if {
|
|
|
|
uint32_t register_read(const size_t register_number) {
|
|
return radio::first_if.read(register_number);
|
|
}
|
|
|
|
void register_write(const size_t register_number, uint32_t value) {
|
|
radio::first_if.write(register_number, value);
|
|
}
|
|
|
|
#ifdef PRALINE
|
|
extern "C" {
|
|
extern struct rffc507x_debug_t {
|
|
uint32_t requested_freq_mhz;
|
|
uint32_t calculated_vco_mhz;
|
|
uint32_t expected_n;
|
|
uint8_t expected_lodiv;
|
|
uint8_t expected_presc;
|
|
bool was_called;
|
|
uint32_t calc_lo_freq_mhz;
|
|
uint32_t calc_vco_inside_mhz;
|
|
uint8_t calc_lodiv_log2;
|
|
uint8_t calc_presc_log2;
|
|
uint64_t calc_n_q24;
|
|
} rffc507x_debug_info;
|
|
}
|
|
|
|
/*struct TuningInfo {
|
|
uint32_t requested_freq_mhz;
|
|
uint32_t expected_n;
|
|
uint8_t expected_lodiv;
|
|
uint8_t expected_presc;
|
|
bool was_called;
|
|
};*/
|
|
|
|
TuningInfo get_tuning_info() {
|
|
return {
|
|
rffc507x_debug_info.requested_freq_mhz,
|
|
rffc507x_debug_info.calculated_vco_mhz,
|
|
rffc507x_debug_info.expected_n,
|
|
rffc507x_debug_info.expected_lodiv,
|
|
rffc507x_debug_info.expected_presc,
|
|
rffc507x_debug_info.was_called,
|
|
rffc507x_debug_info.calc_lo_freq_mhz,
|
|
rffc507x_debug_info.calc_vco_inside_mhz,
|
|
rffc507x_debug_info.calc_lodiv_log2,
|
|
rffc507x_debug_info.calc_presc_log2,
|
|
rffc507x_debug_info.calc_n_q24,
|
|
};
|
|
}
|
|
#endif
|
|
|
|
} /* namespace first_if */
|
|
|
|
namespace second_if {
|
|
|
|
uint32_t register_read(const size_t register_number) {
|
|
return radio::second_if->read(register_number);
|
|
}
|
|
|
|
void register_write(const size_t register_number, uint32_t value) {
|
|
radio::second_if->write(register_number, value);
|
|
}
|
|
|
|
int8_t temp_sense() {
|
|
return radio::second_if->temp_sense();
|
|
}
|
|
|
|
} /* namespace second_if */
|
|
|
|
#ifdef PRALINE
|
|
namespace fpga {
|
|
|
|
/* Use fpga_bridge.c functions for FPGA register access.
|
|
* These properly switch SPI mode between iCE40 (Mode 3, 8-bit)
|
|
* and MAX2831 (Mode 0, 9-bit). After each access, we must
|
|
* invalidate the SPI arbiter's cached config since fpga_bridge.c
|
|
* modifies SSP1 registers directly. */
|
|
|
|
uint32_t register_read(const size_t register_number) {
|
|
uint32_t result = fpga_debug_register_read(static_cast<uint8_t>(register_number));
|
|
ssp1_arbiter.invalidate(); // Force arbiter to reconfigure on next transfer
|
|
return result;
|
|
}
|
|
|
|
void register_write(const size_t register_number, uint32_t value) {
|
|
fpga_debug_register_write(static_cast<uint8_t>(register_number), static_cast<uint8_t>(value));
|
|
ssp1_arbiter.invalidate(); // Force arbiter to reconfigure on next transfer
|
|
}
|
|
|
|
void init() {
|
|
// Initialize FPGA registers after bitstream load
|
|
// DC_BLOCK (bit 0) must be enabled for RX to work
|
|
fpga_debug_register_write(1, 0x01); // CTRL: DC_BLOCK=1
|
|
fpga_debug_register_write(2, 0x00); // RX_DECIM: no decimation
|
|
fpga_debug_register_write(3, 0x00); // TX_CTRL: NCO disabled
|
|
fpga_debug_register_write(4, 0x00); // TX_INTRP: no interpolation
|
|
fpga_debug_register_write(5, 0x00); // TX_PSTEP: zero phase step
|
|
ssp1_arbiter.invalidate(); // Force arbiter to reconfigure on next transfer
|
|
}
|
|
|
|
} /* namespace fpga */
|
|
#endif
|
|
|
|
namespace sgpio {
|
|
|
|
/* SGPIO register map for debug viewing
|
|
* We expose key registers for diagnosing data flow issues.
|
|
* Register numbers map to:
|
|
* 0: CTRL_ENABLE - Which slices are enabled
|
|
* 1: GPIO_INREG - GPIO input register (data pins state)
|
|
* 2: GPIO_OUTREG - GPIO output register (direction, disable, etc)
|
|
* 3: GPIO_OENREG - GPIO output enable register
|
|
* 4: STATUS_1 - Exchange interrupt status (slice A = bit 0)
|
|
* 5: REG_SS[0] - Shadow register slice A (current sample data)
|
|
*/
|
|
uint32_t register_read(const size_t register_number) {
|
|
switch (register_number) {
|
|
case 0:
|
|
return LPC_SGPIO->CTRL_ENABLE;
|
|
case 1:
|
|
return LPC_SGPIO->GPIO_INREG;
|
|
case 2:
|
|
return LPC_SGPIO->GPIO_OUTREG;
|
|
case 3:
|
|
return LPC_SGPIO->GPIO_OENREG;
|
|
case 4:
|
|
return LPC_SGPIO->STATUS_1;
|
|
case 5:
|
|
return LPC_SGPIO->REG_SS[0];
|
|
default:
|
|
return 0xFFFFFFFF;
|
|
}
|
|
}
|
|
|
|
} /* namespace sgpio */
|
|
|
|
} /* namespace debug */
|
|
|
|
} /* namespace radio */
|