亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频

? 歡迎來到蟲蟲下載站! | ?? 資源下載 ?? 資源專輯 ?? 關于我們
? 蟲蟲下載站

?? usb in a nutshell - chapter 7 - pdiusbd11 and pic16f87x example.htm

?? altra下載線資料。max7000系列
?? HTM
?? 第 1 頁 / 共 4 頁
字號:
          the char array is fixed in the header and is not dynamic. </P><PRE>#define MAX_BUFFER_SIZE 80

bank1 unsigned char circularbuffer[MAX_BUFFER_SIZE];
unsigned char inpointer;
unsigned char outpointer;

unsigned char *pSendBuffer;
unsigned char BytesToSend;
unsigned char CtlTransferInProgress;
unsigned char DeviceAddress;
unsigned char DeviceConfigured;

#define PROGRESS_IDLE             0
#define PROGRESS_ADDRESS          3

void main (void)
{
    TRISB = 0x03;   /* Int &amp; Suspend Inputs */
    RB3 = 1;        /* Device Not Configured (LED) */
    RB2 = 0;        /* Reset PDIUSBD11 */

    InitUART();
    printf("Initialising\n\r");
    I2C_Init(); 

    RB2 = 1;        /* Bring PDIUSBD11 out of reset */

    ADCON1 = 0x80;  /* ADC Control - All 8 Channels Enabled, */
                    /* supporting upgrade to 16F877 */

    USB_Init();
    printf("PDIUSBD11 Ready for connection\n\r");
    while(1) 
	if (!RB0) D11GetIRQ(); /* If IRQ is Low, PDIUSBD11 has an Interrupt Condition */
}    
</PRE>
          <P>The main function is example dependent. It's responsible for 
          initialising the direction of the I/O Ports, initialising the I2C 
          interface, Analog to Digital Converters and PDIUSBD11. Once everything 
          is configured it keeps calling D11GetIRQ which processes PDIUSBD11 
          Interrupt Requests. </P><PRE>void USB_Init(void)
{
    unsigned char Buffer[2];

    /* Disable Hub Function in PDIUSBD11 */
    Buffer[0] = 0x00;
    D11CmdDataWrite(D11_SET_HUB_ADDRESS, Buffer, 1);

    /* Set Address to zero (default) and enable function */
    Buffer[0] = 0x80;
    D11CmdDataWrite(D11_SET_ADDRESS_ENABLE, Buffer, 1);

    /* Enable function generic endpoints */
    Buffer[0] = 0x02;
    D11CmdDataWrite(D11_SET_ENDPOINT_ENABLE, Buffer, 1);

    /* Set Mode - Enable SoftConnect */
    Buffer[0] = 0x97; /* Embedded Function, SoftConnect, Clk Run, No LazyClk, Remote Wakeup */
    Buffer[1] = 0x0B; /* CLKOut = 4MHz */
    D11CmdDataWrite(D11_SET_MODE, Buffer, 2);
}
</PRE>
          <P>The USB Init function initialises the PDIUSBD11. This 
          initialisation procedure has been omitted from the Philips PDIUSBD11 
          datasheet but is available from their <A 
          href="http://www.semiconductors.philips.com/buses/usb/products/device/pdiusbd11/faq/index.html">FAQ</A>. 
          The last command enables the soft-connect pull up resistor on D+ 
          indicating it is a <A 
          href="http://www.beyondlogic.org/usbnutshell/usb2.htm#SpeedIdentification">full 
          speed</A> device but also advertises its presence on the universal 
          serial bus. </P><PRE>void D11GetIRQ(void)
{
        unsigned short Irq;
        unsigned char Buffer[1];

        /* Read Interrupt Register to determine source of interrupt */

        D11CmdDataRead(D11_READ_INTERRUPT_REGISTER, (unsigned char *)&amp;Irq, 2);

        if (Irq) printf("Irq = 0x%X: ",Irq);
</PRE>
          <P>Main() keeps calling the D11GetIRQ in a loop. This function reads 
          the PDIUSBD11's Interrupt Register to establish if any interrupts are 
          pending. If this is the case it will act upon them, otherwise it will 
          continue to loop. Other USB devices may have a series of interrupt 
          vectors assigned to each endpoint. In this case each ISR will service 
          the appropriate interrupt removing the if statements. </P><PRE>        if (Irq &amp; D11_INT_BUS_RESET) {
            printf("Bus Reset\n\r");
            USB_Init();
        }

        if (Irq &amp; D11_INT_EP0_OUT) {
            printf("EP0_Out: ");
            Process_EP0_OUT_Interrupt();
        }

        if (Irq &amp; D11_INT_EP0_IN) {
            printf("EP0_In: \n\r");
            if (CtlTransferInProgress == PROGRESS_ADDRESS) {
                D11CmdDataWrite(D11_SET_ADDRESS_ENABLE,&amp;DeviceAddress,1);
                D11CmdDataRead(D11_READ_LAST_TRANSACTION + D11_ENDPOINT_EP0_IN, Buffer, 1);
                CtlTransferInProgress = PROGRESS_IDLE;
                }
        else {
                D11CmdDataRead(D11_READ_LAST_TRANSACTION + D11_ENDPOINT_EP0_IN, Buffer, 1);
                WriteBufferToEndPoint();
                }
        }
</PRE>
          <P>The If statements work down in order of priority. The highest 
          priority interrupt is the bus reset. This simply calls USB_Init which 
          re-initialises the USB function. The next highest priority is the 
          default pipe consisting of EP0 OUT and EP1 IN. This is where all the 
          enumeration and control requests are sent. We branch to another 
          function to handle the EP0_OUT requests. </P>
          <P>When a request is made by the host and it wants to receive data, 
          the PIC16F876 will send the PDIUSBD11 a 8 byte packet. As the USbus is 
          host controlled it cannot write the data when ever it desires, so the 
          PDIUSBD11 buffers the data and waits for an IN Token to be sent from 
          the host. When the PDIUSBD11 receives the IN Token it generates an 
          interrupt. This makes a good time to reload the next packet of data to 
          send. This is done by an additional function WriteBufferToEndpoint(); 
          </P>
          <P>The section under CtlTransferInProgress == PROGRESS_ADDRESS handles 
          the setting of the device's address. We detail this later. </P><PRE>        if (Irq &amp; D11_INT_EP1_OUT) {
            printf("EP1_OUT\n\r");
            D11CmdDataRead(D11_READ_LAST_TRANSACTION + D11_ENDPOINT_EP1_OUT, Buffer, 1);
            bytes = D11ReadEndpoint(D11_ENDPOINT_EP1_OUT, Buffer);
            for (count = 0; count &lt; bytes; count++) {
               circularbuffer[inpointer++] = Buffer[count];
               if (inpointer &gt;= MAX_BUFFER_SIZE) inpointer = 0;
              }
            loadfromcircularbuffer(); //Kick Start
        }
     
        if (Irq &amp; D11_INT_EP1_IN) {
            printf("EP1_IN\n\r");
            D11CmdDataRead(D11_READ_LAST_TRANSACTION + D11_ENDPOINT_EP1_IN, Buffer, 1);
            loadfromcircularbuffer();
        }
</PRE>
          <P>EP1 OUT and EP1 IN are implemented to read and write bulk data to 
          or from a circular buffer. This setup allows the code to be used in 
          conjunction with the BulkUSB example in the Windows DDK's. The 
          circular buffer is defined earlier in the code as being 80 bytes long 
          taking up all of bank1 of the PIC16F876's RAM. </P><PRE>        if (Irq &amp; D11_INT_EP2_OUT) {
            printf("EP2_OUT\n\r");
            D11CmdDataRead(D11_READ_LAST_TRANSACTION + D11_ENDPOINT_EP2_OUT, Buffer, 1);
            Buffer[0] = 0x01; /* Stall Endpoint */
            D11CmdDataWrite(D11_SET_ENDPOINT_STATUS + D11_ENDPOINT_EP2_OUT, Buffer, 1); 
        }

        if (Irq &amp; D11_INT_EP2_IN) {
            printf("EP2_IN\n\r");
            D11CmdDataRead(D11_READ_LAST_TRANSACTION + D11_ENDPOINT_EP2_IN, Buffer, 1);
            Buffer[0] = 0x01; /* Stall Endpoint */
            D11CmdDataWrite(D11_SET_ENDPOINT_STATUS + D11_ENDPOINT_EP2_IN, Buffer, 1); 
        }

        if (Irq &amp; D11_INT_EP3_OUT) {
            printf("EP3_OUT\n\r");
            D11CmdDataRead(D11_READ_LAST_TRANSACTION + D11_ENDPOINT_EP3_OUT, Buffer, 1);
            Buffer[0] = 0x01; /* Stall Endpoint */
            D11CmdDataWrite(D11_SET_ENDPOINT_STATUS + D11_ENDPOINT_EP3_OUT, Buffer, 1); 
        }

        if (Irq &amp; D11_INT_EP3_IN) {
            printf("EP3_IN\n\r");
            D11CmdDataRead(D11_READ_LAST_TRANSACTION + D11_ENDPOINT_EP3_IN, Buffer, 1);
            Buffer[0] = 0x01; /* Stall Endpoint */
            D11CmdDataWrite(D11_SET_ENDPOINT_STATUS + D11_ENDPOINT_EP3_IN, Buffer, 1); 
        }
 
}
</PRE>
          <P>Endpoints two and three are not used at the moment, so we stall 
          them if any data is received. The PDIUSBD11 has a Set Endpoint Enable 
          Command which can be used to enable or disable function generic 
          endpoints (any endpoints other than the default control pipe). We 
          could use this command to diable the generic endpoints, if we were 
          planning on not using these later. However at the moment this code 
          provides a foundation to build upon. </P><PRE>void Process_EP0_OUT_Interrupt(void)
{
    unsigned long a;
    unsigned char Buffer[2];
    USB_SETUP_REQUEST SetupPacket;

    /* Check if packet received is Setup or Data - Also clears IRQ */
    D11CmdDataRead(D11_READ_LAST_TRANSACTION + D11_ENDPOINT_EP0_OUT, &amp;SetupPacket, 1);

    if (SetupPacket.bmRequestType &amp; D11_LAST_TRAN_SETUP) {
</PRE>
          <P>The first thing we must do is determine is the packet we have 
          received on EP0 Out is a data packet or a <A 
          href="http://www.beyondlogic.org/usbnutshell/usb6.htm#SetupPacket">Setup 
          Packet</A>. A Setup Packet contains a request such as Get Descriptor 
          where as a data packet contains data for a previous request. We are 
          lucky that most requests do not send data packets from the host to the 
          device. A request that does is SET_DESCRIPTOR but is rarely 
          implemented. </P><PRE>        /* This is a setup Packet - Read Packet */
        D11ReadEndpoint(D11_ENDPOINT_EP0_OUT, &amp;SetupPacket);

        /* Acknowlegde Setup Packet to EP0_OUT &amp; Clear Buffer*/
        D11CmdDataWrite(D11_ACK_SETUP, NULL, 0);
        D11CmdDataWrite(D11_CLEAR_BUFFER, NULL, 0);

        /* Acknowlegde Setup Packet to EP0_IN */
        D11CmdDataWrite(D11_ENDPOINT_EP0_IN, NULL, 0);
        D11CmdDataWrite(D11_ACK_SETUP, NULL, 0);

        /* Parse bmRequestType */
        switch (SetupPacket.bmRequestType &amp; 0x7F) {
</PRE>
          <P>As we have seen in our description of <A 
          href="http://www.beyondlogic.org/usbnutshell/usb4.htm#Control">Control 
          Transfers</A>, a setup packet cannot be NAKed or STALLed. When the 
          PDIUSBD11 receives a Setup Packet it flushes the EP0 IN buffer and 
          disables the Validate Buffer and Clear Buffer commands. This ensures 
          the setup packet is acknowledged by the microcontroller by sending an 
          Acknowledge Setup command to both EP0 IN and EP0 OUT before a Validate 
          or Clear Buffer command is effective. The recept of a setup packet 
          will also un-stall a STALLed control endpoint. </P>
          <P>Once the packet has been read into memory and the setup packet 
          acknowledged, we being the parse the request starting with the request 
          type. At the moment we are not interesting in the direction, so we AND 
          off this bit. The three requests all devices must process is the 
          Standard Device Request, Standard Interface Request and Standard 
          Endpoint Requests. We provide our functionality (Read Analog Inputs) 
          by the Vendor Request, so we add a case statement for Standard Vendor 
          Requests. If your device supports a USB Class Specification, then you 
          may also need to add cases for Class Device Request, Class Interface 
          Request and/or Class Endpoint Request. </P><PRE>            case STANDARD_DEVICE_REQUEST:
                printf("Standard Device Request ");
                switch (SetupPacket.bRequest) {
                    case GET_STATUS:
                        /* Get Status Request to Device should return */
                        /* Remote Wakeup and Self Powered Status */
                        Buffer[0] = 0x01;
                        Buffer[1] = 0x00;
                        D11WriteEndpoint(D11_ENDPOINT_EP0_IN, Buffer, 2);
                        break;

                    case CLEAR_FEATURE:
                    case SET_FEATURE:
                        /* We don't support DEVICE_REMOTE_WAKEUP or TEST_MODE */
                        ErrorStallControlEndPoint();
                        break;
</PRE>
          <P>The Get Status request is used to report the status of the device 
          in terms of if the device is bus or self powered and if it supports 
          remote wakeup. In our device we report it as self powered and as not 
          supporting remote wakeup. </P>
          <P>Of the Device Feature requests, this device doesn't support 
          DEVICE_REMOTE_WAKEUP nor TEST_MODE and return a USB Request Error as a 
          result. </P><PRE>                    case SET_ADDRESS:
                        printf("Set Address\n\r");
                        DeviceAddress = SetupPacket.wValue | 0x80;
                        D11WriteEndpoint(D11_ENDPOINT_EP0_IN, NULL, 0);
                        CtlTransferInProgress = PROGRESS_ADDRESS;
                        break;
</PRE>
          <P>The Set Address command is the only command that continues to be 
          processed after the status stage. All other commands must finish 
          processing before the status stage. The device address is read and 
          OR'ed with 0x80 and stored in a variable DeviceAddress. The OR'ing 
          with 0x80 is specific to the PDIUSBD11 with the most significant bit 
          indicating if the device is enabled or not. A zero length packet is 
          returned as status to the host indicating the command is complete. 
          However the host must send an IN Token, retrieve the zero length 

?? 快捷鍵說明

復制代碼 Ctrl + C
搜索代碼 Ctrl + F
全屏模式 F11
切換主題 Ctrl + Shift + D
顯示快捷鍵 ?
增大字號 Ctrl + =
減小字號 Ctrl + -
亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频
理论电影国产精品| 夜夜精品视频一区二区| 极品美女销魂一区二区三区| 欧美一二三区在线| 精久久久久久久久久久| 久久在线免费观看| 97se亚洲国产综合在线| 一区二区三区产品免费精品久久75| 色哟哟一区二区在线观看| 亚洲午夜在线视频| 日韩免费性生活视频播放| 国产精品一级黄| 亚洲与欧洲av电影| 欧美电影免费观看高清完整版在| 国产美女精品在线| 亚洲裸体xxx| 日韩欧美激情一区| 菠萝蜜视频在线观看一区| 夜夜亚洲天天久久| 精品va天堂亚洲国产| 不卡一区二区三区四区| 亚洲成a人片在线观看中文| 精品乱人伦一区二区三区| 成人精品电影在线观看| 日韩福利电影在线观看| 久久精品视频在线免费观看 | 麻豆精品一二三| 国产精品视频你懂的| 欧美精品 国产精品| 国产99久久精品| 日韩国产一区二| 亚洲第一狼人社区| 精品国产91亚洲一区二区三区婷婷 | 亚洲精品高清视频在线观看| 日韩视频一区在线观看| 99精品热视频| 精久久久久久久久久久| 亚洲国产精品久久艾草纯爱| 国产亚洲欧洲997久久综合 | 久久超碰97中文字幕| 亚洲人成伊人成综合网小说| 久久综合一区二区| 91精品国产欧美一区二区成人| kk眼镜猥琐国模调教系列一区二区| 日本不卡在线视频| 亚洲一区二区三区国产| 国产精品女上位| 日韩一区二区三区在线观看| 欧美在线高清视频| 99精品久久99久久久久| 国产成人精品亚洲午夜麻豆| 久久精品免费看| 亚洲成在人线免费| 一区二区三区四区亚洲| 亚洲国产电影在线观看| 久久午夜免费电影| 日韩三级视频中文字幕| 欧美亚洲日本一区| 色综合久久天天| 成人夜色视频网站在线观看| 激情小说亚洲一区| 日韩avvvv在线播放| 日韩中文字幕麻豆| 亚洲午夜久久久| 亚洲在线视频网站| 亚洲精品久久嫩草网站秘色| 中文字幕一区免费在线观看| 中文字幕免费不卡| 国产欧美日韩激情| 一区二区三区电影在线播| 国产精品久久精品日日| 国产欧美一区二区精品性色超碰| 26uuu亚洲综合色欧美| 91精品久久久久久蜜臀| 91精品在线麻豆| 欧美一区二区免费观在线| 91精品综合久久久久久| 日韩限制级电影在线观看| 欧美理论电影在线| 日韩一区二区三区四区五区六区| 欧美福利视频导航| 日韩一区二区在线免费观看| 欧美一二区视频| 精品对白一区国产伦| 国产欧美一区二区三区沐欲| 国产精品沙发午睡系列990531| 国产精品久久夜| 亚洲乱码国产乱码精品精小说 | 亚洲精品视频在线看| 一区二区三区精品| 日韩精品一区第一页| 久久国产福利国产秒拍| 国产不卡高清在线观看视频| 成人亚洲精品久久久久软件| 99久久久精品| 欧美日韩1区2区| 精品成人私密视频| 国产精品久久久久久久午夜片| 一区二区三区在线不卡| 丝袜美腿亚洲综合| 国产精品99久| 在线观看国产日韩| 日韩欧美一区二区三区在线| 久久天天做天天爱综合色| 中文字幕日韩一区| 亚洲国产日韩一级| 国产一区二区三区美女| 成人av资源在线观看| 欧美日韩国产片| 精品av综合导航| 亚洲精品国产无套在线观| 秋霞午夜鲁丝一区二区老狼| 成人性视频免费网站| 欧美久久久一区| 国产精品女上位| 国产成人av在线影院| 91麻豆免费在线观看| 欧美一区二区视频在线观看2020 | 97精品国产露脸对白| 欧美日韩免费一区二区三区视频| 久久久久久免费毛片精品| 亚洲精品视频在线观看网站| 国产在线精品国自产拍免费| 色婷婷狠狠综合| 国产女主播在线一区二区| 婷婷一区二区三区| 91免费小视频| 欧美精品一区二区在线观看| 一区二区三区精品视频| 国产99久久久国产精品潘金| 日韩一区二区在线观看视频播放| 成人免费在线视频| 国产精品一区二区不卡| 日韩一区二区三区电影在线观看| 亚洲日本在线观看| 福利一区福利二区| 精品久久五月天| 午夜精品成人在线| 91九色02白丝porn| 亚洲欧洲一区二区三区| 国产精品一区二区视频| 日韩一区二区三区免费观看| 午夜激情久久久| 91亚洲男人天堂| 日本一区二区免费在线| 国产中文字幕一区| 欧美成va人片在线观看| 日韩成人午夜电影| 精品视频资源站| 亚洲永久精品大片| 在线欧美小视频| 亚洲精品视频在线| 色婷婷国产精品综合在线观看| 亚洲国产高清在线| 成人性生交大片免费看中文网站| xf在线a精品一区二区视频网站| 亚洲sss视频在线视频| 欧美无乱码久久久免费午夜一区| 国产精品成人免费| 99久久国产综合精品女不卡 | 国产精品久久久久久亚洲伦| 国产成人在线视频网站| 国产欧美一区二区三区鸳鸯浴 | 国产精品久久精品日日| 成人免费看片app下载| 中文一区在线播放| 不卡视频免费播放| 亚洲品质自拍视频网站| 91久久免费观看| 亚洲激情图片小说视频| 欧美在线不卡一区| 日韩激情在线观看| 欧美白人最猛性xxxxx69交| 国产一区二区三区四 | 中文字幕中文在线不卡住| va亚洲va日韩不卡在线观看| 亚洲视频电影在线| 欧美色网一区二区| 美女视频黄 久久| 久久老女人爱爱| 97国产精品videossex| 亚洲国产精品综合小说图片区| 3751色影院一区二区三区| 蜜桃视频第一区免费观看| 国产亚洲欧洲997久久综合| 91在线视频免费观看| 亚洲国产美女搞黄色| 欧美videos大乳护士334| 高清不卡在线观看| 亚洲午夜久久久久| 精品剧情在线观看| 91小视频免费观看| 午夜免费欧美电影| 国产性色一区二区| 欧洲一区二区三区免费视频| 六月丁香婷婷色狠狠久久| 亚洲国产成人私人影院tom| 欧美日韩一区在线| 国产九色精品成人porny| 日本三级亚洲精品|