SXXXXXXX_PyDownloadFwViaSRIO/_OLD/Vecchia_app/FpgaBeamMeUp/fpgaflashengine.h.bak
2026-01-22 17:10:05 +01:00

142 lines
4.8 KiB
C

#ifndef FPGAFLASHENGINE_H
#define FPGAFLASHENGINE_H
#include <stdint.h>
#include <exception>
#include "fpgaflashconfig.h"
#include "mydebug.h"
//Profilo contentente i dati della FPGA da utilizzare
class FpgaFlashProfile
{
public:
unsigned long SectorSize_KBytes;
unsigned long BaseAddress;
unsigned long BaseOffset;
reg_moder_qspiport_t spiport;
reg_moder_byteaddress_t byteddress;
unsigned long address_start_area; //hex address, start fimware area
unsigned long address_stop_area; //hex address, stop fimware area
QString ip;
QString port;
QString slotAddress;
QString FileToSend; //complete path of file to send
int dimMbit; //128Mbit for xcku040
//256Mbit for xcku060, xc7a200
bool writeRamp; //instead file, write ramp into flash
bool verifySector; //verify single sector
bool verifyFinal; //verify final write
void reset()
{
SectorSize_KBytes = 0;
BaseAddress = 0;
BaseOffset = 0;
spiport = primarySpiPort;
byteddress = bytes3address;
address_start_area = 0;
address_stop_area = 0;
ip = QString("");
port = QString("");
slotAddress = QString("");
FileToSend = QString("");
dimMbit = 0;
writeRamp = false;
verifyFinal = false;
verifySector = false;
}
};
enum spisr_bit_t
{
rx_fifo_valid = 0x1, //bit 0, This bit flags that data present into SPIRR is valid
rx_fifo_overrun = 0x2, //bit 1, This bit flags that an overrun error occurred during data reception into the RX FIFO.
tx_fifo_almost_full = 0x10, //bit 4, This bit flags that an almost full condition occurred loading the TX FIFO. In particular this condition is activated when the number of bytes into the FIFO differs from respect the FIFO size.
tx_fifo_overrun = 0x20, //bit 5, This bit flags that an overrun error occurred loading data into the TX FIFO.
tx_fifo_underrun = 0x40, //bit 6, This bit flags that an underrun error occurred into the TX FIFO during data transmission.
spi_core_error = 0x400, //bit 10, The SPI Core error flags an error condition during transaction. This condition can be activated: - when an overrun or underrun is detected (on both "TX FIFO" or "RX FIFO") - when the required command is not implemented
spi_core_ack = 0x800, //bit 11, This bit is activated when a previously required transaction required with the "SPI request" on the SPICR register has been accepted
spi_core_busy = 0x1000 //bit 12, This bit is activated when the core is executing the current transaction after that it has been run with the "SPI start" bit on the SPICR register.
};
bool decodeSPISR(unsigned int _spisr, spisr_bit_t _bit);
unsigned int encodeSPISR(unsigned int _spisr, spisr_bit_t _bit);
class FpgaFlashInterface
{
public:
enum step_t
{
s_init=0,
s_reset,
s_status,
s_read_id,
s_erase,
s_write,
s_end
};
virtual bool rtgWrite(uint32_t address, const void* data, unsigned int len=256)=0;
virtual bool rtgRead(uint32_t address, void* data, unsigned int len=256)=0;
//virtual bool rtgErase(uint32_t address, void* data, unsigned int len=256)=0;
virtual bool rtgReadDirect(uint32_t address, void* data, unsigned int len=256)=0;
virtual bool rtgWaitEvent(unsigned int timeout_ms=5000)=0;
virtual void notify(step_t sts, int progress, const char* msg, ...);
virtual void log(type_log_t level, const char* msg, ...);//level<0: error, ==0: info, >0: success
virtual unsigned long timeNowMs();
virtual ~FpgaFlashInterface();
virtual void setLogLevel(log_level_t _level);
virtual log_level_t getLogLevel();
log_level_t log_level;
};
class FpgaFlashEngine
{
public:
FpgaFlashEngine();
void setProfile(const FpgaFlashProfile& profile);
void setInterface(FpgaFlashInterface* flashInterface);
bool fpgaErase(const void* data, unsigned int size);
bool fpgaProgram(const void* data, unsigned int size);
bool fpgaReset();
bool fpgaTerminate();
bool readFlashID();
bool readStatusSPI();
bool simulateWrite(uint32_t address, const void* data, unsigned int len);
bool simulateRead(uint32_t address, void *data, unsigned int len);
bool simulateErase(uint32_t address, void *data, unsigned int len);
bool simulateReset();
bool simulateReadStatusSPI();
bool simulateTerminate();
unsigned int simulateReadFlashID();
bool getEnableMsgBlk();
};
#endif // FPGAFLASHENGINE_H