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

📄 periph.c

📁 使用Jungo Windriver開發的USB driver 及其firmware,類型為mass storage,應用於FX2(Cypress CY68013A)上.
💻 C
字号:
/******************************************************************************
*   File:     periph.c                                                         
*
*   Contents:  Implementation of functions for supporting USB peripheral
*              device functionality for l123456 devices, based on the
*              Cypress FX2LP (CY7C68013A) development board.
*              The functions' implementation was derived from the specific
*              device configuration defined with the DriverWizard.
*
*   Code was generated by DriverWizard v8.02 - http://www.jungo.com
*   Copyright (c) 2008 Jungo Ltd.  http://www.jungo.com
*******************************************************************************/

#pragma NOIV               // Do not generate interrupt vectors

#include "wdf_cypress_lib.h"

#define NUM_OF_INTERFACES 1
extern BOOL   GotSUD;         // Received setup data flag
extern BOOL   Sleep;
extern BOOL   Rwuen;
extern BOOL   Selfpwr;

BYTE   Configuration;      // Current configuration
BYTE   AlternateSettings[NUM_OF_INTERFACES];   // Alternate settings

BYTE xdata myBuffer[1024];
#define MIN(a,b) ((a) < (b) ? (a) : (b))
static int CalcMaxPacketSize(int high_speed_max_packet, EP_TYPE type)
{
    if (EZUSB_HIGHSPEED())
        return high_speed_max_packet;

    if (type == ISOCHRONOUS)
        return MIN(high_speed_max_packet, 1023);

    return MIN(high_speed_max_packet, 64);
}

//-----------------------------------------------------------------------------
// Task Dispatcher hooks
//   The following hooks are called by the task dispatcher.
//-----------------------------------------------------------------------------

void WDF_InitInterface(BYTE ifc)
{
    int i;

    switch (ifc)
    {
    case 0:
        switch (AlternateSettings[ifc])
        {
        case 0:
            WDF_EP1OUTConfig(BULK);
            for (i = 0; i < 1; i++)
                WDF_SkipOutPacket(0x1);

            break;
        }

    default:
        break;
    }
}

void WDF_Init(void)
{
    BREAKPT &= ~bmBPEN;      // to see BKPT LED go out TGE
    Rwuen = FALSE;               // Disable remote wakeup
    Selfpwr = FALSE;            // Disable self powered

    // set the CPU clock to 48MHz
    CPUCS = ((CPUCS & ~bmCLKSPD) | bmCLKSPD1) ;

    // set the slave FIFO interface to 48MHz
    IFCONFIG |= 0x40;

    // enable dual autopointer feature
    AUTOPTRSETUP |= 0x01;

    WDF_InitInterface(0);
}

void WDF_Poll(void)
{
    switch (AlternateSettings[0])
    {
        case 0:
            if (!WDF_FIFOEmpty(0x1))
            {
                // Read the size of ready data in the FIFO
                WORD bytesCount = WDF_GetEPByteCount(0x1);
                // There is data in endpoint buffer - ignore it
                WDF_SkipOutPacket(0x1);
            }
            break;
     }

}

//-----------------------------------------------------------------------------
// Device Request hooks
//   The following hooks are called by the end point 0 device request parser.
//-----------------------------------------------------------------------------

BOOL WDF_GetDescriptor(void)
{
    return(TRUE);
}

// Called when a Set Configuration command is received
BOOL WDF_SetConfiguration(BYTE config)
{
    Configuration = config;
    return(TRUE);            // Handled by user code
}

// Called when a Get Configuration command is received
BOOL WDF_GetConfiguration(void)
{
    EP0BUF[0] = Configuration;
    EP0BCH = 0;
    EP0BCL = 1;
    return(TRUE);            // Handled by user code
}

// Called when a Set Interface command is received
BOOL WDF_SetInterface(BYTE ifc, BYTE alt_set)
{
    AlternateSettings[ifc] = alt_set;
    WDF_InitInterface(ifc);
    return(TRUE);            // Handled by user code
}

// Called when a Get Interface command is received
BOOL WDF_GetInterface(BYTE ifc)
{
    EP0BUF[0] = AlternateSettings[ifc];
    EP0BCH = 0;
    EP0BCL = 1;
    return(TRUE);            // Handled by user code
}

BOOL WDF_GetStatus(void)
{
    return(TRUE);
}

BOOL WDF_ClearFeature(void)
{
    return(TRUE);
}

BOOL WDF_SetFeature(void)
{
    return(TRUE);
}

BOOL WDF_VendorCmnd(void)
{
    if (!(SETUPDAT[0] & SETUP_VENDOR_REQUEST))
        return FALSE;

    switch (SETUPDAT[1])
    {
    /* Add here code for handling your specific vendor requests */
    default:
        return FALSE;
        break;
    }
    return TRUE;
}

// Called before the device goes into suspend mode
BOOL WDF_Suspend(void)
{
    return(TRUE);
}

// Called after the device resumes
BOOL WDF_Resume(void)
{
    return(TRUE);
}
//-----------------------------------------------------------------------------
// USB Interrupt Handlers
//   The following functions are called by the USB interrupt jump table.
//-----------------------------------------------------------------------------

// Setup Data Available Interrupt Handler
void ISR_Sudav(void) interrupt 0
{
    GotSUD = TRUE;            // Set flag
    EZUSB_IRQ_CLEAR();
    USBIRQ = bmSUDAV;         // Clear SUDAV IRQ
}

// Setup Token Interrupt Handler
void ISR_Sutok(void) interrupt 0
{
    EZUSB_IRQ_CLEAR();
    USBIRQ = bmSUTOK;         // Clear SUTOK IRQ
}

void ISR_Sof(void) interrupt 0
{
    EZUSB_IRQ_CLEAR();
    USBIRQ = bmSOF;            // Clear SOF IRQ
}

void ISR_Ures(void) interrupt 0
{
    // whenever we get a USB reset, we should revert to full speed mode
    pConfigDscr = pFullSpeedConfigDscr;
    ((CONFIGDSCR xdata *) pConfigDscr)->type = CONFIG_DSCR_TYPE;
    pOtherConfigDscr = pHighSpeedConfigDscr;
    ((CONFIGDSCR xdata *) pOtherConfigDscr)->type = OTHERSPEED_DSCR_TYPE;

    EZUSB_IRQ_CLEAR();
    USBIRQ = bmURES;         // Clear URES IRQ
}

void ISR_Susp(void) interrupt 0
{
    Sleep = TRUE;
    EZUSB_IRQ_CLEAR();
    USBIRQ = bmSUSP;
}

void ISR_Highspeed(void) interrupt 0
{
    if (EZUSB_HIGHSPEED())
    {
	pConfigDscr = pHighSpeedConfigDscr;
	((CONFIGDSCR xdata *) pConfigDscr)->type = CONFIG_DSCR_TYPE;
	pOtherConfigDscr = pFullSpeedConfigDscr;
	((CONFIGDSCR xdata *) pOtherConfigDscr)->type = OTHERSPEED_DSCR_TYPE;
    }

    EZUSB_IRQ_CLEAR();
    USBIRQ = bmHSGRANT;
}
void ISR_Ep0ack(void) interrupt 0
{
}
void ISR_Stub(void) interrupt 0
{
}
void ISR_Ep0in(void) interrupt 0
{
}
void ISR_Ep0out(void) interrupt 0
{
}
void ISR_Ep1in(void) interrupt 0
{
}
void ISR_Ep1out(void) interrupt 0
{
}
void ISR_Ep2inout(void) interrupt 0
{
}
void ISR_Ep4inout(void) interrupt 0
{
}
void ISR_Ep6inout(void) interrupt 0
{
}
void ISR_Ep8inout(void) interrupt 0
{
}
void ISR_Ibn(void) interrupt 0
{
}
void ISR_Ep0pingnak(void) interrupt 0
{
}
void ISR_Ep1pingnak(void) interrupt 0
{
}
void ISR_Ep2pingnak(void) interrupt 0
{
}
void ISR_Ep4pingnak(void) interrupt 0
{
}
void ISR_Ep6pingnak(void) interrupt 0
{
}
void ISR_Ep8pingnak(void) interrupt 0
{
}
void ISR_Errorlimit(void) interrupt 0
{
}
void ISR_Ep2piderror(void) interrupt 0
{
}
void ISR_Ep4piderror(void) interrupt 0
{
}
void ISR_Ep6piderror(void) interrupt 0
{
}
void ISR_Ep8piderror(void) interrupt 0
{
}
void ISR_Ep2pflag(void) interrupt 0
{
}
void ISR_Ep4pflag(void) interrupt 0
{
}
void ISR_Ep6pflag(void) interrupt 0
{
}
void ISR_Ep8pflag(void) interrupt 0
{
}
void ISR_Ep2eflag(void) interrupt 0
{
}
void ISR_Ep4eflag(void) interrupt 0
{
}
void ISR_Ep6eflag(void) interrupt 0
{
}
void ISR_Ep8eflag(void) interrupt 0
{
}
void ISR_Ep2fflag(void) interrupt 0
{
}
void ISR_Ep4fflag(void) interrupt 0
{
}
void ISR_Ep6fflag(void) interrupt 0
{
}
void ISR_Ep8fflag(void) interrupt 0
{
}
void ISR_GpifComplete(void) interrupt 0
{
}
void ISR_GpifWaveform(void) interrupt 0
{
}   

⌨️ 快捷键说明

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