IEEE 802.15.4 subsystem
Sign in or create your account | Project List | Help
IEEE 802.15.4 subsystem Commit Details
Date: | 2015-05-24 14:37:38 (8 years 6 months ago) |
---|---|
Author: | Alexander Aring |
Commit: | 5129029d3bcffb21aabf38f522f4f1e5426e4919 |
Message: | atusb: fw: add support for rzusbstick This patch adds support for the rzusbstick for the atusb firmware. More detailed information about this usb stick: http://www.atmel.com/tools/rzusbstick.aspx Original I have the rzraven kit: http://www.atmel.com/tools/rzraven.aspx Which comes with a special cable and avr dragon programmer. You need some programmer and wires to the programmers pins. To lookup how to connect the programmer to the rzusbstick pinout, see: http://www.atmel.com/Images/doc8117.pdf page 22 (schematics of the rzusbstick). Difference between atusb and rzusbstick(rzusb) is mainly the at86rf231 vs at86rf230 one. The rzusb contains the at86rf230 which is a little bit hard to deal with it (and has a huge errata inside the datasheet). Nevertheless with small schanges the atusb firmware can run now on the rzusb. The rzusb contains also a bigger mcu, so we can maybe cache more pdus for receive handling. To compile the rzusb firmware call: make NAME=rzusb this will generate the rzusb.bin then call the programmer (in my case avrdude): avrdude -P usb -c dragon_jtag -p usb1287 -U flash:w:rzusb.bin NOTE: currently there is no chance (I suppose) to ensure that the atusb receive the correct firmware, so don't try to flash the atusb with the rzusb firmware! Also the vendor and product id is the same. This currently a RFC, it's a quick hack and I think we should update more the documentation to support the rzusb. Signed-off-by: Alexander Aring <alex.aring@gmail.com> Cc: Stefan Schmidt <stefan@osg.samsung.com> Cc: Werner Almesberger <werner@almesberger.net> |
Files: |
atusb/fw/Makefile (1 diff) atusb/fw/atusb.c (1 diff) atusb/fw/board.c (2 diffs) atusb/fw/board.h (2 diffs) atusb/fw/board_app.c (2 diffs) atusb/fw/mac.c (5 diffs) atusb/fw/spi.c (3 diffs) atusb/fw/usb/atu2.c (1 diff) |
Change Details
atusb/fw/Makefile | ||
---|---|---|
18 | 18 | -Wall -Wextra -Wshadow -Werror -Wno-unused-parameter \ |
19 | 19 | -Wmissing-prototypes -Wmissing-declarations -Wstrict-prototypes |
20 | 20 | |
21 | ifeq ($(NAME),rzusb) | |
22 | CHIP=at90usb1287 | |
23 | CFLAGS += -DRZUSB | |
24 | else | |
21 | 25 | CHIP=atmega32u2 |
26 | CFLAGS += -DATUSB | |
27 | endif | |
22 | 28 | HOST=jlime |
23 | 29 | BOOT_ADDR=0x7000 |
24 | 30 |
atusb/fw/atusb.c | ||
---|---|---|
37 | 37 | |
38 | 38 | usb_init(); |
39 | 39 | ep0_init(); |
40 | #ifdef ATUSB | |
40 | 41 | timer_init(); |
41 | 42 | |
42 | 43 | /* move interrupt vectors to 0 */ |
43 | 44 | MCUCR = 1 << IVCE; |
44 | 45 | MCUCR = 0; |
46 | #endif | |
45 | 47 | |
46 | 48 | sei(); |
47 | 49 |
atusb/fw/board.c | ||
---|---|---|
41 | 41 | * clock. The clock switching procedure is described in the ATmega32U2 |
42 | 42 | * data sheet in secton 8.2.2. |
43 | 43 | */ |
44 | ||
44 | #ifdef ATUSB | |
45 | 45 | spi_begin(); |
46 | 46 | spi_send(AT86RF230_REG_WRITE | REG_TRX_CTRL_0); |
47 | 47 | spi_send(CLKM_CTRL_8MHz); |
48 | 48 | spi_end(); |
49 | #endif | |
50 | #ifdef RZUSB | |
51 | spi_begin(); | |
52 | spi_send(AT86RF230_REG_WRITE | REG_TRX_CTRL_0); | |
53 | spi_send(0x10); | |
54 | spi_end(); | |
55 | ||
56 | /* TX_AUTO_CRC_ON, default disabled */ | |
57 | spi_begin(); | |
58 | spi_send(AT86RF230_REG_WRITE | 0x05); | |
59 | spi_send(0x80); | |
60 | spi_end(); | |
61 | #endif | |
49 | 62 | } |
50 | 63 | |
51 | 64 | |
... | ... | |
131 | 144 | WDTCSR = 1 << WDCE; /* Disable watchdog while still enabling |
132 | 145 | change */ |
133 | 146 | |
134 | /* We start with a 1 MHz/8 clock. Disable the prescaler. */ | |
135 | ||
136 | 147 | CLKPR = 1 << CLKPCE; |
148 | #ifdef ATUSB | |
149 | /* We start with a 1 MHz/8 clock. Disable the prescaler. */ | |
137 | 150 | CLKPR = 0; |
151 | #endif | |
152 | #ifdef RZUSB | |
153 | /* We start with a 16 MHz/8 clock. Put the prescaler to 2. */ | |
154 | CLKPR = 1 << CLKPS0; | |
155 | #endif | |
138 | 156 | |
139 | 157 | get_sernum(); |
140 | 158 | } |
atusb/fw/board.h | ||
---|---|---|
18 | 18 | |
19 | 19 | #include <atusb/atusb.h> |
20 | 20 | |
21 | ||
21 | #ifdef ATUSB | |
22 | 22 | #define LED_PORT B |
23 | 23 | #define LED_BIT 6 |
24 | 24 | #define nRST_RF_PORT C |
... | ... | |
38 | 38 | #define IRQ_RF_PORT D |
39 | 39 | #define IRQ_RF_BIT 0 |
40 | 40 | |
41 | #define SPI_WAIT_DONE() while (!(UCSR1A & 1 << RXC1)) | |
42 | #define SPI_DATA UDR1 | |
43 | ||
44 | #endif | |
45 | #ifdef RZUSB | |
46 | #define LED_PORT D | |
47 | #define LED_BIT 7 | |
48 | #define nRST_RF_PORT B | |
49 | #define nRST_RF_BIT 5 | |
50 | #define SLP_TR_PORT B | |
51 | #define SLP_TR_BIT 4 | |
52 | ||
53 | #define SCLK_PORT B | |
54 | #define SCLK_BIT 1 | |
55 | #define MOSI_PORT B | |
56 | #define MOSI_BIT 2 | |
57 | ||
58 | #define MISO_PORT B | |
59 | #define MISO_BIT 3 | |
60 | #define nSS_PORT B | |
61 | #define nSS_BIT 0 | |
62 | #define IRQ_RF_PORT D | |
63 | #define IRQ_RF_BIT 4 | |
64 | ||
65 | #define SPI_WAIT_DONE() while ((SPSR & (1 << SPIF)) == 0) | |
66 | #define SPI_DATA SPDR | |
67 | ||
68 | #endif | |
41 | 69 | |
42 | 70 | #define SET_2(p, b) PORT##p |= 1 << (b) |
43 | 71 | #define CLR_2(p, b) PORT##p &= ~(1 << (b)) |
atusb/fw/board_app.c | ||
---|---|---|
154 | 154 | |
155 | 155 | uint8_t irq_serial; |
156 | 156 | |
157 | ||
157 | #ifdef ATUSB | |
158 | 158 | ISR(INT0_vect) |
159 | #endif | |
160 | #ifdef RZUSB | |
161 | ISR(TIMER1_CAPT_vect) | |
162 | #endif | |
159 | 163 | { |
160 | 164 | if (mac_irq) { |
161 | 165 | if (mac_irq()) |
... | ... | |
168 | 172 | } |
169 | 173 | } |
170 | 174 | |
171 | ||
175 | #ifdef ATUSB | |
172 | 176 | void board_app_init(void) |
173 | 177 | { |
174 | 178 | /* enable INT0, trigger on rising edge */ |
175 | 179 | EICRA = 1 << ISC01 | 1 << ISC00; |
176 | 180 | EIMSK = 1 << 0; |
177 | 181 | } |
182 | #endif | |
183 | #ifdef RZUSB | |
184 | void board_app_init(void) | |
185 | { | |
186 | /* enable timer input capture 1, trigger on rising edge */ | |
187 | TCCR1B = (1 << ICES1); | |
188 | TIFR1 = (1 << ICF1); | |
189 | TIMSK1 = (1 << ICIE1); | |
190 | } | |
191 | #endif |
atusb/fw/mac.c | ||
---|---|---|
21 | 21 | #include "board.h" |
22 | 22 | #include "mac.h" |
23 | 23 | |
24 | ||
25 | 24 | #define RX_BUFS 3 |
26 | 25 | |
27 | 26 | |
... | ... | |
102 | 101 | usb_next(); |
103 | 102 | } |
104 | 103 | |
104 | static void change_state(uint8_t new) | |
105 | { | |
106 | while ((reg_read(REG_TRX_STATUS) & TRX_STATUS_MASK) == | |
107 | TRX_STATUS_TRANSITION); | |
108 | reg_write(REG_TRX_STATE, new); | |
109 | } | |
105 | 110 | |
106 | 111 | static void rx_done(void *user) |
107 | 112 | { |
108 | 113 | led(0); |
109 | 114 | next_buf(&rx_out); |
110 | 115 | usb_next(); |
116 | #ifdef RZUSB | |
117 | /* slap at86rf230 - reduce fragmentation issue */ | |
118 | change_state(TRX_STATUS_RX_AACK_ON); | |
119 | #endif | |
111 | 120 | } |
112 | 121 | |
113 | 122 | |
... | ... | |
117 | 126 | uint8_t *buf; |
118 | 127 | |
119 | 128 | spi_begin(); |
129 | #ifdef ATUSB | |
120 | 130 | if (!(spi_io(AT86RF230_BUF_READ) & RX_CRC_VALID)) { |
121 | 131 | spi_end(); |
122 | 132 | return; |
123 | 133 | } |
134 | #endif | |
135 | #ifdef RZUSB | |
136 | spi_io(AT86RF230_BUF_READ); | |
137 | #endif | |
138 | ||
124 | 139 | size = spi_recv(); |
125 | 140 | if (!size || (size & 0x80)) { |
126 | 141 | spi_end(); |
... | ... | |
169 | 184 | /* ----- TX/RX ------------------------------------------------------------- */ |
170 | 185 | |
171 | 186 | |
172 | static void change_state(uint8_t new) | |
173 | { | |
174 | while ((reg_read(REG_TRX_STATUS) & TRX_STATUS_MASK) == | |
175 | TRX_STATUS_TRANSITION); | |
176 | reg_write(REG_TRX_STATE, new); | |
177 | } | |
178 | ||
179 | ||
180 | 187 | bool mac_rx(int on) |
181 | 188 | { |
182 | 189 | if (on) { |
... | ... | |
209 | 216 | } |
210 | 217 | while (status != TRX_STATUS_RX_ON && status != TRX_STATUS_RX_AACK_ON); |
211 | 218 | |
219 | #ifdef ATUSB | |
212 | 220 | /* |
213 | 221 | * We use TRX_CMD_FORCE_PLL_ON instead of TRX_CMD_PLL_ON because a new |
214 | 222 | * reception may have begun while we were still working on the previous |
215 | 223 | * one. |
216 | 224 | */ |
217 | 225 | reg_write(REG_TRX_STATE, TRX_CMD_FORCE_PLL_ON); |
226 | #endif | |
227 | #ifdef RZUSB | |
228 | /* | |
229 | * at86rf230 doesn't support force change, nevetherless this works | |
230 | * somehow | |
231 | */ | |
232 | reg_write(REG_TRX_STATE, TRX_CMD_PLL_ON); | |
233 | #endif | |
218 | 234 | |
219 | 235 | handle_irq(); |
220 | 236 |
atusb/fw/spi.c | ||
---|---|---|
34 | 34 | uint8_t spi_io(uint8_t v) |
35 | 35 | { |
36 | 36 | // while (!(UCSR1A & 1 << UDRE1)); |
37 | UDR1 = v; | |
38 | while (!(UCSR1A & 1 << RXC1)); | |
39 | return UDR1; | |
37 | SPI_DATA = v; | |
38 | SPI_WAIT_DONE(); | |
39 | return SPDR; | |
40 | 40 | } |
41 | 41 | |
42 | 42 | |
... | ... | |
51 | 51 | { |
52 | 52 | if (!n) |
53 | 53 | return; |
54 | UDR1 = 0; | |
54 | SPI_DATA = 0; | |
55 | 55 | while (--n) { |
56 | while (!(UCSR1A & 1 << RXC1)); | |
57 | *buf++ = UDR1; | |
58 | UDR1 = 0; | |
56 | SPI_WAIT_DONE(); | |
57 | *buf++ = SPI_DATA; | |
58 | SPI_DATA = 0; | |
59 | 59 | } |
60 | while (!(UCSR1A & 1 << RXC1)); | |
61 | *buf++ = UDR1; | |
60 | SPI_WAIT_DONE(); | |
61 | *buf++ = SPI_DATA; | |
62 | 62 | } |
63 | 63 | |
64 | 64 | |
65 | 65 | void spi_off(void) |
66 | 66 | { |
67 | 67 | spi_initialized = 0; |
68 | UCSR1B = 0; | |
68 | #ifdef ATUSB | |
69 | UCSR1B = 0; | |
70 | #endif | |
71 | #ifdef RZUSB | |
72 | SPCR &= ~(1 << SPE); | |
73 | #endif | |
69 | 74 | } |
70 | 75 | |
71 | 76 | |
... | ... | |
77 | 82 | OUT(nSS); |
78 | 83 | IN(MISO); |
79 | 84 | |
85 | #ifdef ATUSB | |
80 | 86 | UBRR1 = 0; /* set bit rate to zero to begin */ |
81 | 87 | UCSR1C = 1 << UMSEL11 | 1 << UMSEL10; |
82 | 88 | /* set MSPI, MSB first, SPI data mode 0 */ |
83 | 89 | UCSR1B = 1 << RXEN1 | 1 << TXEN1; |
84 | 90 | /* enable receiver and transmitter */ |
85 | 91 | UBRR1 = 0; /* reconfirm the bit rate */ |
92 | #endif | |
93 | #ifdef RZUSB | |
94 | SPCR = (1 << SPE) | (1 << MSTR); | |
95 | SPSR = (1 << SPI2X); | |
96 | #endif | |
86 | 97 | |
87 | 98 | spi_initialized = 1; |
88 | 99 | } |
atusb/fw/usb/atu2.c | ||
---|---|---|
252 | 252 | USBCON |= 1 << FRZCLK; /* freeze the clock */ |
253 | 253 | |
254 | 254 | /* enable the PLL and wait for it to lock */ |
255 | #ifdef ATUSB | |
255 | 256 | PLLCSR &= ~(1 << PLLP2 | 1 << PLLP1 | 1 << PLLP0); |
257 | #endif | |
258 | #ifdef RZUSB | |
259 | /* TODO sheet page 50 For Atmel AT90USB128x only. Do not use with Atmel AT90USB64x. */ | |
260 | /* FOR 8 XTAL Mhz only!!! */ | |
261 | PLLCSR = ((1 << PLLP1) | (1 << PLLP0)); | |
262 | #endif | |
256 | 263 | PLLCSR |= 1 << PLLE; |
257 | 264 | while (!(PLLCSR & (1 << PLOCK))); |
258 | 265 | |
266 | #ifdef ATUSB | |
259 | 267 | USBCON &= ~(1 << USBE); /* reset the controller */ |
260 | 268 | USBCON |= 1 << USBE; |
269 | #endif | |
270 | #ifdef RZUSB | |
271 | UHWCON |= (1 << UVREGE); | |
272 | ||
273 | USBCON &= ~((1 << USBE) | (1 << OTGPADE)); /* reset the controller */ | |
274 | USBCON |= ((1 << USBE) | (1 << OTGPADE)); | |
275 | #endif | |
261 | 276 | |
262 | 277 | USBCON &= ~(1 << FRZCLK); /* thaw the clock */ |
263 | 278 |