diff options
author | Tim Newsome <tim@sifive.com> | 2017-02-06 19:17:23 -0800 |
---|---|---|
committer | Tim Newsome <tim@sifive.com> | 2017-02-06 19:17:23 -0800 |
commit | 4695be7cea868b34082787d5728c35577d0c05d1 (patch) | |
tree | b9d730b3955e924e0b198ccc6c7d5014d06817f9 /riscv/remote_bitbang.h | |
parent | 9be157042081e894e6c12dc96449cf865469bcfe (diff) | |
download | riscv-isa-sim-4695be7cea868b34082787d5728c35577d0c05d1.zip riscv-isa-sim-4695be7cea868b34082787d5728c35577d0c05d1.tar.gz riscv-isa-sim-4695be7cea868b34082787d5728c35577d0c05d1.tar.bz2 |
Refactor remote bitbang code.
Diffstat (limited to 'riscv/remote_bitbang.h')
-rw-r--r-- | riscv/remote_bitbang.h | 138 |
1 files changed, 3 insertions, 135 deletions
diff --git a/riscv/remote_bitbang.h b/riscv/remote_bitbang.h index 5f2a3ea..c0aa7e0 100644 --- a/riscv/remote_bitbang.h +++ b/riscv/remote_bitbang.h @@ -3,14 +3,7 @@ #include <stdint.h> -#define DEBUG -#ifdef DEBUG -# define D(x) x -#else -# define D(x) -#endif // DEBUG - -class sim_t; +#include "jtag_dtm.h" template <typename T> class circular_buffer_t @@ -51,143 +44,18 @@ public: void append(T value); }; -typedef enum { - TEST_LOGIC_RESET, - RUN_TEST_IDLE, - SELECT_DR_SCAN, - CAPTURE_DR, - SHIFT_DR, - EXIT1_DR, - PAUSE_DR, - EXIT2_DR, - UPDATE_DR, - SELECT_IR_SCAN, - CAPTURE_IR, - SHIFT_IR, - EXIT1_IR, - PAUSE_IR, - EXIT2_IR, - UPDATE_IR -} jtag_state_t; - -class jtag_tap_t -{ - static const unsigned idcode_ir = 1; - static const unsigned idcode_dr = 0xdeadbeef; - static const unsigned dtmcontrol_ir = 0x10; - - public: - jtag_tap_t() : - state(TEST_LOGIC_RESET) {} - - void reset() { - state = TEST_LOGIC_RESET; - } - - void set_pins(bool tck, bool tms, bool tdi) { - if (!_tck && tck) { - // Positive clock edge. - - switch (state) { - case SHIFT_DR: - dr >>= 1; - dr |= (uint64_t) _tdi << (dr_length-1); - break; - case SHIFT_IR: - ir >>= 1; - ir |= _tdi << (ir_length-1); - break; - default: - break; - } - state = next[state][_tms]; - switch (state) { - case TEST_LOGIC_RESET: - ir = idcode_ir; - break; - case CAPTURE_DR: - switch (ir) { - case idcode_ir: - dr = 0xdeadbeef; - dr_length = 32; - break; - case dtmcontrol_ir: - dr = dtmcontrol; - dr_length = 32; - default: - D(fprintf(stderr, "Unsupported IR: 0x%x\n", ir)); - break; - } - break; - case SHIFT_DR: - _tdo = dr & 1; - break; - case UPDATE_DR: - break; - case CAPTURE_IR: - break; - case SHIFT_IR: - _tdo = ir & 1; - break; - case UPDATE_IR: - break; - default: - break; - } - } - - _tck = tck; - _tms = tms; - _tdi = tdi; - - D(fprintf(stderr, "state=%2d tck=%d tms=%d tdi=%d tdo=%d ir=0x%x dr=0x%lx\n", - state, _tck, _tms, _tdi, _tdo, ir, dr)); - } - - bool tdo() const { return _tdo; } - - private: - bool _tck, _tms, _tdi, _tdo; - uint32_t ir; - const unsigned ir_length = 5; - uint64_t dr; - unsigned dr_length; - - uint32_t dtmcontrol = 1; - - jtag_state_t state; - const jtag_state_t next[16][2] = { - /* TEST_LOGIC_RESET */ { RUN_TEST_IDLE, TEST_LOGIC_RESET }, - /* RUN_TEST_IDLE */ { RUN_TEST_IDLE, SELECT_DR_SCAN }, - /* SELECT_DR_SCAN */ { CAPTURE_DR, SELECT_IR_SCAN }, - /* CAPTURE_DR */ { SHIFT_DR, EXIT1_DR }, - /* SHIFT_DR */ { SHIFT_DR, EXIT1_DR }, - /* EXIT1_DR */ { PAUSE_DR, UPDATE_DR }, - /* PAUSE_DR */ { PAUSE_DR, EXIT2_DR }, - /* EXIT2_DR */ { SHIFT_DR, UPDATE_DR }, - /* UPDATE_DR */ { RUN_TEST_IDLE, SELECT_DR_SCAN }, - /* SELECT_IR_SCAN */ { CAPTURE_IR, TEST_LOGIC_RESET }, - /* CAPTURE_IR */ { SHIFT_IR, EXIT1_IR }, - /* SHIFT_IR */ { SHIFT_IR, EXIT1_IR }, - /* EXIT1_IR */ { PAUSE_IR, UPDATE_IR }, - /* PAUSE_IR */ { PAUSE_IR, EXIT2_IR }, - /* EXIT2_IR */ { SHIFT_IR, UPDATE_IR }, - /* UPDATE_IR */ { RUN_TEST_IDLE, SELECT_DR_SCAN } - }; -}; - class remote_bitbang_t { public: // Create a new server, listening for connections from localhost on the given // port. - remote_bitbang_t(uint16_t port, sim_t *sim); + remote_bitbang_t(uint16_t port, jtag_dtm_t *tap); // Do a bit of work. void tick(); private: - jtag_tap_t tap; + jtag_dtm_t *tap; int socket_fd; int client_fd; |