From: Bert Vermeulen Date: Sat, 15 Jan 2011 13:28:03 +0000 (+0100) Subject: added example code for generating a stored pattern X-Git-Tag: libsigrok-0.1.0~435 X-Git-Url: https://sigrok.org/gitaction?a=commitdiff_plain;h=917e0e71d53cb0a0ac7965cb4f36791b14f7e5ff;p=libsigrok.git added example code for generating a stored pattern --- diff --git a/hardware/demo/demo.c b/hardware/demo/demo.c index 86aadc4a..30484d08 100644 --- a/hardware/demo/demo.c +++ b/hardware/demo/demo.c @@ -31,6 +31,7 @@ #define BUFSIZE 4096 enum { + GENMODE_DEFAULT, GENMODE_RANDOM, GENMODE_INC, }; @@ -61,11 +62,22 @@ static const char *patternmodes[] = { NULL, }; +static uint8_t genmode_default[] = { + 0x4c, 0x92, 0x92, 0x92, 0x64, 0x00, 0x00, 0x00, + 0x82, 0xfe, 0xfe, 0x82, 0x00, 0x00, 0x00, 0x00, + 0x7c, 0x82, 0x82, 0x92, 0x74, 0x00, 0x00, 0x00, + 0xfe, 0x12, 0x12, 0x32, 0xcc, 0x00, 0x00, 0x00, + 0x7c, 0x82, 0x82, 0x82, 0x7c, 0x00, 0x00, 0x00, + 0xfe, 0x10, 0x28, 0x44, 0x82, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0xbe, 0xbe, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, +}; + /* List of struct sigrok_device_instance, maintained by opendev()/closedev(). */ static GSList *device_instances = NULL; static uint64_t cur_samplerate = 0; static uint64_t limit_samples = -1; -static int default_genmode = GENMODE_RANDOM; +static int default_genmode = GENMODE_DEFAULT; static void hw_stop_acquisition(int device_index, gpointer session_device_id); @@ -183,11 +195,19 @@ static int hw_set_configuration(int device_index, int capability, void *value) static void samples_generator(uint8_t *buf, uint64_t size, void *data) { struct databag *mydata = data; - uint64_t i; + uint64_t p, 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) + p = 0; + } + break; case GENMODE_RANDOM: /* Random */ for (i = 0; i < size; i++) *(buf + i) = (uint8_t)(rand() & 0xff);