link-mso19: Fix white-space, cosmetics, coding-style.

Fix the bare minumum of whitespace/indentation/coding-style via
automatic 'indent' run, followed by some minor manual fixes.
Some more fixes and cleanups might follow later.
This commit is contained in:
Uwe Hermann 2013-01-08 02:48:49 +01:00
parent f48cef7897
commit 00b44ccb8b
3 changed files with 282 additions and 297 deletions

View File

@ -60,6 +60,7 @@ static int hw_init(struct sr_context *sr_ctx)
sr_err("Driver context malloc failed.");
return SR_ERR_MALLOC;
}
drvc->sr_ctx = sr_ctx;
di->priv = drvc;
@ -69,15 +70,17 @@ static int hw_init(struct sr_context *sr_ctx)
static GSList *hw_scan(GSList *options)
{
int i;
(void)options;
GSList *devices = NULL;
const char *conn = NULL;
const char *serialcomm = NULL;
GSList *l;
struct sr_hwopt *opt;
struct udev *udev;
(void)options;
for (l = options; l; l = l->next) {
struct sr_hwopt* opt = l->data;
opt = l->data;
switch (opt->hwopt) {
case SR_HWOPT_CONN:
conn = opt->value;
@ -92,10 +95,11 @@ static GSList *hw_scan(GSList *options)
if (serialcomm == NULL)
serialcomm = SERIALCOMM;
struct udev *udev = udev_new();
udev = udev_new();
if (!udev) {
sr_err("Failed to initialize udev.");
}
struct udev_enumerate *enumerate = udev_enumerate_new(udev);
udev_enumerate_add_match_subsystem(enumerate, "usb-serial");
udev_enumerate_scan_devices(enumerate);
@ -103,13 +107,14 @@ static GSList *hw_scan(GSList *options)
struct udev_list_entry *dev_list_entry;
for (dev_list_entry = devs;
dev_list_entry != NULL;
dev_list_entry = udev_list_entry_get_next(dev_list_entry))
{
dev_list_entry = udev_list_entry_get_next(dev_list_entry)) {
const char *syspath = udev_list_entry_get_name(dev_list_entry);
struct udev_device *dev = udev_device_new_from_syspath(udev, syspath);
struct udev_device *dev =
udev_device_new_from_syspath(udev, syspath);
const char *sysname = udev_device_get_sysname(dev);
struct udev_device *parent = udev_device_get_parent_with_subsystem_devtype(
dev, "usb", "usb_device");
struct udev_device *parent =
udev_device_get_parent_with_subsystem_devtype(dev, "usb",
"usb_device");
if (!parent) {
sr_err("Unable to find parent usb device for %s",
@ -117,14 +122,18 @@ static GSList *hw_scan(GSList *options)
continue;
}
const char *idVendor = udev_device_get_sysattr_value(parent, "idVendor");
const char *idProduct = udev_device_get_sysattr_value(parent, "idProduct");
const char *idVendor =
udev_device_get_sysattr_value(parent, "idVendor");
const char *idProduct =
udev_device_get_sysattr_value(parent, "idProduct");
if (strcmp(USB_VENDOR, idVendor)
|| strcmp(USB_PRODUCT, idProduct))
continue;
const char* iSerial = udev_device_get_sysattr_value(parent, "serial");
const char* iProduct = udev_device_get_sysattr_value(parent, "product");
const char *iSerial =
udev_device_get_sysattr_value(parent, "serial");
const char *iProduct =
udev_device_get_sysattr_value(parent, "product");
char path[32];
snprintf(path, sizeof(path), "/dev/%s", sysname);
@ -164,8 +173,7 @@ static GSList *hw_scan(GSList *options)
devc->protocol_trigger.mask[i] = 0xff;
}
if (!(devc->serial = sr_serial_dev_inst_new(conn, serialcomm)))
{
if (!(devc->serial = sr_serial_dev_inst_new(conn, serialcomm))) {
g_free(devc);
return devices;
}
@ -212,6 +220,7 @@ static GSList *hw_dev_list(void)
static int hw_dev_open(struct sr_dev_inst *sdi)
{
int ret;
struct dev_context *devc;
devc = sdi->priv;
@ -225,7 +234,7 @@ static int hw_dev_open(struct sr_dev_inst *sdi)
mso_check_trigger(devc->serial, &devc->trigger_state);
sr_dbg("Trigger state: 0x%x.", devc->trigger_state);
int ret = mso_reset_adc(sdi);
ret = mso_reset_adc(sdi);
if (ret != SR_OK)
return ret;
@ -328,8 +337,11 @@ static int hw_dev_config_set(const struct sr_dev_inst *sdi, int hwcap,
const void *value)
{
int ret;
struct dev_context *devc;
uint64_t num_samples, slope;
int trigger_pos;
float pos;
devc = sdi->priv;
if (sdi->status != SR_ST_ACTIVE)
@ -337,59 +349,52 @@ static int hw_dev_config_set(const struct sr_dev_inst *sdi, int hwcap,
switch (hwcap) {
case SR_HWCAP_SAMPLERATE:
// FIXME
return mso_configure_rate(sdi, *(const uint64_t *)value);
ret = SR_OK;
break;
case SR_HWCAP_LIMIT_SAMPLES:
{
const uint64_t num_samples = *(const uint64_t *)value;
if (num_samples < 1024)
{
num_samples = *(uint64_t *)value;
if (num_samples < 1024) {
sr_err("minimum of 1024 samples required");
ret = SR_ERR_ARG;
} else {
devc->limit_samples = num_samples;
sr_dbg("setting limit_samples to %i\n", num_samples);
sr_dbg("setting limit_samples to %i\n",
num_samples);
ret = SR_OK;
}
}
break;
case SR_HWCAP_CAPTURE_RATIO:
ret = SR_OK;
break;
case SR_HWCAP_TRIGGER_SLOPE:
{
const uint64_t slope = *(const uint64_t *)value;
if (slope != SLOPE_NEGATIVE && slope != SLOPE_POSITIVE)
{
slope = *(uint64_t *)value;
if (slope != SLOPE_NEGATIVE && slope != SLOPE_POSITIVE) {
sr_err("Invalid trigger slope");
ret = SR_ERR_ARG;
} else {
devc->trigger_slope = slope;
ret = SR_OK;
}
}
break;
case SR_HWCAP_HORIZ_TRIGGERPOS:
{
const float pos = *(const float *)value;
pos = *(float *)value;
if (pos < 0 || pos > 255) {
sr_err("Trigger position (%f) should be between 0 and 255.", pos);
ret = SR_ERR_ARG;
} else {
int trigger_pos = (int)pos;
trigger_pos = (int)pos;
devc->trigger_holdoff[0] = trigger_pos & 0xff;
ret = SR_OK;
}
}
break;
case SR_HWCAP_RLE:
ret = SR_OK;
break;
default:
ret = SR_ERR;
break;
}
return ret;
@ -404,7 +409,6 @@ static int hw_dev_acquisition_start(const struct sr_dev_inst *sdi,
struct dev_context *devc;
int ret = SR_ERR;
devc = sdi->priv;
if (sdi->status != SR_ST_ACTIVE)
@ -437,12 +441,10 @@ static int hw_dev_acquisition_start(const struct sr_dev_inst *sdi,
if (ret != SR_OK)
return ret;
ret = mso_configure_trigger(sdi);
if (ret != SR_OK)
return ret;
/* END of config hardware part */
ret = mso_arm(sdi);
if (ret != SR_OK)
@ -467,7 +469,6 @@ static int hw_dev_acquisition_start(const struct sr_dev_inst *sdi,
return SR_ERR_MALLOC;
}
packet->type = SR_DF_HEADER;
packet->payload = (unsigned char *)header;
header->feed_version = 1;
@ -489,7 +490,6 @@ static int hw_dev_acquisition_start(const struct sr_dev_inst *sdi,
/* This stops acquisition on ALL devices, ignoring dev_index. */
static int hw_dev_acquisition_stop(struct sr_dev_inst *sdi, void *cb_data)
{
/* Avoid compiler warnings. */
(void)cb_data;
stop_acquisition(sdi);

View File

@ -68,13 +68,11 @@ ret:
return ret;
}
SR_PRIV int mso_configure_trigger(struct sr_dev_inst *sdi)
{
struct dev_context *devc = sdi->priv;
uint16_t threshold_value = mso_calc_raw_from_mv(devc);
threshold_value = 0x153C;
uint8_t trigger_config = 0;
@ -123,7 +121,8 @@ SR_PRIV int mso_configure_trigger(struct sr_dev_inst *sdi)
ops[5] = mso_trans(8, devc->trigger_holdoff[1]);
ops[6] = mso_trans(11,
devc->dso_trigger_width / SR_HZ_TO_NS(devc->cur_rate));
devc->dso_trigger_width /
SR_HZ_TO_NS(devc->cur_rate));
/* Select the SPI/I2C trigger config bank */
ops[7] = mso_trans(REG_CTL2, (devc->ctlbase2 | BITS_CTL2_BANK(2)));
@ -204,7 +203,6 @@ SR_PRIV inline uint16_t mso_calc_raw_from_mv(struct dev_context *devc)
devc->vbit));
}
SR_PRIV int mso_parse_serial(const char *iSerial, const char *iProduct,
struct dev_context *devc)
{
@ -218,7 +216,6 @@ SR_PRIV int mso_parse_serial(const char *iSerial, const char *iProduct,
else
devc->num_sample_rates = 0x10; */
/* parse iSerial */
if (iSerial[0] != '4' || sscanf(iSerial, "%5u%3u%3u%1u%1u%6u",
&u1, &u2, &u3, &u4, &u5, &u6) != 6)
@ -329,10 +326,6 @@ SR_PRIV int mso_configure_rate(struct sr_dev_inst *sdi, uint32_t rate)
return ret;
}
SR_PRIV int mso_check_trigger(struct sr_serial_dev_inst *serial, uint8_t * info)
{
uint16_t ops[] = { mso_trans(REG_TRIGGER, 0) };
@ -343,7 +336,6 @@ SR_PRIV int mso_check_trigger(struct sr_serial_dev_inst *serial, uint8_t *info)
if (info == NULL || ret != SR_OK)
return ret;
uint8_t buf = 0;
if (serial_read(serial, &buf, 1) != 1) /* FIXME: Need timeout */
ret = SR_ERR;
@ -355,7 +347,6 @@ SR_PRIV int mso_check_trigger(struct sr_serial_dev_inst *serial, uint8_t *info)
SR_PRIV int mso_receive_data(int fd, int revents, void *cb_data)
{
struct sr_datafeed_packet packet;
struct sr_datafeed_logic logic;
struct sr_dev_inst *sdi;
@ -451,7 +442,6 @@ SR_PRIV int mso_configure_probes(const struct sr_dev_inst *sdi)
int probe_bit, stage, i;
char *tc;
devc = sdi->priv;
devc->la_trigger_mask = 0xFF; //the mask for the LA_TRIGGER (bits set to 0 matter, those set to 1 are ignored).
@ -482,6 +472,3 @@ SR_PRIV int mso_configure_probes(const struct sr_dev_inst *sdi)
return SR_OK;
}

View File

@ -22,9 +22,6 @@
#ifndef LIBSIGROK_HARDWARE_LINK_MSO19_PROTOCOL_H
#define LIBSIGROK_HARDWARE_LINK_MSO19_PROTOCOL_H
#define USB_VENDOR "3195"
#define USB_PRODUCT "f190"
#include <stdint.h>
#include <string.h>
#include <glib.h>
@ -40,6 +37,9 @@
#define sr_warn(s, args...) sr_warn(DRIVER_LOG_DOMAIN s, ## args)
#define sr_err(s, args...) sr_err(DRIVER_LOG_DOMAIN s, ## args)
#define USB_VENDOR "3195"
#define USB_PRODUCT "f190"
#define NUM_PROBES 8
#define NUM_TRIGGER_STAGES 4
#define TRIGGER_TYPES "01" //the first r/f is used for the whole group
@ -129,7 +129,8 @@ struct dev_context {
SR_PRIV int mso_parse_serial(const char *iSerial, const char *iProduct,
struct dev_context *ctx);
SR_PRIV int mso_check_trigger(struct sr_serial_dev_inst *serial, uint8_t *info);
SR_PRIV int mso_check_trigger(struct sr_serial_dev_inst *serial,
uint8_t * info);
SR_PRIV int mso_reset_adc(struct sr_dev_inst *sdi);
SR_PRIV int mso_clkrate_out(struct sr_serial_dev_inst *serial, uint16_t val);
SR_PRIV int mso_configure_rate(struct sr_dev_inst *sdi, uint32_t rate);
@ -147,9 +148,6 @@ SR_PRIV int mso_toggle_led(struct sr_dev_inst *sdi, int state);
SR_PRIV int mso_configure_probes(const struct sr_dev_inst *sdi);
SR_PRIV void stop_acquisition(const struct sr_dev_inst *sdi);
///////////////////////
//
/* serial protocol */
#define mso_trans(a, v) \
(((v) & 0x3f) | (((v) & 0xc0) << 6) | (((a) & 0xf) << 8) | \
@ -211,9 +209,9 @@ static struct rate_map rate_map[] = {
{ SR_KHZ(5), 0x03c7, 0x20 },
{ SR_KHZ(2), 0x07f3, 0x20 },
{ SR_KHZ(1), 0x0fe7, 0x20 },
{ 500, 0x1fcf, 0x20 },
{ 200, 0x4f87, 0x20 },
{ 100, 0x9f0f, 0x20 },
{ SR_HZ(500), 0x1fcf, 0x20 },
{ SR_HZ(200), 0x4f87, 0x20 },
{ SR_HZ(100), 0x9f0f, 0x20 },
};
/* FIXME: Determine corresponding voltages */