X-Git-Url: http://sigrok.org/gitweb/?a=blobdiff_plain;f=hardware%2Fchronovu-la8%2Fapi.c;h=2dd12e3bf05411900c121ca760e7d25ccca35417;hb=7b78b2f78fbd8309fd9898c4940b82328a2c39af;hp=4c349e5786f68554d2f855a5fa71d46e2ce39dff;hpb=123e13138385055003cb6bc09e74df783df5af85;p=libsigrok.git diff --git a/hardware/chronovu-la8/api.c b/hardware/chronovu-la8/api.c index 4c349e57..2dd12e3b 100644 --- a/hardware/chronovu-la8/api.c +++ b/hardware/chronovu-la8/api.c @@ -70,17 +70,7 @@ static int clear_instances(void) static int hw_init(struct sr_context *sr_ctx) { - struct drv_context *drvc; - - if (!(drvc = g_try_malloc0(sizeof(struct drv_context)))) { - sr_err("Driver context malloc failed."); - return SR_ERR_MALLOC; - } - - drvc->sr_ctx = sr_ctx; - di->priv = drvc; - - return SR_OK; + return std_hw_init(sr_ctx, di, DRIVER_LOG_DOMAIN); } static GSList *hw_scan(GSList *options) @@ -96,6 +86,7 @@ static GSList *hw_scan(GSList *options) (void)options; drvc = di->priv; + devices = NULL; /* Allocate memory for our private device context. */ @@ -109,7 +100,7 @@ static GSList *hw_scan(GSList *options) devc->cur_samplerate = SR_MHZ(100); /* 100MHz == max. samplerate */ devc->limit_msec = 0; devc->limit_samples = 0; - devc->session_dev_id = NULL; + devc->cb_data = NULL; memset(devc->mangled_buf, 0, BS); devc->final_buf = NULL; devc->trigger_pattern = 0x00; /* Value irrelevant, see trigger_mask. */ @@ -169,8 +160,6 @@ static GSList *hw_scan(GSList *options) devices = g_slist_append(devices, sdi); drvc->instances = g_slist_append(drvc->instances, sdi); - sr_spew("Device init successful."); - /* Close device. We'll reopen it again when we need it. */ (void) la8_close(devc); /* Log, but ignore errors. */ @@ -191,11 +180,7 @@ err_free_nothing: static GSList *hw_dev_list(void) { - struct drv_context *drvc; - - drvc = di->priv; - - return drvc->instances; + return ((struct drv_context *)(di->priv))->instances; } static int hw_dev_open(struct sr_dev_inst *sdi) @@ -255,12 +240,7 @@ static int hw_dev_close(struct sr_dev_inst *sdi) { struct dev_context *devc; - if (!(devc = sdi->priv)) { - sr_err("%s: sdi->priv was NULL.", __func__); - return SR_ERR_BUG; - } - - sr_dbg("Closing device."); + devc = sdi->priv; if (sdi->status == SR_ST_ACTIVE) { sr_dbg("Status ACTIVE, closing device."); @@ -271,7 +251,6 @@ static int hw_dev_close(struct sr_dev_inst *sdi) sdi->status = SR_ST_INACTIVE; - sr_dbg("Freeing sample buffer."); g_free(devc->final_buf); return SR_OK; @@ -293,14 +272,6 @@ static int config_get(int id, const void **data, const struct sr_dev_inst *sdi) struct dev_context *devc; switch (id) { - case SR_DI_HWCAPS: - *data = hwcaps; - break; - case SR_DI_TRIGGER_TYPES: - *data = (char *)TRIGGER_TYPES; - sr_spew("%s: Returning trigger types: %s.", __func__, - TRIGGER_TYPES); - break; case SR_CONF_SAMPLERATE: if (sdi) { devc = sdi->priv; @@ -366,10 +337,16 @@ static int config_list(int key, const void **data, const struct sr_dev_inst *sdi (void)sdi; switch (key) { + case SR_CONF_DEVICE_OPTIONS: + *data = hwcaps; + break; case SR_CONF_SAMPLERATE: fill_supported_samplerates_if_needed(); *data = &samplerates; break; + case SR_CONF_TRIGGER_TYPE: + *data = (char *)TRIGGER_TYPE; + break; default: return SR_ERR_ARG; } @@ -429,8 +406,6 @@ static int hw_dev_acquisition_start(const struct sr_dev_inst *sdi, void *cb_data) { struct dev_context *devc; - struct sr_datafeed_packet packet; - struct sr_datafeed_header header; uint8_t buf[4]; int bytes_written; @@ -455,8 +430,6 @@ static int hw_dev_acquisition_start(const struct sr_dev_inst *sdi, return SR_ERR; } - sr_dbg("Starting acquisition."); - /* Fill acquisition parameters into buf[]. */ buf[0] = devc->divcount; buf[1] = 0xff; /* This byte must always be 0xff. */ @@ -474,17 +447,12 @@ static int hw_dev_acquisition_start(const struct sr_dev_inst *sdi, return SR_ERR; } - sr_dbg("Acquisition started successfully."); + sr_dbg("Hardware acquisition started successfully."); - devc->session_dev_id = cb_data; + devc->cb_data = cb_data; /* Send header packet to the session bus. */ - sr_dbg("Sending SR_DF_HEADER."); - packet.type = SR_DF_HEADER; - packet.payload = &header; - header.feed_version = 1; - gettimeofday(&header.starttime, NULL); - sr_session_send(devc->session_dev_id, &packet); + std_session_send_df_header(cb_data, DRIVER_LOG_DOMAIN); /* Time when we should be done (for detecting trigger timeouts). */ devc->done = (devc->divcount + 1) * 0.08388608 + time(NULL)