X-Git-Url: https://sigrok.org/gitweb/?a=blobdiff_plain;f=src%2Fhardware%2Fbeaglelogic%2Fapi.c;h=cba429cacdd4966a928a07818632130ac2448143;hb=88a0265ebcb265ba839c02cc5bcd39e359c9f60f;hp=74795caf42dee540e2be1d7606f3bbd1fa58861d;hpb=dcd438ee3523098201c7937e75e55775da3b506f;p=libsigrok.git diff --git a/src/hardware/beaglelogic/api.c b/src/hardware/beaglelogic/api.c index 74795caf..cba429ca 100644 --- a/src/hardware/beaglelogic/api.c +++ b/src/hardware/beaglelogic/api.c @@ -17,6 +17,7 @@ * along with this program. If not, see . */ +#include #include "protocol.h" #include "beaglelogic.h" @@ -47,10 +48,9 @@ static const int32_t soft_trigger_matches[] = { SR_TRIGGER_EDGE, }; -/* Channels are numbered 0-13 */ -SR_PRIV const char *beaglelogic_channel_names[] = { - "P8_45", "P8_46", "P8_43", "P8_44", "P8_41", "P8_42", "P8_39", "P8_40", - "P8_27", "P8_29", "P8_28", "P8_30", "P8_21", "P8_20", NULL, +SR_PRIV const char *channel_names[] = { + "P8_45", "P8_46", "P8_43", "P8_44", "P8_41", "P8_42", "P8_39", + "P8_40", "P8_27", "P8_29", "P8_28", "P8_30", "P8_21", "P8_20", }; /* Possible sample rates : 10 Hz to 100 MHz = (100 / x) MHz */ @@ -88,7 +88,7 @@ static GSList *scan(struct sr_dev_driver *di, GSList *options) int i, maxch; devices = NULL; - drvc = di->priv; + drvc = di->context; drvc->instances = NULL; /* Probe for /dev/beaglelogic */ @@ -136,7 +136,7 @@ static GSList *scan(struct sr_dev_driver *di, GSList *options) /* Fill the channels */ for (i = 0; i < maxch; i++) sr_channel_new(sdi, i, SR_CHANNEL_LOGIC, TRUE, - beaglelogic_channel_names[i]); + channel_names[i]); sdi->priv = devc; drvc->instances = g_slist_append(drvc->instances, sdi); @@ -147,12 +147,7 @@ static GSList *scan(struct sr_dev_driver *di, GSList *options) 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) @@ -166,6 +161,7 @@ static int dev_open(struct sr_dev_inst *sdi) /* Set fd and local attributes */ devc->pollfd.fd = devc->fd; devc->pollfd.events = G_IO_IN; + devc->pollfd.revents = 0; /* Get the default attributes */ beaglelogic_get_samplerate(devc); @@ -199,29 +195,6 @@ static int dev_close(struct sr_dev_inst *sdi) return SR_OK; } -static int cleanup(const struct sr_dev_driver *di) -{ - struct drv_context *drvc; - struct sr_dev_inst *sdi; - GSList *l; - - /* unused driver */ - if (!(drvc = di->priv)) - return SR_OK; - - /* Clean up the instances */ - for (l = drvc->instances; l; l = l->next) { - sdi = l->data; - di->dev_close(sdi); - g_free(sdi->priv); - sr_dev_inst_free(sdi); - } - g_slist_free(drvc->instances); - drvc->instances = NULL; - - return SR_OK; -} - static int config_get(uint32_t key, GVariant **data, const struct sr_dev_inst *sdi, const struct sr_channel_group *cg) { @@ -283,10 +256,8 @@ static int config_set(uint32_t key, GVariant *data, const struct sr_dev_inst *sd return beaglelogic_set_triggerflags(devc); case SR_CONF_CAPTURE_RATIO: devc->capture_ratio = g_variant_get_uint64(data); - if (devc->capture_ratio > 100) { - devc->capture_ratio = 0; + if (devc->capture_ratio > 100) return SR_ERR; - } return SR_OK; default: return SR_ERR_NA; @@ -338,19 +309,14 @@ static int config_list(uint32_t key, GVariant **data, const struct sr_dev_inst * #define BUFUNIT_TIMEOUT_MS(devc) (100 + ((devc->bufunitsize * 1000) / \ (uint32_t)(devc->cur_samplerate))) -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) { - (void)cb_data; struct dev_context *devc = sdi->priv; struct sr_trigger *trigger; if (sdi->status != SR_ST_ACTIVE) return SR_ERR_DEV_CLOSED; - /* Save user pointer */ - devc->cb_data = cb_data; - /* Clear capture state */ devc->bytes_read = 0; devc->offset = 0; @@ -366,12 +332,12 @@ static int dev_acquisition_start(const struct sr_dev_inst *sdi, if (devc->limit_samples > 0) pre_trigger_samples = devc->capture_ratio * devc->limit_samples/100; devc->stl = soft_trigger_logic_new(sdi, trigger, pre_trigger_samples); - if (devc->stl == NULL) + if (!devc->stl) return SR_ERR_MALLOC; devc->trigger_fired = FALSE; } else devc->trigger_fired = TRUE; - std_session_send_df_header(cb_data, LOG_PREFIX); + std_session_send_df_header(sdi, LOG_PREFIX); /* Trigger and add poll on file */ beaglelogic_start(devc); @@ -382,12 +348,9 @@ static int dev_acquisition_start(const struct sr_dev_inst *sdi, 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 dev_context *devc = sdi->priv; - struct sr_datafeed_packet pkt; - - (void)cb_data; if (sdi->status != SR_ST_ACTIVE) return SR_ERR_DEV_CLOSED; @@ -400,9 +363,7 @@ static int dev_acquisition_stop(struct sr_dev_inst *sdi, void *cb_data) /* Remove session source and send EOT packet */ sr_session_source_remove_pollfd(sdi->session, &devc->pollfd); - pkt.type = SR_DF_END; - pkt.payload = NULL; - sr_session_send(sdi, &pkt); + std_session_send_df_end(sdi, LOG_PREFIX); return SR_OK; } @@ -412,10 +373,9 @@ SR_PRIV struct sr_dev_driver beaglelogic_driver_info = { .longname = "BeagleLogic", .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, @@ -423,5 +383,5 @@ SR_PRIV struct sr_dev_driver beaglelogic_driver_info = { .dev_close = dev_close, .dev_acquisition_start = dev_acquisition_start, .dev_acquisition_stop = dev_acquisition_stop, - .priv = NULL, + .context = NULL, };