X-Git-Url: https://sigrok.org/gitweb/?a=blobdiff_plain;f=hardware%2Fasix-sigma%2Fasix-sigma.c;h=f356c8482fdbf3e1791378098cda179a09853faf;hb=5b5ea7c6d25bb42de09b61d0a070d78252f2367b;hp=7cc7c9da901b97a9d5abf9d2f9561efdd6d3bf8f;hpb=98b8cbc17e03119fcaa735a4bc2f0451000ab54f;p=libsigrok.git diff --git a/hardware/asix-sigma/asix-sigma.c b/hardware/asix-sigma/asix-sigma.c index 7cc7c9da..f356c848 100644 --- a/hardware/asix-sigma/asix-sigma.c +++ b/hardware/asix-sigma/asix-sigma.c @@ -407,6 +407,7 @@ static int hw_init(char *deviceinfo) sigma->num_probes = 0; sigma->samples_per_event = 0; sigma->capture_ratio = 50; + sigma->use_triggers = 0; /* Register SIGMA device. */ sdi = sigrok_device_instance_new(0, ST_INITIALIZING, @@ -654,6 +655,9 @@ static int configure_probes(struct sigrok_device_instance *sdi, GSList *probes) return SIGROK_ERR; } } + + if (trigger_set) + sigma->use_triggers = 1; } return SIGROK_OK; @@ -809,7 +813,8 @@ static int get_trigger_offset(uint16_t *samples, uint16_t last_sample, * spread 20 ns apart. */ static int decode_chunk_ts(uint8_t *buf, uint16_t *lastts, - uint16_t *lastsample, int triggerpos, void *user_data) + uint16_t *lastsample, int triggerpos, + uint16_t limit_chunk, void *user_data) { struct sigrok_device_instance *sdi = user_data; struct sigma *sigma = sdi->priv; @@ -841,6 +846,10 @@ static int decode_chunk_ts(uint8_t *buf, uint16_t *lastts, tsdiff = ts - *lastts; *lastts = ts; + /* Decode partial chunk. */ + if (limit_chunk && ts > limit_chunk) + return SIGROK_OK; + /* Pad last sample up to current point. */ numpad = tsdiff * sigma->samples_per_event - clustersize; if (numpad > 0) { @@ -908,20 +917,25 @@ static int decode_chunk_ts(uint8_t *buf, uint16_t *lastts, sent += tosend; } - packet.type = DF_TRIGGER; - packet.length = 0; - packet.payload = 0; - session_bus(sigma->session_id, &packet); + /* Only send trigger if explicitly enabled. */ + if (sigma->use_triggers) { + packet.type = DF_TRIGGER; + packet.length = 0; + packet.payload = 0; + session_bus(sigma->session_id, &packet); + } } /* Send rest of the chunk to sigrok. */ tosend = n - sent; - packet.type = DF_LOGIC; - packet.length = tosend * sizeof(uint16_t); - packet.unitsize = 2; - packet.payload = samples + sent; - session_bus(sigma->session_id, &packet); + if (tosend > 0) { + packet.type = DF_LOGIC; + packet.length = tosend * sizeof(uint16_t); + packet.unitsize = 2; + packet.payload = samples + sent; + session_bus(sigma->session_id, &packet); + } *lastsample = samples[n - 1]; } @@ -991,20 +1005,29 @@ static int receive_data(int fd, int revents, void *user_data) /* Decode chunks and send them to sigrok. */ for (i = 0; i < newchunks; ++i) { + int limit_chunk = 0; + + /* The last chunk may potentially be only in part. */ + if (sigma->state.chunks_downloaded == numchunks - 1) + { + /* Find the last valid timestamp */ + limit_chunk = sigma->state.stoppos % 512 + sigma->state.lastts; + } + if (sigma->state.chunks_downloaded + i == sigma->state.triggerchunk) decode_chunk_ts(buf + (i * CHUNK_SIZE), &sigma->state.lastts, &sigma->state.lastsample, sigma->state.triggerpos & 0x1ff, - user_data); + limit_chunk, user_data); else decode_chunk_ts(buf + (i * CHUNK_SIZE), &sigma->state.lastts, &sigma->state.lastsample, - -1, user_data); - } + -1, limit_chunk, user_data); - sigma->state.chunks_downloaded += newchunks; + ++sigma->state.chunks_downloaded; + } } return TRUE;