Date:2010-08-20 20:09:45 (9 years 4 months ago)
Author:Werner Almesberger
Commit:bb4b07f86aa4af35b9208be26b774611a0a8e9aa
Message:Simplified the presentation of build date information and added a command-line utility to retrieve it.

- fw/include/atspi/ep0.h, fw/atspi/ep0.c (my_setup): merged
ATSPI_BUILD_NUMBER and ATSPI_BUILD_DATE into single ATSPI_BUILD
- fw/atspi/ep0.c (my_setup): added work-arounds for compiler bugs
- tools/atspi-id/Makefile, tools/atspi-id/atspi-id.c: command-line utility
to query hardware and firmware version
Files: fw/atspi/ep0.c (4 diffs)
fw/include/atspi/ep0.h (2 diffs)
tools/atspi-id/Makefile (1 diff)
tools/atspi-id/atspi-id.c (1 diff)

Change Details

fw/atspi/ep0.c
2929#define error(...)
3030
3131
32/*
33 * SDCC 2.8.0 had a number of code generation bugs that appeared in the big
34 * switch statement of my_setup. SDCC_FORCE_UPDATE forced the value of the
35 * "size" variable to be written to memory. This work-around doesn't seem
36 * to be necessary with 2.9.0, but we keep it around, just in case.
37 *
38 * Unfortunately, the setup->bRequest garbling bug is still with us. Without
39 * the evaluation forced with SDCC_FORCE_EVAL, sdcc gets confused about the
40 * value of setup->bRequest and then rejects all SETUP requests.
41 */
42
43#define SDCC_FORCE_EVAL(type, value) \
44    do { \
45    static volatile type foo; \
46    foo = value; \
47    } while (0)
48
49#define SDCC_FORCE_UPDATE(type, var) \
50    do { \
51    volatile type foo; \
52    foo = var; \
53    var = foo; \
54    } while (0)
55
56
3257static const uint8_t id[] = { EP0ATSPI_MAJOR, EP0ATSPI_MINOR, HW_TYPE };
3358static __xdata uint8_t buf[MAX_PSDU+3]; /* command, PHDR, and LQ */
3459static uint8_t size;
...... 
7398}
7499
75100
101#define BUILD_OFFSET 7 /* '#' plus "65535" plus ' ' */
102
103
76104static __bit my_setup(struct setup_request *setup) __reentrant
77105{
106    unsigned tmp;
78107    uint8_t i;
79108
80109    switch (setup->bmRequestType | setup->bRequest << 8) {
...... 
84113            return 0;
85114        usb_send(&ep0, id, setup->wLength, NULL, NULL);
86115        return 1;
87    case ATSPI_FROM_DEV(ATSPI_BUILD_NUMBER):
88        debug("ATSPI_BUILD_NUMBER\n");
89        if (setup->wLength > 2)
90            return 0;
91        usb_send(&ep0, (void *) &build_number, setup->wLength,
92            NULL, NULL);
93        return 1;
94    case ATSPI_FROM_DEV(ATSPI_BUILD_DATE):
95        debug("ATSPI_BUILD_DATE\n");
96        for (size = 0; build_date[size]; size++);
97        if (size > EP1_SIZE)
98            return 0;
116    case ATSPI_FROM_DEV(ATSPI_BUILD):
117        debug("ATSPI_BUILD\n");
118        tmp = build_number;
119        for (i = BUILD_OFFSET-2; tmp; i--) {
120            buf[i] = (tmp % 10)+'0';
121            tmp /= 10;
122        }
123        buf[i] = '#';
124        buf[BUILD_OFFSET-1] = ' ';
125        for (size = 0; build_date[size]; size++)
126            buf[BUILD_OFFSET+size] = build_date[size];
127        size += BUILD_OFFSET-i+1;
128        SDCC_FORCE_EVAL(uint8_t, setup->bRequest);
99129        if (size > setup->wLength)
100130            return 0;
101        usb_send(&ep0, build_date, size, NULL, NULL);
131        usb_send(&ep0, buf+i, size, NULL, NULL);
102132        return 1;
133
103134    case ATSPI_TO_DEV(ATSPI_RESET):
104135        debug("ATSPI_RESET\n");
105136        RSTSRC = SWRSF;
...... 
180211        nSS = 1;
181212        usb_send(&ep0, buf, size, NULL, NULL);
182213        return 1;
214#endif
183215
184216    default:
185217        error("Unrecognized SETUP: 0x%02x 0x%02x ...\n",
fw/include/atspi/ep0.h
1818 * Direction bRequest wValue wIndex wLength
1919 *
2020 * ->host ATSPI_ID - - 3
21 * ->host ATSPI_BUILD - - #bytes
2122 * host-> ATSPI_RESET - - 0
22 * ->host ATSPI_BUILD_NUMBER - - 2
23 * ->host ATSPI_BUILD_DATE - - #bytes
2423 *
2524 * host-> ATSPI_RF_RESET - -
2625 *
...... 
6160
6261enum atspi_requests {
6362    ATSPI_ID = 0x00,
63    ATSPI_BUILD,
6464    ATSPI_RESET,
65    ATSPI_BUILD_NUMBER,
66    ATSPI_BUILD_DATE,
6765    ATSPI_RF_RESET = 0x10,
6866    ATSPI_REG_WRITE = 0x20,
6967    ATSPI_REG_READ,
tools/atspi-id/Makefile
1#
2# atspi/Makefile - Build the ATSPI identification utility
3#
4# Written 2010 by Werner Almesberger
5# Copyright 2010 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
14F32XBASE = ../../../f32xbase
15
16MAIN = atspi-id
17OBJS = $(F32XBASE)/lib/usb.o
18
19include $(F32XBASE)/lib/Makefile.common
20
21CFLAGS += -I$(F32XBASE)/include -I../../fw/include
tools/atspi-id/atspi-id.c
1/*
2 * atspi-id/atspi-id.c - Identify a ben-wpan AF86RF230 board
3 *
4 * Written 2010 by Werner Almesberger
5 * Copyright 2010 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
17#include "f32xbase/usb.h"
18#include "atspi/ep0.h"
19#include "atspi/usb-ids.h"
20
21
22#define FROM_DEV ATSPI_FROM_DEV(0)
23
24#define BUF_SIZE 256
25
26
27
28static int get_id(usb_dev_handle *dev, void *data, int size)
29{
30    int res;
31
32    res = usb_control_msg(dev, FROM_DEV, ATSPI_ID, 0, 0, data, size, 1000);
33    if (res < 0)
34        fprintf(stderr, "ATSPI_ID: %s\n", usb_strerror());
35    return res;
36}
37
38
39static int atspi_get_protocol(usb_dev_handle *dev,
40    uint8_t *major, uint8_t *minor, uint8_t *target)
41{
42    uint8_t ids[3];
43
44    if (get_id(dev, ids, 3) < 0)
45        return -1;
46    if (major)
47        *major = ids[0];
48    if (minor)
49        *minor = ids[1];
50    if (target)
51        *target = ids[2];
52
53    return 0;
54}
55
56
57static int atspi_get_build(usb_dev_handle *dev, char *buf, size_t size)
58{
59    int res;
60
61    res = usb_control_msg(dev, FROM_DEV, ATSPI_BUILD, 0, 0, buf, size,
62        1000);
63    if (res < 0)
64        fprintf(stderr, "ATSPI_BUILD: %s\n", usb_strerror());
65    return res;
66}
67
68
69static void show_info(usb_dev_handle *dev)
70{
71    const struct usb_device *device = usb_device(dev);
72    uint8_t major, minor, target;
73    char buf[BUF_SIZE+1]; /* +1 for terminating \0 */
74    int len;
75
76    printf("%04x:%04x ",
77        device->descriptor.idVendor, device->descriptor.idProduct);
78
79    if (atspi_get_protocol(dev, &major, &minor, &target) < 0)
80        exit(1);
81    printf("protocol %u.%u hw %u\n", major, minor, target);
82
83    len = atspi_get_build(dev, buf, sizeof(buf)-1);
84    if (len < 0)
85        exit(1);
86    buf[len] = 0;
87    printf("%10s%s\n", "", buf);
88}
89
90
91static void usage(const char *name)
92{
93    fprintf(stderr, "%s\n", name);
94    exit(1);
95}
96
97
98int main(int argc, const char **argv)
99{
100    usb_dev_handle *dev;
101
102    if (argc != 1)
103        usage(*argv);
104    dev = open_usb(USB_VENDOR, USB_PRODUCT);
105    if (!dev) {
106        fprintf(stderr, ":-(\n");
107        return 1;
108    }
109
110    show_info(dev);
111
112    return 0;
113}

Archive Download the corresponding diff file



interactive