2019-11-18 16:03:59 +01:00
|
|
|
/*
|
|
|
|
|
* Copyright (C) 2019 Gwenhael Goavec-Merou <gwenhael.goavec-merou@trabucayre.com>
|
|
|
|
|
*
|
|
|
|
|
* This program is free software: you can redistribute it and/or modify
|
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
|
* the Free Software Foundation, either version 3 of the License, or
|
|
|
|
|
* (at your option) any later version.
|
|
|
|
|
*
|
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
|
*
|
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
#ifndef LATTICE_HPP_
|
|
|
|
|
#define LATTICE_HPP_
|
|
|
|
|
|
|
|
|
|
#include <stdint.h>
|
|
|
|
|
#include <iostream>
|
|
|
|
|
#include <string>
|
|
|
|
|
#include <vector>
|
|
|
|
|
|
2020-03-06 09:05:57 +01:00
|
|
|
#include "jtag.hpp"
|
2019-11-18 16:03:59 +01:00
|
|
|
#include "device.hpp"
|
|
|
|
|
#include "jedParser.hpp"
|
2019-12-20 09:09:38 +01:00
|
|
|
#include "latticeBitParser.hpp"
|
2020-04-22 15:21:01 +02:00
|
|
|
#include "spiInterface.hpp"
|
2019-11-18 16:03:59 +01:00
|
|
|
|
2020-04-22 15:21:01 +02:00
|
|
|
class Lattice: public Device, SPIInterface {
|
2019-11-18 16:03:59 +01:00
|
|
|
public:
|
2021-02-21 18:30:13 +01:00
|
|
|
Lattice(Jtag *jtag, std::string filename, const std::string &file_type,
|
|
|
|
|
Device::prog_type_t prg_type,
|
2021-01-30 07:57:49 +01:00
|
|
|
int8_t verbose);
|
2019-11-18 16:03:59 +01:00
|
|
|
int idCode() override;
|
2019-12-20 09:09:38 +01:00
|
|
|
int userCode();
|
2019-11-18 16:03:59 +01:00
|
|
|
void reset() override {}
|
|
|
|
|
void program(unsigned int offset) override;
|
2019-12-20 09:09:38 +01:00
|
|
|
bool program_mem();
|
2020-04-22 15:21:01 +02:00
|
|
|
bool program_flash(unsigned int offset);
|
2020-04-27 16:37:05 +02:00
|
|
|
bool Verify(std::vector<std::string> data, bool unlock = false);
|
2019-11-18 16:03:59 +01:00
|
|
|
|
2020-04-22 15:21:01 +02:00
|
|
|
/* spi interface */
|
|
|
|
|
int spi_put(uint8_t cmd, uint8_t *tx, uint8_t *rx,
|
2020-08-23 17:16:21 +02:00
|
|
|
uint32_t len) override;
|
|
|
|
|
int spi_put(uint8_t *tx, uint8_t *rx, uint32_t len) override;
|
2020-04-22 15:21:01 +02:00
|
|
|
int spi_wait(uint8_t cmd, uint8_t mask, uint8_t cond,
|
|
|
|
|
uint32_t timeout, bool verbose=false) override;
|
|
|
|
|
|
2019-11-18 16:03:59 +01:00
|
|
|
private:
|
2020-09-26 08:40:43 +02:00
|
|
|
enum lattice_family_t {
|
|
|
|
|
MACHXO2_FAMILY = 0,
|
|
|
|
|
MACHXO3_FAMILY = 1,
|
2020-10-16 08:03:45 +02:00
|
|
|
MACHXO3D_FAMILY = 2,
|
|
|
|
|
ECP5_FAMILY = 3,
|
|
|
|
|
NEXUS_FAMILY = 4,
|
2020-09-26 08:40:43 +02:00
|
|
|
UNKNOWN_FAMILY = 999
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
lattice_family_t _fpga_family;
|
|
|
|
|
|
2020-04-22 15:21:01 +02:00
|
|
|
bool program_intFlash();
|
|
|
|
|
bool program_extFlash(unsigned int offset);
|
2019-11-18 16:03:59 +01:00
|
|
|
bool wr_rd(uint8_t cmd, uint8_t *tx, int tx_len,
|
|
|
|
|
uint8_t *rx, int rx_len, bool verbose = false);
|
|
|
|
|
void unlock();
|
|
|
|
|
bool EnableISC(uint8_t flash_mode);
|
|
|
|
|
bool DisableISC();
|
|
|
|
|
bool EnableCfgIf();
|
|
|
|
|
bool DisableCfg();
|
|
|
|
|
bool pollBusyFlag(bool verbose = false);
|
|
|
|
|
bool flashEraseAll();
|
|
|
|
|
bool flashErase(uint8_t mask);
|
2020-08-19 17:00:44 +02:00
|
|
|
bool flashProg(uint32_t start_addr, const std::string &name,
|
2020-05-02 09:47:41 +02:00
|
|
|
std::vector<std::string> data);
|
2019-11-20 07:30:54 +01:00
|
|
|
bool checkStatus(uint32_t val, uint32_t mask);
|
|
|
|
|
void displayReadReg(uint32_t dev);
|
2019-11-18 16:03:59 +01:00
|
|
|
uint32_t readStatusReg();
|
2019-11-20 07:30:54 +01:00
|
|
|
uint64_t readFeaturesRow();
|
|
|
|
|
bool writeFeaturesRow(uint64_t features, bool verify);
|
|
|
|
|
uint16_t readFeabits();
|
|
|
|
|
bool writeFeabits(uint16_t feabits, bool verify);
|
2019-11-18 16:03:59 +01:00
|
|
|
bool writeProgramDone();
|
|
|
|
|
bool loadConfiguration();
|
|
|
|
|
|
|
|
|
|
/* test */
|
|
|
|
|
bool checkID();
|
|
|
|
|
};
|
|
|
|
|
#endif // LATTICE_HPP_
|