From: Gerhard Sittig Date: Tue, 6 Oct 2020 17:18:42 +0000 (+0200) Subject: itech-it8500: declaration nits X-Git-Url: https://sigrok.org/gitaction?a=commitdiff_plain;h=8c8fff477310550170f5441e24d87673c472f624;p=libsigrok.git itech-it8500: declaration nits Rearrange the order of declarations in the protocol.h header. Start with packet layout, continue with requests (commands), then responses (status), before the device context and the set of routines. Rename the status codes to STS_* in contrast to CMD_* codes. Use an enum for different byte values, leave defines for packet sizes et al. Phrase bit fields in terms of bit numbers not byte values. Total nit: Change the breaks in the long list of add_source() args. Keep event type and timeout together, similar to callback and its data. --- diff --git a/src/hardware/itech-it8500/api.c b/src/hardware/itech-it8500/api.c index fe3b6762..a720af52 100644 --- a/src/hardware/itech-it8500/api.c +++ b/src/hardware/itech-it8500/api.c @@ -627,8 +627,8 @@ static int dev_acquisition_start(const struct sr_dev_inst *sdi) devc = sdi->priv; serial = sdi->conn; - ret = serial_source_add(sdi->session, serial, G_IO_IN, - (1000.0 / devc->sample_rate), + ret = serial_source_add(sdi->session, serial, + G_IO_IN, (1000.0 / devc->sample_rate), itech_it8500_receive_data, (void *)sdi); if (ret == SR_OK) { sr_sw_limits_acquisition_start(&devc->limits); diff --git a/src/hardware/itech-it8500/protocol.c b/src/hardware/itech-it8500/protocol.c index 825860a7..de8057a8 100644 --- a/src/hardware/itech-it8500/protocol.c +++ b/src/hardware/itech-it8500/protocol.c @@ -137,7 +137,7 @@ SR_PRIV int itech_it8500_send_cmd(struct sr_serial_dev_inst *serial, resp->command); if (resp->command == CMD_RESPONSE) { - if (resp->data[0] != IT8500_COMMAND_SUCCESSFUL) { + if (resp->data[0] != STS_COMMAND_SUCCESSFUL) { sr_dbg("%s: Command (%02x) failed: status=%02x", __func__, cmd->command, resp->data[0]); goto error; diff --git a/src/hardware/itech-it8500/protocol.h b/src/hardware/itech-it8500/protocol.h index b3b4ce3e..71b126b3 100644 --- a/src/hardware/itech-it8500/protocol.h +++ b/src/hardware/itech-it8500/protocol.h @@ -43,15 +43,16 @@ #define IT8500_DATA_LEN 22 #define IT8500_PACKET_LEN (IT8500_HEADER_LEN + IT8500_DATA_LEN + 1) -#define IT8500_PREAMBLE 0xaa -#define IT8500_MAX_MODEL_NAME_LEN 5 +/* + * Data structure to track commands and reponses. + */ +struct itech_it8500_cmd_packet { + uint8_t command; /* Command number. */ + uint8_t address; /* Unit address: 0..254 (255 = broadcast). */ + uint8_t data[IT8500_DATA_LEN]; /* Command/Response data. */ +}; -/* Status packet status byte values. */ -#define IT8500_COMMAND_SUCCESSFUL 0x80 -#define IT8500_INVALID_CHECKSUM 0x90 -#define IT8500_INVALID_PARAMETER 0xa0 -#define IT8500_UNKNOWN_COMMAND 0xb0 -#define IT8500_INVALID_COMMAND 0xc0 +#define IT8500_PREAMBLE 0xaa /* * Operating modes. @@ -125,39 +126,41 @@ enum itech_it8500_command { CMD_GET_OPP_DELAY = 0x89, }; -/* - * Data structure to track commands and reponses. - */ -struct itech_it8500_cmd_packet { - uint8_t command; /* Command number. */ - uint8_t address; /* Unit address: 0..254 (255 = broadcast). */ - uint8_t data[IT8500_DATA_LEN]; /* Command/Response data. */ +/* Status packet status byte values. */ +enum itech_it8500_status_code { + STS_COMMAND_SUCCESSFUL = 0x80, + STS_INVALID_CHECKSUM = 0x90, + STS_INVALID_PARAMETER = 0xa0, + STS_UNKNOWN_COMMAND = 0xb0, + STS_INVALID_COMMAND = 0xc0, }; /* * "Operation state" register flags. */ -#define OS_CAL_FLAG 0x01 -#define OS_WTG_FLAG 0x02 -#define OS_REM_FLAG 0x04 -#define OS_OUT_FLAG 0x08 -#define OS_LOCAL_FLAG 0x10 -#define OS_SENSE_FLAG 0x20 -#define OS_LOT_FLAG 0x40 +#define OS_CAL_FLAG (1UL << 0) +#define OS_WTG_FLAG (1UL << 1) +#define OS_REM_FLAG (1UL << 2) +#define OS_OUT_FLAG (1UL << 3) +#define OS_LOCAL_FLAG (1UL << 4) +#define OS_SENSE_FLAG (1UL << 5) +#define OS_LOT_FLAG (1UL << 6) /* * "Demand state" register flags. */ -#define DS_RV_FLAG 0x0001 -#define DS_OV_FLAG 0x0002 -#define DS_OC_FLAG 0x0004 -#define DS_OP_FLAG 0x0008 -#define DS_OT_FLAG 0x0010 -#define DS_SV_FLAG 0x0020 -#define DS_CC_MODE_FLAG 0x0040 -#define DS_CV_MODE_FLAG 0x0080 -#define DS_CW_MODE_FLAG 0x0100 -#define DS_CR_MODE_FLAG 0x0200 +#define DS_RV_FLAG (1UL << 0) +#define DS_OV_FLAG (1UL << 1) +#define DS_OC_FLAG (1UL << 2) +#define DS_OP_FLAG (1UL << 3) +#define DS_OT_FLAG (1UL << 4) +#define DS_SV_FLAG (1UL << 5) +#define DS_CC_MODE_FLAG (1UL << 6) +#define DS_CV_MODE_FLAG (1UL << 7) +#define DS_CW_MODE_FLAG (1UL << 8) +#define DS_CR_MODE_FLAG (1UL << 9) + +#define IT8500_MAX_MODEL_NAME_LEN 5 struct dev_context { char model[IT8500_MAX_MODEL_NAME_LEN + 1];