if (!g_file_test(BEAGLELOGIC_DEV_NODE, G_FILE_TEST_EXISTS))
return NULL;
- sdi = g_malloc0(sizeof(struct sr_dev_inst));
- sdi->status = SR_ST_INACTIVE;
- sdi->model = g_strdup("BeagleLogic");
- sdi->version = g_strdup("1.0");
-
- /* Unless explicitly specified, keep max channels to 8 only */
- maxch = 8;
+ maxch = NUM_CHANNELS;
for (l = options; l; l = l->next) {
src = l->data;
if (src->key == SR_CONF_NUM_LOGIC_CHANNELS)
maxch = g_variant_get_int32(src->data);
}
- /* We need to test for number of channels by opening the node */
- devc = beaglelogic_devc_alloc();
-
- if (beaglelogic_open_nonblock(devc) != SR_OK) {
- g_free(devc);
- sr_dev_inst_free(sdi);
-
- return NULL;
- }
-
- if (maxch > 8) {
+ if (maxch > 8)
maxch = NUM_CHANNELS;
- devc->sampleunit = BL_SAMPLEUNIT_16_BITS;
- } else {
+ else
maxch = 8;
- devc->sampleunit = BL_SAMPLEUNIT_8_BITS;
- }
- beaglelogic_set_sampleunit(devc);
- beaglelogic_close(devc);
+ sdi = g_new0(struct sr_dev_inst, 1);
+ sdi->status = SR_ST_INACTIVE;
+ sdi->model = g_strdup("BeagleLogic");
+ sdi->version = g_strdup("1.0");
+
+ devc = beaglelogic_devc_alloc();
- sr_info("BeagleLogic device found at "BEAGLELOGIC_DEV_NODE);
+ devc->beaglelogic = &beaglelogic_native_ops;
+ /* Fill the channels */
for (i = 0; i < maxch; i++)
sr_channel_new(sdi, i, SR_CHANNEL_LOGIC, TRUE,
channel_names[i]);
sdi->priv = devc;
+ /* Signal */
+ sr_info("BeagleLogic device found at "BEAGLELOGIC_DEV_NODE);
+
return std_scan_complete(di, g_slist_append(NULL, sdi));
}
struct dev_context *devc = sdi->priv;
/* Open BeagleLogic */
- if (beaglelogic_open_nonblock(devc))
+ if (devc->beaglelogic->open(devc))
return SR_ERR;
/* Set fd and local attributes */
devc->pollfd.revents = 0;
/* Get the default attributes */
- beaglelogic_get_samplerate(devc);
- beaglelogic_get_sampleunit(devc);
- beaglelogic_get_triggerflags(devc);
- beaglelogic_get_buffersize(devc);
- beaglelogic_get_bufunitsize(devc);
+ devc->beaglelogic->get_samplerate(devc);
+ devc->beaglelogic->get_sampleunit(devc);
+ devc->beaglelogic->get_buffersize(devc);
+ devc->beaglelogic->get_bufunitsize(devc);
+
+ /* Set the triggerflags to default for continuous capture unless we
+ * explicitly limit samples using SR_CONF_LIMIT_SAMPLES */
+ devc->triggerflags = BL_TRIGGERFLAGS_CONTINUOUS;
+ devc->beaglelogic->set_triggerflags(devc);
/* Map the kernel capture FIFO for reads, saves 1 level of memcpy */
- if (beaglelogic_mmap(devc) != SR_OK) {
+ if (devc->beaglelogic->mmap(devc) != SR_OK) {
sr_err("Unable to map capture buffer");
- beaglelogic_close(devc);
+ devc->beaglelogic->close(devc);
return SR_ERR;
}
struct dev_context *devc = sdi->priv;
/* Close the memory mapping and the file */
- beaglelogic_munmap(devc);
- beaglelogic_close(devc);
+ devc->beaglelogic->munmap(devc);
+ devc->beaglelogic->close(devc);
return SR_OK;
}
-static int config_get(uint32_t key, GVariant **data, const struct sr_dev_inst *sdi,
- const struct sr_channel_group *cg)
+static int config_get(uint32_t key, GVariant **data,
+ const struct sr_dev_inst *sdi, const struct sr_channel_group *cg)
{
struct dev_context *devc = sdi->priv;
return SR_OK;
}
-static int config_set(uint32_t key, GVariant *data, const struct sr_dev_inst *sdi,
- const struct sr_channel_group *cg)
+static int config_set(uint32_t key, GVariant *data,
+ const struct sr_dev_inst *sdi, const struct sr_channel_group *cg)
{
struct dev_context *devc = sdi->priv;
uint64_t tmp_u64;
switch (key) {
case SR_CONF_SAMPLERATE:
devc->cur_samplerate = g_variant_get_uint64(data);
- return beaglelogic_set_samplerate(devc);
+ return devc->beaglelogic->set_samplerate(devc);
case SR_CONF_LIMIT_SAMPLES:
tmp_u64 = g_variant_get_uint64(data);
devc->limit_samples = tmp_u64;
sr_warn("Insufficient buffer space has been allocated.");
sr_warn("Please use \'echo <size in bytes> > "\
BEAGLELOGIC_SYSFS_ATTR(memalloc) \
- "\' as root to increase the buffer size, this"\
+ "\' to increase the buffer size, this"\
" capture is now truncated to %d Msamples",
devc->buffersize /
(SAMPLEUNIT_TO_BYTES(devc->sampleunit) * 1000000));
}
- return beaglelogic_set_triggerflags(devc);
+ return devc->beaglelogic->set_triggerflags(devc);
case SR_CONF_CAPTURE_RATIO:
devc->capture_ratio = g_variant_get_uint64(data);
- if (devc->capture_ratio > 100)
- return SR_ERR;
- return SR_OK;
+ break;
default:
return SR_ERR_NA;
}
return SR_OK;
}
-static int config_list(uint32_t key, GVariant **data, const struct sr_dev_inst *sdi,
- const struct sr_channel_group *cg)
+static int config_list(uint32_t key, GVariant **data,
+ const struct sr_dev_inst *sdi, const struct sr_channel_group *cg)
{
switch (key) {
case SR_CONF_SCAN_OPTIONS:
static int dev_acquisition_start(const struct sr_dev_inst *sdi)
{
struct dev_context *devc = sdi->priv;
+ GSList *l;
struct sr_trigger *trigger;
+ struct sr_channel *channel;
/* Clear capture state */
devc->bytes_read = 0;
devc->offset = 0;
/* Configure channels */
- devc->sampleunit = g_slist_length(sdi->channels) > 8 ?
- BL_SAMPLEUNIT_16_BITS : BL_SAMPLEUNIT_8_BITS;
- beaglelogic_set_sampleunit(devc);
+ devc->sampleunit = BL_SAMPLEUNIT_8_BITS;
+
+ for (l = sdi->channels; l; l = l->next) {
+ channel = l->data;
+ if (channel->index >= 8 && channel->enabled)
+ devc->sampleunit = BL_SAMPLEUNIT_16_BITS;
+ }
+ devc->beaglelogic->set_sampleunit(devc);
/* Configure triggers & send header packet */
if ((trigger = sr_session_trigger_get(sdi->session))) {
int pre_trigger_samples = 0;
if (devc->limit_samples > 0)
- pre_trigger_samples = devc->capture_ratio * devc->limit_samples/100;
+ pre_trigger_samples = (devc->capture_ratio * devc->limit_samples) / 100;
devc->stl = soft_trigger_logic_new(sdi, trigger, pre_trigger_samples);
if (!devc->stl)
return SR_ERR_MALLOC;
std_session_send_df_header(sdi);
/* Trigger and add poll on file */
- beaglelogic_start(devc);
+ devc->beaglelogic->start(devc);
sr_session_source_add_pollfd(sdi->session, &devc->pollfd,
BUFUNIT_TIMEOUT_MS(devc), beaglelogic_receive_data,
(void *)sdi);
struct dev_context *devc = sdi->priv;
/* Execute a stop on BeagleLogic */
- beaglelogic_stop(devc);
+ devc->beaglelogic->stop(devc);
/* lseek to offset 0, flushes the cache */
lseek(devc->fd, 0, SEEK_SET);