From ecdde91dff3d81157ebad9b8e65e28d671a6d940 Mon Sep 17 00:00:00 2001 From: Gwenhael Goavec-Merou Date: Sat, 28 Sep 2019 15:31:43 +0200 Subject: [PATCH] Altera: - merge epcq and svf into the class - merge reset() - check in constructor file type to determine if bitstream is to send in sram or spi flash --- altera.cpp | 63 ++++++++++++++++++++++++++++++++++++++++++++++++------ altera.hpp | 8 ++++--- 2 files changed, 62 insertions(+), 9 deletions(-) diff --git a/altera.cpp b/altera.cpp index c37a74e..d7599a9 100644 --- a/altera.cpp +++ b/altera.cpp @@ -1,13 +1,64 @@ #include "altera.hpp" #include "ftdijtag.hpp" #include "device.hpp" +#include "epcq.hpp" -Altera::Altera(FtdiJtag *jtag, enum prog_mode mode, std::string filename):Device(jtag, mode, filename), - _bitfile(filename) -{} +#define IDCODE 6 +#define IRLENGTH 10 +#define BIT_FOR_FLASH "/usr/local/share/cyc1000_prog/test_sfl.svf" + +Altera::Altera(FtdiJtag *jtag, std::string filename):Device(jtag, filename), + _svf(_jtag) +{ + if (_filename != "") { + if (_file_extension == "svf") + _mode = Device::MEM_MODE; + else + _mode = Device::SPI_MODE; + } +} Altera::~Altera() {} -void Altera::program() -{} +void Altera::reset() +{ + /* PULSE_NCONFIG */ + unsigned char tx_buff[2] = {0x01, 0x00}; + _jtag->set_state(FtdiJtag::TEST_LOGIC_RESET); + _jtag->shiftIR(tx_buff, NULL, IRLENGTH); + _jtag->toggleClk(1); + _jtag->set_state(FtdiJtag::TEST_LOGIC_RESET); +} + +void Altera::program(unsigned int offset) +{ + if (_mode == Device::NONE_MODE) + return; + /* in all case we consider svf is mandatory + * MEM_MODE : svf file provided for constructor + * is the bitstream to use + * SPI_MODE : svf file provided is bridge to have + * access to the SPI flash + */ + /* mem mode -> svf */ + if (_mode == Device::MEM_MODE) { + _svf.parse(_filename); + } else if (_mode == Device::SPI_MODE) { + /* GGM: TODO: fix this issue */ + EPCQ epcq(_jtag->vid(), _jtag->pid(), 2, 6000000); + _svf.parse(BIT_FOR_FLASH); + epcq.program(offset, _filename, (_file_extension == "rpd")? true:false); + reset(); + } +} int Altera::idCode() -{} +{ + unsigned char tx_data = IDCODE; + unsigned char rx_data[4]; + _jtag->go_test_logic_reset(); + _jtag->shiftIR(&tx_data, NULL, IRLENGTH); + _jtag->shiftDR(NULL, rx_data, 32); + return ((rx_data[0] & 0x000000ff) | + ((rx_data[1] << 8) & 0x0000ff00) | + ((rx_data[2] << 16) & 0x00ff0000) | + ((rx_data[3] << 24) & 0xff000000)); +} diff --git a/altera.hpp b/altera.hpp index ed3c580..03def00 100644 --- a/altera.hpp +++ b/altera.hpp @@ -4,16 +4,18 @@ #include "bitparser.hpp" #include "device.hpp" #include "ftdijtag.hpp" +#include "svf_jtag.hpp" class Altera: public Device { public: - Altera(FtdiJtag *jtag, enum prog_mode mode, std::string filename); + Altera(FtdiJtag *jtag, std::string filename); ~Altera(); - void program(); + void program(unsigned int offset = 0); int idCode(); + void reset() override; private: - BitParser _bitfile; + SVF_jtag _svf; }; #endif