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

View File

@ -68,13 +68,11 @@ ret:
return ret; return ret;
} }
SR_PRIV int mso_configure_trigger(struct sr_dev_inst *sdi) SR_PRIV int mso_configure_trigger(struct sr_dev_inst *sdi)
{ {
struct dev_context *devc = sdi->priv; struct dev_context *devc = sdi->priv;
uint16_t threshold_value = mso_calc_raw_from_mv(devc); uint16_t threshold_value = mso_calc_raw_from_mv(devc);
threshold_value = 0x153C; threshold_value = 0x153C;
uint8_t trigger_config = 0; 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[5] = mso_trans(8, devc->trigger_holdoff[1]);
ops[6] = mso_trans(11, 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 */ /* Select the SPI/I2C trigger config bank */
ops[7] = mso_trans(REG_CTL2, (devc->ctlbase2 | BITS_CTL2_BANK(2))); ops[7] = mso_trans(REG_CTL2, (devc->ctlbase2 | BITS_CTL2_BANK(2)));
@ -197,14 +196,13 @@ SR_PRIV int mso_dac_out(struct sr_dev_inst *sdi, uint16_t val)
return mso_send_control_message(devc->serial, ARRAY_AND_SIZE(ops)); return mso_send_control_message(devc->serial, ARRAY_AND_SIZE(ops));
} }
SR_PRIV inline uint16_t mso_calc_raw_from_mv(struct dev_context *devc) SR_PRIV inline uint16_t mso_calc_raw_from_mv(struct dev_context * devc)
{ {
return (uint16_t) (0x200 - return (uint16_t) (0x200 -
((devc->dso_trigger_voltage / devc->dso_probe_attn) / ((devc->dso_trigger_voltage / devc->dso_probe_attn) /
devc->vbit)); devc->vbit));
} }
SR_PRIV int mso_parse_serial(const char *iSerial, const char *iProduct, SR_PRIV int mso_parse_serial(const char *iSerial, const char *iProduct,
struct dev_context *devc) struct dev_context *devc)
{ {
@ -218,7 +216,6 @@ SR_PRIV int mso_parse_serial(const char *iSerial, const char *iProduct,
else else
devc->num_sample_rates = 0x10; */ devc->num_sample_rates = 0x10; */
/* parse iSerial */ /* parse iSerial */
if (iSerial[0] != '4' || sscanf(iSerial, "%5u%3u%3u%1u%1u%6u", if (iSerial[0] != '4' || sscanf(iSerial, "%5u%3u%3u%1u%1u%6u",
&u1, &u2, &u3, &u4, &u5, &u6) != 6) &u1, &u2, &u3, &u4, &u5, &u6) != 6)
@ -329,11 +326,7 @@ SR_PRIV int mso_configure_rate(struct sr_dev_inst *sdi, uint32_t rate)
return ret; return ret;
} }
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)
{ {
uint16_t ops[] = { mso_trans(REG_TRIGGER, 0) }; uint16_t ops[] = { mso_trans(REG_TRIGGER, 0) };
int ret; int ret;
@ -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) if (info == NULL || ret != SR_OK)
return ret; return ret;
uint8_t buf = 0; uint8_t buf = 0;
if (serial_read(serial, &buf, 1) != 1) /* FIXME: Need timeout */ if (serial_read(serial, &buf, 1) != 1) /* FIXME: Need timeout */
ret = SR_ERR; 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) SR_PRIV int mso_receive_data(int fd, int revents, void *cb_data)
{ {
struct sr_datafeed_packet packet; struct sr_datafeed_packet packet;
struct sr_datafeed_logic logic; struct sr_datafeed_logic logic;
struct sr_dev_inst *sdi; 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; int probe_bit, stage, i;
char *tc; char *tc;
devc = sdi->priv; 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). 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; return SR_OK;
} }

View File

@ -22,9 +22,6 @@
#ifndef LIBSIGROK_HARDWARE_LINK_MSO19_PROTOCOL_H #ifndef LIBSIGROK_HARDWARE_LINK_MSO19_PROTOCOL_H
#define 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 <stdint.h>
#include <string.h> #include <string.h>
#include <glib.h> #include <glib.h>
@ -40,6 +37,9 @@
#define sr_warn(s, args...) sr_warn(DRIVER_LOG_DOMAIN s, ## args) #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 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_PROBES 8
#define NUM_TRIGGER_STAGES 4 #define NUM_TRIGGER_STAGES 4
#define TRIGGER_TYPES "01" //the first r/f is used for the whole group #define TRIGGER_TYPES "01" //the first r/f is used for the whole group
@ -73,7 +73,7 @@ struct mso_patgen {
uint8_t config; uint8_t config;
/* Samples buffer */ /* Samples buffer */
uint8_t buffer[1024]; uint8_t buffer[1024];
/* Input/output configuration for the samples buffer (?)*/ /* Input/output configuration for the samples buffer (?) */
uint8_t io[1024]; uint8_t io[1024];
/* Number of loops for the pattern generator */ /* Number of loops for the pattern generator */
uint8_t loops; uint8_t loops;
@ -129,7 +129,8 @@ struct dev_context {
SR_PRIV int mso_parse_serial(const char *iSerial, const char *iProduct, SR_PRIV int mso_parse_serial(const char *iSerial, const char *iProduct,
struct dev_context *ctx); 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_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_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); 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 int mso_configure_probes(const struct sr_dev_inst *sdi);
SR_PRIV void stop_acquisition(const struct sr_dev_inst *sdi); SR_PRIV void stop_acquisition(const struct sr_dev_inst *sdi);
///////////////////////
//
/* serial protocol */ /* serial protocol */
#define mso_trans(a, v) \ #define mso_trans(a, v) \
(((v) & 0x3f) | (((v) & 0xc0) << 6) | (((a) & 0xf) << 8) | \ (((v) & 0x3f) | (((v) & 0xc0) << 6) | (((a) & 0xf) << 8) | \
@ -173,7 +171,7 @@ SR_PRIV static const char mso_foot[] = { 0x7e };
/* bank 2 registers (SPI/I2C protocol trigger) */ /* bank 2 registers (SPI/I2C protocol trigger) */
#define REG_PT_WORD(x) (x) #define REG_PT_WORD(x) (x)
#define REG_PT_MASK(x) (x+4) #define REG_PT_MASK(x) (x + 4)
#define REG_PT_SPIMODE 8 #define REG_PT_SPIMODE 8
/* bits - REG_CTL1 */ /* bits - REG_CTL1 */
@ -211,9 +209,9 @@ static struct rate_map rate_map[] = {
{ SR_KHZ(5), 0x03c7, 0x20 }, { SR_KHZ(5), 0x03c7, 0x20 },
{ SR_KHZ(2), 0x07f3, 0x20 }, { SR_KHZ(2), 0x07f3, 0x20 },
{ SR_KHZ(1), 0x0fe7, 0x20 }, { SR_KHZ(1), 0x0fe7, 0x20 },
{ 500, 0x1fcf, 0x20 }, { SR_HZ(500), 0x1fcf, 0x20 },
{ 200, 0x4f87, 0x20 }, { SR_HZ(200), 0x4f87, 0x20 },
{ 100, 0x9f0f, 0x20 }, { SR_HZ(100), 0x9f0f, 0x20 },
}; };
/* FIXME: Determine corresponding voltages */ /* FIXME: Determine corresponding voltages */