]> sigrok.org Git - libsigrok.git/blobdiff - hardware/chronovu-la8/chronovu-la8.c
sr: Made sample rate lists const
[libsigrok.git] / hardware / chronovu-la8 / chronovu-la8.c
index 60384a1d15affc822d6639e44ac6d581f086902d..ba543d890c872671da435cf4c607ead88301708d 100644 (file)
@@ -70,7 +70,7 @@ struct context {
        uint64_t limit_samples;
 
        /** TODO */
-       gpointer session_id;
+       void *session_dev_id;
 
        /**
         * A buffer containing some (mangled) samples from the device.
@@ -120,7 +120,7 @@ static uint64_t supported_samplerates[255 + 1] = { 0 };
  * Min: 1 sample per 0.01us -> sample time is 0.084s, samplerate 100MHz
  * Max: 1 sample per 2.55us -> sample time is 21.391s, samplerate 392.15kHz
  */
-static struct sr_samplerates samplerates = {
+static const struct sr_samplerates samplerates = {
        .low  = 0,
        .high = 0,
        .step = 0,
@@ -128,7 +128,7 @@ static struct sr_samplerates samplerates = {
 };
 
 /* Note: Continuous sampling is not supported by the hardware. */
-static int hwcaps[] = {
+static const int hwcaps[] = {
        SR_HWCAP_LOGIC_ANALYZER,
        SR_HWCAP_SAMPLERATE,
        SR_HWCAP_LIMIT_MSEC, /* TODO: Not yet implemented. */
@@ -138,7 +138,7 @@ static int hwcaps[] = {
 
 /* Function prototypes. */
 static int la8_close_usb_reset_sequencer(struct context *ctx);
-static int hw_dev_acquisition_stop(int dev_index, gpointer session_data);
+static int hw_dev_acquisition_stop(int dev_index, void *cb_data);
 static int la8_reset(struct context *ctx);
 
 static void fill_supported_samplerates_if_needed(void)
@@ -400,10 +400,10 @@ static int la8_reset(struct context *ctx)
        return SR_OK;
 }
 
-static int configure_probes(struct context *ctx, GSList *probes)
+static int configure_probes(struct context *ctx, const GSList *probes)
 {
-       struct sr_probe *probe;
-       GSList *l;
+       const struct sr_probe *probe;
+       const GSList *l;
        uint8_t probe_bit;
        char *tc;
 
@@ -479,7 +479,7 @@ static int hw_init(const char *devinfo)
        ctx->cur_samplerate = SR_MHZ(100); /* 100MHz == max. samplerate */
        ctx->limit_msec = 0;
        ctx->limit_samples = 0;
-       ctx->session_id = NULL;
+       ctx->session_dev_id = NULL;
        memset(ctx->mangled_buf, 0, BS);
        ctx->final_buf = NULL;
        ctx->trigger_pattern = 0x00; /* Value irrelevant, see trigger_mask. */
@@ -551,12 +551,12 @@ static int hw_dev_open(int dev_index)
 
        if (!(sdi = sr_dev_inst_get(dev_insts, dev_index))) {
                sr_err("la8: %s: sdi was NULL", __func__);
-               return SR_ERR; /* TODO: SR_ERR_ARG? */
+               return SR_ERR_BUG;
        }
 
        if (!(ctx = sdi->priv)) {
                sr_err("la8: %s: sdi->priv was NULL", __func__);
-               return SR_ERR; /* TODO: SR_ERR_ARG? */
+               return SR_ERR_BUG;
        }
 
        sr_dbg("la8: Opening LA8 device (%04x:%04x).", USB_VENDOR_ID,
@@ -633,12 +633,12 @@ static int hw_dev_close(int dev_index)
 
        if (!(sdi = sr_dev_inst_get(dev_insts, dev_index))) {
                sr_err("la8: %s: sdi was NULL", __func__);
-               return SR_ERR; /* TODO: SR_ERR_ARG? */
+               return SR_ERR_BUG;
        }
 
        if (!(ctx = sdi->priv)) {
                sr_err("la8: %s: sdi->priv was NULL", __func__);
-               return SR_ERR; /* TODO: SR_ERR_ARG? */
+               return SR_ERR_BUG;
        }
 
        sr_dbg("la8: Closing device.");
@@ -681,11 +681,11 @@ static int hw_cleanup(void)
        return ret;
 }
 
-static void *hw_dev_info_get(int dev_index, int dev_info_id)
+static const void *hw_dev_info_get(int dev_index, int dev_info_id)
 {
        struct sr_dev_inst *sdi;
        struct context *ctx;
-       void *info;
+       const void *info;
 
        if (!(sdi = sr_dev_inst_get(dev_insts, dev_index))) {
                sr_err("la8: %s: sdi was NULL", __func__);
@@ -753,58 +753,58 @@ static int hw_dev_status_get(int dev_index)
        return sdi->status;
 }
 
-static int *hw_hwcap_get_all(void)
+static const int *hw_hwcap_get_all(void)
 {
        sr_spew("la8: Returning list of device capabilities.");
 
        return hwcaps;
 }
 
-static int hw_dev_config_set(int dev_index, int hwcap, void *value)
+static int hw_dev_config_set(int dev_index, int hwcap, const void *value)
 {
        struct sr_dev_inst *sdi;
        struct context *ctx;
 
        if (!(sdi = sr_dev_inst_get(dev_insts, dev_index))) {
                sr_err("la8: %s: sdi was NULL", __func__);
-               return SR_ERR; /* TODO: SR_ERR_ARG? */
+               return SR_ERR_BUG;
        }
 
        if (!(ctx = sdi->priv)) {
                sr_err("la8: %s: sdi->priv was NULL", __func__);
-               return SR_ERR; /* TODO: SR_ERR_ARG? */
+               return SR_ERR_BUG;
        }
 
        sr_spew("la8: %s: dev_index %d, hwcap %d", __func__, dev_index, hwcap);
 
        switch (hwcap) {
        case SR_HWCAP_SAMPLERATE:
-               if (set_samplerate(sdi, *(uint64_t *)value) == SR_ERR) {
+               if (set_samplerate(sdi, *(const uint64_t *)value) == SR_ERR) {
                        sr_err("la8: %s: setting samplerate failed.", __func__);
                        return SR_ERR;
                }
                sr_dbg("la8: SAMPLERATE = %" PRIu64, ctx->cur_samplerate);
                break;
        case SR_HWCAP_PROBECONFIG:
-               if (configure_probes(ctx, (GSList *)value) != SR_OK) {
+               if (configure_probes(ctx, (const GSList *)value) != SR_OK) {
                        sr_err("la8: %s: probe config failed.", __func__);
                        return SR_ERR;
                }
                break;
        case SR_HWCAP_LIMIT_MSEC:
-               if (*(uint64_t *)value == 0) {
+               if (*(const uint64_t *)value == 0) {
                        sr_err("la8: %s: LIMIT_MSEC can't be 0.", __func__);
                        return SR_ERR;
                }
-               ctx->limit_msec = *(uint64_t *)value;
+               ctx->limit_msec = *(const uint64_t *)value;
                sr_dbg("la8: LIMIT_MSEC = %" PRIu64, ctx->limit_msec);
                break;
        case SR_HWCAP_LIMIT_SAMPLES:
-               if (*(uint64_t *)value < MIN_NUM_SAMPLES) {
+               if (*(const uint64_t *)value < MIN_NUM_SAMPLES) {
                        sr_err("la8: %s: LIMIT_SAMPLES too small.", __func__);
                        return SR_ERR;
                }
-               ctx->limit_samples = *(uint64_t *)value;
+               ctx->limit_samples = *(const uint64_t *)value;
                sr_dbg("la8: LIMIT_SAMPLES = %" PRIu64, ctx->limit_samples);
                break;
        default:
@@ -912,7 +912,7 @@ static void send_block_to_session_bus(struct context *ctx, int block)
                logic.length = BS;
                logic.unitsize = 1;
                logic.data = ctx->final_buf + (block * BS);
-               sr_session_bus(ctx->session_id, &packet);
+               sr_session_send(ctx->session_dev_id, &packet);
                return;
        }
 
@@ -935,7 +935,7 @@ static void send_block_to_session_bus(struct context *ctx, int block)
                logic.length = trigger_point;
                logic.unitsize = 1;
                logic.data = ctx->final_buf + (block * BS);
-               sr_session_bus(ctx->session_id, &packet);
+               sr_session_send(ctx->session_dev_id, &packet);
        }
 
        /* Send the SR_DF_TRIGGER packet to the session bus. */
@@ -943,7 +943,7 @@ static void send_block_to_session_bus(struct context *ctx, int block)
                (block * BS) + trigger_point);
        packet.type = SR_DF_TRIGGER;
        packet.payload = NULL;
-       sr_session_bus(ctx->session_id, &packet);
+       sr_session_send(ctx->session_dev_id, &packet);
 
        /* If at least one sample is located after the trigger... */
        if (trigger_point < (BS - 1)) {
@@ -956,11 +956,11 @@ static void send_block_to_session_bus(struct context *ctx, int block)
                logic.length = BS - trigger_point;
                logic.unitsize = 1;
                logic.data = ctx->final_buf + (block * BS) + trigger_point;
-               sr_session_bus(ctx->session_id, &packet);
+               sr_session_send(ctx->session_dev_id, &packet);
        }
 }
 
-static int receive_data(int fd, int revents, void *session_data)
+static int receive_data(int fd, int revents, void *cb_data)
 {
        int i, ret;
        struct sr_dev_inst *sdi;
@@ -970,8 +970,8 @@ static int receive_data(int fd, int revents, void *session_data)
        (void)fd;
        (void)revents;
 
-       if (!(sdi = session_data)) {
-               sr_err("la8: %s: session_data was NULL", __func__);
+       if (!(sdi = cb_data)) {
+               sr_err("la8: %s: cb_data was NULL", __func__);
                return FALSE;
        }
 
@@ -988,7 +988,7 @@ static int receive_data(int fd, int revents, void *session_data)
        /* Get one block of data. */
        if ((ret = la8_read_block(ctx)) < 0) {
                sr_err("la8: %s: la8_read_block error: %d", __func__, ret);
-               hw_dev_acquisition_stop(sdi->index, session_data);
+               hw_dev_acquisition_stop(sdi->index, sdi);
                return FALSE;
        }
 
@@ -1004,34 +1004,35 @@ static int receive_data(int fd, int revents, void *session_data)
        for (i = 0; i < NUM_BLOCKS; i++)
                send_block_to_session_bus(ctx, i);
 
-       hw_dev_acquisition_stop(sdi->index, session_data);
+       hw_dev_acquisition_stop(sdi->index, sdi);
 
        // return FALSE; /* FIXME? */
        return TRUE;
 }
 
-static int hw_dev_acquisition_start(int dev_index, gpointer session_data)
+static int hw_dev_acquisition_start(int dev_index, void *cb_data)
 {
        struct sr_dev_inst *sdi;
        struct context *ctx;
        struct sr_datafeed_packet packet;
        struct sr_datafeed_header header;
+       struct sr_datafeed_meta_logic meta;
        uint8_t buf[4];
        int bytes_written;
 
        if (!(sdi = sr_dev_inst_get(dev_insts, dev_index))) {
                sr_err("la8: %s: sdi was NULL", __func__);
-               return SR_ERR; /* TODO: SR_ERR_ARG? */
+               return SR_ERR_BUG;
        }
 
        if (!(ctx = sdi->priv)) {
                sr_err("la8: %s: sdi->priv was NULL", __func__);
-               return SR_ERR; /* TODO: SR_ERR_ARG? */
+               return SR_ERR_BUG;
        }
 
        if (!ctx->ftdic) {
                sr_err("la8: %s: ctx->ftdic was NULL", __func__);
-               return SR_ERR_ARG;
+               return SR_ERR_BUG;
        }
 
        ctx->divcount = samplerate_to_divcount(ctx->cur_samplerate);
@@ -1061,7 +1062,7 @@ static int hw_dev_acquisition_start(int dev_index, gpointer session_data)
 
        sr_dbg("la8: Acquisition started successfully.");
 
-       ctx->session_id = session_data;
+       ctx->session_dev_id = cb_data;
 
        /* Send header packet to the session bus. */
        sr_dbg("la8: Sending SR_DF_HEADER.");
@@ -1069,9 +1070,14 @@ static int hw_dev_acquisition_start(int dev_index, gpointer session_data)
        packet.payload = &header;
        header.feed_version = 1;
        gettimeofday(&header.starttime, NULL);
-       header.samplerate = ctx->cur_samplerate;
-       header.num_logic_probes = NUM_PROBES;
-       sr_session_bus(session_data, &packet);
+       sr_session_send(ctx->session_dev_id, &packet);
+
+       /* Send metadata about the SR_DF_LOGIC packets to come. */
+       packet.type = SR_DF_META_LOGIC;
+       packet.payload = &meta;
+       meta.samplerate = ctx->cur_samplerate;
+       meta.num_probes = NUM_PROBES;
+       sr_session_send(ctx->session_dev_id, &packet);
 
        /* Time when we should be done (for detecting trigger timeouts). */
        ctx->done = (ctx->divcount + 1) * 0.08388608 + time(NULL)
@@ -1085,7 +1091,7 @@ static int hw_dev_acquisition_start(int dev_index, gpointer session_data)
        return SR_OK;
 }
 
-static int hw_dev_acquisition_stop(int dev_index, gpointer session_data)
+static int hw_dev_acquisition_stop(int dev_index, void *cb_data)
 {
        struct sr_dev_inst *sdi;
        struct context *ctx;
@@ -1106,12 +1112,12 @@ static int hw_dev_acquisition_stop(int dev_index, gpointer session_data)
        /* Send end packet to the session bus. */
        sr_dbg("la8: Sending SR_DF_END.");
        packet.type = SR_DF_END;
-       sr_session_bus(session_data, &packet);
+       sr_session_send(cb_data, &packet);
 
        return SR_OK;
 }
 
-SR_PRIV struct sr_dev_plugin chronovu_la8_plugin_info = {
+SR_PRIV struct sr_dev_driver chronovu_la8_driver_info = {
        .name = "chronovu-la8",
        .longname = "ChronoVu LA8",
        .api_version = 1,