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

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

?? usbd_otghs.c

?? AT91SAM9263的USB Device端口驅動
?? C
?? 第 1 頁 / 共 4 頁
字號:
/* ----------------------------------------------------------------------------
 *         ATMEL Microcontroller Software Support  -  ROUSSET  -
 * ----------------------------------------------------------------------------
 * Copyright (c) 2006, 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 disclaiimer below.
 *
 * - Redistributions in binary form must reproduce the above copyright notice,
 * this list of conditions and the disclaimer below in the documentation and/or
 * other materials provided with the distribution.
 *
 * 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_L("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_L("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_L("Wr ");

        if (pEndpoint->dBytesBuffered > 0) {

            TRACE_DEBUG_L("%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_L("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_L("Ack ");
                pInterface->OTGHS_DEVEPTCCR[bEndpoint] = AT91C_OTGHS_RXOUT;

                OTGHS_EndOfTransfer(pEndpoint, USB_STATUS_SUCCESS);
            }

?? 快捷鍵說明

復制代碼 Ctrl + C
搜索代碼 Ctrl + F
全屏模式 F11
切換主題 Ctrl + Shift + D
顯示快捷鍵 ?
增大字號 Ctrl + =
減小字號 Ctrl + -
亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频
亚洲精品乱码久久久久| 精品黑人一区二区三区久久| 美女视频黄a大片欧美| 亚洲日本成人在线观看| 欧美区一区二区三区| 国产成人福利片| 麻豆精品一二三| 亚洲1区2区3区4区| 国产精品亲子伦对白| 久久久国产综合精品女国产盗摄| 色悠悠久久综合| 成人免费的视频| 国产福利一区在线| 亚洲一区精品在线| 亚洲三级小视频| 中文一区在线播放 | 精品精品国产高清一毛片一天堂| 日本丰满少妇一区二区三区| 99久久国产综合色|国产精品| 国产成人免费视频| 国产精品一区二区男女羞羞无遮挡 | 久久久久久久综合| 欧美欧美欧美欧美| 91久久线看在观草草青青| 国产一区在线不卡| 激情综合一区二区三区| 日韩影院在线观看| 亚洲综合激情另类小说区| 亚洲欧洲成人精品av97| 中文在线资源观看网站视频免费不卡| 亚洲精品一区二区三区蜜桃下载| 精品日韩欧美在线| 欧美日韩激情一区二区| 在线观看视频一区二区| 97精品久久久久中文字幕| 国产不卡在线视频| 国产91精品精华液一区二区三区| 国产精品99久久久久| 国产一区二区网址| 丰满放荡岳乱妇91ww| 国产91清纯白嫩初高中在线观看| 大胆亚洲人体视频| 99热这里都是精品| av一区二区不卡| 成人av在线影院| 91一区二区三区在线观看| 91在线国产观看| 色婷婷亚洲一区二区三区| 91成人免费网站| 欧美巨大另类极品videosbest| 日韩一区二区不卡| 精品va天堂亚洲国产| 久久精品欧美一区二区三区不卡 | 国产综合色产在线精品| 国产丶欧美丶日本不卡视频| 色婷婷久久一区二区三区麻豆| 欧美丰满美乳xxx高潮www| 国产亚洲人成网站| 亚洲视频 欧洲视频| 午夜国产精品一区| 国产日本一区二区| 亚洲精选视频在线| 成人黄色在线看| 久久人人爽人人爽| 蜜臀av亚洲一区中文字幕| 欧美三区在线视频| 亚洲欧美影音先锋| 成人手机在线视频| 久久久久久综合| 久久国产麻豆精品| 日韩一区二区在线看| 日韩美女视频19| 高清在线观看日韩| 久久精品男人的天堂| 九九国产精品视频| 欧美一区二区国产| 婷婷国产v国产偷v亚洲高清| 色综合天天综合网天天看片| 国产婷婷色一区二区三区| 精品中文字幕一区二区小辣椒| 欧美日韩精品系列| 午夜一区二区三区视频| 欧美中文字幕不卡| 亚洲永久精品大片| 欧美日韩在线播放一区| 一区二区日韩av| 色94色欧美sute亚洲13| 一区二区在线观看免费| 日本韩国欧美三级| 亚洲高清在线视频| 日韩亚洲欧美高清| 欧美bbbbb| 久久影院午夜论| 国产91对白在线观看九色| 中文字幕av一区二区三区免费看 | 久久久久国产精品免费免费搜索| 久久91精品国产91久久小草 | 国产精品久久久久天堂| 成人性生交大片免费看中文| 国产精品天美传媒| 色综合久久88色综合天天免费| 亚洲精品国产第一综合99久久 | 成人精品国产一区二区4080| 中文字幕欧美激情| 色欧美日韩亚洲| 丝袜a∨在线一区二区三区不卡| 欧美高清视频在线高清观看mv色露露十八 | 欧美大片顶级少妇| 国产一区二区主播在线| 中文字幕中文在线不卡住| 色婷婷激情综合| 奇米精品一区二区三区四区| 精品成人私密视频| 色综合一区二区三区| 视频在线观看国产精品| 日韩欧美一卡二卡| 99久久久国产精品免费蜜臀| 水野朝阳av一区二区三区| 国产亚洲综合av| 欧美日韩高清不卡| 国产乱码精品一区二区三| 一区二区三区精品久久久| 欧美色视频一区| 国产综合久久久久久鬼色| 一区二区在线免费| 久久一区二区三区国产精品| 93久久精品日日躁夜夜躁欧美| 日韩电影一区二区三区| 国产精品国产自产拍高清av王其| 欧美精品精品一区| 99视频热这里只有精品免费| 麻豆成人免费电影| 伊人一区二区三区| 亚洲国产精品黑人久久久| 91精品国产综合久久国产大片| 粉嫩av一区二区三区粉嫩| 五月婷婷综合网| 自拍偷拍国产亚洲| 久久久影视传媒| 欧美日本一区二区三区| 99久久精品一区| 国产激情一区二区三区桃花岛亚洲| 亚洲一区在线视频观看| 国产精品美女一区二区| 日韩一区二区三区四区| 欧美又粗又大又爽| av不卡在线播放| 国产在线精品免费| 麻豆国产欧美日韩综合精品二区 | 99精品一区二区三区| 韩国一区二区在线观看| 人人狠狠综合久久亚洲| 亚洲va国产天堂va久久en| 中文字幕一区二区三区在线不卡| 亚洲精品在线电影| 欧美电影精品一区二区| 日韩视频一区二区三区| 宅男在线国产精品| 欧美老年两性高潮| 欧美日韩在线精品一区二区三区激情| 97久久超碰精品国产| 成人网男人的天堂| 成人成人成人在线视频| 成人蜜臀av电影| 成人国产精品视频| 99久久婷婷国产综合精品电影| 成人国产亚洲欧美成人综合网| 成人av一区二区三区| 高清国产午夜精品久久久久久| 国产精品小仙女| 床上的激情91.| av综合在线播放| 色综合久久综合网欧美综合网| 色综合久久久久网| 91片黄在线观看| 欧美午夜不卡视频| 这里是久久伊人| 日韩一区二区三区三四区视频在线观看| 在线精品视频免费观看| 欧洲国内综合视频| 欧美日韩日日摸| 欧美一区二区三区白人| 欧美r级在线观看| 欧美激情一区二区三区全黄| 中文字幕在线一区二区三区| 亚洲人吸女人奶水| 一区二区欧美国产| 首页综合国产亚洲丝袜| 日产国产高清一区二区三区| 精品一区二区在线视频| 成人精品在线视频观看| 在线精品视频免费播放| 在线综合视频播放| 国产亲近乱来精品视频| 成人欧美一区二区三区小说 | 日韩中文欧美在线| 狠狠色丁香婷综合久久| 北条麻妃一区二区三区| 欧美网站一区二区| 久久蜜桃av一区二区天堂|