X-Git-Url: https://sigrok.org/gitweb/?a=blobdiff_plain;ds=sidebyside;f=src%2Fhardware%2Fbeaglelogic%2Fapi.c;h=b974010468f38dfb440198c150fe6bcb7e486286;hb=1079324f9e76c4775395e5baaf916f37d4785278;hp=c86925be56d9133ed1443d282cec44d65c7fe834;hpb=155b680da482cea2381becb73c51cfb838bff31e;p=libsigrok.git
diff --git a/src/hardware/beaglelogic/api.c b/src/hardware/beaglelogic/api.c
index c86925be..b9740104 100644
--- a/src/hardware/beaglelogic/api.c
+++ b/src/hardware/beaglelogic/api.c
@@ -17,22 +17,26 @@
* along with this program. If not, see .
*/
+#include
#include "protocol.h"
#include "beaglelogic.h"
SR_PRIV struct sr_dev_driver beaglelogic_driver_info;
-static struct sr_dev_driver *di = &beaglelogic_driver_info;
-/* Hardware capabiities */
-static const int32_t hwcaps[] = {
- SR_CONF_LOGIC_ANALYZER,
- SR_CONF_SAMPLERATE,
- SR_CONF_TRIGGER_MATCH,
+/* Scan options */
+static const uint32_t scanopts[] = {
+ SR_CONF_NUM_LOGIC_CHANNELS,
+};
- SR_CONF_LIMIT_SAMPLES,
+/* Hardware capabilities */
+static const uint32_t devopts[] = {
+ SR_CONF_LOGIC_ANALYZER,
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 */
@@ -44,30 +48,28 @@ static const int32_t soft_trigger_matches[] = {
SR_TRIGGER_EDGE,
};
-/* Channels are numbered 0-13 */
-SR_PRIV const char *beaglelogic_channel_names[NUM_CHANNELS + 1] = {
- "P8_45", "P8_46", "P8_43", "P8_44", "P8_41", "P8_42", "P8_39", "P8_40",
- "P8_27", "P8_29", "P8_28", "P8_30", "P8_21", "P8_20", NULL,
+SR_PRIV const char *channel_names[] = {
+ "P8_45", "P8_46", "P8_43", "P8_44", "P8_41", "P8_42", "P8_39",
+ "P8_40", "P8_27", "P8_29", "P8_28", "P8_30", "P8_21", "P8_20",
};
/* Possible sample rates : 10 Hz to 100 MHz = (100 / x) MHz */
static const uint64_t samplerates[] = {
- SR_HZ(10),
- SR_MHZ(100),
- SR_HZ(1),
+ SR_HZ(10),
+ SR_MHZ(100),
+ SR_HZ(1),
};
-static int init(struct sr_context *sr_ctx)
+static int init(struct sr_dev_driver *di, 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;
@@ -76,25 +78,27 @@ static struct dev_context * beaglelogic_devc_alloc(void)
return devc;
}
-static GSList *scan(GSList *options)
+static GSList *scan(struct sr_dev_driver *di, GSList *options)
{
struct drv_context *drvc;
GSList *devices, *l;
struct sr_config *src;
struct sr_dev_inst *sdi;
struct dev_context *devc;
- struct sr_channel *ch;
int i, maxch;
devices = NULL;
- drvc = di->priv;
+ drvc = di->context;
drvc->instances = NULL;
/* Probe for /dev/beaglelogic */
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 */
@@ -130,12 +134,9 @@ static GSList *scan(GSList *options)
sr_info("BeagleLogic device found at "BEAGLELOGIC_DEV_NODE);
/* 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;
- sdi->channels = g_slist_append(sdi->channels, ch);
- }
+ for (i = 0; i < maxch; i++)
+ sr_channel_new(sdi, i, SR_CHANNEL_LOGIC, TRUE,
+ channel_names[i]);
sdi->priv = devc;
drvc->instances = g_slist_append(drvc->instances, sdi);
@@ -144,12 +145,12 @@ static GSList *scan(GSList *options)
return devices;
}
-static GSList *dev_list(void)
+static GSList *dev_list(const struct sr_dev_driver *di)
{
- return ((struct drv_context *)(di->priv))->instances;
+ return ((struct drv_context *)(di->context))->instances;
}
-static int dev_clear(void)
+static int dev_clear(const struct sr_dev_driver *di)
{
return std_dev_clear(di, NULL);
}
@@ -165,6 +166,7 @@ static int dev_open(struct sr_dev_inst *sdi)
/* Set fd and local attributes */
devc->pollfd.fd = devc->fd;
devc->pollfd.events = G_IO_IN;
+ devc->pollfd.revents = 0;
/* Get the default attributes */
beaglelogic_get_samplerate(devc);
@@ -198,14 +200,14 @@ static int dev_close(struct sr_dev_inst *sdi)
return SR_OK;
}
-static int cleanup(void)
+static int cleanup(const struct sr_dev_driver *di)
{
struct drv_context *drvc;
struct sr_dev_inst *sdi;
GSList *l;
/* unused driver */
- if (!(drvc = di->priv))
+ if (!(drvc = di->context))
return SR_OK;
/* Clean up the instances */
@@ -218,30 +220,29 @@ static int cleanup(void)
g_slist_free(drvc->instances);
drvc->instances = NULL;
- di->priv = NULL;
-
return SR_OK;
}
-static int config_get(int key, GVariant **data, const struct sr_dev_inst *sdi,
+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;
+
(void)cg;
switch (key) {
case SR_CONF_LIMIT_SAMPLES:
*data = g_variant_new_uint64(devc->limit_samples);
break;
-
case SR_CONF_SAMPLERATE:
*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;
-
default:
return SR_ERR_NA;
}
@@ -249,11 +250,12 @@ static int config_get(int key, GVariant **data, const struct sr_dev_inst *sdi,
return SR_OK;
}
-static int config_set(int key, GVariant *data, const struct sr_dev_inst *sdi,
+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;
+
(void)cg;
if (sdi->status != SR_ST_ACTIVE)
@@ -263,7 +265,6 @@ static int config_set(int key, GVariant *data, const struct sr_dev_inst *sdi,
case SR_CONF_SAMPLERATE:
devc->cur_samplerate = g_variant_get_uint64(data);
return beaglelogic_set_samplerate(devc);
-
case SR_CONF_LIMIT_SAMPLES:
tmp_u64 = g_variant_get_uint64(data);
devc->limit_samples = tmp_u64;
@@ -281,7 +282,11 @@ static int config_set(int key, GVariant *data, const struct sr_dev_inst *sdi,
(SAMPLEUNIT_TO_BYTES(devc->sampleunit) * 1000000));
}
return 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;
default:
return SR_ERR_NA;
}
@@ -289,7 +294,7 @@ static int config_set(int key, GVariant *data, const struct sr_dev_inst *sdi,
return SR_OK;
}
-static int config_list(int key, GVariant **data, const struct sr_dev_inst *sdi,
+static int config_list(uint32_t key, GVariant **data, const struct sr_dev_inst *sdi,
const struct sr_channel_group *cg)
{
int ret;
@@ -297,14 +302,17 @@ static int config_list(int key, GVariant **data, const struct sr_dev_inst *sdi,
GVariantBuilder gvb;
(void)sdi;
- (void)data;
(void)cg;
ret = SR_OK;
switch (key) {
+ case SR_CONF_SCAN_OPTIONS:
+ *data = g_variant_new_fixed_array(G_VARIANT_TYPE_UINT32,
+ scanopts, ARRAY_SIZE(scanopts), sizeof(uint32_t));
+ break;
case SR_CONF_DEVICE_OPTIONS:
- *data = g_variant_new_fixed_array(G_VARIANT_TYPE_INT32,
- hwcaps, ARRAY_SIZE(hwcaps), sizeof(int32_t));
+ *data = g_variant_new_fixed_array(G_VARIANT_TYPE_UINT32,
+ devopts, ARRAY_SIZE(devopts), sizeof(uint32_t));
break;
case SR_CONF_SAMPLERATE:
g_variant_builder_init(&gvb, G_VARIANT_TYPE("a{sv}"));
@@ -353,7 +361,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)
+ return SR_ERR_MALLOC;
devc->trigger_fired = FALSE;
} else
devc->trigger_fired = TRUE;
@@ -409,5 +422,5 @@ SR_PRIV struct sr_dev_driver beaglelogic_driver_info = {
.dev_close = dev_close,
.dev_acquisition_start = dev_acquisition_start,
.dev_acquisition_stop = dev_acquisition_stop,
- .priv = NULL,
+ .context = NULL,
};