X-Git-Url: https://sigrok.org/gitweb/?a=blobdiff_plain;f=src%2Fhardware%2Fpipistrello-ols%2Fapi.c;h=865c3bf6bef9219daa57ca68d7204bb198c5e7f7;hb=208c1d35435626a11afa1ab301b2071b2a4e187b;hp=8a1fa5dca59a813ec547d432eb9055656fe931be;hpb=acc885c7553d12ce18d45fc603ebf7d0c188db09;p=libsigrok.git
diff --git a/src/hardware/pipistrello-ols/api.c b/src/hardware/pipistrello-ols/api.c
index 8a1fa5dc..865c3bf6 100644
--- a/src/hardware/pipistrello-ols/api.c
+++ b/src/hardware/pipistrello-ols/api.c
@@ -17,18 +17,19 @@
* along with this program. If not, see .
*/
+#include
#include "protocol.h"
-static const int32_t hwcaps[] = {
+static const uint32_t devopts[] = {
SR_CONF_LOGIC_ANALYZER,
- SR_CONF_SAMPLERATE,
- SR_CONF_TRIGGER_MATCH,
- SR_CONF_CAPTURE_RATIO,
- SR_CONF_LIMIT_SAMPLES,
- SR_CONF_PATTERN_MODE,
- SR_CONF_EXTERNAL_CLOCK,
- SR_CONF_SWAP,
- SR_CONF_RLE,
+ SR_CONF_LIMIT_SAMPLES | SR_CONF_GET | SR_CONF_SET | SR_CONF_LIST,
+ SR_CONF_SAMPLERATE | SR_CONF_GET | SR_CONF_SET | SR_CONF_LIST,
+ SR_CONF_TRIGGER_MATCH | SR_CONF_LIST,
+ SR_CONF_CAPTURE_RATIO | SR_CONF_GET | SR_CONF_SET,
+ SR_CONF_PATTERN_MODE | SR_CONF_GET | SR_CONF_SET | SR_CONF_LIST,
+ SR_CONF_EXTERNAL_CLOCK | SR_CONF_GET | SR_CONF_SET,
+ SR_CONF_SWAP | SR_CONF_SET,
+ SR_CONF_RLE | SR_CONF_GET | SR_CONF_SET,
};
static const int32_t trigger_matches[] = {
@@ -61,11 +62,10 @@ static const char *patterns[] = {
};
/* Channels are numbered 0-31 (on the PCB silkscreen). */
-SR_PRIV const char *p_ols_channel_names[NUM_CHANNELS + 1] = {
+SR_PRIV const char *p_ols_channel_names[] = {
"0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "10", "11", "12",
"13", "14", "15", "16", "17", "18", "19", "20", "21", "22", "23",
"24", "25", "26", "27", "28", "29", "30", "31",
- NULL,
};
/* Default supported samplerates, can be overridden by device metadata. */
@@ -76,14 +76,13 @@ static const uint64_t samplerates[] = {
};
SR_PRIV struct sr_dev_driver p_ols_driver_info;
-static struct sr_dev_driver *di = &p_ols_driver_info;
-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 GSList *scan(GSList *options)
+static GSList *scan(struct sr_dev_driver *di, GSList *options)
{
struct sr_dev_inst *sdi;
struct drv_context *drvc;
@@ -95,15 +94,12 @@ static GSList *scan(GSList *options)
(void)options;
- drvc = di->priv;
+ drvc = di->context;
devices = NULL;
/* Allocate memory for our private device context. */
- if (!(devc = g_try_malloc0(sizeof(struct dev_context)))) {
- sr_err("Device context malloc failed.");
- goto err_free_nothing;
- }
+ devc = g_malloc0(sizeof(struct dev_context));
/* Device-specific settings */
devc->max_samplebytes = devc->max_samplerate = devc->protocol_version = 0;
@@ -115,10 +111,7 @@ static GSList *scan(GSList *options)
devc->flag_reg = 0;
/* Allocate memory for the incoming ftdi data. */
- if (!(devc->ftdi_buf = g_try_malloc0(FTDI_BUF_SIZE))) {
- sr_err("ftdi_buf malloc failed.");
- goto err_free_devc;
- }
+ devc->ftdi_buf = g_malloc0(FTDI_BUF_SIZE);
/* Allocate memory for the FTDI context (ftdic) and initialize it. */
if (!(devc->ftdic = ftdi_new())) {
@@ -185,7 +178,6 @@ static GSList *scan(GSList *options)
/* Parse the metadata. */
sdi = p_ols_get_metadata((uint8_t *)buf, bytes_read, devc);
- sdi->index = 0;
/* Configure samplerate and divider. */
if (p_ols_set_samplerate(sdi, DEFAULT_SAMPLERATE) != SR_OK)
@@ -203,16 +195,14 @@ err_free_ftdic:
ftdi_free(devc->ftdic); /* NOT free() or g_free()! */
err_free_ftdi_buf:
g_free(devc->ftdi_buf);
-err_free_devc:
g_free(devc);
-err_free_nothing:
return NULL;
}
-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 void clear_helper(void *priv)
@@ -225,18 +215,17 @@ static void clear_helper(void *priv)
g_free(devc->ftdi_buf);
}
-static int dev_clear(void)
+static int dev_clear(const struct sr_dev_driver *di)
{
return std_dev_clear(di, clear_helper);
}
-static int cleanup(void)
+static int cleanup(const struct sr_dev_driver *di)
{
- return dev_clear();
+ return dev_clear(di);
}
-
-static int config_get(int id, 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;
@@ -247,7 +236,7 @@ static int config_get(int id, GVariant **data, const struct sr_dev_inst *sdi,
return SR_ERR_ARG;
devc = sdi->priv;
- switch (id) {
+ switch (key) {
case SR_CONF_SAMPLERATE:
*data = g_variant_new_uint64(devc->cur_samplerate);
break;
@@ -278,7 +267,7 @@ static int config_get(int id, GVariant **data, const struct sr_dev_inst *sdi,
return SR_OK;
}
-static int config_set(int id, 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;
@@ -294,7 +283,7 @@ static int config_set(int id, GVariant *data, const struct sr_dev_inst *sdi,
devc = sdi->priv;
- switch (id) {
+ switch (key) {
case SR_CONF_SAMPLERATE:
tmp_u64 = g_variant_get_uint64(data);
if (tmp_u64 < samplerates[0] || tmp_u64 > samplerates[1])
@@ -310,10 +299,9 @@ static int config_set(int id, GVariant *data, const struct sr_dev_inst *sdi,
break;
case SR_CONF_CAPTURE_RATIO:
devc->capture_ratio = g_variant_get_uint64(data);
- if (devc->capture_ratio < 0 || devc->capture_ratio > 100) {
- devc->capture_ratio = 0;
+ if (devc->capture_ratio < 0 || devc->capture_ratio > 100)
ret = SR_ERR;
- } else
+ else
ret = SR_OK;
break;
case SR_CONF_EXTERNAL_CLOCK:
@@ -375,7 +363,7 @@ static int config_set(int id, GVariant *data, const struct sr_dev_inst *sdi,
return ret;
}
-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)
{
struct dev_context *devc;
@@ -387,8 +375,8 @@ static int config_list(int key, GVariant **data, const struct sr_dev_inst *sdi,
switch (key) {
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}"));
@@ -450,7 +438,7 @@ static int dev_open(struct sr_dev_inst *sdi)
if (p_ols_open(devc) != SR_OK) {
return SR_ERR;
} else {
- sdi->status = SR_ST_ACTIVE;
+ sdi->status = SR_ST_ACTIVE;
return SR_OK;
}
}
@@ -475,7 +463,6 @@ static int dev_close(struct sr_dev_inst *sdi)
return ret;
}
-
static int set_trigger(const struct sr_dev_inst *sdi, int stage)
{
struct dev_context *devc;
@@ -519,8 +506,36 @@ static int set_trigger(const struct sr_dev_inst *sdi, int stage)
return SR_OK;
}
-static int dev_acquisition_start(const struct sr_dev_inst *sdi,
- void *cb_data)
+static int disable_trigger(const struct sr_dev_inst *sdi, int stage)
+{
+ struct dev_context *devc;
+ uint8_t cmd, arg[4];
+
+ devc = sdi->priv;
+
+ cmd = CMD_SET_TRIGGER_MASK + stage * 4;
+ arg[0] = arg[1] = arg[2] = arg[3] = 0x00;
+ if (write_longcommand(devc, cmd, arg) != SR_OK)
+ return SR_ERR;
+
+ cmd = CMD_SET_TRIGGER_VALUE + stage * 4;
+ if (write_longcommand(devc, cmd, arg) != SR_OK)
+ return SR_ERR;
+
+ cmd = CMD_SET_TRIGGER_CONFIG + stage * 4;
+ arg[2] = 0x03;
+ if (write_longcommand(devc, cmd, arg) != SR_OK)
+ return SR_ERR;
+
+ cmd = CMD_SET_TRIGGER_EDGE + stage * 4;
+ arg[2] = 0x00;
+ if (write_longcommand(devc, cmd, arg) != SR_OK)
+ return SR_ERR;
+
+ return SR_OK;
+}
+
+static int dev_acquisition_start(const struct sr_dev_inst *sdi, void *cb_data)
{
struct dev_context *devc;
uint32_t samplecount, readcount, delaycount;
@@ -560,7 +575,7 @@ static int dev_acquisition_start(const struct sr_dev_inst *sdi,
* buffer.
*/
sr_dbg("max_samples = %d", devc->max_samples);
- sr_dbg("limit_samples = %d", devc->limit_samples);
+ sr_dbg("limit_samples = %" PRIu64, devc->limit_samples);
samplecount = MIN(devc->max_samples, devc->limit_samples);
sr_dbg("Samplecount = %d", samplecount);
@@ -583,13 +598,21 @@ static int dev_acquisition_start(const struct sr_dev_inst *sdi,
sr_err("Failed to configure channels.");
return SR_ERR;
}
+
if (devc->num_stages > 0) {
delaycount = readcount * (1 - devc->capture_ratio / 100.0);
devc->trigger_at = (readcount - delaycount) * samplespercount - devc->num_stages;
- for (i = 0; i <= devc->num_stages; i++) {
- sr_dbg("Setting p-ols stage %d trigger.", i);
- if ((ret = set_trigger(sdi, i)) != SR_OK)
- return ret;
+ for (i = 0; i < NUM_TRIGGER_STAGES; i++) {
+ if (i <= devc->num_stages) {
+ sr_dbg("Setting p-ols stage %d trigger.", i);
+ if ((ret = set_trigger(sdi, i)) != SR_OK)
+ return ret;
+ }
+ else {
+ sr_dbg("Disabling p-ols stage %d trigger.", i);
+ if ((ret = disable_trigger(sdi, i)) != SR_OK)
+ return ret;
+ }
}
} else {
/* No triggers configured, force trigger on first stage. */
@@ -665,22 +688,18 @@ static int dev_acquisition_start(const struct sr_dev_inst *sdi,
devc->cnt_bytes = devc->cnt_samples = devc->cnt_samples_rle = 0;
memset(devc->sample, 0, 4);
- /* Send header packet to the session bus. */
std_session_send_df_header(cb_data, LOG_PREFIX);
/* Hook up a dummy handler to receive data from the device. */
- sr_session_source_add(sdi->session, 0, G_IO_IN, 10, p_ols_receive_data,
+ sr_session_source_add(sdi->session, -1, 0, 10, p_ols_receive_data,
cb_data);
return SR_OK;
}
-
-
static int dev_acquisition_stop(struct sr_dev_inst *sdi, void *cb_data)
{
struct dev_context *devc;
- struct sr_datafeed_packet packet;
devc = sdi->priv;
@@ -691,12 +710,9 @@ static int dev_acquisition_stop(struct sr_dev_inst *sdi, void *cb_data)
write_shortcommand(devc, CMD_RESET);
write_shortcommand(devc, CMD_RESET);
- sr_session_source_remove(sdi->session, 0);
+ sr_session_source_remove(sdi->session, -1);
- /* Send end packet to the session bus. */
- sr_dbg("Sending SR_DF_END.");
- packet.type = SR_DF_END;
- sr_session_send(cb_data, &packet);
+ std_session_send_df_end(cb_data, LOG_PREFIX);
return SR_OK;
}
@@ -717,5 +733,5 @@ SR_PRIV struct sr_dev_driver p_ols_driver_info = {
.dev_close = dev_close,
.dev_acquisition_start = dev_acquisition_start,
.dev_acquisition_stop = dev_acquisition_stop,
- .priv = NULL,
+ .context = NULL,
};