⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 isr.lst

📁 PDIUSBD12 USB1.1 C51源代码
💻 LST
📖 第 1 页 / 共 5 页
字号:
C51 COMPILER V4.01,  ISR                                                                   07/07/01  13:16:07  PAGE 1   


DOS C51 COMPILER V4.01, COMPILATION OF MODULE ISR
OBJECT MODULE PLACED IN ISR.OBJ
COMPILER INVOKED BY: C:\KEIL\C51V4\BIN\C51.EXE ISR.C DEBUG SMALL CODE SYMBOLS OBJECTEXTEND NOAMAKE

stmt level    source

   1          /*
   2             //*************************************************************************
   3             //
   4             //                  P H I L I P S   P R O P R I E T A R Y
   5             //
   6             //           COPYRIGHT (c)   1997 BY PHILIPS SINGAPORE.
   7             //                     --  ALL RIGHTS RESERVED  --
   8             //
   9             // File Name:	ISR.C
  10             // Created:		19 Dec 97
  11             // Modified:
  12             // Revision:		3.0
  13             //
  14             //*************************************************************************
  15             //
  16             // 98/11/25 		Added I/O mode Main endpoints access. (WK)
  17             //*************************************************************************
  18             */
  19          #include <stdio.h>
  20          #include <string.h>
  21          
  22          #include <reg51.h>                /* special function register declarations   */
  23          
  24          #include "epphal.h"
  25          #include "d12ci.h"
  26          #include "mainloop.h"
  27          #include "usb100.h"
  28          
  29          extern void bus_reset(void);
  30          
  31          extern void ep0_txdone(void);
  32          extern void ep0_rxdone(void);
  33          
  34          extern void ep1_txdone(void);
  35          extern void ep1_rxdone(void);
  36          
  37          extern void main_txdone(void);
  38          extern void main_rxdone(void);
  39          
  40          extern void dma_eot(void);
  41          
  42          /*
  43          //*************************************************************************
  44          //  Public static data
  45          //*************************************************************************
  46          */
  47          
  48          EPPFLAGS bEPPflags;
  49          
  50          /* Control endpoint TX/RX buffers */
  51          extern CONTROL_XFER ControlData;
  52          
  53          /* ISR static vars */
  54          unsigned char idata GenEpBuf[EP1_PACKET_SIZE];
  55          unsigned char idata EpBuf[EP2_PACKET_SIZE];
  56          IO_REQUEST idata ioRequest;
  57          unsigned char ioSize, ioCount;
  58          
  59          unsigned long ClockTicks = 0;
C51 COMPILER V4.01,  ISR                                                                   07/07/01  13:16:07  PAGE 2   

  60          unsigned char xdata MainEpBuf[256];
  61          
  62          extern BOOL bNoRAM;
  63          
  64          timer_isr() interrupt 1
  65          {
  66   1      	DISABLE;
  67   1      	ClockTicks++;
  68   1      	bEPPflags.bits.timer = 1;
  69   1      	ENABLE;
  70   1      }
  71          
  72          
  73          usb_isr() interrupt 0
  74          {
  75   1      	DISABLE;
  76   1      	fn_usb_isr();
  77   1      	ENABLE;
  78   1      }
  79          
  80          void fn_usb_isr()
  81          {
  82   1      	unsigned int i_st;
  83   1      
  84   1      	bEPPflags.bits.in_isr = 1;
  85   1      
  86   1      	i_st = D12_ReadInterruptRegister();
  87   1      
  88   1      	if(i_st != 0) {
  89   2      		if(i_st & D12_INT_BUSRESET) {
  90   3      			bus_reset();
  91   3      			bEPPflags.bits.bus_reset = 1;
  92   3      		}
  93   2      
  94   2      		if(i_st & D12_INT_EOT)
  95   2      			dma_eot();
  96   2      
  97   2      		if(i_st & D12_INT_SUSPENDCHANGE)
  98   2      			bEPPflags.bits.suspend = 1;
  99   2      
 100   2      		if(i_st & D12_INT_ENDP0IN)
 101   2      			ep0_txdone();
 102   2      		if(i_st & D12_INT_ENDP0OUT)
 103   2      			ep0_rxdone();
 104   2      		if(i_st & D12_INT_ENDP1IN)
 105   2      			ep1_txdone();
 106   2      		if(i_st & D12_INT_ENDP1OUT)
 107   2      			ep1_rxdone();
 108   2      		if(i_st & D12_INT_ENDP2IN)
 109   2      			main_txdone();
 110   2      		if(i_st & D12_INT_ENDP2OUT)
 111   2      			main_rxdone();
 112   2      	}
 113   1      
 114   1      	bEPPflags.bits.in_isr = 0;
 115   1      }
 116          
 117          void bus_reset(void)
 118          {
 119   1      }
 120          
 121          void ep0_rxdone(void)
 122          {
 123   1      	unsigned char ep_last, i;
 124   1      
 125   1      	ep_last = D12_ReadLastTransactionStatus(0); // Clear interrupt flag
C51 COMPILER V4.01,  ISR                                                                   07/07/01  13:16:07  PAGE 3   

 126   1      
 127   1      	if (ep_last & D12_SETUPPACKET) {
 128   2      
 129   2      		ControlData.wLength = 0;
 130   2      		ControlData.wCount = 0;
 131   2      
 132   2      		if( D12_ReadEndpoint(0, sizeof(ControlData.DeviceRequest),
 133   2      			(unsigned char *)(&(ControlData.DeviceRequest))) != sizeof(DEVICE_REQUEST) ) {
 134   3      
 135   3      			D12_SetEndpointStatus(0, 1);
 136   3      			D12_SetEndpointStatus(1, 1);
 137   3      			bEPPflags.bits.control_state = USB_IDLE;
 138   3      			
 139   3      			return;
 140   3      		}
 141   2      
 142   2      		ControlData.DeviceRequest.wValue = SWAP(ControlData.DeviceRequest.wValue);
 143   2      		ControlData.DeviceRequest.wIndex = SWAP(ControlData.DeviceRequest.wIndex);
 144   2      		ControlData.DeviceRequest.wLength = SWAP(ControlData.DeviceRequest.wLength);
 145   2      
 146   2      		// Acknowledge setup here to unlock in/out endp
 147   2      		D12_AcknowledgeEndpoint(0);
 148   2      		D12_AcknowledgeEndpoint(1);
 149   2      
 150   2      		ControlData.wLength = ControlData.DeviceRequest.wLength;
 151   2      		ControlData.wCount = 0;
 152   2      
 153   2      		if (ControlData.DeviceRequest.bmRequestType & (unsigned char)USB_ENDPOINT_DIRECTION_MASK) {
 154   3      			bEPPflags.bits.setup_packet = 1;
 155   3      			bEPPflags.bits.control_state = USB_IDLE;		/* get command */
 156   3      		}
 157   2      		else {
 158   3      			if (ControlData.DeviceRequest.wLength == 0) {
 159   4      				bEPPflags.bits.setup_packet = 1;
 160   4      				bEPPflags.bits.control_state = USB_IDLE;		/* set command */
 161   4      			}
 162   3      			else {
 163   4      				if(ControlData.DeviceRequest.wLength > MAX_CONTROLDATA_SIZE) {
 164   5      					bEPPflags.bits.control_state = USB_IDLE;
 165   5      					D12_SetEndpointStatus(0, 1);
 166   5      					D12_SetEndpointStatus(1, 1);
 167   5      				}
 168   4      				else {
 169   5      					bEPPflags.bits.control_state = USB_RECEIVE;	/* set command with OUT token */
 170   5      				}
 171   4      			} // set command with data
 172   3      		} // else set command
 173   2      	} // if setup packet
 174   1      
 175   1      	else if (bEPPflags.bits.control_state == USB_RECEIVE) {
 176   2      		i =	D12_ReadEndpoint(0, EP0_PACKET_SIZE,
 177   2      			ControlData.dataBuffer + ControlData.wCount);
 178   2      
 179   2      		ControlData.wCount += i;
 180   2      		if( i != EP0_PACKET_SIZE || ControlData.wCount >= ControlData.wLength) {
 181   3      			bEPPflags.bits.setup_packet = 1;
 182   3      			bEPPflags.bits.control_state = USB_IDLE;
 183   3      		}
 184   2      	}
 185   1      
 186   1      	else {
 187   2      		bEPPflags.bits.control_state = USB_IDLE;
 188   2      	}
 189   1      }
 190          
 191          void ep0_txdone(void)
C51 COMPILER V4.01,  ISR                                                                   07/07/01  13:16:07  PAGE 4   

 192          {
 193   1      	short i = ControlData.wLength - ControlData.wCount;
 194   1      
 195   1      	D12_ReadLastTransactionStatus(1); // Clear interrupt flag
 196   1      
 197   1      	if (bEPPflags.bits.control_state != USB_TRANSMIT) 
 198   1      		return;
 199   1      
 200   1      	if( i >= EP0_PACKET_SIZE) {
 201   2      		D12_WriteEndpoint(1, EP0_PACKET_SIZE, ControlData.pData + ControlData.wCount);
 202   2      		ControlData.wCount += EP0_PACKET_SIZE;
 203   2      
 204   2      		bEPPflags.bits.control_state = USB_TRANSMIT;
 205   2      	}
 206   1      	else if( i != 0) {
 207   2      		D12_WriteEndpoint(1, i, ControlData.pData + ControlData.wCount);
 208   2      		ControlData.wCount += i;
 209   2      
 210   2      		bEPPflags.bits.control_state = USB_IDLE;
 211   2      	}
 212   1      	else if (i == 0){
 213   2      		D12_WriteEndpoint(1, 0, 0); // Send zero packet at the end ???
 214   2      
 215   2      		bEPPflags.bits.control_state = USB_IDLE;
 216   2      	}
 217   1      }
 218          
 219          void dma_eot(void)
 220          {
 221   1      }
 222          
 223          void ep1_txdone(void)
 224          {
 225   1      	D12_ReadLastTransactionStatus(3); /* Clear interrupt flag */
 226   1      }
 227          
 228          void ep1_rxdone(void)
 229          {
 230   1      	unsigned char len;
 231   1      
 232   1      	D12_ReadLastTransactionStatus(2); /* Clear interrupt flag */
 233   1      
 234   1      	len = D12_ReadEndpoint(2, sizeof(GenEpBuf), GenEpBuf);
 235   1      
 236   1      	if(len != 0)
 237   1      		bEPPflags.bits.ep1_rxdone = 1;
 238   1      }
 239          
 240          void main_txdone(void)
 241          {
 242   1      	unsigned char len;
 243   1      
 244   1      	D12_ReadLastTransactionStatus(5); /* Clear interrupt flag */
 245   1      
 246   1      	len = ioSize - ioCount;
 247   1      	if(len == 0) {
 248   2      		if(bEPPflags.bits.dma_state == DMA_PENDING)
 249   2      			bEPPflags.bits.setup_dma ++;
 250   2      		else
 251   2      			bEPPflags.bits.dma_state = DMA_IDLE;
 252   2      	}
 253   1      	else {
 254   2      		if(len > 64)
 255   2      			len = 64;
 256   2      		if(bNoRAM)
 257   2      			len = D12_WriteEndpoint(5, len, EpBuf + ioCount);
C51 COMPILER V4.01,  ISR                                                                   07/07/01  13:16:07  PAGE 5   

 258   2      		else
 259   2      			len = D12_WriteEndpoint(5, len, MainEpBuf + ioCount);
 260   2      		ioCount += len;

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -