beautypg.com

Motorola USB08 User Manual

Page 109

background image

Source Code Files

Contents

USB08 Evaluation Board

Designer Reference Manual

MOTOROLA

Source Code Files

109

void handleIN() {

uchar n;

uchar *dest;

UCR0 &= ~BM_TX0E;

// Deactivate EP0 Transmitter

UIR2 = BM_TXD0FR;

// Reset EP0 Transmit complete Flag

switch(SetupBuffer.bRequest) {

case SET_ADDRESS:

UADDR = SetupBuffer.wValue.lo | BM_USBEN;

if(SetupBuffer.wValue.lo != 0) USB_State = US_ADDRESSED;

else USB_State = US_DEFAULT;

SetupBuffer.bRequest = REQUEST_COMPLETE;

break;

case GET_DESCRIPTOR:

// copy (up to) 8 Bytes to EP0 Data Registers

n = 0;

dest = (uchar *)&UE0D0;

while(SetupSize!=0 && n<8) {

*dest = *SetupDataPtr;

dest++;

SetupDataPtr++;

SetupSize--;

n++;

}

// prepare to send n Bytes at next IN Transaction

// toggle DATA0/1

UCR0 = ((UCR0^BM_T0SEQ) & BM_T0SEQ) + BM_TX0E + BM_RX0E + n;

// check if this is the last DATA packet to send

if(n < 8) SetupBuffer.bRequest = REQUEST_COMPLETE;

break;

case CLEAR_FEATURE:

case SET_CONFIGURATION:

// nothing to do - handshake finished

SetupBuffer.bRequest = REQUEST_COMPLETE;

break;

case REQUEST_COMPLETE:

// Request is finished - just clear the TXD0F Flag (see above)

// and do not re-enable EP0 Transmitter, since there is no more

// data to send

break;

default:

forceSTALL();

break;

}

}

//----------------------------------------------------------------------------