main.lst
来自「非常全的nrf2401设计资料」· LST 代码 · 共 319 行
LST
319 行
C51 COMPILER V7.50 MAIN 04/09/2009 10:12:49 PAGE 1
C51 COMPILER V7.50, COMPILATION OF MODULE MAIN
OBJECT MODULE PLACED IN .\build\main.obj
COMPILER INVOKED BY: C:\Keil\C51\BIN\C51.EXE main.c LARGE OMF2 OPTIMIZE(9,SPEED) BROWSE INCDIR(..\common;..\..\..\..\com
-p\protocol\wdp\common\;..\..\..\..\comp\protocol\wdp\host\;..\..\..\..\arch\hal\include;..\..\..\..\arch\hal\nrf24lu1;..
-\..\..\..\arch\nrf24lu1;..\common;..\..\..\..\comp\protocol\fap) DEBUG PRINT(.\lst\main.lst) OBJECT(.\build\main.obj)
line level source
1 /* Copyright (c) 2007 Nordic Semiconductor. All Rights Reserved.
2 *
3 * The information contained herein is confidential property of
4 * Nordic Semiconductor. The use, copying, transfer or disclosure
5 * of such information is prohibited except by express written
6 * agreement with Nordic Semiconductor.
7 */
8
9 /** @file
10 * Wireless Desktop USB dongle application for nRF24LU1.
11 *
12 * @author Lasse Olsen
13 *
14 */
15
16 #include <Nordic\reg24lu1.h>
17 #include <stdint.h>
18 #include <stdbool.h>
19 #include <string.h>
20
21 #include "hal_nrf.h"
22 #include "hal_flash.h"
23 #include "timer.h"
24 #include "cklf.h"
25 #include "cpu.h"
26 #include "usb_api.h"
27 #include "lu1_bfb.h"
28 #include "wdp_host.h"
29 #include "app_param.h"
30
31 extern volatile uint16_t timer_cnt;
32
33 typedef enum
34 {
35 APP_PAIRING,
36 APP_NORMAL,
37 APP_SUSP_WE,
38 APP_SUSP_WD
39 } app_states_t;
40
41 //State function prototypes
42 app_states_t app_pairing(void);
43 app_states_t app_normal(void);
44 app_states_t app_susp_we(void);
45 app_states_t app_susp_wd(void);
46
47 static uint8_t radio_data[WDP_MAX_PL_LENGTH]; // General data buffer
48
49 void main(void)
50 {
51 1 app_states_t app_state = APP_PAIRING;
52 1
53 1 CLKCTL = 0; // Reset clock control register
C51 COMPILER V7.50 MAIN 04/09/2009 10:12:49 PAGE 2
54 1
55 1 // Set up GPIO
56 1 P0DIR = 0x38; // Output: P0.0 - P0.2, Input: P0.3 - P0.5
57 1 P0ALT = 0; // All general I/O
58 1 P0 = 0;
59 1
60 1 // Radio + SPI setup
61 1 CE_LOW(); // Radio chip enable low
62 1 RFCTL = 0x10; // Internal MCU to radio SPI enable
63 1 RFCKEN = 1; // Radio clk enable
64 1 RF = 1; // Radio IRQ enable
65 1
66 1 t2_init(FAP_RX_PERIOD); // Setup timer 2 used by the WDP and FAP module
67 1
68 1 usb_init(); // Initialize USB
69 1
70 1 wdp_host_init(); // Initialize the Wireless Desktop Protocol (WDP)
71 1
72 1 EA=1; // Enable global IRQ
73 1
74 1 usb_wait_for_configuration(); // Wait until USB enumerated
75 1
76 1 if(hal_flash_byte_read(PARAM_PREV_PAIRED) == APP_PAIRING_COMMITED) // If dongle has paired to d
-evices before
77 1 {
78 2 hal_flash_bytes_read(PARAM_MASTER_ADR0, radio_data, FAP_ADDRESS_WIDTH-1); // Read pairing earlier dist
-ributed pairing address from flash
79 2 wdp_host_set_master_adr(radio_data); // Setup WDP using earlier u
-sed master address
80 2 }
81 1 else
82 1 {
83 2 if(hal_flash_byte_read(PARAM_PREV_PAIRED) != 0xff) // If flash not erased
84 2 { // Erase parameter page
85 3 hal_flash_page_erase(PARAM_PAGE_N0);
86 3 }
87 2 wdp_host_enable_random_adr_gen(); // Start random address gene
-ration if no previous pairing has been committed
88 2 }
89 1
90 1 timer_cnt = 0; // Reset global timing varia
-ble
91 1
92 1 wdp_host_rx_setup(WDP_RX_PAIRING); // By default listen for pai
-ring requests on power up
93 1 app_state = APP_PAIRING;
94 1
95 1 while(true)
96 1 {
97 2 switch(app_state) // State control
98 2 {
99 3 case APP_PAIRING:
100 3 app_state = app_pairing(); // Pairing state
101 3 break;
102 3 case APP_NORMAL: // Normal state
103 3 app_state = app_normal();
104 3 break;
105 3 case APP_SUSP_WE: // PC suspend state, remote
-wakeup enabled
106 3 app_state = app_susp_we();
107 3 break;
108 3 case APP_SUSP_WD: // PC suspend state, remote
C51 COMPILER V7.50 MAIN 04/09/2009 10:12:49 PAGE 3
-wakeup disabled
109 3 app_state = app_susp_wd();
110 3 break;
111 3 default:
112 3 break;
113 3 }
114 2 } // End while
115 1 } // End main
116
117
118 app_states_t app_pairing(void)
119 {
120 1 if(usb_get_state() == USB_REM_WU_ENABLE)
121 1 {
122 2 return APP_SUSP_WE;
123 2 }
124 1
125 1 if(usb_get_state() == USB_REM_WU_DISABLE)
126 1 {
127 2 return APP_SUSP_WD;
128 2 }
129 1
130 1 wdp_host_process_events();
131 1
132 1 if(wdp_host_get_clear_pairing_result()) // If pairing requests received
-from a device
133 1 {
134 2 if(hal_flash_byte_read(PARAM_PREV_PAIRED) != APP_PAIRING_COMMITED) // If this was the very first pa
-iring request ever
135 2 {
136 3 wdp_host_get_master_adr(radio_data);
137 3 hal_flash_bytes_write(PARAM_MASTER_ADR0, radio_data, FAP_ADDRESS_WIDTH-1);
138 3 hal_flash_byte_write(PARAM_PREV_PAIRED, APP_PAIRING_COMMITED); // Write master address to flash
139 3 }
140 2
141 2 wdp_host_rx_setup(WDP_RX_NORMAL);
142 2 return APP_NORMAL;
143 2 }
144 1
145 1 if(timer_cnt == APP_PAIRING_TIMEOUT)
146 1 {
147 2 timer_cnt = 0xffff;
148 2 wdp_host_rx_setup(WDP_RX_NORMAL);
149 2 return APP_NORMAL;
150 2 }
151 1
152 1 return APP_PAIRING;
153 1 }
154
155 app_states_t app_normal(void)
156 {
157 1 uint8_t dev_type, length, index;
158 1 uint8_t previous_app_attribute;
159 1
160 1 if(usb_get_state() == USB_REM_WU_ENABLE)
161 1 {
162 2 return APP_SUSP_WE;
163 2 }
164 1
165 1 if(usb_get_state() == USB_REM_WU_DISABLE)
166 1 {
167 2 return APP_SUSP_WD;
C51 COMPILER V7.50 MAIN 04/09/2009 10:12:49 PAGE 4
168 2 }
169 1
170 1 wdp_host_process_events();
171 1
172 1 if(wdp_host_get_rx_data(radio_data, &length, &dev_type)) // If radio activity
173 1 {
174 2 if(radio_data[APP_CMD] == APP_USER_INPUT && radio_data[APP_ATTRIBUTE] != previous_app_attribute)
175 2 {
176 3 previous_app_attribute = radio_data[APP_ATTRIBUTE];
177 3
178 3 switch(dev_type)
179 3 {
180 4 case WDP_MOUSE: // If mouse data
181 4 if(length == APP_MOUSE_PL_LENGTH)
182 4 {
183 5 usb_send_packet
184 5 (
185 5 &radio_data[APP_DATA],
186 5 USB_EP_MOUSE,
187 5 (APP_MOUSE_PL_LENGTH - APP_DATA)
188 5 );
189 5 }
190 4 break;
191 4 case WDP_KEYBOARD: // If keyboard data
192 4 if(length == APP_KEYBOARD_PL_LENGTH)
193 4 {
194 5 usb_send_packet
195 5 (
196 5 &radio_data[APP_DATA],
197 5 USB_EP_KEYBOARD,
198 5 (APP_KEYBOARD_PL_LENGTH - APP_DATA)
199 5 );
200 5 }
201 4 break;
202 4 }
203 3 }
204 2 else if( radio_data[APP_CMD] == APP_GET_REQUEST) // If data request received
205 2 {
206 3 wdp_host_write_downlink_data(dev_type, radio_data, WDP_MAX_DL_PL_LENGTH); // Preload uplink data to
-device
207 3 }
208 2
209 2 if(!wdp_host_get_connection_status(WDP_MOUSE))
210 2 {
211 3 for(index = APP_DATA; index < APP_MOUSE_PL_LENGTH; index++)
212 3 {
213 4 radio_data[index] = 0;
214 4 }
215 3 usb_send_packet(
216 3 &radio_data[APP_DATA],
217 3 USB_EP_MOUSE,
218 3 (APP_MOUSE_PL_LENGTH - APP_DATA)
219 3 );
220 3 }
221 2
222 2 if(!wdp_host_get_connection_status(WDP_KEYBOARD))
223 2 {
224 3 for(index = APP_DATA; index < APP_KEYBOARD_PL_LENGTH; index++)
225 3 {
226 4 radio_data[index] = 0;
227 4 }
228 3 usb_send_packet(
C51 COMPILER V7.50 MAIN 04/09/2009 10:12:49 PAGE 5
229 3 &radio_data[APP_DATA],
230 3 USB_EP_KEYBOARD,
231 3 (APP_KEYBOARD_PL_LENGTH - APP_DATA)
232 3 );
233 3 }
234 2 }
235 1 return APP_NORMAL;
236 1 }
237
238 app_states_t app_susp_we(void)
239 {
240 1 wdp_host_rx_setup(WDP_RX_SUSPEND); // Set up WDP low power receive mode
241 1
242 1 while (wdp_get_mode() != WDP_IDLE) // Wait until "receive burst" finished
243 1 ;
244 1
245 1 if(wdp_host_process_events()) // If any radio data received during "receive burst"
246 1 {
247 2 wdp_host_rx_setup(WDP_RX_NORMAL); // Wakeup PC if radio data received
248 2 usb_wakeup();
249 2 return APP_NORMAL;
250 2 }
251 1
252 1 // Minimize the powerconsumption by powering down the MCU
253 1 cklf_gpio_wakeup(0x0000, 0x0000); // GPIO wakeup off
254 1 cklf_rtc_disable();
255 1 cklf_rtc_init(0x00, 0x1FFF); // Setup power down timeout to app. 1 s
256 1 cpu_pwr_down(); // MCU goto sleep
257 1
258 1 WUF = 0; // Clear WU flag
259 1
260 1 return APP_SUSP_WE;
261 1 }
262
263 app_states_t app_susp_wd(void)
264 {
265 1 wdp_host_rx_setup(WDP_RX_OFF); // Disable radio to minimize power consumption
266 1 cpu_pwr_down(); // MCU goto sleep. May only be awaken from USB.
267 1 wdp_host_rx_setup(WDP_RX_NORMAL); // Setup WDP to normal receive mode
268 1
269 1 return APP_NORMAL;
270 1 }
MODULE INFORMATION: STATIC OVERLAYABLE
CODE SIZE = 625 ----
CONSTANT SIZE = ---- ----
XDATA SIZE = 15 5
PDATA SIZE = ---- ----
DATA SIZE = ---- ----
IDATA SIZE = ---- ----
BIT SIZE = ---- ----
EDATA SIZE = ---- ----
HDATA SIZE = ---- ----
XDATA CONST SIZE = ---- ----
FAR CONST SIZE = ---- ----
END OF MODULE INFORMATION.
C51 COMPILATION COMPLETE. 0 WARNING(S), 0 ERROR(S)
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?