]> sigrok.org Git - libsigrok.git/blobdiff - hardware/openbench-logic-sniffer/ols.c
Use g_try_malloc/g_free/g_strdup consistently.
[libsigrok.git] / hardware / openbench-logic-sniffer / ols.c
index 112c48d0a5b7ee069edde7c3f0f32119ea4da934..7dcd8b826e82a5df8dbb5fd53813b5aceac99918 100644 (file)
@@ -1,7 +1,7 @@
 /*
  * This file is part of the sigrok project.
  *
- * Copyright (C) 2010 Bert Vermeulen <bert@biot.com>
+ * Copyright (C) 2012 Bert Vermeulen <bert@biot.com>
  *
  * This program is free software: you can redistribute it and/or modify
  * it under the terms of the GNU General Public License as published by
@@ -217,7 +217,6 @@ static struct ols_device *ols_device_new(void)
        ols->trigger_at = -1;
        ols->probe_mask = 0xffffffff;
        ols->cur_samplerate = SR_KHZ(200);
-       ols->period_ps = 5000000;
        ols->serial = NULL;
 
        return ols;
@@ -360,7 +359,7 @@ static int hw_init(const char *deviceinfo)
        final_devcnt = 0;
 
        if (deviceinfo)
-               ports = g_slist_append(NULL, strdup(deviceinfo));
+               ports = g_slist_append(NULL, g_strdup(deviceinfo));
        else
                /* No specific device given, so scan all serial ports. */
                ports = list_serial_ports();
@@ -416,10 +415,10 @@ static int hw_init(const char *deviceinfo)
                        send_shortcommand(fd, CMD_ID);
                        fds[devcnt].fd = fd;
                        fds[devcnt].events = G_IO_IN;
-                       device_names[devcnt] = strdup(l->data);
+                       device_names[devcnt] = g_strdup(l->data);
                        devcnt++;
                }
-               free(l->data);
+               g_free(l->data);
        }
 
        /* 2ms isn't enough for reliable transfer with pl2303, let's try 10 */
@@ -466,8 +465,8 @@ static int hw_init(const char *deviceinfo)
                        serial_restore_params(fds[i].fd, serial_params[i]);
                        serial_close(fds[i].fd);
                }
-               free(serial_params[i]);
-               free(device_names[i]);
+               g_free(serial_params[i]);
+               g_free(device_names[i]);
        }
 
        g_free(serial_params);
@@ -615,12 +614,11 @@ static int set_configuration_samplerate(struct sr_device_instance *sdi,
         * from the requested.
         */
        ols->cur_samplerate = CLOCK_RATE / (ols->cur_samplerate_divider + 1);
-       if(ols->flag_reg & FLAG_DEMUX)
+       if (ols->flag_reg & FLAG_DEMUX)
                ols->cur_samplerate *= 2;
-       ols->period_ps = 1000000000000 / ols->cur_samplerate;
-       if(ols->cur_samplerate != samplerate)
-               sr_warn("ols: can't match samplerate %" PRIu64 ", using %" PRIu64, 
-                       samplerate, ols->cur_samplerate);
+       if (ols->cur_samplerate != samplerate)
+               sr_err("ols: can't match samplerate %" PRIu64 ", using %"
+                      PRIu64, samplerate, ols->cur_samplerate);
 
        return SR_OK;
 }
@@ -652,7 +650,7 @@ static int hw_set_configuration(int device_index, int capability, void *value)
                if (*tmp_u64 < MIN_NUM_SAMPLES)
                        return SR_ERR;
                if (*tmp_u64 > ols->max_samples)
-                       sr_warn("ols: sample limit exceeds hw max");
+                       sr_err("ols: sample limit exceeds hw max");
                ols->limit_samples = *tmp_u64;
                sr_info("ols: sample limit %" PRIu64, ols->limit_samples);
                ret = SR_OK;
@@ -818,8 +816,6 @@ static int receive_data(int fd, int revents, void *session_data)
                        if (ols->trigger_at > 0) {
                                /* there are pre-trigger samples, send those first */
                                packet.type = SR_DF_LOGIC;
-                               packet.timeoffset = 0;
-                               packet.duration = ols->trigger_at * ols->period_ps;
                                packet.payload = &logic;
                                logic.length = ols->trigger_at * 4;
                                logic.unitsize = 4;
@@ -830,14 +826,10 @@ static int receive_data(int fd, int revents, void *session_data)
 
                        /* send the trigger */
                        packet.type = SR_DF_TRIGGER;
-                       packet.timeoffset = ols->trigger_at * ols->period_ps;
-                       packet.duration = 0;
                        sr_session_bus(session_data, &packet);
 
                        /* send post-trigger samples */
                        packet.type = SR_DF_LOGIC;
-                       packet.timeoffset = ols->trigger_at * ols->period_ps;
-                       packet.duration = (ols->num_samples - ols->trigger_at) * ols->period_ps;
                        packet.payload = &logic;
                        logic.length = (ols->num_samples * 4) - (ols->trigger_at * 4);
                        logic.unitsize = 4;
@@ -847,8 +839,6 @@ static int receive_data(int fd, int revents, void *session_data)
                } else {
                        /* no trigger was used */
                        packet.type = SR_DF_LOGIC;
-                       packet.timeoffset = 0;
-                       packet.duration = ols->num_samples * ols->period_ps;
                        packet.payload = &logic;
                        logic.length = ols->num_samples * 4;
                        logic.unitsize = 4;
@@ -861,8 +851,6 @@ static int receive_data(int fd, int revents, void *session_data)
                serial_flush(fd);
                serial_close(fd);
                packet.type = SR_DF_END;
-               packet.timeoffset = ols->num_samples * ols->period_ps;
-               packet.duration = 0;
                sr_session_bus(session_data, &packet);
        }
 
@@ -1014,7 +1002,6 @@ static int hw_start_acquisition(int device_index, gpointer session_data)
        gettimeofday(&header->starttime, NULL);
        header->samplerate = ols->cur_samplerate;
        header->num_logic_probes = NUM_PROBES;
-       header->num_analog_probes = 0;
        sr_session_bus(session_data, packet);
 
        g_free(header);
@@ -1034,7 +1021,7 @@ static void hw_stop_acquisition(int device_index, gpointer session_device_id)
        sr_session_bus(session_device_id, &packet);
 }
 
-struct sr_device_plugin ols_plugin_info = {
+SR_PRIV struct sr_device_plugin ols_plugin_info = {
        .name = "ols",
        .longname = "Openbench Logic Sniffer",
        .api_version = 1,