From 8316bc0070f2c47d011dcd16a6ec8e1759e8dade Mon Sep 17 00:00:00 2001 From: Werner Almesberger Date: Sat, 26 Jan 2013 20:01:32 -0300 Subject: [PATCH] ubb-la/ubb-la.c (do_buf): move pretty-printing to new function print_samples --- ubb-la/ubb-la.c | 52 ++++++++++++++++++++++++++++--------------------- 1 file changed, 30 insertions(+), 22 deletions(-) diff --git a/ubb-la/ubb-la.c b/ubb-la/ubb-la.c index 2dd147d..adff9ce 100644 --- a/ubb-la/ubb-la.c +++ b/ubb-la/ubb-la.c @@ -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; }