Date:2014-03-06 15:34:28 (5 years 5 months ago)
Author:Werner Almesberger
Commit:9e223f77e699c294818ca9cc5ad6d62f8da013e8
Message:ubbctl/: also support decoding and setting of interrupts and alternate functions

Files: ubbctl/README (1 diff)
ubbctl/ubbctl.c (5 diffs)

Change Details

ubbctl/README
3030pull-up is enabled.
3131
3232"F0" and "F1" indicate that the pin configured as a function (i.e.,
33for the MMC controller) and does not operate as GPIO.
33for the MMC controller) and does not operate as GPIO. If the second
34function of the pin is selected, "Fb..." is shown instead of "F...".
35
36"I..." indicates that the pin is configured as an interrupt. The
37next letter defines the type of interrupt, "r" for rising edge,
38"f" for falling edge, "h" for high level, and "l" for low level. If
39the pull-up is enabled, ubbctl adds an "R". Finally, it shows the
40pin status. E.g., "IfR1" would be an interrupt triggering on the
41falling edge, with pull-up enabled, and currently inactive.
3442
3543ubbctl can run in continuous mode, in which it updates the status
3644regularly (currently every 200 ms):
ubbctl/ubbctl.c
11/*
22 * ubbctl.c - Set and query UBB signals
33 *
4 * Written 2013 by Werner Almesberger
5 * Copyright 2013 Werner Almesberger
4 * Written 2013-2014 by Werner Almesberger
5 * Copyright 2013-2014 Werner Almesberger
66 *
77 * This program is free software; you can redistribute it and/or modify
88 * it under the terms of the GNU General Public License as published by
...... 
4646        pin = PIN(p->mask);
4747        if (PDFUN & p->mask) {
4848            putchar('F');
49            if (PDSEL & p->mask)
50                putchar('b');
51        } else if (PDSEL & p->mask) {
52            putchar('I');
53            if (PDTRG & p->mask) {
54                if (PDDIR & p->mask)
55                    putchar('r');
56                else
57                    putchar('f');
58            } else {
59                if (PDDIR & p->mask)
60                    putchar('h');
61                else
62                    putchar('l');
63            }
64            if (!(PDPULL & p->mask))
65                putchar('R');
4966        } else if (PDDIR & p->mask) {
5067            set = !!(PDDAT & p->mask);
5168            if (pin != set)
...... 
6582
6683static int setup_pin(const char *s, int doit)
6784{
85    static const char trigger[] = "lhfrLHFR";
6886    const struct pin *p;
69    const char *eq;
87    const char *eq, *t;
88    uint8_t trig;
7089
7190    if (!strcasecmp(s, "on"))
7291        s = "nPWR=0";
...... 
83102    if (!p->name)
84103        return 0;
85104
86    if (!strcasecmp(eq+1, "f")) {
87        if (doit)
105    if (!strcasecmp(eq+1, "f") || !strcasecmp(eq+1, "fa")) {
106        if (doit) {
107            PDFUNS = p->mask;
108            PDSELC = p->mask;
109        }
110        return 1;
111    }
112    if (!strcasecmp(eq+1, "fb")) {
113        if (doit) {
88114            PDFUNS = p->mask;
89    } else if (!strcmp(eq+1, "0")) {
115            PDSELS = p->mask;
116        }
117        return 1;
118    }
119    if (!strcmp(eq+1, "0")) {
90120        if (doit) {
91121            PDDATC = p->mask;
92122            PDDIRS = p->mask;
93123            PDFUNC = p->mask;
94124        }
95    } else if (!strcmp(eq+1, "1")) {
125        return 1;
126    }
127    if (!strcmp(eq+1, "1")) {
96128        if (doit) {
97129            PDDATS = p->mask;
98130            PDDIRS = p->mask;
99131            PDFUNC = p->mask;
100132        }
101    } else if (!strcasecmp(eq+1, "r")) {
133        return 1;
134    }
135    if (!strcasecmp(eq+1, "r")) {
102136        if (doit) {
103137            PDPULLC = p->mask;
104138            PDDIRC = p->mask;
105139            PDFUNC = p->mask;
140            PDSELC = p->mask;
106141        }
107    } else if (!strcasecmp(eq+1, "z")) {
142        return 1;
143    }
144    if (!strcasecmp(eq+1, "z")) {
108145        if (doit) {
109146            PDPULLS = p->mask;
110147            PDDIRC = p->mask;
111148            PDFUNC = p->mask;
149            PDSELC = p->mask;
112150        }
151        return 1;
152    }
153    if (eq[1] != 'i' && eq[1] != 'I')
154        return 0;
155
156    t = strchr(trigger, eq[2]);
157    if (!t || !*t)
158        return 0;
159
160    if (!eq[3] || eq[3] == 'z' || eq[3] == 'Z') {
161        if (doit)
162            PDPULLS = p->mask;
163    } else if (eq[3] == 'r' || eq[3] == 'R') {
164        if (doit)
165            PDPULLC = p->mask;
113166    } else {
114167        return 0;
115168    }
169
170    if (!doit)
171        return 1;
172
173    PDFUNC = p->mask;
174    PDSELS = p->mask;
175    trig = (t-trigger) & 3;
176    if (trig & 1)
177        PDDIRS = p->mask;
178    else
179        PDDIRC = p->mask;
180    if (trig & 2)
181        PDTRGS = p->mask;
182    else
183        PDTRGC = p->mask;
184
116185    return 1;
117186}
118187
...... 
124193" %s name=value|action ...\n\n"
125194" -c continously update the pin status (until user interrupts)\n\n"
126195"Names: nPWR, CMD, CLK, DAT0, DAT1, DAT2, DAT3\n"
127"Values: F, 0, 1, Z, R\n"
196"Values: F, Fa, Fb, 0, 1, Z, R, Ir[R|Z], If[R|Z], Ih[R|Z], Il[R|Z]\n"
128197"Actions: ON, OFF\n"
129198    , name, name);
130199    exit(1);

Archive Download the corresponding diff file

Branches:
master



interactive