IEEE 802.15.4 subsystem
Sign in or create your account | Project List | Help
IEEE 802.15.4 subsystem Git Source Tree
Root/
Source at commit f8fbb02bb026e41f3655b9d9e204db9a66d53c9d created 13 years 1 month ago. By Werner Almesberger, atusb/fw2: further abstract board functions | |
---|---|
1 | #include <stdint.h> |
2 | |
3 | #include <avr/io.h> |
4 | |
5 | #define F_CPU 8000000UL |
6 | #include <util/delay.h> |
7 | |
8 | #include "at86rf230.h" |
9 | #include "board.h" |
10 | #include "spi.h" |
11 | |
12 | |
13 | static void set_clkm(void) |
14 | { |
15 | /* switch CLKM to 8 MHz */ |
16 | |
17 | /* |
18 | * @@@ Note: Atmel advise against changing the external clock in |
19 | * mid-flight. We should therefore switch to the RC clock first, then |
20 | * crank up the external clock, and finally switch back to the external |
21 | * clock. The clock switching procedure is described in the ATmega32U2 |
22 | * data sheet in secton 8.2.2. |
23 | */ |
24 | |
25 | spi_begin(); |
26 | spi_send(AT86RF230_REG_WRITE | REG_TRX_CTRL_0); |
27 | spi_send(CLKM_CTRL_8MHz); |
28 | spi_end(); |
29 | } |
30 | |
31 | |
32 | void reset_rf(void) |
33 | { |
34 | /* AT86RF231 data sheet, 12.4.13, reset pulse width: 625 ns (min) */ |
35 | |
36 | CLR(nRST_RF); |
37 | _delay_us(1); |
38 | SET(nRST_RF); |
39 | |
40 | /* 12.4.14: SPI access latency after reset: 625 ns (min) */ |
41 | |
42 | _delay_us(1); |
43 | |
44 | /* we must restore TRX_CTRL_0 after each reset (9.6.4) */ |
45 | |
46 | set_clkm(); |
47 | } |
48 | |
49 | |
50 | uint8_t read_irq(void) |
51 | { |
52 | return PIN(IRQ_RF); |
53 | } |
54 | |
55 | |
56 | void led(int on) |
57 | { |
58 | if (on) |
59 | SET(LED); |
60 | else |
61 | CLR(LED); |
62 | } |
63 | |
64 | |
65 | void board_init(void) |
66 | { |
67 | /* We start with a 1 MHz/8 clock. Disable the prescaler. */ |
68 | |
69 | CLKPR = 1 << CLKPCE; |
70 | CLKPR = 0; |
71 | |
72 | /* set up all the outputs; default port value is 0 */ |
73 | |
74 | OUT(LED); |
75 | OUT(nRST_RF); /* resets the transceiver */ |
76 | OUT(SLP_TR); |
77 | } |
78 |