📄 isr.lst
字号:
C51 COMPILER V7.50 ISR 04/22/2005 11:54:50 PAGE 1
C51 COMPILER V7.50, COMPILATION OF MODULE ISR
OBJECT MODULE PLACED IN isr.OBJ
COMPILER INVOKED BY: C:\Keil\C51\BIN\C51.EXE isr.c DEBUG OBJECTEXTEND SRC(.\isr.SRC)
line level source
1 /*
2 //*************************************************************************
3 //
4 // BASBA P R O P R I E T A R Y
5 //
6 // COPYRIGHT (c) 2003 BY BASBA USA.
7 // -- ALL RIGHTS RESERVED --
8 //
9 // File Name: isr.c
10 // Purpose: Handles the interrupt generated by PDIUSBD12. It retrieve
11 // data from PDIUSBD12's internal FIFO to CPU memory, and
12 // setup proper event flags to inform mainloop for processing
13 // Author: Shuming Yu
14 // Created: 10 May 2003
15 // Modified:
16 // Revision: 1.0
17 //
18 //*************************************************************************
19 */
20
21 #include <reg51.h> /* special function register declarations */
22
23 #include "d12hal.h"
24 #include "cmds.h"
25 #include "mainloop.h"
26 #include "usbStruc.h"
27
28 #define INTERRUPT_INT0_Overflow 0
29 #define INTERRUPT_Timer_0_Overflow 1
30
31 void bus_reset(void);
32
33 void ProcessCtrlInEP(void);
34 void ProcessCtrlOutEP(void);
35
36 //*************************************************************************
37 // Public static data
38 //*************************************************************************
39
40 extern EPPFLAGS bEPPflags; /* USB event flags */
41 extern CONTROL_XFER ControlData; /* Control endpoint TX/RX buffers */
42
43 /* ISR static vars */
44 //unsigned char idata GenEpBuf[EP1_PACKET_SIZE];
45 unsigned char idata GenEpBuf[EP0_PACKET_SIZE];
46 //IO_REQUEST idata ioRequest;
47
48 unsigned long ClockTicks = 0;
49
50 timer_isr() interrupt INTERRUPT_Timer_0_Overflow
51 {
52 1 DISABLE;
53 1 ClockTicks++;
54 1 bEPPflags.bits.timer = 1;
55 1 ENABLE;
C51 COMPILER V7.50 ISR 04/22/2005 11:54:50 PAGE 2
56 1 }
57
58 usb_isr() interrupt INTERRUPT_INT0_Overflow
59 {
60 1 DISABLE;
61 1 fn_usb_isr();
62 1 ENABLE;
63 1 }
64
65 /* Interrupt service subroutine */
66 void fn_usb_isr()
67 {
68 1 unsigned int i_st;
69 1
70 1 bEPPflags.bits.in_isr = 1;
71 1
72 1 i_st = D12_ReadInterruptRegister();
73 1
74 1 if(i_st != 0) {
75 2 if(i_st & D12_INT_BUSRESET) {
76 3 bus_reset();
77 3 bEPPflags.bits.bus_reset = 1;
78 3 }
79 2 if(i_st & D12_INT_EOT)
80 2 ;
81 2 if(i_st & D12_INT_SUSPENDCHANGE)
82 2 bEPPflags.bits.suspend = 1;
83 2
84 2 if(i_st & D12_INT_ENDP0IN)
85 2 /* Control Endpoint IN Interrupt */
86 2 ProcessCtrlInEP();
87 2 if(i_st & D12_INT_ENDP0OUT)
88 2 /* Control Endpoint OUT Interrupt */
89 2 ProcessCtrlOutEP();
90 2 if(i_st & D12_INT_ENDP1IN) {
91 3 /* Endpoint 1 IN Interrupt (generic input) */
92 3 D12_ReadLastTransactionStatus(3); /* Clear interrupt flag */
93 3 /* send data back to host */
94 3 bEPPflags.bits.ep1_sxdone = 1; //host request to send data
95 3 }
96 2 if(i_st & D12_INT_ENDP1OUT)
97 2 { /* Endpoint 1 OUT Interrupt (generic output) */
98 3 unsigned char len;
99 3
100 3 D12_ReadLastTransactionStatus(2); /* Clear interrupt flag */
101 3 len = D12_ReadEndpoint(2, GenEpBuf, sizeof(GenEpBuf));
102 3 if(len != 0)
103 3 bEPPflags.bits.ep1_rxdone = 1;
104 3 }
105 2 //if(i_st & D12_INT_ENDP2IN)
106 2 // main_txdone();
107 2 //if(i_st & D12_INT_ENDP2OUT)
108 2 // main_rxdone();
109 2 }
110 1
111 1 bEPPflags.bits.in_isr = 0;
112 1 }
113
114 void bus_reset(void)
115 {
116 1 }
117
C51 COMPILER V7.50 ISR 04/22/2005 11:54:50 PAGE 3
118 // Control OUT handler
119 void ProcessCtrlOutEP(void)
120 {
121 1 unsigned char ep_last, i;
122 1
123 1 /* Clear corresponding endpoint interrupt flag */
124 1 ep_last = D12_ReadLastTransactionStatus(0);
125 1
126 1 /* check to see if the current received status is a SETUP package,
127 1 if so, SETUP endpoints have to be 'ACK'ed. */
128 1 if (ep_last & D12_SETUPPACKET) { /* SETUP package ? */
129 2 ControlData.wLength = 0;
130 2 ControlData.wCount = 0;
131 2
132 2 /* Select control OUT endpoint, readbuffer, if validate device request,
133 2 save to deviceRequest clear buffer */
134 2 if( D12_ReadEndpoint(0, (unsigned char *)(&(ControlData.DeviceRequest)),
135 2 sizeof(ControlData.DeviceRequest)) != sizeof(DEVICE_REQUEST) ) {
136 3
137 3 stall_ep0; /* stall control endpoints */
*** WARNING C275 IN LINE 137 OF ISR.C: expression with possibly no effect
138 3 bEPPflags.bits.control_state = USB_IDLE;
139 3
140 3 return;
141 3 }
142 2
143 2 /* swap data low byte and high byte, for USB data structure is different
144 2 from C51 data structure */
145 2 ControlData.DeviceRequest.wValue = SWAP(ControlData.DeviceRequest.wValue);
146 2 ControlData.DeviceRequest.wIndex = SWAP(ControlData.DeviceRequest.wIndex);
147 2 ControlData.DeviceRequest.wLength = SWAP(ControlData.DeviceRequest.wLength);
148 2
149 2 /* Acknowledge SETUP command to both IN and OUT endpoints, to reanable validate
150 2 and ClearBuffer commands. */
151 2 D12_AcknowledgeEndpoint(0);
152 2 D12_AcknowledgeEndpoint(1);
153 2
154 2 /* If ControlRead, wLength means the number of bytes to be sent to host;
155 2 if ControlWrite,wLength means the number of bytes to be got from host. */
156 2 ControlData.wLength = ControlData.DeviceRequest.wLength;
157 2 ControlData.wCount = 0;
158 2
159 2 /* Verify whether the contro transfer is Control READ/WRITE ? */
160 2 if (ControlData.DeviceRequest.bmRequestType & (unsigned char)USB_ENDPOINT_DIRECTION_MASK) {
161 3 /* Control Read (get command, device will need to send data packet back to host) */
162 3 bEPPflags.bits.setup_packet = 1; // set event SETUP packet
163 3 bEPPflags.bits.control_state = USB_TRANSMIT;
164 3 }
165 2 else { /* Control Write (set command) */
166 3 if (ControlData.DeviceRequest.wLength == 0) {
167 4 /* Control Write without data */
168 4 bEPPflags.bits.setup_packet = 1; // set event SETUP packet
169 4 bEPPflags.bits.control_state = USB_IDLE;
170 4 }
171 3 else { /*Control Write with data */
172 4 if(ControlData.DeviceRequest.wLength > MAX_CONTROLDATA_SIZE) {
173 5 /* data length not acceptable */
174 5 bEPPflags.bits.control_state = USB_IDLE;
175 5 stall_ep0; /* stall control endpoints */
*** WARNING C275 IN LINE 175 OF ISR.C: expression with possibly no effect
176 5 }
177 4 else {
C51 COMPILER V7.50 ISR 04/22/2005 11:54:50 PAGE 4
178 5 /* Device need to be received number of wLength bytes of data from host */
179 5 bEPPflags.bits.control_state = USB_RECEIVE; /* set command with OUT token */
180 5 }
181 4 } // set command with data
182 3 } // else set command
183 2 } // if setup packet
184 1
185 1 else if (bEPPflags.bits.control_state == USB_RECEIVE) {
186 2 i = D12_ReadEndpoint(0, ControlData.dataBuffer + ControlData.wCount,
187 2 EP0_PACKET_SIZE);
188 2
189 2 ControlData.wCount += i;
190 2 if( i != EP0_PACKET_SIZE || ControlData.wCount >= ControlData.wLength) {
191 3 bEPPflags.bits.setup_packet = 1;
192 3 bEPPflags.bits.control_state = USB_IDLE;
193 3 }
194 2 }
195 1
196 1 else {
197 2 bEPPflags.bits.control_state = USB_IDLE;
198 2 }
199 1 }
200
201 // Control IN handler
202 void ProcessCtrlInEP(void)
203 {
204 1 short i = ControlData.wLength - ControlData.wCount;
205 1
206 1 D12_ReadLastTransactionStatus(1); /* Clear interrupt flag */
207 1
208 1 /* if not in transmit status, return */
209 1 if (bEPPflags.bits.control_state != USB_TRANSMIT)
210 1 return;
211 1
212 1 /* number of rest bytes to be sent is more then EP0_PACKET_SIZE bytes, send EP0_PACKET_SIZE bytes */
213 1 if( i >= EP0_PACKET_SIZE) {
214 2 D12_WriteEndpoint(1, ControlData.pData + ControlData.wCount, EP0_PACKET_SIZE);
215 2 ControlData.wCount += EP0_PACKET_SIZE;
216 2
217 2 bEPPflags.bits.control_state = USB_TRANSMIT;
218 2 }
219 1 /* send rest of bytes (number of bytes is less than EP0_PACKET_SIZE bytes) */
220 1 else if( i != 0) {
221 2 D12_WriteEndpoint(1, ControlData.pData + ControlData.wCount, i);
222 2 ControlData.wCount += i;
223 2
224 2 bEPPflags.bits.control_state = USB_IDLE;
225 2 }
226 1 /* Send zero packet at the end, if no data phase,
227 1 IO device acknowledging receipt of setup phase (status phanse) */
228 1 else if (i == 0){
229 2 D12_WriteEndpoint(1, 0, 0);
230 2
231 2 bEPPflags.bits.control_state = USB_IDLE;
232 2 }
233 1 }
234
235
236
MODULE INFORMATION: STATIC OVERLAYABLE
C51 COMPILER V7.50 ISR 04/22/2005 11:54:50 PAGE 5
CODE SIZE = 599 ----
CONSTANT SIZE = ---- ----
XDATA SIZE = ---- ----
PDATA SIZE = ---- ----
DATA SIZE = 4 5
IDATA SIZE = 16 ----
BIT SIZE = ---- ----
END OF MODULE INFORMATION.
C51 COMPILATION COMPLETE. 2 WARNING(S), 0 ERROR(S)
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -