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

📄 isp1581.lst

📁 DSP通过双口RAM和ISP1581实现下位机的USB固件程序
💻 LST
📖 第 1 页 / 共 2 页
字号:
C51 COMPILER V7.06   ISP1581                                                               09/09/2005 13:57:31 PAGE 1   


C51 COMPILER V7.06, COMPILATION OF MODULE ISP1581
OBJECT MODULE PLACED IN Isp1581.OBJ
COMPILER INVOKED BY: C:\Keil\C51\BIN\C51.EXE Isp1581.c BROWSE DEBUG OBJECTEXTEND

stmt level    source

   1          #include "SMPro.h"
   2          #include "HAL.h"
   3          #include "USB.H"
   4          #include "Isp1581.h"
   5          extern ZBOARDFLAGS bZBoardFlags;
   6          
   7          void outport(unsigned short nPort, unsigned short nVal)
   8          {
   9   1              unsigned short idata temp;
  10   1              
  11   1              unsigned char xdata *exAddress;
  12   1              exAddress = nPort;
  13   1              temp=nVal;
  14   1              ISP1581_CS=0;//xxg
  15   1              *exAddress=temp;
  16   1              temp=temp>>8;
  17   1              *(exAddress+1)=temp;
  18   1              ISP1581_CS=1;//xxg
  19   1      
  20   1      }
  21          
  22          void outportb(unsigned short nPort, unsigned char nVal)
  23          {
  24   1              unsigned char xdata *exAddress;
  25   1              exAddress = nPort;
  26   1              
  27   1              ISP1581_CS=0;//xxg
  28   1              *exAddress = nVal;
  29   1              ISP1581_CS=1;//xxg
  30   1      }
  31          
  32          unsigned short inport(unsigned short nPort)
  33          {
  34   1              unsigned short idata nVal;
  35   1              unsigned char idata temp;
  36   1              unsigned char xdata *exAddress;
  37   1              exAddress = nPort;
  38   1              
  39   1              ISP1581_CS=0;//xxg
  40   1              
  41   1              temp=*exAddress;
  42   1              nVal=*(exAddress+1);
  43   1              ISP1581_CS=1;//xxg
  44   1              nVal=nVal<<8;
  45   1              nVal=nVal+temp;
  46   1              return nVal;
  47   1              
  48   1      }
  49          
  50          unsigned char inportb(unsigned short nPort)
  51          {
  52   1              //unsigned short idata nVal;
  53   1              unsigned char nVal;
  54   1              unsigned char xdata *exAddress;
  55   1              exAddress = nPort;
C51 COMPILER V7.06   ISP1581                                                               09/09/2005 13:57:31 PAGE 2   

  56   1              ISP1581_CS=0;//xxg
  57   1              nVal = *exAddress;
  58   1              ISP1581_CS=1;//xxg
  59   1              return nVal;
  60   1      
  61   1      }
  62          //////////////////////////////////////////////////////////
  63          void ISP1581_ResetDevice(void)
  64          {
  65   1              unsigned char i=0,j;
  66   1      
  67   1              ISP1581_SetMode(mode_reset);
  68   1              ISP1581_SetMode(0x0);
  69   1              for(i = 0; i <15; i++)
  70   1              {
  71   2                      for(j = 0; j < 255; j++)
  72   2                      {
  73   3                      }
  74   2              
  75   2              }
  76   1              
  77   1      }
  78          void ISP1581_SendResume(void)
  79          {
  80   1              UCHAR c;
  81   1              if(bZBoardFlags.bits.At_IRQL1 == 0)
  82   1                      RaiseIRQL();
  83   1      
  84   1              ISP1581_ReadChipID();; // wake up device first;
  85   1              // need to add some delay for 3 ms to let the device get out of suspend, (crystal to be stable);
  86   1              // srcatch is used to store user information for wake up;
  87   1              ISP1581_UnlockDevice();
  88   1              c = ISP1581_GetMode();
  89   1              ISP1581_SetMode(c|mode_sndrsu);
  90   1              ISP1581_SetMode(c);
  91   1      
  92   1              if(bZBoardFlags.bits.At_IRQL1 == 0)
  93   1                      LowerIRQL();
  94   1      }
  95          
  96          void ISP1581_GoSuspend(void)
  97          {
  98   1              unsigned char c;
  99   1              c = ISP1581_GetMode();
 100   1              ISP1581_SetMode(c|mode_gosusp);
 101   1              ISP1581_SetMode(c);
 102   1              //return;
 103   1      }
 104          
 105          
 106          void ISP1581_SetEPIndex(UCHAR bEPIndex)  //OK
 107          {
 108   1              outportb(rega_epindex, bEPIndex);
 109   1      }
 110          
 111          UCHAR ISP1581_GetEndpointStatus(UCHAR bEPIndex) //OK
 112          {
 113   1              UCHAR c;
 114   1              if(bZBoardFlags.bits.At_IRQL1 == 0)
 115   1                      RaiseIRQL();
 116   1              ISP1581_SetEPIndex(bEPIndex);
 117   1              c = inportb(rega_epctlfc);
C51 COMPILER V7.06   ISP1581                                                               09/09/2005 13:57:31 PAGE 3   

 118   1      
 119   1              if(bZBoardFlags.bits.At_IRQL1 == 0)
 120   1                      LowerIRQL();
 121   1              return c;
 122   1      }
 123          
 124          void ISP1581_SetEndpointStatus(UCHAR bEPIndex, UCHAR bStalled) //OK
 125          {
 126   1              if(bZBoardFlags.bits.At_IRQL1 == 0)
 127   1                      RaiseIRQL();
 128   1      
 129   1              ISP1581_SetEPIndex(bEPIndex);
 130   1              outportb(rega_epctlfc, bStalled);
 131   1      
 132   1              if(bZBoardFlags.bits.At_IRQL1 == 0)
 133   1                      LowerIRQL();
 134   1      }
 135          void ISP1581_ControlReadHandshake(void)
 136          {
 137   1              ISP1581_SetEndpointStatus(EPINDEX4CONTROL_IN, epctlfc_status|epctlfc_stall);
 138   1      }
 139          void ISP1581_ControlWriteHandshake(void)
 140          {
 141   1              ISP1581_SetEndpointStatus(EPINDEX4CONTROL_OUT, epctlfc_status|epctlfc_stall);
 142   1      }
 143          
 144          void ISP1581_SetAddressEnable(UCHAR bAddress, UCHAR bEnable)
 145          {
 146   1              if(bZBoardFlags.bits.At_IRQL1 == 0)
 147   1                      RaiseIRQL();
 148   1      
 149   1              if(bEnable)
 150   1                      bAddress |= addren_enable;
 151   1              else
 152   1                      bAddress &= addren_addrmask;
 153   1      
 154   1              outportb(rega_addren, bAddress); // set new address enable);
 155   1      
 156   1              if(bZBoardFlags.bits.At_IRQL1 == 0)
 157   1                      LowerIRQL();
 158   1      }
 159          USHORT ISP1581_ReadControlEndpointSetup(UCHAR * buf)
 160          {
 161   1              USHORT i,c;
 162   1      
 163   1              ISP1581_SetEPIndex(EPINDEX4CONTROL_SETUP);
 164   1              c = inport(rega_dcount);
 165   1              for(i=0; i<c; i++)
 166   1              {
 167   2                      *buf = inportb(rega_dport);
 168   2                      buf ++;
 169   2              }
 170   1      
 171   1              return c;
 172   1      }
 173          
 174          USHORT ISP1581_WriteControlEndpoint(UCHAR * buf, USHORT len)
 175          {
 176   1              USHORT i;
 177   1              UCHAR  c;
 178   1      
 179   1              ISP1581_SetEPIndex(EPINDEX4EP07OUT);// work around for es4, write in endpoint corrupts out endpoint data
C51 COMPILER V7.06   ISP1581                                                               09/09/2005 13:57:31 PAGE 4   

 180   1              ISP1581_SetEPIndex(EPINDEX4CONTROL_IN);
 181   1      
 182   1              outport(rega_dcount, len);
 183   1              for(i=0;i<len;i++,buf++)
 184   1              {
 185   2                c=*buf;
 186   2                outportb(rega_dport,c);
 187   2              }
 188   1              return len;
 189   1      }
 190          
 191          USHORT ISP1581_ReadControlEndpoint(UCHAR * buf, unsigned short len)
 192          {
 193   1              USHORT i, j, RX_LEN;
 194   1              
 195   1              if(bZBoardFlags.bits.At_IRQL1 == 0)
 196   1                      RaiseIRQL();
 197   1      
 198   1              ISP1581_SetEPIndex(EPINDEX4CONTROL_OUT);
 199   1              // get pkt length
 200   1              RX_LEN = inport(rega_dcount);
 201   1      
 202   1              if(RX_LEN <= EP0_PACKET_SIZE)
 203   1              {
 204   2                      j = RX_LEN;
 205   2              }
 206   1              else
 207   1              {
 208   2                      j = EP0_PACKET_SIZE;
 209   2              }
 210   1      
 211   1              for(i=0; i< j; i++) // Maxium data length allowed.
 212   1              {
 213   2                      * buf = inportb(rega_dport);
 214   2                      buf ++;
 215   2              }
 216   1      
 217   1              for(i = j; i <RX_LEN; i++)   // strip invalid data other than setup has set
 218   1                      inportb(rega_dport);
 219   1      
 220   1              if(RX_LEN > len)
 221   1                      j = EP0_PACKET_SIZE;    // return max length informing more data received than expected.
 222   1      
 223   1              if(bZBoardFlags.bits.At_IRQL1 == 0)
 224   1                      LowerIRQL();
 225   1      
 226   1              return j;
 227   1      }
 228          USHORT ISP1581_ReadBulkEndpoint(UCHAR bEPIndex, unsigned char * buf, USHORT len)
 229          {
 230   1              USHORT i, j, c;
 231   1      
 232   1              ISP1581_SetEPIndex(bEPIndex);
 233   1              j = inport(rega_dcount);
 234   1      
 235   1              if(j<len)
 236   1                      len=j;
 237   1              for(i=0; i<len; i=i+1, buf++ )
 238   1              {
 239   2                      c = inportb(rega_dport);
 240   2                      *buf = c;
 241   2              }
C51 COMPILER V7.06   ISP1581                                                               09/09/2005 13:57:31 PAGE 5   

 242   1              for(i=len; i<j; i=i+1)
 243   1                      inportb(rega_dport);                  // data received is more than count setup got, discards the extra 
             -data.
 244   1              
 245   1              return len;
 246   1      }
 247          void ISP1581_WriteBulkEndpoint(UCHAR bEPIndex, unsigned char * buf, USHORT len)
 248          {
 249   1              USHORT  i;
 250   1      
 251   1              if(bZBoardFlags.bits.At_IRQL1 == 0)
 252   1                      RaiseIRQL();
 253   1      
 254   1              ISP1581_SetEPIndex(EPINDEX4EP07OUT);// work around for es4, write in endpoint corrupts out endpoint data
 255   1              ISP1581_SetEPIndex(bEPIndex);
 256   1                      outport(rega_dcount, len);
 257   1      
 258   1      
 259   1              for(i=0; i<len; i++, buf++ )
 260   1              {
 261   2                      outportb(rega_dport,*buf);
 262   2              }
 263   1      
 264   1              if(bZBoardFlags.bits.At_IRQL1 == 0)
 265   1                      LowerIRQL();
 266   1      }
 267          /*
 268          USHORT ISP1581_ReadISOEndpoint(UCHAR bEPIndex, unsigned short * buf, USHORT len)
 269          {
 270                  USHORT i, j;
 271          
 272                  ISP1581_SetEPIndex(bEPIndex);
 273                  //outport(aport, rega_dcount);
 274                  j = inport(rega_dcount);
 275                  if(j<len)
 276                          len=j;
 277                  for(i=0; i<len; i=i++, buf++ )
 278                  {
 279                          *buf = inportb(rega_dport);
 280                  }
 281                  
 282                  for(i=len; i<j; i=i+1)
 283                          inportb(rega_dport);                  // data received is more than count setup got, discards the extra 
             -data.
 284          
 285                  return len;
 286          }
 287          */
 288          /*void ISP1581_WriteISOEndpoint(UCHAR bEPIndex, unsigned short * buf, USHORT len)
 289          {
 290                  USHORT  i;
 291          
 292                  if(bZBoardFlags.bits.At_IRQL1 == 0)
 293                          RaiseIRQL();
 294          
 295                  ISP1581_SetEPIndex(EPINDEX4EP07OUT);// work around for es4, write in endpoint corrupts out endpoint data
 296                  ISP1581_SetEPIndex(bEPIndex);
 297          
 298                  if (len < 256)
 299                  {
 300                          outport(rega_dcount, len);
 301                  }
C51 COMPILER V7.06   ISP1581                                                               09/09/2005 13:57:31 PAGE 6   

 302          
 303                  for(i=0; i<len; i ++, buf++ )
 304                  {
 305                          outportb(rega_dport,*buf);
 306                  }
 307          
 308                  if(bZBoardFlags.bits.At_IRQL1 == 0)
 309                          LowerIRQL();
 310          }
 311          
 312          */
 313          void ISP1581_StallEP0InControlWrite(void)
 314          {
 315   1              ISP1581_SetEndpointStatus(EPINDEX4CONTROL_IN, epctlfc_stall);
 316   1              ISP1581_SetEndpointStatus(EPINDEX4CONTROL_OUT, epctlfc_stall);
 317   1      }
 318          
 319          void ISP1581_StallEP0InControlRead(void)
 320          {
 321   1              ISP1581_SetEndpointStatus(EPINDEX4CONTROL_OUT, epctlfc_stall);
 322   1              ISP1581_SetEndpointStatus(EPINDEX4CONTROL_IN, epctlfc_stall);
 323   1      }
 324          

⌨️ 快捷键说明

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