From: Gerhard Sittig Date: Fri, 15 May 2020 07:06:40 +0000 (+0200) Subject: asix-sigma: style nits, expression complexity, information locality X-Git-Url: https://sigrok.org/gitaction?a=commitdiff_plain;h=5c231fc466fac5da4b24f79a29af7a3fa0a10f76;p=libsigrok.git asix-sigma: style nits, expression complexity, information locality Address minor style nits to improve readability and simplify review. The sizeof() expressions need not duplicate data type details. Concentrate the assignment to, update of, and evaluation of variables in closer proximity to reduce potential for errors during maintenance. Separate the gathering of input data and the check for their availability from each other, to simplify expressions and better reflect the logic's flow. --- diff --git a/src/hardware/asix-sigma/api.c b/src/hardware/asix-sigma/api.c index 9c74d7c1..88cb795c 100644 --- a/src/hardware/asix-sigma/api.c +++ b/src/hardware/asix-sigma/api.c @@ -465,7 +465,7 @@ static int dev_acquisition_start(const struct sr_dev_inst *sdi) } /* Setup trigger in and out pins to default values. */ - memset(&triggerinout_conf, 0, sizeof(struct triggerinout)); + memset(&triggerinout_conf, 0, sizeof(triggerinout_conf)); triggerinout_conf.trgout_bytrigger = 1; triggerinout_conf.trgout_enable = 1; /* TODO diff --git a/src/hardware/asix-sigma/protocol.c b/src/hardware/asix-sigma/protocol.c index 74b3a9fc..ee15bb0d 100644 --- a/src/hardware/asix-sigma/protocol.c +++ b/src/hardware/asix-sigma/protocol.c @@ -976,8 +976,9 @@ SR_PRIV int sigma_convert_trigger(const struct sr_dev_inst *sdi) int channelbit, trigger_set; devc = sdi->priv; - memset(&devc->trigger, 0, sizeof(struct sigma_trigger)); - if (!(trigger = sr_session_trigger_get(sdi->session))) + memset(&devc->trigger, 0, sizeof(devc->trigger)); + trigger = sr_session_trigger_get(sdi->session); + if (!trigger) return SR_OK; trigger_set = 0; @@ -1303,12 +1304,11 @@ static int download_capture(struct sr_dev_inst *sdi) uint32_t i; uint32_t dl_lines_total, dl_lines_curr, dl_lines_done; uint32_t dl_first_line, dl_line; - uint32_t dl_events_in_line; + uint32_t dl_events_in_line, trigger_event; uint32_t trg_line, trg_event; int ret; devc = sdi->priv; - dl_events_in_line = EVENTS_PER_ROW; sr_info("Downloading sample data."); devc->state.state = SIGMA_DOWNLOAD; @@ -1394,12 +1394,13 @@ static int download_capture(struct sr_dev_inst *sdi) } for (i = 0; i < dl_lines_curr; i++) { - uint32_t trigger_event = ~0; /* The last "DRAM line" need not span its full length. */ + dl_events_in_line = EVENTS_PER_ROW; if (dl_lines_done + i == dl_lines_total - 1) dl_events_in_line = stoppos & ROW_MASK; /* Test if the trigger happened on this line. */ + trigger_event = ~0; if (dl_lines_done + i == trg_line) trigger_event = trg_event; @@ -1497,7 +1498,7 @@ static void add_trigger_function(enum triggerop oper, enum triggerfunc func, int i, j; int x[2][2], tmp, a, b, aset, bset, rset; - memset(x, 0, 4 * sizeof(int)); + memset(x, 0, sizeof(x)); /* Trigger detect condition. */ switch (oper) { @@ -1581,9 +1582,10 @@ SR_PRIV int sigma_build_basic_trigger(struct dev_context *devc, struct triggerlut *lut) { int i,j; - uint16_t masks[2] = { 0, 0 }; + uint16_t masks[2]; - memset(lut, 0, sizeof(struct triggerlut)); + memset(lut, 0, sizeof(*lut)); + memset(&masks, 0, sizeof(masks)); /* Constant for simple triggers. */ lut->m4 = 0xa000;