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

📄 sl811s.lst

📁 keyword:usb host sl8
💻 LST
📖 第 1 页 / 共 5 页
字号:
 140          //*****************************************************************************************
 141          // Buffer Read from SL811H
 142          // addr = buffer start address
 143          // s    = return buffer address where data are to be save/read
 144          // c    = buffer data length
 145          //*****************************************************************************************
 146          void SL811BufRead(BYTE addr, BYTE *s, BYTE c)
 147          {       
 148   1              SL811H_ADDR = addr;     
 149   1              while (c--) 
 150   1                      *s++ = SL811H_DATA;
 151   1      }
 152          
 153          //*****************************************************************************************
 154          // Buffer Write  to SL811H
 155          // addr = buffer start address
 156          // s    = buffer address where data are to be written
 157          // c    = buffer data length
 158          //*****************************************************************************************
 159          void SL811BufWrite(BYTE addr, BYTE *s, BYTE c)
 160          {       
 161   1              SL811H_ADDR = addr;     
 162   1              while (c--) 
 163   1                      SL811H_DATA = *s++;
 164   1      }
 165          
 166          //*****************************************************************************************
 167          // Swap high and low byte 
 168          //*****************************************************************************************
 169          WORD WordSwap(WORD input)
 170          {
 171   1              return(((input&0x00FF)<<8)|((input&0xFF00)>>8));
 172   1      }
 173          
 174          //*****************************************************************************************
 175          // Audio Control Key Scanning Routine 
 176          //*****************************************************************************************
 177          void audio_key_scan(void)
 178          {
 179   1              Audio_Keys = (~PINSC) & AUDIO_KEYS;                             // Mute/Vol Up/Vol Down Keys
C51 COMPILER V7.09   SL811S                                                                10/04/2004 17:01:23 PAGE 4   

 180   1              if(Audio_Keys != Prev_Audio_Keys)                               // Detect for any changes
 181   1              {
 182   2                      SL811Write(EP1A_Slave_Buf,Audio_Keys);          // send bitmap back to host
 183   2                      EP1A_IN_Arm(EP1A_Slave_Buf,2,ep1_toggle);       // Arm Ep1 and toggle data
 184   2              }
 185   1              Prev_Audio_Keys = Audio_Keys;                                   // update previous key states
 186   1      }
 187          
 188          //*****************************************************************************************
 189          // Internet Control Key Scanning Routine
 190          //*****************************************************************************************
 191          void internet_key_scan(void)
 192          {
 193   1              return;
 194   1      }
 195          
 196          //*****************************************************************************************
 197          // EP1 interrupt service routine 
 198          //*****************************************************************************************
 199          int ep1_isr(void)
 200          {
 201   1              SL811Write(IntStatus,EP1_DONE);                                 // clear EP1 interrupt  
 202   1              if(SL811Read(EP1AStatus) & EP_ACK)                              // check for ACK bit set
 203   1                      ep1_toggle = (((SL811Read(EP1AControl)&DATAX)==0) ? 1:0);                       
 204   1                                                                                                              // toggle DATA sequence         
 205   1              return;
 206   1      }
 207          
 208          //*****************************************************************************************
 209          // EP1's IN Token Arming (using Set A)
 210          //*****************************************************************************************
 211          void EP1A_IN_Arm(BYTE buf_adr, BYTE len, BYTE seq)
 212          {                                                                                               
 213   1          SL811Write(EP1AAddress,buf_adr);                            // ep1 address buffer start adress
 214   1              SL811Write(EP1AXferLen,len);                                    // max length of transfer allowed
 215   1              if(seq)
 216   1                  SL811Write(EP1AControl,DATA1_IN);                   // armed to transmit to host, DATA1
 217   1              else
 218   1                  SL811Write(EP1AControl,DATA0_IN);                   // armed to transmit to host, DATA0
 219   1      }
 220          
 221          //*****************************************************************************************
 222          // SOF interrupt service routine (act as 1ms timer)
 223          //*****************************************************************************************
 224          int sof_isr(void)
 225          {
 226   1              SL811Write(IntStatus,SOF_DONE);                                 // clear SOF interrupt          
 227   1              sof_cnt++;                                                                              // track msec timing
 228   1      
 229   1              if(sof_cnt==TIME_OUT)                                                   // reset counter on specify 
 230   1              {                                                                                               // time out.                            
 231   2                      sof_cnt = 0;                                                            
 232   2                      timeout = 1;                                                            // set timeout flag
 233   2              }
 234   1      
 235   1              return;
 236   1      }
 237          
 238          //*****************************************************************************************
 239          // EP0 interrupt service routine
 240          //*****************************************************************************************
 241          int ep0_isr(void)
C51 COMPILER V7.09   SL811S                                                                10/04/2004 17:01:23 PAGE 5   

 242          {
 243   1              BYTE    status, byte_rx, len_xfr;
 244   1              BYTE    data_seq, req_type;
 245   1      
 246   1              SL811Write(IntStatus,EP0_DONE);                                                         // clear EP0 interrupt  
 247   1              status  = SL811Read(EP0AStatus);                                                        // get packet status
 248   1              byte_rx = SL811Read(EP0AXferLen) - SL811Read(EP0ACounter);      // get no. of bytes received
 249   1                                                                                                                                      // for OUT data from host
 250   1              //----------------------------------------------------------------------------------------
 251   1              // ACK received 
 252   1              //----------------------------------------------------------------------------------------
 253   1              if(status & EP_ACK)
 254   1              {
 255   2                      //----------------------------------------------------------------
 256   2                      // Set newly assigned USB address
 257   2                      //----------------------------------------------------------------
 258   2                      if(Slave_USBaddr)                                                               
 259   2                      {                                                                                                               // if new USB address was assigned, 
 260   3                          SL811Write(USBAddress,Slave_USBaddr);                               // communicate all USB transaction      
 261   3                              Slave_USBaddr = 0;                                                                      // using this new address.                              
 262   3                      }
 263   2      
 264   2                      //================================================================
 265   2                      // SETUP's ACKed
 266   2                      //================================================================
 267   2                      if(status & EP_SETUP)                                   
 268   2                      {
 269   3                      SL811BufRead(EP0A_Slave_Buf, (BYTE*)&dReq, byte_rx);            // capture SETUP data request
 270   3                              len_req = WordSwap(dReq.wLength);                                                       // len_req = actual requested length
 271   3                              in_buffer_idx = 0;                                                                                      // reset buffer locatio indexing
 272   3                              IN_NULL = FALSE;                                                                                        // these are for IN-NULL packet
 273   3                              IN_EXACT = FALSE;                                                                                       // transfer condition
 274   3                              req_type = (dReq.bmRequest&0x60)>>5;                                            // decode for Std,Class,Vendor type
 275   3      
 276   3                          switch (req_type)                                                                                   // Parse bmRequest Type
 277   3                              {
 278   4                                      //---------------------------------------------------------------------
 279   4                                      // Standard USB Requests
 280   4                                      //---------------------------------------------------------------------
 281   4                                      case STD_REQUEST:
 282   4                                          switch (dReq.bRequest)                                                              // Parse bRequest
 283   4                                      {
 284   5                                              case GET_DESCRIPTOR:
 285   5                                                      switch ((BYTE)dReq.wValue)                              // Parse wValue
 286   5                                              {         
 287   6                                                              case DEVICE:

⌨️ 快捷键说明

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