libsigrok: Coding style fixes.
This commit is contained in:
parent
d86dc674a2
commit
1b452b8510
13
backend.c
13
backend.c
|
@ -18,23 +18,14 @@
|
|||
*/
|
||||
|
||||
#include <glib.h>
|
||||
#include "sigrok.h"
|
||||
#include <sigrok.h>
|
||||
|
||||
int sigrok_init(void)
|
||||
{
|
||||
int ret;
|
||||
|
||||
ret = load_hwplugins();
|
||||
|
||||
return ret;
|
||||
return load_hwplugins();
|
||||
}
|
||||
|
||||
|
||||
void sigrok_cleanup(void)
|
||||
{
|
||||
|
||||
device_close_all();
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
|
21
datastore.c
21
datastore.c
|
@ -21,12 +21,10 @@
|
|||
#include <stdint.h>
|
||||
#include <string.h>
|
||||
#include <glib.h>
|
||||
#include "sigrok.h"
|
||||
#include <sigrok.h>
|
||||
|
||||
static gpointer new_chunk(struct datastore **ds);
|
||||
|
||||
|
||||
|
||||
struct datastore *datastore_new(int unitsize)
|
||||
{
|
||||
struct datastore *ds;
|
||||
|
@ -39,7 +37,6 @@ struct datastore *datastore_new(int unitsize)
|
|||
return ds;
|
||||
}
|
||||
|
||||
|
||||
void datastore_destroy(struct datastore *ds)
|
||||
{
|
||||
GSList *chunk;
|
||||
|
@ -48,11 +45,10 @@ void datastore_destroy(struct datastore *ds)
|
|||
g_free(chunk->data);
|
||||
g_slist_free(ds->chunklist);
|
||||
g_free(ds);
|
||||
|
||||
}
|
||||
|
||||
|
||||
void datastore_put(struct datastore *ds, void *data, unsigned int length, int in_unitsize, int *probelist)
|
||||
void datastore_put(struct datastore *ds, void *data, unsigned int length,
|
||||
int in_unitsize, int *probelist)
|
||||
{
|
||||
unsigned int stored;
|
||||
int capacity, size, num_chunks, chunk_bytes_free, chunk_offset;
|
||||
|
@ -66,10 +62,12 @@ void datastore_put(struct datastore *ds, void *data, unsigned int length, int in
|
|||
chunk = new_chunk(&ds);
|
||||
else
|
||||
chunk = g_slist_last(ds->chunklist)->data;
|
||||
|
||||
num_chunks = g_slist_length(ds->chunklist);
|
||||
capacity = (num_chunks * DATASTORE_CHUNKSIZE);
|
||||
chunk_bytes_free = capacity - (ds->ds_unitsize * ds->num_units);
|
||||
chunk_offset = capacity - (DATASTORE_CHUNKSIZE * (num_chunks - 1)) - chunk_bytes_free;
|
||||
chunk_offset = capacity - (DATASTORE_CHUNKSIZE * (num_chunks - 1))
|
||||
- chunk_bytes_free;
|
||||
stored = 0;
|
||||
while (stored < length) {
|
||||
if (chunk_bytes_free == 0) {
|
||||
|
@ -81,17 +79,16 @@ void datastore_put(struct datastore *ds, void *data, unsigned int length, int in
|
|||
if (length - stored > (unsigned int)chunk_bytes_free)
|
||||
size = chunk_bytes_free;
|
||||
else
|
||||
/* last part, won't fill up this chunk */
|
||||
/* Last part, won't fill up this chunk. */
|
||||
size = length - stored;
|
||||
|
||||
memcpy(chunk + chunk_offset, data + stored, size);
|
||||
chunk_bytes_free -= size;
|
||||
stored += size;
|
||||
}
|
||||
ds->num_units += stored / ds->ds_unitsize;
|
||||
|
||||
}
|
||||
|
||||
|
||||
static gpointer new_chunk(struct datastore **ds)
|
||||
{
|
||||
gpointer chunk;
|
||||
|
@ -101,5 +98,3 @@ static gpointer new_chunk(struct datastore **ds)
|
|||
|
||||
return chunk;
|
||||
}
|
||||
|
||||
|
||||
|
|
9
debug.c
9
debug.c
|
@ -18,16 +18,14 @@
|
|||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include "sigrok.h"
|
||||
#include <sigrok.h>
|
||||
|
||||
void hexdump(unsigned char *address, int length)
|
||||
{
|
||||
int i;
|
||||
|
||||
for(i = 0; i < length; i++)
|
||||
{
|
||||
if((i & 0x0f) == 0)
|
||||
{
|
||||
for (i = 0; i < length; i++) {
|
||||
if ((i & 0x0f) == 0) {
|
||||
if (i)
|
||||
printf("\n");
|
||||
printf("%.4x ", i);
|
||||
|
@ -35,5 +33,4 @@ void hexdump(unsigned char *address, int length)
|
|||
printf("%.2x ", address[i]);
|
||||
}
|
||||
printf("\n");
|
||||
|
||||
}
|
||||
|
|
93
device.c
93
device.c
|
@ -19,13 +19,12 @@
|
|||
|
||||
#include <stdio.h>
|
||||
#include <glib.h>
|
||||
#include "sigrok.h"
|
||||
#include <sigrok.h>
|
||||
|
||||
extern struct sigrok_global *global;
|
||||
|
||||
GSList *devices = NULL;
|
||||
|
||||
|
||||
void device_scan(void)
|
||||
{
|
||||
GSList *plugins, *l;
|
||||
|
@ -34,45 +33,36 @@ void device_scan(void)
|
|||
|
||||
plugins = list_hwplugins();
|
||||
|
||||
/* initialize all plugins first. Since the init() call may involve
|
||||
/*
|
||||
* Initialize all plugins first. Since the init() call may involve
|
||||
* a firmware upload and associated delay, we may as well get all
|
||||
* of these out of the way first.
|
||||
*/
|
||||
for(l = plugins; l; l = l->next)
|
||||
{
|
||||
for (l = plugins; l; l = l->next) {
|
||||
plugin = l->data;
|
||||
g_message("initializing %s plugin", plugin->name);
|
||||
num_devices = plugin->init(NULL);
|
||||
for (i = 0; i < num_devices; i++)
|
||||
{
|
||||
device_new(plugin, i);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
void device_close_all(void)
|
||||
{
|
||||
struct device *device;
|
||||
|
||||
while(devices)
|
||||
{
|
||||
while (devices) {
|
||||
device = devices->data;
|
||||
device->plugin->close(device->plugin_index);
|
||||
device_destroy(device);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
GSList *device_list(void)
|
||||
{
|
||||
|
||||
return devices;
|
||||
}
|
||||
|
||||
|
||||
struct device *device_new(struct device_plugin *plugin, int plugin_index)
|
||||
{
|
||||
struct device *device;
|
||||
|
@ -84,9 +74,9 @@ struct device *device_new(struct device_plugin *plugin, int plugin_index)
|
|||
device->plugin_index = plugin_index;
|
||||
devices = g_slist_append(devices, device);
|
||||
|
||||
num_probes = (int) device->plugin->get_device_info(device->plugin_index, DI_NUM_PROBES);
|
||||
for(i = 0; i < num_probes; i++)
|
||||
{
|
||||
num_probes = (int)device->plugin->get_device_info(device->plugin_index,
|
||||
DI_NUM_PROBES);
|
||||
for (i = 0; i < num_probes; i++) {
|
||||
snprintf(probename, 16, "%d", i + 1);
|
||||
device_probe_add(device, probename);
|
||||
}
|
||||
|
@ -94,38 +84,37 @@ struct device *device_new(struct device_plugin *plugin, int plugin_index)
|
|||
return device;
|
||||
}
|
||||
|
||||
|
||||
void device_clear(struct device *device)
|
||||
{
|
||||
unsigned int probenum;
|
||||
unsigned int pnum;
|
||||
|
||||
/* TODO: plugin-specific clear call? */
|
||||
/* TODO: Plugin-specific clear call? */
|
||||
|
||||
if(device->probes)
|
||||
for(probenum = 1; probenum <= g_slist_length(device->probes); probenum++)
|
||||
device_probe_clear(device, probenum);
|
||||
if (!device->probes)
|
||||
return;
|
||||
|
||||
for (pnum = 1; pnum <= g_slist_length(device->probes); pnum++)
|
||||
device_probe_clear(device, pnum);
|
||||
}
|
||||
|
||||
|
||||
void device_destroy(struct device *device)
|
||||
{
|
||||
unsigned int probenum;
|
||||
unsigned int pnum;
|
||||
|
||||
/* TODO: plugin-specific destroy call, need to decrease refcount in plugin */
|
||||
/*
|
||||
* TODO: Plugin-specific destroy call, need to decrease refcount
|
||||
* in plugin.
|
||||
*/
|
||||
|
||||
devices = g_slist_remove(devices, device);
|
||||
if(device->probes)
|
||||
{
|
||||
for(probenum = 1; probenum <= g_slist_length(device->probes); probenum++)
|
||||
device_probe_clear(device, probenum);
|
||||
if (device->probes) {
|
||||
for (pnum = 1; pnum <= g_slist_length(device->probes); pnum++)
|
||||
device_probe_clear(device, pnum);
|
||||
g_slist_free(device->probes);
|
||||
}
|
||||
g_free(device);
|
||||
|
||||
}
|
||||
|
||||
|
||||
void device_probe_clear(struct device *device, int probenum)
|
||||
{
|
||||
struct probe *p;
|
||||
|
@ -134,21 +123,17 @@ void device_probe_clear(struct device *device, int probenum)
|
|||
if (!p)
|
||||
return;
|
||||
|
||||
if(p->name)
|
||||
{
|
||||
if (p->name) {
|
||||
g_free(p->name);
|
||||
p->name = NULL;
|
||||
}
|
||||
|
||||
if(p->trigger)
|
||||
{
|
||||
if (p->trigger) {
|
||||
g_free(p->trigger);
|
||||
p->trigger = NULL;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
void device_probe_add(struct device *device, char *name)
|
||||
{
|
||||
struct probe *p;
|
||||
|
@ -159,21 +144,17 @@ void device_probe_add(struct device *device, char *name)
|
|||
p->name = g_strdup(name);
|
||||
p->trigger = NULL;
|
||||
device->probes = g_slist_append(device->probes, p);
|
||||
|
||||
}
|
||||
|
||||
|
||||
struct probe *probe_find(struct device *device, int probenum)
|
||||
{
|
||||
GSList *l;
|
||||
struct probe *p, *found_probe;
|
||||
|
||||
found_probe = NULL;
|
||||
for(l = device->probes; l; l = l->next)
|
||||
{
|
||||
for (l = device->probes; l; l = l->next) {
|
||||
p = l->data;
|
||||
if(p->index == probenum)
|
||||
{
|
||||
if (p->index == probenum) {
|
||||
found_probe = p;
|
||||
break;
|
||||
}
|
||||
|
@ -182,7 +163,6 @@ struct probe *probe_find(struct device *device, int probenum)
|
|||
return found_probe;
|
||||
}
|
||||
|
||||
|
||||
void device_probe_name(struct device *device, int probenum, char *name)
|
||||
{
|
||||
struct probe *p;
|
||||
|
@ -194,29 +174,25 @@ void device_probe_name(struct device *device, int probenum, char *name)
|
|||
if (p->name)
|
||||
g_free(p->name);
|
||||
p->name = g_strdup(name);
|
||||
|
||||
}
|
||||
|
||||
|
||||
void device_trigger_clear(struct device *device)
|
||||
{
|
||||
struct probe *p;
|
||||
unsigned int probenum;
|
||||
unsigned int pnum;
|
||||
|
||||
if(device->probes)
|
||||
for(probenum = 1; probenum <= g_slist_length(device->probes); probenum++)
|
||||
{
|
||||
p = probe_find(device, probenum);
|
||||
if(p && p->trigger)
|
||||
{
|
||||
if (!device->probes)
|
||||
return;
|
||||
|
||||
for (pnum = 1; pnum <= g_slist_length(device->probes); pnum++) {
|
||||
p = probe_find(device, pnum);
|
||||
if (p && p->trigger) {
|
||||
g_free(p->trigger);
|
||||
p->trigger = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
void device_trigger_set(struct device *device, int probenum, char *trigger)
|
||||
{
|
||||
struct probe *p;
|
||||
|
@ -229,7 +205,4 @@ void device_trigger_set(struct device *device, int probenum, char *trigger)
|
|||
g_free(p->trigger);
|
||||
|
||||
p->trigger = g_strdup(trigger);
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
|
36
sigrok.h
36
sigrok.h
|
@ -76,7 +76,7 @@ struct protocol {
|
|||
};
|
||||
|
||||
/*
|
||||
* datafeed
|
||||
* Datafeed
|
||||
*/
|
||||
|
||||
/* datafeed_packet.type values */
|
||||
|
@ -107,7 +107,7 @@ struct datafeed_header {
|
|||
};
|
||||
|
||||
/*
|
||||
* output
|
||||
* Output
|
||||
*/
|
||||
struct output {
|
||||
struct output_format *format;
|
||||
|
@ -217,13 +217,13 @@ void device_trigger_set(struct device *device, int probenum, char *trigger);
|
|||
|
||||
/* Hardware plugin capabilities */
|
||||
enum {
|
||||
HWCAP_DUMMY, // used to terminate lists
|
||||
HWCAP_DUMMY, /* Used to terminate lists */
|
||||
HWCAP_LOGIC_ANALYZER,
|
||||
HWCAP_SAMPLERATE, // change samplerate
|
||||
HWCAP_PROBECONFIG, // configure probe mask
|
||||
HWCAP_CAPTURE_RATIO, // set pre-trigger / post-trigger ratio
|
||||
HWCAP_LIMIT_MSEC, // set a time limit for sample acquisition
|
||||
HWCAP_LIMIT_SAMPLES, // set a limit on number of samples
|
||||
HWCAP_SAMPLERATE, /* Change samplerate */
|
||||
HWCAP_PROBECONFIG, /* Configure probe mask */
|
||||
HWCAP_CAPTURE_RATIO, /* Set pre-trigger / post-trigger ratio */
|
||||
HWCAP_LIMIT_MSEC, /* Set a time limit for sample acquisition */
|
||||
HWCAP_LIMIT_SAMPLES, /* Set a limit on number of samples */
|
||||
};
|
||||
|
||||
struct hwcap_option {
|
||||
|
@ -293,8 +293,9 @@ enum {
|
|||
DI_CUR_SAMPLERATE,
|
||||
};
|
||||
|
||||
/* a device supports either a range of samplerates with steps of a given
|
||||
* granularity, or is limited to a set of defined samplerates. use either
|
||||
/*
|
||||
* A device supports either a range of samplerates with steps of a given
|
||||
* granularity, or is limited to a set of defined samplerates. Use either
|
||||
* step or list, but not both.
|
||||
*/
|
||||
struct samplerates {
|
||||
|
@ -305,13 +306,13 @@ struct samplerates {
|
|||
};
|
||||
|
||||
struct device_plugin {
|
||||
/* plugin-specific */
|
||||
/* Plugin-specific */
|
||||
char *name;
|
||||
int api_version;
|
||||
int (*init) (char *deviceinfo);
|
||||
void (*cleanup) (void);
|
||||
|
||||
/* device-specific */
|
||||
/* Device-specific */
|
||||
int (*open) (int device_index);
|
||||
void (*close) (int device_index);
|
||||
void *(*get_device_info) (int device_index, int device_info_id);
|
||||
|
@ -337,7 +338,8 @@ GSList *list_hwplugins(void);
|
|||
/* Generic device instances */
|
||||
struct sigrok_device_instance *sigrok_device_instance_new(int index,
|
||||
int status, char *vendor, char *model, char *version);
|
||||
struct sigrok_device_instance *get_sigrok_device_instance(GSList *device_instances, int device_index);
|
||||
struct sigrok_device_instance *get_sigrok_device_instance(
|
||||
GSList *device_instances, int device_index);
|
||||
void sigrok_device_instance_free(struct sigrok_device_instance *sdi);
|
||||
|
||||
/* USB-specific instances */
|
||||
|
@ -352,7 +354,8 @@ void serial_device_instance_free(struct serial_device_instance *serial);
|
|||
int find_hwcap(int *capabilities, int hwcap);
|
||||
struct hwcap_option *find_hwcap_option(int hwcap);
|
||||
void source_remove(int fd);
|
||||
void source_add(int fd, int events, int timeout, receive_data_callback rcv_cb, void *user_data);
|
||||
void source_add(int fd, int events, int timeout, receive_data_callback rcv_cb,
|
||||
void *user_data);
|
||||
|
||||
/*--- session.c -------------------------------------------------------------*/
|
||||
|
||||
|
@ -367,7 +370,7 @@ struct session {
|
|||
GSList *devices;
|
||||
/* List of struct analyzer* */
|
||||
GSList *analyzers;
|
||||
/* datafeed callbacks */
|
||||
/* Datafeed callbacks */
|
||||
GSList *datafeed_callbacks;
|
||||
GTimeVal starttime;
|
||||
};
|
||||
|
@ -406,6 +409,7 @@ int serial_open(const char *pathname, int flags);
|
|||
int serial_close(int fd);
|
||||
void *serial_backup_params(int fd);
|
||||
void serial_restore_params(int fd, void *backup);
|
||||
int serial_set_params(int fd, int speed, int bits, int parity, int stopbits, int flowcontrol);
|
||||
int serial_set_params(int fd, int speed, int bits, int parity, int stopbits,
|
||||
int flowcontrol);
|
||||
|
||||
#endif
|
||||
|
|
Loading…
Reference in New Issue