openFPGALoader/src/lattice.hpp

105 lines
2.9 KiB
C++
Raw Normal View History

2021-06-26 15:24:07 +02:00
// SPDX-License-Identifier: Apache-2.0
/*
* Copyright (C) 2019 Gwenhael Goavec-Merou <gwenhael.goavec-merou@trabucayre.com>
*/
#ifndef LATTICE_HPP_
#define LATTICE_HPP_
#include <stdint.h>
#include <iostream>
#include <string>
#include <vector>
#include "jtag.hpp"
#include "device.hpp"
#include "jedParser.hpp"
2021-11-09 09:54:09 +01:00
#include "feaparser.hpp"
#include "latticeBitParser.hpp"
#include "spiInterface.hpp"
class Lattice: public Device, SPIInterface {
public:
Lattice(Jtag *jtag, std::string filename, const std::string &file_type,
2021-11-09 09:54:09 +01:00
Device::prog_type_t prg_type, std::string flash_sector, bool verify,
int8_t verbose);
int idCode() override;
int userCode();
void reset() override {}
void program(unsigned int offset) override;
bool program_mem();
bool program_flash(unsigned int offset);
2021-11-09 09:54:09 +01:00
bool Verify(std::vector<std::string> data, bool unlock = false, uint32_t flash_area = 0);
bool dumpFlash(const std::string &filename,
uint32_t base_addr, uint32_t len) override;
/* spi interface */
int spi_put(uint8_t cmd, uint8_t *tx, uint8_t *rx,
uint32_t len) override;
int spi_put(uint8_t *tx, uint8_t *rx, uint32_t len) override;
int spi_wait(uint8_t cmd, uint8_t mask, uint8_t cond,
uint32_t timeout, bool verbose=false) override;
private:
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,
UNKNOWN_FAMILY = 999
};
lattice_family_t _fpga_family;
bool program_intFlash(JedParser& _jed);
bool program_extFlash(unsigned int offset);
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();
2021-11-09 09:54:09 +01:00
bool flashErase(uint32_t mask);
2020-08-19 17:00:44 +02:00
bool flashProg(uint32_t start_addr, const std::string &name,
std::vector<std::string> data);
bool checkStatus(uint32_t val, uint32_t mask);
void displayReadReg(uint32_t dev);
uint32_t readStatusReg();
uint64_t readFeaturesRow();
bool writeFeaturesRow(uint64_t features, bool verify);
uint16_t readFeabits();
bool writeFeabits(uint16_t feabits, bool verify);
bool writeProgramDone();
bool loadConfiguration();
/* test */
bool checkID();
2021-11-09 09:54:09 +01:00
/*********************** MODS FOR MacXO3D *****************************/
enum lattice_flash_sector_t {
LATTICE_FLASH_UNDEFINED = 0,
LATTICE_FLASH_CFG0,
LATTICE_FLASH_CFG1,
LATTICE_FLASH_UFM0,
LATTICE_FLASH_UFM1,
LATTICE_FLASH_UFM2,
LATTICE_FLASH_UFM3,
LATTICE_FLASH_FEA,
LATTICE_FLASH_PKEY,
LATTICE_FLASH_AKEY,
LATTICE_FLASH_CSEC,
LATTICE_FLASH_USEC
};
lattice_flash_sector_t _flash_sector;
bool program_intFlash_MachXO3D(JedParser& _jed);
2021-11-09 09:54:09 +01:00
bool program_fea_MachXO3D();
bool programFeatureRow_MachXO3D(uint8_t* feature_row);
bool programFeabits_MachXO3D(uint32_t feabits);
};
#endif // LATTICE_HPP_