devc = beaglelogic_devc_alloc();
+ 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]);
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_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;
- beaglelogic_set_triggerflags(devc);
+ 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;
}
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;
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);
break;
if (channel->index >= 8 && channel->enabled)
devc->sampleunit = BL_SAMPLEUNIT_16_BITS;
}
- beaglelogic_set_sampleunit(devc);
+ devc->beaglelogic->set_sampleunit(devc);
/* Configure triggers & send header packet */
if ((trigger = sr_session_trigger_get(sdi->session))) {
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);
#define IOCTL_BL_GET_TRIGGER_FLAGS _IOR('k', 0x23, uint32_t)
#define IOCTL_BL_SET_TRIGGER_FLAGS _IOW('k', 0x23, uint32_t)
+#define IOCTL_BL_GET_CUR_INDEX _IOR('k', 0x24, uint32_t)
#define IOCTL_BL_CACHE_INVALIDATE _IO('k', 0x25)
#define IOCTL_BL_GET_BUFFER_SIZE _IOR('k', 0x26, uint32_t)
#define IOCTL_BL_SET_BUFFER_SIZE _IOW('k', 0x26, uint32_t)
#define IOCTL_BL_GET_BUFUNIT_SIZE _IOR('k', 0x27, uint32_t)
+#define IOCTL_BL_SET_BUFUNIT_SIZE _IOW('k', 0x27, uint32_t)
#define IOCTL_BL_FILL_TEST_PATTERN _IO('k', 0x28)
* SR_OK or SR_ERR
*/
-SR_PRIV int beaglelogic_open_nonblock(struct dev_context *devc);
-SR_PRIV int beaglelogic_close(struct dev_context *devc);
+struct beaglelogic_ops {
+ int (*open)(struct dev_context *devc);
+ int (*close)(struct dev_context *devc);
-SR_PRIV int beaglelogic_get_buffersize(struct dev_context *devc);
-SR_PRIV int beaglelogic_set_buffersize(struct dev_context *devc);
+ int (*get_buffersize)(struct dev_context *devc);
+ int (*set_buffersize)(struct dev_context *devc);
-SR_PRIV int beaglelogic_get_samplerate(struct dev_context *devc);
-SR_PRIV int beaglelogic_set_samplerate(struct dev_context *devc);
+ int (*get_samplerate)(struct dev_context *devc);
+ int (*set_samplerate)(struct dev_context *devc);
-SR_PRIV int beaglelogic_get_sampleunit(struct dev_context *devc);
-SR_PRIV int beaglelogic_set_sampleunit(struct dev_context *devc);
+ int (*get_sampleunit)(struct dev_context *devc);
+ int (*set_sampleunit)(struct dev_context *devc);
-SR_PRIV int beaglelogic_get_triggerflags(struct dev_context *devc);
-SR_PRIV int beaglelogic_set_triggerflags(struct dev_context *devc);
+ int (*get_triggerflags)(struct dev_context *devc);
+ int (*set_triggerflags)(struct dev_context *devc);
-/* Start and stop the capture operation */
-SR_PRIV int beaglelogic_start(struct dev_context *devc);
-SR_PRIV int beaglelogic_stop(struct dev_context *devc);
+ /* Start and stop the capture operation */
+ int (*start)(struct dev_context *devc);
+ int (*stop)(struct dev_context *devc);
-/* Get the last error size */
-SR_PRIV int beaglelogic_getlasterror(struct dev_context *devc);
+ /* Get the last error size */
+ int (*get_lasterror)(struct dev_context *devc);
-/* Gets the unit size of the capture buffer (usually 4 or 8 MB) */
-SR_PRIV int beaglelogic_get_bufunitsize(struct dev_context *devc);
+ /* Gets the unit size of the capture buffer (usually 4 or 8 MB) */
+ int (*get_bufunitsize)(struct dev_context *devc);
+ int (*set_bufunitsize)(struct dev_context *devc);
-SR_PRIV int beaglelogic_mmap(struct dev_context *devc);
-SR_PRIV int beaglelogic_munmap(struct dev_context *devc);
+ int (*mmap)(struct dev_context *devc);
+ int (*munmap)(struct dev_context *devc);
+};
+
+SR_PRIV extern const struct beaglelogic_ops beaglelogic_native_ops;
#endif
#include "protocol.h"
#include "beaglelogic.h"
-SR_PRIV inline int beaglelogic_open_nonblock(struct dev_context *devc) {
+static int beaglelogic_open_nonblock(struct dev_context *devc) {
devc->fd = open(BEAGLELOGIC_DEV_NODE, O_RDONLY | O_NONBLOCK);
return (devc->fd == -1 ? SR_ERR : SR_OK);
}
-SR_PRIV inline int beaglelogic_close(struct dev_context *devc) {
+static int beaglelogic_close(struct dev_context *devc) {
return close(devc->fd);
}
-SR_PRIV inline int beaglelogic_get_buffersize(struct dev_context *devc) {
+static int beaglelogic_get_buffersize(struct dev_context *devc) {
return ioctl(devc->fd, IOCTL_BL_GET_BUFFER_SIZE, &devc->buffersize);
}
-SR_PRIV inline int beaglelogic_set_buffersize(struct dev_context *devc) {
+static int beaglelogic_set_buffersize(struct dev_context *devc) {
return ioctl(devc->fd, IOCTL_BL_SET_BUFFER_SIZE, devc->buffersize);
}
/* This is treated differently as it gets a uint64_t while a uint32_t is read */
-SR_PRIV inline int beaglelogic_get_samplerate(struct dev_context *devc) {
+static int beaglelogic_get_samplerate(struct dev_context *devc) {
uint32_t arg, err;
err = ioctl(devc->fd, IOCTL_BL_GET_SAMPLE_RATE, &arg);
devc->cur_samplerate = arg;
return err;
}
-SR_PRIV inline int beaglelogic_set_samplerate(struct dev_context *devc) {
+static int beaglelogic_set_samplerate(struct dev_context *devc) {
return ioctl(devc->fd, IOCTL_BL_SET_SAMPLE_RATE,
(uint32_t)devc->cur_samplerate);
}
-SR_PRIV inline int beaglelogic_get_sampleunit(struct dev_context *devc) {
+static int beaglelogic_get_sampleunit(struct dev_context *devc) {
return ioctl(devc->fd, IOCTL_BL_GET_SAMPLE_UNIT, &devc->sampleunit);
}
-SR_PRIV inline int beaglelogic_set_sampleunit(struct dev_context *devc) {
+static int beaglelogic_set_sampleunit(struct dev_context *devc) {
return ioctl(devc->fd, IOCTL_BL_SET_SAMPLE_UNIT, devc->sampleunit);
}
-SR_PRIV inline int beaglelogic_get_triggerflags(struct dev_context *devc) {
+static int beaglelogic_get_triggerflags(struct dev_context *devc) {
return ioctl(devc->fd, IOCTL_BL_GET_TRIGGER_FLAGS, &devc->triggerflags);
}
-SR_PRIV inline int beaglelogic_set_triggerflags(struct dev_context *devc) {
+static int beaglelogic_set_triggerflags(struct dev_context *devc) {
return ioctl(devc->fd, IOCTL_BL_SET_TRIGGER_FLAGS, devc->triggerflags);
}
-SR_PRIV int beaglelogic_getlasterror(struct dev_context *devc) {
+static int beaglelogic_get_lasterror(struct dev_context *devc) {
int fd;
char buf[16];
int ret;
return SR_OK;
}
-SR_PRIV inline int beaglelogic_start(struct dev_context *devc) {
+static int beaglelogic_start(struct dev_context *devc) {
return ioctl(devc->fd, IOCTL_BL_START);
}
-SR_PRIV inline int beaglelogic_stop(struct dev_context *devc) {
+static int beaglelogic_stop(struct dev_context *devc) {
return ioctl(devc->fd, IOCTL_BL_STOP);
}
-SR_PRIV int beaglelogic_get_bufunitsize(struct dev_context *devc) {
+static int beaglelogic_get_bufunitsize(struct dev_context *devc) {
return ioctl(devc->fd, IOCTL_BL_GET_BUFUNIT_SIZE, &devc->bufunitsize);
}
-SR_PRIV int beaglelogic_mmap(struct dev_context *devc) {
+static int beaglelogic_set_bufunitsize(struct dev_context *devc) {
+ return ioctl(devc->fd, IOCTL_BL_SET_BUFUNIT_SIZE, devc->bufunitsize);
+}
+
+static int beaglelogic_mmap(struct dev_context *devc) {
if (!devc->buffersize)
beaglelogic_get_buffersize(devc);
devc->sample_buf = mmap(NULL, devc->buffersize,
return (devc->sample_buf == MAP_FAILED ? -1 : SR_OK);
}
-SR_PRIV int beaglelogic_munmap(struct dev_context *devc) {
+static int beaglelogic_munmap(struct dev_context *devc) {
return munmap(devc->sample_buf, devc->buffersize);
}
+
+SR_PRIV const struct beaglelogic_ops beaglelogic_native_ops = {
+ .open = beaglelogic_open_nonblock,
+ .close = beaglelogic_close,
+ .get_buffersize = beaglelogic_get_buffersize,
+ .set_buffersize = beaglelogic_set_buffersize,
+ .get_samplerate = beaglelogic_get_samplerate,
+ .set_samplerate = beaglelogic_set_samplerate,
+ .get_sampleunit = beaglelogic_get_sampleunit,
+ .set_sampleunit = beaglelogic_set_sampleunit,
+ .get_triggerflags = beaglelogic_get_triggerflags,
+ .set_triggerflags = beaglelogic_set_triggerflags,
+ .start = beaglelogic_start,
+ .stop = beaglelogic_stop,
+ .get_lasterror = beaglelogic_get_lasterror,
+ .get_bufunitsize = beaglelogic_get_bufunitsize,
+ .set_bufunitsize = beaglelogic_set_bufunitsize,
+ .mmap = beaglelogic_mmap,
+ .munmap = beaglelogic_munmap,
+};
int max_channels;
uint32_t fw_ver;
+ /* Operations */
+ const struct beaglelogic_ops *beaglelogic;
+
+ /* Acquisition settings: see beaglelogic.h */
uint64_t cur_samplerate;
uint64_t limit_samples;
uint32_t sampleunit;