//flash_chip_select();
//mpsse_send_spi(command, 4);
+ send_spi(command, 4);
memset(data, 0, n);
- //mpsse_xfer_spi(data, n);
+ xfer_spi(data, n);
//flash_chip_deselect();
if (verbose)
}
void xfer_spi(uint8_t* data, uint32_t len){
- /* Flip bit order of all bytes */
+ /* Reverse bit order of all bytes */
for(int i = 0; i < len; i++){
data[i] = bit_reverse(data[i]);
}
- jtag_go_to_state(STATE_SHIFT_DR);
+ /* Don't switch states if we're already in SHIFT-DR */
+ if(jtag_current_state() != STATE_SHIFT_DR)
+ jtag_go_to_state(STATE_SHIFT_DR);
jtag_tap_shift(data, data, len * 8, true);
+ /* Reverse bit order of all return bytes */
+ for(int i = 0; i < len; i++){
+ data[i] = bit_reverse(data[i]);
+ }
+}
+
+void send_spi(uint8_t* data, uint32_t len){
+ uint8_t unused[len];
+
/* Flip bit order of all bytes */
for(int i = 0; i < len; i++){
data[i] = bit_reverse(data[i]);
}
+
+ jtag_go_to_state(STATE_SHIFT_DR);
+ /* Stay in SHIFT-DR state, this keep CS low */
+ jtag_tap_shift(data, unused, len * 8, false);
}
// ---------------------------------------------------------
fprintf(stderr, "status..\n");
read_status_register();
+
+ /* Reset ECP5 to release SPI interface */
+ ecp_jtag_cmd(ISC_ENABLE);
+ ecp_jtag_cmd(ISC_ERASE);
+ ecp_jtag_cmd(ISC_DISABLE);
+
+ /* Put device into SPI bypass mode */
+ enter_spi_background_mode();
//usleep(20000);
if (test_mode)
{
- /* Reset ECP5 to release SPI interface */
- ecp_jtag_cmd(ISC_ENABLE);
- ecp_jtag_cmd(ISC_ERASE);
- ecp_jtag_cmd(ISC_DISABLE);
-
- /* Put device into SPI bypass mode */
- enter_spi_background_mode();
-
flash_reset();
flash_read_id();
}
jtag_go_to_state(STATE_TEST_LOGIC_RESET);
}
-uint8_t data[1024];
+uint8_t data[32*1024];
uint8_t* ptr;
-uint8_t rx_cnt;
+uint16_t rx_cnt;
extern struct ftdi_context mpsse_ftdic;
rx_cnt++;
}
-
-void jtag_tap_shift(
+static void _jtag_tap_shift(
uint8_t *input_data,
uint8_t *output_data,
uint32_t data_bits,
bool must_end)
{
+ //printf("_jtag_tap_shift(0x%08x,0x%08x,%u,%s);\n",input_data, output_data, data_bits, must_end ? "true" : "false");
uint32_t bit_count = data_bits;
uint32_t byte_count = (data_bits + 7) / 8;
rx_cnt = 0;
output_data[i] = data[7+i*8];
}
+#define MIN(a,b) (a < b) ? a : b
+
+void jtag_tap_shift(
+ uint8_t *input_data,
+ uint8_t *output_data,
+ uint32_t data_bits,
+ bool must_end)
+{
+ uint32_t data_bits_sent = 0;
+ while(data_bits_sent != data_bits){
+
+ uint32_t _data_bits = MIN(256, data_bits);
+ bool last = (data_bits_sent + _data_bits) == data_bits;
+
+ _jtag_tap_shift(
+ input_data + data_bits_sent/8,
+ output_data + data_bits_sent/8,
+ _data_bits,
+ last & must_end
+ );
+ data_bits_sent += _data_bits;
+ }
+}
+
void jtag_state_ack(bool tms)
{
if (tms) {