static void parse_line(unsigned channel, const char *line, unsigned *baud, unsigned *clk) { if (line == NULL) return; if(*line != '.' && *line != '\0') { dbg_device[channel].base = strtopaddr(line, (char **)&line, 16); if(*line == '^') dbg_device[channel].shift = strtoul(line+1, (char **)&line, 0); } if(*line == '.') ++line; if(*line != '.' && *line != '\0') *baud = strtoul(line, (char **)&line, 0); if(*line == '.') ++line; if(*line != '.' && *line != '\0') *clk = strtoul(line, (char **)&line, 0); }
/* * Syntax: base^shift.baud.clock.alt * Where: * * base = physical address (0x8005000 = UART3, 0x80010000 = UART1) * shift = not used by driver code (typically set to 0) * baud = baud rate * clock = clock frequency (typically 3686400, but may be different) * alt = 'A' if port uses alternate GPIO pins for Rx/Tx */ static void parse_line(unsigned channel, const char *line, unsigned *baud, unsigned *clk, int *alt) { /* * Get device base address and register stride */ if (*line != '.' && *line != '\0') { dbg_device[channel].base = strtopaddr(line, (char **)&line, 16); if (*line == '^') dbg_device[channel].shift = strtoul(line+1, (char **)&line, 0); } /* * Get baud rate */ if (*line == '.') ++line; if (*line != '.' && *line != '\0') *baud = strtoul(line, (char **)&line, 0); /* * Get clock rate */ if (*line == '.') ++line; if (*line != '.' && *line != '\0') *clk = strtoul(line, (char **)&line, 0); /* * Check if port uses alternate GPIO pins */ if (*line == '.') ++line; if (*line != '\0') *alt = (*line == 'A'); }
unsigned long strtoul(const char *nptr, char **endptr, int base) { //Assuming that sizeof(paddr_t) >= sizeof(unsigned long) return strtopaddr(nptr, endptr, base); }