scanalogic2: Cosmetics, whitespace, typos, etc.

This commit is contained in:
Uwe Hermann 2013-06-11 18:55:47 +02:00
parent e52e712d05
commit c824eb6323
3 changed files with 56 additions and 74 deletions

View File

@ -24,7 +24,7 @@ static const int hwcaps[] = {
SR_CONF_SAMPLERATE, SR_CONF_SAMPLERATE,
SR_CONF_LIMIT_SAMPLES, SR_CONF_LIMIT_SAMPLES,
SR_CONF_TRIGGER_TYPE, SR_CONF_TRIGGER_TYPE,
SR_CONF_CAPTURE_RATIO SR_CONF_CAPTURE_RATIO,
}; };
SR_PRIV const uint64_t ikalogic_scanalogic2_samplerates[NUM_SAMPLERATES] = { SR_PRIV const uint64_t ikalogic_scanalogic2_samplerates[NUM_SAMPLERATES] = {
@ -38,12 +38,12 @@ SR_PRIV const uint64_t ikalogic_scanalogic2_samplerates[NUM_SAMPLERATES] = {
SR_MHZ(2.5), SR_MHZ(2.5),
SR_MHZ(5), SR_MHZ(5),
SR_MHZ(10), SR_MHZ(10),
SR_MHZ(20) SR_MHZ(20),
}; };
static const char *probe_names[NUM_PROBES + 1] = { static const char *probe_names[NUM_PROBES + 1] = {
"0", "1", "2", "3", "0", "1", "2", "3",
NULL NULL,
}; };
SR_PRIV struct sr_dev_driver ikalogic_scanalogic2_driver_info; SR_PRIV struct sr_dev_driver ikalogic_scanalogic2_driver_info;
@ -78,21 +78,17 @@ static GSList *scan(GSList *options)
if (usb_devices == NULL) if (usb_devices == NULL)
return NULL; return NULL;
for (l = usb_devices; l; l = l->next) for (l = usb_devices; l; l = l->next) {
{
usb = l->data; usb = l->data;
ret = ikalogic_scanalogic2_get_device_info(*usb, &dev_info); ret = ikalogic_scanalogic2_get_device_info(*usb, &dev_info);
if (ret != SR_OK) { if (ret != SR_OK) {
sr_warn("Failed to get device information.\n"); sr_warn("Failed to get device information.");
sr_usb_dev_inst_free(usb); sr_usb_dev_inst_free(usb);
continue; continue;
} }
devc = g_try_malloc(sizeof(struct dev_context)); if (!(devc = g_try_malloc(sizeof(struct dev_context)))) {
if (!devc) {
sr_err("Device instance malloc failed."); sr_err("Device instance malloc failed.");
sr_usb_dev_inst_free(usb); sr_usb_dev_inst_free(usb);
continue; continue;
@ -115,7 +111,6 @@ static GSList *scan(GSList *options)
fw_ver_str = g_strdup_printf("%u.%u", dev_info.fw_ver_major, fw_ver_str = g_strdup_printf("%u.%u", dev_info.fw_ver_major,
dev_info.fw_ver_minor); dev_info.fw_ver_minor);
if (!fw_ver_str) { if (!fw_ver_str) {
sr_err("Firmware string malloc failed."); sr_err("Firmware string malloc failed.");
sr_usb_dev_inst_free(usb); sr_usb_dev_inst_free(usb);
@ -127,9 +122,7 @@ static GSList *scan(GSList *options)
sdi = sr_dev_inst_new(device_index, SR_ST_INACTIVE, VENDOR_NAME, sdi = sr_dev_inst_new(device_index, SR_ST_INACTIVE, VENDOR_NAME,
MODEL_NAME, fw_ver_str); MODEL_NAME, fw_ver_str);
g_free(fw_ver_str); g_free(fw_ver_str);
if (!sdi) { if (!sdi) {
sr_err("sr_dev_inst_new failed."); sr_err("sr_dev_inst_new failed.");
sr_usb_dev_inst_free(usb); sr_usb_dev_inst_free(usb);
@ -195,18 +188,16 @@ static GSList *scan(GSList *options)
static GSList *dev_list(void) static GSList *dev_list(void)
{ {
struct drv_context *drvc; return ((struct drv_context *)(di->priv))->instances;
drvc = di->priv;
return drvc->instances;
} }
static void clear_dev_context(void *priv) static void clear_dev_context(void *priv)
{ {
struct dev_context *devc = priv; struct dev_context *devc;
sr_dbg("Device context cleard."); devc = priv;
sr_dbg("Device context cleared.");
libusb_free_transfer(devc->xfer_in); libusb_free_transfer(devc->xfer_in);
libusb_free_transfer(devc->xfer_out); libusb_free_transfer(devc->xfer_out);
@ -243,7 +234,6 @@ static int dev_open(struct sr_dev_inst *sdi)
*/ */
if (libusb_kernel_driver_active(usb->devhdl, USB_INTERFACE) == 1) { if (libusb_kernel_driver_active(usb->devhdl, USB_INTERFACE) == 1) {
ret = libusb_detach_kernel_driver(usb->devhdl, USB_INTERFACE); ret = libusb_detach_kernel_driver(usb->devhdl, USB_INTERFACE);
if (ret < 0) { if (ret < 0) {
sr_err("Failed to detach kernel driver: %i.", sr_err("Failed to detach kernel driver: %i.",
libusb_error_name(ret)); libusb_error_name(ret));
@ -252,7 +242,6 @@ static int dev_open(struct sr_dev_inst *sdi)
} }
ret = libusb_claim_interface(usb->devhdl, USB_INTERFACE); ret = libusb_claim_interface(usb->devhdl, USB_INTERFACE);
if (ret) { if (ret) {
sr_err("Failed to claim interface: %s.", sr_err("Failed to claim interface: %s.",
libusb_error_name(ret)); libusb_error_name(ret));
@ -271,7 +260,6 @@ static int dev_open(struct sr_dev_inst *sdi)
buffer[0] = CMD_RESET; buffer[0] = CMD_RESET;
ret = ikalogic_scanalogic2_transfer_out(usb->devhdl, buffer); ret = ikalogic_scanalogic2_transfer_out(usb->devhdl, buffer);
if (ret != PACKET_LENGTH) { if (ret != PACKET_LENGTH) {
sr_err("Device reset failed: %s.", libusb_error_name(ret)); sr_err("Device reset failed: %s.", libusb_error_name(ret));
return SR_ERR; return SR_ERR;
@ -279,12 +267,11 @@ static int dev_open(struct sr_dev_inst *sdi)
/* /*
* Set the device to idle state. If the device is not in idle state it * Set the device to idle state. If the device is not in idle state it
* possibly will reset itself after a few seconds without being used and * possibly will reset itself after a few seconds without being used
* thereby close the connection. * and thereby close the connection.
*/ */
buffer[0] = CMD_IDLE; buffer[0] = CMD_IDLE;
ret = ikalogic_scanalogic2_transfer_out(usb->devhdl, buffer); ret = ikalogic_scanalogic2_transfer_out(usb->devhdl, buffer);
if (ret != PACKET_LENGTH) { if (ret != PACKET_LENGTH) {
sr_err("Failed to set device in idle state: %s.", sr_err("Failed to set device in idle state: %s.",
libusb_error_name(ret)); libusb_error_name(ret));
@ -321,9 +308,7 @@ static int dev_close(struct sr_dev_inst *sdi)
static int cleanup(void) static int cleanup(void)
{ {
dev_clear(); return dev_clear();
return SR_OK;
} }
static int config_get(int key, GVariant **data, const struct sr_dev_inst *sdi) static int config_get(int key, GVariant **data, const struct sr_dev_inst *sdi)
@ -498,12 +483,11 @@ static int dev_acquisition_start(const struct sr_dev_inst *sdi, void *cb_data)
if (!(devc->usbfd = g_try_malloc(devc->num_usbfd * sizeof(int)))) { if (!(devc->usbfd = g_try_malloc(devc->num_usbfd * sizeof(int)))) {
sr_err("File descriptor array malloc failed."); sr_err("File descriptor array malloc failed.");
free(pfd); free(pfd);
return SR_ERR_MALLOC; return SR_ERR_MALLOC;
} }
if ((ret = libusb_submit_transfer(devc->xfer_out)) != 0) { if ((ret = libusb_submit_transfer(devc->xfer_out)) != 0) {
sr_err("Submit transfer failed: %s", libusb_error_name(ret)); sr_err("Submit transfer failed: %s.", libusb_error_name(ret));
g_free(devc->usbfd); g_free(devc->usbfd);
return SR_ERR; return SR_ERR;
} }

View File

@ -111,8 +111,8 @@ static void process_sample_data(const struct sr_dev_inst *sdi)
ptr[i] = devc->sample_buffer[devc->probe_map[i]] + offset; ptr[i] = devc->sample_buffer[devc->probe_map[i]] + offset;
/* /*
* Skip the first 4 bytes of the buffer because they contain channel and * Skip the first 4 bytes of the buffer because they contain channel
* packet information only. * and packet information only.
*/ */
ptr[i] = devc->xfer_data_in + 4; ptr[i] = devc->xfer_data_in + 4;
@ -128,19 +128,18 @@ static void process_sample_data(const struct sr_dev_inst *sdi)
* Adjust the position of the first sample to be * Adjust the position of the first sample to be
* processed because possibly more samples than * processed because possibly more samples than
* necessary might have been aquired. This is because * necessary might have been aquired. This is because
* the number of aquired samples is always rounded up to * the number of aquired samples is always rounded up
* a multiple of 8. * to a multiple of 8.
*/ */
k = k - (devc->pre_trigger_bytes * 8) + k = k - (devc->pre_trigger_bytes * 8) +
devc->pre_trigger_samples; devc->pre_trigger_samples;
sr_dbg("Start processing at sample: %" PRIu8 ".", sr_dbg("Start processing at sample: %d.", 7 - k);
7 - k);
/* /*
* Send the trigger before the first sample is processed * Send the trigger before the first sample is
* if no pre trigger samples were calculated through the * processed if no pre trigger samples were calculated
* capture ratio. * through the capture ratio.
*/ */
if (devc->trigger_type != TRIGGER_TYPE_NONE && if (devc->trigger_type != TRIGGER_TYPE_NONE &&
devc->pre_trigger_samples == 0) { devc->pre_trigger_samples == 0) {
@ -230,9 +229,9 @@ SR_PRIV int ikalogic_scanalogic2_receive_data(int fd, int revents,
time_elapsed = current_time - devc->wait_data_ready_time; time_elapsed = current_time - devc->wait_data_ready_time;
/* /*
* Check here for stopping in addition to the transfer callback * Check here for stopping in addition to the transfer
* functions to avoid waiting until the WAIT_DATA_READY_INTERVAL * callback functions to avoid waiting until the
* has expired. * WAIT_DATA_READY_INTERVAL has expired.
*/ */
if (sdi->status == SR_ST_STOPPING) { if (sdi->status == SR_ST_STOPPING) {
if (!devc->stopping_in_progress) { if (!devc->stopping_in_progress) {
@ -247,7 +246,7 @@ SR_PRIV int ikalogic_scanalogic2_receive_data(int fd, int revents,
} }
if (ret != 0) { if (ret != 0) {
sr_err("Submit transfer failed: %s", libusb_error_name(ret)); sr_err("Submit transfer failed: %s.", libusb_error_name(ret));
abort_acquisition(sdi); abort_acquisition(sdi);
return TRUE; return TRUE;
} }
@ -259,9 +258,8 @@ SR_PRIV int ikalogic_scanalogic2_receive_data(int fd, int revents,
NULL); NULL);
/* Check if an error occurred on a transfer. */ /* Check if an error occurred on a transfer. */
if (devc->transfer_error) { if (devc->transfer_error)
abort_acquisition(sdi); abort_acquisition(sdi);
}
return TRUE; return TRUE;
} }
@ -278,7 +276,7 @@ SR_PRIV void ikalogic_scanalogic2_receive_transfer_in(
devc = sdi->priv; devc = sdi->priv;
if (transfer->status != LIBUSB_TRANSFER_COMPLETED) { if (transfer->status != LIBUSB_TRANSFER_COMPLETED) {
sr_err("Transfer to device failed: %i", transfer->status); sr_err("Transfer to device failed: %i.", transfer->status);
devc->transfer_error = TRUE; devc->transfer_error = TRUE;
return; return;
} }
@ -288,7 +286,7 @@ SR_PRIV void ikalogic_scanalogic2_receive_transfer_in(
devc->stopping_in_progress = TRUE; devc->stopping_in_progress = TRUE;
if (libusb_submit_transfer(devc->xfer_in) != 0) { if (libusb_submit_transfer(devc->xfer_in) != 0) {
sr_err("Submit transfer failed: %s", sr_err("Submit transfer failed: %s.",
libusb_error_name(ret)); libusb_error_name(ret));
devc->transfer_error = TRUE; devc->transfer_error = TRUE;
} }
@ -296,7 +294,7 @@ SR_PRIV void ikalogic_scanalogic2_receive_transfer_in(
return; return;
} }
sr_dbg("State changed from %i to %i.", devc->state, devc->next_state); sr_spew("State changed from %i to %i.", devc->state, devc->next_state);
devc->state = devc->next_state; devc->state = devc->next_state;
if (devc->state == STATE_WAIT_DATA_READY) { if (devc->state == STATE_WAIT_DATA_READY) {
@ -356,10 +354,10 @@ SR_PRIV void ikalogic_scanalogic2_receive_transfer_in(
ret = libusb_submit_transfer(devc->xfer_out); ret = libusb_submit_transfer(devc->xfer_out);
} else { } else {
/* /*
* The received device status is invalid which indicates * The received device status is invalid which
* that the device is not ready to accept commands. * indicates that the device is not ready to accept
* Request a new device status until a valid device * commands. Request a new device status until a valid
* status is received. * device status is received.
*/ */
ret = libusb_submit_transfer(transfer); ret = libusb_submit_transfer(transfer);
} }
@ -383,15 +381,15 @@ SR_PRIV void ikalogic_scanalogic2_receive_transfer_in(
} else { } else {
/* /*
* The device is not ready and therefore not able to * The device is not ready and therefore not able to
* change to the idle state. Request a new device status * change to the idle state. Request a new device
* until the device is ready. * status until the device is ready.
*/ */
ret = libusb_submit_transfer(transfer); ret = libusb_submit_transfer(transfer);
} }
} }
if (ret != 0) { if (ret != 0) {
sr_err("Submit transfer failed: %s", libusb_error_name(ret)); sr_err("Submit transfer failed: %s.", libusb_error_name(ret));
devc->transfer_error = TRUE; devc->transfer_error = TRUE;
} }
} }
@ -407,7 +405,7 @@ SR_PRIV void ikalogic_scanalogic2_receive_transfer_out(
devc = sdi->priv; devc = sdi->priv;
if (transfer->status != LIBUSB_TRANSFER_COMPLETED) { if (transfer->status != LIBUSB_TRANSFER_COMPLETED) {
sr_err("Transfer to device failed: %i", transfer->status); sr_err("Transfer to device failed: %i.", transfer->status);
devc->transfer_error = TRUE; devc->transfer_error = TRUE;
return; return;
} }
@ -417,7 +415,7 @@ SR_PRIV void ikalogic_scanalogic2_receive_transfer_out(
devc->stopping_in_progress = TRUE; devc->stopping_in_progress = TRUE;
if (libusb_submit_transfer(devc->xfer_in) != 0) { if (libusb_submit_transfer(devc->xfer_in) != 0) {
sr_err("Submit transfer failed: %s", sr_err("Submit transfer failed: %s.",
libusb_error_name(ret)); libusb_error_name(ret));
devc->transfer_error = TRUE; devc->transfer_error = TRUE;
@ -426,7 +424,7 @@ SR_PRIV void ikalogic_scanalogic2_receive_transfer_out(
return; return;
} }
sr_dbg("State changed from %i to %i.", devc->state, devc->next_state); sr_spew("State changed from %i to %i.", devc->state, devc->next_state);
devc->state = devc->next_state; devc->state = devc->next_state;
if (devc->state == STATE_IDLE) { if (devc->state == STATE_IDLE) {
@ -439,7 +437,7 @@ SR_PRIV void ikalogic_scanalogic2_receive_transfer_out(
} }
if (ret != 0) { if (ret != 0) {
sr_err("Submit transfer failed: %s", libusb_error_name(ret)); sr_err("Submit transfer failed: %s.", libusb_error_name(ret));
devc->transfer_error = TRUE; devc->transfer_error = TRUE;
} }
} }
@ -479,7 +477,7 @@ SR_PRIV int ikalogic_scanalogic2_set_limit_samples(
if (limit_samples > MAX_SAMPLES) if (limit_samples > MAX_SAMPLES)
limit_samples = MAX_SAMPLES; limit_samples = MAX_SAMPLES;
sr_info("Limit samples set to %" PRIu64 ".", limit_samples); sr_dbg("Limit samples set to %" PRIu64 ".", limit_samples);
devc->limit_samples = limit_samples; devc->limit_samples = limit_samples;
@ -539,7 +537,7 @@ SR_PRIV void ikalogic_scanalogic2_configure_trigger(
devc->trigger_type = TRIGGER_TYPE_ANYEDGE; devc->trigger_type = TRIGGER_TYPE_ANYEDGE;
} }
sr_dbg("Trigger set to channel %" PRIu8 " and type %" PRIu8 ".", sr_dbg("Trigger set to channel 0x%02x and type 0x%02x.",
devc->trigger_channel, devc->trigger_type); devc->trigger_channel, devc->trigger_type);
} }
@ -562,7 +560,7 @@ SR_PRIV int ikalogic_scanalogic2_set_capture_ratio(
return SR_OK; return SR_OK;
} }
SR_PRIV int ikaloigc_scanalogic2_set_after_trigger_delay( SR_PRIV int ikalogic_scanalogic2_set_after_trigger_delay(
const struct sr_dev_inst *sdi, uint64_t after_trigger_delay) const struct sr_dev_inst *sdi, uint64_t after_trigger_delay)
{ {
struct dev_context *devc; struct dev_context *devc;
@ -619,8 +617,8 @@ SR_PRIV void ikalogic_scanalogic2_calculate_trigger_samples(
* Round up the number of sample bytes to ensure that at least the * Round up the number of sample bytes to ensure that at least the
* requested number of samples will be acquired. Note that due to this * requested number of samples will be acquired. Note that due to this
* rounding the buffer to store these sample bytes needs to be at least * rounding the buffer to store these sample bytes needs to be at least
* one sample byte larger than the minimal number of sample bytes needed * one sample byte larger than the minimal number of sample bytes
* to store the requested samples. * needed to store the requested samples.
*/ */
if (pre_trigger_samples % 8 != 0) if (pre_trigger_samples % 8 != 0)
pre_trigger_bytes++; pre_trigger_bytes++;
@ -734,8 +732,8 @@ SR_PRIV int ikalogic_scanalogic2_get_device_info(struct sr_usb_dev_inst usb,
/* /*
* Set the device to idle state. If the device is not in idle state it * Set the device to idle state. If the device is not in idle state it
* possibly will reset itself after a few seconds without being used and * possibly will reset itself after a few seconds without being used
* thereby close the connection. * and thereby close the connection.
*/ */
buffer[0] = CMD_IDLE; buffer[0] = CMD_IDLE;
ret = ikalogic_scanalogic2_transfer_out(usb.devhdl, buffer); ret = ikalogic_scanalogic2_transfer_out(usb.devhdl, buffer);
@ -763,17 +761,17 @@ SR_PRIV int ikalogic_scanalogic2_get_device_info(struct sr_usb_dev_inst usb,
} }
SR_PRIV int ikalogic_scanalogic2_transfer_in(libusb_device_handle *dev_handle, SR_PRIV int ikalogic_scanalogic2_transfer_in(libusb_device_handle *dev_handle,
unsigned char *data) uint8_t *data)
{ {
return libusb_control_transfer(dev_handle, USB_REQUEST_TYPE_IN, return libusb_control_transfer(dev_handle, USB_REQUEST_TYPE_IN,
USB_HID_SET_REPORT, USB_HID_REPORT_TYPE_FEATURE, USB_INTERFACE, USB_HID_SET_REPORT, USB_HID_REPORT_TYPE_FEATURE, USB_INTERFACE,
data, PACKET_LENGTH, USB_TIMEOUT); (unsigned char *)data, PACKET_LENGTH, USB_TIMEOUT);
} }
SR_PRIV int ikalogic_scanalogic2_transfer_out(libusb_device_handle *dev_handle, SR_PRIV int ikalogic_scanalogic2_transfer_out(libusb_device_handle *dev_handle,
unsigned char *data) uint8_t *data)
{ {
return libusb_control_transfer(dev_handle, USB_REQUEST_TYPE_OUT, return libusb_control_transfer(dev_handle, USB_REQUEST_TYPE_OUT,
USB_HID_SET_REPORT, USB_HID_REPORT_TYPE_FEATURE, USB_INTERFACE, USB_HID_SET_REPORT, USB_HID_REPORT_TYPE_FEATURE, USB_INTERFACE,
data, PACKET_LENGTH, USB_TIMEOUT); (unsigned char *)data, PACKET_LENGTH, USB_TIMEOUT);
} }

View File

@ -241,15 +241,15 @@ SR_PRIV void ikalogic_scanalogic2_configure_trigger(
const struct sr_dev_inst *sdi); const struct sr_dev_inst *sdi);
SR_PRIV int ikalogic_scanalogic2_set_capture_ratio( SR_PRIV int ikalogic_scanalogic2_set_capture_ratio(
const struct sr_dev_inst *sdi, uint64_t capture_ratio); const struct sr_dev_inst *sdi, uint64_t capture_ratio);
SR_PRIV int ikaloigc_scanalogic2_set_after_trigger_delay( SR_PRIV int ikalogic_scanalogic2_set_after_trigger_delay(
const struct sr_dev_inst *sdi, uint64_t after_trigger_delay); const struct sr_dev_inst *sdi, uint64_t after_trigger_delay);
SR_PRIV void ikalogic_scanalogic2_calculate_trigger_samples( SR_PRIV void ikalogic_scanalogic2_calculate_trigger_samples(
const struct sr_dev_inst *sdi); const struct sr_dev_inst *sdi);
SR_PRIV int ikalogic_scanalogic2_get_device_info(struct sr_usb_dev_inst usb, SR_PRIV int ikalogic_scanalogic2_get_device_info(struct sr_usb_dev_inst usb,
struct device_info *dev_info); struct device_info *dev_info);
SR_PRIV int ikalogic_scanalogic2_transfer_in(libusb_device_handle *dev_handle, SR_PRIV int ikalogic_scanalogic2_transfer_in(libusb_device_handle *dev_handle,
unsigned char *data); uint8_t *data);
SR_PRIV int ikalogic_scanalogic2_transfer_out(libusb_device_handle *dev_handle, SR_PRIV int ikalogic_scanalogic2_transfer_out(libusb_device_handle *dev_handle,
unsigned char *data); uint8_t *data);
#endif #endif