2021-06-26 15:24:07 +02:00
|
|
|
// SPDX-License-Identifier: Apache-2.0
|
2020-08-19 15:15:13 +02:00
|
|
|
/*
|
|
|
|
|
* Copyright (C) 2020 Gwenhael Goavec-Merou <gwenhael.goavec-merou@trabucayre.com>
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
#ifndef USBBLASTER_H
|
|
|
|
|
#define USBBLASTER_H
|
|
|
|
|
#include <ftdi.h>
|
|
|
|
|
#include <iostream>
|
|
|
|
|
#include <string>
|
|
|
|
|
#include <vector>
|
|
|
|
|
|
2022-10-15 16:17:32 +02:00
|
|
|
#include "cable.hpp"
|
2020-08-19 15:15:13 +02:00
|
|
|
#include "jtagInterface.hpp"
|
|
|
|
|
#include "ftdipp_mpsse.hpp"
|
2021-05-13 16:06:29 +02:00
|
|
|
#include "fx2_ll.hpp"
|
|
|
|
|
|
|
|
|
|
/*!
|
|
|
|
|
* \file UsbBlaster.hpp
|
|
|
|
|
* \class UsbBlaster_ll
|
|
|
|
|
* \brief altera/intel usb blaster abstract class for blasterI and blasterII
|
|
|
|
|
* \author Gwenhael Goavec-Merou
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
class UsbBlaster_ll {
|
|
|
|
|
public:
|
|
|
|
|
virtual ~UsbBlaster_ll() {}
|
|
|
|
|
virtual int setClkFreq(uint32_t clkHZ) = 0;
|
2021-05-15 08:32:51 +02:00
|
|
|
virtual uint32_t getClkFreq() = 0;
|
2021-05-13 16:06:29 +02:00
|
|
|
virtual int write(uint8_t *wr_buf, int wr_len,
|
|
|
|
|
uint8_t *rd_buf, int rd_len) = 0;
|
|
|
|
|
};
|
2020-08-19 15:15:13 +02:00
|
|
|
|
|
|
|
|
/*!
|
|
|
|
|
* \file UsbBlaster.hpp
|
|
|
|
|
* \class UsbBlaster
|
|
|
|
|
* \brief altera/intel usb blaster implementation
|
|
|
|
|
* \author Gwenhael Goavec-Merou
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
class UsbBlaster : public JtagInterface {
|
|
|
|
|
public:
|
2022-10-15 16:17:32 +02:00
|
|
|
UsbBlaster(const cable_t &cable, const std::string &firmware_path,
|
2023-07-30 08:39:15 +02:00
|
|
|
int8_t verbose = 0);
|
2020-08-19 15:15:13 +02:00
|
|
|
virtual ~UsbBlaster();
|
|
|
|
|
|
|
|
|
|
int setClkFreq(uint32_t clkHZ) override;
|
2021-05-15 08:32:51 +02:00
|
|
|
uint32_t getClkFreq() override;
|
2020-08-19 15:15:13 +02:00
|
|
|
|
|
|
|
|
/*!
|
|
|
|
|
* \brief drive TMS to move in JTAG state machine
|
|
|
|
|
* \param tms serie of TMS state
|
|
|
|
|
* \param len number of TMS state
|
|
|
|
|
* \param flush_buffer force flushing the buffer
|
|
|
|
|
* \return number of state written
|
|
|
|
|
* */
|
2021-11-06 10:31:00 +01:00
|
|
|
int writeTMS(uint8_t *tms, uint32_t len, bool flush_buffer) override;
|
2020-08-19 15:15:13 +02:00
|
|
|
|
|
|
|
|
/* TDI */
|
|
|
|
|
int writeTDI(uint8_t *tx, uint8_t *rx, uint32_t len, bool end) override;
|
|
|
|
|
/*!
|
|
|
|
|
* \brief toggle clock with static tms and tdi
|
|
|
|
|
* \param tms TMS state
|
|
|
|
|
* \param tdi TDI state
|
|
|
|
|
* \param clk_len number of clock cycle
|
|
|
|
|
* \return number of clock cycle
|
|
|
|
|
* */
|
|
|
|
|
int toggleClk(uint8_t tms, uint8_t tdi, uint32_t clk_len) override;
|
|
|
|
|
|
|
|
|
|
/*!
|
|
|
|
|
* \brief return internal buffer size (in byte).
|
|
|
|
|
* \return _buffer_size divided by 2 (two byte for clk) and divided by 8 (one
|
|
|
|
|
* state == one byte)
|
|
|
|
|
*/
|
|
|
|
|
int get_buffer_size() override { return 63/8/2; }
|
|
|
|
|
|
|
|
|
|
bool isFull() override { return _nb_bit == 8*get_buffer_size();}
|
|
|
|
|
|
|
|
|
|
int flush() override;
|
|
|
|
|
|
|
|
|
|
private:
|
2021-05-13 16:06:29 +02:00
|
|
|
UsbBlaster_ll *ll_driver;
|
2020-08-19 15:15:13 +02:00
|
|
|
int writeByte(uint8_t *tdo, int nb_byte);
|
|
|
|
|
int writeBit(uint8_t *tdo, int nb_bit);
|
|
|
|
|
int write(bool read, int rd_len);
|
|
|
|
|
int setBitmode(uint8_t mode);
|
|
|
|
|
uint8_t *_in_buf;
|
|
|
|
|
|
2023-07-30 08:39:15 +02:00
|
|
|
int8_t _verbose;
|
2020-08-19 15:15:13 +02:00
|
|
|
uint8_t _tck_pin; /*!< tck pin: 1 << pin id */
|
|
|
|
|
uint8_t _tms_pin; /*!< tms pin: 1 << pin id */
|
|
|
|
|
uint8_t _tdi_pin; /*!< tdi pin: 1 << pin id */
|
|
|
|
|
int _nb_bit;
|
|
|
|
|
uint8_t _curr_tms;
|
2020-09-06 11:01:41 +02:00
|
|
|
uint16_t _buffer_size;
|
2020-08-19 15:15:13 +02:00
|
|
|
};
|
2021-05-13 16:06:29 +02:00
|
|
|
|
|
|
|
|
/*!
|
|
|
|
|
* \file UsbBlaster.hpp
|
|
|
|
|
* \class UsbBlasterI
|
|
|
|
|
* \brief altera/intel low level usb blaster class for blasterI
|
|
|
|
|
* \author Gwenhael Goavec-Merou
|
|
|
|
|
*/
|
|
|
|
|
class UsbBlasterI: public UsbBlaster_ll {
|
|
|
|
|
public:
|
|
|
|
|
UsbBlasterI();
|
|
|
|
|
virtual ~UsbBlasterI();
|
|
|
|
|
|
|
|
|
|
int setClkFreq(uint32_t clkHZ) override;
|
2021-05-15 08:32:51 +02:00
|
|
|
uint32_t getClkFreq() override;
|
2021-05-13 16:06:29 +02:00
|
|
|
int write(uint8_t *wr_buf, int wr_len,
|
|
|
|
|
uint8_t *rd_buf, int rd_len) override;
|
|
|
|
|
private:
|
|
|
|
|
/*
|
|
|
|
|
* \brief init and configure FT245
|
|
|
|
|
*/
|
|
|
|
|
void init_internal();
|
|
|
|
|
struct ftdi_context *_ftdi; /*!< ftid_context */
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
/*!
|
|
|
|
|
* \file UsbBlaster.hpp
|
|
|
|
|
* \class UsbBlasterII
|
|
|
|
|
* \brief altera/intel low level usb blaster class for blasterII
|
|
|
|
|
* \author Gwenhael Goavec-Merou
|
|
|
|
|
*/
|
|
|
|
|
class UsbBlasterII: public UsbBlaster_ll {
|
|
|
|
|
public:
|
|
|
|
|
UsbBlasterII(const std::string &firmware_path);
|
|
|
|
|
virtual ~UsbBlasterII();
|
|
|
|
|
|
|
|
|
|
int setClkFreq(uint32_t clkHZ) override;
|
2021-05-15 08:32:51 +02:00
|
|
|
uint32_t getClkFreq() override;
|
2021-05-13 16:06:29 +02:00
|
|
|
int write(uint8_t *wr_buf, int wr_len,
|
|
|
|
|
uint8_t *rd_buf, int rd_len) override;
|
|
|
|
|
private:
|
|
|
|
|
FX2_ll *fx2;
|
|
|
|
|
};
|
2020-08-19 15:15:13 +02:00
|
|
|
#endif
|