]> sigrok.org Git - libsigrok.git/commitdiff
dslogic: Implement trigger functionality
authorDiego Asanza <redacted>
Sat, 16 Apr 2016 10:45:27 +0000 (12:45 +0200)
committerUwe Hermann <redacted>
Mon, 16 May 2016 15:57:07 +0000 (17:57 +0200)
This commit implements DSLogic trigger functionality.

The following triggers are working:

 - trigger on rising edge
 - trigger on falling edge
 - trigger on any edge
 - trigger on logic one
 - trigger on logic zero

Pre-trigger capture ratio is also working.

Signed-off-by: Diego Asanza <redacted>
Tested-by: Andrew Bradford <redacted>
src/hardware/fx2lafw/api.c
src/hardware/fx2lafw/dslogic.c
src/hardware/fx2lafw/dslogic.h
src/hardware/fx2lafw/protocol.c
src/hardware/fx2lafw/protocol.h

index dfe6bed65002722e8f51afa8c4211a8672b7a215..fe5ba9fe9b49ce49aefe6e632f0edb5c3c09d9d8 100644 (file)
@@ -664,7 +664,7 @@ static int start_transfers(const struct sr_dev_inst *sdi)
        devc->acq_aborted = FALSE;
        devc->empty_transfer_count = 0;
 
-       if ((trigger = sr_session_trigger_get(sdi->session))) {
+       if ((trigger = sr_session_trigger_get(sdi->session)) && !devc->dslogic) {
                int pre_trigger_samples = 0;
                if (devc->limit_samples > 0)
                        pre_trigger_samples = devc->capture_ratio * devc->limit_samples/100;
@@ -741,11 +741,11 @@ static void LIBUSB_CALL dslogic_trigger_receive(struct libusb_transfer *transfer
        } else if (transfer->status == LIBUSB_TRANSFER_COMPLETED
                        && transfer->actual_length == sizeof(struct dslogic_trigger_pos)) {
                tpos = (struct dslogic_trigger_pos *)transfer->buffer;
-               sr_dbg("tpos real_pos %.8x ram_saddr %.8x", tpos->real_pos, tpos->ram_saddr);
+               sr_info("tpos real_pos %d ram_saddr %d", tpos->real_pos, tpos->ram_saddr);
+               devc->trigger_pos  = tpos->real_pos;
                g_free(tpos);
                start_transfers(sdi);
        }
-
        libusb_free_transfer(transfer);
 }
 
index f912278fa23c7505462b50bb700dfd41b25eb70c..0e4c5599bceb3590e1859d733a603b121419989f 100644 (file)
@@ -165,14 +165,13 @@ static int dslogic_set_trigger(const struct sr_dev_inst *sdi,
        struct sr_trigger *trigger;
        struct sr_trigger_stage *stage;
        struct sr_trigger_match *match;
+
        struct dev_context *devc;
+       devc = sdi->priv;
        const GSList *l, *m;
        int channelbit, i = 0;
        uint16_t v16;
 
-       devc = sdi->priv;
-       devc->trigger_en = FALSE;
-
        cfg->trig_mask0[0] = 0xffff;
        cfg->trig_mask1[0] = 0xffff;
 
@@ -188,8 +187,33 @@ static int dslogic_set_trigger(const struct sr_dev_inst *sdi,
        cfg->trig_count0[0] = 0;
        cfg->trig_count1[0] = 0;
 
-       if (!(trigger = sr_session_trigger_get(sdi->session)))
+       cfg->trig_pos = 0;
+       cfg->trig_sda = 0;
+       cfg->trig_glb = 0;
+       cfg->trig_adp = cfg->count - cfg->trig_pos - 1;
+
+       for (i = 1; i < 16; i++) {
+               cfg->trig_mask0[i] = 0xff;
+               cfg->trig_mask1[i] = 0xff;
+               cfg->trig_value0[i] = 0;
+               cfg->trig_value1[i] = 0;
+               cfg->trig_edge0[i] = 0;
+               cfg->trig_edge1[i] = 0;
+               cfg->trig_count0[i] = 0;
+               cfg->trig_count1[i] = 0;
+               cfg->trig_logic0[i] = 2;
+               cfg->trig_logic1[i] = 2;
+       }
+
+       cfg->trig_pos = (uint32_t)(devc->capture_ratio / 100.0 * devc->limit_samples);
+       sr_dbg("pos: %d", cfg->trig_pos);
+
+       sr_dbg("configuring trigger");
+
+       if (!(trigger = sr_session_trigger_get(sdi->session))){
+               sr_dbg("No session trigger found");
                return SR_OK;
+       }
 
        for (l = trigger->stages; l; l = l->next) {
                stage = l->data;
@@ -199,7 +223,6 @@ static int dslogic_set_trigger(const struct sr_dev_inst *sdi,
                                /* Ignore disabled channels with a trigger. */
                                continue;
                        channelbit = 1 << (match->channel->index);
-                       devc->trigger_en = TRUE; /* Triggered. */
                        /* Simple trigger support (event). */
                        if (match->match == SR_TRIGGER_ONE) {
                                cfg->trig_mask0[0] &= ~channelbit;
@@ -221,34 +244,19 @@ static int dslogic_set_trigger(const struct sr_dev_inst *sdi,
                                cfg->trig_value1[0] |= channelbit;
                                cfg->trig_edge0[0] |= channelbit;
                                cfg->trig_edge1[0] |= channelbit;
-                       } else if (match->match == SR_TRIGGER_EDGE){
+                       } else if(match->match == SR_TRIGGER_EDGE){
                                cfg->trig_edge0[0] |= channelbit;
                                cfg->trig_edge1[0] |= channelbit;
                        }
                }
        }
-
-       if (devc->trigger_en) {
-               for (i = 1; i < 16; i++) {
-                       cfg->trig_mask0[i] = 0xff;
-                       cfg->trig_mask1[i] = 0xff;
-                       cfg->trig_value0[i] = 0;
-                       cfg->trig_value1[i] = 0;
-                       cfg->trig_edge0[i] = 0;
-                       cfg->trig_edge1[i] = 0;
-                       cfg->trig_count0[i] = 0;
-                       cfg->trig_count1[i] = 0;
-                       cfg->trig_logic0[i] = 2;
-                       cfg->trig_logic1[i] = 2;
-               }
-               v16 = RL16(&cfg->mode);
-               v16 |= 1 << 0;
-               WL16(&cfg->mode, v16);
-       }
-
+       v16 = RL16(&cfg->mode);
+       v16 |= 1 << 0;
+       WL16(&cfg->mode, v16);
        return SR_OK;
 }
 
+
 SR_PRIV int dslogic_fpga_configure(const struct sr_dev_inst *sdi)
 {
        struct dev_context *devc;
@@ -319,9 +327,8 @@ SR_PRIV int dslogic_fpga_configure(const struct sr_dev_inst *sdi)
                v16 = 1 << 14;
        else if (devc->dslogic_mode == DS_OP_LOOPBACK_TEST)
                v16 = 1 << 13;
-       //if (devc->dslogic_external_clock)
-       //      v16 |= 1 << 1;
-       //v16 |= 1 << 0;
+       if (devc->dslogic_external_clock)
+               v16 |= 1 << 1;
        WL16(&cfg.mode, v16);
        v32 = ceil(SR_MHZ(100) * 1.0 / devc->cur_samplerate);
        WL32(&cfg.divider, v32);
index 0a83bbd805af00bbfd68579087890cb7cc1dc132..e6646513c6a40c0db1d1f555227596fbad7ab737 100644 (file)
@@ -55,7 +55,8 @@ struct dslogic_mode {
 struct dslogic_trigger_pos {
        uint32_t real_pos;
        uint32_t ram_saddr;
-       uint8_t first_block[504];
+       uint32_t remain_cnt;
+       uint8_t first_block[500];
 };
 
 /*
index ad16da9524d7da3e2275e0fa9f7d128f3961dbf5..f028d132711221301857b94eae5f1a85353e823d 100644 (file)
@@ -306,7 +306,6 @@ SR_PRIV struct dev_context *fx2lafw_dev_new(void)
        devc->limit_samples = 0;
        devc->capture_ratio = 0;
        devc->sample_wide = FALSE;
-       devc->trigger_en = FALSE;
        devc->stl = NULL;
 
        return devc;
@@ -455,6 +454,7 @@ SR_PRIV void LIBUSB_CALL fx2lafw_receive_transfer(struct libusb_transfer *transf
        struct sr_dev_inst *sdi;
        struct dev_context *devc;
        gboolean packet_has_error = FALSE;
+       struct sr_datafeed_packet packet;
        unsigned int num_samples;
        int trigger_offset, cur_sample_count, unitsize;
        int pre_trigger_samples;
@@ -507,8 +507,6 @@ SR_PRIV void LIBUSB_CALL fx2lafw_receive_transfer(struct libusb_transfer *transf
        } else {
                devc->empty_transfer_count = 0;
        }
-       if (devc->trigger_en)
-               devc->trigger_fired = TRUE;
        if (devc->trigger_fired) {
                if (!devc->limit_samples || devc->sent_samples < devc->limit_samples) {
                        /* Send the incoming transfer to the session bus. */
@@ -517,9 +515,29 @@ SR_PRIV void LIBUSB_CALL fx2lafw_receive_transfer(struct libusb_transfer *transf
                        else
                                num_samples = cur_sample_count;
 
-                       devc->send_data_proc(sdi, (uint8_t *)transfer->buffer,
-                               num_samples * unitsize, unitsize);
-                       devc->sent_samples += num_samples;
+                       if(devc->dslogic && devc->trigger_pos > devc->sent_samples
+                               && devc->trigger_pos <= devc->sent_samples + num_samples){
+                                       /* dslogic trigger in this block. Send trigger position */
+                                       trigger_offset = devc->trigger_pos - devc->sent_samples;
+                                       /* pre-trigger samples */
+                                       devc->send_data_proc(sdi, (uint8_t *)transfer->buffer,
+                                               trigger_offset * unitsize, unitsize);
+                                       devc->sent_samples += trigger_offset;
+                                       /* trigger position */
+                                       devc->trigger_pos = 0;
+                                       packet.type = SR_DF_TRIGGER;
+                                       packet.payload = NULL;
+                                       sr_session_send(sdi, &packet);
+                                       /* post trigger samples */
+                                       num_samples -= trigger_offset;
+                                       devc->send_data_proc(sdi, (uint8_t *)transfer->buffer
+                                                       + trigger_offset * unitsize,    num_samples * unitsize, unitsize);
+                                       devc->sent_samples += num_samples;
+                       }else{
+                               devc->send_data_proc(sdi, (uint8_t *)transfer->buffer,
+                                       num_samples * unitsize, unitsize);
+                               devc->sent_samples += num_samples;
+                       }
                }
        } else {
                trigger_offset = soft_trigger_logic_check(devc->stl,
index 2e424ac32b790436120d16865a2da028342ccd85..54b2f97df9b3ea980b87520c01d26a5711bb798e 100644 (file)
@@ -133,8 +133,8 @@ struct dev_context {
        /* Is this a DSLogic? */
        gboolean dslogic;
        uint16_t dslogic_mode;
+       uint32_t trigger_pos;
        int dslogic_external_clock;
-       gboolean trigger_en;
 };
 
 SR_PRIV int fx2lafw_command_start_acquisition(const struct sr_dev_inst *sdi);