URL
https://opencores.org/ocsvn/an-fpga-implementation-of-low-latency-noc-based-mpsoc/an-fpga-implementation-of-low-latency-noc-based-mpsoc/trunk
Subversion Repositories an-fpga-implementation-of-low-latency-noc-based-mpsoc
Compare Revisions
- This comparison shows the changes necessary to convert path
/an-fpga-implementation-of-low-latency-noc-based-mpsoc/trunk/mpsoc/src_c
- from Rev 25 to Rev 28
- ↔ Reverse comparison
Rev 25 → Rev 28
/Makefile
1,6 → 1,6
TOOLCHAIN:=${PRONOC_WORK}/toolchain |
SUBDIRS = ihex2bin ihex2mif jtag plot |
BIN_FILES = ihex2bin/ihex2bin ihex2mif/ihex2mif jtag/jtag_main |
BIN_FILES = ihex2bin/ihex2bin ihex2mif/ihex2mif |
PRONOC_WORK_BIN := $(TOOLCHAIN)/bin |
|
|
14,5 → 14,6
binfiles: |
|
mkdir -p $(PRONOC_WORK_BIN) |
cp -f $(BIN_FILES) $(PRONOC_WORK_BIN) |
|
cp -f $(BIN_FILES) $(PRONOC_WORK_BIN) |
cp jtag/simple_jtag/jtag_main $(PRONOC_WORK_BIN)/jtag_main |
# cp jtag/urjtag-0.10/src/jtag_main $(PRONOC_WORK_BIN)/jtag_main |
/jtag/jinfo
Cannot display: file marked as a binary type.
svn:mime-type = application/octet-stream
jtag/jinfo
Property changes :
Deleted: svn:executable
## -1 +0,0 ##
-*
\ No newline at end of property
Deleted: svn:mime-type
## -1 +0,0 ##
-application/octet-stream
\ No newline at end of property
Index: jtag/jtag-virtual.c
===================================================================
--- jtag/jtag-virtual.c (revision 25)
+++ jtag/jtag-virtual.c (nonexistent)
@@ -1,139 +0,0 @@
-/* Copyright 2012 Brian Swetland
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#include
-#include
-
-#include "jtag.h"
-
-int jtag_dr_8x4(unsigned *out) {
- unsigned bits = 0;
- unsigned tmp;
- int n, r;
-
- for (n = 0; n < 8; n++) {
- if ((r = jtag_dr(4, 0, &tmp)) < 0) return r;
- bits |= (tmp <<= (n * 4));
- }
- *out = bits;
- return 0;
-}
-
-/* number of bits needed given a max value 1-255 */
-unsigned needbits(unsigned max) {
- if (max > 127) return 8;
- if (max > 63) return 7;
- if (max > 31) return 6;
- if (max > 15) return 5;
- if (max > 7) return 4;
- if (max > 3) return 3;
- if (max > 1) return 2;
- return 1;
-}
-
-static unsigned ir_width = 10;
-
-static unsigned hub_version = 0;
-static unsigned hub_nodecount = 0;
-static unsigned hub_mfg = 0;
-
-static unsigned vir_width = 0;
-static unsigned vir_width_addr = 0;
-static unsigned vir_width_ir = 0;
-static unsigned vir_addr = 0;
-
-
-int jtag_vir(unsigned vir) {
- int r;
- if ((r = jtag_ir(ir_width, 14)) < 0) return r;
- if ((r = jtag_dr(vir_width, vir_addr | vir, 0)) < 0) return r;
- return 0;
-}
-
-int jtag_vdr(unsigned sz, unsigned bits, unsigned *out) {
- int r;
- if ((r = jtag_ir(ir_width, 12)) < 0) return r;
- if ((r = jtag_dr(sz, bits, out)) < 0) return r;
- return 0;
-}
-
-int jtag_vdr_long(unsigned sz, unsigned * bits, unsigned *out, int words) {
- int r;
- if ((r = jtag_ir(ir_width, 12)) < 0) return r;
- if ((r = jtag_dr_long(sz, bits, out, words)) < 0) return r;
- return 0;
-}
-
-int jtag_open_virtual_device(unsigned iid) {
- unsigned n, bits;
- int r;
-
- if ((r = jtag_open()) < 0) return r;
-
- if ((r = jtag_reset()) < 0) return r;
-
- /* select empty node_addr + node_vir -- all zeros */
- if ((r = jtag_ir(ir_width, 14)) < 0) return r;
- if ((r = jtag_dr(32, 0, 0)) < 0) return r;
-
- /* select vdr - this will be the hub info (addr=0,vir=0) */
- if ((r = jtag_ir(ir_width, 12)) < 0) return r;
-
- /* read hub info */
- if ((r = jtag_dr_8x4(&bits)) < 0) return r;
- hub_version = (bits >> 27) & 0x1F;
- hub_nodecount = (bits >> 19) & 0xFF;
- hub_mfg = (bits >> 8) & 0x7FF;
-
- if (hub_mfg != 0x06e) {
- fprintf(stderr,"HUB: Cannot Find Virtual JTAG HUB\n");
- return -1;
- }
-
- /* altera docs claim this field is the sum of M bits (VIR field) and
- * N bits (ADDR field), but empirical evidence suggests it is actually
- * just the width of the ADDR field and the docs are wrong...
- */
- vir_width_ir = bits & 0xFF;
- vir_width_addr = needbits(hub_nodecount);
- vir_width = vir_width_ir + vir_width_addr;
-
- fprintf(stderr,"HUB: Mfg=0x%03x, Ver=0x%02x, Nodes=%d, VIR=%d+%d bits\n",
- hub_mfg, hub_version, hub_nodecount, vir_width_addr, vir_width_ir);
-
- for (n = 0; n < hub_nodecount; n++) {
- unsigned node_ver, node_id, node_mfg, node_iid;
- if ((r = jtag_dr_8x4(&bits)) < 0) return r;
- node_ver = (bits >> 27) & 0x1F;
- node_id = (bits >> 19) & 0xFF;
- node_mfg = (bits >> 8) & 0x7FF;
- node_iid = bits & 0xFF;
-
- fprintf(stderr,"NODE: Mfg=0x%03x, Ver=0x%02x, ID=0x%02x, IID=0x%02x\n",
- node_mfg, node_ver, node_id, node_iid);
-
- if ((node_id == 0x08) && (node_iid) == iid) {
- vir_addr = (n + 1) << vir_width_ir;
- }
- }
-
- if ((vir_addr == 0) && (iid < 256)) {
- fprintf(stderr,"ERROR: IID 0x%02x not found\n", iid);
- return -1;
- }
- return 0;
-}
-
-
jtag/jtag-virtual.c
Property changes :
Deleted: svn:executable
## -1 +0,0 ##
-*
\ No newline at end of property
Index: jtag/jtag.h
===================================================================
--- jtag/jtag.h (revision 25)
+++ jtag/jtag.h (nonexistent)
@@ -1,50 +0,0 @@
-/* Copyright 2012 Brian Swetland
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#ifndef _JTAG_H_
-#define _JTAG_H_
-
-int jtag_open(void);
-int jtag_close(void);
-
-/* move into RESET state */
-int jtag_reset(void);
-
-/* clock count times, TDI=0, TMS=bits[0], bits >>= 1 */
-int jtag_move(int count, unsigned bits);
-
-/* clock count-1 times, TMS=0, TDI=bits[0], bits >>= 1
- * clock 1 time, TMS=1, TDI=bits[0]
- * if out, capture TDO into out
- */
-int jtag_shift(int count, unsigned bits, unsigned *out);
-
-
-/* load sz bits into IR */
-int jtag_ir(unsigned sz, unsigned bits);
-
-/* load sz bits into DR, capture sz bits into out if non-null */
-int jtag_dr(unsigned sz, unsigned bits, unsigned *out);
-int jtag_dr_long(unsigned sz, unsigned * bits, unsigned *out, int words);
-
-
-
-/* altera virtual jtag support */
-int jtag_open_virtual_device(unsigned iid);
-int jtag_vir(unsigned vir);
-int jtag_vdr(unsigned sz, unsigned bits, unsigned *out);
-int jtag_vdr_long(unsigned , unsigned * , unsigned *, int );
-
-#endif
jtag/jtag.h
Property changes :
Deleted: svn:executable
## -1 +0,0 ##
-*
\ No newline at end of property
Index: jtag/jinfo.c
===================================================================
--- jtag/jinfo.c (revision 25)
+++ jtag/jinfo.c (nonexistent)
@@ -1,36 +0,0 @@
-/* Copyright 2012 Brian Swetland
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#include
-#include "jtag.h"
-
-int main(int argc, char **argv) {
- unsigned bits;
-
- if (jtag_open() < 0)
- return -1;
-
- if (jtag_reset() < 0)
- return -1;
- if (jtag_dr(32, 0, &bits) < 0)
- return -1;
- fprintf(stderr,"IDCODE: %08x\n", bits);
-
- if (jtag_open_virtual_device(0xffffffff))
- return -1;
-
- jtag_close();
- return 0;
-}
jtag/jinfo.c
Property changes :
Deleted: svn:executable
## -1 +0,0 ##
-*
\ No newline at end of property
Index: jtag/rom.bin
===================================================================
Cannot display: file marked as a binary type.
svn:mime-type = application/octet-stream
Index: jtag/rom.bin
===================================================================
--- jtag/rom.bin (revision 25)
+++ jtag/rom.bin (nonexistent)
jtag/rom.bin
Property changes :
Deleted: svn:executable
## -1 +0,0 ##
-*
\ No newline at end of property
Deleted: svn:mime-type
## -1 +0,0 ##
-application/octet-stream
\ No newline at end of property
Index: jtag/README
===================================================================
--- jtag/README (revision 25)
+++ jtag/README (nonexistent)
@@ -1,20 +0,0 @@
-
-Quick hack commandline tools to interact with Altera FPGA Virtual JTAG interfaces,
-using the USB Blaster device (as integrated on Terasic dev boards, etc).
-
-Not terribly fancy or optimized but only depends on libusb-1.0
-
-Currently does not support multiple devices on the chain.
-
-jtag.c - provides simple jtag interface
-jtag-virtual.c - provides simple virtual jtag interface
-
-jload.c - example of using the virtual jtag interface for a downloader interface
- with a CTRL/ADDR/DATA register set. CTRL[0] asserts reset, writes to
- DATA store to [ADDR] and auto-increment ADRR.
-
-jinfo.c - dumps idcode and virtual jtag hub and device info table
-
-
-Why? Scripting the Altera quartus_stp tool in TCL was driving me nuts.
-
jtag/README
Property changes :
Deleted: svn:executable
## -1 +0,0 ##
-*
\ No newline at end of property
Index: jtag/jtag_main
===================================================================
Cannot display: file marked as a binary type.
svn:mime-type = application/octet-stream
Index: jtag/jtag_main
===================================================================
--- jtag/jtag_main (revision 25)
+++ jtag/jtag_main (nonexistent)
jtag/jtag_main
Property changes :
Deleted: svn:executable
## -1 +0,0 ##
-*
\ No newline at end of property
Deleted: svn:mime-type
## -1 +0,0 ##
-application/octet-stream
\ No newline at end of property
Index: jtag/jtag_main.c
===================================================================
--- jtag/jtag_main.c (revision 25)
+++ jtag/jtag_main.c (nonexistent)
@@ -1,363 +0,0 @@
-#include
-#include
-#include
-#include
-#include // getopt
-#include
-#include
-#include "jtag.h"
-
-
-
-
-#define UPDATE_WB_ADDR 0x7
-#define UPDATE_WB_WR_DATA 0x6
-#define UPDATE_WB_RD_DATA 0x5
-#define RD_WR_STATUS 0x4
-
-#define BIT_NUM (word_width<<3)
-#define BYTE_NUM word_width
-/* Global vars */
-unsigned int index_num=126;
-unsigned int word_width=4; //
-unsigned int write_verify=0;
-unsigned int memory_offset=0;
-unsigned int memory_boundary=0xFFFFFFFF;
-
-
-
-char * binary_file_name=0;
-char enable_binary_send=0;
-char * write_data=0;
-
-
-
-
-/* functions */
-int send_binary_file();
-void usage();
-void processArgs (int , char** );
-int send_data ();
-int hexcut( char * , unsigned * , int );
-int vdr_large (unsigned , char * , char *);
-void hexgen( char * , unsigned *, int );
-
-int main(int argc, char **argv) {
- //unsigned bits;
- //unsigned int val;
-
- //unsigned bits;
- //unsigned val;
-
- processArgs (argc, argv );
- printf("index num=%u\n",index_num);
- if (jtag_open_virtual_device(index_num)){
- fprintf (stderr, "Error openning jtag IP with %d index num\n",index_num);
- return -1;
- }
- if (enable_binary_send) {
- if( send_binary_file() == -1) return -1;
- }
-
- if (write_data!=0){
- printf("send %s to jtag\n",write_data);
- send_data();
-
-
- }
-
- return 0;
-}
-
-
-
-void usage(){
-
- printf ("usage:./jtag_main [-n index number] [-i file_name][-c][-s rd/wr offset address][-d string]\n");
-
- printf ("\t-n index number: the target jtag IP core index number. The default number is 126\n");
- printf ("\t-i file_name: input binary file name (.bin file)\n");
- printf ("\t-w bin file word width in byte. default is 4 bytes (32 bits)\n");
- printf ("\t-c verify after write\n");
- printf ("\t-s memory wr/rd offset address in hex. The default value is 0x0000000\n");
- printf ("\t-e memory boundary address in hex. The default value is 0xFFFFFFFF\n");
- printf ("\t-d string: use for setting instruction or data value to jtag tap. string format : \"instr1,instr2,...,instrn\"\n \tinstri = I:instruct_num: send instruct_num to instruction register \n \tD:data_size_in_bit:data : send data in hex to data register\n \tR:data_size_in_bit:data : Read data register and show it on screan then write given data in hex to data register\n");
-
-}
-
-void processArgs (int argc, char **argv )
-{
- char c;
-int p;
-
- /* don't want getopt to moan - I can do that just fine thanks! */
- opterr = 0;
- if (argc < 2) usage();
- while ((c = getopt (argc, argv, "s:e:d:n:i:w:c")) != -1)
- {
- switch (c)
- {
- case 'n': /* index number */
- index_num = atoi(optarg);
- break;
- case 'i': /* input binary file name */
- binary_file_name = optarg;
- enable_binary_send=1;
- break;
- case 'w': /* word width in byte */
- word_width= atoi(optarg);
- break;
- case 'c': /* word width in byte */
- write_verify= 1;
- break;
- case 'd': /* word width in byte */
- write_data= optarg;
- break;
- case 's': /* word width in byte */
-
- p=sscanf(optarg,"%x",&memory_offset);
- if( p==0){
- fprintf (stderr, "invalid memory offset adress format `%s'.\n", optarg);
- usage();
- exit(1);
- }
- //printf("p=%d,memory_offset=%x\n",p,memory_offset);
- break;
- case 'e': /* word width in byte */
- p=sscanf(optarg,"%x",&memory_boundary);
- if( p==0){
- fprintf (stderr, "invalid memory boundary adress format `%s'.\n", optarg);
- usage();
- exit(1);
- }
- break;
-
- case '?':
- if (isprint (optopt))
- fprintf (stderr, "Unknown option `-%c'.\n", optopt);
- else
- fprintf (stderr,
- "Unknown option character `\\x%x'.\n",
- optopt);
- default:
- usage();
- exit(1);
- }
- }
-}
-
-unsigned * read_file (FILE * fp, unsigned int * n ){
-
- unsigned * buffer;
- unsigned val;
- unsigned char ch;
- unsigned int i=0;
- char cnt=0;
- unsigned int num=0;
- fseek(fp, 0, SEEK_END); // seek to end of file
- num = ftell(fp); // get current file pointer
- *n=num;// number of bytes from the beginning of the file
- num=(num/BYTE_NUM)+2;
- fseek(fp, 0, SEEK_SET);
- //printf ("num=%u\n",num);
- buffer = (unsigned *) malloc(num * sizeof(unsigned)); //memory allocated using malloc
- if(buffer == NULL)
- {
- printf("Error! memory not allocated.");
- exit(0);
- }
- ch=fgetc(fp);
- while(!feof(fp)){
- val<<=8;
- val|=ch;
- cnt++;
- //printf("ch=%x\t",ch);
- if(cnt==BYTE_NUM){
- //printf("%d:%x\n",i,val);
- buffer[i] = val;
- val=0;
- cnt=0;
- i++;
- }
- ch=fgetc(fp);
- }
- if( cnt>0){
- val<<=(8 *(BYTE_NUM-cnt));
- printf("%d:%x\n",i,val);
- buffer[i] = val;
-
- }
-
-return buffer;
-
-}
-
-
-
-int send_data ()
-{
- char * pch;
- char string[100];
- int bit=0, inst=0, d=0;
- char out[100];
- pch = strtok (write_data,",");
- printf("%s\n",pch);
- while (pch != NULL)
- {
- while(1){
- d=1;
- if(sscanf( pch, "D:%d:%s", &bit, string )) break;
- if(sscanf( pch, "d:%d:%s", &bit, string )) break;
- //if(sscanf( pch, "D:%d:" PRIx64 , &bit, &data )) break;
- //if(sscanf( pch, "d:%d:%016x", &bit, &data )) break;
- d=2;
- if(sscanf( pch, "R:%d:%s",&bit, string)) break;
- if(sscanf( pch, "r:%d:%s",&bit, string)) break;
- d=0;
- if(sscanf( pch, "I:%d", &inst)) break;
- if(sscanf( pch, "i:%d", &inst)) break;
- printf("invalid format : %s\n",pch);
- return -1;
-
- }
- if(d==1){
- //printf ("(bit=%d, data=%s)",bit, string);
- //jtag_vdr(bit, data, 0);
- vdr_large(bit,string,0);
- }if(d==2){
-
- vdr_large(bit,string,out);
- printf("###read data#%s###read data#\n",out);
- }else{
-
- jtag_vir(inst);
- //printf("%d\n",inst);
- }
-
- pch = strtok (NULL, ",");
-
- }
- return 0;
-}
-
-
-
-int send_binary_file(){
- FILE *fp;
- int i=0;
- unsigned out;
- unsigned int num=0;
- unsigned int mem_size;
- unsigned int memory_offset_in_word;
- printf("send %s to the wishbone bus\n",binary_file_name);
- fp = fopen(binary_file_name,"rb");
- if (!fp) {
- fprintf (stderr,"Error: can not open %s file in read mode\n",binary_file_name);
- return -1;
- }
- unsigned * buffer;
- buffer=read_file (fp, &num);
- mem_size=memory_boundary-memory_offset;
- if(num>mem_size){
- printf("\n\n Warning: %s file size (%x) is larger than the given memory size (%x). I will stop writing on end of memory address\n\n",binary_file_name,num,mem_size);
- num=mem_size;
- }
- fclose(fp);
- //disable the cpu
- jtag_vir(RD_WR_STATUS);
- jtag_vdr(BIT_NUM, 0x1, &out);
- //getchar();
- jtag_vir(UPDATE_WB_ADDR);
- // change memory sizes from byte to word
- memory_offset_in_word=memory_offset /BYTE_NUM;
- num=num /BYTE_NUM;
-
- jtag_vdr(BIT_NUM, memory_offset_in_word, 0);
- jtag_vir(UPDATE_WB_WR_DATA);
-
- printf ("start programing\n");
- //printf ("num=%d\n",num);
- for(i=0;isize)? 0 : size-count*8;
-
- sscanf(hexstring+start, "%08x", &val[count-1]);
- *(hexstring+start)=0;
- }
-
- // printf("size=%d, hexnum=%u\n",size,hexnum);
-
-
- return hexnum;
-}
-
-
-void hexgen( char * hexstring, unsigned * val, int words ){
- size_t count = 0;
- sprintf(hexstring,"0x");
- for(count = 0; count < words; count++) {
- if(count == 0) sprintf((hexstring+2),"%x",val[words-count-1]);
- else sprintf(hexstring,"%08x",val[words-count-1]);
- hexstring+=strlen(hexstring);
- }
-
- // return hexnum;
-}
-
-
jtag/jtag_main.c
Property changes :
Deleted: svn:executable
## -1 +0,0 ##
-*
\ No newline at end of property
Index: jtag/jconsole.c
===================================================================
--- jtag/jconsole.c (revision 25)
+++ jtag/jconsole.c (nonexistent)
@@ -1,135 +0,0 @@
-#include
-#include
-#include
-#include
-#include
-
-
-#include
-#include "jtag.h"
-
-#define VIR_CTRL 0x0
-#define VIR_ADDR 0x1
-#define VIR_DATA 0x2
-#define VIR_UART 0x7
-
-
-#define UPDATE_WB_ADDR 0x7
-#define UPDATE_WB_WR_DATA 0x6
-#define UPDATE_WB_RD_DATA 0x5
-#define RD_WR_STATUS 0x4
-
-int main(int argc, char **argv) {
- //unsigned bits;
- //unsigned int val;
-
- //unsigned bits;
- uint32_t val;
- FILE *fp;
-
- if (argc != 2) {
- fprintf(stderr,"usage: download bin file\n");
- return -1;
- }
- fp = fopen(argv[1],"rb");
- if (!fp) return -1;
-
- if (jtag_open_virtual_device(126))
- return -1;
-
-
- int i=0;
- unsigned int out;
-//disable the cpu
- jtag_vir(RD_WR_STATUS);
- jtag_vdr(32, 0xFFFFFFFF, &out);
- printf ("status=%x\n",out);
- getchar();
-//
- jtag_vir(UPDATE_WB_WR_DATA);
- unsigned char ch;
- char cnt=0;
- val=0;
- ch=fgetc(fp);
- while(!feof(fp)){
- val<<=8;
- val|=ch;
- cnt++;
- printf("ch=%x\t",ch);
- if(cnt==4){
- printf("%d:%x\n",i,val);
- jtag_vdr(32, val, 0);
- val=0;
- cnt=0;
- i++;
- }
- ch=fgetc(fp);
- }
- if( cnt>0){
- val<<=(8 *(4-cnt));
- printf("%d:%x\n",i,val);
- jtag_vdr(32, val, 0);
-
- }
-
-
- getchar();
-/*
- printf ("start=\n");
- jtag_vir(UPDATE_WB_ADDR);
- jtag_vdr(32, 0, 0);
- jtag_vir(UPDATE_WB_WR_DATA);
-
- for(i=0;i<1000; i++){
- //printf ("addr=\n");
- //scanf("%x", &val);
-
- jtag_vdr(32, 2*i, 0);
- //jtag_vdr(32, 0, &out);
- //printf ("out=%x\n",out);
-
- printf ("data=\n");
- scanf("%x", &val);
- jtag_vir(UPDATE_WB_WR_DATA);
- jtag_vdr(32, val, 0);
-
- printf ("data=\n");
- scanf("%x", &val);
- jtag_vdr(32, val, 0);
-
- printf ("data=\n");
- scanf("%x", &val);
- jtag_vdr(32, val, 0);
-
-
- }
-*/
- printf ("done programing\n");
- jtag_vir(UPDATE_WB_RD_DATA);
- jtag_vdr(32, 0, &out);
- for(i=1;i<1001; i++){
- jtag_vdr(32, i, &out);
- printf ("out[%d]=%x\n",i-1,out);
-
-
- }
-
- jtag_vir(RD_WR_STATUS);
- jtag_vdr(32, 0, &out);
- printf ("status=%x\n",out);
- for (;;) {
- /*
- jtag_vdr(9, 0, &bits);
- if (bits & 0x100) {
- bits &= 0xFF;
- if ((bits < ' ') || (bits > 127))
- fputc('.', stderr);
- else
- fputc(bits, stderr);
- }
- */
- }
-
- return 0;
-}
-
jtag/jconsole.c
Property changes :
Deleted: svn:executable
## -1 +0,0 ##
-*
\ No newline at end of property
Index: jtag/jtag.c
===================================================================
--- jtag/jtag.c (revision 25)
+++ jtag/jtag.c (nonexistent)
@@ -1,321 +0,0 @@
-/* Copyright 2012 Brian Swetland
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#include
-#include
-#include
-#include
-#include
-
-#include
-
-#define TRACE_USB 0
-#define TRACE_JTAG 0
-
-static struct libusb_device_handle *udev;
-static int usb_open(unsigned vid, unsigned pid) {
- if (libusb_init(NULL) < 0)
- return -1;
-
- if (!(udev = libusb_open_device_with_vid_pid(NULL, vid, pid))) {
- fprintf(stderr,"cannot find device\n");
- return -1;
- }
-
- if (libusb_claim_interface(udev, 0) < 0) {
- fprintf(stderr,"cannot claim interface\n");
- return -1;
- }
- return 0;
-}
-static void usb_close(void) {
- libusb_exit(NULL);
-}
-#if TRACE_USB
-static void dump(char *prefix, void *data, int len) {
- unsigned char *x = data;
- fprintf(stderr,"%s: (%d)", prefix, len);
- while (len > 0) {
- fprintf(stderr," %02x", *x++);
- len--;
- }
- fprintf(stderr,"\n");
-}
-#endif
-static int usb_bulk(unsigned char ep, void *data, int len, unsigned timeout) {
- int r, xfer;
-#if TRACE_USB
- if (!(ep & 0x80))
- dump("xmit", data, len);
-#endif
- r = libusb_bulk_transfer(udev, ep, data, len, &xfer, timeout);
- if (r < 0) {
- fprintf(stderr,"bulk: error: %d\n", r);
- return r;
- }
-#if TRACE_USB
- if (ep & 0x80)
- dump("recv", data, xfer);
-#endif
- return xfer;
-}
-
-#define EP1_IN 0x81
-#define EP2_OUT 0x02
-
-#define UB_BYTEMODE 0x80
-#define UB_BITMODE 0x00
-#define UB_READBACK 0x40
-
-/* bits in bit mode */
-#define UB_OE 0x20
-#define UB_TDI 0x10
-#define UB_nCS 0x08
-#define UB_nCE 0x04
-#define UB_TMS 0x02
-#define UB_TCK 0x01
-#define BUFF_SZ 512
-/* bytecount for data bytes that follow in byte mode */
-#define UB_COUNT(n) ((n) & 0x3F)
-
-int jtag_move(int count, unsigned bits){
- unsigned char buf[BUFF_SZ];
- int n = 0;
-#if TRACE_JTAG
- fprintf(stderr,"move: %08x (%d)\n", bits, count);
-#endif
- while (count-- > 0) {
- if (bits & 1) {
- buf[n++] = UB_TMS;
- buf[n++] = UB_TMS | UB_TCK;
- } else {
- buf[n++] = 0;
- buf[n++] = UB_TCK;
- }
- bits >>= 1;
- }
- return usb_bulk(EP2_OUT, buf, n, 1000);
-}
-
-int jtag_shift(int count, unsigned bits, unsigned *out) {
- unsigned char buf[BUFF_SZ];
- unsigned RB = out ? UB_READBACK : 0;
- int n = 0;
- int readcount = count;
- int r,bit;
-#if TRACE_JTAG
- fprintf(stderr,"xfer: %08x (%d)\n", bits, count);
-#endif
- while (count-- > 0) {
- if (bits & 1) {
- buf[n++] = UB_TDI;
- buf[n++] = UB_TDI | UB_TCK | RB;
- } else {
- buf[n++] = 0;
- buf[n++] = UB_TCK | RB;
- }
- bits >>= 1;
- }
- buf[n-1] |= UB_TMS;
- buf[n-2] |= UB_TMS;
- r = usb_bulk(EP2_OUT, buf, n, 1000);
- if (r < 0)
- return r;
- if (!out)
- return 0;
- bits = 0;
- bit = 1;
- while (readcount > 0) {
- r = usb_bulk(EP1_IN, buf, BUFF_SZ, 1000);
- if (r < 0)
- return r;
- if (r < 3)
- continue;
- for (n = 2; n < r; n++) {
- if (buf[n] & 1)
- bits |= bit;
- bit <<= 1;
- readcount--;
- if (readcount == 0) {
-#if TRACE_JTAG
- fprintf(stderr," : %08x\n", bits);
-#endif
- *out = bits;
- return 0;
- }
- }
- }
- return -1;
-}
-
-
-int jtag_shift_long(int count, unsigned * bits, unsigned *out) {
- unsigned char buf[BUFF_SZ];
- unsigned RB = out ? UB_READBACK : 0;
- int n = 0;
- int readcount = count;
- int r,bit;
- unsigned int p=0;
-
-#if TRACE_JTAG
- fprintf(stderr,"xfer: %08x (%d)\n", bits[count>>5], count);
-#endif
- while (count-- > 0) {
- p=((readcount-count)-1)>>5;
- if (bits[p] & 1) {
- buf[n++] = UB_TDI;
- buf[n++] = UB_TDI | UB_TCK | RB;
- } else {
- buf[n++] = 0;
- buf[n++] = UB_TCK | RB;
- }
- bits[p] = bits[p] >> 1;
- }
- buf[n-1] |= UB_TMS;
- buf[n-2] |= UB_TMS;
- r = usb_bulk(EP2_OUT, buf, n, 1000);
- if (r < 0)
- return r;
- if (!out)
- return 0;
-
- unsigned B = 0;
- bit = 1;
-
- count=readcount;
- int shift=0;
- while (readcount > 0) {
-
- r = usb_bulk(EP1_IN, buf, BUFF_SZ, 1000);
- //int j;
- //for(j=0;j>5;
- //printf("%u",buf[n]&1);
- if (buf[n] & 1)
- B |= bit;
- bit <<= 1;
- shift++;
- if(shift%32==0){
- bit=1;
- out[p]= B;
- //printf("out[%u]=%x\n",p, out[p]);
- B=0;
-
-
- }
- readcount--;
- if (readcount == 0) {
-#if TRACE_JTAG
- fprintf(stderr," : %08x\n", bits[p]);
-#endif
- out[p]= B;
- //printf("out[%u]=%x\n",p, out[p]);
- return 0;
- }
- }
- }
- return -1;
-}
-
-
-
-/* JTAG notes
- *
- * TMS is sampled on +TCK
- * Capture-XR state loads shift register on +TCK as state is exited
- * Shift-XR state TDO goes active (containing shiftr[0]) on the first -TCK
- * after entry, shifts occur on each +TCK, *including* the +TCK
- * that will exist Shift-XR when TMS=1 again
- * Update-XR update occurs on the -TCK after entry to state
- *
- * Any -> Reset: 11111
- * Any -> Reset -> RTI: 111110
- * RTI -> ShiftDR: 100
- * ShiftDR shifting: 0 x N
- * ShiftDR -> UpdateDR -> RTI: 110
- * ShiftDR -> UpdateDR -> ShiftDR: 11100
- * RTI -> ShiftIR: 1100
- * ShiftIR shifting: 0 x N
- * ShiftIR -> UpdateIR -> RTI: 110
- */
-
-#define RESET 8,0b01111111
-#define SHIFTDR 3,0b001
-#define SHIFTIR 4,0b0011
-#define DONE 2,0b01
-#define AGAIN 4,0b0011
-
-int jtag_ir(unsigned sz, unsigned bits) {
- int r;
- if ((r = jtag_move(SHIFTIR)) < 0) return r;
- if ((r = jtag_shift(sz, bits, 0)) < 0) return r;
- if ((r = jtag_move(DONE)) < 0) return r;
- return 0;
-}
-
-int jtag_dr(unsigned sz, unsigned bits, unsigned *out) {
- int r;
- if ((r = jtag_move(SHIFTDR)) < 0) return r;
- if ((r = jtag_shift(sz, bits, out)) < 0) return r;
- if ((r = jtag_move(DONE)) < 0) return r;
- return 0;
-}
-
-int jtag_dr_long(unsigned sz, unsigned * bits, unsigned *out, int words) {
- int r;
- //unsigned s=32;
- if ((r = jtag_move(SHIFTDR)) < 0) return r;
- //for(i=0;i
jtag/jtag.c
Property changes :
Deleted: svn:executable
## -1 +0,0 ##
-*
\ No newline at end of property
Index: jtag/usb-blaster-protocol.txt
===================================================================
--- jtag/usb-blaster-protocol.txt (revision 25)
+++ jtag/usb-blaster-protocol.txt (nonexistent)
@@ -1,60 +0,0 @@
-http://sf.net/apps/mediawiki/urjtag/index.php?title=Cable_Altera_USB-Blaster
-----------------------------------------------------------------------------
-
-Altera USB-Blaster
-------------------
-
-General
--------
- _________
- | |
- | AT93C46 |
- |_________|
- __|__________ _________
- | | | |
- USB__| FTDI 245BM |__| EPM7064 |__JTAG (B_TDO,B_TDI,B_TMS,B_TCK)
- |_____________| |_________|
- __|__________ _|___________
- | | | |
- | 6 MHz XTAL | | 24 MHz Osc. |
- |_____________| |_____________|
-
-
-Quoting from ixo.de (http://www.ixo.de/info/usb_jtag/)
-usb_jtag/device/c51/usbjtag.c comments:
-
-usb_jtag firmware now happens to behave just like the combination of
-FT245BM and Altera-programmed EPM7064 CPLD in Altera's USB-Blaster.
-The CPLD knows two major modes: Bit banging mode and Byte shift mode.
-It starts in Bit banging mode. While bytes are received from the host
-on EP2OUT, each byte B of them is processed as follows:
-
-Bit banging mode
-----------------
-1. Remember bit 6 (0x40) in B as the "Read bit".
-2. If bit 7 (0x80) is set, switch to Byte shift mode for the coming X
- bytes ( X := B & 0x3F ), and don't do anything else now.
-3. Otherwise, set the JTAG signals as follows:
- - TCK/DCLK high if bit 0 was set (0x01), otherwise low
- - TMS/nCONFIG high if bit 1 was set (0x02), otherwise low
- - nCE high if bit 2 was set (0x04), otherwise low
- - nCS high if bit 3 was set (0x08), otherwise low
- - TDI/ASDI/DATAO high if bit 4 was set (0x10), otherwise low
- - Output Enable/LED active if bit 5 was set (0x20), otherwise low
-4. If "Read bit" (0x40) was set, record the state of TDO(CONF_DONE) and
- DATAOUT/(nSTATUS) pins and put is as a byte( (DATAOUT<<1)|TDO) in the
- output FIFO _to_ the host.
-
-Byte shift mode
----------------
-1. Load shift register with byte from host
-2. Do 8 times (i.e. for each bit of the byte; implemented in shift.a51)
- - if nCS=1, set carry bit from TDO, else set carry bit from DATAOUT
- (Active Serial mode)
- - Rotate shift register through carry bit
- - TDI := Carry bit
- - Raise TCK, then lower TCK.
-3. If "Read bit" was set when switching into byte shift mode, record the
- shift register content and put it into the FIFO to the host.
-
-
jtag/usb-blaster-protocol.txt
Property changes :
Deleted: svn:executable
## -1 +0,0 ##
-*
\ No newline at end of property
Index: jtag/Makefile
===================================================================
--- jtag/Makefile (revision 25)
+++ jtag/Makefile (revision 28)
@@ -1,23 +1,3 @@
-
-CFLAGS := -g -Wall
-LIBS := -lusb-1.0
-
-all: jinfo jtag_main
-
-jinfo.c: jtag.h
-jtag_main.c: jtag.h
-jtag.c: jtag.h
-jtag-virtual.c: jtag.h
-
-
-
-JINFO_OBJS := jinfo.o jtag-virtual.o jtag.o
-jinfo: $(JINFO_OBJS)
- $(CC) -o jinfo $(JINFO_OBJS) $(LIBS)
-
-JTAG_MAIN_OBJS := jtag_main.o jtag-virtual.o jtag.o
-jtag_main: $(JTAG_MAIN_OBJS)
- $(CC) -o jtag_main $(JTAG_MAIN_OBJS) $(LIBS)
-
-clean::
- rm -f jinfo jtag_main *.o
+all:
+ cd simple_jtag; make
+ #cd urjtag-0.10; ./configure; wait; make
Index: jtag/simple_jtag/Makefile
===================================================================
--- jtag/simple_jtag/Makefile (nonexistent)
+++ jtag/simple_jtag/Makefile (revision 28)
@@ -0,0 +1,29 @@
+
+CFLAGS := -g -Wall
+LIBS := -lusb-1.0
+
+all: jinfo jtag_main usblist
+
+
+jinfo.c: jtag.h
+jtag_main.c: jtag.h
+jtag.c: jtag.h
+jtag-virtual.c: jtag.h
+list_usb_dev.c: jtag.h
+
+
+
+JINFO_OBJS := jinfo.o jtag-virtual.o jtag.o
+jinfo: $(JINFO_OBJS)
+ $(CC) -o jinfo $(JINFO_OBJS) $(LIBS)
+
+JTAG_MAIN_OBJS := jtag_main.o jtag-virtual.o jtag.o
+jtag_main: $(JTAG_MAIN_OBJS)
+ $(CC) -o jtag_main $(JTAG_MAIN_OBJS) $(LIBS)
+
+LIST_USB_OBJS := list_usb_dev.o jtag-virtual.o jtag.o
+usblist: $(LIST_USB_OBJS)
+ $(CC) -o list_usb_dev $(LIST_USB_OBJS) $(LIBS)
+
+clean::
+ rm -f jinfo jtag_main list_usb_dev *.o
jtag/simple_jtag/Makefile
Property changes :
Added: svn:executable
## -0,0 +1 ##
+*
\ No newline at end of property
Index: jtag/simple_jtag/README
===================================================================
--- jtag/simple_jtag/README (nonexistent)
+++ jtag/simple_jtag/README (revision 28)
@@ -0,0 +1,20 @@
+
+Quick hack commandline tools to interact with Altera FPGA Virtual JTAG interfaces,
+using the USB Blaster device (as integrated on Terasic dev boards, etc).
+
+Not terribly fancy or optimized but only depends on libusb-1.0
+
+Currently does not support multiple devices on the chain.
+
+jtag.c - provides simple jtag interface
+jtag-virtual.c - provides simple virtual jtag interface
+
+jload.c - example of using the virtual jtag interface for a downloader interface
+ with a CTRL/ADDR/DATA register set. CTRL[0] asserts reset, writes to
+ DATA store to [ADDR] and auto-increment ADRR.
+
+jinfo.c - dumps idcode and virtual jtag hub and device info table
+
+
+Why? Scripting the Altera quartus_stp tool in TCL was driving me nuts.
+
jtag/simple_jtag/README
Property changes :
Added: svn:executable
## -0,0 +1 ##
+*
\ No newline at end of property
Index: jtag/simple_jtag/jconsole.c
===================================================================
--- jtag/simple_jtag/jconsole.c (nonexistent)
+++ jtag/simple_jtag/jconsole.c (revision 28)
@@ -0,0 +1,135 @@
+#include
+#include
+#include
+#include
+#include
+
+
+#include
+#include "jtag.h"
+
+#define VIR_CTRL 0x0
+#define VIR_ADDR 0x1
+#define VIR_DATA 0x2
+#define VIR_UART 0x7
+
+
+#define UPDATE_WB_ADDR 0x7
+#define UPDATE_WB_WR_DATA 0x6
+#define UPDATE_WB_RD_DATA 0x5
+#define RD_WR_STATUS 0x4
+
+int main(int argc, char **argv) {
+ //unsigned bits;
+ //unsigned int val;
+
+ //unsigned bits;
+ uint32_t val;
+ FILE *fp;
+
+ if (argc != 2) {
+ fprintf(stderr,"usage: download bin file\n");
+ return -1;
+ }
+ fp = fopen(argv[1],"rb");
+ if (!fp) return -1;
+
+ if (jtag_open_virtual_device(126))
+ return -1;
+
+
+ int i=0;
+ unsigned int out;
+//disable the cpu
+ jtag_vir(RD_WR_STATUS);
+ jtag_vdr(32, 0xFFFFFFFF, &out);
+ printf ("status=%x\n",out);
+ getchar();
+//
+ jtag_vir(UPDATE_WB_WR_DATA);
+ unsigned char ch;
+ char cnt=0;
+ val=0;
+ ch=fgetc(fp);
+ while(!feof(fp)){
+ val<<=8;
+ val|=ch;
+ cnt++;
+ printf("ch=%x\t",ch);
+ if(cnt==4){
+ printf("%d:%x\n",i,val);
+ jtag_vdr(32, val, 0);
+ val=0;
+ cnt=0;
+ i++;
+ }
+ ch=fgetc(fp);
+ }
+ if( cnt>0){
+ val<<=(8 *(4-cnt));
+ printf("%d:%x\n",i,val);
+ jtag_vdr(32, val, 0);
+
+ }
+
+
+ getchar();
+/*
+ printf ("start=\n");
+ jtag_vir(UPDATE_WB_ADDR);
+ jtag_vdr(32, 0, 0);
+ jtag_vir(UPDATE_WB_WR_DATA);
+
+ for(i=0;i<1000; i++){
+ //printf ("addr=\n");
+ //scanf("%x", &val);
+
+ jtag_vdr(32, 2*i, 0);
+ //jtag_vdr(32, 0, &out);
+ //printf ("out=%x\n",out);
+
+ printf ("data=\n");
+ scanf("%x", &val);
+ jtag_vir(UPDATE_WB_WR_DATA);
+ jtag_vdr(32, val, 0);
+
+ printf ("data=\n");
+ scanf("%x", &val);
+ jtag_vdr(32, val, 0);
+
+ printf ("data=\n");
+ scanf("%x", &val);
+ jtag_vdr(32, val, 0);
+
+
+ }
+*/
+ printf ("done programing\n");
+ jtag_vir(UPDATE_WB_RD_DATA);
+ jtag_vdr(32, 0, &out);
+ for(i=1;i<1001; i++){
+ jtag_vdr(32, i, &out);
+ printf ("out[%d]=%x\n",i-1,out);
+
+
+ }
+
+ jtag_vir(RD_WR_STATUS);
+ jtag_vdr(32, 0, &out);
+ printf ("status=%x\n",out);
+ for (;;) {
+ /*
+ jtag_vdr(9, 0, &bits);
+ if (bits & 0x100) {
+ bits &= 0xFF;
+ if ((bits < ' ') || (bits > 127))
+ fputc('.', stderr);
+ else
+ fputc(bits, stderr);
+ }
+ */
+ }
+
+ return 0;
+}
+
jtag/simple_jtag/jconsole.c
Property changes :
Added: svn:executable
## -0,0 +1 ##
+*
\ No newline at end of property
Index: jtag/simple_jtag/jinfo.c
===================================================================
--- jtag/simple_jtag/jinfo.c (nonexistent)
+++ jtag/simple_jtag/jinfo.c (revision 28)
@@ -0,0 +1,37 @@
+/* Copyright 2012 Brian Swetland
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include
+#include "jtag.h"
+
+int main(int argc, char **argv) {
+ unsigned bits;
+
+ if (jtag_open() < 0)
+ return -1;
+
+ if (jtag_reset() < 0)
+ return -1;
+
+ if (jtag_dr(32, 0, &bits) < 0)
+ return -1;
+ fprintf(stderr,"IDCODE: %08x\n", bits);
+
+ if (jtag_open_virtual_device(0xffffffff))
+ return -1;
+
+ jtag_close();
+ return 0;
+}
jtag/simple_jtag/jinfo.c
Property changes :
Added: svn:executable
## -0,0 +1 ##
+*
\ No newline at end of property
Index: jtag/simple_jtag/jtag-virtual.c
===================================================================
--- jtag/simple_jtag/jtag-virtual.c (nonexistent)
+++ jtag/simple_jtag/jtag-virtual.c (revision 28)
@@ -0,0 +1,141 @@
+/* Copyright 2012 Brian Swetland
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include
+#include
+
+#include "jtag.h"
+
+int jtag_dr_8x4(unsigned *out) {
+ unsigned bits = 0;
+ unsigned tmp;
+ int n, r;
+
+ for (n = 0; n < 8; n++) {
+ if ((r = jtag_dr(4, 0, &tmp)) < 0) return r;
+ bits |= (tmp <<= (n * 4));
+ }
+ *out = bits;
+ return 0;
+}
+
+/* number of bits needed given a max value 1-255 */
+unsigned needbits(unsigned max) {
+ if (max > 127) return 8;
+ if (max > 63) return 7;
+ if (max > 31) return 6;
+ if (max > 15) return 5;
+ if (max > 7) return 4;
+ if (max > 3) return 3;
+ if (max > 1) return 2;
+ return 1;
+}
+
+static unsigned ir_width = 10;
+
+static unsigned hub_version = 0;
+static unsigned hub_nodecount = 0;
+static unsigned hub_mfg = 0;
+
+static unsigned vir_width = 0;
+static unsigned vir_width_addr = 0;
+static unsigned vir_width_ir = 0;
+static unsigned vir_addr = 0;
+
+
+int jtag_vir(unsigned vir) {
+ int r;
+ if ((r = jtag_ir(ir_width, 14)) < 0) return r;
+ if ((r = jtag_dr(vir_width, vir_addr | vir, 0)) < 0) return r;
+ return 0;
+}
+
+int jtag_vdr(unsigned sz, unsigned bits, unsigned *out) {
+ int r;
+ if ((r = jtag_ir(ir_width, 12)) < 0) return r;
+ if ((r = jtag_dr(sz, bits, out)) < 0) return r;
+ return 0;
+}
+
+int jtag_vdr_long(unsigned sz, unsigned * bits, unsigned *out, int words) {
+ int r;
+ if ((r = jtag_ir(ir_width, 12)) < 0) return r;
+ if ((r = jtag_dr_long(sz, bits, out, words)) < 0) return r;
+ return 0;
+}
+
+int jtag_open_virtual_device(unsigned iid) {
+ unsigned n, bits;
+ int r;
+
+ if ((r = jtag_open()) < 0) return r;
+
+ if ((r = jtag_reset()) < 0) return r;
+
+ /* select empty node_addr + node_vir -- all zeros */
+ if ((r = jtag_ir(ir_width, 14)) < 0) return r;
+ if ((r = jtag_dr(32, 0, 0)) < 0) return r;
+
+ /* select vdr - this will be the hub info (addr=0,vir=0) */
+ if ((r = jtag_ir(ir_width, 12)) < 0) return r;
+
+ /* read hub info */
+ if ((r = jtag_dr_8x4(&bits)) < 0) return r;
+ hub_version = (bits >> 27) & 0x1F;
+ hub_nodecount = (bits >> 19) & 0xFF;
+ hub_mfg = (bits >> 8) & 0x7FF;
+
+ if (hub_mfg != 0x06e) {
+ fprintf(stderr,"hub_version=%x, hub_nodecount=%x, hub_mfg=%x \n",hub_version, hub_nodecount, hub_mfg);
+
+ fprintf(stderr,"HUB: Cannot Find Virtual JTAG HUB\n");
+ return -1;
+ }
+
+ /* altera docs claim this field is the sum of M bits (VIR field) and
+ * N bits (ADDR field), but empirical evidence suggests it is actually
+ * just the width of the ADDR field and the docs are wrong...
+ */
+ vir_width_ir = bits & 0xFF;
+ vir_width_addr = needbits(hub_nodecount);
+ vir_width = vir_width_ir + vir_width_addr;
+
+ fprintf(stderr,"HUB: Mfg=0x%03x, Ver=0x%02x, Nodes=%d, VIR=%d+%d bits\n",
+ hub_mfg, hub_version, hub_nodecount, vir_width_addr, vir_width_ir);
+
+ for (n = 0; n < hub_nodecount; n++) {
+ unsigned node_ver, node_id, node_mfg, node_iid;
+ if ((r = jtag_dr_8x4(&bits)) < 0) return r;
+ node_ver = (bits >> 27) & 0x1F;
+ node_id = (bits >> 19) & 0xFF;
+ node_mfg = (bits >> 8) & 0x7FF;
+ node_iid = bits & 0xFF;
+
+ fprintf(stderr,"NODE: Mfg=0x%03x, Ver=0x%02x, ID=0x%02x, IID=0x%02x\n",
+ node_mfg, node_ver, node_id, node_iid);
+
+ if ((node_id == 0x08) && (node_iid) == iid) {
+ vir_addr = (n + 1) << vir_width_ir;
+ }
+ }
+
+ if ((vir_addr == 0) && (iid < 256)) {
+ fprintf(stderr,"ERROR: IID 0x%02x not found\n", iid);
+ return -1;
+ }
+ return 0;
+}
+
+
jtag/simple_jtag/jtag-virtual.c
Property changes :
Added: svn:executable
## -0,0 +1 ##
+*
\ No newline at end of property
Index: jtag/simple_jtag/jtag.c
===================================================================
--- jtag/simple_jtag/jtag.c (nonexistent)
+++ jtag/simple_jtag/jtag.c (revision 28)
@@ -0,0 +1,332 @@
+/* Copyright 2012 Brian Swetland
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include
+#include
+#include
+#include
+#include
+
+#include
+
+#define TRACE_USB 0
+#define TRACE_JTAG 0
+
+#define TIMOUT 1000
+
+/* You may want to change the VENDOR_ID and PRODUCT_ID
+ * depending on your device.
+ */
+#define VENDOR_ID 0x09fb // Altera
+#define PRODUCT_ID 0x6001 // usb blaster (DE2-115)
+// Altera usb blaster product IDs "6001", "6002", "6003", MODE="0666"
+// dose not work for USB-Blaster II "6010", "6810"
+// run ./list_usb_dev to see the list of all usb devices' vid and pid
+
+static struct libusb_device_handle *udev;
+static int usb_open(unsigned vid, unsigned pid) {
+ if (libusb_init(NULL) < 0)
+ return -1;
+
+ if (!(udev = libusb_open_device_with_vid_pid(NULL, vid, pid))) {
+ fprintf(stderr,"cannot find device\n");
+ return -1;
+ }
+
+ if (libusb_claim_interface(udev, 0) < 0) {
+ fprintf(stderr,"cannot claim interface\n");
+ return -1;
+ }
+ return 0;
+}
+static void usb_close(void) {
+ libusb_exit(NULL);
+}
+#if TRACE_USB
+static void dump(char *prefix, void *data, int len) {
+ unsigned char *x = data;
+ fprintf(stderr,"%s: (%d)", prefix, len);
+ while (len > 0) {
+ fprintf(stderr," %02x", *x++);
+ len--;
+ }
+ fprintf(stderr,"\n");
+}
+#endif
+static int usb_bulk(unsigned char ep, void *data, int len, unsigned timeout) {
+ int r, xfer;
+#if TRACE_USB
+ if (!(ep & 0x80))
+ dump("xmit", data, len);
+#endif
+ r = libusb_bulk_transfer(udev, ep, data, len, &xfer, timeout);
+ if (r < 0) {
+ fprintf(stderr,"bulk: error: %d\n", r);
+ return r;
+ }
+#if TRACE_USB
+ if (ep & 0x80)
+ dump("recv", data, xfer);
+#endif
+ return xfer;
+}
+
+#define EP1_IN 0x81
+#define EP2_OUT 0x02
+
+#define UB_BYTEMODE 0x80
+#define UB_BITMODE 0x00
+#define UB_READBACK 0x40
+
+/* bits in bit mode */
+#define UB_OE 0x20
+#define UB_TDI 0x10
+#define UB_nCS 0x08
+#define UB_nCE 0x04
+#define UB_TMS 0x02
+#define UB_TCK 0x01
+#define BUFF_SZ 512
+/* bytecount for data bytes that follow in byte mode */
+#define UB_COUNT(n) ((n) & 0x3F)
+
+int jtag_move(int count, unsigned bits){
+ unsigned char buf[BUFF_SZ];
+ int n = 0;
+#if TRACE_JTAG
+ fprintf(stderr,"move: %08x (%d)\n", bits, count);
+#endif
+ while (count-- > 0) {
+ if (bits & 1) {
+ buf[n++] = UB_TMS;
+ buf[n++] = UB_TMS | UB_TCK;
+ } else {
+ buf[n++] = 0;
+ buf[n++] = UB_TCK;
+ }
+ bits >>= 1;
+ }
+ return usb_bulk(EP2_OUT, buf, n, TIMOUT);
+}
+
+int jtag_shift(int count, unsigned bits, unsigned *out) {
+ unsigned char buf[BUFF_SZ];
+ unsigned RB = out ? UB_READBACK : 0;
+ int n = 0;
+ int readcount = count;
+ int r,bit;
+#if TRACE_JTAG
+ fprintf(stderr,"xfer: %08x (%d)\n", bits, count);
+#endif
+ while (count-- > 0) {
+ if (bits & 1) {
+ buf[n++] = UB_TDI;
+ buf[n++] = UB_TDI | UB_TCK | RB;
+ } else {
+ buf[n++] = 0;
+ buf[n++] = UB_TCK | RB;
+ }
+ bits >>= 1;
+ }
+ buf[n-1] |= UB_TMS;
+ buf[n-2] |= UB_TMS;
+ r = usb_bulk(EP2_OUT, buf, n, TIMOUT);
+ if (r < 0)
+ return r;
+ if (!out)
+ return 0;
+ bits = 0;
+ bit = 1;
+ while (readcount > 0) {
+ r = usb_bulk(EP1_IN, buf, BUFF_SZ, TIMOUT);
+ if (r < 0)
+ return r;
+ if (r < 3)
+ continue;
+ for (n = 2; n < r; n++) {
+ if (buf[n] & 1)
+ bits |= bit;
+ bit <<= 1;
+ readcount--;
+ if (readcount == 0) {
+#if TRACE_JTAG
+ fprintf(stderr," : %08x\n", bits);
+#endif
+ *out = bits;
+ return 0;
+ }
+ }
+ }
+ return -1;
+}
+
+
+int jtag_shift_long(int count, unsigned * bits, unsigned *out) {
+ unsigned char buf[BUFF_SZ];
+ unsigned RB = out ? UB_READBACK : 0;
+ int n = 0;
+ int readcount = count;
+ int r,bit;
+ unsigned int p=0;
+
+#if TRACE_JTAG
+ fprintf(stderr,"xfer: %08x (%d)\n", bits[count>>5], count);
+#endif
+ while (count-- > 0) {
+ p=((readcount-count)-1)>>5;
+ if (bits[p] & 1) {
+ buf[n++] = UB_TDI;
+ buf[n++] = UB_TDI | UB_TCK | RB;
+ } else {
+ buf[n++] = 0;
+ buf[n++] = UB_TCK | RB;
+ }
+ bits[p] = bits[p] >> 1;
+ }
+ buf[n-1] |= UB_TMS;
+ buf[n-2] |= UB_TMS;
+ r = usb_bulk(EP2_OUT, buf, n, TIMOUT);
+ if (r < 0)
+ return r;
+ if (!out)
+ return 0;
+
+ unsigned B = 0;
+ bit = 1;
+
+ count=readcount;
+ int shift=0;
+ while (readcount > 0) {
+
+ r = usb_bulk(EP1_IN, buf, BUFF_SZ, TIMOUT);
+ //int j;
+ //for(j=0;j>5;
+ //printf("%u",buf[n]&1);
+ if (buf[n] & 1)
+ B |= bit;
+ bit <<= 1;
+ shift++;
+ if(shift%32==0){
+ bit=1;
+ out[p]= B;
+ //printf("out[%u]=%x\n",p, out[p]);
+ B=0;
+
+
+ }
+ readcount--;
+ if (readcount == 0 ) {
+#if TRACE_JTAG
+ fprintf(stderr," : %08x\n", bits[p]);
+#endif
+ if (shift%32!=0) out[p]= B;
+ //printf("out[%u]=%x\n",p, out[p]);
+ return 0;
+ }
+ }
+ }
+ return -1;
+}
+
+
+
+/* JTAG notes
+ *
+ * TMS is sampled on +TCK
+ * Capture-XR state loads shift register on +TCK as state is exited
+ * Shift-XR state TDO goes active (containing shiftr[0]) on the first -TCK
+ * after entry, shifts occur on each +TCK, *including* the +TCK
+ * that will exist Shift-XR when TMS=1 again
+ * Update-XR update occurs on the -TCK after entry to state
+ *
+ * Any -> Reset: 11111
+ * Any -> Reset -> RTI: 111110
+ * RTI -> ShiftDR: 100
+ * ShiftDR shifting: 0 x N
+ * ShiftDR -> UpdateDR -> RTI: 110
+ * ShiftDR -> UpdateDR -> ShiftDR: 11100
+ * RTI -> ShiftIR: 1100
+ * ShiftIR shifting: 0 x N
+ * ShiftIR -> UpdateIR -> RTI: 110
+ */
+
+#define RESET 8,0b01111111
+#define SHIFTDR 3,0b001
+#define SHIFTIR 4,0b0011
+#define DONE 2,0b01
+#define AGAIN 4,0b0011
+
+int jtag_ir(unsigned sz, unsigned bits) {
+ int r;
+ if ((r = jtag_move(SHIFTIR)) < 0) return r;
+ if ((r = jtag_shift(sz, bits, 0)) < 0) return r;
+ if ((r = jtag_move(DONE)) < 0) return r;
+ return 0;
+}
+
+int jtag_dr(unsigned sz, unsigned bits, unsigned *out) {
+ int r;
+ if ((r = jtag_move(SHIFTDR)) < 0) return r;
+ if ((r = jtag_shift(sz, bits, out)) < 0) return r;
+ if ((r = jtag_move(DONE)) < 0) return r;
+ return 0;
+}
+
+int jtag_dr_long(unsigned sz, unsigned * bits, unsigned *out, int words) {
+ int r;
+ //unsigned s=32;
+ if ((r = jtag_move(SHIFTDR)) < 0) return r;
+ //for(i=0;i
jtag/simple_jtag/jtag.c
Property changes :
Added: svn:executable
## -0,0 +1 ##
+*
\ No newline at end of property
Index: jtag/simple_jtag/jtag.h
===================================================================
--- jtag/simple_jtag/jtag.h (nonexistent)
+++ jtag/simple_jtag/jtag.h (revision 28)
@@ -0,0 +1,50 @@
+/* Copyright 2012 Brian Swetland
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef _JTAG_H_
+#define _JTAG_H_
+
+int jtag_open(void);
+int jtag_close(void);
+
+/* move into RESET state */
+int jtag_reset(void);
+
+/* clock count times, TDI=0, TMS=bits[0], bits >>= 1 */
+int jtag_move(int count, unsigned bits);
+
+/* clock count-1 times, TMS=0, TDI=bits[0], bits >>= 1
+ * clock 1 time, TMS=1, TDI=bits[0]
+ * if out, capture TDO into out
+ */
+int jtag_shift(int count, unsigned bits, unsigned *out);
+
+
+/* load sz bits into IR */
+int jtag_ir(unsigned sz, unsigned bits);
+
+/* load sz bits into DR, capture sz bits into out if non-null */
+int jtag_dr(unsigned sz, unsigned bits, unsigned *out);
+int jtag_dr_long(unsigned sz, unsigned * bits, unsigned *out, int words);
+
+
+
+/* altera virtual jtag support */
+int jtag_open_virtual_device(unsigned iid);
+int jtag_vir(unsigned vir);
+int jtag_vdr(unsigned sz, unsigned bits, unsigned *out);
+int jtag_vdr_long(unsigned , unsigned * , unsigned *, int );
+
+#endif
jtag/simple_jtag/jtag.h
Property changes :
Added: svn:executable
## -0,0 +1 ##
+*
\ No newline at end of property
Index: jtag/simple_jtag/jtag_main.c
===================================================================
--- jtag/simple_jtag/jtag_main.c (nonexistent)
+++ jtag/simple_jtag/jtag_main.c (revision 28)
@@ -0,0 +1,438 @@
+#include
+#include
+#include
+#include
+#include // getopt
+#include
+#include
+#include "jtag.h"
+
+
+
+
+#define UPDATE_WB_ADDR 0x7
+#define UPDATE_WB_WR_DATA 0x6
+#define UPDATE_WB_RD_DATA 0x5
+#define RD_WR_STATUS 0x4
+
+#define BIT_NUM (word_width<<3)
+#define BYTE_NUM word_width
+/* Global vars */
+unsigned int index_num=126;
+unsigned int word_width=4; //
+unsigned int write_verify=0;
+unsigned int memory_offset=0;
+unsigned int memory_boundary=0xFFFFFFFF;
+
+
+
+char * binary_file_name=0;
+char enable_binary_send=0;
+char * write_data=0;
+
+
+
+
+/* functions */
+int send_binary_file();
+void usage();
+void processArgs (int , char** );
+int send_data ();
+int hexcut( char * , unsigned * , int );
+int vdr_large (unsigned , char * , char *);
+void hexgen( char * , unsigned *, int );
+
+int main(int argc, char **argv) {
+ //unsigned bits;
+ //unsigned int val;
+
+ //unsigned bits;
+ //unsigned val;
+
+ processArgs (argc, argv );
+ printf("index num=%u\n",index_num);
+ if (jtag_open_virtual_device(index_num)){
+ fprintf (stderr, "Error openning jtag IP with %d index num\n",index_num);
+ return -1;
+ }
+ if (enable_binary_send) {
+ if( send_binary_file() == -1) return -1;
+ }
+
+ if (write_data!=0){
+ printf("send %s to jtag\n",write_data);
+ send_data();
+
+
+ }
+
+ return 0;
+}
+
+
+
+void usage(){
+
+ printf ("usage:./jtag_main [-n index number] [-i file_name][-c][-s rd/wr offset address][-d string]\n");
+
+ printf ("\t-n index number: the target jtag IP core index number. The default number is 126\n");
+ printf ("\t-i file_name: input binary file name (.bin file)\n");
+ printf ("\t-w bin file word width in byte. default is 4 bytes (32 bits)\n");
+ printf ("\t-c verify after write\n");
+ printf ("\t-s memory wr/rd offset address in hex. The default value is 0x0000000\n");
+ printf ("\t-e memory boundary address in hex. The default value is 0xFFFFFFFF\n");
+ printf ("\t-d string: use for setting instruction or data value to jtag tap. string format : \"instr1,instr2,...,instrn\"\n \tinstri = I:instruct_num: send instruct_num to instruction register \n \tD:data_size_in_bit:data : send data in hex to data register\n \tR:data_size_in_bit:data : Read data register and show it on screan then write given data in hex to data register\n");
+
+}
+
+void processArgs (int argc, char **argv )
+{
+ char c;
+int p;
+
+ /* don't want getopt to moan - I can do that just fine thanks! */
+ opterr = 0;
+ if (argc < 2) usage();
+ while ((c = getopt (argc, argv, "s:e:d:n:i:w:c")) != -1)
+ {
+ switch (c)
+ {
+ case 'n': /* index number */
+ index_num = atoi(optarg);
+ break;
+ case 'i': /* input binary file name */
+ binary_file_name = optarg;
+ enable_binary_send=1;
+ break;
+ case 'w': /* word width in byte */
+ word_width= atoi(optarg);
+ break;
+ case 'c': /* word width in byte */
+ write_verify= 1;
+ break;
+ case 'd': /* word width in byte */
+ write_data= optarg;
+ break;
+ case 's': /* word width in byte */
+
+ p=sscanf(optarg,"%x",&memory_offset);
+ if( p==0){
+ fprintf (stderr, "invalid memory offset adress format `%s'.\n", optarg);
+ usage();
+ exit(1);
+ }
+ //printf("p=%d,memory_offset=%x\n",p,memory_offset);
+ break;
+ case 'e': /* word width in byte */
+ p=sscanf(optarg,"%x",&memory_boundary);
+ if( p==0){
+ fprintf (stderr, "invalid memory boundary adress format `%s'.\n", optarg);
+ usage();
+ exit(1);
+ }
+ break;
+
+ case '?':
+ if (isprint (optopt))
+ fprintf (stderr, "Unknown option `-%c'.\n", optopt);
+ else
+ fprintf (stderr,
+ "Unknown option character `\\x%x'.\n",
+ optopt);
+ default:
+ usage();
+ exit(1);
+ }
+ }
+}
+
+unsigned * read_file (FILE * fp, unsigned int * n ){
+
+ unsigned * buffer;
+ unsigned val;
+ unsigned char ch;
+ unsigned int i=0;
+ char cnt=0;
+ unsigned int num=0;
+ unsigned int width= (BYTE_NUM < sizeof(unsigned )) ? BYTE_NUM : sizeof(unsigned ); //max is 4 then
+ fseek(fp, 0, SEEK_END); // seek to end of file
+ num = ftell(fp); // get current file pointer
+ *n=num;// number of bytes from the beginning of the file
+
+
+
+
+ num=(num/width)+2;
+ fseek(fp, 0, SEEK_SET);
+ //printf ("num=%u\n",num);
+ buffer = (unsigned *) malloc(num * sizeof(unsigned ) ); //memory allocated using malloc
+ if(buffer == NULL)
+ {
+ printf("Error! memory not allocated.");
+ exit(0);
+ }
+ ch=fgetc(fp);
+
+ while(!feof(fp)){
+ val<<=8;
+ val|=ch;
+ cnt++;
+ //printf("ch=%x\t",ch);
+ if(cnt==width){
+ //printf("%d:%x\n",i,val);
+ buffer[i] = val;
+ val=0;
+ cnt=0;
+ i++;
+ }
+ ch=fgetc(fp);
+ }
+ if( cnt>0){
+ val<<=(8 *(width-cnt));
+ printf("%d:%x\n",i,val);
+ buffer[i] = val;
+
+ }
+
+return buffer;
+
+}
+
+
+
+int send_data ()
+{
+ char * pch;
+ char string[100];
+ int bit=0, inst=0, d=0;
+ char out[100];
+ pch = strtok (write_data,",");
+ printf("%s\n",pch);
+ while (pch != NULL)
+ {
+ while(1){
+ d=1;
+ if(sscanf( pch, "D:%d:%s", &bit, string )) break;
+ if(sscanf( pch, "d:%d:%s", &bit, string )) break;
+ //if(sscanf( pch, "D:%d:" PRIx64 , &bit, &data )) break;
+ //if(sscanf( pch, "d:%d:%016x", &bit, &data )) break;
+ d=2;
+ if(sscanf( pch, "R:%d:%s",&bit, string)) break;
+ if(sscanf( pch, "r:%d:%s",&bit, string)) break;
+ d=0;
+ if(sscanf( pch, "I:%d", &inst)) break;
+ if(sscanf( pch, "i:%d", &inst)) break;
+ printf("invalid format : %s\n",pch);
+ return -1;
+
+ }
+ if(d==1){
+ //printf ("(bit=%d, data=%s)",bit, string);
+ //jtag_vdr(bit, data, 0);
+ vdr_large(bit,string,0);
+ }if(d==2){
+
+ vdr_large(bit,string,out);
+ printf("###read data#%s###read data#\n",out);
+ }else{
+
+ jtag_vir(inst);
+ //printf("%d\n",inst);
+ }
+
+ pch = strtok (NULL, ",");
+
+ }
+ return 0;
+}
+
+int compare_values( unsigned * val1, unsigned * val2, int words, unsigned int address){
+
+ int i,error=0;
+ for(i=0;imem_size){
+ printf("\n\n Warning: %s file size (%x) is larger than the given memory size (%x). I will stop writing on end of memory address\n\n",binary_file_name,file_size,mem_size);
+ file_size=mem_size;
+ }
+ fclose(fp);
+ //disable the cpu
+ jtag_vir(RD_WR_STATUS);
+ jtag_vdr(BIT_NUM, 0x1, &out);
+ //getchar();
+ jtag_vir(UPDATE_WB_ADDR);
+ // change memory sizes from byte to word
+ memory_offset_in_word=memory_offset /BYTE_NUM;
+ //size of buffer
+ num= (BYTE_NUM < sizeof(unsigned )) ? file_size /BYTE_NUM : file_size /sizeof(unsigned );
+
+ jtag_vdr(BIT_NUM, memory_offset_in_word, 0);
+ jtag_vir(UPDATE_WB_WR_DATA);
+
+ printf ("start programing\n");
+ //printf ("num=%d\n",num);
+ for(i=0;isize)? 0 : size-count*8;
+
+ sscanf(hexstring+start, "%08x", &val[count-1]);
+ *(hexstring+start)=0;
+ }
+
+ // printf("size=%d, hexnum=%u\n",size,hexnum);
+
+
+ return hexnum;
+}
+
+
+void hexgen( char * hexstring, unsigned * val, int words ){
+ size_t count = 0;
+ sprintf(hexstring,"0x");
+ for(count = 0; count < words; count++) {
+ if(count == 0) sprintf((hexstring+2),"%x",val[words-count-1]);
+ else sprintf(hexstring,"%08x",val[words-count-1]);
+ hexstring+=strlen(hexstring);
+ }
+
+ // return hexnum;
+}
+
+
jtag/simple_jtag/jtag_main.c
Property changes :
Added: svn:executable
## -0,0 +1 ##
+*
\ No newline at end of property
Index: jtag/simple_jtag/list_usb_dev.c
===================================================================
--- jtag/simple_jtag/list_usb_dev.c (nonexistent)
+++ jtag/simple_jtag/list_usb_dev.c (revision 28)
@@ -0,0 +1,59 @@
+#include
+#include
+#include
+#include
+#include
+#include
+
+
+int main(){
+// discover devices
+
+if (libusb_init(NULL) < 0)
+ return -1;
+
+
+
+
+
+
+
+
+
+
+libusb_context *ctx=NULL;
+//uint16_t vendor_id,
+//uint16_t product_id
+
+ struct libusb_device **devs;
+ //struct libusb_device *found = NULL;
+ struct libusb_device *dev;
+ //struct libusb_device_handle *handle = NULL;
+ size_t i = 0;
+ int r;
+ if (libusb_get_device_list(ctx, &devs) < 0)
+ return -1;
+ while ((dev = devs[i++]) != NULL) {
+ struct libusb_device_descriptor desc;
+ r = libusb_get_device_descriptor(dev, &desc);
+ if (r < 0)
+ goto out;
+ printf("vid=%x,\t pid=%x\n",desc.idVendor,desc.idProduct);
+ //if (desc.idVendor == vendor_id && desc.idProduct == product_id) {
+ // found = dev;
+ // break;
+ //}
+ }
+ //if (found) {
+ // r = libusb_open(found, &handle);
+ // if (r < 0)
+ // handle = NULL;
+ //}
+out:
+ libusb_free_device_list(devs, 1);
+ //return handle;
+
+return 0;
+
+}
+
jtag/simple_jtag/list_usb_dev.c
Property changes :
Added: svn:executable
## -0,0 +1 ##
+*
\ No newline at end of property
Index: jtag/simple_jtag/usb-blaster-protocol.txt
===================================================================
--- jtag/simple_jtag/usb-blaster-protocol.txt (nonexistent)
+++ jtag/simple_jtag/usb-blaster-protocol.txt (revision 28)
@@ -0,0 +1,60 @@
+http://sf.net/apps/mediawiki/urjtag/index.php?title=Cable_Altera_USB-Blaster
+----------------------------------------------------------------------------
+
+Altera USB-Blaster
+------------------
+
+General
+-------
+ _________
+ | |
+ | AT93C46 |
+ |_________|
+ __|__________ _________
+ | | | |
+ USB__| FTDI 245BM |__| EPM7064 |__JTAG (B_TDO,B_TDI,B_TMS,B_TCK)
+ |_____________| |_________|
+ __|__________ _|___________
+ | | | |
+ | 6 MHz XTAL | | 24 MHz Osc. |
+ |_____________| |_____________|
+
+
+Quoting from ixo.de (http://www.ixo.de/info/usb_jtag/)
+usb_jtag/device/c51/usbjtag.c comments:
+
+usb_jtag firmware now happens to behave just like the combination of
+FT245BM and Altera-programmed EPM7064 CPLD in Altera's USB-Blaster.
+The CPLD knows two major modes: Bit banging mode and Byte shift mode.
+It starts in Bit banging mode. While bytes are received from the host
+on EP2OUT, each byte B of them is processed as follows:
+
+Bit banging mode
+----------------
+1. Remember bit 6 (0x40) in B as the "Read bit".
+2. If bit 7 (0x80) is set, switch to Byte shift mode for the coming X
+ bytes ( X := B & 0x3F ), and don't do anything else now.
+3. Otherwise, set the JTAG signals as follows:
+ - TCK/DCLK high if bit 0 was set (0x01), otherwise low
+ - TMS/nCONFIG high if bit 1 was set (0x02), otherwise low
+ - nCE high if bit 2 was set (0x04), otherwise low
+ - nCS high if bit 3 was set (0x08), otherwise low
+ - TDI/ASDI/DATAO high if bit 4 was set (0x10), otherwise low
+ - Output Enable/LED active if bit 5 was set (0x20), otherwise low
+4. If "Read bit" (0x40) was set, record the state of TDO(CONF_DONE) and
+ DATAOUT/(nSTATUS) pins and put is as a byte( (DATAOUT<<1)|TDO) in the
+ output FIFO _to_ the host.
+
+Byte shift mode
+---------------
+1. Load shift register with byte from host
+2. Do 8 times (i.e. for each bit of the byte; implemented in shift.a51)
+ - if nCS=1, set carry bit from TDO, else set carry bit from DATAOUT
+ (Active Serial mode)
+ - Rotate shift register through carry bit
+ - TDI := Carry bit
+ - Raise TCK, then lower TCK.
+3. If "Read bit" was set when switching into byte shift mode, record the
+ shift register content and put it into the FIFO to the host.
+
+
jtag/simple_jtag/usb-blaster-protocol.txt
Property changes :
Added: svn:executable
## -0,0 +1 ##
+*
\ No newline at end of property
© copyright 1999-2024
OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.