X-Git-Url: http://sigrok.org/gitweb/?a=blobdiff_plain;ds=sidebyside;f=src%2Fhardware%2Fbaylibre-acme%2Fapi.c;h=a1b860e3621fb91a1655d97fda085a66fb339e08;hb=0a2ffa3ebf025dd3955319ca0d0750464b8dadac;hp=72e8f345b870d04d35a52cd6994eabc225bbdcb9;hpb=7a1a3a36a98eda90c2fe4a78326ea68afe94a041;p=libsigrok.git
diff --git a/src/hardware/baylibre-acme/api.c b/src/hardware/baylibre-acme/api.c
index 72e8f345..a1b860e3 100644
--- a/src/hardware/baylibre-acme/api.c
+++ b/src/hardware/baylibre-acme/api.c
@@ -17,14 +17,13 @@
* along with this program. If not, see .
*/
+#include
#include "protocol.h"
#include
#include
-SR_PRIV struct sr_dev_driver baylibre_acme_driver_info;
-
static const uint32_t devopts[] = {
- SR_CONF_CONTINUOUS | SR_CONF_SET,
+ SR_CONF_CONTINUOUS,
SR_CONF_LIMIT_SAMPLES | SR_CONF_GET | SR_CONF_SET,
SR_CONF_LIMIT_MSEC | SR_CONF_GET | SR_CONF_SET,
SR_CONF_SAMPLERATE | SR_CONF_GET | SR_CONF_SET | SR_CONF_LIST,
@@ -52,25 +51,15 @@ static const uint64_t samplerates[] = {
SR_HZ(1),
};
-static int init(struct sr_dev_driver *di, struct sr_context *sr_ctx)
-{
- return std_init(sr_ctx, di, LOG_PREFIX);
-}
-
static GSList *scan(struct sr_dev_driver *di, GSList *options)
{
- struct drv_context *drvc;
struct dev_context *devc;
struct sr_dev_inst *sdi;
- GSList *devices;
gboolean status;
int i;
(void)options;
- drvc = di->priv;
- devices = NULL;
-
devc = g_malloc0(sizeof(struct dev_context));
devc->samplerate = SR_HZ(10);
@@ -78,7 +67,6 @@ static GSList *scan(struct sr_dev_driver *di, GSList *options)
sdi->status = SR_ST_INACTIVE;
sdi->vendor = g_strdup("BayLibre");
sdi->model = g_strdup("ACME");
- sdi->driver = di;
sdi->priv = devc;
status = bl_acme_is_sane();
@@ -129,10 +117,7 @@ static GSList *scan(struct sr_dev_driver *di, GSList *options)
if (!sdi->channel_groups)
goto err_out;
- devices = g_slist_append(devices, sdi);
- drvc->instances = g_slist_append(drvc->instances, sdi);
-
- return devices;
+ return std_scan_complete(di, g_slist_append(NULL, sdi));
err_out:
g_free(devc);
@@ -141,21 +126,10 @@ err_out:
return NULL;
}
-static GSList *dev_list(const struct sr_dev_driver *di)
-{
- return ((struct drv_context *)(di->priv))->instances;
-}
-
-static int dev_clear(const struct sr_dev_driver *di)
-{
- return std_dev_clear(di, NULL);
-}
-
static int dev_open(struct sr_dev_inst *sdi)
{
(void)sdi;
- /* Nothing to do here. */
sdi->status = SR_ST_ACTIVE;
return SR_OK;
@@ -165,19 +139,11 @@ static int dev_close(struct sr_dev_inst *sdi)
{
(void)sdi;
- /* Nothing to do here. */
sdi->status = SR_ST_INACTIVE;
return SR_OK;
}
-static int cleanup(const struct sr_dev_driver *di)
-{
- dev_clear(di);
-
- return SR_OK;
-}
-
static int config_get(uint32_t key, GVariant **data,
const struct sr_dev_inst *sdi,
const struct sr_channel_group *cg)
@@ -192,10 +158,8 @@ static int config_get(uint32_t key, GVariant **data,
ret = SR_OK;
switch (key) {
case SR_CONF_LIMIT_SAMPLES:
- *data = g_variant_new_uint64(devc->limit_samples);
- break;
case SR_CONF_LIMIT_MSEC:
- *data = g_variant_new_uint64(devc->limit_msec);
+ ret = sr_sw_limits_config_get(&devc->limits, key, data);
break;
case SR_CONF_SAMPLERATE:
*data = g_variant_new_uint64(devc->samplerate);
@@ -237,12 +201,8 @@ static int config_set(uint32_t key, GVariant *data,
ret = SR_OK;
switch (key) {
case SR_CONF_LIMIT_SAMPLES:
- devc->limit_samples = g_variant_get_uint64(data);
- devc->limit_msec = 0;
- break;
case SR_CONF_LIMIT_MSEC:
- devc->limit_msec = g_variant_get_uint64(data) * 1000;
- devc->limit_samples = 0;
+ ret = sr_sw_limits_config_set(&devc->limits, key, data);
break;
case SR_CONF_SAMPLERATE:
samplerate = g_variant_get_uint64(data);
@@ -348,7 +308,7 @@ static int dev_acquisition_open(const struct sr_dev_inst *sdi)
return 0;
}
-static int dev_acquisition_start(const struct sr_dev_inst *sdi, void *cb_data)
+static int dev_acquisition_start(const struct sr_dev_inst *sdi)
{
struct dev_context *devc;
struct itimerspec tspec = {
@@ -356,8 +316,6 @@ static int dev_acquisition_start(const struct sr_dev_inst *sdi, void *cb_data)
.it_value = { 0, 0 }
};
- (void)cb_data;
-
if (sdi->status != SR_ST_ACTIVE)
return SR_ERR_DEV_CLOSED;
@@ -365,7 +323,6 @@ static int dev_acquisition_start(const struct sr_dev_inst *sdi, void *cb_data)
return SR_ERR;
devc = sdi->priv;
- devc->samples_read = 0;
devc->samples_missed = 0;
devc->timer_fd = timerfd_create(CLOCK_MONOTONIC, 0);
if (devc->timer_fd < 0) {
@@ -391,20 +348,16 @@ static int dev_acquisition_start(const struct sr_dev_inst *sdi, void *cb_data)
sr_session_source_add_channel(sdi->session, devc->channel,
G_IO_IN | G_IO_ERR, 1000, bl_acme_receive_data, (void *)sdi);
- /* Send header packet to the session bus. */
- std_session_send_df_header(sdi, LOG_PREFIX);
- devc->start_time = g_get_monotonic_time();
+ std_session_send_df_header(sdi);
+ sr_sw_limits_acquisition_start(&devc->limits);
return SR_OK;
}
-static int dev_acquisition_stop(struct sr_dev_inst *sdi, void *cb_data)
+static int dev_acquisition_stop(struct sr_dev_inst *sdi)
{
- struct sr_datafeed_packet packet;
struct dev_context *devc;
- (void)cb_data;
-
devc = sdi->priv;
if (sdi->status != SR_ST_ACTIVE)
@@ -415,27 +368,23 @@ static int dev_acquisition_stop(struct sr_dev_inst *sdi, void *cb_data)
g_io_channel_shutdown(devc->channel, FALSE, NULL);
g_io_channel_unref(devc->channel);
devc->channel = NULL;
- close(devc->timer_fd);
- /* Send last packet. */
- packet.type = SR_DF_END;
- sr_session_send(sdi, &packet);
+ std_session_send_df_end(sdi);
if (devc->samples_missed > 0)
- sr_warn("%d samples missed", devc->samples_missed);
+ sr_warn("%" PRIu64 " samples missed", devc->samples_missed);
return SR_OK;
}
-SR_PRIV struct sr_dev_driver baylibre_acme_driver_info = {
+static struct sr_dev_driver baylibre_acme_driver_info = {
.name = "baylibre-acme",
.longname = "BayLibre ACME (Another Cute Measurement Equipment)",
.api_version = 1,
- .init = init,
- .cleanup = cleanup,
+ .init = std_init,
+ .cleanup = std_cleanup,
.scan = scan,
- .dev_list = dev_list,
- .dev_clear = dev_clear,
+ .dev_list = std_dev_list,
.config_get = config_get,
.config_set = config_set,
.config_list = config_list,
@@ -443,5 +392,6 @@ SR_PRIV struct sr_dev_driver baylibre_acme_driver_info = {
.dev_close = dev_close,
.dev_acquisition_start = dev_acquisition_start,
.dev_acquisition_stop = dev_acquisition_stop,
- .priv = NULL,
+ .context = NULL,
};
+SR_REGISTER_DEV_DRIVER(baylibre_acme_driver_info);