Date:2010-11-11 12:41:25 (9 years 11 days ago)
Author:Werner Almesberger
Commit:96b6a50b3a1f9f889e1a59631bc17836511aaf06
Message:The Great ATSPI Renaming, part 2: rename ATSPI_* identifiers to ATUSB_*

- atusb/fw/include/atusb/ep0.h, atusb/fw/atusb/ep0.c: rename all ATSPI_*
identifiers (EP0 commands, protocol revision, etc.) to ATUSB_*
- tools/lib/atusb.c, tools/atspi-id/atspi-id.c: track identifier change
Files: atusb/fw/atusb/ep0.c (7 diffs)
atusb/fw/include/atusb/ep0.h (2 diffs)
tools/atspi-id/atspi-id.c (3 diffs)
tools/lib/atusb.c (10 diffs)

Change Details

atusb/fw/atusb/ep0.c
5858    } while (0)
5959
6060
61static const uint8_t id[] = { EP0ATSPI_MAJOR, EP0ATSPI_MINOR, HW_TYPE };
61static const uint8_t id[] = { EP0ATUSB_MAJOR, EP0ATUSB_MINOR, HW_TYPE };
6262static __xdata uint8_t buf[MAX_PSDU+3]; /* command, PHDR, and LQI */
6363static uint8_t size;
6464
...... 
110110    uint8_t i;
111111
112112    switch (setup->bmRequestType | setup->bRequest << 8) {
113    case ATSPI_FROM_DEV(ATSPI_ID):
114        debug("ATSPI_ID\n");
113    case ATUSB_FROM_DEV(ATUSB_ID):
114        debug("ATUSB_ID\n");
115115        if (setup->wLength > 3)
116116            return 0;
117117        usb_send(&ep0, id, setup->wLength, NULL, NULL);
118118        return 1;
119    case ATSPI_FROM_DEV(ATSPI_BUILD):
120        debug("ATSPI_BUILD\n");
119    case ATUSB_FROM_DEV(ATUSB_BUILD):
120        debug("ATUSB_BUILD\n");
121121        tmp = build_number;
122122        for (i = BUILD_OFFSET-2; tmp; i--) {
123123            buf[i] = (tmp % 10)+'0';
...... 
134134        usb_send(&ep0, buf+i, size, NULL, NULL);
135135        return 1;
136136
137    case ATSPI_TO_DEV(ATSPI_RESET):
138        debug("ATSPI_RESET\n");
137    case ATUSB_TO_DEV(ATUSB_RESET):
138        debug("ATUSB_RESET\n");
139139        RSTSRC = SWRSF;
140140        while (1);
141141
142    case ATSPI_TO_DEV(ATSPI_RF_RESET):
143        debug("ATSPI_RF_RESET\n");
142    case ATUSB_TO_DEV(ATUSB_RF_RESET):
143        debug("ATUSB_RF_RESET\n");
144144        reset_rf();
145145        return 1;
146146
147    case ATSPI_FROM_DEV(ATSPI_POLL_INT):
148        debug("ATSPI_POLL_INT\n");
147    case ATUSB_FROM_DEV(ATUSB_POLL_INT):
148        debug("ATUSB_POLL_INT\n");
149149        if (setup->wLength < 1)
150150            return 0;
151151        *buf = IRQ_RF;
152152        usb_send(&ep0, buf, 1, NULL, NULL);
153153        return 1;
154154
155    case ATSPI_TO_DEV(ATSPI_TEST):
156        debug("ATSPI_TEST\n");
155    case ATUSB_TO_DEV(ATUSB_TEST):
156        debug("ATUSB_TEST\n");
157157        test_mode();
158158        return 1;
159159
160    case ATSPI_TO_DEV(ATSPI_REG_WRITE):
161        debug("ATSPI_REG_WRITE\n");
160    case ATUSB_TO_DEV(ATUSB_REG_WRITE):
161        debug("ATUSB_REG_WRITE\n");
162162        nSS = 0;
163163        spi_send(AT86RF230_REG_WRITE | setup->wIndex);
164164        spi_send(setup->wValue);
165165        nSS = 1;
166166        return 1;
167    case ATSPI_FROM_DEV(ATSPI_REG_READ):
168        debug("ATSPI_REG_READ\n");
167    case ATUSB_FROM_DEV(ATUSB_REG_READ):
168        debug("ATUSB_REG_READ\n");
169169        nSS = 0;
170170        spi_send(AT86RF230_REG_READ | setup->wIndex);
171171        *buf = spi_recv();
...... 
173173        usb_send(&ep0, buf, 1, NULL, NULL);
174174        return 1;
175175
176    case ATSPI_TO_DEV(ATSPI_BUF_WRITE):
177        debug("ATSPI_BUF_WRITE\n");
176    case ATUSB_TO_DEV(ATUSB_BUF_WRITE):
177        debug("ATUSB_BUF_WRITE\n");
178178        if (setup->wLength < 1)
179179            return 0;
180180        if (setup->wLength > MAX_PSDU)
...... 
184184        size = setup->wLength+2;
185185        usb_recv(&ep0, buf+2, setup->wLength, do_buf_write, NULL);
186186        return 1;
187    case ATSPI_FROM_DEV(ATSPI_BUF_READ):
188        debug("ATSPI_BUF_READ\n");
187    case ATUSB_FROM_DEV(ATUSB_BUF_READ):
188        debug("ATUSB_BUF_READ\n");
189189        if (setup->wLength < 2) /* PHR+LQI */
190190            return 0;
191191        if (setup->wLength > MAX_PSDU+2) /* PHR+PSDU+LQI */
...... 
201201        usb_send(&ep0, buf, size+1, NULL, NULL);
202202        return 1;
203203
204    case ATSPI_TO_DEV(ATSPI_SRAM_WRITE):
205        debug("ATSPI_SRAM_WRITE\n");
204    case ATUSB_TO_DEV(ATUSB_SRAM_WRITE):
205        debug("ATUSB_SRAM_WRITE\n");
206206        if (setup->wIndex > SRAM_SIZE)
207207            return 0;
208208        if (setup->wIndex+setup->wLength > SRAM_SIZE)
...... 
212212        size = setup->wLength+2;
213213        usb_recv(&ep0, buf+2, setup->wLength, do_buf_write, NULL);
214214        return 1;
215    case ATSPI_TO_DEV(ATSPI_SRAM_READ):
216        debug("ATSPI_SRAM_READ\n");
215    case ATUSB_TO_DEV(ATUSB_SRAM_READ):
216        debug("ATUSB_SRAM_READ\n");
217217        if (setup->wIndex > SRAM_SIZE)
218218            return 0;
219219        if (setup->wIndex+setup->wLength > SRAM_SIZE)
atusb/fw/include/atusb/ep0.h
1717/*
1818 * Direction bRequest wValue wIndex wLength
1919 *
20 * ->host ATSPI_ID - - 3
21 * ->host ATSPI_BUILD - - #bytes
22 * host-> ATSPI_RESET - - 0
20 * ->host ATUSB_ID - - 3
21 * ->host ATUSB_BUILD - - #bytes
22 * host-> ATUSB_RESET - - 0
2323 *
24 * host-> ATSPI_RF_RESET - - 0
25 * ->host ATSPI_POLL_INT - - 1
26 * host-> ATSPI_TEST - - 0
24 * host-> ATUSB_RF_RESET - - 0
25 * ->host ATUSB_POLL_INT - - 1
26 * host-> ATUSB_TEST - - 0
2727 *
28 * host-> ATSPI_REG_WRITE value addr 0
29 * ->host ATSPI_REG_READ - addr 1
30 * host-> ATSPI_BUF_WRITE - - #bytes
31 * ->host ATSPI_BUF_READ - - #bytes
32 * host-> ATSPI_SRAM_WRITE - addr #bytes
33 * ->host ATSPI_SRAM_READ - addr #bytes
28 * host-> ATUSB_REG_WRITE value addr 0
29 * ->host ATUSB_REG_READ - addr 1
30 * host-> ATUSB_BUF_WRITE - - #bytes
31 * ->host ATUSB_BUF_READ - - #bytes
32 * host-> ATUSB_SRAM_WRITE - addr #bytes
33 * ->host ATUSB_SRAM_READ - addr #bytes
3434 */
3535
3636/*
3737 * EP0 protocol:
3838 *
3939 * 0.0 initial release
40 * 0.1 addition of ATSPI_TEST
40 * 0.1 addition of ATUSB_TEST
4141 */
4242
43#define EP0ATSPI_MAJOR 0 /* EP0 protocol, major revision */
44#define EP0ATSPI_MINOR 1 /* EP0 protocol, minor revision */
43#define EP0ATUSB_MAJOR 0 /* EP0 protocol, major revision */
44#define EP0ATUSB_MINOR 1 /* EP0 protocol, minor revision */
4545
4646#define HW_TYPE_100813 0 /* 100813 */
4747
...... 
5757 */
5858
5959
60#define ATSPI_TO_DEV(req) (0x40 | (req) << 8)
61#define ATSPI_FROM_DEV(req) (0xc0 | (req) << 8)
60#define ATUSB_TO_DEV(req) (0x40 | (req) << 8)
61#define ATUSB_FROM_DEV(req) (0xc0 | (req) << 8)
6262
6363
6464enum atspi_requests {
65    ATSPI_ID = 0x00,
66    ATSPI_BUILD,
67    ATSPI_RESET,
68    ATSPI_RF_RESET = 0x10,
69    ATSPI_POLL_INT,
70    ATSPI_TEST,
71    ATSPI_REG_WRITE = 0x20,
72    ATSPI_REG_READ,
73    ATSPI_BUF_WRITE,
74    ATSPI_BUF_READ,
75    ATSPI_SRAM_WRITE,
76    ATSPI_SRAM_READ,
65    ATUSB_ID = 0x00,
66    ATUSB_BUILD,
67    ATUSB_RESET,
68    ATUSB_RF_RESET = 0x10,
69    ATUSB_POLL_INT,
70    ATUSB_TEST,
71    ATUSB_REG_WRITE = 0x20,
72    ATUSB_REG_READ,
73    ATUSB_BUF_WRITE,
74    ATUSB_BUF_READ,
75    ATUSB_SRAM_WRITE,
76    ATUSB_SRAM_READ,
7777};
7878
7979
tools/atspi-id/atspi-id.c
2525
2626#ifdef HAVE_USB
2727
28#define FROM_DEV ATSPI_FROM_DEV(0)
28#define FROM_DEV ATUSB_FROM_DEV(0)
2929
3030#define BUF_SIZE 256
3131
...... 
3434{
3535    int res;
3636
37    res = usb_control_msg(dev, FROM_DEV, ATSPI_ID, 0, 0, data, size, 1000);
37    res = usb_control_msg(dev, FROM_DEV, ATUSB_ID, 0, 0, data, size, 1000);
3838    if (res < 0)
39        fprintf(stderr, "ATSPI_ID: %s\n", usb_strerror());
39        fprintf(stderr, "ATUSB_ID: %s\n", usb_strerror());
4040    return res;
4141}
4242
...... 
6363{
6464    int res;
6565
66    res = usb_control_msg(dev, FROM_DEV, ATSPI_BUILD, 0, 0, buf, size,
66    res = usb_control_msg(dev, FROM_DEV, ATUSB_BUILD, 0, 0, buf, size,
6767        1000);
6868    if (res < 0)
69        fprintf(stderr, "ATSPI_BUILD: %s\n", usb_strerror());
69        fprintf(stderr, "ATUSB_BUILD: %s\n", usb_strerror());
7070    return res;
7171}
7272
tools/lib/atusb.c
11/*
2 * lib/atusb.c - ATSPI access functions library (USB version)
2 * lib/atusb.c - ATUSB access functions library (USB version)
33 *
44 * Written 2010 by Werner Almesberger
55 * Copyright 2010 Werner Almesberger
...... 
2121#include "driver.h"
2222
2323
24#define FROM_DEV ATSPI_FROM_DEV(0)
25#define TO_DEV ATSPI_TO_DEV(0)
24#define FROM_DEV ATUSB_FROM_DEV(0)
25#define TO_DEV ATUSB_TO_DEV(0)
2626
2727
2828/* ----- error handling ---------------------------------------------------- */
...... 
8383        return;
8484
8585    res =
86        usb_control_msg(dev, TO_DEV, ATSPI_RESET, 0, 0, NULL, 0, 1000);
86        usb_control_msg(dev, TO_DEV, ATUSB_RESET, 0, 0, NULL, 0, 1000);
8787    if (res < 0) {
88        fprintf(stderr, "ATSPI_RESET: %d\n", res);
88        fprintf(stderr, "ATUSB_RESET: %d\n", res);
8989        error = 1;
9090    }
9191}
...... 
100100        return;
101101
102102    res =
103        usb_control_msg(dev, TO_DEV, ATSPI_RF_RESET, 0, 0, NULL, 0, 1000);
103        usb_control_msg(dev, TO_DEV, ATUSB_RF_RESET, 0, 0, NULL, 0, 1000);
104104    if (res < 0) {
105        fprintf(stderr, "ATSPI_RF_RESET: %d\n", res);
105        fprintf(stderr, "ATUSB_RF_RESET: %d\n", res);
106106        error = 1;
107107    }
108108}
...... 
117117        return;
118118
119119    res =
120        usb_control_msg(dev, TO_DEV, ATSPI_TEST, 0, 0, NULL, 0, 1000);
120        usb_control_msg(dev, TO_DEV, ATUSB_TEST, 0, 0, NULL, 0, 1000);
121121    if (res < 0) {
122        fprintf(stderr, "ATSPI_TEST: %d\n", res);
122        fprintf(stderr, "ATUSB_TEST: %d\n", res);
123123        error = 1;
124124    }
125125}
...... 
136136    if (error)
137137        return;
138138
139    res = usb_control_msg(dev, TO_DEV, ATSPI_REG_WRITE, value, reg,
139    res = usb_control_msg(dev, TO_DEV, ATUSB_REG_WRITE, value, reg,
140140        NULL, 0, 1000);
141141    if (res < 0) {
142        fprintf(stderr, "ATSPI_REG_WRITE: %d\n", res);
142        fprintf(stderr, "ATUSB_REG_WRITE: %d\n", res);
143143        error = 1;
144144    }
145145}
...... 
154154    if (error)
155155        return 0;
156156
157    res = usb_control_msg(dev, FROM_DEV, ATSPI_REG_READ, 0, reg,
157    res = usb_control_msg(dev, FROM_DEV, ATUSB_REG_READ, 0, reg,
158158        (void *) &value, 1, 1000);
159159    if (res < 0) {
160        fprintf(stderr, "ATSPI_REG_READ: %d\n", res);
160        fprintf(stderr, "ATUSB_REG_READ: %d\n", res);
161161        error = 1;
162162    }
163163    return value;
...... 
175175    if (error)
176176        return;
177177
178    res = usb_control_msg(dev, TO_DEV, ATSPI_BUF_WRITE, 0, 0,
178    res = usb_control_msg(dev, TO_DEV, ATUSB_BUF_WRITE, 0, 0,
179179        (void *) buf, size, 1000);
180180    if (res < 0) {
181        fprintf(stderr, "ATSPI_BUF_WRITE: %d\n", res);
181        fprintf(stderr, "ATUSB_BUF_WRITE: %d\n", res);
182182        error = 1;
183183    }
184184
...... 
193193    if (error)
194194        return -1;
195195
196    res = usb_control_msg(dev, FROM_DEV, ATSPI_BUF_READ, 0, 0,
196    res = usb_control_msg(dev, FROM_DEV, ATUSB_BUF_READ, 0, 0,
197197        buf, size, 1000);
198198    if (res < 0) {
199        fprintf(stderr, "ATSPI_BUF_READ: %d\n", res);
199        fprintf(stderr, "ATUSB_BUF_READ: %d\n", res);
200200        error = 1;
201201    }
202202
...... 
216216    if (error)
217217        return -1;
218218
219    res = usb_control_msg(dev, FROM_DEV, ATSPI_POLL_INT, 0, 0,
219    res = usb_control_msg(dev, FROM_DEV, ATUSB_POLL_INT, 0, 0,
220220        (void *) &buf, 1, 1000);
221221    if (res < 0) {
222        fprintf(stderr, "ATSPI_POLL_INT: %d\n", res);
222        fprintf(stderr, "ATUSB_POLL_INT: %d\n", res);
223223        error = 1;
224224    }
225225

Archive Download the corresponding diff file



interactive