1
0
mirror of git://projects.qi-hardware.com/ben-blinkenlights.git synced 2024-07-01 03:12:21 +03:00

ubb-patgen/ubb-patgen.c: clean up section structure

This commit is contained in:
Werner Almesberger 2013-01-15 13:02:19 -03:00
parent dad97398d3
commit a5fbf55419

View File

@ -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)
{