gowin: Use std::unique_ptr instead of manual RAII
This commit is contained in:
parent
8f88d221dd
commit
91608ca206
|
|
@ -80,12 +80,11 @@ Gowin::Gowin(Jtag *jtag, const string filename, const string &file_type, std::st
|
|||
bool verify, int8_t verbose): Device(jtag, filename, file_type,
|
||||
verify, verbose),
|
||||
SPIInterface(filename, verbose, 0, verify, false, false),
|
||||
_fs(NULL), _idcode(0), is_gw1n1(false), is_gw2a(false),
|
||||
is_gw1n4(false), is_gw5a(false), _external_flash(external_flash),
|
||||
_idcode(0), is_gw1n1(false), is_gw2a(false), is_gw1n4(false),
|
||||
is_gw5a(false), _external_flash(external_flash),
|
||||
_spi_sck(BSCAN_SPI_SCK), _spi_cs(BSCAN_SPI_CS),
|
||||
_spi_di(BSCAN_SPI_DI), _spi_do(BSCAN_SPI_DO),
|
||||
_spi_msk(BSCAN_SPI_MSK),
|
||||
_mcufw(NULL)
|
||||
_spi_msk(BSCAN_SPI_MSK)
|
||||
{
|
||||
detectFamily();
|
||||
|
||||
|
|
@ -100,7 +99,7 @@ Gowin::Gowin(Jtag *jtag, const string filename, const string &file_type, std::st
|
|||
if (!_file_extension.empty() && prg_type != Device::RD_FLASH) {
|
||||
if (_file_extension == "fs") {
|
||||
try {
|
||||
_fs = new FsParser(_filename, _mode == Device::MEM_MODE, _verbose);
|
||||
_fs = std::unique_ptr<ConfigBitstreamParser>(new FsParser(_filename, _mode == Device::MEM_MODE, _verbose));
|
||||
} catch (std::exception &e) {
|
||||
throw std::runtime_error(e.what());
|
||||
}
|
||||
|
|
@ -109,7 +108,7 @@ Gowin::Gowin(Jtag *jtag, const string filename, const string &file_type, std::st
|
|||
if (!_external_flash)
|
||||
throw std::runtime_error("incompatible file format");
|
||||
try {
|
||||
_fs = new RawParser(_filename, false);
|
||||
_fs = std::unique_ptr<ConfigBitstreamParser>(new RawParser(_filename, false));
|
||||
} catch (std::exception &e) {
|
||||
throw std::runtime_error(e.what());
|
||||
}
|
||||
|
|
@ -118,7 +117,6 @@ Gowin::Gowin(Jtag *jtag, const string filename, const string &file_type, std::st
|
|||
printInfo("Parse file ", false);
|
||||
if (_fs->parse() == EXIT_FAILURE) {
|
||||
printError("FAIL");
|
||||
delete _fs;
|
||||
throw std::runtime_error("can't parse file");
|
||||
} else {
|
||||
printSuccess("DONE");
|
||||
|
|
@ -144,11 +142,10 @@ Gowin::Gowin(Jtag *jtag, const string filename, const string &file_type, std::st
|
|||
if (_idcode != 0x0100981b)
|
||||
throw std::runtime_error("Microcontroller firmware flashing only supported on GW1NSR-4C");
|
||||
|
||||
_mcufw = new RawParser(mcufw, false);
|
||||
_mcufw = std::unique_ptr<ConfigBitstreamParser>(new RawParser(mcufw, false));
|
||||
|
||||
if (_mcufw->parse() == EXIT_FAILURE) {
|
||||
printError("FAIL");
|
||||
delete _mcufw;
|
||||
throw std::runtime_error("can't parse file");
|
||||
} else {
|
||||
printSuccess("DONE");
|
||||
|
|
@ -167,14 +164,6 @@ Gowin::Gowin(Jtag *jtag, const string filename, const string &file_type, std::st
|
|||
}
|
||||
}
|
||||
|
||||
Gowin::~Gowin()
|
||||
{
|
||||
if (_fs)
|
||||
delete _fs;
|
||||
if (_mcufw)
|
||||
delete _mcufw;
|
||||
}
|
||||
|
||||
bool Gowin::detectFamily()
|
||||
{
|
||||
_idcode = _jtag->get_target_device_id();
|
||||
|
|
@ -415,7 +404,7 @@ void Gowin::program(unsigned int offset, bool unprotect_flash)
|
|||
void Gowin::checkCRC()
|
||||
{
|
||||
uint32_t ucode = readUserCode();
|
||||
uint16_t checksum = static_cast<FsParser *>(_fs)->checksum();
|
||||
uint16_t checksum = static_cast<FsParser *>(_fs.get())->checksum();
|
||||
if (static_cast<uint16_t>(0xffff & ucode) == checksum)
|
||||
goto success;
|
||||
/* no match:
|
||||
|
|
@ -788,7 +777,7 @@ bool Gowin::writeSRAM(const uint8_t *data, int length)
|
|||
}
|
||||
progress.done();
|
||||
send_command(0x0a);
|
||||
uint32_t checksum = static_cast<FsParser *>(_fs)->checksum();
|
||||
uint32_t checksum = static_cast<FsParser *>(_fs.get())->checksum();
|
||||
checksum = htole32(checksum);
|
||||
_jtag->shiftDR((uint8_t *)&checksum, NULL, 32);
|
||||
send_command(0x08);
|
||||
|
|
|
|||
|
|
@ -10,6 +10,7 @@
|
|||
#include <iostream>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
#include <memory>
|
||||
|
||||
#include "configBitstreamParser.hpp"
|
||||
#include "device.hpp"
|
||||
|
|
@ -22,7 +23,6 @@ class Gowin: public Device, SPIInterface {
|
|||
Gowin(Jtag *jtag, std::string filename, const std::string &file_type,
|
||||
std::string mcufw, Device::prog_type_t prg_type,
|
||||
bool external_flash, bool verify, int8_t verbose);
|
||||
~Gowin();
|
||||
uint32_t idCode() override;
|
||||
void reset() override;
|
||||
void program(unsigned int offset, bool unprotect_flash) override;
|
||||
|
|
@ -128,7 +128,8 @@ class Gowin: public Device, SPIInterface {
|
|||
*/
|
||||
bool gw5a_enable_spi();
|
||||
|
||||
ConfigBitstreamParser *_fs;
|
||||
std::unique_ptr<ConfigBitstreamParser> _fs;
|
||||
std::unique_ptr<ConfigBitstreamParser> _mcufw;
|
||||
uint32_t _idcode;
|
||||
bool is_gw1n1;
|
||||
bool is_gw2a;
|
||||
|
|
@ -141,7 +142,6 @@ class Gowin: public Device, SPIInterface {
|
|||
uint8_t _spi_di; /**< di signal (mosi) offset in bscan SPI */
|
||||
uint8_t _spi_do; /**< do signal (miso) offset in bscan SPI */
|
||||
uint8_t _spi_msk; /** default spi msk with only do out */
|
||||
ConfigBitstreamParser *_mcufw;
|
||||
JtagInterface::tck_edge_t _prev_rd_edge; /**< default probe rd edge cfg */
|
||||
JtagInterface::tck_edge_t _prev_wr_edge; /**< default probe wr edge cfg */
|
||||
};
|
||||
|
|
|
|||
Loading…
Reference in New Issue