1 #ifndef REMOTE_BITBANG_H
2 #define REMOTE_BITBANG_H
16 class circular_buffer_t
19 // The buffer can store capacity-1 data elements.
20 circular_buffer_t(unsigned int capacity
) : data(new T
[capacity
]),
21 start(0), end(0), capacity(capacity
) {}
22 circular_buffer_t() : start(0), end(0), capacity(0) {}
23 ~circular_buffer_t() { delete[] data
; }
26 unsigned int start
; // Data start, inclusive.
27 unsigned int end
; // Data end, exclusive.
28 unsigned int capacity
; // Size of the buffer.
29 unsigned int size() const;
30 bool empty() const { return start
== end
; }
31 bool full() const { return ((end
+1) % capacity
) == start
; }
32 T
entry(unsigned index
) { return data
[(start
+ index
) % capacity
]; }
34 // Return size and address of the block of RAM where more data can be copied
35 // to be added to the buffer.
36 unsigned int contiguous_empty_size() const;
37 T
*contiguous_empty() { return data
+ end
; }
38 void data_added(unsigned int bytes
);
40 unsigned int contiguous_data_size() const;
41 T
*contiguous_data() { return data
+ start
; }
42 // Tell the buffer that some bytes were consumed from the start of the
44 void consume(unsigned int bytes
);
48 T
operator[](unsigned int i
) const { return data
[(start
+ i
) % capacity
]; }
50 void append(const T
*src
, unsigned int count
);
77 state(TEST_LOGIC_RESET
) {}
80 state
= TEST_LOGIC_RESET
;
83 void set_pins(bool tck
, bool tms
, bool tdi
) {
85 // Positive clock edge.
87 D(fprintf(stderr
, "Next state: %d\n", state
));
89 state
= next
[state
][_tms
];
92 case TEST_LOGIC_RESET
:
102 dr
|= (uint64_t) _tdi
<< (dr_length
-1);
111 ir
= ir
| (_tdi
<< (ir_length
-1));
123 D(fprintf(stderr
, "tck=%d tms=%d tdi=%d tdo=%d ir=0x%x dr=0x%lx\n",
124 _tck
, _tms
, _tdi
, _tdo
, ir
, dr
));
127 bool tdo() const { return _tdo
; }
130 bool _tck
, _tms
, _tdi
, _tdo
;
137 const jtag_state_t next
[16][2] = {
138 /* TEST_LOGIC_RESET */ { RUN_TEST_IDLE
, TEST_LOGIC_RESET
},
139 /* RUN_TEST_IDLE */ { RUN_TEST_IDLE
, SELECT_DR_SCAN
},
140 /* SELECT_DR_SCAN */ { CAPTURE_DR
, SELECT_IR_SCAN
},
141 /* CAPTURE_DR */ { SHIFT_DR
, EXIT1_DR
},
142 /* SHIFT_DR */ { SHIFT_DR
, EXIT1_DR
},
143 /* EXIT1_DR */ { PAUSE_DR
, UPDATE_DR
},
144 /* PAUSE_DR */ { PAUSE_DR
, EXIT2_DR
},
145 /* EXIT2_DR */ { SHIFT_DR
, UPDATE_DR
},
146 /* UPDATE_DR */ { RUN_TEST_IDLE
, SELECT_DR_SCAN
},
147 /* SELECT_IR_SCAN */ { CAPTURE_IR
, TEST_LOGIC_RESET
},
148 /* CAPTURE_IR */ { SHIFT_IR
, EXIT1_IR
},
149 /* SHIFT_IR */ { SHIFT_IR
, EXIT1_IR
},
150 /* EXIT1_IR */ { PAUSE_IR
, UPDATE_IR
},
151 /* PAUSE_IR */ { PAUSE_IR
, EXIT2_IR
},
152 /* EXIT2_IR */ { SHIFT_IR
, UPDATE_IR
},
153 /* UPDATE_IR */ { RUN_TEST_IDLE
, SELECT_DR_SCAN
}
157 class remote_bitbang_t
160 // Create a new server, listening for connections from localhost on the given
162 remote_bitbang_t(uint16_t port
, sim_t
*sim
);
172 circular_buffer_t
<uint8_t> recv_buf
;
173 circular_buffer_t
<uint8_t> send_buf
;
175 // Check for a client connecting, and accept if there is one.
177 // Read as much into recv_buf as possible.
179 // Write as much of send_buf as possible.
182 // Process the input buffer.
183 void process_input();