From a3483a839462bde24818c03fca27a270ad1a1cd4 Mon Sep 17 00:00:00 2001 From: Jared Boone Date: Fri, 2 Jun 2017 16:54:24 -0700 Subject: [PATCH] CPLD: Introduce Config type to clean up programming interface. Hide the details of how the CPLD data is stored. --- firmware/application/cpld_update.cpp | 8 ++++---- firmware/application/cpld_update.hpp | 6 ++---- firmware/application/portapack.cpp | 4 ++-- firmware/common/portapack_cpld_data.hpp | 13 +++++++++++++ 4 files changed, 21 insertions(+), 10 deletions(-) diff --git a/firmware/application/cpld_update.cpp b/firmware/application/cpld_update.cpp index 0a01d6d7..52b59b08 100644 --- a/firmware/application/cpld_update.cpp +++ b/firmware/application/cpld_update.cpp @@ -27,11 +27,11 @@ #include "jtag_target_gpio.hpp" #include "cpld_max5.hpp" #include "cpld_xilinx.hpp" +#include "portapack_cpld_data.hpp" #include "hackrf_cpld_data.hpp" bool cpld_update_if_necessary( - const std::array& block_0, - const std::array& block_1 + const portapack::cpld::Config config ) { jtag::GPIOTarget target { portapack::gpio_cpld_tck, @@ -65,11 +65,11 @@ bool cpld_update_if_necessary( } /* Verify CPLD contents against current bitstream. */ - auto ok = cpld.verify(block_0, block_1); + auto ok = cpld.verify(config.block_0, config.block_1); /* CPLD verifies incorrectly. Erase and program with current bitstream. */ if( !ok ) { - ok = cpld.program(block_0, block_1); + ok = cpld.program(config.block_0, config.block_1); } /* If programming OK, reset CPLD to user mode. Otherwise leave it in diff --git a/firmware/application/cpld_update.hpp b/firmware/application/cpld_update.hpp index ba39790d..38691e08 100644 --- a/firmware/application/cpld_update.hpp +++ b/firmware/application/cpld_update.hpp @@ -22,12 +22,10 @@ #ifndef __CPLD_UPDATE_H__ #define __CPLD_UPDATE_H__ -#include -#include +#include "portapack_cpld_data.hpp" bool cpld_update_if_necessary( - const std::array& block_0, - const std::array& block_1 + const portapack::cpld::Config config ); bool cpld_hackrf_load_sram(); diff --git a/firmware/application/portapack.cpp b/firmware/application/portapack.cpp index 8eac95cb..59254061 100644 --- a/firmware/application/portapack.cpp +++ b/firmware/application/portapack.cpp @@ -176,11 +176,11 @@ void init() { clock_manager.run_at_full_speed(); if( portapack_model() == PortaPackModel::R2_20170522 ) { - if( !cpld_update_if_necessary(portapack::cpld::rev_20170522::block_0, portapack::cpld::rev_20170522::block_1) ) { + if( !cpld_update_if_necessary(portapack::cpld::rev_20170522::config) ) { chSysHalt(); } } else { - if( !cpld_update_if_necessary(portapack::cpld::rev_20150901::block_0, portapack::cpld::rev_20150901::block_1) ) { + if( !cpld_update_if_necessary(portapack::cpld::rev_20150901::config) ) { chSysHalt(); } } diff --git a/firmware/common/portapack_cpld_data.hpp b/firmware/common/portapack_cpld_data.hpp index 8170bdee..71190b0b 100644 --- a/firmware/common/portapack_cpld_data.hpp +++ b/firmware/common/portapack_cpld_data.hpp @@ -28,14 +28,27 @@ namespace portapack { namespace cpld { +struct Config { + const std::array& block_0; + const std::array& block_1; +}; + namespace rev_20150901 { + extern const std::array block_0; extern const std::array block_1; + +const Config config { block_0, block_1 }; + } /* namespace rev_20150901 */ namespace rev_20170522 { + extern const std::array block_0; extern const std::array block_1; + +const Config config { block_0, block_1 }; + } /* namespace rev_20170522 */ } /* namespace cpld */