📄 fw2hid.lst
字号:
C51 COMPILER V6.10 FW2HID 07/11/2005 20:41:13 PAGE 1
C51 COMPILER V6.10, COMPILATION OF MODULE FW2HID
OBJECT MODULE PLACED IN .\fw2HID.OBJ
COMPILER INVOKED BY: C:\Keil\C51\BIN\C51.EXE .\fw2HID.C OPTIMIZE(6,SPEED) BROWSE DEBUG OBJECTEXTEND
stmt level source
1 //-----------------------------------------------------------------------------
2 // File: fw2HID.c (fw.c modified by LTH on 20-Aug-01
3 // Contents: Firmware frameworks task dispatcher and device request parser
4 // source.
5 //
6 // Copyright (c) 2001 Cypress Semiconductor, Inc. All rights reserved
7 //-----------------------------------------------------------------------------
8 #include "ezusb.h"
9 #include "ezregs.h"
10 //-----------------------------------------------------------------------------
11 // Macros
12 //-----------------------------------------------------------------------------
13 #define min(a,b) (((a)<(b))?(a):(b))
14 #define max(a,b) (((a)>(b))?(a):(b))
15 //-----------------------------------------------------------------------------
16 // Constants
17 //-----------------------------------------------------------------------------
18 #define bmRequestType 0
19 #define bRequest 1
20 #define wValueL 2
21 #define wValueH 3
22 #define wIndexL 4
23 #define wIndexH 5
24 #define wLengthL 6
25 #define wLengthH 7
26 //
27 #define GET_REPORT 0x01 // HID Request Types
28 #define SET_REPORT 0x09
29 #define GET_IDLE 0x02
30 #define SET_IDLE 0x0A
31 //
32 #define rt_INPUT 1 // HID report types
33 #define rt_OUTPUT 2
34 #define rt_FEATURE 3 // all others are 'reserved'
35 //-----------------------------------------------------------------------------
36 // Global Variables
37 //-----------------------------------------------------------------------------
38 //volatile BOOL GotSUD; // set by SUDAV ISR
39 //volatile BOOL Sleep; // Sleep mode enable flag
40 BOOL GotSUD; // set by SUDAV ISR
41 BOOL Sleep; // Sleep mode enable flag
42 BOOL Rwuen;
43 BOOL Selfpwr;
44 BYTE IdleRate;
45 //-----------------------------------------------------------------------------
46 // Prototypes
47 //-----------------------------------------------------------------------------
48 void SetupCommand(void);
49 void TD_Init(void);
50 void TD_Poll(void);
51 BOOL TD_Suspend(void);
52 BOOL TD_Resume(void);
53
54 BOOL DR_SetConfiguration(void);
55 BOOL DR_GetConfiguration(void);
C51 COMPILER V6.10 FW2HID 07/11/2005 20:41:13 PAGE 2
56 BOOL DR_SetInterface(void);
57 BOOL DR_GetInterface(void);
58 BOOL DR_GetStatus(void);
59 BOOL DR_ClearFeature(void);
60 BOOL DR_SetFeature(void);
61
62 void process_standard_request(void);
63 void process_class_request(void);
64 void process_descriptor(void);
65
66 //-----------------------------------------------------------------------------
67 // Descriptors
68 //-----------------------------------------------------------------------------
69 extern code DeviceDescr,ConfigDescr,String0,String1,String2,HIDDescr;
70 extern code ReportDescr,ReportDescr_end;
71 //-----------------------------------------------------------------------------
72 // Code
73 //-----------------------------------------------------------------------------
74
75 // Task dispatcher
76 void main(void) // power-on reset takes us here
77 {
78 1 // Initialize Global States
79 1 Sleep = FALSE; // Disable sleep mode
80 1 Rwuen = FALSE; // Disable remote wakeup
81 1 Selfpwr = FALSE; // Disable self powered
82 1 GotSUD = FALSE; // Clear "Got setup data" flag
83 1
84 1 // Initialize user device
85 1 TD_Init();
86 1
87 1 EZUSB_IRQ_ENABLE(); // Enable USB interrupt (INT2)
88 1 EZUSB_ENABLE_RSMIRQ(); // Wake-up interrupt
89 1 PORTCCFG |= 0xc0; // Turn on r/w lines for external memory (Keil monitor)
90 1 USBBAV = USBBAV | 1 & ~bmBREAK; // Disable breakpoints and ENABLE autovectoring
91 1 USBIEN |= bmSUDAV | bmSUSP | bmURES; // Enable selected interrupts
92 1 EA = 1; // Enable 8051 interrupts
93 1
94 1 EZUSB_Discon(TRUE); // ReNumerate
95 1
96 1 // Task Dispatcher
97 1 while(TRUE) // Main Loop
98 1 {
99 2 if(GotSUD) // Wait for SUDAV
100 2 {
101 3 SetupCommand(); // Service the SETUP request
102 3 GotSUD = FALSE; // Clear SUDAV flag--NOTE: clearing GotSUD after calling SetupCommand()
103 3 } // properly handles multi-packet Get_Descriptor_Report requests
104 2 // (which would generate multiple SUDAV interrupts).
105 2 if (Sleep) // set to TRUE by the SUSPEND ISR
106 2 {
107 3 if(TD_Suspend()) // hook in periph.c to do stuff before suspending
108 3 {
109 4 Sleep = FALSE; // Clear the "go to sleep" flag. Do it here to prevent any race condition b
-etween wakeup and the next sleep.
110 4 do
111 4 {
112 5 EZUSB_Susp(); // Place processor in idle mode.
113 5 }
114 4 while(!Rwuen && EZUSB_EXTWAKEUP());
115 4 // Must continue to go back into suspend if the host has disabled remote wakeup
116 4 // *and* the wakeup was caused by the external wakeup pin.
C51 COMPILER V6.10 FW2HID 07/11/2005 20:41:13 PAGE 3
117 4
118 4 // 8051 activity will resume here due to USB bus or Wakeup# pin activity.
119 4 EZUSB_Resume(); // If source is the Wakeup# pin, signal the host to Resume.
120 4 TD_Resume();
121 4 }
122 3 }
123 2
124 2 TD_Poll();
125 2 } // end while(TRUE)
126 1 }
127
128 // Device request parser
129 void SetupCommand(void)
130 {
131 1 switch(SETUPDAT[bmRequestType] & 0x60) // 00-std,20-class,40-vendor,60-reserved.
132 1 {
133 2 case SETUP_STANDARD_REQUEST:
134 2 process_standard_request();
135 2 break;
136 2 case SETUP_CLASS_REQUEST:
137 2 process_class_request();
138 2 break;
139 2 default:
140 2 EZUSB_STALL_EP0(); // we don't handle SETUP_VENDOR_REQUEST or "Reserved".
141 2 }
142 1 EP0CS = bmHS; // Clear the HS-NAK bit by writing '1' to it
143 1 }
144
145 void process_standard_request(void)
146 {
147 1 switch(SETUPDAT[bRequest])
148 1 {
149 2 case SC_GET_DESCRIPTOR: // *** Get Descriptor
150 2 process_descriptor();
151 2 break;
152 2 case SC_GET_INTERFACE: // *** Get Interface
153 2 DR_GetInterface();
154 2 break;
155 2 case SC_SET_INTERFACE: // *** Set Interface
156 2 DR_SetInterface();
157 2 break;
158 2 case SC_SET_CONFIGURATION: // *** Set Configuration
159 2 DR_SetConfiguration();
160 2 break;
161 2 case SC_GET_CONFIGURATION: // *** Get Configuration
162 2 DR_GetConfiguration();
163 2 break;
164 2 case SC_GET_STATUS: // *** Get Status
165 2 if(DR_GetStatus())
166 2 switch(SETUPDAT[bmRequestType])
167 2 {
168 3 case GS_DEVICE: // Device
169 3 IN0BUF[0] = ((BYTE)Rwuen << 1) | (BYTE)Selfpwr;
170 3 IN0BUF[1] = 0;
171 3 EZUSB_SET_EP_BYTES(IN0BUF_ID,2);
172 3 break;
173 3 case GS_INTERFACE: // Interface
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -