drivers: call adapter_get_required_serial() in jtag_libusb_open()
[openocd.git] / src / jtag / aice / aice_usb.c
index f0bb6ccae51f1ef30c2a4add13c3c60eee6072e6..5d586763c4390307756b3cc2c1c7f040bc802a58 100644 (file)
@@ -583,7 +583,7 @@ static int aice_scan_chain(uint32_t *id_codes, uint8_t *num_of_ids)
                if (cmd_ack_code != AICE_CMD_SCAN_CHAIN) {
 
                        if (retry_times > aice_max_retry_times) {
-                               LOG_ERROR("aice command timeout (command=0x%" PRIx8 ", response=0x%" PRIx8 ")",
+                               LOG_ERROR("aice command timeout (command=0x%x, response=0x%" PRIx8 ")",
                                                AICE_CMD_SCAN_CHAIN, cmd_ack_code);
                                return ERROR_FAIL;
                        }
@@ -638,8 +638,8 @@ int aice_read_ctrl(uint32_t address, uint32_t *data)
        LOG_DEBUG("READ_CTRL response, data: 0x%" PRIx32, *data);
 
        if (cmd_ack_code != AICE_CMD_READ_CTRL) {
-               LOG_ERROR("aice command error (command=0x%" PRIx32 ", response=0x%" PRIx8 ")",
-                               (uint32_t)AICE_CMD_READ_CTRL, cmd_ack_code);
+               LOG_ERROR("aice command error (command=0x%x, response=0x%" PRIx8 ")",
+                               AICE_CMD_READ_CTRL, cmd_ack_code);
                return ERROR_FAIL;
        }
 
@@ -676,7 +676,7 @@ int aice_write_ctrl(uint32_t address, uint32_t data)
        LOG_DEBUG("WRITE_CTRL response");
 
        if (cmd_ack_code != AICE_CMD_WRITE_CTRL) {
-               LOG_ERROR("aice command error (command=0x%" PRIx8 ", response=0x%" PRIx8 ")",
+               LOG_ERROR("aice command error (command=0x%x, response=0x%" PRIx8 ")",
                                AICE_CMD_WRITE_CTRL, cmd_ack_code);
                return ERROR_FAIL;
        }
@@ -718,7 +718,7 @@ static int aice_read_dtr(uint8_t target_id, uint32_t *data)
                } else {
 
                        if (retry_times > aice_max_retry_times) {
-                               LOG_ERROR("aice command timeout (command=0x%" PRIx8 ", response=0x%" PRIx8 ")",
+                               LOG_ERROR("aice command timeout (command=0x%x, response=0x%" PRIx8 ")",
                                                AICE_CMD_T_READ_DTR, cmd_ack_code);
                                return ERROR_FAIL;
                        }
@@ -768,7 +768,7 @@ static int aice_read_dtr_to_buffer(uint8_t target_id, uint32_t buffer_idx)
                        break;
                } else {
                        if (retry_times > aice_max_retry_times) {
-                               LOG_ERROR("aice command timeout (command=0x%" PRIx8 ", response=0x%" PRIx8 ")",
+                               LOG_ERROR("aice command timeout (command=0x%x, response=0x%" PRIx8 ")",
                                                AICE_CMD_READ_DTR_TO_BUFFER, cmd_ack_code);
 
                                return ERROR_FAIL;
@@ -820,7 +820,7 @@ static int aice_write_dtr(uint8_t target_id, uint32_t data)
                        break;
                } else {
                        if (retry_times > aice_max_retry_times) {
-                               LOG_ERROR("aice command timeout (command=0x%" PRIx8 ", response=0x%" PRIx8 ")",
+                               LOG_ERROR("aice command timeout (command=0x%x, response=0x%" PRIx8 ")",
                                                AICE_CMD_T_WRITE_DTR, cmd_ack_code);
 
                                return ERROR_FAIL;
@@ -871,7 +871,7 @@ static int aice_write_dtr_from_buffer(uint8_t target_id, uint32_t buffer_idx)
                        break;
                } else {
                        if (retry_times > aice_max_retry_times) {
-                               LOG_ERROR("aice command timeout (command=0x%" PRIx8 ", response=0x%" PRIx8 ")",
+                               LOG_ERROR("aice command timeout (command=0x%x, response=0x%" PRIx8 ")",
                                                AICE_CMD_WRITE_DTR_FROM_BUFFER, cmd_ack_code);
 
                                return ERROR_FAIL;
@@ -921,7 +921,7 @@ static int aice_read_misc(uint8_t target_id, uint32_t address, uint32_t *data)
                        break;
                } else {
                        if (retry_times > aice_max_retry_times) {
-                               LOG_ERROR("aice command timeout (command=0x%" PRIx8 ", response=0x%" PRIx8 ")",
+                               LOG_ERROR("aice command timeout (command=0x%x, response=0x%" PRIx8 ")",
                                                AICE_CMD_T_READ_MISC, cmd_ack_code);
                                return ERROR_FAIL;
                        }
@@ -976,7 +976,7 @@ static int aice_write_misc(uint8_t target_id, uint32_t address, uint32_t data)
                        break;
                } else {
                        if (retry_times > aice_max_retry_times) {
-                               LOG_ERROR("aice command timeout (command=0x%" PRIx8 ", response=0x%" PRIx8 ")",
+                               LOG_ERROR("aice command timeout (command=0x%x, response=0x%" PRIx8 ")",
                                                AICE_CMD_T_WRITE_MISC, cmd_ack_code);
 
                                return ERROR_FAIL;
@@ -1026,7 +1026,7 @@ static int aice_read_edmsr(uint8_t target_id, uint32_t address, uint32_t *data)
                        break;
                } else {
                        if (retry_times > aice_max_retry_times) {
-                               LOG_ERROR("aice command timeout (command=0x%" PRIx8 ", response=0x%" PRIx8 ")",
+                               LOG_ERROR("aice command timeout (command=0x%x, response=0x%" PRIx8 ")",
                                                AICE_CMD_T_READ_EDMSR, cmd_ack_code);
 
                                return ERROR_FAIL;
@@ -1082,7 +1082,7 @@ static int aice_write_edmsr(uint8_t target_id, uint32_t address, uint32_t data)
                        break;
                } else {
                        if (retry_times > aice_max_retry_times) {
-                               LOG_ERROR("aice command timeout (command=0x%" PRIx8 ", response=0x%" PRIx8 ")",
+                               LOG_ERROR("aice command timeout (command=0x%x, response=0x%" PRIx8 ")",
                                                AICE_CMD_T_WRITE_EDMSR, cmd_ack_code);
 
                                return ERROR_FAIL;
@@ -1165,8 +1165,7 @@ static int aice_write_dim(uint8_t target_id, uint32_t *word, uint8_t num_of_word
                        break;
                } else {
                        if (retry_times > aice_max_retry_times) {
-                               LOG_ERROR("aice command timeout (command=0x%" PRIx8
-                                               ", response=0x%" PRIx8 ")",
+                               LOG_ERROR("aice command timeout (command=0x%x, response=0x%" PRIx8 ")",
                                                AICE_CMD_T_WRITE_DIM, cmd_ack_code);
 
                                return ERROR_FAIL;
@@ -1220,7 +1219,7 @@ static int aice_do_execute(uint8_t target_id)
                        break;
                } else {
                        if (retry_times > aice_max_retry_times) {
-                               LOG_ERROR("aice command timeout (command=0x%" PRIx8 ", response=0x%" PRIx8 ")",
+                               LOG_ERROR("aice command timeout (command=0x%x, response=0x%" PRIx8 ")",
                                                AICE_CMD_T_EXECUTE, cmd_ack_code);
 
                                return ERROR_FAIL;
@@ -1273,7 +1272,7 @@ static int aice_write_mem_b(uint8_t target_id, uint32_t address, uint32_t data)
                                break;
                        } else {
                                if (retry_times > aice_max_retry_times) {
-                                       LOG_ERROR("aice command timeout (command=0x%" PRIx8 ", response=0x%" PRIx8 ")",
+                                       LOG_ERROR("aice command timeout (command=0x%x, response=0x%" PRIx8 ")",
                                                        AICE_CMD_T_WRITE_MEM_B, cmd_ack_code);
 
                                        return ERROR_FAIL;
@@ -1328,7 +1327,7 @@ static int aice_write_mem_h(uint8_t target_id, uint32_t address, uint32_t data)
                                break;
                        } else {
                                if (retry_times > aice_max_retry_times) {
-                                       LOG_ERROR("aice command timeout (command=0x%" PRIx8 ", response=0x%" PRIx8 ")",
+                                       LOG_ERROR("aice command timeout (command=0x%x, response=0x%" PRIx8 ")",
                                                        AICE_CMD_T_WRITE_MEM_H, cmd_ack_code);
 
                                        return ERROR_FAIL;
@@ -1383,7 +1382,7 @@ static int aice_write_mem(uint8_t target_id, uint32_t address, uint32_t data)
                                break;
                        } else {
                                if (retry_times > aice_max_retry_times) {
-                                       LOG_ERROR("aice command timeout (command=0x%" PRIx8 ", response=0x%" PRIx8 ")",
+                                       LOG_ERROR("aice command timeout (command=0x%x, response=0x%" PRIx8 ")",
                                                        AICE_CMD_T_WRITE_MEM, cmd_ack_code);
 
                                        return ERROR_FAIL;
@@ -1434,7 +1433,7 @@ static int aice_fastread_mem(uint8_t target_id, uint8_t *word, uint32_t num_of_w
                        break;
                } else {
                        if (retry_times > aice_max_retry_times) {
-                               LOG_ERROR("aice command timeout (command=0x%" PRIx8 ", response=0x%" PRIx8 ")",
+                               LOG_ERROR("aice command timeout (command=0x%x, response=0x%" PRIx8 ")",
                                                AICE_CMD_T_FASTREAD_MEM, cmd_ack_code);
 
                                return ERROR_FAIL;
@@ -1490,7 +1489,7 @@ static int aice_fastwrite_mem(uint8_t target_id, const uint8_t *word, uint32_t n
                        break;
                } else {
                        if (retry_times > aice_max_retry_times) {
-                               LOG_ERROR("aice command timeout (command=0x%" PRIx8 ", response=0x%" PRIx8 ")",
+                               LOG_ERROR("aice command timeout (command=0x%x, response=0x%" PRIx8 ")",
                                                AICE_CMD_T_FASTWRITE_MEM, cmd_ack_code);
 
                                return ERROR_FAIL;
@@ -1540,7 +1539,7 @@ static int aice_read_mem_b(uint8_t target_id, uint32_t address, uint32_t *data)
                        break;
                } else {
                        if (retry_times > aice_max_retry_times) {
-                               LOG_ERROR("aice command timeout (command=0x%" PRIx8 ", response=0x%" PRIx8 ")",
+                               LOG_ERROR("aice command timeout (command=0x%x, response=0x%" PRIx8 ")",
                                                AICE_CMD_T_READ_MEM_B, cmd_ack_code);
 
                                return ERROR_FAIL;
@@ -1590,7 +1589,7 @@ static int aice_read_mem_h(uint8_t target_id, uint32_t address, uint32_t *data)
                        break;
                } else {
                        if (retry_times > aice_max_retry_times) {
-                               LOG_ERROR("aice command timeout (command=0x%" PRIx8 ", response=0x%" PRIx8 ")",
+                               LOG_ERROR("aice command timeout (command=0x%x, response=0x%" PRIx8 ")",
                                                AICE_CMD_T_READ_MEM_H, cmd_ack_code);
 
                                return ERROR_FAIL;
@@ -1641,7 +1640,7 @@ static int aice_read_mem(uint8_t target_id, uint32_t address, uint32_t *data)
                        break;
                } else {
                        if (retry_times > aice_max_retry_times) {
-                               LOG_ERROR("aice command timeout (command=0x%" PRIx8 ", response=0x%" PRIx8 ")",
+                               LOG_ERROR("aice command timeout (command=0x%x, response=0x%" PRIx8 ")",
                                                AICE_CMD_T_READ_MEM, cmd_ack_code);
 
                                return ERROR_FAIL;
@@ -1686,7 +1685,7 @@ static int aice_batch_buffer_read(uint8_t buf_index, uint32_t *word, uint32_t nu
                        break;
                } else {
                        if (retry_times > aice_max_retry_times) {
-                               LOG_ERROR("aice command timeout (command=0x%" PRIx8 ", response=0x%" PRIx8 ")",
+                               LOG_ERROR("aice command timeout (command=0x%x, response=0x%" PRIx8 ")",
                                                AICE_CMD_BATCH_BUFFER_READ, cmd_ack_code);
 
                                return ERROR_FAIL;
@@ -1738,7 +1737,7 @@ int aice_batch_buffer_write(uint8_t buf_index, const uint8_t *word, uint32_t num
                        break;
                } else {
                        if (retry_times > aice_max_retry_times) {
-                               LOG_ERROR("aice command timeout (command=0x%" PRIx8 ", response=0x%" PRIx8 ")",
+                               LOG_ERROR("aice command timeout (command=0x%x, response=0x%" PRIx8 ")",
                                                AICE_CMD_BATCH_BUFFER_WRITE, cmd_ack_code);
 
                                return ERROR_FAIL;
@@ -1835,9 +1834,9 @@ static int aice_check_dbger(uint32_t coreid, uint32_t expect_status)
                aice_read_misc(coreid, NDS_EDM_MISC_DBGER, &value_dbger);
 
                if ((value_dbger & expect_status) == expect_status) {
-                       if (ERROR_OK != check_suppressed_exception(coreid, value_dbger))
+                       if (check_suppressed_exception(coreid, value_dbger) != ERROR_OK)
                                return ERROR_FAIL;
-                       if (ERROR_OK != check_privilege(coreid, value_dbger))
+                       if (check_privilege(coreid, value_dbger) != ERROR_OK)
                                return ERROR_FAIL;
                        return ERROR_OK;
                }
@@ -1895,18 +1894,18 @@ static int aice_read_reg(uint32_t coreid, uint32_t num, uint32_t *val)
 
        uint32_t instructions[4]; /** execute instructions in DIM */
 
-       if (NDS32_REG_TYPE_GPR == nds32_reg_type(num)) { /* general registers */
+       if (nds32_reg_type(num) == NDS32_REG_TYPE_GPR) { /* general registers */
                instructions[0] = MTSR_DTR(num);
                instructions[1] = DSB;
                instructions[2] = NOP;
                instructions[3] = BEQ_MINUS_12;
-       } else if (NDS32_REG_TYPE_SPR == nds32_reg_type(num)) { /* user special registers */
+       } else if (nds32_reg_type(num) == NDS32_REG_TYPE_SPR) { /* user special registers */
                instructions[0] = MFUSR_G0(0, nds32_reg_sr_index(num));
                instructions[1] = MTSR_DTR(0);
                instructions[2] = DSB;
                instructions[3] = BEQ_MINUS_12;
-       } else if (NDS32_REG_TYPE_AUMR == nds32_reg_type(num)) { /* audio registers */
-               if ((CB_CTL <= num) && (num <= CBE3)) {
+       } else if (nds32_reg_type(num) == NDS32_REG_TYPE_AUMR) { /* audio registers */
+               if ((num >= CB_CTL) && (num <= CBE3)) {
                        instructions[0] = AMFAR2(0, nds32_reg_sr_index(num));
                        instructions[1] = MTSR_DTR(0);
                        instructions[2] = DSB;
@@ -1917,7 +1916,7 @@ static int aice_read_reg(uint32_t coreid, uint32_t num, uint32_t *val)
                        instructions[2] = DSB;
                        instructions[3] = BEQ_MINUS_12;
                }
-       } else if (NDS32_REG_TYPE_FPU == nds32_reg_type(num)) { /* fpu registers */
+       } else if (nds32_reg_type(num) == NDS32_REG_TYPE_FPU) { /* fpu registers */
                if (num == FPCSR) {
                        instructions[0] = FMFCSR;
                        instructions[1] = MTSR_DTR(0);
@@ -1983,7 +1982,7 @@ static int aice_usb_read_reg(uint32_t coreid, uint32_t num, uint32_t *val)
        } else if ((core_info[coreid].target_dtr_valid == true) && (num == DR43)) {
                *val = core_info[coreid].target_dtr_backup;
        } else {
-               if (ERROR_OK != aice_read_reg(coreid, num, val))
+               if (aice_read_reg(coreid, num, val) != ERROR_OK)
                        *val = 0xBBADBEEF;
        }
 
@@ -2004,18 +2003,18 @@ static int aice_write_reg(uint32_t coreid, uint32_t num, uint32_t val)
                return ERROR_FAIL;
        }
 
-       if (NDS32_REG_TYPE_GPR == nds32_reg_type(num)) { /* general registers */
+       if (nds32_reg_type(num) == NDS32_REG_TYPE_GPR) { /* general registers */
                instructions[0] = MFSR_DTR(num);
                instructions[1] = DSB;
                instructions[2] = NOP;
                instructions[3] = BEQ_MINUS_12;
-       } else if (NDS32_REG_TYPE_SPR == nds32_reg_type(num)) { /* user special registers */
+       } else if (nds32_reg_type(num) == NDS32_REG_TYPE_SPR) { /* user special registers */
                instructions[0] = MFSR_DTR(0);
                instructions[1] = MTUSR_G0(0, nds32_reg_sr_index(num));
                instructions[2] = DSB;
                instructions[3] = BEQ_MINUS_12;
-       } else if (NDS32_REG_TYPE_AUMR == nds32_reg_type(num)) { /* audio registers */
-               if ((CB_CTL <= num) && (num <= CBE3)) {
+       } else if (nds32_reg_type(num) == NDS32_REG_TYPE_AUMR) { /* audio registers */
+               if ((num >= CB_CTL) && (num <= CBE3)) {
                        instructions[0] = MFSR_DTR(0);
                        instructions[1] = AMTAR2(0, nds32_reg_sr_index(num));
                        instructions[2] = DSB;
@@ -2026,7 +2025,7 @@ static int aice_write_reg(uint32_t coreid, uint32_t num, uint32_t val)
                        instructions[2] = DSB;
                        instructions[3] = BEQ_MINUS_12;
                }
-       } else if (NDS32_REG_TYPE_FPU == nds32_reg_type(num)) { /* fpu registers */
+       } else if (nds32_reg_type(num) == NDS32_REG_TYPE_FPU) { /* fpu registers */
                if (num == FPCSR) {
                        instructions[0] = MFSR_DTR(0);
                        instructions[1] = FMTCSR;
@@ -2086,7 +2085,7 @@ static int aice_usb_open(struct aice_port_param_s *param)
        const uint16_t pids[] = { param->pid, 0 };
        struct libusb_device_handle *devh;
 
-       if (jtag_libusb_open(vids, pids, NULL, &devh, NULL) != ERROR_OK)
+       if (jtag_libusb_open(vids, pids, &devh, NULL) != ERROR_OK)
                return ERROR_FAIL;
 
        /* BE ***VERY CAREFUL*** ABOUT MAKING CHANGES IN THIS
@@ -2110,7 +2109,7 @@ static int aice_usb_open(struct aice_port_param_s *param)
        /* reopen jlink after usb_reset
         * on win32 this may take a second or two to re-enumerate */
        int retval;
-       while ((retval = jtag_libusb_open(vids, pids, NULL, &devh, NULL)) != ERROR_OK) {
+       while ((retval = jtag_libusb_open(vids, pids, &devh, NULL)) != ERROR_OK) {
                usleep(1000);
                timeout--;
                if (!timeout)
@@ -2146,7 +2145,7 @@ static int aice_usb_read_reg_64(uint32_t coreid, uint32_t num, uint64_t *val)
        uint32_t value;
        uint32_t high_value;
 
-       if (ERROR_OK != aice_read_reg(coreid, num, &value))
+       if (aice_read_reg(coreid, num, &value) != ERROR_OK)
                value = 0xBBADBEEF;
 
        aice_read_reg(coreid, R1, &high_value);
@@ -2215,24 +2214,24 @@ static int aice_execute_custom_script(const char *script)
        bool set_op;
 
        script_fd = fopen(script, "r");
-       if (script_fd == NULL) {
+       if (!script_fd) {
                return ERROR_FAIL;
        } else {
-               while (fgets(line_buffer, LINE_BUFFER_SIZE, script_fd) != NULL) {
+               while (fgets(line_buffer, LINE_BUFFER_SIZE, script_fd)) {
                        /* execute operations */
                        set_op = false;
                        op_str = strstr(line_buffer, "set");
-                       if (op_str != NULL) {
+                       if (op_str) {
                                set_op = true;
                                goto get_reset_type;
                        }
 
                        op_str = strstr(line_buffer, "clear");
-                       if (op_str == NULL)
+                       if (!op_str)
                                continue;
 get_reset_type:
                        reset_str = strstr(op_str, "srst");
-                       if (reset_str != NULL) {
+                       if (reset_str) {
                                if (set_op)
                                        write_ctrl_value = AICE_CUSTOM_DELAY_SET_SRST;
                                else
@@ -2240,7 +2239,7 @@ get_reset_type:
                                goto get_delay;
                        }
                        reset_str = strstr(op_str, "dbgi");
-                       if (reset_str != NULL) {
+                       if (reset_str) {
                                if (set_op)
                                        write_ctrl_value = AICE_CUSTOM_DELAY_SET_DBGI;
                                else
@@ -2248,7 +2247,7 @@ get_reset_type:
                                goto get_delay;
                        }
                        reset_str = strstr(op_str, "trst");
-                       if (reset_str != NULL) {
+                       if (reset_str) {
                                if (set_op)
                                        write_ctrl_value = AICE_CUSTOM_DELAY_SET_TRST;
                                else
@@ -2503,10 +2502,10 @@ static int aice_restore_tmp_registers(uint32_t coreid)
 
 static int aice_open_device(struct aice_port_param_s *param)
 {
-       if (ERROR_OK != aice_usb_open(param))
+       if (aice_usb_open(param) != ERROR_OK)
                return ERROR_FAIL;
 
-       if (ERROR_FAIL == aice_get_version_info()) {
+       if (aice_get_version_info() == ERROR_FAIL) {
                LOG_ERROR("Cannot get AICE version!");
                return ERROR_FAIL;
        }
@@ -2514,7 +2513,7 @@ static int aice_open_device(struct aice_port_param_s *param)
        LOG_INFO("AICE initialization started");
 
        /* attempt to reset Andes EDM */
-       if (ERROR_FAIL == aice_reset_box()) {
+       if (aice_reset_box() == ERROR_FAIL) {
                LOG_ERROR("Cannot initial AICE box!");
                return ERROR_FAIL;
        }
@@ -2526,7 +2525,7 @@ static int aice_usb_set_jtag_clock(uint32_t a_clock)
 {
        jtag_clock = a_clock;
 
-       if (ERROR_OK != aice_usb_set_clock(a_clock)) {
+       if (aice_usb_set_clock(a_clock) != ERROR_OK) {
                LOG_ERROR("Cannot set AICE JTAG clock!");
                return ERROR_FAIL;
        }
@@ -2705,7 +2704,7 @@ static int aice_usb_state(uint32_t coreid, enum aice_target_state_s *state)
                /* Clear CRST */
                aice_write_misc(coreid, NDS_EDM_MISC_DBGER, NDS_DBGER_CRST);
        } else if ((dbger_value & NDS_DBGER_DEX) == NDS_DBGER_DEX) {
-               if (AICE_TARGET_RUNNING == core_info[coreid].core_state) {
+               if (core_info[coreid].core_state == AICE_TARGET_RUNNING) {
                        /* enter debug mode, init EDM registers */
                        /* backup EDM registers */
                        aice_backup_edm_registers(coreid);
@@ -2713,7 +2712,7 @@ static int aice_usb_state(uint32_t coreid, enum aice_target_state_s *state)
                        aice_init_edm_registers(coreid, true);
                        aice_backup_tmp_registers(coreid);
                        core_info[coreid].core_state = AICE_TARGET_HALTED;
-               } else if (AICE_TARGET_UNKNOWN == core_info[coreid].core_state) {
+               } else if (core_info[coreid].core_state == AICE_TARGET_UNKNOWN) {
                        /* debug 'debug mode', use force debug to halt core */
                        aice_usb_halt(coreid);
                }
@@ -2732,7 +2731,7 @@ static int aice_usb_reset(void)
                return ERROR_FAIL;
 
        /* issue TRST */
-       if (custom_trst_script == NULL) {
+       if (!custom_trst_script) {
                if (aice_write_ctrl(AICE_WRITE_CTRL_JTAG_PIN_CONTROL,
                                        AICE_JTAG_PIN_CONTROL_TRST) != ERROR_OK)
                        return ERROR_FAIL;
@@ -2755,7 +2754,7 @@ static int aice_issue_srst(uint32_t coreid)
        /* After issuing srst, target will be running. So we need to restore EDM_CTL. */
        aice_restore_edm_registers(coreid);
 
-       if (custom_srst_script == NULL) {
+       if (!custom_srst_script) {
                if (aice_write_ctrl(AICE_WRITE_CTRL_JTAG_PIN_CONTROL,
                                        AICE_JTAG_PIN_CONTROL_SRST) != ERROR_OK)
                        return ERROR_FAIL;
@@ -2799,7 +2798,7 @@ static int aice_issue_reset_hold(uint32_t coreid)
                aice_write_ctrl(AICE_WRITE_CTRL_JTAG_PIN_STATUS, pin_status & (~0x4));
 
        /* issue restart */
-       if (custom_restart_script == NULL) {
+       if (!custom_restart_script) {
                if (aice_write_ctrl(AICE_WRITE_CTRL_JTAG_PIN_CONTROL,
                                        AICE_JTAG_PIN_CONTROL_RESTART) != ERROR_OK)
                        return ERROR_FAIL;
@@ -2819,7 +2818,7 @@ static int aice_issue_reset_hold(uint32_t coreid)
                aice_write_ctrl(AICE_WRITE_CTRL_JTAG_PIN_STATUS, pin_status | 0x4);
 
                /* issue restart again */
-               if (custom_restart_script == NULL) {
+               if (!custom_restart_script) {
                        if (aice_write_ctrl(AICE_WRITE_CTRL_JTAG_PIN_CONTROL,
                                                AICE_JTAG_PIN_CONTROL_RESTART) != ERROR_OK)
                                return ERROR_FAIL;
@@ -2889,7 +2888,7 @@ static int aice_usb_assert_srst(uint32_t coreid, enum aice_srst_type_s srst)
        if (srst == AICE_SRST)
                result = aice_issue_srst(coreid);
        else {
-               if (1 == total_num_of_core)
+               if (total_num_of_core == 1)
                        result = aice_issue_reset_hold(coreid);
                else
                        result = aice_issue_reset_hold_multi();
@@ -2972,7 +2971,7 @@ static int aice_usb_step(uint32_t coreid)
                aice_write_reg(coreid, ir0_reg_num, ir0_value);
        }
 
-       if (ERROR_FAIL == aice_usb_run(coreid))
+       if (aice_usb_run(coreid) == ERROR_FAIL)
                return ERROR_FAIL;
 
        int i = 0;
@@ -3092,7 +3091,7 @@ static int aice_usb_read_memory_unit(uint32_t coreid, uint32_t addr, uint32_t si
                        ", size: %" PRIu32 ", count: %" PRIu32 "",
                        addr, size, count);
 
-       if (NDS_MEMORY_ACC_CPU == core_info[coreid].access_channel)
+       if (core_info[coreid].access_channel == NDS_MEMORY_ACC_CPU)
                aice_usb_set_address_dim(coreid, addr);
 
        uint32_t value;
@@ -3101,7 +3100,7 @@ static int aice_usb_read_memory_unit(uint32_t coreid, uint32_t addr, uint32_t si
 
        switch (size) {
                case 1:
-                       if (NDS_MEMORY_ACC_BUS == core_info[coreid].access_channel)
+                       if (core_info[coreid].access_channel == NDS_MEMORY_ACC_BUS)
                                read_mem_func = aice_usb_read_mem_b_bus;
                        else
                                read_mem_func = aice_usb_read_mem_b_dim;
@@ -3113,7 +3112,7 @@ static int aice_usb_read_memory_unit(uint32_t coreid, uint32_t addr, uint32_t si
                        }
                        break;
                case 2:
-                       if (NDS_MEMORY_ACC_BUS == core_info[coreid].access_channel)
+                       if (core_info[coreid].access_channel == NDS_MEMORY_ACC_BUS)
                                read_mem_func = aice_usb_read_mem_h_bus;
                        else
                                read_mem_func = aice_usb_read_mem_h_dim;
@@ -3127,7 +3126,7 @@ static int aice_usb_read_memory_unit(uint32_t coreid, uint32_t addr, uint32_t si
                        }
                        break;
                case 4:
-                       if (NDS_MEMORY_ACC_BUS == core_info[coreid].access_channel)
+                       if (core_info[coreid].access_channel == NDS_MEMORY_ACC_BUS)
                                read_mem_func = aice_usb_read_mem_w_bus;
                        else
                                read_mem_func = aice_usb_read_mem_w_dim;
@@ -3211,7 +3210,7 @@ static int aice_usb_write_memory_unit(uint32_t coreid, uint32_t addr, uint32_t s
                        ", size: %" PRIu32 ", count: %" PRIu32 "",
                        addr, size, count);
 
-       if (NDS_MEMORY_ACC_CPU == core_info[coreid].access_channel)
+       if (core_info[coreid].access_channel == NDS_MEMORY_ACC_CPU)
                aice_usb_set_address_dim(coreid, addr);
 
        size_t i;
@@ -3219,7 +3218,7 @@ static int aice_usb_write_memory_unit(uint32_t coreid, uint32_t addr, uint32_t s
 
        switch (size) {
                case 1:
-                       if (NDS_MEMORY_ACC_BUS == core_info[coreid].access_channel)
+                       if (core_info[coreid].access_channel == NDS_MEMORY_ACC_BUS)
                                write_mem_func = aice_usb_write_mem_b_bus;
                        else
                                write_mem_func = aice_usb_write_mem_b_dim;
@@ -3231,7 +3230,7 @@ static int aice_usb_write_memory_unit(uint32_t coreid, uint32_t addr, uint32_t s
                        }
                        break;
                case 2:
-                       if (NDS_MEMORY_ACC_BUS == core_info[coreid].access_channel)
+                       if (core_info[coreid].access_channel == NDS_MEMORY_ACC_BUS)
                                write_mem_func = aice_usb_write_mem_h_bus;
                        else
                                write_mem_func = aice_usb_write_mem_h_dim;
@@ -3246,7 +3245,7 @@ static int aice_usb_write_memory_unit(uint32_t coreid, uint32_t addr, uint32_t s
                        }
                        break;
                case 4:
-                       if (NDS_MEMORY_ACC_BUS == core_info[coreid].access_channel)
+                       if (core_info[coreid].access_channel == NDS_MEMORY_ACC_BUS)
                                write_mem_func = aice_usb_write_mem_w_bus;
                        else
                                write_mem_func = aice_usb_write_mem_w_dim;
@@ -3322,10 +3321,10 @@ static int aice_usb_bulk_read_mem(uint32_t coreid, uint32_t addr,
 
        int retval;
 
-       if (NDS_MEMORY_ACC_CPU == core_info[coreid].access_channel)
+       if (core_info[coreid].access_channel == NDS_MEMORY_ACC_CPU)
                aice_usb_set_address_dim(coreid, addr);
 
-       if (NDS_MEMORY_ACC_CPU == core_info[coreid].access_channel)
+       if (core_info[coreid].access_channel == NDS_MEMORY_ACC_CPU)
                retval = aice_usb_read_memory_unit(coreid, addr, 4, length / 4, buffer);
        else
                retval = aice_bulk_read_mem(coreid, addr, length / 4, buffer);
@@ -3340,10 +3339,10 @@ static int aice_usb_bulk_write_mem(uint32_t coreid, uint32_t addr,
 
        int retval;
 
-       if (NDS_MEMORY_ACC_CPU == core_info[coreid].access_channel)
+       if (core_info[coreid].access_channel == NDS_MEMORY_ACC_CPU)
                aice_usb_set_address_dim(coreid, addr);
 
-       if (NDS_MEMORY_ACC_CPU == core_info[coreid].access_channel)
+       if (core_info[coreid].access_channel == NDS_MEMORY_ACC_CPU)
                retval = aice_usb_write_memory_unit(coreid, addr, 4, length / 4, buffer);
        else
                retval = aice_bulk_write_mem(coreid, addr, length / 4, buffer);
@@ -3353,7 +3352,7 @@ static int aice_usb_bulk_write_mem(uint32_t coreid, uint32_t addr,
 
 static int aice_usb_read_debug_reg(uint32_t coreid, uint32_t addr, uint32_t *val)
 {
-       if (AICE_TARGET_HALTED == core_info[coreid].core_state) {
+       if (core_info[coreid].core_state == AICE_TARGET_HALTED) {
                if (addr == NDS_EDM_SR_EDMSW) {
                        *val = core_info[coreid].edmsw_backup;
                } else if (addr == NDS_EDM_SR_EDM_DTR) {
@@ -3373,7 +3372,7 @@ static int aice_usb_read_debug_reg(uint32_t coreid, uint32_t addr, uint32_t *val
 
 static int aice_usb_write_debug_reg(uint32_t coreid, uint32_t addr, const uint32_t val)
 {
-       if (AICE_TARGET_HALTED == core_info[coreid].core_state) {
+       if (core_info[coreid].core_state == AICE_TARGET_HALTED) {
                if (addr == NDS_EDM_SR_EDM_DTR) {
                        core_info[coreid].host_dtr_backup = val;
                        core_info[coreid].edmsw_backup |= 0x2;
@@ -3402,7 +3401,7 @@ static int aice_usb_memory_mode(uint32_t coreid, enum nds_memory_select mem_sele
 
        core_info[coreid].memory_select = mem_select;
 
-       if (NDS_MEMORY_SELECT_AUTO != core_info[coreid].memory_select)
+       if (core_info[coreid].memory_select != NDS_MEMORY_SELECT_AUTO)
                aice_write_misc(coreid, NDS_EDM_MISC_ACC_CTL,
                                core_info[coreid].memory_select - 1);
        else
@@ -3454,13 +3453,13 @@ static int aice_usb_read_tlb(uint32_t coreid, target_addr_t virtual_address,
        aice_read_reg(coreid, MR4, &value_mr4);
 
        access_page_size = value_mr4 & 0xF;
-       if (0 == access_page_size) { /* 4K page */
+       if (access_page_size == 0) { /* 4K page */
                virtual_offset = virtual_address & 0x00000FFF;
                physical_page_number = value_mr3 & 0xFFFFF000;
-       } else if (1 == access_page_size) { /* 8K page */
+       } else if (access_page_size == 1) { /* 8K page */
                virtual_offset = virtual_address & 0x00001FFF;
                physical_page_number = value_mr3 & 0xFFFFE000;
-       } else if (5 == access_page_size) { /* 1M page */
+       } else if (access_page_size == 5) { /* 1M page */
                virtual_offset = virtual_address & 0x000FFFFF;
                physical_page_number = value_mr3 & 0xFFF00000;
        } else {
@@ -3546,10 +3545,10 @@ static int aice_usb_dcache_inval_all(uint32_t coreid)
                        cache_index = (way_index << (dcache->log2_set + dcache->log2_line_size)) |
                                (set_index << dcache->log2_line_size);
 
-                       if (ERROR_OK != aice_write_dtr(coreid, cache_index))
+                       if (aice_write_dtr(coreid, cache_index) != ERROR_OK)
                                return ERROR_FAIL;
 
-                       if (ERROR_OK != aice_execute_dim(coreid, instructions, 4))
+                       if (aice_execute_dim(coreid, instructions, 4) != ERROR_OK)
                                return ERROR_FAIL;
                }
        }
@@ -3594,10 +3593,10 @@ static int aice_usb_dcache_wb_all(uint32_t coreid)
                        cache_index = (way_index << (dcache->log2_set + dcache->log2_line_size)) |
                                (set_index << dcache->log2_line_size);
 
-                       if (ERROR_OK != aice_write_dtr(coreid, cache_index))
+                       if (aice_write_dtr(coreid, cache_index) != ERROR_OK)
                                return ERROR_FAIL;
 
-                       if (ERROR_OK != aice_execute_dim(coreid, instructions, 4))
+                       if (aice_execute_dim(coreid, instructions, 4) != ERROR_OK)
                                return ERROR_FAIL;
                }
        }
@@ -3642,10 +3641,10 @@ static int aice_usb_icache_inval_all(uint32_t coreid)
                        cache_index = (way_index << (icache->log2_set + icache->log2_line_size)) |
                                (set_index << icache->log2_line_size);
 
-                       if (ERROR_OK != aice_write_dtr(coreid, cache_index))
+                       if (aice_write_dtr(coreid, cache_index) != ERROR_OK)
                                return ERROR_FAIL;
 
-                       if (ERROR_OK != aice_execute_dim(coreid, instructions, 4))
+                       if (aice_execute_dim(coreid, instructions, 4) != ERROR_OK)
                                return ERROR_FAIL;
                }
        }
@@ -3721,7 +3720,7 @@ static int aice_usb_program_edm(uint32_t coreid, char *command_sequence)
 
        /* init strtok() */
        command_str = strtok(command_sequence, ";");
-       if (command_str == NULL)
+       if (!command_str)
                return ERROR_OK;
 
        do {
@@ -3740,14 +3739,14 @@ static int aice_usb_program_edm(uint32_t coreid, char *command_sequence)
                        reg_name_0 = strstr(command_str, "gen_port0");
                        reg_name_1 = strstr(command_str, "gen_port1");
 
-                       if (reg_name_0 != NULL) {
+                       if (reg_name_0) {
                                data_value = strtoul(reg_name_0 + 9, NULL, 0);
 
                                if (aice_write_misc(coreid,
                                                        NDS_EDM_MISC_GEN_PORT0, data_value) != ERROR_OK)
                                        return ERROR_FAIL;
 
-                       } else if (reg_name_1 != NULL) {
+                       } else if (reg_name_1) {
                                data_value = strtoul(reg_name_1 + 9, NULL, 0);
 
                                if (aice_write_misc(coreid,
@@ -3763,7 +3762,7 @@ static int aice_usb_program_edm(uint32_t coreid, char *command_sequence)
                /* update command_str */
                command_str = strtok(NULL, ";");
 
-       } while (command_str != NULL);
+       } while (command_str);
 
        return ERROR_OK;
 }
@@ -3896,13 +3895,13 @@ static int fill_profiling_batch_commands(uint32_t coreid, uint32_t reg_no)
        aice_read_dtr_to_buffer(coreid, AICE_BATCH_DATA_BUFFER_0);
 
        /* get samples */
-       if (NDS32_REG_TYPE_GPR == nds32_reg_type(reg_no)) {
+       if (nds32_reg_type(reg_no) == NDS32_REG_TYPE_GPR) {
                /* general registers */
                dim_instructions[0] = MTSR_DTR(reg_no);
                dim_instructions[1] = DSB;
                dim_instructions[2] = NOP;
                dim_instructions[3] = BEQ_MINUS_12;
-       } else if (NDS32_REG_TYPE_SPR == nds32_reg_type(reg_no)) {
+       } else if (nds32_reg_type(reg_no) == NDS32_REG_TYPE_SPR) {
                /* user special registers */
                dim_instructions[0] = MFUSR_G0(0, nds32_reg_sr_index(reg_no));
                dim_instructions[1] = MTSR_DTR(0);

Linking to existing account procedure

If you already have an account and want to add another login method you MUST first sign in with your existing account and then change URL to read https://review.openocd.org/login/?link to get to this page again but this time it'll work for linking. Thank you.

SSH host keys fingerprints

1024 SHA256:YKx8b7u5ZWdcbp7/4AeXNaqElP49m6QrwfXaqQGJAOk gerrit-code-review@openocd.zylin.com (DSA)
384 SHA256:jHIbSQa4REvwCFG4cq5LBlBLxmxSqelQPem/EXIrxjk gerrit-code-review@openocd.org (ECDSA)
521 SHA256:UAOPYkU9Fjtcao0Ul/Rrlnj/OsQvt+pgdYSZ4jOYdgs gerrit-code-review@openocd.org (ECDSA)
256 SHA256:A13M5QlnozFOvTllybRZH6vm7iSt0XLxbA48yfc2yfY gerrit-code-review@openocd.org (ECDSA)
256 SHA256:spYMBqEYoAOtK7yZBrcwE8ZpYt6b68Cfh9yEVetvbXg gerrit-code-review@openocd.org (ED25519)
+--[ED25519 256]--+
|=..              |
|+o..   .         |
|*.o   . .        |
|+B . . .         |
|Bo. = o S        |
|Oo.+ + =         |
|oB=.* = . o      |
| =+=.+   + E     |
|. .=o   . o      |
+----[SHA256]-----+
2048 SHA256:0Onrb7/PHjpo6iVZ7xQX2riKN83FJ3KGU0TvI0TaFG4 gerrit-code-review@openocd.zylin.com (RSA)