ols: Properly initialize operational state before start

This commit is contained in:
Bert Vermeulen 2013-04-15 18:28:16 +02:00
parent e45ad6e24f
commit bf25678359
3 changed files with 30 additions and 13 deletions

View File

@ -151,16 +151,23 @@ static GSList *hw_scan(GSList *options)
sdi = sr_dev_inst_new(0, SR_ST_INACTIVE, sdi = sr_dev_inst_new(0, SR_ST_INACTIVE,
"Sump", "Logic Analyzer", "v1.0"); "Sump", "Logic Analyzer", "v1.0");
sdi->driver = di; sdi->driver = di;
devc = ols_dev_new();
for (i = 0; i < 32; i++) { for (i = 0; i < 32; i++) {
if (!(probe = sr_probe_new(i, SR_PROBE_LOGIC, TRUE, if (!(probe = sr_probe_new(i, SR_PROBE_LOGIC, TRUE,
ols_probe_names[i]))) ols_probe_names[i])))
return 0; return 0;
sdi->probes = g_slist_append(sdi->probes, probe); sdi->probes = g_slist_append(sdi->probes, probe);
} }
devc = ols_dev_new();
sdi->priv = devc; sdi->priv = devc;
} }
/* Configure samplerate and divider. */
if (ols_set_samplerate(sdi, DEFAULT_SAMPLERATE) != SR_OK)
sr_dbg("Failed to set default samplerate (%"PRIu64").",
DEFAULT_SAMPLERATE);
/* Clear trigger masks, values and stages. */
ols_configure_probes(sdi);
devc->serial = serial; devc->serial = serial;
drvc->instances = g_slist_append(drvc->instances, sdi); drvc->instances = g_slist_append(drvc->instances, sdi);
devices = g_slist_append(devices, sdi); devices = g_slist_append(devices, sdi);
@ -472,6 +479,9 @@ static int hw_dev_acquisition_start(const struct sr_dev_inst *sdi,
if (send_shortcommand(devc->serial, CMD_RUN) != SR_OK) if (send_shortcommand(devc->serial, CMD_RUN) != SR_OK)
return SR_ERR; return SR_ERR;
/* Reset all operational states. */
devc->num_transfers = devc->num_samples = devc->num_bytes = 0;
/* Send header packet to the session bus. */ /* Send header packet to the session bus. */
std_session_send_df_header(cb_data, DRIVER_LOG_DOMAIN); std_session_send_df_header(cb_data, DRIVER_LOG_DOMAIN);
@ -481,7 +491,6 @@ static int hw_dev_acquisition_start(const struct sr_dev_inst *sdi,
return SR_OK; return SR_OK;
} }
/* TODO: 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. */ /* Avoid compiler warnings. */

View File

@ -133,14 +133,20 @@ SR_PRIV struct dev_context *ols_dev_new(void)
{ {
struct dev_context *devc; struct dev_context *devc;
if (!(devc = g_try_malloc0(sizeof(struct dev_context)))) { if (!(devc = g_try_malloc(sizeof(struct dev_context)))) {
sr_err("Device context malloc failed."); sr_err("Device context malloc failed.");
return NULL; return NULL;
} }
/* Device-specific settings */
devc->max_samples = devc->max_samplerate = devc->protocol_version = 0;
/* Acquisition settings */
devc->limit_samples = devc->capture_ratio = 0;
devc->trigger_at = -1; devc->trigger_at = -1;
devc->probe_mask = 0xffffffff; devc->probe_mask = 0xffffffff;
devc->cur_samplerate = SR_KHZ(200); devc->flag_reg = 0;
devc->serial = NULL; devc->serial = NULL;
return devc; return devc;

View File

@ -41,6 +41,7 @@
#define SERIAL_SPEED B115200 #define SERIAL_SPEED B115200
#define CLOCK_RATE SR_MHZ(100) #define CLOCK_RATE SR_MHZ(100)
#define MIN_NUM_SAMPLES 4 #define MIN_NUM_SAMPLES 4
#define DEFAULT_SAMPLERATE SR_KHZ(200)
/* Command opcodes */ /* Command opcodes */
#define CMD_RESET 0x00 #define CMD_RESET 0x00
@ -76,34 +77,35 @@
/* Private, per-device-instance driver context. */ /* Private, per-device-instance driver context. */
struct dev_context { struct dev_context {
uint32_t max_samplerate; struct sr_serial_dev_inst *serial;
/* Fixed device settings */
uint32_t max_samples; uint32_t max_samples;
uint32_t max_samplerate;
uint32_t protocol_version; uint32_t protocol_version;
/* Acquisition settings */
uint64_t cur_samplerate; uint64_t cur_samplerate;
uint32_t cur_samplerate_divider; uint32_t cur_samplerate_divider;
uint64_t limit_samples; uint64_t limit_samples;
/* Current state of the flag register */
uint32_t flag_reg;
/* Pre/post trigger capture ratio, in percentage.
* 0 means no pre-trigger data. */
int capture_ratio; int capture_ratio;
int trigger_at; int trigger_at;
uint32_t probe_mask; uint32_t probe_mask;
uint32_t trigger_mask[4]; uint32_t trigger_mask[4];
uint32_t trigger_value[4]; uint32_t trigger_value[4];
int num_stages; int num_stages;
uint32_t flag_reg;
/* Operational states */
unsigned int num_transfers; unsigned int num_transfers;
unsigned int num_samples; unsigned int num_samples;
int rle_count;
int num_bytes; int num_bytes;
/* Temporary variables */
int rle_count;
unsigned char sample[4]; unsigned char sample[4];
unsigned char tmp_sample[4]; unsigned char tmp_sample[4];
unsigned char *raw_sample_buf; unsigned char *raw_sample_buf;
struct sr_serial_dev_inst *serial;
}; };