IEEE 802.15.4 subsystem
Sign in or create your account | Project List | Help
IEEE 802.15.4 subsystem Commit Details
Date: | 2011-05-10 22:23:08 (8 years 7 months ago) |
---|---|
Author: | Werner Almesberger |
Commit: | 85f60de9d52195afb3a0232a03e850d96584bb9a |
Message: | atusb/fw: use the unique serial number of the ATmega8/16/32U2 for
iSerialNumber - usb/usb.h (USB_LANGID_ENGLISH_US): added USB LANGID for US-English - board.h (board_sernum), board.c (board_sernum, hex, get_sernum, board_init): provide the board's serial number in "board_sernum" (UTF-encoded) - sernum.h (sernum_get_descr), sernum.c (sernum_get_descr): return string descriptors for the serial number - descr.c (device_descriptor), usb/dfu.c (device_descriptor): set iSerialNumber if serial number is available - atusb.c (main), usb/dfu.c (my_descr): call sernum_get_descr for unknown descriptors - Makefile (OBJS, BOOT_OBJS): added sernum.o |
Files: |
atusb/fw/Makefile (1 diff) atusb/fw/atusb.c (2 diffs) atusb/fw/board.c (3 diffs) atusb/fw/board.h (1 diff) atusb/fw/descr.c (1 diff) atusb/fw/sernum.c (1 diff) atusb/fw/sernum.h (1 diff) atusb/fw/usb/dfu.c (3 diffs) atusb/fw/usb/usb.h (2 diffs) |
Change Details
atusb/fw/Makefile | ||
---|---|---|
29 | 29 | SIZE = $(AVR_PREFIX)size |
30 | 30 | |
31 | 31 | USB_OBJS = usb.o atu2.o |
32 | OBJS = atusb.o board.o spi.o descr.o ep0.o $(USB_OBJS) | |
33 | BOOT_OBJS = boot.o board.o spi.o flash.o dfu.o $(USB_OBJS) | |
32 | OBJS = atusb.o board.o sernum.o spi.o descr.o ep0.o $(USB_OBJS) | |
33 | BOOT_OBJS = boot.o board.o sernum.o spi.o flash.o dfu.o $(USB_OBJS) | |
34 | 34 | |
35 | 35 | vpath %.c usb/ |
36 | 36 |
atusb/fw/atusb.c | ||
---|---|---|
18 | 18 | #include "usb.h" |
19 | 19 | |
20 | 20 | #include "board.h" |
21 | #include "sernum.h" | |
21 | 22 | #include "spi.h" |
22 | 23 | #include "atusb/ep0.h" |
23 | 24 | |
... | ... | |
28 | 29 | spi_init(); |
29 | 30 | reset_rf(); |
30 | 31 | |
32 | user_get_descriptor = sernum_get_descr; | |
33 | ||
31 | 34 | /* now we should be at 8 MHz */ |
32 | 35 | |
33 | 36 | usb_init(); |
atusb/fw/board.c | ||
---|---|---|
15 | 15 | |
16 | 16 | #include <avr/io.h> |
17 | 17 | #include <avr/interrupt.h> |
18 | #include <avr/boot.h> | |
18 | 19 | |
19 | 20 | #define F_CPU 8000000UL |
20 | 21 | #include <util/delay.h> |
21 | 22 | |
23 | #include "usb.h" | |
22 | 24 | #include "at86rf230.h" |
23 | 25 | #include "board.h" |
24 | 26 | #include "spi.h" |
25 | 27 | |
26 | 28 | |
29 | uint8_t board_sernum[42] = { 42, USB_DT_STRING }; | |
30 | ||
31 | ||
27 | 32 | static void set_clkm(void) |
28 | 33 | { |
29 | 34 | /* switch CLKM to 8 MHz */ |
... | ... | |
94 | 99 | } |
95 | 100 | |
96 | 101 | |
102 | static char hex(uint8_t nibble) | |
103 | { | |
104 | return nibble < 10 ? '0'+nibble : 'a'+nibble-10; | |
105 | } | |
106 | ||
107 | ||
108 | static void get_sernum(void) | |
109 | { | |
110 | uint8_t sig; | |
111 | int i; | |
112 | ||
113 | for (i = 0; i != 10; i++) { | |
114 | sig = boot_signature_byte_get(i+0xe); | |
115 | board_sernum[(i << 2)+2] = hex(sig >> 4); | |
116 | board_sernum[(i << 2)+4] = hex(sig & 0xf); | |
117 | } | |
118 | } | |
119 | ||
120 | ||
97 | 121 | void board_init(void) |
98 | 122 | { |
99 | 123 | /* Disable the watchdog timer */ |
... | ... | |
111 | 135 | /* set up all the outputs; default port value is 0 */ |
112 | 136 | |
113 | 137 | OUT(LED); |
114 | OUT(nRST_RF); /* resets the transceiver */ | |
138 | OUT(nRST_RF); /* this also resets the transceiver */ | |
115 | 139 | OUT(SLP_TR); |
140 | ||
141 | get_sernum(); | |
116 | 142 | } |
atusb/fw/board.h | ||
---|---|---|
62 | 62 | #define DFU_USB_PRODUCT USB_PRODUCT |
63 | 63 | |
64 | 64 | |
65 | #define HAS_BOARD_SERNUM | |
66 | ||
67 | extern uint8_t board_sernum[42]; | |
68 | ||
69 | ||
65 | 70 | void reset_rf(void); |
66 | 71 | void reset_cpu(void); |
67 | 72 | uint8_t read_irq(void); |
atusb/fw/descr.c | ||
---|---|---|
34 | 34 | LE(0x0001), /* bcdDevice */ |
35 | 35 | 0, /* iManufacturer */ |
36 | 36 | 0, /* iProduct */ |
37 | #ifdef HAS_BOARD_SERNUM | |
38 | 1, /* iSerialNumber */ | |
39 | #else | |
37 | 40 | 0, /* iSerialNumber */ |
41 | #endif | |
38 | 42 | 1 /* bNumConfigurations */ |
39 | 43 | }; |
40 | 44 |
atusb/fw/sernum.c | ||
---|---|---|
1 | /* | |
2 | * fw/sernum.c - ATUSB serial number | |
3 | * | |
4 | * Written 2008-2011 by Werner Almesberger | |
5 | * Copyright 2008-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 | ||
16 | #include "usb.h" | |
17 | ||
18 | #include "board.h" | |
19 | #include "sernum.h" | |
20 | ||
21 | ||
22 | static const uint8_t string_descriptor_0[] = { | |
23 | 4, /* blength */ | |
24 | USB_DT_STRING, /* bDescriptorType */ | |
25 | LE(USB_LANGID_ENGLISH_US) /* wLANGID[0] */ | |
26 | }; | |
27 | ||
28 | ||
29 | int sernum_get_descr(uint8_t type, uint8_t index, const uint8_t **reply, | |
30 | uint8_t *size) | |
31 | { | |
32 | if (type != USB_DT_STRING) | |
33 | return 0; | |
34 | switch (index) { | |
35 | case 0: | |
36 | *reply = string_descriptor_0; | |
37 | *size = sizeof(string_descriptor_0); | |
38 | return 1; | |
39 | case 1: | |
40 | *reply = board_sernum; | |
41 | *size = sizeof(board_sernum); | |
42 | return 1; | |
43 | default: | |
44 | return 0; | |
45 | } | |
46 | } |
atusb/fw/sernum.h | ||
---|---|---|
1 | /* | |
2 | * fw/sernum.h - ATUSB serial number | |
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 | #ifndef SERNUM_H | |
14 | #define SERNUM_H | |
15 | ||
16 | #include <stdint.h> | |
17 | ||
18 | #include "board.h" | |
19 | ||
20 | ||
21 | #ifdef HAS_BOARD_SERNUM | |
22 | ||
23 | int sernum_get_descr(uint8_t type, uint8_t index, const uint8_t **reply, | |
24 | uint8_t *size); | |
25 | ||
26 | #else /* HAS_BOARD_SERNUM */ | |
27 | ||
28 | static inline int sernum_get_descr(uint8_t type, uint8_t index, | |
29 | const uint8_t **reply, uint8_t *size) | |
30 | { | |
31 | return 0; | |
32 | } | |
33 | ||
34 | #endif /* !HAS_BOARD_SERNUM */ | |
35 | ||
36 | #endif /* !SERNUM_H */ |
atusb/fw/usb/dfu.c | ||
---|---|---|
31 | 31 | #include "dfu.h" |
32 | 32 | |
33 | 33 | #include "../board.h" |
34 | #include "../sernum.h" | |
34 | 35 | |
35 | 36 | |
36 | 37 | #ifndef NULL |
... | ... | |
54 | 55 | LE(0x0001), /* bcdDevice */ |
55 | 56 | 0, /* iManufacturer */ |
56 | 57 | 0, /* iProduct */ |
58 | #ifdef HAS_BOARD_SERNUM | |
59 | 1, /* iSerialNumber */ | |
60 | #else | |
57 | 61 | 0, /* iSerialNumber */ |
62 | #endif | |
58 | 63 | 1 /* bNumConfigurations */ |
59 | 64 | }; |
60 | 65 | |
... | ... | |
262 | 267 | uint8_t *size) |
263 | 268 | { |
264 | 269 | if (type != DFU_DT_FUNCTIONAL) |
265 | return 0; | |
270 | return sernum_get_descr(type, index, reply, size); | |
266 | 271 | *reply = functional_descriptor; |
267 | 272 | *size = sizeof(functional_descriptor); |
268 | 273 | return 1; |
atusb/fw/usb/usb.h | ||
---|---|---|
1 | 1 | /* |
2 | 2 | * fw/usb//usb.h - USB hardware setup and standard device requests |
3 | 3 | * |
4 | * Written 2008, 2009 by Werner Almesberger | |
5 | * Copyright 2008, 2009 Werner Almesberger | |
4 | * Written 2008, 2009, 2011 by Werner Almesberger | |
5 | * Copyright 2008, 2009, 2011 Werner Almesberger | |
6 | 6 | * |
7 | 7 | * This program is free software; you can redistribute it and/or modify |
8 | 8 | * it under the terms of the GNU General Public License as published by |
... | ... | |
74 | 74 | #define SET_INTERFACE 0x0b |
75 | 75 | #define SYNCH_FRAME 0x0c |
76 | 76 | |
77 | /* | |
78 | * USB Language ID codes | |
79 | * | |
80 | * http://www.usb.org/developers/docs/USB_LANGIDs.pdf | |
81 | */ | |
82 | ||
83 | #define USB_LANGID_ENGLISH_US 0x409 | |
84 | ||
77 | 85 | |
78 | 86 | /* |
79 | 87 | * Odd. sdcc seems to think "x" assumes the size of the destination, i.e., |