This is an automated email from Gerrit.

"Daniel Anselmi <danse...@gmx.ch>" just uploaded a new patch set to Gerrit, 
which you can find at https://review.openocd.org/c/openocd/+/7839

-- gerrit

commit ddd55fc4a7b538273d1b042f17451897743d75d4
Author: Daniel Anselmi <danse...@gmx.ch>
Date:   Mon Feb 27 17:20:36 2023 +0100

    pld: add refresh command for lattice devices
    
    Change-Id: I9da83a614b96da3e947ac4608b0a291b1d126914
    Signed-off-by: Daniel Anselmi <danse...@gmx.ch>

diff --git a/src/pld/certus.c b/src/pld/certus.c
index 8bfdff4952..a49501f541 100644
--- a/src/pld/certus.c
+++ b/src/pld/certus.c
@@ -304,3 +304,27 @@ int lattice_certus_get_facing_read_bits(struct 
lattice_pld_device *pld_device_in
 
        return ERROR_OK;
 }
+
+int lattice_certus_refresh(struct lattice_pld_device *lattice_device)
+{
+       struct jtag_tap *tap = lattice_device->tap;
+       if (!tap)
+               return ERROR_FAIL;
+
+       int retval = lattice_preload(lattice_device);
+       if (retval != ERROR_OK)
+               return retval;
+
+       retval = lattice_set_instr(tap, LSC_REFRESH, TAP_IDLE);
+       if (retval != ERROR_OK)
+               return retval;
+       jtag_add_runtest(2, TAP_IDLE);
+       jtag_add_sleep(200000);
+       retval = lattice_set_instr(tap, BYPASS, TAP_IDLE);
+       if (retval != ERROR_OK)
+               return retval;
+       jtag_add_runtest(100, TAP_IDLE);
+       jtag_add_sleep(1000);
+
+       return jtag_execute_queue();
+}
diff --git a/src/pld/certus.h b/src/pld/certus.h
index d21ad61d20..0fbfdef45c 100644
--- a/src/pld/certus.h
+++ b/src/pld/certus.h
@@ -17,5 +17,6 @@ int lattice_certus_load(struct lattice_pld_device 
*lattice_device, struct lattic
 int lattice_certus_connect_spi_to_jtag(struct lattice_pld_device 
*pld_device_info);
 int lattice_certus_disconnect_spi_from_jtag(struct lattice_pld_device 
*pld_device_info);
 int lattice_certus_get_facing_read_bits(struct lattice_pld_device 
*pld_device_info, unsigned int *facing_read_bits);
+int lattice_certus_refresh(struct lattice_pld_device *lattice_device);
 
 #endif /* OPENOCD_PLD_CERTUS_H */
diff --git a/src/pld/ecp2_3.c b/src/pld/ecp2_3.c
index a7b7580c72..5dfea9a277 100644
--- a/src/pld/ecp2_3.c
+++ b/src/pld/ecp2_3.c
@@ -304,3 +304,14 @@ int lattice_ecp2_3_get_facing_read_bits(struct 
lattice_pld_device *pld_device_in
 
        return ERROR_OK;
 }
+
+int lattice_ecp2_3_refresh(struct lattice_pld_device *lattice_device)
+{
+       if (!lattice_device || !lattice_device->tap)
+               return ERROR_FAIL;
+
+       int retval = lattice_set_instr(lattice_device->tap, LSCC_REFRESH, 
TAP_IDLE);
+       if (retval != ERROR_OK)
+               return retval;
+       return jtag_execute_queue();
+}
diff --git a/src/pld/ecp2_3.h b/src/pld/ecp2_3.h
index c5dec5693a..d3f7464e12 100644
--- a/src/pld/ecp2_3.h
+++ b/src/pld/ecp2_3.h
@@ -18,5 +18,6 @@ int lattice_ecp3_load(struct lattice_pld_device 
*lattice_device, struct lattice_
 int lattice_ecp2_3_connect_spi_to_jtag(struct lattice_pld_device 
*pld_device_info);
 int lattice_ecp2_3_disconnect_spi_from_jtag(struct lattice_pld_device 
*pld_device_info);
 int lattice_ecp2_3_get_facing_read_bits(struct lattice_pld_device 
*pld_device_info, unsigned int *facing_read_bits);
+int lattice_ecp2_3_refresh(struct lattice_pld_device *lattice_device);
 
 #endif /* OPENOCD_PLD_ECP2_3_H */
diff --git a/src/pld/ecp5.c b/src/pld/ecp5.c
index 024fe2b4a7..f8ba33eaff 100644
--- a/src/pld/ecp5.c
+++ b/src/pld/ecp5.c
@@ -276,3 +276,27 @@ int lattice_ecp5_get_facing_read_bits(struct 
lattice_pld_device *pld_device_info
 
        return ERROR_OK;
 }
+
+int lattice_ecp5_refresh(struct lattice_pld_device *lattice_device)
+{
+       struct jtag_tap *tap = lattice_device->tap;
+       if (!tap)
+               return ERROR_FAIL;
+
+       int retval = lattice_preload(lattice_device);
+       if (retval != ERROR_OK)
+               return retval;
+
+       retval = lattice_set_instr(tap, LSC_REFRESH, TAP_IDLE);
+       if (retval != ERROR_OK)
+               return retval;
+       jtag_add_runtest(2, TAP_IDLE);
+       jtag_add_sleep(200000);
+       retval = lattice_set_instr(tap, BYPASS, TAP_IDLE);
+       if (retval != ERROR_OK)
+               return retval;
+       jtag_add_runtest(100, TAP_IDLE);
+       jtag_add_sleep(1000);
+
+       return jtag_execute_queue();
+}
diff --git a/src/pld/ecp5.h b/src/pld/ecp5.h
index daf481fa6a..975678ece3 100644
--- a/src/pld/ecp5.h
+++ b/src/pld/ecp5.h
@@ -17,5 +17,6 @@ int lattice_ecp5_load(struct lattice_pld_device 
*lattice_device, struct lattice_
 int lattice_ecp5_connect_spi_to_jtag(struct lattice_pld_device 
*pld_device_info);
 int lattice_ecp5_disconnect_spi_from_jtag(struct lattice_pld_device 
*pld_device_info);
 int lattice_ecp5_get_facing_read_bits(struct lattice_pld_device 
*pld_device_info, unsigned int *facing_read_bits);
+int lattice_ecp5_refresh(struct lattice_pld_device *lattice_device);
 
 #endif /* OPENOCD_PLD_ECP5_H */
diff --git a/src/pld/lattice.c b/src/pld/lattice.c
index 876c6c9468..79c2b72a0a 100644
--- a/src/pld/lattice.c
+++ b/src/pld/lattice.c
@@ -578,6 +578,35 @@ COMMAND_HANDLER(lattice_read_status_command_handler)
        return retval;
 }
 
+COMMAND_HANDLER(lattice_refresh_command_handler)
+{
+       if (CMD_ARGC != 1)
+               return ERROR_COMMAND_SYNTAX_ERROR;
+
+       struct pld_device *device = 
get_pld_device_by_name_or_numstr(CMD_ARGV[0]);
+       if (!device) {
+               command_print(CMD, "pld device '#%s' is out of bounds or 
unknown", CMD_ARGV[0]);
+               return ERROR_FAIL;
+       }
+
+       struct lattice_pld_device *lattice_device = device->driver_priv;
+       if (!lattice_device)
+               return ERROR_FAIL;
+
+       int retval = lattice_check_device_family(lattice_device);
+       if (retval != ERROR_OK)
+               return retval;
+
+       if (lattice_device->family == LATTICE_ECP2 || lattice_device->family == 
LATTICE_ECP3)
+               return lattice_ecp2_3_refresh(lattice_device);
+       else if (lattice_device->family == LATTICE_ECP5)
+               return lattice_ecp5_refresh(lattice_device);
+       else if (lattice_device->family == LATTICE_CERTUS)
+               return lattice_certus_refresh(lattice_device);
+
+       return ERROR_FAIL;
+}
+
 static const struct command_registration lattice_exec_command_handlers[] = {
        {
                .name = "read_status",
@@ -603,6 +632,12 @@ static const struct command_registration 
lattice_exec_command_handlers[] = {
                .handler = lattice_set_preload_command_handler,
                .help = "set length for preload (device specific)",
                .usage = "pld_name value",
+       }, {
+               .name = "refresh",
+               .mode = COMMAND_EXEC,
+               .handler = lattice_refresh_command_handler,
+               .help = "refresh from configuration memory",
+               .usage = "pld_name",
        },
        COMMAND_REGISTRATION_DONE
 };
diff --git a/src/pld/lattice_cmd.h b/src/pld/lattice_cmd.h
index 389b7afe42..99bb7b9bc8 100644
--- a/src/pld/lattice_cmd.h
+++ b/src/pld/lattice_cmd.h
@@ -14,6 +14,7 @@
 #define LSC_READ_STATUS      0x3C
 #define LSC_INIT_ADDRESS     0x46
 #define LSC_BITSTREAM_BURST  0x7A
+#define LSC_REFRESH          0x79
 #define READ_USERCODE        0xC0
 #define ISC_ENABLE           0xC6
 

-- 

Reply via email to