nx: Add support for NX IDCODEs
authorGreg Davill <greg.davill@gmail.com>
Tue, 25 Aug 2020 02:44:47 +0000 (12:14 +0930)
committerGreg Davill <greg.davill@gmail.com>
Tue, 25 Aug 2020 02:44:47 +0000 (12:14 +0930)
ecpprog/ecpprog.c
ecpprog/jtag_tap.c
ecpprog/lattice_cmds.h

index 15368e9caa87e0008629f62f43d843365aa8b096..3c38d0ff200c87ea45fc8ac1a51d3fb28a78800c 100644 (file)
 
 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(){
 
index 9aa1608eefc8f0c04a5c0ba4fd8df9abb53f6d70..43bb0628375714b32b546da80e9fb7f0a191d305 100644 (file)
@@ -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,
index 5e42d6c575671db0c0f1f1733a78eed40d3341ff..1a4c82dd075bf591e48b7a4bec38b02c2b400efb 100644 (file)
@@ -2,7 +2,7 @@
 #include <stdint.h>
 
 /* 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 },
+};