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