tidy up code
authorGreg Davill <greg.davill@gmail.com>
Sun, 19 Apr 2020 08:31:25 +0000 (18:01 +0930)
committerGreg Davill <greg.davill@gmail.com>
Sun, 19 Apr 2020 08:31:25 +0000 (18:01 +0930)
ecpprog/ecpprog.c
ecpprog/mpsse.c

index 0c36874586aa2be8fdff2398e86e48e972eaba59..47e31033a095183c16d3bbb4678576397104960c 100644 (file)
@@ -528,18 +528,16 @@ static void read_status_register(){
 
 static void enter_spi_background_mode(){
 
-       uint8_t data_in[4] = {0,0,0,0};
-       uint8_t data_out[4] = {0,0,0,0};
+       uint8_t data[4] = {0x3A};
 
-       data_in[0] = 0x3A;
        jtag_go_to_state(STATE_SHIFT_IR);
-       jtag_tap_shift(data_in, data_out, 8, true);
+       jtag_tap_shift(data, data, 8, true);
 
        /* These bytes seem to be required to un-lock the SPI interface */
-       data_in[0] = 0xFE;
-       data_in[1] = 0x68;
+       data[0] = 0xFE;
+       data[1] = 0x68;
        jtag_go_to_state(STATE_SHIFT_DR);
-       jtag_tap_shift(data_in, data_out, 16, true);
+       jtag_tap_shift(data, data, 16, true);
 
        /* Entering IDLE is essential */
        jtag_go_to_state(STATE_RUN_TEST_IDLE);
@@ -561,12 +559,10 @@ void ecp_jtag_cmd8(uint8_t cmd, uint8_t param){
 
        jtag_go_to_state(STATE_SHIFT_IR);
        jtag_tap_shift(data, data, 8, true);
-       jtag_go_to_state(STATE_PAUSE_IR);
 
        data[0] = param;
        jtag_go_to_state(STATE_SHIFT_DR);
        jtag_tap_shift(data, data, 8, true);
-       jtag_go_to_state(STATE_PAUSE_DR);
 
        jtag_go_to_state(STATE_RUN_TEST_IDLE);
        jtag_wait_time(32);     
@@ -928,19 +924,12 @@ int main(int argc, char **argv)
        // Initialize USB connection to FT2232H
        // ---------------------------------------------------------
 
-       fprintf(stderr, "init..");
+       fprintf(stderr, "init..\n");
        jtag_init(ifnum, devstr, slow_clock);
 
-       fprintf(stderr, "idcode..\n");
        read_idcode();
-
-       fprintf(stderr, "status..\n");
        read_status_register();
 
-
-       
-       //usleep(20000);
-
        if (test_mode)
        {
                /* Reset ECP5 to release SPI interface */
@@ -959,87 +948,39 @@ int main(int argc, char **argv)
                // ---------------------------------------------------------
                // Reset
                // ---------------------------------------------------------
-
-               fprintf(stderr, "Not Supported yet\n");
                fprintf(stderr, "reset..\n");
 
-
-
-               uint8_t data[1] = {LSC_BITSTREAM_BURST};
-
-
-               fprintf(stderr, "status..\n");
-               read_status_register();
-
                ecp_jtag_cmd8(ISC_ENABLE, 0);
-
-
                ecp_jtag_cmd8(ISC_ERASE, 0);
+               ecp_jtag_cmd8(LSC_RESET_CRC, 0);
+
+               read_status_register();
 
                // ---------------------------------------------------------
                // Program
                // ---------------------------------------------------------
 
                fprintf(stderr, "programming..\n");
-
-
-       //      ecp_jtag_cmd(LSC_BITSTREAM_BURST);
-
-data[0] = LSC_BITSTREAM_BURST;
-       jtag_go_to_state(STATE_SHIFT_IR);
-       jtag_tap_shift(data, data, 8, true);
-
-       jtag_go_to_state(STATE_PAUSE_IR);
+               ecp_jtag_cmd(LSC_BITSTREAM_BURST);
                while (1) {
-                       const uint32_t len = 1024*1024;
-                       static unsigned char buffer[1024*1024];
+                       const uint32_t len = 16*1024;
+                       static unsigned char buffer[16*1024];
                        int rc = fread(buffer, 1, len, f);
                        if (rc <= 0)
                                break;
-                       //if (verbose)
-                               //fprintf(stderr, "sending %d bytes.\n", rc);
-                       
-
-                               for(int i = 0; i < len; i++){
-                                       buffer[i] = bit_reverse(buffer[i]);
-                               }
-
-                               jtag_go_to_state(STATE_CAPTURE_DR);
-                               jtag_tap_shift(buffer, buffer, len*8, true);
-                               jtag_go_to_state(STATE_PAUSE_DR);
+                       if (verbose)
+                               fprintf(stderr, "sending %d bytes.\n", rc);
 
-               
-
-                               /* Entering IDLE is essential */
-                               //jtag_go_to_state(STATE_RUN_TEST_IDLE);
-
-
-                               //read_status_register();
+                       for(int i = 0; i < len; i++){
+                               buffer[i] = bit_reverse(buffer[i]);
+                       }
 
-                               
+                       jtag_go_to_state(STATE_CAPTURE_DR);
+                       jtag_tap_shift(buffer, buffer, len*8, false);
                }
-
+       
                ecp_jtag_cmd(ISC_DISABLE);
-               jtag_go_to_state(STATE_RUN_TEST_IDLE);
-               jtag_tap_shift(data, data, 8, true);
-
-               //jtag_wait_time(1000);
-
-
-               fprintf(stderr, "status..\n");
-               verbose = true;
-               read_status_register();
-
-
-
-//             jtag_wait_time(1000);
-
-
-
-               //mpsse_send_dummy_bytes(6);
-               //mpsse_send_dummy_bit();
-
-               
+               read_status_register(); 
        }
        else /* program flash */
        {
@@ -1049,16 +990,12 @@ data[0] = LSC_BITSTREAM_BURST;
 
                fprintf(stderr, "reset..\n");
                /* Reset ECP5 to release SPI interface */
-               ecp_jtag_cmd(ISC_ENABLE);
-               ecp_jtag_cmd(ISC_ERASE);
-               ecp_jtag_cmd(ISC_DISABLE);
+               ecp_jtag_cmd8(ISC_ENABLE, 0);
+               ecp_jtag_cmd8(ISC_ERASE, 0);
+               ecp_jtag_cmd8(ISC_DISABLE, 0);
 
                /* Put device into SPI bypass mode */
                enter_spi_background_mode();
-               
-               usleep(25000);
-
-               
 
                flash_reset();
 
index c2e6d87a87abc701bab6f97b90b6f7193b8bf8e8..df93e19a4919e98cfe6f78a4b57d4fa75d065b62 100644 (file)
@@ -113,13 +113,6 @@ void mpsse_send_byte(uint8_t data)
        }
 }
 
-void mpsse_purge(void){
-       int rc = ftdi_usb_purge_buffers(&mpsse_ftdic);
-       if (rc != 0) {
-               fprintf(stderr, "Purge error.\n");
-               mpsse_error(2);
-       }
-}
 
 void mpsse_xfer(uint8_t* data_buffer, uint16_t send_length, uint16_t receive_length)
 {