2020-08-19 15:15:13 +02:00
|
|
|
/*
|
|
|
|
|
* Copyright (C) 2020 Gwenhael Goavec-Merou <gwenhael.goavec-merou@trabucayre.com>
|
|
|
|
|
*
|
|
|
|
|
* This program is free software: you can redistribute it and/or modify
|
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
|
* the Free Software Foundation, either version 3 of the License, or
|
|
|
|
|
* (at your option) any later version.
|
|
|
|
|
*
|
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
|
*
|
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
#ifndef USBBLASTER_H
|
|
|
|
|
#define USBBLASTER_H
|
|
|
|
|
#include <ftdi.h>
|
|
|
|
|
#include <iostream>
|
|
|
|
|
#include <string>
|
|
|
|
|
#include <vector>
|
|
|
|
|
|
|
|
|
|
#include "board.hpp"
|
|
|
|
|
#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:
|
2021-05-13 16:06:29 +02:00
|
|
|
UsbBlaster(int vid, int pid, const std::string &firmware_path,
|
|
|
|
|
bool verbose = false);
|
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
|
|
|
|
|
* */
|
|
|
|
|
int writeTMS(uint8_t *tms, int len, bool flush_buffer) override;
|
|
|
|
|
|
|
|
|
|
/* 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;
|
|
|
|
|
|
|
|
|
|
bool _verbose;
|
|
|
|
|
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
|