Hardware Design: SIE
Sign in or create your account | Project List | Help
Hardware Design: SIE Git Source Tree
Root/
| 1 | /* JTAG routines |
| 2 | |
| 3 | Copyright (C) 2004 Andrew Rogers |
| 4 | |
| 5 | This program is free software; you can redistribute it and/or modify |
| 6 | it under the terms of the GNU General Public License as published by |
| 7 | the Free Software Foundation; either version 2 of the License, or |
| 8 | (at your option) any later version. |
| 9 | |
| 10 | This program is distributed in the hope that it will be useful, |
| 11 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 13 | GNU General Public License for more details. |
| 14 | |
| 15 | You should have received a copy of the GNU General Public License |
| 16 | along with this program; if not, write to the Free Software |
| 17 | Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ |
| 18 | |
| 19 | |
| 20 | |
| 21 | #ifndef JTAG_H |
| 22 | #define JTAG_H |
| 23 | |
| 24 | #include <vector> |
| 25 | #include <stdio.h> |
| 26 | |
| 27 | #include "iobase.h" |
| 28 | |
| 29 | typedef unsigned char byte; |
| 30 | |
| 31 | class Jtag |
| 32 | { |
| 33 | private: |
| 34 | static const int MAXNUMDEVICES=1000; |
| 35 | protected: |
| 36 | struct chainParam_t |
| 37 | { |
| 38 | unsigned long idcode; // Store IDCODE |
| 39 | //byte bypass[4]; // The bypass instruction. Most instruction register lengths are a lot less than 32 bits. |
| 40 | int irlen; // instruction register length. |
| 41 | }; |
| 42 | std::vector<chainParam_t> devices; |
| 43 | IOBase *io; |
| 44 | int numDevices; |
| 45 | IOBase::tapState_t postDRState; |
| 46 | IOBase::tapState_t postIRState; |
| 47 | int deviceIndex; |
| 48 | FILE *logfile; |
| 49 | bool shiftDRincomplete; |
| 50 | public: |
| 51 | Jtag(IOBase *iob); |
| 52 | int getChain(); // Shift IDCODEs from devices |
| 53 | inline void setPostDRState(IOBase::tapState_t s){postDRState=s;} |
| 54 | inline void setPostIRState(IOBase::tapState_t s){postIRState=s;} |
| 55 | int setDeviceIRLength(int dev, int len); |
| 56 | unsigned long getDeviceID(int dev){ |
| 57 | if(dev>=devices.size())return 0; |
| 58 | return devices[dev].idcode; |
| 59 | } |
| 60 | int selectDevice(int dev); |
| 61 | void shiftDR(const byte *tdi, byte *tdo, int length, int align=0, bool exit=true);// Some devices use TCK for aligning data, for example, Xilinx FPGAs for configuration data. |
| 62 | void shiftIR(const byte *tdi, byte *tdo=0); // No length argumant required as IR length specified in chainParam_t |
| 63 | inline void longToByteArray(unsigned long l, byte *b){ |
| 64 | b[0]=(byte)(l&0xff); |
| 65 | b[1]=(byte)((l>>8)&0xff); |
| 66 | b[2]=(byte)((l>>16)&0xff); |
| 67 | b[3]=(byte)((l>>24)&0xff); |
| 68 | } |
| 69 | inline unsigned long byteArrayToLong(byte *b){ |
| 70 | return (b[3]<<24)+(b[2]<<16)+(b[1]<<8)+b[0]; |
| 71 | } |
| 72 | }; |
| 73 | |
| 74 | #endif //JTAG_H |
| 75 |
Branches:
master
