From cf67dbe9879103f7276fe5a9b4cd3c941f89d4c5 Mon Sep 17 00:00:00 2001 From: Greg Davill Date: Tue, 25 Aug 2020 12:14:47 +0930 Subject: [PATCH] nx: Add support for NX IDCODEs --- ecpprog/ecpprog.c | 51 ++++++++++++++++++++++++++++++++++++++---- ecpprog/jtag_tap.c | 3 ++- ecpprog/lattice_cmds.h | 17 +++++++++++--- 3 files changed, 63 insertions(+), 8 deletions(-) diff --git a/ecpprog/ecpprog.c b/ecpprog/ecpprog.c index 15368e9..3c38d0f 100644 --- a/ecpprog/ecpprog.c +++ b/ecpprog/ecpprog.c @@ -47,6 +47,21 @@ static bool verbose = false; +enum device_type { + TYPE_NONE = 0, + TYPE_ECP5 = 1, + TYPE_NX = 2, +}; + +struct device_info { + const char* name; + uint32_t id; + enum device_type type; +}; + +static struct device_info connected_device = {0}; + + // --------------------------------------------------------- // FLASH definitions // --------------------------------------------------------- @@ -435,15 +450,30 @@ static void flash_disable_protection() // ECP5 specific JTAG functions // --------------------------------------------------------- - static void print_idcode(uint32_t idcode){ - for(int i = 0; i < sizeof(ecp_devices)/sizeof(struct ecp_device_id); i++){ + connected_device.id = idcode; + + /* ECP5 Parts */ + for(int i = 0; i < sizeof(ecp_devices)/sizeof(struct device_id_pair); i++){ if(idcode == ecp_devices[i].device_id) { + connected_device.name = ecp_devices[i].device_name; + connected_device.type = TYPE_ECP5; printf("IDCODE: 0x%08x (%s)\n", idcode ,ecp_devices[i].device_name); return; } } + + /* NX Parts */ + for(int i = 0; i < sizeof(nx_devices)/sizeof(struct device_id_pair); i++){ + if(idcode == nx_devices[i].device_id) + { + connected_device.name = nx_devices[i].device_name; + connected_device.type = TYPE_NX; + printf("IDCODE: 0x%08x (%s)\n", idcode ,nx_devices[i].device_name); + return; + } + } printf("IDCODE: 0x%08x does not match :(\n", idcode); } @@ -467,8 +497,7 @@ static void read_idcode(){ print_idcode(idcode); } - -static void print_status_register(uint32_t status){ +void print_ecp5_status_register(uint32_t status){ printf("ECP5 Status Register: 0x%08x\n", status); if(verbose){ @@ -511,6 +540,20 @@ static void print_status_register(uint32_t status){ } } +void print_nx_status_register(uint32_t status){ + printf("NX Status Register: 0x%08x\n", status); +} + + +void print_status_register(uint32_t status){ + if(connected_device.type == TYPE_ECP5){ + print_ecp5_status_register(status); + }else if(connected_device.type == TYPE_NX){ + print_nx_status_register(status); + } +} + + static void read_status_register(){ diff --git a/ecpprog/jtag_tap.c b/ecpprog/jtag_tap.c index 9aa1608..43bb062 100644 --- a/ecpprog/jtag_tap.c +++ b/ecpprog/jtag_tap.c @@ -213,8 +213,9 @@ static void jtag_shift_bytes( memcpy(output_data, data, byte_count); } - +#ifndef MIN #define MIN(a,b) (a < b) ? a : b +#endif void jtag_tap_shift( uint8_t *input_data, diff --git a/ecpprog/lattice_cmds.h b/ecpprog/lattice_cmds.h index 5e42d6c..1a4c82d 100644 --- a/ecpprog/lattice_cmds.h +++ b/ecpprog/lattice_cmds.h @@ -2,7 +2,7 @@ #include /* Not sure if all of these are applicable to the JTAG interface */ -enum lattice_cmd +enum lattice_ecp5_cmd { ISC_NOOP = 0xFF, /* 0 bits - Non-operation */ READ_ID = 0xE0, /* 24 bits - Read out the 32-bit IDCODE of the device */ @@ -45,12 +45,12 @@ enum lattice_cmd }; -struct ecp_device_id { +struct device_id_pair { const char* device_name; uint32_t device_id; }; -const struct ecp_device_id ecp_devices[] = +const struct device_id_pair ecp_devices[] = { {"LFE5U-12" , 0x21111043 }, {"LFE5U-25" , 0x41111043 }, @@ -63,3 +63,14 @@ const struct ecp_device_id ecp_devices[] = {"LFE5UM5G-45", 0x81112043 }, {"LFE5UM5G-85", 0x81113043 } }; + +const struct device_id_pair nx_devices[] = +{ + /* Crosslink NX */ + {"LIFCL-17", 0x010F0043 }, + {"LIFCL-40-ES", 0x010F1043 }, + {"LIFCL-40", 0x110F1043 }, + /* Certus NX */ + {"LFD2NX-17", 0x310F0043 }, + {"LFD2NX-40", 0x310F1043 }, +}; -- 2.30.2