?? fw.c
字號:
#pragma NOIV
//-----------------------------------------------------------------------------
// File: fw.c
// Contents: Firmware frameworks task dispatcher and device request parser
// source.
// indent 3. NO TABS!
//
// Copyright (c) 2005 Cypress Semiconductor
//
// $Workfile: fw.c $
// $Date: 8/08/05 10:49a $
// $Revision: 1 $
//-----------------------------------------------------------------------------
//
// Copyright 2005, Cypress Semiconductor Corporation.
//
// This software is owned by Cypress Semiconductor Corporation (Cypress)
// and is protected by and subject to worldwide patent protection (United
// States and foreign), United States copyright laws and international
// treaty provisions. Cypress hereby grants to licensee a personal,
// non-exclusive, non-transferable license to copy, use, modify, create
// derivative works of, and compile the Cypress Source Code and derivative
// works for the sole purpose of creating custom software in support of
// licensee product to be used only in conjunction with a Cypress integrated
// circuit as specified in the applicable agreement. Any reproduction,
// modification, translation, compilation, or representation of this
// software except as specified above is prohibited without the express
// written permission of Cypress.
//
// Disclaimer: CYPRESS MAKES NO WARRANTY OF ANY KIND,EXPRESS OR IMPLIED,
// WITH REGARD TO THIS MATERIAL, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
// WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
// Cypress reserves the right to make changes without further notice to the
// materials described herein. Cypress does not assume any liability arising
// out of the application or use of any product or circuit described herein.
// Cypress does not authorize its products for use as critical components in
// life-support systems where a malfunction or failure may reasonably be
// expected to result in significant injury to the user. The inclusion of
// Cypress' product in a life-support systems application implies that the
// manufacturer assumes all risk of such use and in doing so indemnifies
// Cypress against all charges.
//
// Use may be limited by and subject to the applicable Cypress software
// license agreement.
//
//--------------------------------------------------------------------------
#include "globals.h"
//-----------------------------------------------------------------------------
// Code
// Task dispatcher
//-----------------------------------------------------------------------------
void main(void)
{
TD_Init(); // HW/SW initialization
EZUSB_IRQ_ENABLE(); // Enable USB interrupt (INT2)
EZUSB_ENABLE_RSMIRQ(); // Wake-up interrupt
INTSETUP |= (bmAV2EN); // Enable INT 2 autovectoring
USBIE = bmSUDAV | bmSUSP | bmURES | bmHSGRANT; // Enable selected interrupts
//////////////////////////////////////////////////////////////////////////////
//
// How we got here Renum Bit Discon Bit Desired Action
// --------------- --------- ---------- --------------------
// LI Boot-Loader Good_FW 0 1 Set the renum bit and connect
// LI Boot-Loader !Good_FW 0 0 renumerate
// USB Reset 1 0 do nothing
// Debug Mode (no bootloader) 0 0 renumerate
// I2C Boot-Loader Good_FW 1 0 do nothing
// I2C Boot-Loader !Good_FW 0 0 renumerate
//
if(!(USBCS & (bmRENUM | bmDISCON)))
{
EA = 0;
// disconnect from USB and set the renumerate bit
USBCS |= (bmDISCON | bmRENUM);
EZUSB_Delay(2500); // Wait 2500 ms
USBIRQ = 0xff; // Clear any pending USB interrupt requests.
EPIRQ = 0xff;
EZUSB_IRQ_CLEAR();
}
EA = 1; // Enable 8051 interrupts
TR0 = 1; // Make sure that the timer ISR runs at once.
// unconditionally re-connect. If we loaded from eeprom we are
// disconnected and need to connect. If we just renumerated this
// is not necessary but doesn't hurt anything
USBCS = (bmRENUM|bmNOSYNSOF);
// complete the handshake phase of any pending SETUP transfer.
// The only time this should happen is after a MSC Reset. We want
// to go through all of the EP init code before handshaking the status
// phase of the MSC Reset.
EP0CS |= bmHSNAK;
Sleep = 0; // sleep is off
// Task Dispatcher
while(TRUE) // Main Loop
{
// Suspend code -- Turn off LEDs, chip enables and put CPU into suspend.
// We don't support remote wakeup. Only wake on SOFs.
if (Sleep)
{
Sleep = FALSE;
WAKEUPCS = bmWU2 | bmWU | bmDPEN;
EZUSB_Susp(); // Place processor in idle mode.
} // endif (sleep)
TD_Poll();
} // End while-forever loop
}
//-----------------------------------------------------------------------------
// Standard requests are
// Device request parser
//-----------------------------------------------------------------------------
void SetupCommand(void)
{
WORD Tmp;
BYTE setupdat0 = SETUPDAT[0];
BYTE setupdat2 = SETUPDAT[2];
BYTE setupdat4 = SETUPDAT[4];
EP0BCH = 0; // Default to MSB of the length is 0
SUDPTRH = MSB(halfKBuffer); // Default to descriptor table
if ((setupdat0 & SETUP_MASK) == SETUP_STANDARD_REQUEST)
{
switch(SETUPDAT[1])
{
case SC_GET_DESCRIPTOR: // *** Get Descriptor
switch(SETUPDAT[3])
{
case GD_DEVICE: // Device
SUDPTRL = pLSB(DeviceDscrOffset); //sendDescriptor(LSB(pDeviceDscr), 0);
break;
case GD_DEVICE_QUALIFIER: // Device Qualifier
// if high-speed is disabled, we are supposed to STALL this request
if (!CT1)
{
// high-speed is enabled, return the device qualifier
// sendDescriptor(LSB(pDeviceQualDscr), 0);
SUDPTRL = pLSB(DeviceQualDscrOffset);
}
else
{
// high-speed is disabled, STALL this request
EZUSB_STALL_EP0();
}
break;
case GD_CONFIGURATION: // Configuration
((CONFIGDSCR xdata *) pHighSpeedConfigDscr)->type = CONFIG_DSCR;
Tmp = wPacketSize;
goto gd_cases;
case GD_OTHER_SPEED_CONFIGURATION: // Other Speed Configuration
((CONFIGDSCR xdata *) pHighSpeedConfigDscr)->type = OTHERSPEED_DSCR;
if (EZUSB_HIGHSPEED()) Tmp = 64; else Tmp = 512;
gd_cases:
((BYTE xdata *) pHighSpeedConfigDscr)[9+9+4] =
((BYTE xdata *) pHighSpeedConfigDscr)[9+9+7+4] = ((BYTE*)&Tmp)[1];
((BYTE xdata *) pHighSpeedConfigDscr)[9+9+5] =
((BYTE xdata *) pHighSpeedConfigDscr)[9+9+7+5] = ((BYTE*)&Tmp)[0];
sendDescriptor(LSB(pHighSpeedConfigDscr), (BYTE)&HighSpeedConfigLen);
break;
case GD_STRING: // String
SUDPTRH = MSB(halfKBuffer+cHALF_BUFF_OFFSET);
SUDPTRL = cINQUIRY_LENGTH + (setupdat2 * 48);
break;
#ifdef HID
case GD_REPORT: // Get-Descriptor: Report
if (halfKBuffer[(WORD)&HIDIntrfcDscrOffset+3] == setupdat4)
{
sendDescriptor(pLSB(HIDReportDscrOffset), (BYTE)&HIDReportDscrLen);
break;
}
else EZUSB_STALL_EP0(); // Stall End Point 0
break;
case GD_HID: // Get-Descriptor: HID
SUDPTRL = pLSB(HIDDscrOffset);
break;
#endif
default: // Invalid request
EZUSB_STALL_EP0(); // Stall End Point 0
} // switch
break;
case SC_GET_INTERFACE: // *** Get Interface
EP0BUF[0] = AlternateSetting;
EP0BCL = 1;
break;
case SC_SET_INTERFACE: // *** Set Interface
TOGCTL = 0x2; // Reset data toggle for EP2
TOGCTL = 0x22;
TOGCTL = 0x14; // Reset data toggle for EP4
TOGCTL = 0x34;
AlternateSetting = setupdat2;
break;
?? 快捷鍵說明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -