IEEE 802.15.4 subsystem
Sign in or create your account | Project List | Help
IEEE 802.15.4 subsystem Commit Details
Date: | 2016-03-30 22:08:00 (7 years 8 months ago) |
---|---|
Author: | Stefan Schmidt |
Commit: | 968721c335ce5ce562484f060dc6c70d8e96fc57 |
Message: | atusb: fw: re-factor SPI, USB and board_app code for board specifics Move board specific code form spi, usb and board_app into the new board specific files to avoid to many ifdefs. |
Files: |
atusb/fw/board_app.c (1 diff) atusb/fw/board_atusb.c (2 diffs) atusb/fw/board_atusb.h (1 diff) atusb/fw/board_rzusb.c (2 diffs) atusb/fw/board_rzusb.h (1 diff) atusb/fw/spi.c (2 diffs) atusb/fw/usb/atu2.c (2 diffs) atusb/fw/usb/usb.h (1 diff) |
Change Details
atusb/fw/board_app.c | ||
---|---|---|
171 | 171 | usb_send(&eps[1], &irq_serial, 1, done, NULL); |
172 | 172 | } |
173 | 173 | } |
174 | ||
175 | #ifdef ATUSB | |
176 | void board_app_init(void) | |
177 | { | |
178 | /* enable INT0, trigger on rising edge */ | |
179 | EICRA = 1 << ISC01 | 1 << ISC00; | |
180 | EIMSK = 1 << 0; | |
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/board_atusb.c | ||
---|---|---|
25 | 25 | #include "at86rf230.h" |
26 | 26 | #include "board.h" |
27 | 27 | #include "spi.h" |
28 | #include "usb/usb.h" | |
29 | ||
30 | static bool spi_initialized = 0; | |
28 | 31 | |
29 | 32 | void set_clkm(void) |
30 | 33 | { |
... | ... | |
58 | 61 | |
59 | 62 | get_sernum(); |
60 | 63 | } |
64 | ||
65 | void spi_begin(void) | |
66 | { | |
67 | if (!spi_initialized) | |
68 | spi_init(); | |
69 | CLR(nSS); | |
70 | } | |
71 | ||
72 | void spi_off(void) | |
73 | { | |
74 | spi_initialized = 0; | |
75 | UCSR1B = 0; | |
76 | } | |
77 | ||
78 | void spi_init(void) | |
79 | { | |
80 | SET(nSS); | |
81 | OUT(SCLK); | |
82 | OUT(MOSI); | |
83 | OUT(nSS); | |
84 | IN(MISO); | |
85 | ||
86 | UBRR1 = 0; /* set bit rate to zero to begin */ | |
87 | UCSR1C = 1 << UMSEL11 | 1 << UMSEL10; | |
88 | /* set MSPI, MSB first, SPI data mode 0 */ | |
89 | UCSR1B = 1 << RXEN1 | 1 << TXEN1; | |
90 | /* enable receiver and transmitter */ | |
91 | UBRR1 = 0; /* reconfirm the bit rate */ | |
92 | ||
93 | spi_initialized = 1; | |
94 | } | |
95 | ||
96 | void usb_init(void) | |
97 | { | |
98 | USBCON |= 1 << FRZCLK; /* freeze the clock */ | |
99 | ||
100 | /* enable the PLL and wait for it to lock */ | |
101 | PLLCSR &= ~(1 << PLLP2 | 1 << PLLP1 | 1 << PLLP0); | |
102 | PLLCSR |= 1 << PLLE; | |
103 | while (!(PLLCSR & (1 << PLOCK))); | |
104 | ||
105 | USBCON &= ~(1 << USBE); /* reset the controller */ | |
106 | USBCON |= 1 << USBE; | |
107 | ||
108 | USBCON &= ~(1 << FRZCLK); /* thaw the clock */ | |
109 | ||
110 | UDCON &= ~(1 << DETACH); /* attach the pull-up */ | |
111 | UDIEN = 1 << EORSTE; /* enable device interrupts */ | |
112 | // UDCON |= 1 << RSTCPU; /* reset CPU on bus reset */ | |
113 | ||
114 | ep_init(); | |
115 | } | |
116 | ||
117 | void board_app_init(void) | |
118 | { | |
119 | /* enable INT0, trigger on rising edge */ | |
120 | EICRA = 1 << ISC01 | 1 << ISC00; | |
121 | EIMSK = 1 << 0; | |
122 | } |
atusb/fw/board_atusb.h | ||
---|---|---|
41 | 41 | void set_clkm(void); |
42 | 42 | void board_init(void); |
43 | 43 | |
44 | void spi_begin(void); | |
45 | void spi_off(void); | |
46 | void spi_init(void); | |
47 | ||
44 | 48 | #endif /* !BOARD_H */ |
atusb/fw/board_rzusb.c | ||
---|---|---|
25 | 25 | #include "at86rf230.h" |
26 | 26 | #include "board.h" |
27 | 27 | #include "spi.h" |
28 | #include "usb/usb.h" | |
29 | ||
30 | static bool spi_initialized = 0; | |
28 | 31 | |
29 | 32 | void set_clkm(void) |
30 | 33 | { |
... | ... | |
64 | 67 | |
65 | 68 | get_sernum(); |
66 | 69 | } |
70 | ||
71 | void spi_begin(void) | |
72 | { | |
73 | if (!spi_initialized) | |
74 | spi_init(); | |
75 | CLR(nSS); | |
76 | } | |
77 | ||
78 | void spi_off(void) | |
79 | { | |
80 | spi_initialized = 0; | |
81 | SPCR &= ~(1 << SPE); | |
82 | } | |
83 | ||
84 | void spi_init(void) | |
85 | { | |
86 | SET(nSS); | |
87 | OUT(SCLK); | |
88 | OUT(MOSI); | |
89 | OUT(nSS); | |
90 | IN(MISO); | |
91 | ||
92 | SPCR = (1 << SPE) | (1 << MSTR); | |
93 | SPSR = (1 << SPI2X); | |
94 | ||
95 | spi_initialized = 1; | |
96 | } | |
97 | ||
98 | void usb_init(void) | |
99 | { | |
100 | USBCON |= 1 << FRZCLK; /* freeze the clock */ | |
101 | ||
102 | /* enable the PLL and wait for it to lock */ | |
103 | /* TODO sheet page 50 For Atmel AT90USB128x only. Do not use with Atmel AT90USB64x. */ | |
104 | /* FOR 8 XTAL Mhz only!!! */ | |
105 | PLLCSR = ((1 << PLLP1) | (1 << PLLP0)); | |
106 | PLLCSR |= 1 << PLLE; | |
107 | while (!(PLLCSR & (1 << PLOCK))); | |
108 | ||
109 | UHWCON |= (1 << UVREGE); | |
110 | ||
111 | USBCON &= ~((1 << USBE) | (1 << OTGPADE)); /* reset the controller */ | |
112 | USBCON |= ((1 << USBE) | (1 << OTGPADE)); | |
113 | ||
114 | USBCON &= ~(1 << FRZCLK); /* thaw the clock */ | |
115 | ||
116 | UDCON &= ~(1 << DETACH); /* attach the pull-up */ | |
117 | UDIEN = 1 << EORSTE; /* enable device interrupts */ | |
118 | // UDCON |= 1 << RSTCPU; /* reset CPU on bus reset */ | |
119 | ||
120 | ep_init(); | |
121 | } | |
122 | ||
123 | void board_app_init(void) | |
124 | { | |
125 | /* enable timer input capture 1, trigger on rising edge */ | |
126 | TCCR1B = (1 << ICES1); | |
127 | TIFR1 = (1 << ICF1); | |
128 | TIMSK1 = (1 << ICIE1); | |
129 | } |
atusb/fw/board_rzusb.h | ||
---|---|---|
41 | 41 | void set_clkm(void); |
42 | 42 | void board_init(void); |
43 | 43 | |
44 | void spi_begin(void); | |
45 | void spi_off(void); | |
46 | void spi_init(void); | |
47 | ||
44 | 48 | #endif /* !BOARD_H */ |
atusb/fw/spi.c | ||
---|---|---|
20 | 20 | #include "spi.h" |
21 | 21 | |
22 | 22 | |
23 | static bool spi_initialized = 0; | |
24 | ||
25 | ||
26 | void spi_begin(void) | |
27 | { | |
28 | if (!spi_initialized) | |
29 | spi_init(); | |
30 | CLR(nSS); | |
31 | } | |
32 | ||
33 | ||
34 | 23 | uint8_t spi_io(uint8_t v) |
35 | 24 | { |
36 | 25 | // while (!(UCSR1A & 1 << UDRE1)); |
... | ... | |
60 | 49 | SPI_WAIT_DONE(); |
61 | 50 | *buf++ = SPI_DATA; |
62 | 51 | } |
63 | ||
64 | ||
65 | void spi_off(void) | |
66 | { | |
67 | spi_initialized = 0; | |
68 | #ifdef ATUSB | |
69 | UCSR1B = 0; | |
70 | #endif | |
71 | #ifdef RZUSB | |
72 | SPCR &= ~(1 << SPE); | |
73 | #endif | |
74 | } | |
75 | ||
76 | ||
77 | void spi_init(void) | |
78 | { | |
79 | SET(nSS); | |
80 | OUT(SCLK); | |
81 | OUT(MOSI); | |
82 | OUT(nSS); | |
83 | IN(MISO); | |
84 | ||
85 | #ifdef ATUSB | |
86 | UBRR1 = 0; /* set bit rate to zero to begin */ | |
87 | UCSR1C = 1 << UMSEL11 | 1 << UMSEL10; | |
88 | /* set MSPI, MSB first, SPI data mode 0 */ | |
89 | UCSR1B = 1 << RXEN1 | 1 << TXEN1; | |
90 | /* enable receiver and transmitter */ | |
91 | UBRR1 = 0; /* reconfirm the bit rate */ | |
92 | #endif | |
93 | #ifdef RZUSB | |
94 | SPCR = (1 << SPE) | (1 << MSTR); | |
95 | SPSR = (1 << SPI2X); | |
96 | #endif | |
97 | ||
98 | spi_initialized = 1; | |
99 | } |
atusb/fw/usb/atu2.c | ||
---|---|---|
180 | 180 | } |
181 | 181 | |
182 | 182 | |
183 | static void ep_init(void) | |
183 | void ep_init(void) | |
184 | 184 | { |
185 | 185 | UENUM = 0; |
186 | 186 | UECONX = (1 << RSTDT) | (1 << EPEN); /* enable */ |
... | ... | |
245 | 245 | UDCON |= 1 << DETACH; /* detach the pull-up */ |
246 | 246 | _delay_ms(1); |
247 | 247 | } |
248 | ||
249 | ||
250 | void usb_init(void) | |
251 | { | |
252 | USBCON |= 1 << FRZCLK; /* freeze the clock */ | |
253 | ||
254 | /* enable the PLL and wait for it to lock */ | |
255 | #ifdef ATUSB | |
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 | |
263 | PLLCSR |= 1 << PLLE; | |
264 | while (!(PLLCSR & (1 << PLOCK))); | |
265 | ||
266 | #ifdef ATUSB | |
267 | USBCON &= ~(1 << USBE); /* reset the controller */ | |
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 | |
276 | ||
277 | USBCON &= ~(1 << FRZCLK); /* thaw the clock */ | |
278 | ||
279 | UDCON &= ~(1 << DETACH); /* attach the pull-up */ | |
280 | UDIEN = 1 << EORSTE; /* enable device interrupts */ | |
281 | // UDCON |= 1 << RSTCPU; /* reset CPU on bus reset */ | |
282 | ||
283 | ep_init(); | |
284 | } |
atusb/fw/usb/usb.h | ||
---|---|---|
184 | 184 | void usb_reset(void); |
185 | 185 | void usb_init(void); |
186 | 186 | |
187 | void ep_init(void); | |
188 | ||
187 | 189 | #endif /* !USB_H */ |