From a5fbf5541931b8b8e10550cb609919e2c0c51c27 Mon Sep 17 00:00:00 2001 From: Werner Almesberger Date: Tue, 15 Jan 2013 13:02:19 -0300 Subject: [PATCH] ubb-patgen/ubb-patgen.c: clean up section structure --- ubb-patgen/ubb-patgen.c | 114 +++++++++++++++++++++------------------- 1 file changed, 60 insertions(+), 54 deletions(-) diff --git a/ubb-patgen/ubb-patgen.c b/ubb-patgen/ubb-patgen.c index 7a38f2f..361d214 100644 --- a/ubb-patgen/ubb-patgen.c +++ b/ubb-patgen/ubb-patgen.c @@ -134,7 +134,63 @@ static int select_freq(struct mmcclk *res, int hz, int rel) } -/* ----- DMA the pattern --------------------------------------------------- */ +/* ----- Pattern parser ---------------------------------------------------- */ + + +static void *parse_pattern(const char *s, int *nibbles) +{ + uint8_t *buf = physmem_malloc(4095); /* maximum block size */ + int n = 0; + uint8_t v = 0; + char *end; + unsigned long i; + + memset(buf, 0, 4095); + while (*s) { + char ch[2] = { *s, 0 }; + + v = strtoul(ch, &end, 16); + if (*end) { + fprintf(stderr, "\"%c\" is not a hex digit\n", *s); + exit(1); + } + if (s[1] == '{') { + i = strtoul(s+2, &end, 0); + if (!*end) { + fprintf(stderr, "unterminated range\n"); + exit(1); + } + if (*end != '}' || end == s+2) { + fprintf(stderr, "invalid range \"%.*s\"\n", + end-s, s+1); + exit(1); + } + s = end+1; + } else { + i = 1; + s++; + } + while (i) { + if (n == 8192-64-1) { + fprintf(stderr, "pattern is too long\n"); + exit(1); + } + buf[n >> 1] |= v << 4*(~n & 1); + n++; + i--; + } + } + /* pad to multiples of 32 bytes */ + while (n & 63) { + buf[n >> 1] |= v << 4*(~n & 1); + n++; + } + *nibbles = n; + return buf; +} + + +/* ----- DMA control ------------------------------------------------------- */ static uint32_t old_dmac; @@ -185,6 +241,9 @@ static void wait_dma_done(void) } +/* ----- Send pattern using MSC and DMA ------------------------------------ */ + + static void wait_response(void) { while (!((MSC_STAT >> 11 ) & 1)); /* MSC_STAT.END_CMD_RES */ @@ -298,59 +357,6 @@ static void send_buffer(const struct mmcclk *clk, } -static void *parse_pattern(const char *s, int *nibbles) -{ - uint8_t *buf = physmem_malloc(4095); /* maximum block size */ - int n = 0; - uint8_t v = 0; - char *end; - unsigned long i; - - memset(buf, 0, 4095); - while (*s) { - char ch[2] = { *s, 0 }; - - v = strtoul(ch, &end, 16); - if (*end) { - fprintf(stderr, "\"%c\" is not a hex digit\n", *s); - exit(1); - } - if (s[1] == '{') { - i = strtoul(s+2, &end, 0); - if (!*end) { - fprintf(stderr, "unterminated range\n"); - exit(1); - } - if (*end != '}' || end == s+2) { - fprintf(stderr, "invalid range \"%.*s\"\n", - end-s, s+1); - exit(1); - } - s = end+1; - } else { - i = 1; - s++; - } - while (i) { - if (n == 8192-64-1) { - fprintf(stderr, "pattern is too long\n"); - exit(1); - } - buf[n >> 1] |= v << 4*(~n & 1); - n++; - i--; - } - } - /* pad to multiples of 32 bytes */ - while (n & 63) { - buf[n >> 1] |= v << 4*(~n & 1); - n++; - } - *nibbles = n; - return buf; -} - - static void dma_pattern(const struct mmcclk *clk, const char *pattern, uint32_t mask) {