//flash_chip_select();
// Write command and read first 4 bytes
- //mpsse_xfer_spi(data, len);
+ ////mpsse_xfer_spi(data, len);
xfer_spi(data, len);
//jtag_go_to_state(STATE_SHIFT_DR);
//jtag_tap_shift(data, data, 8*5, false);
uint8_t data[1] = { FC_WE };
//flash_chip_select();
- mpsse_xfer_spi(data, 1);
+ //mpsse_xfer_spi(data, 1);
//flash_chip_deselect();
if (verbose) {
uint8_t data[1] = { FC_CE };
//flash_chip_select();
- mpsse_xfer_spi(data, 1);
+ //mpsse_xfer_spi(data, 1);
//flash_chip_deselect();
}
uint8_t command[4] = { FC_SE, (uint8_t)(addr >> 16), (uint8_t)(addr >> 8), (uint8_t)addr };
//flash_chip_select();
- mpsse_send_spi(command, 4);
+ //mpsse_send_spi(command, 4);
//flash_chip_deselect();
}
uint8_t command[4] = { FC_BE32, (uint8_t)(addr >> 16), (uint8_t)(addr >> 8), (uint8_t)addr };
//flash_chip_select();
- mpsse_send_spi(command, 4);
+ //mpsse_send_spi(command, 4);
//flash_chip_deselect();
}
uint8_t command[4] = { FC_BE64, (uint8_t)(addr >> 16), (uint8_t)(addr >> 8), (uint8_t)addr };
//flash_chip_select();
- mpsse_send_spi(command, 4);
+ //mpsse_send_spi(command, 4);
//flash_chip_deselect();
}
uint8_t command[4] = { FC_PP, (uint8_t)(addr >> 16), (uint8_t)(addr >> 8), (uint8_t)addr };
//flash_chip_select();
- mpsse_send_spi(command, 4);
- mpsse_send_spi(data, n);
+ //mpsse_send_spi(command, 4);
+ //mpsse_send_spi(data, n);
//flash_chip_deselect();
if (verbose)
uint8_t command[4] = { FC_RD, (uint8_t)(addr >> 16), (uint8_t)(addr >> 8), (uint8_t)addr };
//flash_chip_select();
- mpsse_send_spi(command, 4);
+ //mpsse_send_spi(command, 4);
memset(data, 0, n);
- mpsse_xfer_spi(data, n);
+ //mpsse_xfer_spi(data, n);
//flash_chip_deselect();
if (verbose)
uint8_t data[2] = { FC_RSR1 };
//flash_chip_select();
- mpsse_xfer_spi(data, 2);
+ //mpsse_xfer_spi(data, 2);
//flash_chip_deselect();
if ((data[1] & 0x01) == 0) {
// Write Status Register 1 <- 0x00
uint8_t data[2] = { FC_WSR1, 0x00 };
//flash_chip_select();
- mpsse_xfer_spi(data, 2);
+ //mpsse_xfer_spi(data, 2);
//flash_chip_deselect();
flash_wait();
data[0] = FC_RSR1;
//flash_chip_select();
- mpsse_xfer_spi(data, 2);
+ //mpsse_xfer_spi(data, 2);
//flash_chip_deselect();
if (data[1] != 0x00)
break;
if (verbose)
fprintf(stderr, "sending %d bytes.\n", rc);
- mpsse_send_spi(buffer, rc);
+ //mpsse_send_spi(buffer, rc);
}
- mpsse_send_dummy_bytes(6);
- mpsse_send_dummy_bit();
+ //mpsse_send_dummy_bytes(6);
+ //mpsse_send_dummy_bit();
}
jtag_go_to_state(STATE_TEST_LOGIC_RESET);
}
-uint8_t data[512];
+uint8_t data[1024];
uint8_t* ptr;
uint8_t rx_cnt;
{
uint8_t ret;
*ptr++ = MC_DATA_TMS | MC_DATA_IN | MC_DATA_LSB | MC_DATA_BITS;
- *ptr++ = 0;
-
- uint8_t data0 = 0;
- if(tdi)
- data0 |= 0x80;
- if(tms)
- data0 |= 0x01;
-
- *ptr++ = data0;
+ *ptr++ = 0;
+ *ptr++ = (tdi ? 0x80 : 0) | (tms ? 0x01 : 0);
rx_cnt++;
}
bool must_end)
{
- printf("Remain: %u \n", mpsse_ftdic.readbuffer_remaining);
-
uint32_t bit_count = data_bits;
uint32_t byte_count = (data_bits + 7) / 8;
rx_cnt = 0;
mpsse_xfer(data, ptr-data, rx_cnt);
+ /* Data out from the FTDI is actually from an internal shift register
+ * Instead of reconstructing the bitpattern, we can just take every 8th byte.*/
for(int i = 0; i < rx_cnt/8; i++)
output_data[i] = data[7+i*8];
-
-
- printf("finish: %u - %u \n", rx_cnt, mpsse_ftdic.readbuffer_remaining);
-
}
void jtag_state_ack(bool tms)
mpsse_xfer(data, 3, 0);
}
}
-
- printf(" - Remain: %u \n", mpsse_ftdic.readbuffer_remaining);
}
void jtag_wait_time(uint32_t microseconds)
data[1] = remain;
mpsse_xfer(data, 2, 0);
}
-
-
- printf(" -- Remain: %u \n", mpsse_ftdic.readbuffer_remaining);
}
}
}
-void mpsse_send_spi(uint8_t *data, int n)
-{
- if (n < 1)
- return;
-
- /* Output only, update data on negative clock edge. */
- mpsse_send_byte(MC_DATA_OUT | MC_DATA_OCN);
- mpsse_send_byte(n - 1);
- mpsse_send_byte((n - 1) >> 8);
-
- int rc = ftdi_write_data(&mpsse_ftdic, data, n);
- if (rc != n) {
- fprintf(stderr, "Write error (chunk, rc=%d, expected %d).\n", rc, n);
- mpsse_error(2);
- }
-}
-
-void mpsse_xfer_spi(uint8_t *data, int n)
-{
- if (n < 1)
- return;
-
- /* Input and output, update data on negative edge read on positive. */
- mpsse_send_byte(MC_DATA_IN | MC_DATA_OUT | MC_DATA_OCN);
- mpsse_send_byte(n - 1);
- mpsse_send_byte((n - 1) >> 8);
-
- int rc = ftdi_write_data(&mpsse_ftdic, data, n);
- if (rc != n) {
- fprintf(stderr, "Write error (chunk, rc=%d, expected %d).\n", rc, n);
- mpsse_error(2);
- }
-
- for (int i = 0; i < n; i++)
- data[i] = mpsse_recv_byte();
-}
-
-uint8_t mpsse_xfer_spi_bits(uint8_t data, int n)
-{
- if (n < 1)
- return 0;
-
- /* Input and output, update data on negative edge read on positive, bits. */
- mpsse_send_byte(MC_DATA_IN | MC_DATA_OUT | MC_DATA_OCN | MC_DATA_BITS);
- mpsse_send_byte(n - 1);
- mpsse_send_byte(data);
-
- return mpsse_recv_byte();
-}
-
-void mpsse_set_gpio(uint8_t gpio, uint8_t direction)
-{
- mpsse_send_byte(MC_SETB_LOW);
- mpsse_send_byte(gpio); /* Value */
- mpsse_send_byte(direction); /* Direction */
-}
-
-int mpsse_readb_low(void)
-{
- uint8_t data;
- mpsse_send_byte(MC_READB_LOW);
- data = mpsse_recv_byte();
- return data;
-}
-
-int mpsse_readb_high(void)
-{
- uint8_t data;
- mpsse_send_byte(MC_READB_HIGH);
- data = mpsse_recv_byte();
- return data;
-}
-
-void mpsse_send_dummy_bytes(uint8_t n)
-{
- // add 8 x count dummy bits (aka n bytes)
- mpsse_send_byte(MC_CLK_N8);
- mpsse_send_byte(n - 1);
- mpsse_send_byte(0x00);
-
-}
-
-void mpsse_send_dummy_bit(void)
-{
- // add 1 dummy bit
- mpsse_send_byte(MC_CLK_N);
- mpsse_send_byte(0x00);
-}
-
void mpsse_jtag_init(){
mpsse_send_byte(MC_SETB_LOW);
mpsse_send_byte(0x08); /* Value */