From c0fb071c912f8d84ec95f39e5cf56690c51199c9 Mon Sep 17 00:00:00 2001 From: Greg Davill Date: Sun, 19 Apr 2020 12:43:17 +0930 Subject: [PATCH] cleanup of un-used code --- ecpprog.c | 32 ++++++++++---------- jtag_tap.c | 26 +++------------- mpsse.c | 89 ------------------------------------------------------ 3 files changed, 21 insertions(+), 126 deletions(-) diff --git a/ecpprog.c b/ecpprog.c index 5483a0c..7c57209 100644 --- a/ecpprog.c +++ b/ecpprog.c @@ -118,7 +118,7 @@ static void flash_read_id() //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); @@ -227,7 +227,7 @@ static void flash_write_enable() uint8_t data[1] = { FC_WE }; //flash_chip_select(); - mpsse_xfer_spi(data, 1); + //mpsse_xfer_spi(data, 1); //flash_chip_deselect(); if (verbose) { @@ -242,7 +242,7 @@ static void flash_bulk_erase() uint8_t data[1] = { FC_CE }; //flash_chip_select(); - mpsse_xfer_spi(data, 1); + //mpsse_xfer_spi(data, 1); //flash_chip_deselect(); } @@ -253,7 +253,7 @@ static void flash_4kB_sector_erase(int addr) 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(); } @@ -264,7 +264,7 @@ static void flash_32kB_sector_erase(int addr) 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(); } @@ -275,7 +275,7 @@ static void flash_64kB_sector_erase(int addr) 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(); } @@ -287,8 +287,8 @@ static void flash_prog(int addr, uint8_t *data, int n) 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) @@ -304,9 +304,9 @@ static void flash_read(int addr, uint8_t *data, int n) 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) @@ -325,7 +325,7 @@ static void flash_wait() 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) { @@ -365,7 +365,7 @@ static void flash_disable_protection() // 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(); @@ -374,7 +374,7 @@ static void flash_disable_protection() data[0] = FC_RSR1; //flash_chip_select(); - mpsse_xfer_spi(data, 2); + //mpsse_xfer_spi(data, 2); //flash_chip_deselect(); if (data[1] != 0x00) @@ -964,11 +964,11 @@ int main(int argc, char **argv) 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(); } diff --git a/jtag_tap.c b/jtag_tap.c index 90593fe..3775ca0 100644 --- a/jtag_tap.c +++ b/jtag_tap.c @@ -138,7 +138,7 @@ void jtag_init(void) jtag_go_to_state(STATE_TEST_LOGIC_RESET); } -uint8_t data[512]; +uint8_t data[1024]; uint8_t* ptr; uint8_t rx_cnt; @@ -148,15 +148,8 @@ static inline uint8_t jtag_pulse_clock_and_read_tdo(bool tms, bool tdi) { 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++; } @@ -168,8 +161,6 @@ void jtag_tap_shift( 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; @@ -191,12 +182,10 @@ void jtag_tap_shift( 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) @@ -240,8 +229,6 @@ void jtag_go_to_state(unsigned state) mpsse_xfer(data, 3, 0); } } - - printf(" - Remain: %u \n", mpsse_ftdic.readbuffer_remaining); } void jtag_wait_time(uint32_t microseconds) @@ -261,8 +248,5 @@ void jtag_wait_time(uint32_t microseconds) data[1] = remain; mpsse_xfer(data, 2, 0); } - - - printf(" -- Remain: %u \n", mpsse_ftdic.readbuffer_remaining); } diff --git a/mpsse.c b/mpsse.c index 203bac3..269d0da 100644 --- a/mpsse.c +++ b/mpsse.c @@ -147,95 +147,6 @@ void mpsse_xfer(uint8_t* data_buffer, uint16_t send_length, uint16_t receive_len } } -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 */ -- 2.30.2