+/*! \file jtag.h
+ \author Travis Goodspeed
+ \brief JTAG handler functions.
+*/
+
+#ifndef JTAG_H
+#define JTAG_H
+
+#include "app.h"
+
+#define JTAG 0x10
+
+//! All states in the JTAG TAP
+enum eTAPState
+{
+ UNKNOWN = 0x0000,
+ TEST_LOGIC_RESET = 0x0001,
+ RUN_TEST_IDLE = 0x0002,
+ SELECT_DR_SCAN = 0x0004,
+ CAPTURE_DR = 0x0008,
+ SHIFT_DR = 0x0010,
+ EXIT1_DR = 0x0020,
+ PAUSE_DR = 0x0040,
+ EXIT2_DR = 0x0080,
+ UPDATE_DR = 0x0100,
+ SELECT_IR_SCAN = 0x0200,
+ CAPTURE_IR = 0x0400,
+ SHIFT_IR = 0x0800,
+ EXIT1_IR = 0x1000,
+ PAUSE_IR = 0x2000,
+ EXIT2_IR = 0x4000,
+ UPDATE_IR = 0x8000
+};
+
+extern unsigned char jtagid;
+
+//! the global state of the JTAG TAP
+extern enum eTAPState jtag_state;
+
+//! Returns true if we're in any of the data register states
+int in_dr();
+//! Returns true if we're in any of the instruction register states
+int in_ir();
+//! Returns true if we're in run-test-idle state
+int in_run_test_idle();
+//! Check the state
+int in_state(enum eTAPState state);
+
+//! jtag_trans_n flags
+enum eTransFlags
+{
+ MSB = 0x0,
+ LSB = 0x1,
+ NOEND = 0x2,
+ NORETIDLE = 0x4
+};
+
+//! Shift n bytes.
+uint32_t jtag_trans_n(uint32_t word,
+ uint8_t bitcount,
+ enum eTransFlags flags);
+//! Shift 8 bits in/out of selected register
+uint8_t jtag_trans_8(uint8_t in);
+//! Shift 16 bits in/out of selected register
+uint16_t jtag_trans_16(uint16_t in);