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.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();

View File

@ -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");

View File

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

View File

@ -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 */

View File

@ -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__*/

View File

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