/*!***************************************************************************
 * 
 * \file  JTAG-Out.h
 * 
 * \brief JTAG driver for Atmel ARM AT91SAM7x.
 *
 * - Compiler:           GNU GCC for ARM
 *
 *****************************************************************************
 *
 *  \author Pro Code Works, LLC. - http://www.ProCodeWorks.com
 *  \date June 2007
 *   
 * ----------------------------------------------------------------------------
 * "THE BEER-WARE LICENSE" (Revision 42):
 *  nelson@ProCodeWorks.com wrote this file. As long as you retain this notice you
 *  can do whatever you want with this stuff. If we meet some day, and you think
 *  this stuff is worth it, you can buy me a beer in return. Nelson Yaple
 *  ----------------------------------------------------------------------------
 * 
 *---------------------------------------------------------------------------*/



typedef enum { INSTRUCTION_REGISTER = 0,
			   	DATA_REGISTER,
			   	MAX_SHIFT_REGISTER } SHIFT_REGISTER_TYPE;

                /* JSM states */
typedef enum {	TEST_LOGIC_RESET = 0,
				RUN_TEST_IDLE,
				PAUSE_DR,
				PAUSE_IR,
				SHIFT_DR,
				SHIFT_IR,
				UNDEFINED_JTAG_STATE,
				MAX_JTAG_STATE
			  } JTAG_STATE_TYPE;

typedef unsigned char SCAN_DATA_TYPE;

// --- Bit defines for the JTAG IO Pins
#define TDI_PIN 27
#define TCK_PIN 30
#define TMS_PIN 29
#define TDO_PIN 28
#define TRST_PIN 21
#define TSEL0_PIN 19
#define TSEL1_PIN 20

#define TDI     (1 << TDI_PIN)
#define TCK     (1 << TCK_PIN)
#define TMS     (1 << TMS_PIN)
#define TDO     (1 << TDO_PIN)
#define TRST    (1 << TRST_PIN)
#define TSEL0   (1 << TSEL0_PIN)
#define TSEL1   (1 << TSEL1_PIN)

// --- Some EJTAG Instruction Registers ---
#define INSTR_EXTEST    0x00
#define INSTR_IDCODE    0x01
#define INSTR_SAMPLE    0x02
#define INSTR_IMPCODE   0x03
#define INSTR_ADDRESS   0x08
#define INSTR_DATA      0x09
#define INSTR_CONTROL   0x0A
#define INSTR_BYPASS    0xFF


void JTAG_Initialize(void);

void JTAG_ResetJSM(
    int Select,
    Bool Reset,
    JTAG_STATE_TYPE state_e);

void JTAG_ScanIO(
    int Select,
	SHIFT_REGISTER_TYPE jtag_register_e, 
	int length_in_bits, 
    SCAN_DATA_TYPE *out_data, 
    SCAN_DATA_TYPE *in_data, 
    JTAG_STATE_TYPE state_e);

unsigned char ClockJTAG(
    int Select,
    unsigned int, 
    unsigned int);

void ScanDataInOut(
    int Select,
    unsigned char *,
    unsigned int,
    unsigned char *);

void PulseClock(int Select);




