CPLD: Organize CPLD code into namespaces.

Use type aliases to hide actual CPLD type (somewhat).
This commit is contained in:
Jared Boone 2017-06-02 21:57:13 -07:00
parent dd0c009e6f
commit dec4e41189
6 changed files with 51 additions and 22 deletions

View File

@ -182,11 +182,11 @@ void init() {
clock_manager.set_reference_ppb(persistent_memory::correction_ppb()); clock_manager.set_reference_ppb(persistent_memory::correction_ppb());
clock_manager.run_at_full_speed(); clock_manager.run_at_full_speed();
if( !cpld_update_if_necessary(portapack_cpld_config()) ) { if( !portapack::cpld::update_if_necessary(portapack_cpld_config()) ) {
chSysHalt(); chSysHalt();
} }
if( !cpld_hackrf_load_sram() ) { if( !hackrf::cpld::load_sram() ) {
chSysHalt(); chSysHalt();
} }
@ -217,7 +217,7 @@ void shutdown() {
radio::disable(); radio::disable();
audio::shutdown(); audio::shutdown();
cpld_hackrf_init_from_eeprom(); hackrf::cpld::init_from_eeprom();
clock_manager.shutdown(); clock_manager.shutdown();

View File

@ -182,7 +182,7 @@ AboutView::AboutView(NavigationView& nav) {
button_ok.on_select = [&nav](Button&){ nav.pop(); }; button_ok.on_select = [&nav](Button&){ nav.pop(); };
if( cpld_hackrf_verify_eeprom() ) { if( hackrf::cpld::verify_eeprom() ) {
text_cpld_hackrf_status.set(" OK"); text_cpld_hackrf_status.set(" OK");
} else { } else {
text_cpld_hackrf_status.set("BAD"); text_cpld_hackrf_status.set("BAD");

View File

@ -33,6 +33,11 @@
namespace cpld { namespace cpld {
namespace max5 { namespace max5 {
struct Config {
const std::array<uint16_t, 3328>& block_0;
const std::array<uint16_t, 512>& block_1;
};
class CPLD { class CPLD {
public: public:
constexpr CPLD( constexpr CPLD(

View File

@ -30,8 +30,11 @@
#include "portapack_cpld_data.hpp" #include "portapack_cpld_data.hpp"
#include "hackrf_cpld_data.hpp" #include "hackrf_cpld_data.hpp"
bool cpld_update_if_necessary( namespace portapack {
const portapack::cpld::Config config namespace cpld {
bool update_if_necessary(
const Config config
) { ) {
jtag::GPIOTarget target { jtag::GPIOTarget target {
portapack::gpio_cpld_tck, portapack::gpio_cpld_tck,
@ -40,7 +43,7 @@ bool cpld_update_if_necessary(
portapack::gpio_cpld_tdo portapack::gpio_cpld_tdo
}; };
jtag::JTAG jtag { target }; jtag::JTAG jtag { target };
cpld::max5::CPLD cpld { jtag }; CPLD cpld { jtag };
/* Unknown state */ /* Unknown state */
cpld.reset(); cpld.reset();
@ -82,6 +85,12 @@ bool cpld_update_if_necessary(
return ok; return ok;
} }
} /* namespace cpld */
} /* namespace portapack */
namespace hackrf {
namespace cpld {
static jtag::GPIOTarget jtag_target_hackrf() { static jtag::GPIOTarget jtag_target_hackrf() {
return { return {
hackrf::one::gpio_cpld_tck, 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(); 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); hackrf_cpld.write_sram(hackrf::one::cpld::verify_blocks);
const auto ok = hackrf_cpld.verify_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; return ok;
} }
bool cpld_hackrf_verify_eeprom() { bool verify_eeprom() {
auto jtag_target_hackrf_cpld = jtag_target_hackrf(); 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); const auto ok = hackrf_cpld.verify_eeprom(hackrf::one::cpld::verify_blocks);
return ok; return ok;
} }
void cpld_hackrf_init_from_eeprom() { void init_from_eeprom() {
auto jtag_target_hackrf_cpld = jtag_target_hackrf(); 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(); hackrf_cpld.init_from_eeprom();
} }
} /* namespace cpld */
} /* namespace hackrf */

View File

@ -24,12 +24,24 @@
#include "portapack_cpld_data.hpp" #include "portapack_cpld_data.hpp"
bool cpld_update_if_necessary( namespace portapack {
const portapack::cpld::Config config namespace cpld {
bool update_if_necessary(
const Config config
); );
bool cpld_hackrf_load_sram(); } /* namespace cpld */
bool cpld_hackrf_verify_eeprom(); } /* namespace portapack */
void cpld_hackrf_init_from_eeprom();
namespace hackrf {
namespace cpld {
bool load_sram();
bool verify_eeprom();
void init_from_eeprom();
} /* namespace cpld */
} /* namespace hackrf */
#endif/*__CPLD_UPDATE_H__*/ #endif/*__CPLD_UPDATE_H__*/

View File

@ -22,16 +22,16 @@
#ifndef __PORTAPACK_CPLD_DATA_H__ #ifndef __PORTAPACK_CPLD_DATA_H__
#define __PORTAPACK_CPLD_DATA_H__ #define __PORTAPACK_CPLD_DATA_H__
#include "cpld_max5.hpp"
#include <cstdint> #include <cstdint>
#include <array> #include <array>
namespace portapack { namespace portapack {
namespace cpld { namespace cpld {
struct Config { using CPLD = ::cpld::max5::CPLD;
const std::array<uint16_t, 3328>& block_0; using Config = ::cpld::max5::Config;
const std::array<uint16_t, 512>& block_1;
};
namespace rev_20150901 { namespace rev_20150901 {