📄 mainloop.lst
字号:
19 =1
20 =1
21 =1 #ifndef __CHAP_9_H__
22 =1 #define __CHAP_9_H__
23 =1
24 =1 /*
25 =1 //*************************************************************************
26 =1 // USB Protocol Layer
C51 COMPILER V8.02 MAINLOOP 07/27/2007 11:10:49 PAGE 15
27 =1 //*************************************************************************
28 =1 */
29 =1
30 =1 /*
31 =1 //*************************************************************************
32 =1 // USB standard device requests
33 =1 //*************************************************************************
34 =1 */
35 =1 void get_status(void);
36 =1 void clear_feature(void);
37 =1 void set_feature(void);
38 =1 void set_address(void);
39 =1 void get_descriptor(void);
40 =1 void get_configuration(void);
41 =1 void set_configuration(void);
42 =1 void get_interface(void);
43 =1 void set_interface(void);
44 =1
45 =1 void reserved(void);
46 =1
47 =1 #endif
37 #include "protodma.h"
1 =1 /*
2 =1 //*************************************************************************
3 =1 //
4 =1 // P H I L I P S P R O P R I E T A R Y
5 =1 //
6 =1 // COPYRIGHT (c) 1997 BY PHILIPS SINGAPORE.
7 =1 // -- ALL RIGHTS RESERVED --
8 =1 //
9 =1 // File Name: PROTODMA.H
10 =1 // Author: Wenkai Du
11 =1 // Created: 19 Dec 97
12 =1 // Modified:
13 =1 // Revision: 2.0
14 =1 //
15 =1 //*************************************************************************
16 =1 //
17 =1 //*************************************************************************
18 =1 */
19 =1
20 =1
21 =1 #ifndef __PROTODMA_H__
22 =1 #define __PROTODMA_H__
23 =1
24 =1 /*
25 =1 //*************************************************************************
26 =1 // USB vendor device requests
27 =1 //*************************************************************************
28 =1 */
29 =1
30 =1 void read_write_register(void);
31 =1
32 =1 #endif
38 /*
39 //*************************************************************************
40 // USB protocol function pointer arrays
41 //*************************************************************************
42 */
43 code void (*StandardDeviceRequest[])(void) =
44 {
45 get_status,
C51 COMPILER V8.02 MAINLOOP 07/27/2007 11:10:49 PAGE 16
46 clear_feature,
47 reserved,
48 set_feature,
49 reserved,
50 set_address,
51 get_descriptor,
52 reserved,
53 get_configuration,
54 set_configuration,
55 get_interface,
56 set_interface,
57 reserved,
58 reserved,
59 reserved,
60 reserved
61 };
62
63 code void (*VendorDeviceRequest[])(void) =
64 {
65 reserved,
66 reserved,
67 reserved,
68 reserved,
69 reserved,
70 reserved,
71 reserved,
72 reserved,
73 reserved,
74 reserved,
75 reserved,
76 reserved,
77 read_write_register,
78 reserved,
79 reserved,
80 reserved
81 };
82
83 /*
84 //*************************************************************************
85 // Public static data
86 //*************************************************************************
87 */
88
89 extern EPPFLAGS bEPPflags;
90 extern unsigned long ClockTicks;
91 extern unsigned char idata GenEpBuf[];
92 extern IO_REQUEST idata ioRequest;
93
94 CONTROL_XFER ControlData;
95
96 code char * _NAME_USB_REQUEST_DIRECTION[] =
97 {
98 "Host_to_device",
99 "Device_to_host"
100 };
101
102 code char * _NAME_USB_REQUEST_RECIPIENT[] =
103 {
104 "Device",
105 "Interface",
106 "Endpoint(0)",
107 "Other"
C51 COMPILER V8.02 MAINLOOP 07/27/2007 11:10:49 PAGE 17
108 };
109
110 code char * _NAME_USB_REQUEST_TYPE[] =
111 {
112 "Standard",
113 "Class",
114 "Vendor",
115 "Reserved"
116 };
117
118 code char * _NAME_USB_STANDARD_REQUEST[] =
119 {
120 "GET_STATUS",
121 "CLEAR_FEATURE",
122 "RESERVED",
123 "SET_FEATURE",
124 "RESERVED",
125 "SET_ADDRESS",
126 "GET_DESCRIPTOR",
127 "SET_DESCRIPTOR",
128 "GET_CONFIGURATION",
129 "SET_CONFIGURATION",
130 "GET_INTERFACE",
131 "SET_INTERFACE",
132 "SYNC_FRAME"
133 };
134
135 void help_devreq(unsigned char typ, unsigned char req)
136 {
137 1 typ >>= 5;
138 1
139 1 if(typ == USB_STANDARD_REQUEST) {
140 2 printf("Request Type = %s, Request = %s.\n", _NAME_USB_REQUEST_TYPE[typ],
141 2 _NAME_USB_STANDARD_REQUEST[req]);
142 2 }
143 1 else {
144 2 #ifdef __C51__
145 2 if(bEPPflags.bits.verbose)
146 2 printf("Request Type = %s, bRequest = 0x%bx.\n", _NAME_USB_REQUEST_TYPE[typ],
147 2 req);
148 2 #else
if(bEPPflags.bits.verbose)
printf("Request Type = %s, bRequest = 0x%x.\n", _NAME_USB_REQUEST_TYPE[typ],
req);
#endif
153 2 }
154 1 }
155
156 /* Configure Timer 0
157 - Mode = 1
158 - Interrupt = ENABLED
159 - Clock Source = INTERNAL
160 - Enable Gating Control = DISABLED
161 */
162
163 #ifndef __C51__
extern void interrupt (*OldTimerIsr)();
extern void interrupt (*OldUsbIsr)();
extern unsigned long ClockIsr;
unsigned char far *privateBuffer;
C51 COMPILER V8.02 MAINLOOP 07/27/2007 11:10:49 PAGE 18
unsigned long dmaBuffer;
unsigned long ioBuffer; // V2.1
unsigned short ioSize, ioCount; // V2.1
#endif
174
175 void init_timer0(void)
176 {
177 1 #ifdef __C51__
178 1 TMOD &= 0XF0; /* clear Timer 0 */
179 1 TMOD |= 0X1;
180 1 TL0 = 0X0; /* value set by user */
181 1 TH0 = 0X0; /* value set by user */
182 1 ET0 = 1; /* IE.1*/
183 1 TR0 = 1; /* TCON.4 start timer */
184 1 PT0 = 1;
185 1
186 1 EA = 1;
187 1 #else
disable();
OldTimerIsr = getvect(0x8);
setvect(0x8, timer_isr);
enable();
#endif
193 1 }
194
195 /* Interrupt Control Unit */
196 /* **** Enabled interrupts in Interrupt Enable Register ****
197 **** GLOBAL INTERRUPT MUST BE ENABLED FOR ANY OTHER
198 **** INTERRUPT TO WORK!
199 */
200 /* GLOBAL INTERRUPT DISABLED ALL INTERRUPTS
201 ARE DISABLED */
202 /* External interrupt 0 */
203 /* Priority Level = 0 */
204 /* Timer 0 interrupt */
205 /* Priority Level = 0 */
206 void init_special_interrupts(void)
207 {
208 1 #ifdef __C51__
209 1 IT0 = 0;
210 1 EX0 = 1;
211 1 PX0 = 0;
212 1 #else
unsigned char c, eo;
OldUsbIsr = getvect(0xD);
setvect(0xD, usb_isr);
c = inportb(0x21);
c &= 0xDF;
outportb(0x21, c);
eo = 0x0;
D12Eval_outportb(eo, 0x80);
eo = 0x80;
D12Eval_outportb(eo, 0x80);
#endif
228 1 }
229
230 void init_port()
231 {
C51 COMPILER V8.02 MAINLOOP 07/27/2007 11:10:49 PAGE 19
232 1 #ifdef __C51__
233 1 P0 = 0xFF;
234 1 P1 = 0xFF;
235 1 P2 = 0xFF;
236 1 #else
unsigned long phys;
privateBuffer = (unsigned char far *)farmalloc(DMA_BUFFER_SIZE*2L);
if(privateBuffer == NULL) {
printf("Error allocation memory!\n");
exit(1);
}
phys = (unsigned long)FP_SEG(privateBuffer)*16 + FP_OFF(privateBuffer);
if( (phys&0x0ffffL) == 0 ) {
dmaBuffer = phys;
}
else {
phys &= 0xf0000L;
phys += 0x10000;
dmaBuffer = phys;
}
printf("privateBuffer allocated at %p, dmaBuffer at %lx.\n",
privateBuffer, dmaBuffer);
#endif
257 1 }
258
259 /*Serial Port */
260 /*Mode = 1 /8-bit UART
261 Serial Port Interrupt = Disabled */
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -