1/*
2 * Copyright 2020, Data61
3 * Commonwealth Scientific and Industrial Research Organisation (CSIRO)
4 * ABN 41 687 119 230.
5 *
6 * This software may be distributed and modified according to the terms of
7 * the GNU General Public License version 2. Note that NO WARRANTY is provided.
8 * See "LICENSE_GPLv2.txt" for details.
9 *
10 * @TAG(DATA61_GPL)
11 */
12
13#include <stdio.h>
14#include <stdint.h>
15#include <ctype.h>
16
17void udelay(unsigned long us)
18{
19    volatile int i;
20    for (; us > 0; us--) {
21        for (i = 0; i < 1000; i++) {
22        }
23    }
24}
25
26unsigned long simple_strtoul(const char *cp, char **endp,
27                             unsigned int base)
28{
29    unsigned long result = 0;
30    unsigned long value;
31
32    if (*cp == '0') {
33        cp++;
34        if ((*cp == 'x') && isxdigit(cp[1])) {
35            base = 16;
36            cp++;
37        }
38
39        if (!base) {
40            base = 8;
41        }
42    }
43
44    if (!base) {
45        base = 10;
46    }
47
48    while (isxdigit(*cp) && (value = isdigit(*cp) ? *cp - '0' : (islower(*cp)
49                                                                 ? toupper(*cp) : *cp) - 'A' + 10) < base) {
50        result = result * base + value;
51        cp++;
52    }
53
54    if (endp) {
55        *endp = (char *)cp;
56    }
57
58    return result;
59}
60
61