X-Git-Url: https://sigrok.org/gitweb/?a=blobdiff_plain;f=src%2Fhardware%2Fopenbench-logic-sniffer%2Fprotocol.c;h=2bcf9f411335a795a2e47155a9bfe70a16ad39cd;hb=838f01227382bfd8e5b9c817e7fefff93d2c7b28;hp=dbf291439a1c71a28fd8ce48dce9dc83049fca29;hpb=55eca716e5982bd8aace203ddb840583534415c0;p=libsigrok.git diff --git a/src/hardware/openbench-logic-sniffer/protocol.c b/src/hardware/openbench-logic-sniffer/protocol.c index dbf29143..2bcf9f41 100644 --- a/src/hardware/openbench-logic-sniffer/protocol.c +++ b/src/hardware/openbench-logic-sniffer/protocol.c @@ -139,16 +139,6 @@ static int convert_trigger(const struct sr_dev_inst *sdi, return SR_OK; } -SR_PRIV struct dev_context *ols_dev_new(void) -{ - struct dev_context *devc; - - devc = g_malloc0(sizeof(struct dev_context)); - devc->trigger_at_smpl = OLS_NO_TRIGGER; - - return devc; -} - static void ols_channel_new(struct sr_dev_inst *sdi, int num_chan) { struct dev_context *devc = sdi->priv; @@ -186,9 +176,9 @@ static void ols_metadata_quirks(struct sr_dev_inst *sdi) devc->device_flags |= DEVICE_FLAG_IS_DEMON_CORE; } -SR_PRIV struct sr_dev_inst *get_metadata(struct sr_serial_dev_inst *serial) +SR_PRIV int ols_get_metadata(struct sr_dev_inst *sdi) { - struct sr_dev_inst *sdi; + struct sr_serial_dev_inst *serial; struct dev_context *devc; uint32_t tmp_int; uint8_t key, type; @@ -196,10 +186,8 @@ SR_PRIV struct sr_dev_inst *get_metadata(struct sr_serial_dev_inst *serial) GString *tmp_str, *devname, *version; guchar tmp_c; - sdi = g_malloc0(sizeof(struct sr_dev_inst)); - sdi->status = SR_ST_INACTIVE; - devc = ols_dev_new(); - sdi->priv = devc; + serial = sdi->conn; + devc = sdi->priv; devname = g_string_new(""); version = g_string_new(""); @@ -324,7 +312,7 @@ SR_PRIV struct sr_dev_inst *get_metadata(struct sr_serial_dev_inst *serial) /* Optionally amend received metadata, model specific quirks. */ ols_metadata_quirks(sdi); - return sdi; + return SR_OK; } SR_PRIV int ols_set_samplerate(const struct sr_dev_inst *sdi, @@ -476,7 +464,7 @@ SR_PRIV int ols_receive_data(int fd, int revents, void *cb_data) * the number of channels. */ j = 0; - memset(devc->tmp_sample, 0, 4); + uint8_t tmp_sample[4] = { 0, 0, 0, 0 }; for (i = 0; i < 4; i++) { if (((devc->capture_flags >> 2) & (1 << i)) == 0) { @@ -485,17 +473,11 @@ SR_PRIV int ols_receive_data(int fd, int revents, void *cb_data) * enabled, copy from received * sample. */ - devc->tmp_sample[i] = - devc->sample[j++]; - } else if (devc->capture_flags & - CAPTURE_FLAG_DEMUX && - (i > 2)) { - /* group 2 & 3 get added to 0 & 1 */ - devc->tmp_sample[i - 2] = + tmp_sample[i] = devc->sample[j++]; } } - memcpy(devc->sample, devc->tmp_sample, 4); + memcpy(devc->sample, tmp_sample, 4); sr_spew("Expanded sample: 0x%.2hhx%.2hhx%.2hhx%.2hhx ", devc->sample[3], devc->sample[2], devc->sample[1], devc->sample[0]); @@ -588,7 +570,7 @@ ols_set_basic_trigger_stage(const struct ols_basic_trigger_desc *trigger_desc, cmd = CMD_SET_BASIC_TRIGGER_CONFIG0 + stage * 4; arg[0] = arg[1] = arg[3] = 0x00; arg[2] = stage; - if (stage == trigger_desc->num_stages) + if (stage == trigger_desc->num_stages - 1) /* Last stage, fire when this one matches. */ arg[3] |= TRIGGER_START; if (send_longcommand(serial, cmd, arg) != SR_OK) @@ -641,7 +623,7 @@ SR_PRIV int ols_prepare_acquisition(const struct sr_dev_inst *sdi) delaycount = readcount * (1 - devc->capture_ratio / 100.0); devc->trigger_at_smpl = (readcount - delaycount) * 4 - basic_trigger_desc.num_stages; - for (int i = 0; i <= basic_trigger_desc.num_stages; i++) { + for (int i = 0; i < basic_trigger_desc.num_stages; i++) { sr_dbg("Setting OLS stage %d trigger.", i); if ((ret = ols_set_basic_trigger_stage( &basic_trigger_desc, serial, i)) != SR_OK) @@ -650,6 +632,7 @@ SR_PRIV int ols_prepare_acquisition(const struct sr_dev_inst *sdi) } else { /* No triggers configured, force trigger on first stage. */ sr_dbg("Forcing trigger at stage 0."); + basic_trigger_desc.num_stages = 1; if ((ret = ols_set_basic_trigger_stage(&basic_trigger_desc, serial, 0)) != SR_OK) return ret;