X-Git-Url: http://sigrok.org/gitweb/?a=blobdiff_plain;ds=sidebyside;f=src%2Fhardware%2Fbeaglelogic%2Fapi.c;h=098efa0627927cc3bb3453ff8d8a0b76d9207baa;hb=e743a47d6d23050c72aa1276c5df4a45a6bc5357;hp=3f83a9168b4b68d2520eba870b1a47fa95814687;hpb=138589b02e3dd6aaad64e94a48efdf47d9b7d7d1;p=libsigrok.git diff --git a/src/hardware/beaglelogic/api.c b/src/hardware/beaglelogic/api.c index 3f83a916..098efa06 100644 --- a/src/hardware/beaglelogic/api.c +++ b/src/hardware/beaglelogic/api.c @@ -31,13 +31,12 @@ static const uint32_t scanopts[] = { /* Hardware capabilities */ static const uint32_t devopts[] = { SR_CONF_LOGIC_ANALYZER, - SR_CONF_SAMPLERATE, - SR_CONF_TRIGGER_MATCH, - - SR_CONF_LIMIT_SAMPLES, SR_CONF_CONTINUOUS, - - SR_CONF_NUM_LOGIC_CHANNELS, + SR_CONF_LIMIT_SAMPLES | SR_CONF_GET | SR_CONF_SET, + SR_CONF_SAMPLERATE | SR_CONF_GET | SR_CONF_SET, + SR_CONF_TRIGGER_MATCH | SR_CONF_LIST, + SR_CONF_CAPTURE_RATIO | SR_CONF_GET | SR_CONF_SET, + SR_CONF_NUM_LOGIC_CHANNELS | SR_CONF_GET, }; /* Trigger matching capabilities */ @@ -67,12 +66,11 @@ static int init(struct sr_context *sr_ctx) return std_init(sr_ctx, di, LOG_PREFIX); } -static struct dev_context * beaglelogic_devc_alloc(void) +static struct dev_context *beaglelogic_devc_alloc(void) { struct dev_context *devc; - /* Allocate zeroed structure */ - devc = g_try_malloc0(sizeof(*devc)); + devc = g_malloc0(sizeof(struct dev_context)); /* Default non-zero values (if any) */ devc->fd = -1; @@ -99,7 +97,10 @@ static GSList *scan(GSList *options) if (!g_file_test(BEAGLELOGIC_DEV_NODE, G_FILE_TEST_EXISTS)) return NULL; - sdi = sr_dev_inst_new(0, SR_ST_INACTIVE, NULL, "BeagleLogic", "1.0"); + sdi = g_malloc0(sizeof(struct sr_dev_inst)); + sdi->status = SR_ST_INACTIVE; + sdi->model = g_strdup("BeagleLogic"); + sdi->version = g_strdup("1.0"); sdi->driver = di; /* Unless explicitly specified, keep max channels to 8 only */ @@ -136,9 +137,8 @@ static GSList *scan(GSList *options) /* Fill the channels */ for (i = 0; i < maxch; i++) { - if (!(ch = sr_channel_new(i, SR_CHANNEL_LOGIC, TRUE, - beaglelogic_channel_names[i]))) - return NULL; + ch = sr_channel_new(i, SR_CHANNEL_LOGIC, TRUE, + beaglelogic_channel_names[i]); sdi->channels = g_slist_append(sdi->channels, ch); } @@ -243,6 +243,10 @@ static int config_get(uint32_t key, GVariant **data, const struct sr_dev_inst *s *data = g_variant_new_uint64(devc->cur_samplerate); break; + case SR_CONF_CAPTURE_RATIO: + *data = g_variant_new_uint64(devc->capture_ratio); + break; + case SR_CONF_NUM_LOGIC_CHANNELS: *data = g_variant_new_uint32(g_slist_length(sdi->channels)); break; @@ -287,6 +291,14 @@ static int config_set(uint32_t key, GVariant *data, const struct sr_dev_inst *sd } return beaglelogic_set_triggerflags(devc); + case SR_CONF_CAPTURE_RATIO: + devc->capture_ratio = g_variant_get_uint64(data); + if (devc->capture_ratio > 100) { + devc->capture_ratio = 0; + return SR_ERR; + } + return SR_OK; + default: return SR_ERR_NA; } @@ -323,7 +335,7 @@ static int config_list(uint32_t key, GVariant **data, const struct sr_dev_inst * *data = g_variant_builder_end(&gvb); break; case SR_CONF_TRIGGER_MATCH: - *data = g_variant_new_fixed_array(G_VARIANT_TYPE_UINT32, + *data = g_variant_new_fixed_array(G_VARIANT_TYPE_INT32, soft_trigger_matches, ARRAY_SIZE(soft_trigger_matches), sizeof(int32_t)); break; @@ -362,7 +374,12 @@ static int dev_acquisition_start(const struct sr_dev_inst *sdi, /* Configure triggers & send header packet */ if ((trigger = sr_session_trigger_get(sdi->session))) { - devc->stl = soft_trigger_logic_new(sdi, trigger); + int pre_trigger_samples = 0; + if (devc->limit_samples > 0) + pre_trigger_samples = devc->capture_ratio * devc->limit_samples/100; + devc->stl = soft_trigger_logic_new(sdi, trigger, pre_trigger_samples); + if (devc->stl == NULL) + return SR_ERR_MALLOC; devc->trigger_fired = FALSE; } else devc->trigger_fired = TRUE;