}
-static int receive_data(int fd, int revents, void *cb_data)
+/*
+ * Handle the Sigma when in CAPTURE mode. This function checks:
+ * - Sampling time ended
+ * - DRAM capacity overflow
+ * This function triggers download of the samples from Sigma
+ * in case either of the above conditions is true.
+ */
+static int sigma_capture_mode(struct sr_dev_inst *sdi)
{
- struct sr_dev_inst *sdi;
- struct dev_context *devc;
+ struct dev_context *devc = sdi->priv;
+
struct sr_datafeed_packet packet;
uint64_t running_msec;
struct timeval tv;
int numchunks;
uint8_t modestatus;
- (void)fd;
- (void)revents;
+ /* Get the current position. */
+ sigma_read_pos(&devc->state.stoppos, &devc->state.triggerpos,
+ devc);
- sdi = cb_data;
- devc = sdi->priv;
+ numchunks = (devc->state.stoppos + 511) / 512;
- if (devc->state.state == SIGMA_IDLE)
+ /* Check if the timer has expired, or memory is full. */
+ gettimeofday(&tv, 0);
+ running_msec = (tv.tv_sec - devc->start_tv.tv_sec) * 1000 +
+ (tv.tv_usec - devc->start_tv.tv_usec) / 1000;
+
+ if (running_msec < devc->limit_msec && numchunks < 32767)
+ /* Still capturing. */
return TRUE;
- if (devc->state.state == SIGMA_CAPTURE) {
- /* Get the current position. */
- sigma_read_pos(&devc->state.stoppos, &devc->state.triggerpos,
- devc);
+ /* Stop acquisition. */
+ sigma_set_register(WRITE_MODE, 0x11, devc);
- numchunks = (devc->state.stoppos + 511) / 512;
+ /* Set SDRAM Read Enable. */
+ sigma_set_register(WRITE_MODE, 0x02, devc);
- /* Check if the timer has expired, or memory is full. */
- gettimeofday(&tv, 0);
- running_msec = (tv.tv_sec - devc->start_tv.tv_sec) * 1000 +
- (tv.tv_usec - devc->start_tv.tv_usec) / 1000;
+ /* Get the current position. */
+ sigma_read_pos(&devc->state.stoppos, &devc->state.triggerpos, devc);
- if (running_msec < devc->limit_msec && numchunks < 32767)
- /* Still capturing. */
- return TRUE;
+ /* Check if trigger has fired. */
+ modestatus = sigma_get_register(READ_MODE, devc);
+ if (modestatus & 0x20)
+ devc->state.triggerchunk = devc->state.triggerpos / 512;
+ else
+ devc->state.triggerchunk = -1;
- /* Stop acquisition. */
- sigma_set_register(WRITE_MODE, 0x11, devc);
+ /* Transfer captured data from device. */
+ download_capture(sdi);
- /* Set SDRAM Read Enable. */
- sigma_set_register(WRITE_MODE, 0x02, devc);
+ /* All done. */
+ packet.type = SR_DF_END;
+ sr_session_send(sdi, &packet);
- /* Get the current position. */
- sigma_read_pos(&devc->state.stoppos, &devc->state.triggerpos, devc);
+ dev_acquisition_stop(sdi, sdi);
- /* Check if trigger has fired. */
- modestatus = sigma_get_register(READ_MODE, devc);
- if (modestatus & 0x20)
- devc->state.triggerchunk = devc->state.triggerpos / 512;
- else
- devc->state.triggerchunk = -1;
+ return TRUE;
+}
- /* Transfer captured data from device. */
- download_capture(sdi);
+static int receive_data(int fd, int revents, void *cb_data)
+{
+ struct sr_dev_inst *sdi;
+ struct dev_context *devc;
- /* All done. */
- packet.type = SR_DF_END;
- sr_session_send(sdi, &packet);
+ (void)fd;
+ (void)revents;
- dev_acquisition_stop(sdi, sdi);
- }
+ sdi = cb_data;
+ devc = sdi->priv;
+
+ if (devc->state.state == SIGMA_IDLE)
+ return TRUE;
+
+ if (devc->state.state == SIGMA_CAPTURE)
+ return sigma_capture_mode(sdi);
return TRUE;
}