openFPGALoader/src/altera.hpp

80 lines
2.4 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 SRC_ALTERA_HPP_
#define SRC_ALTERA_HPP_
2019-09-26 18:29:20 +02:00
#include <string>
2019-09-26 18:29:20 +02:00
#include "device.hpp"
#include "jtag.hpp"
#include "rawParser.hpp"
#include "spiInterface.hpp"
#include "svf_jtag.hpp"
2019-09-26 18:29:20 +02:00
class Altera: public Device, SPIInterface {
2019-09-26 18:29:20 +02:00
public:
Altera(Jtag *jtag, const std::string &filename,
const std::string &file_type,
Device::prog_type_t prg_type,
const std::string &device_package,
bool verify, int8_t verbose);
2019-09-26 18:29:20 +02:00
~Altera();
void programMem(RawParser &_bit);
void program(unsigned int offset = 0) override;
2021-07-11 11:32:35 +02:00
/*!
* \brief read len Byte starting at base_addr and store
* into filename
* \param[in] filename: file name
* \param[in] base_addr: starting address in flash memory
* \param[in] len: length (in Byte)
* \return false if read fails or filename can't be open, true otherwise
*/
bool dumpFlash(const std::string filename, uint32_t base_addr,
uint32_t len);
int idCode() override;
void reset() 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;
2019-09-26 18:29:20 +02:00
private:
/*!
* \brief with intel devices SPI flash direct access is not possible
* so a bridge must be loaded in RAM to access flash
* \return false if missing device mode, true otherwise
*/
bool load_bridge();
/* virtual JTAG access */
/*!
* \brief virtual IR: send USER0 IR followed, in DR, by
* address (_vir_addr) in a burst of _vir_length
* \param[in] reg: data to send in shiftDR mode with addr
*/
void shiftVIR(uint32_t reg);
/*!
* \brief virtual IR: send USER1 IR followed by
* data in DR with an optional read
* \param[in] tx: data to send in shiftDR mode
* \param[in] rx: data to read in shiftDR mode
* \param[in] len: len of tx & rx
* \param[in] end_state: next state at the end of xfer
*/
void shiftVDR(uint8_t * tx, uint8_t * rx, uint32_t len,
int end_state = Jtag::UPDATE_DR, bool debug = false);
SVF_jtag _svf;
std::string _device_package;
uint32_t _vir_addr; /**< addr affected to virtual jtag */
uint32_t _vir_length; /**< length of virtual jtag IR */
2019-09-26 18:29:20 +02:00
};
#endif // SRC_ALTERA_HPP_