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 738618a9453909fbbff324e31c113ddcb722fb88 created 13 years 7 months ago. By Werner Almesberger, Update IRQ_RF after reworking both boards. IRQ_RF was erroneously connected to P0_2 but it should go to P0_0. | |
---|---|
1 | /* |
2 | * atspi/atspi.c - ATSPI initialization and main loop |
3 | * |
4 | * Written 2008-2010 by Werner Almesberger |
5 | * Copyright 2008-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 "regs.h" |
15 | #include "io.h" |
16 | #include "usb.h" |
17 | #include "atspi/ep0.h" |
18 | #include "version.h" |
19 | |
20 | |
21 | void reset_rf(void) |
22 | { |
23 | int i; |
24 | |
25 | nRST_RF = 0; |
26 | /* |
27 | * 11.4.12: min 625 ns. |
28 | * The pulse we generate is slightly longer than 4 us. |
29 | */ |
30 | for (i = 0; i != 10; i++); |
31 | nRST_RF = 1; |
32 | } |
33 | |
34 | |
35 | static void init_io(void) |
36 | { |
37 | /* |
38 | * Signal Mode Value |
39 | * |
40 | * MOSI push-pull 0 |
41 | * MISO open drain 1 (input) |
42 | * SCLK push-pull 0 |
43 | * nSS push-pull 1 |
44 | * nRST_RF push-pull 1 |
45 | * IRQ_RF open drain 1 (input) |
46 | * SLP_TR push-pull 0 |
47 | * |
48 | * LED push-pull 0 (set up by boot loader) |
49 | * |
50 | * all unused open drain 0 |
51 | */ |
52 | |
53 | MOSI = 0; |
54 | MOSI_MODE |= 1 << MOSI_BIT; |
55 | |
56 | SCLK = 0; |
57 | SCLK_MODE |= 1 << SCLK_BIT; |
58 | |
59 | nSS_MODE |= 1 << nSS_BIT; |
60 | |
61 | nRST_RF_MODE |= 1 << nRST_RF_BIT; |
62 | |
63 | SLP_TR = 0; |
64 | SLP_TR_MODE |= 1 << SLP_TR_BIT; |
65 | |
66 | P0 = 1; /* IRQ_RF = 1; LED = 0; the rest is unused */ |
67 | P3 = 0; |
68 | |
69 | #if 0 |
70 | /* |
71 | * We can *almost* disable the pull-ups. The only obstacle is that |
72 | * MISO is not driven when not in use. So we either need an external |
73 | * pull-up/down or keep all the pull-ups on. |
74 | */ |
75 | |
76 | /* |
77 | * Disable pull-ups |
78 | */ |
79 | GPIOCN |= WEAKPUD; |
80 | #endif |
81 | |
82 | /* |
83 | * The manual says the reset is optional, but reality disagrees with |
84 | * this optimistic assessment quite violently. |
85 | */ |
86 | |
87 | reset_rf(); |
88 | } |
89 | |
90 | |
91 | void main(void) |
92 | { |
93 | init_io(); |
94 | |
95 | usb_init(); |
96 | ep0_init(); |
97 | |
98 | while (1) { |
99 | usb_poll(); |
100 | } |
101 | } |
102 |