Renamed file fx2.XXX to fpgalink.XXX
Created a base class FpgaLink to encapsulate the general fpgalink functionality (could be used to create a avr cable) Converted the printf calls to printError and printInfo calls.
This commit is contained in:
parent
7718901d82
commit
82df51d4f5
|
|
@ -146,7 +146,7 @@ target_link_libraries(openFPGALoader
|
||||||
if (ENABLE_FPGALINK)
|
if (ENABLE_FPGALINK)
|
||||||
find_library(LIBFPGALINK libfpgalink)
|
find_library(LIBFPGALINK libfpgalink)
|
||||||
if (${LIBFPGALINK} STREQUAL "LIBFPGALINK-NOTFOUND")
|
if (${LIBFPGALINK} STREQUAL "LIBFPGALINK-NOTFOUND")
|
||||||
message("libfpgalink not found, disabling fx2 support")
|
message("libfpgalink not found, disabling fpgalink support")
|
||||||
set(ENABLE_FPGALINK OFF)
|
set(ENABLE_FPGALINK OFF)
|
||||||
else()
|
else()
|
||||||
message("libfpgalink found: ${LIBFPGALINK}")
|
message("libfpgalink found: ${LIBFPGALINK}")
|
||||||
|
|
@ -155,8 +155,8 @@ if (ENABLE_FPGALINK)
|
||||||
target_include_directories(openFPGALoader PRIVATE ${INC_DIR})
|
target_include_directories(openFPGALoader PRIVATE ${INC_DIR})
|
||||||
target_link_libraries(openFPGALoader ${LIBFPGALINK})
|
target_link_libraries(openFPGALoader ${LIBFPGALINK})
|
||||||
target_sources(openFPGALoader PRIVATE
|
target_sources(openFPGALoader PRIVATE
|
||||||
src/fx2.cpp
|
src/fpgalink.cpp
|
||||||
src/fx2.hpp)
|
src/fpgalink.hpp)
|
||||||
endif()
|
endif()
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -23,8 +23,10 @@
|
||||||
#include <map>
|
#include <map>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
#include <string>
|
#include <string>
|
||||||
|
#include <cstdio>
|
||||||
|
|
||||||
#include "FX2.hpp"
|
#include "display.hpp"
|
||||||
|
#include "fpgalink.hpp"
|
||||||
#include "makestuff/libfpgalink.h"
|
#include "makestuff/libfpgalink.h"
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -36,7 +38,8 @@ using namespace std;
|
||||||
#define CHECK_STATUS(fStatus)\
|
#define CHECK_STATUS(fStatus)\
|
||||||
if (fStatus) \
|
if (fStatus) \
|
||||||
{ \
|
{ \
|
||||||
cerr << error << endl;\
|
printError("Error: ", false);\
|
||||||
|
printError(error);\
|
||||||
flFreeError(error);\
|
flFreeError(error);\
|
||||||
fStatus = progClose(handle, &error);\
|
fStatus = progClose(handle, &error);\
|
||||||
if (error)\
|
if (error)\
|
||||||
|
|
@ -46,9 +49,73 @@ using namespace std;
|
||||||
throw std::exception();\
|
throw std::exception();\
|
||||||
}
|
}
|
||||||
|
|
||||||
|
FpgaLink::FpgaLink(bool verbose):
|
||||||
|
_verbose(verbose)
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
int FpgaLink::writeTMS(uint8_t *tms, int len, bool flush_buffer)
|
||||||
|
{
|
||||||
|
(void)flush_buffer;
|
||||||
|
FLStatus fStatus;
|
||||||
|
const char *error = NULL;
|
||||||
|
uint32_t bitPattern = 0;
|
||||||
|
int ulen = len;
|
||||||
|
int i = 0;
|
||||||
|
while (ulen > 0)
|
||||||
|
{
|
||||||
|
{bitPattern = tms[i++];}
|
||||||
|
ulen-=8;
|
||||||
|
if (ulen > 0) {bitPattern |= tms[i++] << 8;}
|
||||||
|
ulen-=8;
|
||||||
|
if (ulen > 0) {bitPattern |= tms[i++] << 16;}
|
||||||
|
ulen-=8;
|
||||||
|
if (ulen > 0) {bitPattern |= tms[i++] << 24;}
|
||||||
|
ulen-=8;
|
||||||
|
fStatus = jtagClockFSM(handle, bitPattern, (ulen > 0) ? 32 : 32 + ulen, &error);
|
||||||
|
CHECK_STATUS(fStatus);
|
||||||
|
}
|
||||||
|
|
||||||
|
return len;
|
||||||
|
}
|
||||||
|
|
||||||
|
int FpgaLink::toggleClk(uint8_t tms, uint8_t tdi, uint32_t clk_len)
|
||||||
|
{
|
||||||
|
(void)tms;
|
||||||
|
(void)tdi;
|
||||||
|
FLStatus fStatus;
|
||||||
|
const char *error = NULL;
|
||||||
|
fStatus = jtagClocks(handle, clk_len, &error);
|
||||||
|
CHECK_STATUS(fStatus);
|
||||||
|
return EXIT_SUCCESS;
|
||||||
|
}
|
||||||
|
|
||||||
|
int FpgaLink::flush()
|
||||||
|
{
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
int FpgaLink::writeTDI(uint8_t *tx, uint8_t *rx, uint32_t len, bool end)
|
||||||
|
{
|
||||||
|
FLStatus fStatus;
|
||||||
|
const char *error = NULL;
|
||||||
|
if (rx)
|
||||||
|
fStatus = jtagShiftInOut(handle, len, tx, rx, end, &error);
|
||||||
|
else
|
||||||
|
{
|
||||||
|
fStatus = jtagShiftInOnly(handle, len, tx, end, &error);
|
||||||
|
}
|
||||||
|
|
||||||
|
CHECK_STATUS(fStatus);
|
||||||
|
|
||||||
|
return EXIT_SUCCESS;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
FX2Cable::FX2Cable(bool verbose, const jtag_pins_conf_t *pin_conf, const char *ivp, const char *vp):
|
FX2Cable::FX2Cable(bool verbose, const jtag_pins_conf_t *pin_conf, const char *ivp, const char *vp):
|
||||||
_verbose(verbose)
|
FpgaLink::FpgaLink(verbose)
|
||||||
{
|
{
|
||||||
FLStatus fStatus;
|
FLStatus fStatus;
|
||||||
const char *error = NULL;
|
const char *error = NULL;
|
||||||
|
|
@ -57,22 +124,24 @@ FX2Cable::FX2Cable(bool verbose, const jtag_pins_conf_t *pin_conf, const char *i
|
||||||
char portConfig[10];
|
char portConfig[10];
|
||||||
|
|
||||||
vp = "1D50:602B";
|
vp = "1D50:602B";
|
||||||
|
std::string svp(vp);
|
||||||
|
|
||||||
printf("Attempting to open connection to FPGALink device %s...\n", vp);
|
printInfo("Attempting to open connection to FPGALink device " + svp +"...", false);
|
||||||
fStatus = flOpen(vp, &handle, NULL);
|
fStatus = flOpen(vp, &handle, NULL);
|
||||||
if ( fStatus ) {
|
if ( fStatus ) {
|
||||||
{
|
{
|
||||||
int count = 60;
|
int count = 60;
|
||||||
uint8 flag;
|
uint8 flag;
|
||||||
ivp = "04b4:8613";
|
ivp = "04b4:8613";
|
||||||
printf("Loading firmware into %s...\n", ivp);
|
std::string sivp(ivp);
|
||||||
|
printInfo("Loading firmware into " + sivp, true);
|
||||||
fStatus = flLoadStandardFirmware(ivp, vp, &error);
|
fStatus = flLoadStandardFirmware(ivp, vp, &error);
|
||||||
CHECK_STATUS(fStatus);
|
CHECK_STATUS(fStatus);
|
||||||
|
|
||||||
printf("Awaiting renumeration");
|
printInfo("Awaiting renumeration");
|
||||||
flSleep(1000);
|
flSleep(1000);
|
||||||
do {
|
do {
|
||||||
printf(".");
|
printInfo(".", false);
|
||||||
fflush(stdout);
|
fflush(stdout);
|
||||||
fStatus = flIsDeviceAvailable(vp, &flag, &error);
|
fStatus = flIsDeviceAvailable(vp, &flag, &error);
|
||||||
CHECK_STATUS(fStatus);
|
CHECK_STATUS(fStatus);
|
||||||
|
|
@ -81,17 +150,20 @@ FX2Cable::FX2Cable(bool verbose, const jtag_pins_conf_t *pin_conf, const char *i
|
||||||
} while ( !flag && count );
|
} while ( !flag && count );
|
||||||
printf("\n");
|
printf("\n");
|
||||||
if ( !flag ) {
|
if ( !flag ) {
|
||||||
fprintf(stderr, "FPGALink device did not renumerate properly as %s\n", vp);
|
printError("Error: FPGALink device did not renumerate properly as " + svp, true);
|
||||||
flClose(handle);
|
flClose(handle);
|
||||||
handle = NULL;
|
handle = NULL;
|
||||||
throw std::exception();
|
throw std::exception();
|
||||||
}
|
}
|
||||||
|
|
||||||
printf("Attempting to open connection to FPGLink device %s again...\n", vp);
|
printInfo("Attempting to open connection to FPGLink device " + svp + " again...", false);
|
||||||
fStatus = flOpen(vp, &handle, &error);
|
fStatus = flOpen(vp, &handle, &error);
|
||||||
CHECK_STATUS(fStatus);
|
CHECK_STATUS(fStatus);
|
||||||
|
printInfo("success", true);
|
||||||
}
|
}
|
||||||
}
|
} else {
|
||||||
|
printInfo("success", true);
|
||||||
|
}
|
||||||
|
|
||||||
transcode_pin_config(pin_conf, portConfig);
|
transcode_pin_config(pin_conf, portConfig);
|
||||||
fStatus = progOpen(handle, portConfig, &error);
|
fStatus = progOpen(handle, portConfig, &error);
|
||||||
|
|
@ -117,59 +189,3 @@ FX2Cable::~FX2Cable()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
int FX2Cable::writeTMS(uint8_t *tms, int len, bool flush_buffer)
|
|
||||||
{
|
|
||||||
(void)flush_buffer;
|
|
||||||
FLStatus fStatus;
|
|
||||||
const char *error = NULL;
|
|
||||||
uint32_t bitPattern = 0;
|
|
||||||
int ulen = len;
|
|
||||||
int i = 0;
|
|
||||||
while (ulen > 0)
|
|
||||||
{
|
|
||||||
{bitPattern = tms[i++];}
|
|
||||||
ulen-=8;
|
|
||||||
if (ulen > 0) {bitPattern |= tms[i++] << 8;}
|
|
||||||
ulen-=8;
|
|
||||||
if (ulen > 0) {bitPattern |= tms[i++] << 16;}
|
|
||||||
ulen-=8;
|
|
||||||
if (ulen > 0) {bitPattern |= tms[i++] << 24;}
|
|
||||||
ulen-=8;
|
|
||||||
fStatus = jtagClockFSM(handle, bitPattern, (ulen > 0) ? 32 : 32 + ulen, &error);
|
|
||||||
CHECK_STATUS(fStatus);
|
|
||||||
}
|
|
||||||
|
|
||||||
return len;
|
|
||||||
}
|
|
||||||
|
|
||||||
int FX2Cable::toggleClk(uint8_t tms, uint8_t tdi, uint32_t clk_len)
|
|
||||||
{
|
|
||||||
(void)tms;
|
|
||||||
(void)tdi;
|
|
||||||
FLStatus fStatus;
|
|
||||||
const char *error = NULL;
|
|
||||||
fStatus = jtagClocks(handle, clk_len, &error);
|
|
||||||
CHECK_STATUS(fStatus);
|
|
||||||
return EXIT_SUCCESS;
|
|
||||||
}
|
|
||||||
|
|
||||||
int FX2Cable::flush()
|
|
||||||
{
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
int FX2Cable::writeTDI(uint8_t *tx, uint8_t *rx, uint32_t len, bool end)
|
|
||||||
{
|
|
||||||
FLStatus fStatus;
|
|
||||||
const char *error = NULL;
|
|
||||||
if (rx)
|
|
||||||
fStatus = jtagShiftInOut(handle, len, tx, rx, end, &error);
|
|
||||||
else
|
|
||||||
{
|
|
||||||
fStatus = jtagShiftInOnly(handle, len, tx, end, &error);
|
|
||||||
}
|
|
||||||
|
|
||||||
CHECK_STATUS(fStatus);
|
|
||||||
|
|
||||||
return EXIT_SUCCESS;
|
|
||||||
}
|
|
||||||
|
|
@ -30,11 +30,10 @@
|
||||||
* \brief concrete class between jtag implementation and FX2 cable
|
* \brief concrete class between jtag implementation and FX2 cable
|
||||||
*/
|
*/
|
||||||
|
|
||||||
class FX2Cable : public JtagInterface {
|
class FpgaLink : public JtagInterface{
|
||||||
public:
|
|
||||||
FX2Cable(bool verbose, const jtag_pins_conf_t *pin_conf, const char *ivp = NULL, const char *vp = NULL);
|
|
||||||
virtual ~FX2Cable();
|
|
||||||
|
|
||||||
|
public:
|
||||||
|
FpgaLink(bool verbose);
|
||||||
int setClkFreq(uint32_t clkHZ) override{(void)clkHZ; return 0;}
|
int setClkFreq(uint32_t clkHZ) override{(void)clkHZ; return 0;}
|
||||||
int setClkFreq(uint32_t clkHZ, char use_divide_by_5) override {(void)clkHZ; (void)use_divide_by_5;return 0;}
|
int setClkFreq(uint32_t clkHZ, char use_divide_by_5) override {(void)clkHZ; (void)use_divide_by_5;return 0;}
|
||||||
|
|
||||||
|
|
@ -56,11 +55,18 @@ class FX2Cable : public JtagInterface {
|
||||||
|
|
||||||
int flush() override;
|
int flush() override;
|
||||||
|
|
||||||
private:
|
protected:
|
||||||
bool _verbose;
|
bool _verbose;
|
||||||
|
|
||||||
int write(uint8_t *in_buf, uint8_t *out_buf, int len, int rd_len);
|
|
||||||
void transcode_pin_config(const jtag_pins_conf_t *pin_conf, char* buffer);
|
|
||||||
struct FLContext *handle = NULL;
|
struct FLContext *handle = NULL;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
class FX2Cable : public FpgaLink {
|
||||||
|
public:
|
||||||
|
FX2Cable(bool verbose, const jtag_pins_conf_t *pin_conf, const char *ivp = NULL, const char *vp = NULL);
|
||||||
|
virtual ~FX2Cable();
|
||||||
|
|
||||||
|
private:
|
||||||
|
void transcode_pin_config(const jtag_pins_conf_t *pin_conf, char* buffer);
|
||||||
|
};
|
||||||
#endif // SRC_FX2CABLE_HPP_
|
#endif // SRC_FX2CABLE_HPP_
|
||||||
|
|
@ -34,7 +34,7 @@
|
||||||
#include "usbBlaster.hpp"
|
#include "usbBlaster.hpp"
|
||||||
|
|
||||||
#ifdef USE_LIBFPGALINK
|
#ifdef USE_LIBFPGALINK
|
||||||
#include "fx2.hpp"
|
#include "fpgalink.hpp"
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
using namespace std;
|
using namespace std;
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue