diff --git a/CMakeLists.txt b/CMakeLists.txt index c8f1a07..d7d8607 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -131,7 +131,8 @@ ADD_CUSTOM_COMMAND(OUTPUT cables.h INCLUDE_DIRECTORIES(BEFORE ${CMAKE_CURRENT_BINARY_DIR}) add_library(xc3sproglib STATIC sysfs.cpp ioftdi.cpp iofx2.cpp - devicedb.cpp jtag.cpp jedecfile.cpp bitfile.cpp + devicedb.cpp jtag.cpp jedecfile.cpp bitfile.cpp + iomatrixpi.cpp iomatrixvoice.cpp iowiringpi.cpp iobase.cpp progalgxc95x.cpp utilities.cpp progalgxcf.cpp progalgxcfp.cpp progalgxc3s.cpp progalgavr.cpp progalgxc2c.cpp mapfile_xc2c.cpp @@ -139,6 +140,8 @@ add_library(xc3sproglib STATIC sysfs.cpp ioftdi.cpp iofx2.cpp cabledb.cpp pdioverjtag.cpp xmega_pdi_nvm.cpp ${CONDITIONAL_FILES} devices.h cables.h) +set(LIBS ${LIBS} wiringPiDev wiringPi) + add_executable(xc2c_warp xc2c_warp.cpp) target_link_libraries(xc2c_warp xc3sproglib ${CONDITIONAL_LIBS}) diff --git a/cabledb.cpp b/cabledb.cpp index 28449e8..eb6b21f 100644 --- a/cabledb.cpp +++ b/cabledb.cpp @@ -157,6 +157,11 @@ CABLES_TYPES CableDB::getCableType(const char *given_name) return CABLE_XPC; if (strcasecmp(given_name, "sysfsgpio") == 0) return CABLE_SYSFS_GPIO; + if (strcasecmp(given_name, "matrix_pi") == 0) + return CABLE_MATRIX_PI; + if (strcasecmp(given_name, "matrix_voice") == 0) + return CABLE_MATRIX_VOICE; + return CABLE_UNKNOWN; } @@ -168,6 +173,8 @@ const char *CableDB::getCableName(const CABLES_TYPES type ) case CABLE_FTDI: return "ftdi"; case CABLE_FX2: return "fx2"; case CABLE_XPC: return "xpc"; + case CABLE_MATRIX_PI: return "matrix_pi"; + case CABLE_MATRIX_VOICE: return "matrix_voice"; case CABLE_SYSFS_GPIO: return "sysfsgpio"; case CABLE_NONE: return "none"; case CABLE_UNKNOWN: return "unknown"; diff --git a/cabledb.h b/cabledb.h index d5fc73d..495b6cd 100644 --- a/cabledb.h +++ b/cabledb.h @@ -31,7 +31,9 @@ enum CABLES_TYPES CABLE_FTDI, CABLE_FX2, CABLE_XPC, - CABLE_SYSFS_GPIO + CABLE_SYSFS_GPIO, + CABLE_MATRIX_PI, + CABLE_MATRIX_VOICE }; struct cable_t diff --git a/cablelist.txt b/cablelist.txt index 2d66a53..50fa56f 100644 --- a/cablelist.txt +++ b/cablelist.txt @@ -43,5 +43,6 @@ jtaghs2 ftdi 6000000 0x0403:0x6014:Digilent USB Device:0:0xe8:0xeb:0x00 turtelizer ftdi 1500000 0x0403:0xbdc8:Turtelizer JTAG/RS232 Adapter:0:0x00:0x10:0x00:0x0 arm-usb-ocd-h ftdi 1500000 0x15ba:0x002b::1:0x00:0x10:0x00:0x08 tumpa ftdi 1500000 0x0403:0x8a98:TIAO USB Multi-Protocol Adapter:1 -sysfsgpio sysfsgpio 0 NULL - +sysfsgpio sysfsgpio 0 NULL +matrix_pi matrix_pi 0 NULL +matrix_voice matrix_voice 0 NULL diff --git a/iomatrixpi.cpp b/iomatrixpi.cpp new file mode 100644 index 0000000..2759cca --- /dev/null +++ b/iomatrixpi.cpp @@ -0,0 +1,7 @@ +#include "iomatrixpi.h" + +IOMatrixPi::IOMatrixPi() + : IOWiringPi(4, 17, 22, 27) +{ +} + diff --git a/iomatrixpi.h b/iomatrixpi.h new file mode 100644 index 0000000..33c84ab --- /dev/null +++ b/iomatrixpi.h @@ -0,0 +1,12 @@ +#ifndef __IO_MATRIX_PI__ +#define __IO_MATRIX_PI__ + +#include "iowiringpi.h" + +class IOMatrixPi : public IOWiringPi +{ + public: + IOMatrixPi(); +}; + +#endif diff --git a/iomatrixvoice.cpp b/iomatrixvoice.cpp new file mode 100644 index 0000000..3cc31d8 --- /dev/null +++ b/iomatrixvoice.cpp @@ -0,0 +1,7 @@ +#include "iomatrixvoice.h" + +IOMatrixVoice::IOMatrixVoice() + : IOWiringPi(27, 4, 17, 22) +{ +} + diff --git a/iomatrixvoice.h b/iomatrixvoice.h new file mode 100644 index 0000000..2f9d0b7 --- /dev/null +++ b/iomatrixvoice.h @@ -0,0 +1,12 @@ +#ifndef __IO_MATRIX_VOICE__ +#define __IO_MATRIX_VOICE__ + +#include "iowiringpi.h" + +class IOMatrixVoice : public IOWiringPi +{ + public: + IOMatrixVoice(); +}; + +#endif diff --git a/iowiringpi.cpp b/iowiringpi.cpp new file mode 100644 index 0000000..49ea760 --- /dev/null +++ b/iowiringpi.cpp @@ -0,0 +1,90 @@ +#include "iowiringpi.h" + +#include + +IOWiringPi::IOWiringPi(int tms, int tck, int tdi, int tdo) + : TMSPin(tms), TCKPin(tck), TDIPin(tdi), TDOPin(tdo) +{ + wiringPiSetupGpio(); + pinMode(TDIPin, OUTPUT); + pinMode(TMSPin, OUTPUT); + pinMode(TCKPin, OUTPUT); + pinMode(TDOPin, INPUT); +} + +IOWiringPi::~IOWiringPi() +{ +} + +void IOWiringPi::txrx_block(const unsigned char *tdi, unsigned char *tdo, int length, bool last) +{ + int i=0; + int j=0; + unsigned char tdo_byte=0; + unsigned char tdi_byte; + if (tdi) + tdi_byte = tdi[j]; + + while(i>1; + i++; + if((i%8)==0){ // Next byte + if(tdo) + tdo[j]=tdo_byte; // Save the TDO byte + tdo_byte=0; + j++; + if (tdi) + tdi_byte=tdi[j]; // Get the next TDI byte + } + }; + tdo_byte=tdo_byte+(txrx(last, (tdi_byte&1)==1)<<(i%8)); + if(tdo) + tdo[j]=tdo_byte; + + digitalWrite(TCKPin, LOW); + return; +} + +void IOWiringPi::tx_tms(unsigned char *pat, int length, int force) +{ + int i; + unsigned char tms; + for (i = 0; i < length; i++) + { + if ((i & 0x7) == 0) + tms = pat[i>>3]; + tx((tms & 0x01), true); + tms = tms >> 1; + } + + digitalWrite(TCKPin, LOW); +} + +void IOWiringPi::tx(bool tms, bool tdi) +{ + digitalWrite(TCKPin, LOW); + + if(tdi) + digitalWrite(TDIPin, HIGH); + else + digitalWrite(TDIPin, LOW); + + if(tms) + digitalWrite(TMSPin, HIGH); + else + digitalWrite(TMSPin, LOW); + + digitalWrite(TCKPin, HIGH); +} + + +bool IOWiringPi::txrx(bool tms, bool tdi) +{ + tx(tms, tdi); + + return digitalRead(TDOPin); +} + + diff --git a/iowiringpi.h b/iowiringpi.h new file mode 100644 index 0000000..08e74de --- /dev/null +++ b/iowiringpi.h @@ -0,0 +1,25 @@ +#ifndef __IO_WIRING_PI__ +#define __IO_WIRING_PI__ + +#include "iobase.h" + +class IOWiringPi : public IOBase +{ + public: + IOWiringPi(int tms, int tck, int tdi, int tdo); + virtual ~IOWiringPi(); + + protected: + void tx(bool tms, bool tdi); + bool txrx(bool tms, bool tdi); + + void txrx_block(const unsigned char *tdi, unsigned char *tdo, int length, bool last); + void tx_tms(unsigned char *pat, int length, int force); + + int TMSPin; + int TCKPin; + int TDIPin; + int TDOPin; +}; + +#endif diff --git a/utilities.cpp b/utilities.cpp index a78f707..1ce57c0 100644 --- a/utilities.cpp +++ b/utilities.cpp @@ -12,6 +12,8 @@ #include "ioftdi.h" #include "ioxpc.h" #include "sysfs.h" +#include "iomatrixpi.h" +#include "iomatrixvoice.h" #include "utilities.h" extern char *optarg; @@ -91,6 +93,18 @@ int getIO( std::auto_ptr *io, struct cable_t * cable, char const *dev, io->get()->setVerbose(verbose); res = io->get()->Init(cable, serial, use_freq); } + else if(cable->cabletype == CABLE_MATRIX_PI) + { + io->reset(new IOMatrixPi()); + io->get()->setVerbose(verbose); + res = io->get()->Init(cable, serial, use_freq); + } + else if(cable->cabletype == CABLE_MATRIX_VOICE) + { + io->reset(new IOMatrixVoice()); + io->get()->setVerbose(verbose); + res = io->get()->Init(cable, serial, use_freq); + } else { fprintf(stderr, "Unknown Cable \"%s\" \n", getCableName(cable->cabletype));