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

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

?? usbd_otghs.c

?? useful when developer using ARM7 to interface HID devices like USB Keyboard
?? C
?? 第 1 頁 / 共 4 頁
字號:
/* ----------------------------------------------------------------------------
 *         ATMEL Microcontroller Software Support 
 * ----------------------------------------------------------------------------
 * Copyright (c) 2008, Atmel Corporation
 *
 * All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions are met:
 *
 * - Redistributions of source code must retain the above copyright notice,
 * this list of conditions and the disclaimer below.
 *
 * Atmel's name may not be used to endorse or promote products derived from
 * this software without specific prior written permission.
 *
 * DISCLAIMER: THIS SOFTWARE IS PROVIDED BY ATMEL "AS IS" AND ANY EXPRESS OR
 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT ARE
 * DISCLAIMED. IN NO EVENT SHALL ATMEL BE LIABLE FOR ANY DIRECT, INDIRECT,
 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
 * OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
 * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
 * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 * ----------------------------------------------------------------------------
 */

/*!
    Functions for OTGHS peripheral usage.
*/
 
//------------------------------------------------------------------------------
//      Headers
//------------------------------------------------------------------------------

#include <board.h>

#ifdef CHIP_OTGHS

#include "common.h"
#include "trace.h"
#include "usb.h"

//------------------------------------------------------------------------------
//         Definitions
//------------------------------------------------------------------------------

#define NUM_IT_MAX       (AT91C_BASE_OTGHS->OTGHS_IPFEATURES & AT91C_OTGHS_EPT_NBR_MAX)
#define NUM_IT_MAX_DMA   ((AT91C_BASE_OTGHS->OTGHS_IPFEATURES & AT91C_OTGHS_DMA_CHANNEL_NBR)>>4)

#define SHIFT_DMA         24
#define SHIFT_INTERUPT    12

#define DMA

//------------------------------------------------------------------------------
//      Structures
//------------------------------------------------------------------------------

// \brief  Endpoint states
typedef enum {

    endpointStateDisabled,
    endpointStateIdle,
    endpointStateWrite,
    endpointStateRead,
    endpointStateHalted

} EndpointState_t;

//------------------------------------------------------------------------------
//      Macros
//------------------------------------------------------------------------------

//------------------------------------------------------------------------------
//      Internal Functions
//------------------------------------------------------------------------------
//------------------------------------------------------------------------------
// \brief  Returns a pointer to the OTGHS controller interface used by an USB
//         driver
//
//         The pointer is cast to the correct type (AT91PS_OTGHS).
// \param  pUsb Pointer to a S_usb instance
// \return Pointer to the USB controller interface
// \see    S_usb
//------------------------------------------------------------------------------
static AT91PS_OTGHS OTGHS_GetDriverInterface(const S_usb *pUsb)
{
    return (AT91PS_OTGHS) pUsb->pDriver->pInterface;
}

//------------------------------------------------------------------------------
// \fn      OTGHS_GetInterfaceEPT
// \brief   Returns OTGHS endpoint FIFO interface from S_usb structure
//------------------------------------------------------------------------------
static AT91PS_OTGHS_EPTFIFO OTGHS_GetInterfaceEPT(const S_usb *pUsb) 
{
    return (AT91PS_OTGHS_EPTFIFO) pUsb->pDriver->pEndpointFIFO;
}


//------------------------------------------------------------------------------
// \brief  Enables the peripheral clock of the USB controller associated with
//         the specified USB driver
// \param  pUsb Pointer to a S_usb instance
// \see    S_usb
//------------------------------------------------------------------------------
static void OTGHS_EnableMCK(const S_usb *pUsb)
{

}

//------------------------------------------------------------------------------
// \brief  Disables the peripheral clock of the USB controller associated with
//         the specified USB driver
// \param  pUsb Pointer to a S_usb instance
// \see    S_usb
//------------------------------------------------------------------------------
static void OTGHS_DisableMCK(const S_usb *pUsb)
{

}

//------------------------------------------------------------------------------
// \brief  Enables the 48MHz clock of the USB controller associated with
//         the specified USB driver
// \param  pUsb Pointer to a S_usb instance
// \see    S_usb
//------------------------------------------------------------------------------
static void OTGHS_EnableOTGHSCK(const S_usb *pUsb)
{

}

//------------------------------------------------------------------------------
// \brief  Disables the 48MHz clock of the USB controller associated with
//         the specified USB driver
// \param  pUsb Pointer to a S_usb instance
// \see    S_usb
//------------------------------------------------------------------------------
static void OTGHS_DisableOTGHSCK(const S_usb *pUsb)
{

}

//------------------------------------------------------------------------------
// \brief  Enables the transceiver of the USB controller associated with
//         the specified USB driver
// \param  pUsb Pointer to a S_usb instance
// \see    S_usb
//------------------------------------------------------------------------------
static void OTGHS_EnableTransceiver(const S_usb *pUsb)
{
    SET(OTGHS_GetDriverInterface(pUsb)->OTGHS_CTRL, AT91C_OTGHS_OTGPADE);
}

//------------------------------------------------------------------------------
// \brief  Disables the transceiver of the USB controller associated with
//         the specified USB driver
// \param  pUsb Pointer to a S_usb instance
// \see    S_usb
//------------------------------------------------------------------------------
static void OTGHS_DisableTransceiver(const S_usb *pUsb)
{
    CLEAR(OTGHS_GetDriverInterface(pUsb)->OTGHS_CTRL, AT91C_OTGHS_OTGPADE);
}

//------------------------------------------------------------------------------
// \brief  Invokes the callback associated with a finished transfer on an
//         endpoint
// \param  pEndpoint Pointer to a S_usb_endpoint instance
// \param  bStatus   Status code returned by the transfer operation
// \see    Status codes
// \see    S_usb_endpoint
//------------------------------------------------------------------------------
static void OTGHS_EndOfTransfer(S_usb_endpoint *pEndpoint,
                                         char bStatus)
{
    if ((pEndpoint->dState == endpointStateWrite)
        || (pEndpoint->dState == endpointStateRead)) {

        TRACE_DEBUG_WP("E");

        // Endpoint returns in Idle state
        pEndpoint->dState = endpointStateIdle;

        // Invoke callback is present
        if (pEndpoint->fCallback != 0) {

            pEndpoint->fCallback((unsigned int) pEndpoint->pArgument,
                                 (unsigned int) bStatus,
                                 pEndpoint->dBytesTransferred,
                                 pEndpoint->dBytesRemaining
                                 + pEndpoint->dBytesBuffered);
        }
    }
}

//------------------------------------------------------------------------------
// \brief  Transfers a data payload from the current tranfer buffer to the
//         endpoint FIFO.
// \param  pUsb      Pointer to a S_usb instance
// \param  bEndpoint Index of endpoint
// \return Number of bytes transferred
// \see    S_usb
//------------------------------------------------------------------------------
static unsigned int OTGHS_WritePayload(const S_usb *pUsb,
                                       unsigned char bEndpoint)
{
    AT91PS_OTGHS_EPTFIFO pInterfaceEPT = OTGHS_GetInterfaceEPT(pUsb);
    S_usb_endpoint *pEndpoint = USB_GetEndpoint(pUsb, bEndpoint);
    char           *pfifo;
    unsigned int   dBytes;
    unsigned int   dCtr;

    pfifo = (char*)&(pInterfaceEPT->OTGHS_READEPT0[bEndpoint*16384]);

    // Get the number of bytes to send
    dBytes = min(pEndpoint->wMaxPacketSize, pEndpoint->dBytesRemaining);

    // Transfer one packet in the FIFO buffer
    for (dCtr = 0; dCtr < dBytes; dCtr++) {

        pfifo[dCtr] = *(pEndpoint->pData);
        pEndpoint->pData++;
    }

    pEndpoint->dBytesBuffered += dBytes;
    pEndpoint->dBytesRemaining -= dBytes;

    return dBytes;
}

//----------------------------------------------------------------------------
// \brief  Transfers a data payload from an endpoint FIFO to the current
//         transfer buffer.
// \param  pUsb        Pointer to a S_usb instance
// \param  bEndpoint   Index of endpoint
// \param  wPacketSize Size of received data packet
// \return Number of bytes transferred
// \see    S_usb
//------------------------------------------------------------------------------
static unsigned int OTGHS_GetPayload(const S_usb    *pUsb,
                                     unsigned char  bEndpoint,
                                     unsigned short wPacketSize)
{
    AT91PS_OTGHS_EPTFIFO pInterfaceEPT = OTGHS_GetInterfaceEPT(pUsb);
    S_usb_endpoint *pEndpoint = USB_GetEndpoint(pUsb, bEndpoint);
    char           *pfifo;
    unsigned int   dBytes;
    unsigned int   dCtr;

    pfifo = (char*)&(pInterfaceEPT->OTGHS_READEPT0[bEndpoint*16384]);

    // Get number of bytes to retrieve
    dBytes = min(pEndpoint->dBytesRemaining, wPacketSize);

    // Retrieve packet
    for (dCtr = 0; dCtr < dBytes; dCtr++) {

        *(pEndpoint->pData) = pfifo[dCtr];
        pEndpoint->pData++;
    }

    pEndpoint->dBytesRemaining -= dBytes;
    pEndpoint->dBytesTransferred += dBytes;
    pEndpoint->dBytesBuffered += wPacketSize - dBytes;

    return dBytes;
}

//------------------------------------------------------------------------------
// \brief  Transfers a received SETUP packet from endpoint 0 FIFO to the
//         S_usb_request structure of an USB driver
// \param  pUsb Pointer to a S_usb instance
// \see    S_usb
//------------------------------------------------------------------------------
static void OTGHS_GetSetup(const S_usb *pUsb)
{
    unsigned int *pData = (unsigned int *) USB_GetSetup(pUsb);
    AT91PS_OTGHS_EPTFIFO pInterfaceEPT = OTGHS_GetInterfaceEPT(pUsb);

    pData[0] = pInterfaceEPT->OTGHS_READEPT0[0];
    pData[1] = pInterfaceEPT->OTGHS_READEPT0[0];
}

//------------------------------------------------------------------------------
// \brief  This function reset all endpoint transfer descriptors
// \param  pUsb Pointer to a S_usb instance
// \see    S_usb
//------------------------------------------------------------------------------
static void OTGHS_ResetEndpoints(const S_usb *pUsb)
{
    S_usb_endpoint *pEndpoint;
    unsigned char  bEndpoint;

    // Reset the transfer descriptor of every endpoint
    for (bEndpoint = 0; bEndpoint < pUsb->dNumEndpoints; bEndpoint++) {

        pEndpoint = USB_GetEndpoint(pUsb, bEndpoint);

        // Reset endpoint transfer descriptor
        pEndpoint->pData = 0;
        pEndpoint->dBytesRemaining = 0;
        pEndpoint->dBytesTransferred = 0;
        pEndpoint->dBytesBuffered = 0;
        pEndpoint->fCallback = 0;
        pEndpoint->pArgument = 0;

        // Configure endpoint characteristics
        pEndpoint->dState = endpointStateDisabled;
    }
}

//------------------------------------------------------------------------------
// \brief  Disable all endpoints (except control endpoint 0), aborting current
//         transfers if necessary.
// \param  pUsb Pointer to a S_usb instance
//------------------------------------------------------------------------------
static void OTGHS_DisableEndpoints(const S_usb *pUsb)
{
    S_usb_endpoint *pEndpoint;
    unsigned char  bEndpoint;

    // Foreach endpoint, if it is enabled, disable it and invoke the callback
    // Control endpoint 0 is not disabled
    for (bEndpoint = 1; bEndpoint < pUsb->dNumEndpoints; bEndpoint++) {

        pEndpoint = USB_GetEndpoint(pUsb, bEndpoint);
        OTGHS_EndOfTransfer(pEndpoint, USB_STATUS_RESET);

        pEndpoint->dState = endpointStateDisabled;
    }
}

//------------------------------------------------------------------------------
// \brief  Endpoint interrupt handler.
//
//         Handle IN/OUT transfers, received SETUP packets and STALLing
// \param  pUsb      Pointer to a S_usb instance
// \param  bEndpoint Index of endpoint
// \see    S_usb
//------------------------------------------------------------------------------
static void OTGHS_EndpointHandler(const S_usb *pUsb, unsigned char bEndpoint)
{
    S_usb_endpoint *pEndpoint = USB_GetEndpoint(pUsb, bEndpoint);
    AT91PS_OTGHS pInterface = OTGHS_GetDriverInterface(pUsb);
    unsigned int dStatus = pInterface->OTGHS_DEVEPTCSR[bEndpoint];
    unsigned short wPacketSize;

    TRACE_DEBUG_WP("Ept%d, 0x%X ", bEndpoint, dStatus);

    // Handle interrupts
    // IN packet sent
    if((ISSET(pInterface->OTGHS_DEVEPTCMR[bEndpoint], AT91C_OTGHS_TXINI))
    && (ISSET(dStatus, AT91C_OTGHS_TXINI ))) {

        TRACE_DEBUG_WP("Wr ");

        if (pEndpoint->dBytesBuffered > 0) {

            TRACE_DEBUG_WP("%d ", pEndpoint->dBytesBuffered);

            pEndpoint->dBytesTransferred += pEndpoint->dBytesBuffered;
            pEndpoint->dBytesBuffered = 0;
        }

        if ((!pEndpoint->isDataSent) || (pEndpoint->dBytesRemaining > 0)) {
            
            OTGHS_WritePayload(pUsb, bEndpoint);
            pEndpoint->isDataSent = true;

            pInterface->OTGHS_DEVEPTCCR[bEndpoint] = AT91C_OTGHS_TXINI;
            // For a non-control endpoint, the FIFOCON bit must be cleared
            // to start the transfer
            if ((AT91C_OTGHS_EPT_TYPE & pInterface->OTGHS_DEVEPTCFG[bEndpoint])
                != AT91C_OTGHS_EPT_TYPE_CTL_EPT) {

                pInterface->OTGHS_DEVEPTCDR[bEndpoint] = AT91C_OTGHS_FIFOCON;
            }
        }
        else {
            
            pInterface->OTGHS_DEVEPTCDR[bEndpoint] = AT91C_OTGHS_TXINI;

            // Disable interrupt if this is not a control endpoint
            if ((AT91C_OTGHS_EPT_TYPE & pInterface->OTGHS_DEVEPTCFG[bEndpoint])
                != AT91C_OTGHS_EPT_TYPE_CTL_EPT) {

                pInterface->OTGHS_DEVIDR = 1<<SHIFT_INTERUPT<<bEndpoint;

            }
            OTGHS_EndOfTransfer(pEndpoint, USB_STATUS_SUCCESS);
        }
    }

    // OUT packet received
    if(ISSET(dStatus, AT91C_OTGHS_RXOUT)) {

        TRACE_DEBUG_WP("Rd ");

        // Check that the endpoint is in Read state
        if (pEndpoint->dState != endpointStateRead) {

            // Endpoint is NOT in Read state
            if (ISCLEARED(pInterface->OTGHS_DEVEPTCFG[bEndpoint], AT91C_OTGHS_EPT_TYPE)
             && ISCLEARED(dStatus, (0x7FF<<20))) {  // byte count

                // Control endpoint, 0 bytes received
                // Acknowledge the data and finish the current transfer
                TRACE_DEBUG_WP("Ack ");
                pInterface->OTGHS_DEVEPTCCR[bEndpoint] = AT91C_OTGHS_RXOUT;

                OTGHS_EndOfTransfer(pEndpoint, USB_STATUS_SUCCESS);
            }
            else if (ISSET(dStatus, AT91C_OTGHS_STALL)) {

                // Non-control endpoint

?? 快捷鍵說明

復制代碼 Ctrl + C
搜索代碼 Ctrl + F
全屏模式 F11
切換主題 Ctrl + Shift + D
顯示快捷鍵 ?
增大字號 Ctrl + =
減小字號 Ctrl + -
亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频
亚洲素人一区二区| 日韩精品一区二区三区视频 | 91麻豆精品91久久久久同性| 日韩一级片网站| 久久久99免费| 一区二区三区小说| 久久99精品久久久久久| 成人精品视频一区二区三区| 欧美日韩免费电影| 国产视频一区二区在线| 亚洲国产综合在线| 黄色精品一二区| 精品嫩草影院久久| 欧美日韩国产片| 久久久精品国产免费观看同学| 国产精品白丝在线| 日本免费在线视频不卡一不卡二| 成人在线视频一区二区| 欧美精品1区2区3区| 国产日韩欧美一区二区三区综合| 亚洲午夜久久久久久久久电影网| 国产一区视频在线看| 欧美日韩国产一二三| 国产精品私房写真福利视频| 香蕉加勒比综合久久| 成人av网站在线观看| 日韩欧美第一区| 一区二区久久久| 国产99精品国产| 日韩精品一区二区三区中文精品| 一区二区三区四区亚洲| 国产盗摄视频一区二区三区| 欧美精品 国产精品| 亚洲天堂免费在线观看视频| 国内精品久久久久影院薰衣草| 欧美色图片你懂的| 中文字幕人成不卡一区| 国产精华液一区二区三区| 91精品国产色综合久久ai换脸| 日韩理论片网站| 粉嫩av亚洲一区二区图片| 日韩欧美卡一卡二| 亚洲sss视频在线视频| 91免费视频网址| 欧美国产激情二区三区| 久久国产夜色精品鲁鲁99| 欧美精品电影在线播放| 一区二区久久久久久| 97精品久久久久中文字幕 | 国精产品一区一区三区mba视频 | 日一区二区三区| 欧美性生活大片视频| 亚洲精品国产视频| jlzzjlzz亚洲日本少妇| 国产午夜亚洲精品午夜鲁丝片| 久久99精品久久久久婷婷| 欧美一区二区在线不卡| 亚洲国产sm捆绑调教视频 | 亚洲伊人伊色伊影伊综合网| av电影一区二区| 国产精品人妖ts系列视频| 国产二区国产一区在线观看| 欧美电影免费观看高清完整版| 五月天久久比比资源色| 欧美日韩性生活| 午夜在线成人av| 欧美日韩在线电影| 亚洲成人一区二区在线观看| 色婷婷av一区二区三区大白胸| 亚洲欧美日韩国产手机在线| 99精品桃花视频在线观看| 国产精品久久久久久久浪潮网站| 国产91精品久久久久久久网曝门| 国产三级三级三级精品8ⅰ区| 国产精品一二三四| 国产性天天综合网| zzijzzij亚洲日本少妇熟睡| 中文字幕日本乱码精品影院| 一本大道久久a久久精品综合| 亚洲人123区| 欧美日韩精品欧美日韩精品一| 性做久久久久久| 欧美成人女星排名| 韩国精品主播一区二区在线观看 | 国产精品18久久久久久久久久久久| 久久天天做天天爱综合色| 大白屁股一区二区视频| 综合久久久久久| 欧美日产国产精品| 看电影不卡的网站| 国产精品视频一区二区三区不卡| 99re在线精品| 午夜视频久久久久久| 日韩欧美亚洲一区二区| 粉嫩13p一区二区三区| 亚洲柠檬福利资源导航| 欧美精品 国产精品| 国产在线精品一区在线观看麻豆| 国产日韩av一区二区| 在线影视一区二区三区| 毛片av一区二区| 国产精品沙发午睡系列990531| 在线视频亚洲一区| 美女视频黄 久久| 国产精品美女久久久久久久| 欧洲一区在线观看| 久久精品国产网站| 国产精品国产三级国产普通话三级| 欧美吞精做爰啪啪高潮| 久久99热这里只有精品| 中文字幕日韩一区| 欧美一卡在线观看| 99国产精品国产精品久久| 日本不卡视频在线观看| 国产精品免费久久久久| 9191成人精品久久| 狠狠色狠狠色综合| 夜色激情一区二区| 久久久一区二区三区捆绑**| 日本韩国欧美一区| 激情五月激情综合网| 亚洲精品国产一区二区精华液 | 国产成人午夜电影网| 亚洲成人综合在线| 中文字幕国产一区二区| 欧美一区二区三区系列电影| 成人精品视频一区| 欧美一区二区不卡视频| 91免费在线看| 国产一区二区在线视频| 亚洲成av人影院| 国产精品视频你懂的| 欧美电视剧免费观看| 91蜜桃免费观看视频| 韩国成人精品a∨在线观看| 亚洲午夜在线视频| 国产精品久久久久久久久动漫 | 免费观看一级欧美片| 亚洲欧美日韩精品久久久久| 精品国产1区2区3区| 在线这里只有精品| 成人激情av网| 国产制服丝袜一区| 天天综合网天天综合色| 一区二区三区加勒比av| 国产精品色婷婷| 日韩欧美国产一区在线观看| 在线观看一区二区视频| 成人黄色av电影| 国产伦精品一区二区三区视频青涩| 日日夜夜一区二区| 亚洲一区二区三区四区五区黄| 国产精品成人免费| 久久久久久97三级| 欧美大片拔萝卜| 91精品综合久久久久久| 欧美亚洲一区二区三区四区| 91在线视频网址| 99热这里都是精品| 精品国产乱码久久久久久久| 欧美精品成人一区二区三区四区| 在线视频国内一区二区| 99r国产精品| www.日本不卡| 不卡一区二区三区四区| 国产成人午夜视频| 国产成人免费视频网站高清观看视频 | 国内精品伊人久久久久av一坑| 日韩成人一级大片| 午夜私人影院久久久久| 亚洲国产一区二区视频| 亚洲狠狠丁香婷婷综合久久久| 国产精品国产a| 最新不卡av在线| 国产精品传媒在线| 亚洲天堂久久久久久久| 最新欧美精品一区二区三区| 国产精品久久久久久久久快鸭 | 91一区二区在线| 91啪在线观看| 色www精品视频在线观看| 91蝌蚪porny成人天涯| 色欧美日韩亚洲| 在线亚洲一区二区| 欧美午夜视频网站| 欧美日韩1234| 欧美电影免费观看完整版| 精品电影一区二区三区| 国产人伦精品一区二区| 国产精品久久久久7777按摩| 中国色在线观看另类| 亚洲欧洲成人精品av97| 亚洲免费资源在线播放| 亚洲妇熟xx妇色黄| 蜜臀精品一区二区三区在线观看| 精品一区二区免费视频| 成人激情小说网站| 色婷婷综合久久久中文一区二区| 91成人免费在线| 日韩一区二区三区电影在线观看 |