2021-06-26 15:24:07 +02:00
|
|
|
// SPDX-License-Identifier: Apache-2.0
|
2020-03-05 20:00:33 +01:00
|
|
|
/*
|
|
|
|
|
* Copyright (C) 2020 Gwenhael Goavec-Merou <gwenhael.goavec-merou@trabucayre.com>
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
#ifndef FTDIJTAGMPSSE_H
|
|
|
|
|
#define FTDIJTAGMPSSE_H
|
|
|
|
|
#include <ftdi.h>
|
|
|
|
|
#include <iostream>
|
|
|
|
|
#include <string>
|
|
|
|
|
#include <vector>
|
|
|
|
|
|
2022-10-15 16:17:32 +02:00
|
|
|
#include "cable.hpp"
|
2020-03-05 20:00:33 +01:00
|
|
|
#include "jtagInterface.hpp"
|
|
|
|
|
#include "ftdipp_mpsse.hpp"
|
|
|
|
|
|
|
|
|
|
/*!
|
|
|
|
|
* \file FtdiJtagMPSSE.hpp
|
|
|
|
|
* \class FtdiJtagMPSSE
|
|
|
|
|
* \brief concrete class between jtag implementation and FTDI capable bitbang mode
|
|
|
|
|
* \author Gwenhael Goavec-Merou
|
|
|
|
|
*/
|
|
|
|
|
|
2021-12-10 12:12:32 +01:00
|
|
|
class FtdiJtagMPSSE : public JtagInterface, public FTDIpp_MPSSE {
|
2020-03-05 20:00:33 +01:00
|
|
|
public:
|
2023-04-15 08:20:05 +02:00
|
|
|
FtdiJtagMPSSE(const cable_t &cable, const std::string &dev,
|
2022-03-11 07:45:48 +01:00
|
|
|
const std::string &serial, uint32_t clkHZ, bool invert_read_edge,
|
|
|
|
|
int8_t verbose = 0);
|
2020-03-05 20:00:33 +01:00
|
|
|
virtual ~FtdiJtagMPSSE();
|
|
|
|
|
|
2021-07-13 07:00:30 +02:00
|
|
|
int setClkFreq(uint32_t clkHZ) override;
|
2020-03-05 20:00:33 +01:00
|
|
|
|
2021-06-12 08:40:40 +02:00
|
|
|
uint32_t getClkFreq() override {return FTDIpp_MPSSE::getClkFreq();}
|
|
|
|
|
|
2020-03-05 20:00:33 +01:00
|
|
|
/* TMS */
|
2021-11-06 10:31:00 +01:00
|
|
|
int writeTMS(uint8_t *tms, uint32_t len, bool flush_buffer) override;
|
2020-05-31 15:57:21 +02:00
|
|
|
/* clock */
|
|
|
|
|
int toggleClk(uint8_t tms, uint8_t tdi, uint32_t clk_len) override;
|
2020-03-05 20:00:33 +01:00
|
|
|
/* TDI */
|
2020-05-31 15:57:21 +02:00
|
|
|
int writeTDI(uint8_t *tx, uint8_t *rx, uint32_t len, bool end) override;
|
2020-03-05 20:00:33 +01:00
|
|
|
|
2022-07-03 21:44:03 +02:00
|
|
|
/*!
|
|
|
|
|
* \brief send TMD and TDI and receive tdo bits;
|
|
|
|
|
* \param tms: array of TMS values (used to write)
|
|
|
|
|
* \param tdi: array of TDI values (used to write)
|
|
|
|
|
* \param tdo: array of TDO values (used when read)
|
|
|
|
|
* \param len: number of bit to send/receive
|
|
|
|
|
* \return true with full buffers are sent, false otherwise
|
|
|
|
|
*/
|
|
|
|
|
virtual bool writeTMSTDI(const uint8_t *tms, const uint8_t *tdi, uint8_t *tdo,
|
|
|
|
|
uint32_t len) override;
|
2020-03-05 20:00:33 +01:00
|
|
|
/*!
|
|
|
|
|
* \brief return internal buffer size (in byte).
|
|
|
|
|
* \return _buffer_size -3 for mpsse cmd + size, -1 for potential SEND_IMMEDIATE
|
|
|
|
|
*/
|
|
|
|
|
int get_buffer_size() override { return _buffer_size-3; }
|
|
|
|
|
|
|
|
|
|
bool isFull() override { return false;}
|
|
|
|
|
|
2020-05-31 15:57:21 +02:00
|
|
|
int flush() override;
|
|
|
|
|
|
2020-03-05 20:00:33 +01:00
|
|
|
private:
|
2022-10-15 16:17:32 +02:00
|
|
|
void init_internal(const mpsse_bit_config &cable);
|
2022-07-03 21:44:03 +02:00
|
|
|
/* writeTMSTDI specifics */
|
|
|
|
|
/*!
|
|
|
|
|
* \brief try to append tms buffer, flush content if > 6
|
|
|
|
|
* \param buffer: current tms buffer
|
|
|
|
|
* \param bit: bit to append
|
|
|
|
|
* \param offset: bits already stored
|
|
|
|
|
* \param tdo: buffer used when reading after flush
|
|
|
|
|
* \param len: length
|
|
|
|
|
* \return < 0 if transaction fails, offset + 1 when append and 0 when flush
|
|
|
|
|
*/
|
|
|
|
|
int32_t update_tms_buff(uint8_t *buffer, uint8_t bit,
|
|
|
|
|
uint32_t offset, uint8_t tdi, uint8_t *tdo, bool end=false);
|
|
|
|
|
uint32_t update_tdo_buff(uint8_t *buffer, uint8_t *tdo, uint32_t len);
|
2021-07-13 07:00:30 +02:00
|
|
|
/*!
|
|
|
|
|
* \brief configure read and write edge (pos or neg), with freq < 15MHz
|
|
|
|
|
* neg is used for write and pos to sample. with freq >= 15MHz
|
|
|
|
|
* pos is used for write and neg to sample
|
|
|
|
|
*/
|
|
|
|
|
void config_edge();
|
2020-03-05 20:00:33 +01:00
|
|
|
bool _ch552WA; /* avoid errors with SiPeed tangNano */
|
2021-07-13 07:00:30 +02:00
|
|
|
uint8_t _write_mode; /**< write edge configuration */
|
|
|
|
|
uint8_t _read_mode; /**< read edge configuration */
|
2022-03-11 07:45:48 +01:00
|
|
|
bool _invert_read_edge; /**< read edge selection (false: pos, true: neg) */
|
2022-07-03 21:44:03 +02:00
|
|
|
/* writeTMSTDI specifics */
|
|
|
|
|
uint32_t _tdo_pos;
|
|
|
|
|
uint8_t _curr_tdi;
|
|
|
|
|
uint8_t _curr_tms;
|
2020-03-05 20:00:33 +01:00
|
|
|
};
|
|
|
|
|
#endif
|