]> sigrok.org Git - libsigrok.git/blobdiff - hardware/asix-sigma/asix-sigma.c
sigma: Use heap for datafeed packet and header.
[libsigrok.git] / hardware / asix-sigma / asix-sigma.c
index 342b2a4da2a57775a2d0ba77f12bcaa49d37d0a9..d30e056564a1c1e168fc38c8bbb38e9ee0fd802c 100644 (file)
@@ -1023,10 +1023,13 @@ static int receive_data(int fd, int revents, void *cb_data)
        (void)fd;
        (void)revents;
 
+       /* Get the current position. */
+       sigma_read_pos(&ctx->state.stoppos, &ctx->state.triggerpos, ctx);
+
        numchunks = (ctx->state.stoppos + 511) / 512;
 
        if (ctx->state.state == SIGMA_IDLE)
-               return FALSE;
+               return TRUE;
 
        if (ctx->state.state == SIGMA_CAPTURE) {
                /* Check if the timer has expired, or memory is full. */
@@ -1035,11 +1038,11 @@ static int receive_data(int fd, int revents, void *cb_data)
                        (tv.tv_usec - ctx->start_tv.tv_usec) / 1000;
 
                if (running_msec < ctx->limit_msec && numchunks < 32767)
-                       return FALSE;
+                       return TRUE; /* While capturing... */
+               else {
 
                hw_dev_acquisition_stop(sdi->index, sdi);
 
-               return FALSE;
        } else if (ctx->state.state == SIGMA_DOWNLOAD) {
                if (ctx->state.chunks_downloaded >= numchunks) {
                        /* End of samples. */
@@ -1258,8 +1261,8 @@ static int hw_dev_acquisition_start(int dev_index, void *cb_data)
 {
        struct sr_dev_inst *sdi;
        struct context *ctx;
-       struct sr_datafeed_packet packet;
-       struct sr_datafeed_header header;
+       struct sr_datafeed_packet *packet;
+       struct sr_datafeed_header *header;
        struct clockselect_50 clockselect;
        int frac, triggerpin, ret;
        uint8_t triggerselect;
@@ -1351,18 +1354,30 @@ static int hw_dev_acquisition_start(int dev_index, void *cb_data)
 
        ctx->session_dev_id = cb_data;
 
-       /* Send header packet to the session bus. */
-       packet.type = SR_DF_HEADER;
-       packet.payload = &header;
-       header.feed_version = 1;
-       gettimeofday(&header.starttime, NULL);
-       header.samplerate = ctx->cur_samplerate;
-       header.num_logic_probes = ctx->num_probes;
-       sr_session_send(ctx->session_dev_id, &packet);
+       if (!(packet = g_try_malloc(sizeof(struct sr_datafeed_packet)))) {
+               sr_err("sigma: %s: packet malloc failed.", __func__);
+               return SR_ERR_MALLOC;
+       }
+
+       if (!(header = g_try_malloc(sizeof(struct sr_datafeed_header)))) {
+               sr_err("sigma: %s: header malloc failed.", __func__);
+               return SR_ERR_MALLOC;
+       }
 
        /* Add capture source. */
        sr_source_add(0, G_IO_IN, 10, receive_data, sdi);
 
+       /* Send header packet to the session bus. */
+       packet->type = SR_DF_HEADER;
+       packet->payload = header;
+       header->feed_version = 1;
+       gettimeofday(&header->starttime, NULL);
+       header->samplerate = ctx->cur_samplerate;
+       header->num_logic_probes = ctx->num_probes;
+       sr_session_send(ctx->session_dev_id, packet);
+       g_free(header);
+       g_free(packet);
+
        ctx->state.state = SIGMA_CAPTURE;
 
        return SR_OK;