Date:2010-09-05 21:59:59 (9 years 11 days ago)
Author:Werner Almesberger
Commit:9ad96bd5f9193e722f854ccee04629d689678924
Message:Board bringup: talk to the chip and read IDs.

- atusd/ERRATA: mention that the reset circuit can go, as expected
- atusd/tools/Makefile: add include path to at86rf230.h
- atusd/tools/lib/atusd.c: include atusd.h, for consistency checking
- atusd/tools/lib/atusd.c (spi_begin, spi_end, spi_data_in, spi_data_out,
spi_send_partial, spi_recv, spi_finish, spi_send): low-level functions
to access our modified SPI
- atusd/tools/lib/atusd.h, atusd/tools/lib/atusd.c (atusd_reg_write,
atusd_reg_read): register read and write access
- atusd/tools/try.c: read and print chip IDs
Files: atusd/ERRATA (1 diff)
atusd/tools/Makefile (1 diff)
atusd/tools/lib/atusd.c (4 diffs)
atusd/tools/lib/atusd.h (2 diffs)
atusd/tools/try.c (1 diff)

Change Details

atusd/ERRATA
66
77- the footprint of the transistor (Q1) is reversed :-( It works after
88  converting the chip from SOT to PLCC.
9
10- not an erratum, but with experiments showing power-on reset to be
11  reliable, we can consider removing the hardware reset circuit. This will
12  also simplify the layout.
atusd/tools/Makefile
11CC=mipsel-openwrt-linux-gcc
2CFLAGS=-Wall
2CFLAGS=-Wall -I../../atrf/fw/include
33
44MAIN = try
55OBJS = $(MAIN).c lib/atusd.o
atusd/tools/lib/atusd.c
55#include <fcntl.h>
66#include <sys/mman.h>
77
8#include "at86rf230.h"
9#include "atusd.h"
10
811
912enum {
1013    VDD_OFF = 1 << 6, /* VDD disable, PD06 */
...... 
2528#define GPIO(n) REG(0x10000+(n))
2629#define MSC(n) REG(0x21000+(n))
2730
31#define PDPIN GPIO(0x300) /* port D pin level */
2832#define PDDATS GPIO(0x314) /* port D data set */
2933#define PDDATC GPIO(0x318) /* port D data clear */
3034#define PDFUNS GPIO(0x344) /* port D function set */
...... 
142146
143147    /* start MMC clock output */
144148    MSC_STRPCL = 2;
149
150    /*
151     * Give power time to stabilize and the chip time to reset.
152     * Experiments show that even usleep(0) is long enough.
153     */
154    usleep(10*1000);
145155}
146156
147157
...... 
161171    PDDATS = nSEL;
162172    PDDATC = SLP_TR;
163173}
174
175
176static void spi_begin(struct atusd_dsc *dsc)
177{
178    PDDATC = nSEL;
179}
180
181
182static void spi_end(struct atusd_dsc *dsc)
183{
184    PDDATS = nSEL;
185}
186
187
188static void spi_data_in(struct atusd_dsc *dsc)
189{
190    PDDIRC = MxSx;
191}
192
193
194static void spi_data_out(struct atusd_dsc *dsc)
195{
196    PDDIRS = MxSx;
197}
198
199
200
201/*
202 * Send a sequence of bytes but leave the clock high on the last bit, so that
203 * we can turn around the data line for reads.
204 */
205
206static void spi_send_partial(struct atusd_dsc *dsc, uint8_t v)
207{
208    uint8_t mask;
209
210    for (mask = 0x80; mask; mask >>= 1) {
211        PDDATC = SCLK;
212        if (v & mask)
213            PDDATS = MxSx;
214        else
215            PDDATC = MxSx;
216        PDDATS = SCLK;
217    }
218}
219
220
221static uint8_t spi_recv(struct atusd_dsc *dsc)
222{
223    uint8_t res = 0;
224        uint8_t mask;
225
226    for (mask = 0x80; mask; mask >>= 1) {
227        PDDATC = SCLK;
228        if (PDPIN & MxSx)
229            res |= mask;
230        PDDATS = SCLK;
231    }
232    PDDATC = SCLK;
233        return res;
234}
235
236
237static void spi_finish(struct atusd_dsc *dsc)
238{
239    PDDATC = SCLK;
240}
241
242
243static void spi_send(struct atusd_dsc *dsc, uint8_t v)
244{
245    spi_send_partial(dsc, v);
246    spi_finish(dsc);
247}
248
249
250void atusd_reg_write(struct atusd_dsc *dsc, uint8_t reg, uint8_t v)
251{
252    spi_begin(dsc);
253    spi_send(dsc, AT86RF230_REG_WRITE | reg);
254    spi_send(dsc, v);
255    spi_end(dsc);
256}
257
258
259uint8_t atusd_reg_read(struct atusd_dsc *dsc, uint8_t reg)
260{
261    uint8_t res;
262
263    spi_begin(dsc);
264    spi_send_partial(dsc, AT86RF230_REG_READ| reg);
265    spi_data_in(dsc);
266    res = spi_recv(dsc);
267    spi_finish(dsc);
268    spi_data_out(dsc);
269    spi_end(dsc);
270    return res;
271}
atusd/tools/lib/atusd.h
1#ifndef ATUSD_H
2#define ATUSD_H
3
4#include <stdint.h>
5
6
17struct atusd_dsc;
28
39
...... 
511void atusd_close(struct atusd_dsc *dsc);
612void atusd_cycle(struct atusd_dsc *dsc);
713void atusd_reset(struct atusd_dsc *dsc);
14void atusd_reg_write(struct atusd_dsc *dsc, uint8_t reg, uint8_t v);
15uint8_t atusd_reg_read(struct atusd_dsc *dsc, uint8_t reg);
16
17#endif /* ATUSD_H */
atusd/tools/try.c
1#include <stdint.h>
12#include <stdio.h>
23#include <unistd.h>
34
5#include "at86rf230.h"
46#include "lib/atusd.h"
57
68
79int main(void)
810{
911    struct atusd_dsc *dsc;
10    char tmp;
12    uint8_t part, version, man_id_0, man_id_1;
1113
1214    dsc = atusd_open();
13    read(1, &tmp, 1);
14fprintf(stderr, "cycling\n");
15
1516    atusd_cycle(dsc);
16    read(1, &tmp, 1);
17// atusd_reset(dsc);
18
19        part = atusd_reg_read(dsc, REG_PART_NUM);
20        version = atusd_reg_read(dsc, REG_VERSION_NUM);
21        man_id_0 = atusd_reg_read(dsc, REG_MAN_ID_0);
22        man_id_1 = atusd_reg_read(dsc, REG_MAN_ID_1);
23        printf("part 0x%02x version %u manufacturer xxxx%02x%02x\n",
24            part, version, man_id_1, man_id_0);
25
1726    atusd_close(dsc);
1827
1928    return 0;

Archive Download the corresponding diff file



interactive