diff --git a/firmware/application/portapack.cpp b/firmware/application/portapack.cpp index 6cc8556d..b993feab 100644 --- a/firmware/application/portapack.cpp +++ b/firmware/application/portapack.cpp @@ -182,11 +182,11 @@ void init() { clock_manager.set_reference_ppb(persistent_memory::correction_ppb()); clock_manager.run_at_full_speed(); - if( !cpld_update_if_necessary(portapack_cpld_config()) ) { + if( !portapack::cpld::update_if_necessary(portapack_cpld_config()) ) { chSysHalt(); } - if( !cpld_hackrf_load_sram() ) { + if( !hackrf::cpld::load_sram() ) { chSysHalt(); } @@ -217,7 +217,7 @@ void shutdown() { radio::disable(); audio::shutdown(); - cpld_hackrf_init_from_eeprom(); + hackrf::cpld::init_from_eeprom(); clock_manager.shutdown(); diff --git a/firmware/application/ui_setup.cpp b/firmware/application/ui_setup.cpp index 550af2dd..d0a8650a 100644 --- a/firmware/application/ui_setup.cpp +++ b/firmware/application/ui_setup.cpp @@ -182,7 +182,7 @@ AboutView::AboutView(NavigationView& nav) { button_ok.on_select = [&nav](Button&){ nav.pop(); }; - if( cpld_hackrf_verify_eeprom() ) { + if( hackrf::cpld::verify_eeprom() ) { text_cpld_hackrf_status.set(" OK"); } else { text_cpld_hackrf_status.set("BAD"); diff --git a/firmware/common/cpld_max5.hpp b/firmware/common/cpld_max5.hpp index 98bf96d8..bf98edda 100644 --- a/firmware/common/cpld_max5.hpp +++ b/firmware/common/cpld_max5.hpp @@ -33,6 +33,11 @@ namespace cpld { namespace max5 { +struct Config { + const std::array& block_0; + const std::array& block_1; +}; + class CPLD { public: constexpr CPLD( diff --git a/firmware/common/cpld_update.cpp b/firmware/common/cpld_update.cpp index 52b59b08..11fd6867 100644 --- a/firmware/common/cpld_update.cpp +++ b/firmware/common/cpld_update.cpp @@ -30,8 +30,11 @@ #include "portapack_cpld_data.hpp" #include "hackrf_cpld_data.hpp" -bool cpld_update_if_necessary( - const portapack::cpld::Config config +namespace portapack { +namespace cpld { + +bool update_if_necessary( + const Config config ) { jtag::GPIOTarget target { portapack::gpio_cpld_tck, @@ -40,7 +43,7 @@ bool cpld_update_if_necessary( portapack::gpio_cpld_tdo }; jtag::JTAG jtag { target }; - cpld::max5::CPLD cpld { jtag }; + CPLD cpld { jtag }; /* Unknown state */ cpld.reset(); @@ -82,6 +85,12 @@ bool cpld_update_if_necessary( return ok; } +} /* namespace cpld */ +} /* namespace portapack */ + +namespace hackrf { +namespace cpld { + static jtag::GPIOTarget jtag_target_hackrf() { return { hackrf::one::gpio_cpld_tck, @@ -91,9 +100,9 @@ static jtag::GPIOTarget jtag_target_hackrf() { }; } -bool cpld_hackrf_load_sram() { +bool load_sram() { auto jtag_target_hackrf_cpld = jtag_target_hackrf(); - cpld::xilinx::XC2C64A hackrf_cpld { jtag_target_hackrf_cpld }; + hackrf::one::cpld::CPLD hackrf_cpld { jtag_target_hackrf_cpld }; hackrf_cpld.write_sram(hackrf::one::cpld::verify_blocks); const auto ok = hackrf_cpld.verify_sram(hackrf::one::cpld::verify_blocks); @@ -101,18 +110,21 @@ bool cpld_hackrf_load_sram() { return ok; } -bool cpld_hackrf_verify_eeprom() { +bool verify_eeprom() { auto jtag_target_hackrf_cpld = jtag_target_hackrf(); - cpld::xilinx::XC2C64A hackrf_cpld { jtag_target_hackrf_cpld }; + hackrf::one::cpld::CPLD hackrf_cpld { jtag_target_hackrf_cpld }; const auto ok = hackrf_cpld.verify_eeprom(hackrf::one::cpld::verify_blocks); return ok; } -void cpld_hackrf_init_from_eeprom() { +void init_from_eeprom() { auto jtag_target_hackrf_cpld = jtag_target_hackrf(); - cpld::xilinx::XC2C64A hackrf_cpld { jtag_target_hackrf_cpld }; + hackrf::one::cpld::CPLD hackrf_cpld { jtag_target_hackrf_cpld }; hackrf_cpld.init_from_eeprom(); } + +} /* namespace cpld */ +} /* namespace hackrf */ diff --git a/firmware/common/cpld_update.hpp b/firmware/common/cpld_update.hpp index 38691e08..6799c708 100644 --- a/firmware/common/cpld_update.hpp +++ b/firmware/common/cpld_update.hpp @@ -24,12 +24,24 @@ #include "portapack_cpld_data.hpp" -bool cpld_update_if_necessary( - const portapack::cpld::Config config +namespace portapack { +namespace cpld { + +bool update_if_necessary( + const Config config ); -bool cpld_hackrf_load_sram(); -bool cpld_hackrf_verify_eeprom(); -void cpld_hackrf_init_from_eeprom(); +} /* namespace cpld */ +} /* namespace portapack */ + +namespace hackrf { +namespace cpld { + +bool load_sram(); +bool verify_eeprom(); +void init_from_eeprom(); + +} /* namespace cpld */ +} /* namespace hackrf */ #endif/*__CPLD_UPDATE_H__*/ diff --git a/firmware/common/portapack_cpld_data.hpp b/firmware/common/portapack_cpld_data.hpp index 71190b0b..ad4dfd2f 100644 --- a/firmware/common/portapack_cpld_data.hpp +++ b/firmware/common/portapack_cpld_data.hpp @@ -22,16 +22,16 @@ #ifndef __PORTAPACK_CPLD_DATA_H__ #define __PORTAPACK_CPLD_DATA_H__ +#include "cpld_max5.hpp" + #include #include namespace portapack { namespace cpld { -struct Config { - const std::array& block_0; - const std::array& block_1; -}; +using CPLD = ::cpld::max5::CPLD; +using Config = ::cpld::max5::Config; namespace rev_20150901 {