<meter id="pryje"><nav id="pryje"><delect id="pryje"></delect></nav></meter>
          <label id="pryje"></label>

          新聞中心

          2440下的USB實(shí)驗(yàn)

          作者: 時(shí)間:2016-11-25 來源:網(wǎng)絡(luò) 收藏
          static void __irq IsrUsbd(void)

          {
          U8 usbdIntpnd, epIntpnd;
          U8 saveIndexReg = rINDEX_REG; //保存索引寄存器值(現(xiàn)場(chǎng)保護(hù))
          usbdIntpnd = rUSB_INT_REG;//保存中斷標(biāo)志寄存器
          epIntpnd = rEP_INT_REG;

          本文引用地址:http://www.ex-cimer.com/article/201611/321179.htm


          if(usbdIntpnd&SUSPEND_INT)//總線上超過 3ms 沒有活動(dòng)信號(hào)引起中斷
          {
          rUSB_INT_REG = SUSPEND_INT;//清除中斷標(biāo)志位
          }

          if(usbdIntpnd&RESUME_INT)
          {
          rUSB_INT_REG = RESUME_INT; //恢復(fù)引起的中斷
          }

          if(usbdIntpnd&RESET_INT)//接收到復(fù)位信號(hào)引起的中斷
          {
          //ResetUsbd();
          ReconfigUsbd();//重新配置 USB device
          rUSB_INT_REG = RESET_INT; //RESET_INT should be cleared after ResetUsbd().
          PrepareEp1Fifo();
          }


          if(epIntpnd&EP0_INT)//端點(diǎn) 0 中斷
          {
          rEP_INT_REG = EP0_INT;
          Ep0Handler();//進(jìn)入控制傳輸中斷處理程序
          }

          if(epIntpnd&EP1_INT)
          {
          rEP_INT_REG=EP1_INT;
          Ep1Handler();//進(jìn)入 Ep1 中斷處理程序(BULK IN)
          }


          if(epIntpnd&EP2_INT)
          {
          rEP_INT_REG = EP2_INT;
          //Ep2Handler();
          }


          if(epIntpnd&EP3_INT)
          {
          rEP_INT_REG = EP3_INT;
          Ep3Handler();//進(jìn)入 Ep3 中斷處理程序(BULK OUT)
          }


          if(epIntpnd&EP4_INT)
          {
          rEP_INT_REG = EP4_INT;
          //Ep4Handler();
          }


          ClearPending(BIT_USBD);//USB 設(shè)備中斷處理完畢,清除中斷標(biāo)志位
          rINDEX_REG = saveIndexReg;//恢復(fù)索引寄存器原來的值(恢復(fù)現(xiàn)場(chǎng))
          }


          6.2 端點(diǎn) 1 的數(shù)據(jù)傳輸程序


          void Ep1Handler(void)

          {
          U8 in_csr1;


          rINDEX_REG = 1;

          in_csr1 = rIN_CSR1_REG;


          //I think that EPI_SENT_STALL will not be set to 1.
          if(in_csr1 & EPI_SENT_STALL) //USB 已經(jīng)發(fā)布了一個(gè) STALL 握手信號(hào),由此引起該中斷

          {
          CLR_EP1_SENT_STALL();//清除 SENT_STALL 位,STALL 狀態(tài)結(jié)束

          return;

          }


          //IN_PKT_READY is cleared


          //The data transfered was ep1Buf[] which was already configured transferIndex++;
          if(UsbState==0x01234567)
          PrepareEp1Fifo();//準(zhǔn)備好發(fā)送的數(shù)據(jù),把 IN_PKT_READY 置位

          //IN_PKT_READY is set

          //This packit will be used for next IN packit.

          return;

          }

          6.3 USB Device 初始化函數(shù)


          void UsbdInit(U8 fun)

          {

          isUsbdSetConfiguration = 0;

          //MDIV=40,PDIV=4,SDIV=1

          //Upll = (m * Fin) / (p * 2**s)

          //m = (MDIV + 8), p = (PDIV + 2), s = SDIV

          //Upll=48MHz

          rUPLLCON = (40<<12) | (4<<4) | 1;
          //初始化描述符 InitDescriptorTable(fun); ReconfigUsbd();


          UsbState = 0;
          }


          6.4 USB 下載函數(shù)

          static int BoardUsbDownload(U32 addr, U32 run)

          {

          U8 fun;

          int len;


          //GPH9-->output GPH10-->output

          rGPHCON = rGPHCON&~(0xf<<18)|(0x5<<18);

          //GPG9-->input

          rGPGCON &= 0xfff3ffff;

          fun = 1;
          //USB Device 初始化 UsbdInit(fun); Delay(100);
          //GPG9-->output rGPGCON |= 0x00040000;
          //GPG9 ouput 1
          rGPGDAT |= 0x0200;


          //中斷服務(wù)程序
          pISR_USBD =(unsigned)IsrUsbd; ClearPending(BIT_USBD); EnableIrq(BIT_USBD);
          len = WaitDownload(addr); DisableIrq(BIT_USBD);
          rGPGCON &= 0xfff3ffff;//GPG9 input


          if(len>0) {

          Uart_Printf("nUSB download finished,press any key to exitn");

          }


          return len;

          }



          關(guān)鍵詞: 2440USB實(shí)

          評(píng)論


          技術(shù)專區(qū)

          關(guān)閉
          看屁屁www成人影院,亚洲人妻成人图片,亚洲精品成人午夜在线,日韩在线 欧美成人 (function(){ var bp = document.createElement('script'); var curProtocol = window.location.protocol.split(':')[0]; if (curProtocol === 'https') { bp.src = 'https://zz.bdstatic.com/linksubmit/push.js'; } else { bp.src = 'http://push.zhanzhang.baidu.com/push.js'; } var s = document.getElementsByTagName("script")[0]; s.parentNode.insertBefore(bp, s); })();