openFPGALoader/src/gowin.hpp

77 lines
2.5 KiB
C++
Raw Normal View History

2021-06-26 15:24:07 +02:00
// SPDX-License-Identifier: Apache-2.0
2019-12-06 07:27:08 +01:00
/*
* Copyright (C) 2019 Gwenhael Goavec-Merou <gwenhael.goavec-merou@trabucayre.com>
*/
#ifndef GOWIN_HPP_
#define GOWIN_HPP_
#include <stdint.h>
#include <iostream>
#include <string>
#include <vector>
#include "device.hpp"
#include "configBitstreamParser.hpp"
#include "jtag.hpp"
#include "spiInterface.hpp"
2019-12-06 07:27:08 +01:00
class Gowin: public Device, SPIInterface {
2019-12-06 07:27:08 +01:00
public:
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);
2019-12-06 07:27:08 +01:00
~Gowin();
int idCode() override;
2020-01-15 09:49:09 +01:00
void reset() override;
void program(unsigned int offset, bool unprotect_flash) override;
void programFlash();
bool connectJtagToMCU() override;
2019-12-06 07:27:08 +01:00
/* spi interface */
virtual bool protect_flash(uint32_t len) override {
(void) len;
printError("protect flash not supported"); return false;}
virtual bool unprotect_flash() override {
printError("unprotect flash not supported"); return false;}
virtual bool bulk_erase_flash() override {
printError("bulk erase flash not supported"); return false;}
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) override;
2019-12-06 07:27:08 +01:00
private:
bool wr_rd(uint8_t cmd, uint8_t *tx, int tx_len,
uint8_t *rx, int rx_len, bool verbose = false);
bool EnableCfg();
bool DisableCfg();
bool pollFlag(uint32_t mask, uint32_t value);
bool eraseSRAM();
bool eraseFLASH();
2019-12-06 07:27:08 +01:00
bool flashSRAM(uint8_t *data, int length);
bool flashFLASH(uint32_t page, uint8_t *data, int length);
2019-12-06 07:27:08 +01:00
void displayReadReg(uint32_t dev);
uint32_t readStatusReg();
uint32_t readUserCode();
/*!
* \brief compare usercode register with fs checksum and/or
* .fs usercode field
*/
void checkCRC();
ConfigBitstreamParser *_fs;
bool is_gw1n1;
2022-09-06 21:24:40 +02:00
bool is_gw2a;
bool is_gw5a;
bool skip_checksum; /**< bypass checksum verification (GW2A) */
bool _external_flash; /**< select between int or ext flash */
uint8_t _spi_sck; /**< clk signal offset in bscan SPI */
uint8_t _spi_cs; /**< cs signal offset in bscan SPI */
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 */
2022-07-24 17:31:36 +02:00
ConfigBitstreamParser *_mcufw;
2019-12-06 07:27:08 +01:00
};
#endif // GOWIN_HPP_