X-Git-Url: http://sigrok.org/gitweb/?a=blobdiff_plain;f=hardware%2Flink-mso19%2Fapi.c;h=a657e27008b398a4a61331962bb8ebffe72b4d33;hb=a68bf88e3a6ba0184f1d6aea4ce26b9a2950a513;hp=cbf70986a198c71f41e4f97a224de90a18bc5871;hpb=e73ffd4238c6d1be58d3fcdcf7f100200f033856;p=libsigrok.git diff --git a/hardware/link-mso19/api.c b/hardware/link-mso19/api.c index cbf70986..a657e270 100644 --- a/hardware/link-mso19/api.c +++ b/hardware/link-mso19/api.c @@ -51,12 +51,48 @@ static const uint64_t samplerates[] = { SR_PRIV struct sr_dev_driver link_mso19_driver_info; static struct sr_dev_driver *di = &link_mso19_driver_info; -static int hw_init(struct sr_context *sr_ctx) +/* TODO: Use sr_dev_inst to store connection handle & use std_dev_clear(). */ +static int dev_clear(void) { - return std_hw_init(sr_ctx, di, DRIVER_LOG_DOMAIN); + GSList *l; + struct sr_dev_inst *sdi; + struct drv_context *drvc; + struct dev_context *devc; + int ret = SR_OK; + + if (!(drvc = di->priv)) + return SR_OK; + + /* Properly close and free all devices. */ + for (l = drvc->instances; l; l = l->next) { + if (!(sdi = l->data)) { + /* Log error, but continue cleaning up the rest. */ + sr_err("%s: sdi was NULL, continuing", __func__); + ret = SR_ERR_BUG; + continue; + } + if (!(devc = sdi->priv)) { + /* Log error, but continue cleaning up the rest. */ + sr_err("%s: sdi->priv was NULL, continuing", __func__); + ret = SR_ERR_BUG; + continue; + } + std_serial_dev_close(sdi); + sr_serial_dev_inst_free(devc->serial); + sr_dev_inst_free(sdi); + } + g_slist_free(drvc->instances); + drvc->instances = NULL; + + return ret; +} + +static int init(struct sr_context *sr_ctx) +{ + return std_init(sr_ctx, di, LOG_PREFIX); } -static GSList *hw_scan(GSList *options) +static GSList *scan(GSList *options) { int i; GSList *devices = NULL; @@ -67,8 +103,6 @@ static GSList *hw_scan(GSList *options) struct udev *udev; int ptype; - (void)options; - for (l = options; l; l = l->next) { src = l->data; switch (src->key) { @@ -76,7 +110,7 @@ static GSList *hw_scan(GSList *options) conn = g_variant_get_string(src->data, NULL); break; case SR_CONF_SERIALCOMM: - serialcomm = g_variant_get_string(src->data, NULL); + serialcomm = g_variant_get_string(src->data, NULL); break; } } @@ -200,12 +234,12 @@ static GSList *hw_scan(GSList *options) return devices; } -static GSList *hw_dev_list(void) +static GSList *dev_list(void) { return ((struct drv_context *)(di->priv))->instances; } -static int hw_dev_open(struct sr_dev_inst *sdi) +static int dev_open(struct sr_dev_inst *sdi) { int ret; struct dev_context *devc; @@ -236,58 +270,17 @@ static int hw_dev_open(struct sr_dev_inst *sdi) return SR_OK; } -static int hw_dev_close(struct sr_dev_inst *sdi) +static int cleanup(void) { - struct dev_context *devc; - - devc = sdi->priv; - - if (devc->serial && devc->serial->fd != -1) { - serial_close(devc->serial); - sdi->status = SR_ST_INACTIVE; - } - - return SR_OK; + return dev_clear(); } -static int hw_cleanup(void) +static int config_get(int id, GVariant **data, const struct sr_dev_inst *sdi, + const struct sr_channel_group *channel_group) { - GSList *l; - struct sr_dev_inst *sdi; - struct drv_context *drvc; struct dev_context *devc; - int ret = SR_OK; - if (!(drvc = di->priv)) - return SR_OK; - - /* Properly close and free all devices. */ - for (l = drvc->instances; l; l = l->next) { - if (!(sdi = l->data)) { - /* Log error, but continue cleaning up the rest. */ - sr_err("%s: sdi was NULL, continuing", __func__); - ret = SR_ERR_BUG; - continue; - } - if (!(devc = sdi->priv)) { - /* Log error, but continue cleaning up the rest. */ - sr_err("%s: sdi->priv was NULL, continuing", __func__); - ret = SR_ERR_BUG; - continue; - } - hw_dev_close(sdi); - sr_serial_dev_inst_free(devc->serial); - sr_dev_inst_free(sdi); - } - g_slist_free(drvc->instances); - drvc->instances = NULL; - - return ret; -} - -static int config_get(int id, GVariant **data, const struct sr_dev_inst *sdi) -{ - struct dev_context *devc; + (void)channel_group; switch (id) { case SR_CONF_SAMPLERATE: @@ -304,14 +297,17 @@ static int config_get(int id, GVariant **data, const struct sr_dev_inst *sdi) return SR_OK; } -static int config_set(int id, GVariant *data, const struct sr_dev_inst *sdi) +static int config_set(int id, GVariant *data, const struct sr_dev_inst *sdi, + const struct sr_channel_group *channel_group) { int ret; struct dev_context *devc; - uint64_t num_samples, slope; + uint64_t num_samples; + const char *slope; int trigger_pos; double pos; + (void)channel_group; devc = sdi->priv; if (sdi->status != SR_ST_ACTIVE) @@ -339,12 +335,14 @@ static int config_set(int id, GVariant *data, const struct sr_dev_inst *sdi) ret = SR_OK; break; case SR_CONF_TRIGGER_SLOPE: - slope = g_variant_get_uint64(data); - if (slope != SLOPE_NEGATIVE && slope != SLOPE_POSITIVE) { + slope = g_variant_get_string(data, NULL); + + if (!slope || !(slope[0] == 'f' || slope[0] == 'r')) sr_err("Invalid trigger slope"); ret = SR_ERR_ARG; } else { - devc->trigger_slope = slope; + devc->trigger_slope = (slope[0] == 'r') + ? SLOPE_POSITIVE : SLOPE_NEGATIVE; ret = SR_OK; } break; @@ -370,11 +368,13 @@ static int config_set(int id, GVariant *data, const struct sr_dev_inst *sdi) return ret; } -static int config_list(int key, GVariant **data, const struct sr_dev_inst *sdi) +static int config_list(int key, GVariant **data, const struct sr_dev_inst *sdi, + const struct sr_channel_group *channel_group) { GVariant *gvar; GVariantBuilder gvb; + (void)channel_group; (void)sdi; switch (key) { @@ -399,8 +399,7 @@ static int config_list(int key, GVariant **data, const struct sr_dev_inst *sdi) return SR_OK; } -static int hw_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; int ret = SR_ERR; @@ -456,18 +455,18 @@ static int hw_dev_acquisition_start(const struct sr_dev_inst *sdi, devc->trigger_state = 0x00; /* Send header packet to the session bus. */ - std_session_send_df_header(cb_data, DRIVER_LOG_DOMAIN); + std_session_send_df_header(cb_data, LOG_PREFIX); /* Our first probe is analog, the other 8 are of type 'logic'. */ /* TODO. */ - sr_source_add(devc->serial->fd, G_IO_IN, -1, mso_receive_data, cb_data); + serial_source_add(devc->serial, G_IO_IN, -1, mso_receive_data, cb_data); return SR_OK; } /* This stops acquisition on ALL devices, ignoring dev_index. */ -static int hw_dev_acquisition_stop(struct sr_dev_inst *sdi, void *cb_data) +static int dev_acquisition_stop(struct sr_dev_inst *sdi, void *cb_data) { (void)cb_data; @@ -480,17 +479,17 @@ SR_PRIV struct sr_dev_driver link_mso19_driver_info = { .name = "link-mso19", .longname = "Link Instruments MSO-19", .api_version = 1, - .init = hw_init, - .cleanup = hw_cleanup, - .scan = hw_scan, - .dev_list = hw_dev_list, - .dev_clear = hw_cleanup, + .init = init, + .cleanup = cleanup, + .scan = scan, + .dev_list = dev_list, + .dev_clear = dev_clear, .config_get = config_get, .config_set = config_set, .config_list = config_list, - .dev_open = hw_dev_open, - .dev_close = hw_dev_close, - .dev_acquisition_start = hw_dev_acquisition_start, - .dev_acquisition_stop = hw_dev_acquisition_stop, + .dev_open = dev_open, + .dev_close = std_serial_dev_close, + .dev_acquisition_start = dev_acquisition_start, + .dev_acquisition_stop = dev_acquisition_stop, .priv = NULL, };