]> sigrok.org Git - libsigrok.git/blobdiff - hardware/openbench-logic-sniffer/ols.c
sr: s/acquisition_*/dev_acquisition_*/.
[libsigrok.git] / hardware / openbench-logic-sniffer / ols.c
index c322f789fd64f3e831fda864be0c05752782e984..f7fcd5877a76d9522c3bc3f06760b06382674bac 100644 (file)
@@ -46,7 +46,7 @@
 #define O_NONBLOCK FIONBIO
 #endif
 
-static int capabilities[] = {
+static int hwcaps[] = {
        SR_HWCAP_LOGIC_ANALYZER,
        SR_HWCAP_SAMPLERATE,
        SR_HWCAP_CAPTURE_RATIO,
@@ -99,8 +99,8 @@ static struct sr_samplerates samplerates = {
        NULL,
 };
 
-/* List of struct sr_serial_device_instance */
-static GSList *device_instances = NULL;
+/* List of struct sr_serial_dev_inst */
+static GSList *dev_insts = NULL;
 
 static int send_shortcommand(int fd, uint8_t command)
 {
@@ -130,7 +130,7 @@ static int send_longcommand(int fd, uint8_t command, uint32_t data)
        return SR_OK;
 }
 
-static int configure_probes(struct ols_device *ols, GSList *probes)
+static int configure_probes(struct ols_dev *ols, GSList *probes)
 {
        struct sr_probe *probe;
        GSList *l;
@@ -204,12 +204,12 @@ static uint32_t reverse32(uint32_t in)
        return out;
 }
 
-static struct ols_device *ols_device_new(void)
+static struct ols_dev *ols_dev_new(void)
 {
-       struct ols_device *ols;
+       struct ols_dev *ols;
 
        /* TODO: Is 'ols' ever g_free()'d? */
-       if (!(ols = g_try_malloc0(sizeof(struct ols_device)))) {
+       if (!(ols = g_try_malloc0(sizeof(struct ols_dev)))) {
                sr_err("ols: %s: ols malloc failed", __func__);
                return NULL;
        }
@@ -222,20 +222,20 @@ static struct ols_device *ols_device_new(void)
        return ols;
 }
 
-static struct sr_device_instance *get_metadata(int fd)
+static struct sr_dev_inst *get_metadata(int fd)
 {
-       struct sr_device_instance *sdi;
-       struct ols_device *ols;
+       struct sr_dev_inst *sdi;
+       struct ols_dev *ols;
        uint32_t tmp_int;
        uint8_t key, type, token;
-       GString *tmp_str, *devicename, *version;
+       GString *tmp_str, *devname, *version;
        gchar tmp_c;
 
        sdi = sr_dev_inst_new(0, SR_ST_INACTIVE, NULL, NULL, NULL);
-       ols = ols_device_new();
+       ols = ols_dev_new();
        sdi->priv = ols;
 
-       devicename = g_string_new("");
+       devname = g_string_new("");
        version = g_string_new("");
 
        key = 0xff;
@@ -255,7 +255,7 @@ static struct sr_device_instance *get_metadata(int fd)
                        switch (token) {
                        case 0x01:
                                /* Device name */
-                               devicename = g_string_append(devicename, tmp_str->str);
+                               devname = g_string_append(devname, tmp_str->str);
                                break;
                        case 0x02:
                                /* FPGA firmware version */
@@ -339,27 +339,27 @@ static struct sr_device_instance *get_metadata(int fd)
                }
        }
 
-       sdi->model = devicename->str;
+       sdi->model = devname->str;
        sdi->version = version->str;
-       g_string_free(devicename, FALSE);
+       g_string_free(devname, FALSE);
        g_string_free(version, FALSE);
 
        return sdi;
 }
 
-static int hw_init(const char *deviceinfo)
+static int hw_init(const char *devinfo)
 {
-       struct sr_device_instance *sdi;
-       struct ols_device *ols;
+       struct sr_dev_inst *sdi;
+       struct ols_dev *ols;
        GSList *ports, *l;
        GPollFD *fds, probefd;
        int devcnt, final_devcnt, num_ports, fd, ret, i;
-       char buf[8], **device_names, **serial_params;
+       char buf[8], **dev_names, **serial_params;
 
        final_devcnt = 0;
 
-       if (deviceinfo)
-               ports = g_slist_append(NULL, g_strdup(deviceinfo));
+       if (devinfo)
+               ports = g_slist_append(NULL, g_strdup(devinfo));
        else
                /* No specific device given, so scan all serial ports. */
                ports = list_serial_ports();
@@ -371,14 +371,14 @@ static int hw_init(const char *deviceinfo)
                goto hw_init_free_ports; /* TODO: SR_ERR_MALLOC. */
        }
 
-       if (!(device_names = g_try_malloc(num_ports * sizeof(char *)))) {
-               sr_err("ols: %s: device_names malloc failed", __func__);
+       if (!(dev_names = g_try_malloc(num_ports * sizeof(char *)))) {
+               sr_err("ols: %s: dev_names malloc failed", __func__);
                goto hw_init_free_fds; /* TODO: SR_ERR_MALLOC. */
        }
 
        if (!(serial_params = g_try_malloc(num_ports * sizeof(char *)))) {
                sr_err("ols: %s: serial_params malloc failed", __func__);
-               goto hw_init_free_device_names; /* TODO: SR_ERR_MALLOC. */
+               goto hw_init_free_dev_names; /* TODO: SR_ERR_MALLOC. */
        }
 
        devcnt = 0;
@@ -415,7 +415,7 @@ 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] = g_strdup(l->data);
+                       dev_names[devcnt] = g_strdup(l->data);
                        devcnt++;
                }
                g_free(l->data);
@@ -448,12 +448,12 @@ static int hw_init(const char *deviceinfo)
                        /* not an OLS -- some other board that uses the sump protocol */
                        sdi = sr_dev_inst_new(final_devcnt, SR_ST_INACTIVE,
                                        "Sump", "Logic Analyzer", "v1.0");
-                       ols = ols_device_new();
+                       ols = ols_dev_new();
                        ols->num_probes = 32;
                        sdi->priv = ols;
                }
-               ols->serial = sr_serial_dev_inst_new(device_names[i], -1);
-               device_instances = g_slist_append(device_instances, sdi);
+               ols->serial = sr_serial_dev_inst_new(dev_names[i], -1);
+               dev_insts = g_slist_append(dev_insts, sdi);
                final_devcnt++;
                serial_close(fds[i].fd);
                fds[i].fd = 0;
@@ -466,12 +466,12 @@ static int hw_init(const char *deviceinfo)
                        serial_close(fds[i].fd);
                }
                g_free(serial_params[i]);
-               g_free(device_names[i]);
+               g_free(dev_names[i]);
        }
 
        g_free(serial_params);
-hw_init_free_device_names:
-       g_free(device_names);
+hw_init_free_dev_names:
+       g_free(dev_names);
 hw_init_free_fds:
        g_free(fds);
 hw_init_free_ports:
@@ -480,12 +480,12 @@ hw_init_free_ports:
        return final_devcnt;
 }
 
-static int hw_opendev(int device_index)
+static int hw_dev_open(int dev_index)
 {
-       struct sr_device_instance *sdi;
-       struct ols_device *ols;
+       struct sr_dev_inst *sdi;
+       struct ols_dev *ols;
 
-       if (!(sdi = sr_dev_inst_get(device_instances, device_index)))
+       if (!(sdi = sr_dev_inst_get(dev_insts, dev_index)))
                return SR_ERR;
 
        ols = sdi->priv;
@@ -499,12 +499,12 @@ static int hw_opendev(int device_index)
        return SR_OK;
 }
 
-static int hw_closedev(int device_index)
+static int hw_dev_close(int dev_index)
 {
-       struct sr_device_instance *sdi;
-       struct ols_device *ols;
+       struct sr_dev_inst *sdi;
+       struct ols_dev *ols;
 
-       if (!(sdi = sr_dev_inst_get(device_instances, device_index))) {
+       if (!(sdi = sr_dev_inst_get(dev_insts, dev_index))) {
                sr_err("ols: %s: sdi was NULL", __func__);
                return SR_ERR; /* TODO: SR_ERR_ARG? */
        }
@@ -524,12 +524,12 @@ static int hw_closedev(int device_index)
 static int hw_cleanup(void)
 {
        GSList *l;
-       struct sr_device_instance *sdi;
-       struct ols_device *ols;
+       struct sr_dev_inst *sdi;
+       struct ols_dev *ols;
        int ret = SR_OK;
 
        /* Properly close and free all devices. */
-       for (l = device_instances; l; l = l->next) {
+       for (l = dev_insts; l; l = l->next) {
                if (!(sdi = l->data)) {
                        /* Log error, but continue cleaning up the rest. */
                        sr_err("ols: %s: sdi was NULL, continuing", __func__);
@@ -549,25 +549,25 @@ static int hw_cleanup(void)
                sr_serial_dev_inst_free(ols->serial);
                sr_dev_inst_free(sdi);
        }
-       g_slist_free(device_instances);
-       device_instances = NULL;
+       g_slist_free(dev_insts);
+       dev_insts = NULL;
 
        return ret;
 }
 
-static void *hw_get_device_info(int device_index, int device_info_id)
+static void *hw_dev_info_get(int dev_index, int dev_info_id)
 {
-       struct sr_device_instance *sdi;
-       struct ols_device *ols;
+       struct sr_dev_inst *sdi;
+       struct ols_dev *ols;
        void *info;
 
-       if (!(sdi = sr_dev_inst_get(device_instances, device_index)))
+       if (!(sdi = sr_dev_inst_get(dev_insts, dev_index)))
                return NULL;
        ols = sdi->priv;
 
        info = NULL;
-       switch (device_info_id) {
-       case SR_DI_INSTANCE:
+       switch (dev_info_id) {
+       case SR_DI_INST:
                info = sdi;
                break;
        case SR_DI_NUM_PROBES:
@@ -590,25 +590,24 @@ static void *hw_get_device_info(int device_index, int device_info_id)
        return info;
 }
 
-static int hw_get_status(int device_index)
+static int hw_dev_status_get(int dev_index)
 {
-       struct sr_device_instance *sdi;
+       struct sr_dev_inst *sdi;
 
-       if (!(sdi = sr_dev_inst_get(device_instances, device_index)))
+       if (!(sdi = sr_dev_inst_get(dev_insts, dev_index)))
                return SR_ST_NOT_FOUND;
 
        return sdi->status;
 }
 
-static int *hw_get_capabilities(void)
+static int *hw_hwcap_get_all(void)
 {
-       return capabilities;
+       return hwcaps;
 }
 
-static int set_configuration_samplerate(struct sr_device_instance *sdi,
-                                       uint64_t samplerate)
+static int config_set_samplerate(struct sr_dev_inst *sdi, uint64_t samplerate)
 {
-       struct ols_device *ols;
+       struct ols_dev *ols;
 
        ols = sdi->priv;
        if (ols->max_samplerate) {
@@ -638,24 +637,24 @@ static int set_configuration_samplerate(struct sr_device_instance *sdi,
        return SR_OK;
 }
 
-static int hw_set_configuration(int device_index, int capability, void *value)
+static int hw_config_set(int dev_index, int hwcap, void *value)
 {
-       struct sr_device_instance *sdi;
-       struct ols_device *ols;
+       struct sr_dev_inst *sdi;
+       struct ols_dev *ols;
        int ret;
        uint64_t *tmp_u64;
 
-       if (!(sdi = sr_dev_inst_get(device_instances, device_index)))
+       if (!(sdi = sr_dev_inst_get(dev_insts, dev_index)))
                return SR_ERR;
        ols = sdi->priv;
 
        if (sdi->status != SR_ST_ACTIVE)
                return SR_ERR;
 
-       switch (capability) {
+       switch (hwcap) {
        case SR_HWCAP_SAMPLERATE:
                tmp_u64 = value;
-               ret = set_configuration_samplerate(sdi, *tmp_u64);
+               ret = config_set_samplerate(sdi, *tmp_u64);
                break;
        case SR_HWCAP_PROBECONFIG:
                ret = configure_probes(ols, (GSList *) value);
@@ -697,15 +696,15 @@ static int receive_data(int fd, int revents, void *session_data)
 {
        struct sr_datafeed_packet packet;
        struct sr_datafeed_logic logic;
-       struct sr_device_instance *sdi;
-       struct ols_device *ols;
+       struct sr_dev_inst *sdi;
+       struct ols_dev *ols;
        GSList *l;
        int num_channels, offset, i, j;
        unsigned char byte;
 
-       /* find this device's ols_device struct by its fd */
+       /* find this device's ols_dev struct by its fd */
        ols = NULL;
-       for (l = device_instances; l; l = l->next) {
+       for (l = dev_insts; l; l = l->next) {
                sdi = l->data;
                if (ols->serial->fd == fd) {
                        ols = sdi->priv;
@@ -872,12 +871,12 @@ static int receive_data(int fd, int revents, void *session_data)
        return TRUE;
 }
 
-static int hw_start_acquisition(int device_index, gpointer session_data)
+static int hw_dev_acquisition_start(int dev_index, gpointer session_data)
 {
        struct sr_datafeed_packet *packet;
        struct sr_datafeed_header *header;
-       struct sr_device_instance *sdi;
-       struct ols_device *ols;
+       struct sr_dev_inst *sdi;
+       struct ols_dev *ols;
        uint32_t trigger_config[4];
        uint32_t data;
        uint16_t readcount, delaycount;
@@ -885,7 +884,7 @@ static int hw_start_acquisition(int device_index, gpointer session_data)
        int num_channels;
        int i;
 
-       if (!(sdi = sr_dev_inst_get(device_instances, device_index)))
+       if (!(sdi = sr_dev_inst_get(dev_insts, dev_index)))
                return SR_ERR;
 
        ols = sdi->priv;
@@ -1025,31 +1024,31 @@ static int hw_start_acquisition(int device_index, gpointer session_data)
        return SR_OK;
 }
 
-static int hw_stop_acquisition(int device_index, gpointer session_device_id)
+static int hw_dev_acquisition_stop(int dev_index, gpointer session_dev_id)
 {
        struct sr_datafeed_packet packet;
 
        /* Avoid compiler warnings. */
-       (void)device_index;
+       (void)dev_index;
 
        packet.type = SR_DF_END;
-       sr_session_bus(session_device_id, &packet);
+       sr_session_bus(session_dev_id, &packet);
 
        return SR_OK;
 }
 
-SR_PRIV struct sr_device_plugin ols_plugin_info = {
+SR_PRIV struct sr_dev_plugin ols_plugin_info = {
        .name = "ols",
        .longname = "Openbench Logic Sniffer",
        .api_version = 1,
        .init = hw_init,
        .cleanup = hw_cleanup,
-       .opendev = hw_opendev,
-       .closedev = hw_closedev,
-       .get_device_info = hw_get_device_info,
-       .get_status = hw_get_status,
-       .get_capabilities = hw_get_capabilities,
-       .set_configuration = hw_set_configuration,
-       .start_acquisition = hw_start_acquisition,
-       .stop_acquisition = hw_stop_acquisition,
+       .dev_open = hw_dev_open,
+       .dev_close = hw_dev_close,
+       .dev_info_get = hw_dev_info_get,
+       .dev_status_get = hw_dev_status_get,
+       .hwcap_get_all = hw_hwcap_get_all,
+       .config_set = hw_config_set,
+       .dev_acquisition_start = hw_dev_acquisition_start,
+       .dev_acquisition_stop = hw_dev_acquisition_stop,
 };