1
0
mirror of git://projects.qi-hardware.com/ben-blinkenlights.git synced 2024-11-16 18:45:54 +02:00

ubb-la/ubb-la.c (do_buf): move pretty-printing to new function print_samples

This commit is contained in:
Werner Almesberger 2013-01-26 20:01:32 -03:00
parent 4ceee66c79
commit 8316bc0070

View File

@ -166,31 +166,12 @@ quit:
}
static int do_buf(int nibbles, uint32_t trigger, uint32_t mask)
static void print_samples(FILE *file, uint8_t *buf, int skip, int nibbles)
{
uint8_t *buf = physmem_malloc(4096);
struct physmem_vec vec;
int n, i;
uint8_t v, last = 0xff;
int count = 0;
int i, count = 0;
if (mlockall(MCL_CURRENT | MCL_FUTURE)) {
perror("mlockall");
exit(1);
}
memset(buf, 0, 4096);
physmem_flush(buf, 4096);
n = physmem_xlat((void *) buf, nibbles >> 1, &vec, 1);
if (n != 1) {
fprintf(stderr, "physmem_xlat_vec: expected 1, got %d\n", n);
exit(1);
}
if (!xfer(vec.addr, nibbles, trigger, mask))
return 0;
for (i = INITIAL_SKIP; i != nibbles; i++) {
for (i = skip; i != nibbles; i++) {
v = (buf[i >> 1] >> (4*(~i & 1))) & 0xf;
if (v == last) {
count++;
@ -213,6 +194,33 @@ static int do_buf(int nibbles, uint32_t trigger, uint32_t mask)
printf("%X\n", last);
else
printf("%X{%d}\n", last, count);
}
static int do_buf(int nibbles, uint32_t trigger, uint32_t mask)
{
uint8_t *buf = physmem_malloc(4096);
struct physmem_vec vec;
int n;
if (mlockall(MCL_CURRENT | MCL_FUTURE)) {
perror("mlockall");
exit(1);
}
memset(buf, 0, 4096);
physmem_flush(buf, 4096);
n = physmem_xlat((void *) buf, nibbles >> 1, &vec, 1);
if (n != 1) {
fprintf(stderr, "physmem_xlat_vec: expected 1, got %d\n", n);
exit(1);
}
if (!xfer(vec.addr, nibbles, trigger, mask))
return 0;
print_samples(stdout, buf, INITIAL_SKIP, nibbles);
return 1;
}