X-Git-Url: http://sigrok.org/gitweb/?a=blobdiff_plain;f=hardware%2Fdemo%2Fdemo.c;h=fb6dd7f23df6dae6ead4406b426d617048ee095b;hb=92b3101cfc71581a273e667f185b18be0f0c364f;hp=aac08599b0d85d69379ba82a4a227829219c572b;hpb=5a2326a71b3a7d3bc6b367a7a3dfa6f137f5f0ec;p=libsigrok.git diff --git a/hardware/demo/demo.c b/hardware/demo/demo.c index aac08599..fb6dd7f2 100644 --- a/hardware/demo/demo.c +++ b/hardware/demo/demo.c @@ -41,6 +41,7 @@ enum { GENMODE_INC, }; +/* FIXME: Should not be global. */ GIOChannel *channels[2]; struct databag { @@ -55,12 +56,20 @@ struct databag { static int capabilities[] = { SR_HWCAP_LOGIC_ANALYZER, + SR_HWCAP_SAMPLERATE, SR_HWCAP_PATTERN_MODE, SR_HWCAP_LIMIT_SAMPLES, SR_HWCAP_LIMIT_MSEC, SR_HWCAP_CONTINUOUS, }; +static struct sr_samplerates samplerates = { + SR_HZ(1), + SR_GHZ(1), + SR_HZ(1), + NULL, +}; + static const char *patternmodes[] = { "random", "incremental", @@ -80,7 +89,7 @@ static uint8_t genmode_default[] = { /* List of struct sr_device_instance, maintained by opendev()/closedev(). */ static GSList *device_instances = NULL; -static uint64_t cur_samplerate = KHZ(200); +static uint64_t cur_samplerate = SR_KHZ(200); static uint64_t limit_samples = 0; static uint64_t limit_msec = 0; static int default_genmode = GENMODE_DEFAULT; @@ -89,7 +98,7 @@ static int thread_running; static void hw_stop_acquisition(int device_index, gpointer session_device_id); -static int hw_init(char *deviceinfo) +static int hw_init(const char *deviceinfo) { struct sr_device_instance *sdi; @@ -142,6 +151,9 @@ static void *hw_get_device_info(int device_index, int device_info_id) case SR_DI_NUM_PROBES: info = GINT_TO_POINTER(NUM_PROBES); break; + case SR_DI_SAMPLERATES: + info = &samplerates; + break; case SR_DI_CUR_SAMPLERATE: info = &cur_samplerate; break; @@ -176,7 +188,11 @@ static int hw_set_configuration(int device_index, int capability, void *value) device_index = device_index; if (capability == SR_HWCAP_PROBECONFIG) { - /* Nothing to do. */ + /* Nothing to do, but must be supported */ + ret = SR_OK; + } else if (capability == SR_HWCAP_SAMPLERATE) { + tmp_u64 = value; + cur_samplerate = *tmp_u64; ret = SR_OK; } else if (capability == SR_HWCAP_LIMIT_SAMPLES) { tmp_u64 = value; @@ -206,14 +222,14 @@ static int hw_set_configuration(int device_index, int capability, void *value) static void samples_generator(uint8_t *buf, uint64_t size, void *data) { + static uint64_t p = 0; struct databag *mydata = data; - uint64_t p, i; + uint64_t i; memset(buf, 0, size); switch (mydata->sample_generator) { case GENMODE_DEFAULT: - p = 0; for (i = 0; i < size; i++) { *(buf + i) = ~(genmode_default[p] >> 1); if (++p == 64) @@ -299,7 +315,7 @@ static int receive_data(int fd, int revents, void *user_data) packet.length = z; packet.unitsize = 1; packet.payload = c; - session_bus(user_data, &packet); + sr_session_bus(user_data, &packet); } } while (z > 0); @@ -310,7 +326,7 @@ static int receive_data(int fd, int revents, void *user_data) /* Send last packet. */ packet.type = SR_DF_END; - session_bus(user_data, &packet); + sr_session_bus(user_data, &packet); return FALSE; } @@ -347,11 +363,12 @@ static int hw_start_acquisition(int device_index, gpointer session_device_id) g_io_channel_set_buffered(channels[0], FALSE); g_io_channel_set_buffered(channels[1], FALSE); - source_add(mydata->pipe_fds[0], G_IO_IN | G_IO_ERR, 40, receive_data, - session_device_id); + sr_source_add(mydata->pipe_fds[0], G_IO_IN | G_IO_ERR, 40, + receive_data, session_device_id); /* Run the demo thread. */ g_thread_init(NULL); + /* this needs to be done between g_thread_init() and g_thread_create() */ mydata->timer = g_timer_new(); thread_running = 1; my_thread = @@ -373,7 +390,7 @@ static int hw_start_acquisition(int device_index, gpointer session_device_id) header->protocol_id = SR_PROTO_RAW; header->num_logic_probes = NUM_PROBES; header->num_analog_probes = 0; - session_bus(session_device_id, packet); + sr_session_bus(session_device_id, packet); free(header); free(packet);