#include <ftdi.h>
#include <glib.h>
+#include <string.h>
#include <sigrok.h>
#include <sigrok-internal.h>
/** The current sampling limit (in number of samples). */
uint64_t limit_samples;
- /** The number of probes. */
- int num_probes;
-
/** TODO */
gpointer session_id;
/**
- * An 8MB buffer containing the (mangled) samples from the device.
+ * An 4KB buffer containing some (mangled) samples from the device.
* Format: Pretty mangled-up (due to hardware reasons), see code.
*/
- uint8_t *mangled_buf;
+ uint8_t mangled_buf[4096];
/**
* An 8MB buffer where we'll store the de-mangled samples.
la8->cur_samplerate = SR_MHZ(100); /* 100MHz == max. samplerate */
la8->limit_msec = 0;
la8->limit_samples = 0;
- la8->num_probes = NUM_PROBES;
la8->session_id = NULL;
- la8->mangled_buf = NULL;
+ memset(la8->mangled_buf, 0, 4096);
la8->final_buf = NULL;
la8->trigger_pattern = 0x00; /* Value irrelevant, see trigger_mask. */
la8->trigger_mask = 0x00; /* All probes are "don't care". */
la8->block_counter = 0;
la8->divcount = 0; /* 10ns sample period == 100MHz samplerate */
- /* Allocate memory for the raw (mangled) data from the LA8. */
- if (!(la8->mangled_buf = g_try_malloc(SDRAM_SIZE))) {
- sr_err("la8: %s: mangled_buf malloc failed", __func__);
- ret = SR_ERR_MALLOC;
- goto err_free_la8;
- }
-
/* Allocate memory where we'll store the de-mangled data. */
if (!(la8->final_buf = g_try_malloc(SDRAM_SIZE))) {
sr_err("la8: %s: final_buf malloc failed", __func__);
ret = SR_ERR_MALLOC;
- goto err_free_mangled_buf;
+ goto err_free_la8;
}
/* Allocate memory for the FTDI context (ftdic) and initialize it. */
free(la8->ftdic); /* NOT g_free()! */
err_free_final_buf:
g_free(la8->final_buf);
-err_free_mangled_buf:
- g_free(la8->mangled_buf);
err_free_la8:
g_free(la8);
err_free_nothing:
return SR_OK;
}
-static void hw_closedev(int device_index)
+static int hw_closedev(int device_index)
{
struct sr_device_instance *sdi;
struct la8 *la8;
if (!(sdi = sr_get_device_instance(device_instances, device_index))) {
sr_err("la8: %s: sdi was NULL", __func__);
- return;
+ return SR_ERR; /* TODO: SR_ERR_ARG? */
}
if (!(la8 = sdi->priv)) {
sr_err("la8: %s: sdi->priv was NULL", __func__);
- return;
+ return SR_ERR; /* TODO: SR_ERR_ARG? */
}
sr_dbg("la8: closing device");
if (sdi->status == SR_ST_ACTIVE) {
sr_dbg("la8: %s: status ACTIVE, closing device", __func__);
+ /* TODO: Really ignore errors here, or return SR_ERR? */
(void) la8_close_usb_reset_sequencer(la8); /* Ignore errors. */
} else {
sr_dbg("la8: %s: status not ACTIVE, nothing to do", __func__);
sdi->status = SR_ST_INACTIVE;
sr_dbg("la8: %s: freeing sample buffers", __func__);
- free(la8->mangled_buf);
- free(la8->final_buf);
+ g_free(la8->final_buf);
+
+ return SR_OK;
}
static void hw_cleanup(void)
gettimeofday(&header.starttime, NULL);
header.samplerate = la8->cur_samplerate;
header.protocol_id = SR_PROTO_RAW;
- header.num_logic_probes = la8->num_probes;
+ header.num_logic_probes = NUM_PROBES;
header.num_analog_probes = 0;
sr_session_bus(session_device_id, &packet);
.api_version = 1,
.init = hw_init,
.cleanup = hw_cleanup,
- .open = hw_opendev,
- .close = hw_closedev,
+ .opendev = hw_opendev,
+ .closedev = hw_closedev,
.get_device_info = hw_get_device_info,
.get_status = hw_get_status,
.get_capabilities = hw_get_capabilities,