X-Git-Url: https://sigrok.org/gitweb/?a=blobdiff_plain;ds=sidebyside;f=src%2Fhardware%2Fbaylibre-acme%2Fapi.c;h=cdf9968b20b94ad33217ebfa1c6f8ff93849d8be;hb=88a0265ebcb265ba839c02cc5bcd39e359c9f60f;hp=6827a16bfe5da763756f34318856411f0f220ee8;hpb=7c91c22a31a5017117116fa1fe6c2addbac813f1;p=libsigrok.git
diff --git a/src/hardware/baylibre-acme/api.c b/src/hardware/baylibre-acme/api.c
index 6827a16b..cdf9968b 100644
--- a/src/hardware/baylibre-acme/api.c
+++ b/src/hardware/baylibre-acme/api.c
@@ -17,7 +17,10 @@
* along with this program. If not, see .
*/
+#include
#include "protocol.h"
+#include
+#include
SR_PRIV struct sr_dev_driver baylibre_acme_driver_info;
@@ -66,7 +69,7 @@ static GSList *scan(struct sr_dev_driver *di, GSList *options)
(void)options;
- drvc = di->priv;
+ drvc = di->context;
devices = NULL;
devc = g_malloc0(sizeof(struct dev_context));
@@ -141,19 +144,13 @@ err_out:
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);
+ return ((struct drv_context *)(di->context))->instances;
}
static int dev_open(struct sr_dev_inst *sdi)
{
(void)sdi;
- /* Nothing to do here. */
sdi->status = SR_ST_ACTIVE;
return SR_OK;
@@ -163,19 +160,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)
@@ -318,58 +307,100 @@ static int config_list(uint32_t key, GVariant **data,
return ret;
}
-static int dev_acquisition_start(const struct sr_dev_inst *sdi, void *cb_data)
+static void dev_acquisition_close(const struct sr_dev_inst *sdi)
{
- struct dev_context *devc;
+ GSList *chl;
+ struct sr_channel *ch;
- (void)cb_data;
+ for (chl = sdi->channels; chl; chl = chl->next) {
+ ch = chl->data;
+ bl_acme_close_channel(ch);
+ }
+}
+
+static int dev_acquisition_open(const struct sr_dev_inst *sdi)
+{
+ GSList *chl;
+ struct sr_channel *ch;
+
+ for (chl = sdi->channels; chl; chl = chl->next) {
+ ch = chl->data;
+ if (bl_acme_open_channel(ch)) {
+ sr_err("Error opening channel %s", ch->name);
+ dev_acquisition_close(sdi);
+ return SR_ERR;
+ }
+ }
+
+ return 0;
+}
+
+static int dev_acquisition_start(const struct sr_dev_inst *sdi)
+{
+ struct dev_context *devc;
+ struct itimerspec tspec = {
+ .it_interval = { 0, 0 },
+ .it_value = { 0, 0 }
+ };
if (sdi->status != SR_ST_ACTIVE)
return SR_ERR_DEV_CLOSED;
+ if (dev_acquisition_open(sdi))
+ 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) {
+ sr_err("Error creating timer fd");
+ return SR_ERR;
+ }
- if (pipe(devc->pipe_fds)) {
- sr_err("Error setting up pipe");
+ tspec.it_interval.tv_sec = 0;
+ tspec.it_interval.tv_nsec = SR_HZ_TO_NS(devc->samplerate);
+ tspec.it_value = tspec.it_interval;
+
+ if (timerfd_settime(devc->timer_fd, 0, &tspec, NULL)) {
+ sr_err("Failed to set timer");
+ close(devc->timer_fd);
return SR_ERR;
}
- devc->channel = g_io_channel_unix_new(devc->pipe_fds[0]);
+ devc->channel = g_io_channel_unix_new(devc->timer_fd);
g_io_channel_set_flags(devc->channel, G_IO_FLAG_NONBLOCK, NULL);
g_io_channel_set_encoding(devc->channel, NULL, NULL);
g_io_channel_set_buffered(devc->channel, FALSE);
sr_session_source_add_channel(sdi->session, devc->channel,
- G_IO_IN | G_IO_ERR, 1, bl_acme_receive_data, (void *)sdi);
+ 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();
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)
return SR_ERR_DEV_CLOSED;
+ dev_acquisition_close(sdi);
sr_session_source_remove_channel(sdi->session, devc->channel);
g_io_channel_shutdown(devc->channel, FALSE, NULL);
g_io_channel_unref(devc->channel);
devc->channel = NULL;
- /* Send last packet. */
- packet.type = SR_DF_END;
- sr_session_send(sdi, &packet);
+ std_session_send_df_end(sdi, LOG_PREFIX);
+
+ if (devc->samples_missed > 0)
+ sr_warn("%" PRIu64 " samples missed", devc->samples_missed);
return SR_OK;
}
@@ -379,10 +410,9 @@ SR_PRIV struct sr_dev_driver baylibre_acme_driver_info = {
.longname = "BayLibre ACME (Another Cute Measurement Equipment)",
.api_version = 1,
.init = init,
- .cleanup = cleanup,
+ .cleanup = std_cleanup,
.scan = scan,
.dev_list = dev_list,
- .dev_clear = dev_clear,
.config_get = config_get,
.config_set = config_set,
.config_list = config_list,
@@ -390,5 +420,5 @@ 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,
};