IEEE 802.15.4 subsystem
Sign in or create your account | Project List | Help
IEEE 802.15.4 subsystem Commit Details
Date: | 2011-06-03 20:25:57 (12 years 9 months ago) |
---|---|
Author: | Werner Almesberger |
Commit: | 4924755a154794672548f3c31a5d6297e5ccee24 |
Message: | atrf-gpio: new utility to directly access GPIOs (for now atben-only) - tools/atrf-gpio/: new utility to directly access GPIOs - tools/Makefile (BEN_DIRS): added atrf-gpio |
Files: |
tools/Makefile (1 diff) tools/atrf-gpio/Makefile (1 diff) tools/atrf-gpio/atben.c (1 diff) tools/atrf-gpio/atrf-gpio.c (1 diff) tools/atrf-gpio/atrf-gpio.h (1 diff) tools/atrf-gpio/atusb.c (1 diff) |
Change Details
tools/Makefile | ||
---|---|---|
11 | 11 | # |
12 | 12 | |
13 | 13 | |
14 | BEN_DIRS=atrf-id atrf-path atrf-proxy atrf-reset atrf-rssi atrf-trim \ | |
15 | atrf-txrx atrf-xmit atrf-xtal | |
14 | BEN_DIRS=atrf-gpio atrf-id atrf-path atrf-proxy atrf-reset \ | |
15 | atrf-rssi atrf-trim atrf-txrx atrf-xmit atrf-xtal | |
16 | 16 | DIRS=$(BEN_DIRS) usbwait |
17 | 17 | TARGET_ONLY_DIRS=lib |
18 | 18 |
tools/atrf-gpio/Makefile | ||
---|---|---|
1 | # | |
2 | # atrf-gpio/Makefile - Build the GPIO test utility | |
3 | # | |
4 | # Written 2010, 2011 by Werner Almesberger | |
5 | # Copyright 2010, 2011 Werner Almesberger | |
6 | # | |
7 | # This program is free software; you can redistribute it and/or modify | |
8 | # it under the terms of the GNU General Public License as published by | |
9 | # the Free Software Foundation; either version 2 of the License, or | |
10 | # (at your option) any later version. | |
11 | # | |
12 | ||
13 | ||
14 | MAIN = atrf-gpio | |
15 | ||
16 | include ../Makefile.common | |
17 | ||
18 | MACROS_host += -DHAVE_ATUSB | |
19 | OBJS_host = atusb.o | |
20 | ||
21 | MACROS_ben_openwrt += -DHAVE_ATBEN | |
22 | OBJS_ben_openwrt = atben.o | |
23 | ||
24 | MACROS_ben_jlime += -DHAVE_ATBEN | |
25 | OBJS_ben_jlime = atben.o | |
26 | ||
27 | ||
28 | $(MAIN): $(OBJS_$(TARGET)) | |
29 | ||
30 | clean:: | |
31 | rm -f $(OBJS_host) $(OBJS_ben_openwrt) $(OBJS_ben_jlime) |
tools/atrf-gpio/atben.c | ||
---|---|---|
1 | /* | |
2 | * atrf-gpio/atben.c - ATBEN-specific GPIO driver | |
3 | * | |
4 | * Written 2011 by Werner Almesberger | |
5 | * Copyright 2011 Werner Almesberger | |
6 | * | |
7 | * This program is free software; you can redistribute it and/or modify | |
8 | * it under the terms of the GNU General Public License as published by | |
9 | * the Free Software Foundation; either version 2 of the License, or | |
10 | * (at your option) any later version. | |
11 | */ | |
12 | ||
13 | ||
14 | #include <stdint.h> | |
15 | #include <stdlib.h> | |
16 | #include <stdio.h> | |
17 | #include <unistd.h> | |
18 | ||
19 | #include "at86rf230.h" | |
20 | #include "atrf.h" | |
21 | ||
22 | #include "atrf-gpio.h" | |
23 | ||
24 | ||
25 | static struct pin { | |
26 | const char *name; | |
27 | int bit; | |
28 | } pins[] = { | |
29 | { "SCLK", 11 }, | |
30 | { "MISO", 10 }, | |
31 | { "SLP_TR", 9 }, | |
32 | { "MOSI", 8 }, | |
33 | { "nSEL", 13 }, | |
34 | { "IRQ", 12 }, | |
35 | { NULL, 0 } | |
36 | }; | |
37 | ||
38 | static uint32_t orig_dat, orig_pe, orig_dir; | |
39 | static uint32_t changed = 0; | |
40 | ||
41 | ||
42 | /* ----- Ben hardware ------------------------------------------------------ */ | |
43 | ||
44 | ||
45 | static volatile uint32_t *pdpin, *pddat, *pddats, *pddatc; | |
46 | static volatile uint32_t *pdpe, *pdpes, *pdpec; | |
47 | static volatile uint32_t *pddir, *pddirs, *pddirc; | |
48 | ||
49 | ||
50 | static void ben_setup(struct atrf_dsc *dsc) | |
51 | { | |
52 | volatile void *base = atrf_ben_regs(dsc); | |
53 | ||
54 | pdpin = base+0x10300; | |
55 | pddat = base+0x10310; | |
56 | pddats = base+0x10314; | |
57 | pddatc = base+0x10318; | |
58 | ||
59 | pdpe = base+0x10330; | |
60 | pdpes = base+0x10334; | |
61 | pdpec = base+0x10338; | |
62 | ||
63 | pddir = base+0x10360; | |
64 | pddirs = base+0x10364; | |
65 | pddirc = base+0x10368; | |
66 | } | |
67 | ||
68 | ||
69 | /* ----- Diagnostic dump --------------------------------------------------- */ | |
70 | ||
71 | ||
72 | static char decode_cfg(uint32_t bit) | |
73 | { | |
74 | if (*pddir & bit) | |
75 | return *pddat & bit ? '1' : '0'; | |
76 | return *pdpe & bit ? 'Z' : 'P'; | |
77 | } | |
78 | ||
79 | ||
80 | static void dump_pd(uint32_t expect, uint32_t got, uint32_t mask) | |
81 | { | |
82 | const struct pin *pin; | |
83 | ||
84 | fprintf(stderr, "name\tcfg exp got\n"); | |
85 | for (pin = pins; pin->name; pin++) { | |
86 | uint32_t bit = 1 << pin->bit; | |
87 | ||
88 | fprintf(stderr, "%s\t%c %d %d", | |
89 | pin->name, decode_cfg(bit), | |
90 | !!(expect & bit), !!(got & bit)); | |
91 | if ((expect ^ got) & mask & bit) | |
92 | fprintf(stderr, "\t***"); | |
93 | fputc('\n', stderr); | |
94 | } | |
95 | } | |
96 | ||
97 | ||
98 | static void restore_gpios(void) | |
99 | { | |
100 | *pddats = orig_dat & changed; | |
101 | *pddatc = ~orig_dat & changed; | |
102 | *pdpes = orig_pe & changed; | |
103 | *pdpec = ~orig_pe & changed; | |
104 | *pddirs = orig_dir & changed; | |
105 | *pddirc = ~orig_dir & changed; | |
106 | } | |
107 | ||
108 | ||
109 | /* ----- Decode and apply pattern ------------------------------------------ */ | |
110 | ||
111 | ||
112 | void do_atben(struct atrf_dsc *dsc, const char *pattern, const char *next) | |
113 | { | |
114 | static int first = 1; | |
115 | uint32_t read = 0, expect = 0; | |
116 | const struct pin *pin = pins; | |
117 | uint32_t got; | |
118 | const char *p; | |
119 | ||
120 | if (first) { | |
121 | ben_setup(dsc); | |
122 | orig_dat = *pddat; | |
123 | orig_pe = *pdpe; | |
124 | orig_dir = *pddir; | |
125 | atexit(restore_gpios); | |
126 | ||
127 | first = 0; | |
128 | } | |
129 | ||
130 | for (p = pattern; *p; p++) { | |
131 | uint32_t bit; | |
132 | ||
133 | if (!pin->name) { | |
134 | fprintf(stderr, "too many pins in \"%s\"\n", pattern); | |
135 | exit(1); | |
136 | } | |
137 | bit = 1 << pin->bit; | |
138 | switch (*p) { | |
139 | case '0': | |
140 | *pddatc = bit; | |
141 | *pddirs = bit; | |
142 | break; | |
143 | case '1': | |
144 | *pddats = bit; | |
145 | *pddirs = bit; | |
146 | break; | |
147 | case 'H': | |
148 | expect |= bit; | |
149 | /* fall through */ | |
150 | case 'L': | |
151 | read |= bit; | |
152 | /* fall through */ | |
153 | case 'Z': | |
154 | *pdpec = bit; | |
155 | *pddirc = bit; | |
156 | break; | |
157 | case 'h': | |
158 | expect |= bit; | |
159 | /* fall through */ | |
160 | case 'l': | |
161 | read |= bit; | |
162 | /* fall through */ | |
163 | case 'z': | |
164 | *pddirc = bit; | |
165 | *pdpes = bit; | |
166 | break; | |
167 | case 'x': | |
168 | pin++; | |
169 | continue; | |
170 | default: | |
171 | continue; | |
172 | } | |
173 | changed |= bit; | |
174 | pin++; | |
175 | } | |
176 | ||
177 | usleep(1000); | |
178 | ||
179 | got = *pdpin; | |
180 | if ((got & read) != expect) { | |
181 | dump_pd(expect, got, read); | |
182 | fprintf(stderr, "at \"%s\", next \"%s\"\n", pattern, next); | |
183 | exit(1); | |
184 | } | |
185 | } |
tools/atrf-gpio/atrf-gpio.c | ||
---|---|---|
1 | /* | |
2 | * atrf-gpio/atrf-gpio.c - ATBEN/ATUSB GPIO test | |
3 | * | |
4 | * Written 2011 by Werner Almesberger | |
5 | * Copyright 2011 Werner Almesberger | |
6 | * | |
7 | * This program is free software; you can redistribute it and/or modify | |
8 | * it under the terms of the GNU General Public License as published by | |
9 | * the Free Software Foundation; either version 2 of the License, or | |
10 | * (at your option) any later version. | |
11 | */ | |
12 | ||
13 | ||
14 | #include <stdlib.h> | |
15 | #include <stdio.h> | |
16 | #include <unistd.h> | |
17 | #include <string.h> | |
18 | ||
19 | #include "at86rf230.h" | |
20 | #include "atrf.h" | |
21 | ||
22 | #include "atrf-gpio.h" | |
23 | ||
24 | ||
25 | static void atben(struct atrf_dsc *dsc, const char *pattern, const char *next) | |
26 | { | |
27 | #ifdef HAVE_ATBEN | |
28 | do_atben(dsc, pattern, next); | |
29 | #else | |
30 | fprintf(stderr, "not compiled with ATBEN support\n"); | |
31 | exit(1); | |
32 | #endif | |
33 | } | |
34 | ||
35 | ||
36 | static void atusb(struct atrf_dsc *dsc, const char *pattern, const char *next) | |
37 | { | |
38 | #ifdef HAVE_ATUSB | |
39 | do_atusb(dsc, pattern, next); | |
40 | #else | |
41 | fprintf(stderr, "not compiled with ATUSB support\n"); | |
42 | exit(1); | |
43 | #endif | |
44 | } | |
45 | ||
46 | ||
47 | static void bad_reg_op(const char *arg) | |
48 | { | |
49 | fprintf(stderr, "invalid operation \"%s\"\n", arg); | |
50 | exit(1); | |
51 | } | |
52 | ||
53 | ||
54 | static int reg_op(struct atrf_dsc *dsc, const char *arg, int doit) | |
55 | { | |
56 | const char *p; | |
57 | char *end; | |
58 | unsigned long reg, value; | |
59 | uint8_t got; | |
60 | ||
61 | p = strchr(arg, '='); | |
62 | if (!p) | |
63 | p = strchr(arg, ':'); | |
64 | if (!p) | |
65 | p = strchr(arg, '!'); | |
66 | if (!p) | |
67 | p = strchr(arg, '/'); | |
68 | if (!p) | |
69 | return 0; | |
70 | reg = strtoul(arg, &end, 0); | |
71 | if (end != p || reg > 0xff) | |
72 | bad_reg_op(arg); | |
73 | value = strtoul(p+1, &end, 0); | |
74 | if (*end || value > 0xff) | |
75 | bad_reg_op(arg); | |
76 | if (!doit) | |
77 | return 1; | |
78 | switch (*p) { | |
79 | case '=': | |
80 | atrf_reg_write(dsc, reg, value); | |
81 | break; | |
82 | case ':': | |
83 | got = atrf_reg_read(dsc, reg); | |
84 | if (end != p+1 && got != value) { | |
85 | fprintf(stderr, | |
86 | "register 0x%02lx: got 0x%02x expected 0x%02lx\n", | |
87 | reg, got, value); | |
88 | exit(1); | |
89 | } | |
90 | break; | |
91 | case '!': | |
92 | atrf_sram_write(dsc, reg, value); | |
93 | break; | |
94 | case '/': | |
95 | got = atrf_sram_read(dsc, reg); | |
96 | if (got != value) { | |
97 | fprintf(stderr, | |
98 | "got 0x%02x expected 0x%02lx\n", got, value); | |
99 | exit(1); | |
100 | } | |
101 | break; | |
102 | default: | |
103 | abort(); | |
104 | } | |
105 | return 1; | |
106 | } | |
107 | ||
108 | ||
109 | static void usage(const char *name) | |
110 | { | |
111 | fprintf(stderr, | |
112 | "usage: %s [-d driver[:arg]] command|pattern ...\n" | |
113 | " -d driver[:arg] use the specified driver (default: %s)\n\n" | |
114 | " command is one of:\n" | |
115 | " reg=value set transceiver register\n" | |
116 | " reg:[value] read transceiver register and (optionally) verify value\n" | |
117 | " addr!value write one byte to SRAM\n" | |
118 | " addr/value read and verify one byte from SRAM\n" | |
119 | " #... comment\n\n" | |
120 | " pattern is a sequence of the following characters:\n" | |
121 | " 0 = output a strong 0 1 = output a strong 1\n" | |
122 | " L = pull up, expect to read 0 H = pull up, expect to read 1\n" | |
123 | " l = no pull-up, expect to read 0 h = no pull-up, expect to read 1\n" | |
124 | " Z = pull up, don't read z = no pull-up, don't read\n" | |
125 | " x = don't care . = separator\n" | |
126 | , name, atrf_default_driver_name()); | |
127 | exit(1); | |
128 | } | |
129 | ||
130 | ||
131 | /* | |
132 | * 0 strong 0 out | |
133 | * 1 strong 1 out | |
134 | * H pull-up, read 1 | |
135 | * L pull-up, read 0 | |
136 | * h no pull-up, read 1 | |
137 | * l no pull-up, read 0 | |
138 | * Z pull-up, don't read | |
139 | * z no pull-up, don't read | |
140 | * x don't care | |
141 | * . separator | |
142 | */ | |
143 | ||
144 | ||
145 | int main(int argc, char *const *argv) | |
146 | { | |
147 | const char *driver = NULL; | |
148 | struct atrf_dsc *dsc; | |
149 | int trx_off = 1; | |
150 | int c, i; | |
151 | const char *s; | |
152 | ||
153 | while ((c = getopt(argc, argv, "d:p")) != EOF) | |
154 | switch (c) { | |
155 | case 'd': | |
156 | driver = optarg; | |
157 | break; | |
158 | case 'p': | |
159 | trx_off = 0; | |
160 | break; | |
161 | default: | |
162 | usage(*argv); | |
163 | } | |
164 | ||
165 | for (i = optind; i != argc; i++) { | |
166 | if (*argv[i] == '#') | |
167 | continue; | |
168 | if (reg_op(NULL, argv[i], 0)) | |
169 | continue; | |
170 | for (s = argv[i]; *s; s++) | |
171 | if (!strchr("01HLhlZzx.", *s)) | |
172 | fprintf(stderr, | |
173 | "invalid configuration '%c' in \"%s\"\n", | |
174 | *s, argv[i]); | |
175 | } | |
176 | ||
177 | dsc = atrf_open(driver); | |
178 | if (!dsc) | |
179 | return 1; | |
180 | ||
181 | atrf_reset_rf(dsc); | |
182 | ||
183 | if (trx_off) { | |
184 | atrf_reg_write(dsc, REG_TRX_STATE, TRX_CMD_TRX_OFF); | |
185 | do usleep(100); | |
186 | while ((atrf_reg_read(dsc, REG_TRX_STATUS) & TRX_STATUS_MASK) | |
187 | != TRX_STATUS_TRX_OFF); | |
188 | } | |
189 | ||
190 | for (i = optind; i != argc; i++) { | |
191 | if (*argv[i] == '#') | |
192 | continue; | |
193 | if (reg_op(dsc, argv[i], 1)) | |
194 | continue; | |
195 | if (atrf_usb_handle(dsc)) | |
196 | atusb(dsc, argv[i], argv[i+1]); | |
197 | else | |
198 | atben(dsc, argv[i], argv[i+1]); | |
199 | } | |
200 | ||
201 | // atrf_close(dsc); | |
202 | ||
203 | return 0; | |
204 | } |
tools/atrf-gpio/atrf-gpio.h | ||
---|---|---|
1 | /* | |
2 | * atrf-gpio/atrf-gpio.h - ATBEN/ATUSB GPIO test | |
3 | * | |
4 | * Written 2011 by Werner Almesberger | |
5 | * Copyright 2011 Werner Almesberger | |
6 | * | |
7 | * This program is free software; you can redistribute it and/or modify | |
8 | * it under the terms of the GNU General Public License as published by | |
9 | * the Free Software Foundation; either version 2 of the License, or | |
10 | * (at your option) any later version. | |
11 | */ | |
12 | ||
13 | ||
14 | #ifndef ATRF_GPIO_H | |
15 | #define ATRF_GPIO_H | |
16 | ||
17 | #include "atrf.h" | |
18 | ||
19 | ||
20 | void do_atben(struct atrf_dsc *dsc, const char *pattern, const char *next); | |
21 | void do_atusb(struct atrf_dsc *dsc, const char *pattern, const char *next); | |
22 | ||
23 | #endif /* !ATRF_GPIO_H */ |
tools/atrf-gpio/atusb.c | ||
---|---|---|
1 | /* | |
2 | * atrf-gpio/atusb.c - ATUSB-specific GPIO driver | |
3 | * | |
4 | * Written 2011 by Werner Almesberger | |
5 | * Copyright 2011 Werner Almesberger | |
6 | * | |
7 | * This program is free software; you can redistribute it and/or modify | |
8 | * it under the terms of the GNU General Public License as published by | |
9 | * the Free Software Foundation; either version 2 of the License, or | |
10 | * (at your option) any later version. | |
11 | */ | |
12 | ||
13 | ||
14 | #include <stdlib.h> | |
15 | ||
16 | #include "atrf.h" | |
17 | ||
18 | #include "atrf-gpio.h" | |
19 | ||
20 | ||
21 | /* ----- Decode and apply pattern ------------------------------------------ */ | |
22 | ||
23 | ||
24 | void do_atusb(struct atrf_dsc *dsc, const char *pattern, const char *next) | |
25 | { | |
26 | abort(); | |
27 | } |