X-Git-Url: https://sigrok.org/gitweb/?a=blobdiff_plain;f=src%2Fsw_limits.c;h=6e1c4c141018392b6067f5d661f4fdd72adcdf6d;hb=97a000748a1a4ca7370121af0c84d0e2281d527a;hp=da98c66d7b8383eada5c0d25eff11973948989d8;hpb=580b94e4d762d21a018b3cf535fe8764c9cb1c6f;p=libsigrok.git diff --git a/src/sw_limits.c b/src/sw_limits.c index da98c66d..6e1c4c14 100644 --- a/src/sw_limits.c +++ b/src/sw_limits.c @@ -31,6 +31,8 @@ #include #include "libsigrok-internal.h" +#define LOG_PREFIX "sw_limits" + /** * Initialize a software limit instance * @@ -43,6 +45,7 @@ SR_PRIV void sr_sw_limits_init(struct sr_sw_limits *limits) { limits->limit_samples = 0; + limits->limit_frames = 0; limits->limit_msec = 0; } @@ -64,6 +67,9 @@ SR_PRIV int sr_sw_limits_config_get(struct sr_sw_limits *limits, uint32_t key, case SR_CONF_LIMIT_SAMPLES: *data = g_variant_new_uint64(limits->limit_samples); break; + case SR_CONF_LIMIT_FRAMES: + *data = g_variant_new_uint64(limits->limit_frames); + break; case SR_CONF_LIMIT_MSEC: *data = g_variant_new_uint64(limits->limit_msec / 1000); break; @@ -92,6 +98,9 @@ SR_PRIV int sr_sw_limits_config_set(struct sr_sw_limits *limits, uint32_t key, case SR_CONF_LIMIT_SAMPLES: limits->limit_samples = g_variant_get_uint64(data); break; + case SR_CONF_LIMIT_FRAMES: + limits->limit_frames = g_variant_get_uint64(data); + break; case SR_CONF_LIMIT_MSEC: limits->limit_msec = g_variant_get_uint64(data) * 1000; break; @@ -113,6 +122,7 @@ SR_PRIV int sr_sw_limits_config_set(struct sr_sw_limits *limits, uint32_t key, SR_PRIV void sr_sw_limits_acquisition_start(struct sr_sw_limits *limits) { limits->samples_read = 0; + limits->frames_read = 0; limits->start_time = g_get_monotonic_time(); } @@ -124,28 +134,42 @@ SR_PRIV void sr_sw_limits_acquisition_start(struct sr_sw_limits *limits) * * @param limits software limits instance * @returns TRUE if any of the software limits has been reached and the driver - * should stop data acquisition, otherwise FALSE. + * should stop data acquisition, otherwise FALSE. */ SR_PRIV gboolean sr_sw_limits_check(struct sr_sw_limits *limits) { if (limits->limit_samples) { - if (limits->samples_read >= limits->limit_samples) + if (limits->samples_read >= limits->limit_samples) { + sr_dbg("Requested number of samples (%" PRIu64 + ") reached.", limits->limit_samples); + return TRUE; + } + } + + if (limits->limit_frames) { + if (limits->frames_read >= limits->limit_frames) { + sr_dbg("Requested number of frames (%" PRIu64 + ") reached.", limits->limit_frames); return TRUE; + } } if (limits->limit_msec) { guint64 now; now = g_get_monotonic_time(); if (now > limits->start_time && - now - limits->start_time > limits->limit_msec) + now - limits->start_time > limits->limit_msec) { + sr_dbg("Requested sampling time (%" PRIu64 + "ms) reached.", limits->limit_msec / 1000); return TRUE; + } } return FALSE; } /** - * Update the amount samples that have been read + * Update the amount of samples that have been read * * Update the amount of samples that have been read in the current data * acquisition run. For each invocation @p samples_read will be accumulated and @@ -160,3 +184,20 @@ SR_PRIV void sr_sw_limits_update_samples_read(struct sr_sw_limits *limits, { limits->samples_read += samples_read; } + +/** + * Update the amount of frames that have been read + * + * Update the amount of frames that have been read in the current data + * acquisition run. For each invocation @p frames_read will be accumulated and + * once the configured frame limit has been reached sr_sw_limits_check() will + * return TRUE. + * + * @param limits software limits instance + * @param frames_read the amount of frames that have been read + */ +SR_PRIV void sr_sw_limits_update_frames_read(struct sr_sw_limits *limits, + uint64_t frames_read) +{ + limits->frames_read += frames_read; +}