X-Git-Url: https://sigrok.org/gitweb/?a=blobdiff_plain;f=src%2Fhardware%2Fbeaglelogic%2Fapi.c;h=ff8f0424d32049c834a365fe8eefa03c0e4dfe48;hb=f1ba6b4b2c9a8ecf90bb31efb218752aa7e49d1a;hp=e6668ae637e804c2f42667e30d2b21ef7ed5097a;hpb=5e23fcab889c62864b92aa3ad6902ce3e9f5be49;p=libsigrok.git diff --git a/src/hardware/beaglelogic/api.c b/src/hardware/beaglelogic/api.c index e6668ae6..ff8f0424 100644 --- a/src/hardware/beaglelogic/api.c +++ b/src/hardware/beaglelogic/api.c @@ -17,12 +17,10 @@ * along with this program. If not, see . */ +#include #include "protocol.h" #include "beaglelogic.h" -SR_PRIV struct sr_dev_driver beaglelogic_driver_info; -static struct sr_dev_driver *di = &beaglelogic_driver_info; - /* Scan options */ static const uint32_t scanopts[] = { SR_CONF_NUM_LOGIC_CHANNELS, @@ -48,10 +46,9 @@ static const int32_t soft_trigger_matches[] = { SR_TRIGGER_EDGE, }; -/* Channels are numbered 0-13 */ -SR_PRIV const char *beaglelogic_channel_names[NUM_CHANNELS + 1] = { - "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 */ @@ -61,11 +58,6 @@ static const uint64_t samplerates[] = { SR_HZ(1), }; -static int init(struct sr_context *sr_ctx) -{ - return std_init(sr_ctx, di, LOG_PREFIX); -} - static struct dev_context *beaglelogic_devc_alloc(void) { struct dev_context *devc; @@ -79,19 +71,14 @@ static struct dev_context *beaglelogic_devc_alloc(void) return devc; } -static GSList *scan(GSList *options) +static GSList *scan(struct sr_dev_driver *di, GSList *options) { - struct drv_context *drvc; - GSList *devices, *l; + GSList *l; struct sr_config *src; struct sr_dev_inst *sdi; struct dev_context *devc; int i, maxch; - devices = NULL; - drvc = di->priv; - drvc->instances = NULL; - /* Probe for /dev/beaglelogic */ if (!g_file_test(BEAGLELOGIC_DEV_NODE, G_FILE_TEST_EXISTS)) return NULL; @@ -100,7 +87,6 @@ static GSList *scan(GSList *options) sdi->status = SR_ST_INACTIVE; sdi->model = g_strdup("BeagleLogic"); sdi->version = g_strdup("1.0"); - sdi->driver = di; /* Unless explicitly specified, keep max channels to 8 only */ maxch = 8; @@ -137,23 +123,11 @@ static GSList *scan(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); - devices = g_slist_append(devices, sdi); - - return devices; -} - -static GSList *dev_list(void) -{ - return ((struct drv_context *)(di->priv))->instances; -} -static int dev_clear(void) -{ - return std_dev_clear(di, NULL); + return std_scan_complete(di, g_slist_append(NULL, sdi)); } static int dev_open(struct sr_dev_inst *sdi) @@ -167,6 +141,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); @@ -182,8 +157,6 @@ static int dev_open(struct sr_dev_inst *sdi) return SR_ERR; } - /* We're good to go now */ - sdi->status = SR_ST_ACTIVE; return SR_OK; } @@ -191,36 +164,9 @@ static int dev_close(struct sr_dev_inst *sdi) { struct dev_context *devc = sdi->priv; - if (sdi->status == SR_ST_ACTIVE) { - /* Close the memory mapping and the file */ - beaglelogic_munmap(devc); - beaglelogic_close(devc); - } - sdi->status = SR_ST_INACTIVE; - return SR_OK; -} - -static int cleanup(void) -{ - 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; - - di->priv = NULL; + /* Close the memory mapping and the file */ + beaglelogic_munmap(devc); + beaglelogic_close(devc); return SR_OK; } @@ -229,25 +175,22 @@ static int config_get(uint32_t key, GVariant **data, const struct sr_dev_inst *s const struct sr_channel_group *cg) { struct dev_context *devc = sdi->priv; + (void)cg; switch (key) { case SR_CONF_LIMIT_SAMPLES: *data = g_variant_new_uint64(devc->limit_samples); break; - case SR_CONF_SAMPLERATE: *data = g_variant_new_uint64(devc->cur_samplerate); break; - case SR_CONF_CAPTURE_RATIO: *data = g_variant_new_uint64(devc->capture_ratio); break; - case SR_CONF_NUM_LOGIC_CHANNELS: *data = g_variant_new_uint32(g_slist_length(sdi->channels)); break; - default: return SR_ERR_NA; } @@ -260,16 +203,13 @@ static int config_set(uint32_t key, GVariant *data, const struct sr_dev_inst *sd { struct dev_context *devc = sdi->priv; uint64_t tmp_u64; - (void)cg; - if (sdi->status != SR_ST_ACTIVE) - return SR_ERR_DEV_CLOSED; + (void)cg; switch (key) { case SR_CONF_SAMPLERATE: devc->cur_samplerate = g_variant_get_uint64(data); return beaglelogic_set_samplerate(devc); - case SR_CONF_LIMIT_SAMPLES: tmp_u64 = g_variant_get_uint64(data); devc->limit_samples = tmp_u64; @@ -287,15 +227,11 @@ static int config_set(uint32_t key, GVariant *data, const struct sr_dev_inst *sd (SAMPLEUNIT_TO_BYTES(devc->sampleunit) * 1000000)); } 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; } @@ -311,7 +247,6 @@ static int config_list(uint32_t key, GVariant **data, const struct sr_dev_inst * GVariantBuilder gvb; (void)sdi; - (void)data; (void)cg; ret = SR_OK; @@ -347,19 +282,11 @@ 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; @@ -375,12 +302,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); /* Trigger and add poll on file */ beaglelogic_start(devc); @@ -391,15 +318,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; /* Execute a stop on BeagleLogic */ beaglelogic_stop(devc); @@ -409,22 +330,19 @@ 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); return SR_OK; } -SR_PRIV struct sr_dev_driver beaglelogic_driver_info = { +static struct sr_dev_driver beaglelogic_driver_info = { .name = "beaglelogic", .longname = "BeagleLogic", .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, @@ -432,5 +350,6 @@ 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, }; +SR_REGISTER_DEV_DRIVER(beaglelogic_driver_info);