📄 fw.lst
字号:
C51 COMPILER V6.10 FW 11/29/2002 10:53:59 PAGE 1
C51 COMPILER V6.10, COMPILATION OF MODULE FW
OBJECT MODULE PLACED IN .\FW.OBJ
COMPILER INVOKED BY: C:\Keil\C51\BIN\C51.EXE .\FW.C OPTIMIZE(6,SPEED) DEBUG OBJECTEXTEND
stmt level source
1 //-----------------------------------------------------------------------------
2 // File: fw.c
3 // Contents: Firmware frameworks task dispatcher and device request parser
4 // source.
5 //
6 // Copyright (c) 1997 AnchorChips, Inc. All rights reserved
7 //-----------------------------------------------------------------------------
8 #include "ezusb.h"
9 #include "ezregs.h"
10
11 //-----------------------------------------------------------------------------
12 // Random Macros
13 //-----------------------------------------------------------------------------
14 #define min(a,b) (((a)<(b))?(a):(b))
15 #define max(a,b) (((a)>(b))?(a):(b))
16
17 //-----------------------------------------------------------------------------
18 // Constants
19 //-----------------------------------------------------------------------------
20
21 //-----------------------------------------------------------------------------
22 // Global Variables
23 //-----------------------------------------------------------------------------
24 volatile BOOL GotSUD;
25 BOOL Rwuen;
26 BOOL Selfpwr;
27 volatile BOOL Sleep; // Sleep mode enable flag
28
29 WORD pDeviceDscr; // Pointer to Device Descriptor; Descriptors may be moved
30 WORD pConfigDscr;
31 WORD pStringDscr;
32
33 //-----------------------------------------------------------------------------
34 // Prototypes
35 //-----------------------------------------------------------------------------
36 void SetupCommand(void);
37 void TD_Init(void);
38 void TD_Poll(void);
39 BOOL TD_Suspend(void);
40 BOOL TD_Resume(void);
41
42 BOOL DR_GetDescriptor(void);
43 BOOL DR_SetConfiguration(void);
44 BOOL DR_GetConfiguration(void);
45 BOOL DR_SetInterface(void);
46 BOOL DR_GetInterface(void);
47 BOOL DR_GetStatus(void);
48 BOOL DR_ClearFeature(void);
49 BOOL DR_SetFeature(void);
50 BOOL DR_VendorCmnd(void);
51
52 //-----------------------------------------------------------------------------
53 // Code
54 //-----------------------------------------------------------------------------
55
C51 COMPILER V6.10 FW 11/29/2002 10:53:59 PAGE 2
56 // Task dispatcher
57 void main(void)
58 {
59 1 DWORD i;
60 1 WORD offset;
61 1 DWORD DevDescrLen;
62 1 DWORD j=0;
63 1 WORD IntDescrAddr;
64 1 WORD ExtDescrAddr;
65 1
66 1 // Initialize Global States
67 1 Sleep = FALSE; // Disable sleep mode
68 1 Rwuen = FALSE; // Disable remote wakeup
69 1 Selfpwr = FALSE; // Disable self powered
70 1 GotSUD = FALSE; // Clear "Got setup data" flag
71 1
72 1 // Initialize user device
73 1 TD_Init();
74 1
75 1 // The following section of code is used to relocate the descriptor table.
76 1 // Since the SUDPTRH and SUDPTRL are assigned the address of the descriptor
77 1 // table, the descriptor table must be located in on-part memory.
78 1 // The 4K demo tools locate all code sections in external memory.
79 1 // The descriptor table is relocated by the frameworks ONLY if it is found
80 1 // to be located in external memory.
81 1 pDeviceDscr = (WORD)&DeviceDscr;
82 1 pConfigDscr = (WORD)&ConfigDscr;
83 1 pStringDscr = (WORD)&StringDscr;
84 1 if ((WORD)&DeviceDscr & 0xe000)
85 1 {
86 2 IntDescrAddr = INTERNAL_DSCR_ADDR;
87 2 ExtDescrAddr = (WORD)&DeviceDscr;
88 2 DevDescrLen = (WORD)&UserDscr - (WORD)&DeviceDscr + 2;
89 2 for (i = 0; i < DevDescrLen; i++)
90 2 *((BYTE xdata *)IntDescrAddr+i) = 0xCD;
91 2 for (i = 0; i < DevDescrLen; i++)
92 2 *((BYTE xdata *)IntDescrAddr+i) = *((BYTE xdata *)ExtDescrAddr+i);
93 2 pDeviceDscr = IntDescrAddr;
94 2 offset = (WORD)&DeviceDscr - INTERNAL_DSCR_ADDR;
95 2 pConfigDscr -= offset;
96 2 pStringDscr -= offset;
97 2 }
98 1
99 1 EZUSB_IRQ_ENABLE(); // Enable USB interrupt (INT2)
100 1 EZUSB_ENABLE_RSMIRQ(); // Wake-up interrupt
101 1
102 1 // The 8051 is responsible for all USB events, even those that have happened
103 1 // before this point. We cannot ignore pending USB interrupts.
104 1 // The chip will come out of reset with the flags all cleared.
105 1 // USBIRQ = 0xff; // Clear any pending USB interrupt requests
106 1 PORTCCFG |= 0xc0; // Turn on r/w lines for external memory
107 1
108 1 USBBAV = USBBAV | 1 & ~bmBREAK; // Disable breakpoints and autovectoring
109 1 USBIEN |= bmSUDAV | bmSUTOK | bmSUSP | bmURES; // Enable selected interrupts
110 1 EA = 1; // Enable 8051 interrupts
111 1
112 1 #ifndef NO_RENUM
113 1 // Note: at full speed, high speed hosts may take 5 sec to detect device
114 1 EZUSB_Discon(TRUE); // Renumerate
115 1 #endif
116 1
117 1
C51 COMPILER V6.10 FW 11/29/2002 10:53:59 PAGE 3
118 1 CKCON = (CKCON&(~bmSTRETCH)) | FW_STRETCH_VALUE; // Set stretch to 0 (after renumeration)
119 1
120 1 // Task Dispatcher
121 1 while(TRUE) // Main Loop
122 1 {
123 2 if(GotSUD) // Wait for SUDAV
124 2 {
125 3 SetupCommand(); // Implement setup command
126 3 GotSUD = FALSE; // Clear SUDAV flag
127 3 }
128 2
129 2 // Poll User Device
130 2 // NOTE: Idle mode stops the processor clock. There are only two
131 2 // ways out of idle mode, the WAKEUP pin, and detection of the USB
132 2 // resume state on the USB bus. The timers will stop and the
133 2 // processor will not wake up on any other interrupts.
134 2 if (Sleep)
135 2 {
136 3 if(TD_Suspend())
137 3 {
138 4 Sleep = FALSE; // Clear the "go to sleep" flag. Do it here to prevent any race condition b
-etween wakeup and the next sleep.
139 4 do
140 4 {
141 5 EZUSB_Susp(); // Place processor in idle mode.
142 5 }
143 4 while(!Rwuen && EZUSB_EXTWAKEUP());
144 4 // Must continue to go back into suspend if the host has disabled remote wakeup
145 4 // *and* the wakeup was caused by the external wakeup pin.
146 4
147 4 // 8051 activity will resume here due to USB bus or Wakeup# pin activity.
148 4 EZUSB_Resume(); // If source is the Wakeup# pin, signal the host to Resume.
149 4 TD_Resume();
150 4 }
151 3 }
152 2 TD_Poll();
153 2 }
154 1 }
155
156 // Device request parser
157 void SetupCommand(void)
158 {
159 1 void *dscr_ptr;
160 1 DWORD i;
161 1
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -