Source Code Files
Contents
USB08 Evaluation Board Designer Reference Manual
MOTOROLA Source Code Files 111
void initUSB() {
UADDR = BM_USBEN + 0; // USB enable, default address
UCR0 = 0; // reset EP0
UCR1 = 0; // reset EP1
UCR2 = 0; // reset EP2
UCR3 = BM_TX1STR + // clear TX1ST Flag
USB_IPUE*BM_PULLEN; // enable/disable internal Pull-up
UCR4 = 0; // USB normal operation
UIR0 = 0; // disab le Interrupts
UIR2 = 0xff; // clear all Flags in U IR1
R0Sequence = 0; // EP0 Rx starts with D ATA0
R2Sequence = 0; // EP2 Rx starts with D ATA0
USB_State = US_POWERED; // powered, but not yet reset
TxBuf_RdIdx = 0; // reset Buffer Indexes
TxBuf_WrIdx = 0;
RxBuf_RdIdx = 0;
RxBuf_WrIdx = 0;
}
//--------------------- ------------------------ ----------------------- --------
uchar getUSB() {
uchar c;
while(RxBuf_RdIdx == Rx Buf_WrIdx)
; // wait if RxBuffer is empty
c = RxBuffer[RxBuf_RdIdx];
RxBuf_RdIdx = (RxBuf_Rd Idx+1) & (MAX_RXBUF_SIZE -1);
return c;
}
//--------------------- ------------------------ ----------------------- --------
void putUSB(uchar c) {
uchar newIdx;
newIdx = (TxBuf_WrIdx+1) & (MAX_ TX BU F_SIZE-1);
while(newIdx == TxBuf_RdIdx)
; // wait if TxBuffer is full
TxBuffer[TxBuf_WrIdx] = c;
TxBuf_WrIdx = newIdx;
}
//--------------------- ------------------------ ----------------------- --------