openocd: manually fix Yoda conditions
[openocd.git] / src / jtag / drivers / xds110.c
index 85a1b81db1339a3b03b35881442bbac5ed388974..1a17f70cc882fb00697d2e2d0ee0b2d091a992e6 100644 (file)
@@ -379,8 +379,8 @@ static bool usb_connect(void)
                                                /* Get the device's serial number string */
                                                result = libusb_get_string_descriptor_ascii(dev,
                                                                        desc.iSerialNumber, data, max_data);
-                                               if (0 < result &&
-                                                       0 == strcmp((char *)data, (char *)xds110.serial)) {
+                                               if (result > 0 &&
+                                                       strcmp((char *)data, (char *)xds110.serial) == 0) {
                                                        found = true;
                                                        break;
                                                }
@@ -497,7 +497,7 @@ static bool usb_write(unsigned char *buffer, int size, int *written)
        result = libusb_bulk_transfer(xds110.dev, xds110.endpoint_out, buffer,
                                size, &bytes_written, 0);
 
-       while (LIBUSB_ERROR_PIPE == result && retries < 3) {
+       while (result == LIBUSB_ERROR_PIPE && retries < 3) {
                /* Try clearing the pipe stall and retry transfer */
                libusb_clear_halt(xds110.dev, xds110.endpoint_out);
                result = libusb_bulk_transfer(xds110.dev, xds110.endpoint_out, buffer,
@@ -508,7 +508,7 @@ static bool usb_write(unsigned char *buffer, int size, int *written)
        if (NULL != written)
                *written = bytes_written;
 
-       return (0 == result && size == bytes_written) ? true : false;
+       return (result == 0 && size == bytes_written) ? true : false;
 }
 
 static bool usb_get_response(uint32_t *total_bytes_read, uint32_t timeout)
@@ -661,7 +661,7 @@ static bool xds_execute(uint32_t out_length, uint32_t in_length,
                                /* Extract error code from return packet */
                                error = (int)xds110_get_u32(&xds110.read_payload[0]);
                                done = true;
-                               if (SC_ERR_NONE != error)
+                               if (error != SC_ERR_NONE)
                                        LOG_DEBUG("XDS110: command 0x%02x returned error %d",
                                                xds110.write_payload[0], error);
                        }
@@ -1021,7 +1021,7 @@ static bool xds_set_supply(uint32_t voltage)
        xds110.write_payload[0] = XDS_SET_SUPPLY;
 
        xds110_set_u32(volts_pntr, voltage);
-       *source_pntr = (uint8_t)(0 != voltage ? 1 : 0);
+       *source_pntr = (uint8_t)(voltage != 0 ? 1 : 0);
 
        success = xds_execute(XDS_OUT_LEN + 5, XDS_IN_LEN, DEFAULT_ATTEMPTS,
                                DEFAULT_TIMEOUT);
@@ -1165,9 +1165,9 @@ static int xds110_swd_switch_seq(enum swd_special_seq seq)
 static bool xds110_legacy_read_reg(uint8_t cmd, uint32_t *value)
 {
        /* Make sure this is a read request */
-       bool is_read_request = (0 != (SWD_CMD_RnW & cmd));
+       bool is_read_request = (0 != (SWD_CMD_RNW & cmd));
        /* Determine whether this is a DP or AP register access */
-       uint32_t type = (0 != (SWD_CMD_APnDP & cmd)) ? DAP_AP : DAP_DP;
+       uint32_t type = (0 != (SWD_CMD_APNDP & cmd)) ? DAP_AP : DAP_DP;
        /* Determine the AP number from cached SELECT value */
        uint32_t ap_num = (xds110.select & 0xff000000) >> 24;
        /* Extract register address from command */
@@ -1183,7 +1183,7 @@ static bool xds110_legacy_read_reg(uint8_t cmd, uint32_t *value)
        if (!is_read_request)
                return false;
 
-       if (DAP_AP == type) {
+       if (type == DAP_AP) {
                /* Add bank address to register address for CMAPI call */
                address |= bank;
        }
@@ -1227,9 +1227,9 @@ static bool xds110_legacy_read_reg(uint8_t cmd, uint32_t *value)
 static bool xds110_legacy_write_reg(uint8_t cmd, uint32_t value)
 {
        /* Make sure this isn't a read request */
-       bool is_read_request = (0 != (SWD_CMD_RnW & cmd));
+       bool is_read_request = (0 != (SWD_CMD_RNW & cmd));
        /* Determine whether this is a DP or AP register access */
-       uint32_t type = (0 != (SWD_CMD_APnDP & cmd)) ? DAP_AP : DAP_DP;
+       uint32_t type = (0 != (SWD_CMD_APNDP & cmd)) ? DAP_AP : DAP_DP;
        /* Determine the AP number from cached SELECT value */
        uint32_t ap_num = (xds110.select & 0xff000000) >> 24;
        /* Extract register address from command */
@@ -1245,12 +1245,12 @@ static bool xds110_legacy_write_reg(uint8_t cmd, uint32_t value)
        /* Invalidate the RDBUFF cache */
        xds110.use_rdbuff = false;
 
-       if (DAP_AP == type) {
+       if (type == DAP_AP) {
                /* Add bank address to register address for CMAPI call */
                address |= bank;
                /* Any write to an AP register invalidates the firmware's cache */
                xds110.is_ap_dirty = true;
-       } else if (DAP_DP_SELECT == address) {
+       } else if (address == DAP_DP_SELECT) {
                /* Any write to the SELECT register invalidates the firmware's cache */
                xds110.is_ap_dirty = true;
        }
@@ -1264,7 +1264,7 @@ static bool xds110_legacy_write_reg(uint8_t cmd, uint32_t value)
                 * If the debugger wrote to SELECT, cache the value
                 * to use to build the apNum and address values above
                 */
-               if ((DAP_DP == type) && (DAP_DP_SELECT == address))
+               if ((type == DAP_DP) && (address == DAP_DP_SELECT))
                        xds110.select = value;
        }
 
@@ -1296,7 +1296,7 @@ static int xds110_swd_run_queue(void)
                result = 0;
                while (xds110.txn_requests[request] != 0) {
                        cmd = xds110.txn_requests[request++];
-                       if (0 == (SWD_CMD_RnW & cmd)) {
+                       if (0 == (SWD_CMD_RNW & cmd)) {
                                /* DAP register write command */
                                value  = (uint32_t)(xds110.txn_requests[request++]) <<  0;
                                value |= (uint32_t)(xds110.txn_requests[request++]) <<  8;
@@ -1329,9 +1329,9 @@ static int xds110_swd_run_queue(void)
 static void xds110_swd_queue_cmd(uint8_t cmd, uint32_t *value)
 {
        /* Check if this is a read or write request */
-       bool is_read_request = (0 != (SWD_CMD_RnW & cmd));
+       bool is_read_request = (0 != (SWD_CMD_RNW & cmd));
        /* Determine whether this is a DP or AP register access */
-       uint32_t type = (0 != (SWD_CMD_APnDP & cmd)) ? DAP_AP : DAP_DP;
+       uint32_t type = (0 != (SWD_CMD_APNDP & cmd)) ? DAP_AP : DAP_DP;
        /* Extract register address from command */
        uint32_t address = ((cmd & SWD_CMD_A32) >> 1);
        uint32_t request_size = (is_read_request) ? 1 : 5;

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)