jtagonizer

yet another JTAG tool
git clone http://frotz.net/git/jtagonizer.git
Log | Files | Refs | README

jtag.h (3455B)


      1 // Copyright 2014 Brian Swetland <swetland@frotz.net>
      2 //
      3 // Licensed under the Apache License, Version 2.0 (the "License");
      4 // you may not use this file except in compliance with the License.
      5 // You may obtain a copy of the License at
      6 //
      7 // http://www.apache.org/licenses/LICENSE-2.0
      8 //
      9 // Unless required by applicable law or agreed to in writing, software
     10 // distributed under the License is distributed on an "AS IS" BASIS,
     11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
     12 // See the License for the specific language governing permissions and
     13 // limitations under the License.
     14 
     15 #ifndef _JTAG_
     16 #define _JTAG_
     17 
     18 typedef unsigned char u8;
     19 typedef unsigned short u16;
     20 typedef unsigned int u32;
     21 typedef unsigned long u64;
     22 
     23 #define JTAG_RESET	0
     24 #define JTAG_IDLE	1
     25 #define JTAG_DRSELECT	2
     26 #define JTAG_DRCAPTURE	3
     27 #define JTAG_DRSHIFT	4
     28 #define JTAG_DREXIT1	5
     29 #define JTAG_DRPAUSE	6
     30 #define JTAG_DREXIT2	7
     31 #define JTAG_DRUPDATE	8
     32 #define JTAG_IRSELECT	9
     33 #define JTAG_IRCAPTURE	10
     34 #define JTAG_IRSHIFT	11
     35 #define JTAG_IREXIT1	12
     36 #define JTAG_IRPAUSE	13
     37 #define JTAG_IREXIT2	14
     38 #define JTAG_IRUPDATE	15
     39 
     40 typedef struct JTAG JTAG;
     41 
     42 int jtag_mpsse_open(JTAG **jtag);
     43 
     44 void jtag_close(JTAG *jtag);
     45 
     46 int jtag_setspeed(JTAG *jtag, int khz);
     47 
     48 // which state to arrive at upon completion of jtag_ir_*()
     49 void jtag_set_ir_idle(JTAG *jtag, unsigned state);
     50 
     51 // which state to arrive at upon completion of jtag_dr_*()
     52 void jtag_set_dr_idle(JTAG *jtag, unsigned state);
     53 
     54 // bits to shift in ahead/behind the args for jtag_xr_*()
     55 void jtag_set_ir_prefix(JTAG *jtag, unsigned count, const void *bits);
     56 void jtag_set_ir_postfix(JTAG *jtag, unsigned count, const void *bits);
     57 void jtag_set_dr_prefix(JTAG *jtag, unsigned count, const void *bits);
     58 void jtag_set_dr_postfix(JTAG *jtag, unsigned count, const void *bits);
     59 
     60 // clear all prefix/postfix patterns and return to default
     61 // idle states
     62 void jtag_clear_state(JTAG *jtag);
     63 
     64 // Move jtag state machine from current state to new state.
     65 // Moving to JTAG_RESET will work even if current state
     66 // is out of sync.
     67 void jtag_goto(JTAG *jtag, unsigned state);
     68 
     69 // Move to IRSHIFT, shift count bits, then move to after_ir state.
     70 void jtag_ir_wr(JTAG *jtag, unsigned count, const void *wbits);
     71 void jtag_ir_rd(JTAG *jtag, unsigned count, void *rbits);
     72 void jtag_ir_io(JTAG *jtag, unsigned count, const void *wbits, void *rbits);
     73 
     74 // Move to DRSHIFT, shift count bits, then move to after_dr state;
     75 void jtag_dr_wr(JTAG *jtag, unsigned count, const void *wbits);
     76 void jtag_dr_rd(JTAG *jtag, unsigned count, void *rbits);
     77 void jtag_dr_io(JTAG *jtag, unsigned count, const void *wbits, void *rbits);
     78 
     79 // Move to IDLE and stay there for count clocks
     80 void jtag_idle(JTAG *jtag, unsigned count);
     81 
     82 int jtag_commit(JTAG *jtag);
     83 
     84 typedef struct {
     85 	unsigned idcode;
     86 	unsigned idmask;
     87 	unsigned irsize;
     88 	const char *name;
     89 	const char *family;
     90 } JTAG_INFO;
     91 
     92 // reset the bus and probe it
     93 // returns number of devices detected, negative on error
     94 int jtag_enumerate(JTAG *jtag);
     95 
     96 void jtag_print_chain(JTAG *jtag);
     97 
     98 // get information about the nth device on the chain
     99 JTAG_INFO *jtag_get_nth_device(JTAG *jtag, int n);
    100 
    101 // configure for communication with a single device
    102 // will setup ir/dr prefix and postfix
    103 int jtag_select_device(JTAG *jtag, unsigned idcode);
    104 
    105 // select by position in scan chain
    106 int jtag_select_device_nth(JTAG *jtag, int n);
    107 
    108 int jtag_select_by_family(JTAG *jtag, const char *family);
    109 
    110 #endif