openFPGALoader/src/efinix.hpp

76 lines
2.3 KiB
C++
Raw Normal View History

2021-06-26 15:24:07 +02:00
// SPDX-License-Identifier: Apache-2.0
2020-10-31 08:46:53 +01:00
/*
* Copyright (C) 2020-2023 Gwenhael Goavec-Merou <gwenhael.goavec-merou@trabucayre.com>
2020-10-31 08:46:53 +01:00
*/
#ifndef SRC_EFINIX_HPP_
#define SRC_EFINIX_HPP_
#include <string>
#include "device.hpp"
#include "ftdiJtagMPSSE.hpp"
2020-10-31 08:46:53 +01:00
#include "ftdispi.hpp"
#include "jtag.hpp"
#include "spiInterface.hpp"
2020-10-31 08:46:53 +01:00
class Efinix: public Device, SPIInterface {
2020-10-31 08:46:53 +01:00
public:
Efinix(FtdiSpi *spi, const std::string &filename,
const std::string &file_type,
uint16_t rst_pin, uint16_t done_pin, uint16_t oe_pin,
bool verify, int8_t verbose);
Efinix(Jtag* jtag, const std::string &filename,
const std::string &file_type, Device::prog_type_t prg_type,
const std::string &board_name, const std::string &device_package,
const std::string &spiOverJtagPath,
bool verify, int8_t verbose);
2020-10-31 08:46:53 +01:00
~Efinix();
void program(unsigned int offset, bool unprotect_flash) override;
bool dumpFlash(uint32_t base_addr, uint32_t len) override;
bool protect_flash(uint32_t len) override {
(void) len;
printError("protect flash not supported"); return false;}
bool unprotect_flash() override {
printError("unprotect flash not supported"); return false;}
bool bulk_erase_flash() override {
printError("bulk erase flash not supported"); return false;}
2020-10-31 08:46:53 +01:00
/* not supported in SPI Active mode */
2023-08-10 12:50:26 +02:00
uint32_t idCode() override {return 0;}
2020-10-31 08:46:53 +01:00
void reset() override;
/* spi interface */
2023-08-08 15:54:27 +02:00
int spi_put(uint8_t cmd, const uint8_t *tx, uint8_t *rx,
uint32_t len) override;
2023-08-08 15:54:27 +02:00
int spi_put(const 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;
2020-10-31 08:46:53 +01:00
private:
/* list of efinix family devices */
enum efinix_family_t {
TITANIUM_FAMILY = 0,
TRION_FAMILY,
UNKNOWN_FAMILY = 999
};
void init_common(const Device::prog_type_t &prg_type);
void programSPI(unsigned int offset, const uint8_t *data,
const int length, const bool unprotect_flash);
void programJTAG(const uint8_t *data, const int length);
bool post_flash_access() override;
bool prepare_flash_access() override;
2020-10-31 08:46:53 +01:00
FtdiSpi *_spi;
FtdiJtagMPSSE *_ftdi_jtag;
2020-10-31 08:46:53 +01:00
uint16_t _rst_pin;
uint16_t _done_pin;
uint16_t _cs_pin;
uint16_t _oe_pin;
efinix_family_t _fpga_family;
int _irlen;
std::string _device_package;
std::string _spiOverJtagPath;
2020-10-31 08:46:53 +01:00
};
#endif // SRC_EFINIX_HPP_