1 // SPDX-License-Identifier: Apache-2.0 2 /* 3 * Copyright (C) 2020 Gwenhael Goavec-Merou <gwenhael.goavec-merou@trabucayre.com> 4 */ 5 6 #ifndef FTDIJTAGBITBANG_H 7 #define FTDIJTAGBITBANG_H 8 #include <ftdi.h> 9 #include <iostream> 10 #include <string> 11 #include <vector> 12 13 #include "board.hpp" 14 #include "jtagInterface.hpp" 15 #include "ftdipp_mpsse.hpp" 16 17 /*! 18 * \file FtdiJtagBitBang.hpp 19 * \class FtdiJtagBitBang 20 * \brief concrete class between jtag implementation and FTDI capable bitbang mode 21 * \author Gwenhael Goavec-Merou 22 */ 23 24 class FtdiJtagBitBang : public JtagInterface, private FTDIpp_MPSSE { 25 public: 26 FtdiJtagBitBang(const FTDIpp_MPSSE::mpsse_bit_config &cable, 27 const jtag_pins_conf_t *pin_conf, std::string dev, const std::string &serial, 28 uint32_t clkHZ, uint8_t verbose = 0); 29 virtual ~FtdiJtagBitBang(); 30 31 int setClkFreq(uint32_t clkHZ) override; 32 33 /* TMS */ 34 int writeTMS(uint8_t *tms, uint32_t len, bool flush_buffer) override; 35 36 /* TDI */ 37 int writeTDI(uint8_t *tx, uint8_t *rx, uint32_t len, bool end) override; 38 int toggleClk(uint8_t tms, uint8_t tdo, uint32_t clk_len) override; 39 40 /*! 41 * \brief return internal buffer size (in byte). 42 * \return _buffer_size divided by 2 (two byte for clk) and divided by 8 (one 43 * state == one byte) 44 */ get_buffer_size()45 int get_buffer_size() override { return _buffer_size/8/2; } 46 isFull()47 bool isFull() override { return _num == 8*get_buffer_size();} 48 49 int flush() override; 50 51 private: 52 int write(uint8_t *tdo, int nb_bit); 53 int setBitmode(uint8_t mode); 54 55 uint8_t _bitmode; 56 uint8_t _tck_pin; /*!< tck pin: 1 << pin id */ 57 uint8_t _tms_pin; /*!< tms pin: 1 << pin id */ 58 uint8_t _tdo_pin; /*!< tdo pin: 1 << pin id */ 59 uint8_t _tdi_pin; /*!< tdi pin: 1 << pin id */ 60 uint8_t _curr_tms; 61 int _rx_size; 62 }; 63 #endif 64