4, // EP6OUT
4, // EP6IN
5, // EP8OUT
5, // EP8IN
};
// macro for generating the address of an endpoint's control
and status register (EPnCS)
#define epcs(EP) (EPCS_Offset_Lookup_Table[(EP & 0x7E)
| (EP > 128)] + 0xE6A1)
//-------------------------------------------------------------------------
// Code
//-------------------------------------------------------------------------
// Task dispatcher
void main(void)
{
DWORD i;
WORD offset;
DWORD DevDescrLen;
DWORD j=0;
WORD IntDescrAddr;
WORD ExtDescrAddr;
BYTE Packet[PACKETSIZE];
//
// Initialize Global States
Sleep = FALSE; // Disable sleep mode
Rwuen = FALSE; // Disable remote wakeup
Selfpwr = FALSE; // Disable self powered
GotSUD = FALSE; // Clear "Got setup data" flag
// Initialize user device
TD_Init();
// The following section of code is used to relocate the
descriptor table.
// The frameworks uses SUDPTRH and SUDPTRL to
automate the SETUP requests
// for descriptors. These registers only work with memory
locations
// in the EZ-USB internal RAM. Therefore, if the
descriptors are located
// in external RAM, they must be copied to in internal
RAM.
// The descriptor table is relocated by the frameworks
ONLY if it is found
// to be located in external memory.
pDeviceDscr = (WORD)&DeviceDscr;
pDeviceQualDscr = (WORD)&DeviceQualDscr;
pHighSpeedConfigDscr =
(WORD)&HighSpeedConfigDscr;
pFullSpeedConfigDscr = (WORD)&FullSpeedConfigDscr;
pStringDscr = (WORD)&StringDscr;
// Is the descriptor table in external RAM (> 16Kbytes)? If
yes,
// then relocate.
// Note that this code only checks if the descriptors START
in
// external RAM. It will not work if the descriptor table
spans
// internal and external RAM.
Get_Packet(Packet);
Contador(timebase, Packet);
if ((WORD)&DeviceDscr & 0xC000)
{
// first, relocate the descriptors
IntDescrAddr = INTERNAL_DSCR_ADDR;
ExtDescrAddr = (WORD)&DeviceDscr;
DevDescrLen = (WORD)&UserDscr -
(WORD)&DeviceDscr + 2;
for (i = 0; i < DevDescrLen; i++)
*((BYTE xdata *)IntDescrAddr+i) = *((BYTE xdata
*)ExtDescrAddr+i);
// update all of the descriptor pointers
pDeviceDscr = IntDescrAddr;
offset = (WORD)&DeviceDscr -
INTERNAL_DSCR_ADDR;
pDeviceQualDscr -= offset;
pConfigDscr -= offset;
pOtherConfigDscr -= offset;
pHighSpeedConfigDscr -= offset;
pFullSpeedConfigDscr -= offset;
pStringDscr -= offset;
}
EZUSB_IRQ_ENABLE(); // Enable USB interrupt
(INT2)
EZUSB_ENABLE_RSMIRQ(); // Wake-up interrupt
INTSETUP |= (bmAV2EN | bmAV4EN); // Enable INT
2 & 4 autovectoring
USBIE |= bmSUDAV | bmSUTOK | bmSUSP | bmURES |
bmHSGRANT; // Enable selected interrupts
EA = 1; // Enable 8051 interrupts
#ifndef NO_RENUM
69
Kommentare zu diesen Handbüchern