Rewrite GOWIN algorithms

This commit is contained in:
Alexey Starikovskiy 2023-09-01 20:24:33 +03:00 committed by Gwenhael Goavec-Merou
parent cceac16fc5
commit 1789feb2cf
2 changed files with 415 additions and 433 deletions

File diff suppressed because it is too large Load Diff

View File

@ -3,38 +3,37 @@
* Copyright (C) 2019 Gwenhael Goavec-Merou <gwenhael.goavec-merou@trabucayre.com>
*/
#ifndef GOWIN_HPP_
#define GOWIN_HPP_
#ifndef SRC_GOWIN_HPP_
#define SRC_GOWIN_HPP_
#include <stdint.h>
#include <iostream>
#include <string>
#include <vector>
#include "device.hpp"
#include "configBitstreamParser.hpp"
#include "device.hpp"
#include "jtag.hpp"
#include "spiInterface.hpp"
class Gowin: public Device, SPIInterface {
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);
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);
~Gowin();
uint32_t idCode() override;
void reset() override;
void program(unsigned int offset, bool unprotect_flash) override;
void programFlash();
bool connectJtagToMCU() override;
/* spi interface */
virtual bool protect_flash(uint32_t len) override {
bool protect_flash(uint32_t len) override {
(void) len;
printError("protect flash not supported"); return false;}
virtual bool unprotect_flash() override {
bool unprotect_flash() override {
printError("unprotect flash not supported"); return false;}
virtual bool bulk_erase_flash() override {
bool bulk_erase_flash() override {
printError("bulk erase flash not supported"); return false;}
int spi_put(uint8_t cmd, const uint8_t *tx, uint8_t *rx,
uint32_t len) override;
@ -43,16 +42,21 @@ class Gowin: public Device, SPIInterface {
uint32_t timeout, bool verbose) override;
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 send_command(uint8_t cmd);
void spi_gowin_write(const uint8_t *wr, uint8_t *rd, unsigned len);
uint32_t readReg32(uint8_t cmd);
void sendClkUs(unsigned us);
bool enableCfg();
bool disableCfg();
bool pollFlag(uint32_t mask, uint32_t value);
bool eraseSRAM();
bool eraseFLASH();
bool flashSRAM(const uint8_t *data, int length);
bool flashFLASH(uint32_t page, const uint8_t *data, int length);
void displayReadReg(uint32_t dev);
void programFlash();
void programExtFlash(unsigned int offset, bool unprotect_flash);
void programSRAM();
bool writeSRAM(const uint8_t *data, int length);
bool writeFLASH(uint32_t page, const uint8_t *data, int length);
void displayReadReg(const char *, uint32_t dev);
uint32_t readStatusReg();
uint32_t readUserCode();
/*!
@ -63,6 +67,7 @@ class Gowin: public Device, SPIInterface {
ConfigBitstreamParser *_fs;
bool is_gw1n1;
bool is_gw2a;
bool is_gw1n4;
bool is_gw5a;
bool skip_checksum; /**< bypass checksum verification (GW2A) */
bool _external_flash; /**< select between int or ext flash */
@ -73,4 +78,4 @@ class Gowin: public Device, SPIInterface {
uint8_t _spi_msk; /** default spi msk with only do out */
ConfigBitstreamParser *_mcufw;
};
#endif // GOWIN_HPP_
#endif // SRC_GOWIN_HPP_