len -= thisTime;\r
\r
for(i = 0; i < thisTime; i++) {\r
- UDP_ENDPOINT_FIFO(0) = *data;\r
+ AT91C_BASE_UDP->UDP_FDR[0] = *data;\r
data++;\r
}\r
\r
- if(UDP_ENDPOINT_CSR(0) & UDP_CSR_TX_PACKET_ACKED) {\r
- UDP_ENDPOINT_CSR(0) &= ~UDP_CSR_TX_PACKET_ACKED;\r
- while(UDP_ENDPOINT_CSR(0) & UDP_CSR_TX_PACKET_ACKED)\r
+ if(AT91C_BASE_UDP->UDP_CSR[0] & AT91C_UDP_TXCOMP) {\r
+ AT91C_BASE_UDP->UDP_CSR[0] &= ~AT91C_UDP_TXCOMP;\r
+ while(AT91C_BASE_UDP->UDP_CSR[0] & AT91C_UDP_TXCOMP)\r
;\r
}\r
\r
- UDP_ENDPOINT_CSR(0) |= UDP_CSR_TX_PACKET;\r
+ AT91C_BASE_UDP->UDP_CSR[0] |= AT91C_UDP_TXPKTRDY;\r
\r
do {\r
- if(UDP_ENDPOINT_CSR(0) & UDP_CSR_RX_PACKET_RECEIVED_BANK_0) {\r
+ if(AT91C_BASE_UDP->UDP_CSR[0] & AT91C_UDP_RX_DATA_BK0) {\r
// This means that the host is trying to write to us, so\r
// abandon our write to them.\r
- UDP_ENDPOINT_CSR(0) &= ~UDP_CSR_RX_PACKET_RECEIVED_BANK_0;\r
+ AT91C_BASE_UDP->UDP_CSR[0] &= ~AT91C_UDP_RX_DATA_BK0;\r
return;\r
}\r
- } while(!(UDP_ENDPOINT_CSR(0) & UDP_CSR_TX_PACKET_ACKED));\r
+ } while(!(AT91C_BASE_UDP->UDP_CSR[0] & AT91C_UDP_TXCOMP));\r
} while(len > 0);\r
\r
- if(UDP_ENDPOINT_CSR(0) & UDP_CSR_TX_PACKET_ACKED) {\r
- UDP_ENDPOINT_CSR(0) &= ~UDP_CSR_TX_PACKET_ACKED;\r
- while(UDP_ENDPOINT_CSR(0) & UDP_CSR_TX_PACKET_ACKED)\r
+ if(AT91C_BASE_UDP->UDP_CSR[0] & AT91C_UDP_TXCOMP) {\r
+ AT91C_BASE_UDP->UDP_CSR[0] &= ~AT91C_UDP_TXCOMP;\r
+ while(AT91C_BASE_UDP->UDP_CSR[0] & AT91C_UDP_TXCOMP)\r
;\r
}\r
}\r
\r
static void UsbSendZeroLength(void)\r
{\r
- UDP_ENDPOINT_CSR(0) |= UDP_CSR_TX_PACKET;\r
+ AT91C_BASE_UDP->UDP_CSR[0] |= AT91C_UDP_TXPKTRDY;\r
\r
- while(!(UDP_ENDPOINT_CSR(0) & UDP_CSR_TX_PACKET_ACKED))\r
+ while(!(AT91C_BASE_UDP->UDP_CSR[0] & AT91C_UDP_TXCOMP))\r
;\r
\r
- UDP_ENDPOINT_CSR(0) &= ~UDP_CSR_TX_PACKET_ACKED;\r
+ AT91C_BASE_UDP->UDP_CSR[0] &= ~AT91C_UDP_TXCOMP;\r
\r
- while(UDP_ENDPOINT_CSR(0) & UDP_CSR_TX_PACKET_ACKED)\r
+ while(AT91C_BASE_UDP->UDP_CSR[0] & AT91C_UDP_TXCOMP)\r
;\r
}\r
\r
static void UsbSendStall(void)\r
{\r
- UDP_ENDPOINT_CSR(0) |= UDP_CSR_FORCE_STALL;\r
+ AT91C_BASE_UDP->UDP_CSR[0] |= AT91C_UDP_FORCESTALL;\r
\r
- while(!(UDP_ENDPOINT_CSR(0) & UDP_CSR_STALL_SENT))\r
+ while(!(AT91C_BASE_UDP->UDP_CSR[0] & AT91C_UDP_STALLSENT))\r
;\r
\r
- UDP_ENDPOINT_CSR(0) &= ~UDP_CSR_STALL_SENT;\r
+ AT91C_BASE_UDP->UDP_CSR[0] &= ~AT91C_UDP_STALLSENT;\r
\r
- while(UDP_ENDPOINT_CSR(0) & UDP_CSR_STALL_SENT)\r
+ while(AT91C_BASE_UDP->UDP_CSR[0] & AT91C_UDP_STALLSENT)\r
;\r
}\r
\r
UsbSetupData usd;\r
\r
for(i = 0; i < sizeof(usd); i++) {\r
- ((BYTE *)&usd)[i] = UDP_ENDPOINT_FIFO(0);\r
+ ((BYTE *)&usd)[i] = AT91C_BASE_UDP->UDP_FDR[0];\r
}\r
\r
if(usd.bmRequestType & 0x80) {\r
- UDP_ENDPOINT_CSR(0) |= UDP_CSR_CONTROL_DATA_DIR;\r
- while(!(UDP_ENDPOINT_CSR(0) & UDP_CSR_CONTROL_DATA_DIR))\r
+ AT91C_BASE_UDP->UDP_CSR[0] |= AT91C_UDP_DIR;\r
+ while(!(AT91C_BASE_UDP->UDP_CSR[0] & AT91C_UDP_DIR))\r
;\r
}\r
\r
- UDP_ENDPOINT_CSR(0) &= ~UDP_CSR_RX_HAVE_READ_SETUP_DATA;\r
- while(UDP_ENDPOINT_CSR(0) & UDP_CSR_RX_HAVE_READ_SETUP_DATA)\r
+ AT91C_BASE_UDP->UDP_CSR[0] &= ~AT91C_UDP_RXSETUP;\r
+ while(AT91C_BASE_UDP->UDP_CSR[0] & AT91C_UDP_RXSETUP)\r
;\r
\r
switch(usd.bRequest) {\r
\r
case USB_REQUEST_SET_ADDRESS:\r
UsbSendZeroLength();\r
- UDP_FUNCTION_ADDR = UDP_FUNCTION_ADDR_ENABLED | usd.wValue ;\r
+ AT91C_BASE_UDP->UDP_FADDR = AT91C_UDP_FEN | usd.wValue ;\r
if(usd.wValue != 0) {\r
- UDP_GLOBAL_STATE = UDP_GLOBAL_STATE_ADDRESSED;\r
+ AT91C_BASE_UDP->UDP_GLBSTATE = AT91C_UDP_FADDEN;\r
} else {\r
- UDP_GLOBAL_STATE = 0;\r
+ AT91C_BASE_UDP->UDP_GLBSTATE = 0;\r
}\r
break;\r
\r
case USB_REQUEST_SET_CONFIGURATION:\r
CurrentConfiguration = usd.wValue;\r
if(CurrentConfiguration) {\r
- UDP_GLOBAL_STATE = UDP_GLOBAL_STATE_CONFIGURED;\r
- UDP_ENDPOINT_CSR(1) = UDP_CSR_ENABLE_EP |\r
- UDP_CSR_EPTYPE_INTERRUPT_OUT;\r
- UDP_ENDPOINT_CSR(2) = UDP_CSR_ENABLE_EP |\r
- UDP_CSR_EPTYPE_INTERRUPT_IN;\r
+ AT91C_BASE_UDP->UDP_GLBSTATE = AT91C_UDP_CONFG;\r
+ AT91C_BASE_UDP->UDP_CSR[1] = AT91C_UDP_EPEDS |\r
+ AT91C_UDP_EPTYPE_INT_OUT;\r
+ AT91C_BASE_UDP->UDP_CSR[2] = AT91C_UDP_EPEDS |\r
+ AT91C_UDP_EPTYPE_INT_IN;\r
} else {\r
- UDP_GLOBAL_STATE = UDP_GLOBAL_STATE_ADDRESSED;\r
- UDP_ENDPOINT_CSR(1) = 0;\r
- UDP_ENDPOINT_CSR(2) = 0;\r
+ AT91C_BASE_UDP->UDP_GLBSTATE = AT91C_UDP_FADDEN;\r
+ AT91C_BASE_UDP->UDP_CSR[1] = 0;\r
+ AT91C_BASE_UDP->UDP_CSR[2] = 0;\r
}\r
UsbSendZeroLength();\r
break;\r
thisTime = min(len, 8);\r
\r
for(i = 0; i < thisTime; i++) {\r
- UDP_ENDPOINT_FIFO(2) = packet[i];\r
+ AT91C_BASE_UDP->UDP_FDR[2] = packet[i];\r
}\r
- UDP_ENDPOINT_CSR(2) |= UDP_CSR_TX_PACKET;\r
+ AT91C_BASE_UDP->UDP_CSR[2] |= AT91C_UDP_TXPKTRDY;\r
\r
- while(!(UDP_ENDPOINT_CSR(2) & UDP_CSR_TX_PACKET_ACKED))\r
+ while(!(AT91C_BASE_UDP->UDP_CSR[2] & AT91C_UDP_TXCOMP))\r
;\r
- UDP_ENDPOINT_CSR(2) &= ~UDP_CSR_TX_PACKET_ACKED;\r
+ AT91C_BASE_UDP->UDP_CSR[2] &= ~AT91C_UDP_TXCOMP;\r
\r
- while(UDP_ENDPOINT_CSR(2) & UDP_CSR_TX_PACKET_ACKED)\r
+ while(AT91C_BASE_UDP->UDP_CSR[2] & AT91C_UDP_TXCOMP)\r
;\r
\r
len -= thisTime;\r
{\r
int i, len;\r
\r
- if(UDP_ENDPOINT_CSR(1) & UDP_CSR_RX_PACKET_RECEIVED_BANK_0) {\r
- len = UDP_CSR_BYTES_RECEIVED(UDP_ENDPOINT_CSR(1));\r
+ if(AT91C_BASE_UDP->UDP_CSR[1] & AT91C_UDP_RX_DATA_BK0) {\r
+ len = UDP_CSR_BYTES_RECEIVED(AT91C_BASE_UDP->UDP_CSR[1]);\r
\r
for(i = 0; i < len; i++) {\r
- UsbBuffer[UsbSoFarCount] = UDP_ENDPOINT_FIFO(1);\r
+ UsbBuffer[UsbSoFarCount] = AT91C_BASE_UDP->UDP_FDR[1];\r
UsbSoFarCount++;\r
}\r
\r
- UDP_ENDPOINT_CSR(1) &= ~UDP_CSR_RX_PACKET_RECEIVED_BANK_0;\r
- while(UDP_ENDPOINT_CSR(1) & UDP_CSR_RX_PACKET_RECEIVED_BANK_0)\r
+ AT91C_BASE_UDP->UDP_CSR[1] &= ~AT91C_UDP_RX_DATA_BK0;\r
+ while(AT91C_BASE_UDP->UDP_CSR[1] & AT91C_UDP_RX_DATA_BK0)\r
;\r
\r
if(UsbSoFarCount >= 64) {\r
}\r
}\r
\r
- if(UDP_ENDPOINT_CSR(1) & UDP_CSR_RX_PACKET_RECEIVED_BANK_1) {\r
- len = UDP_CSR_BYTES_RECEIVED(UDP_ENDPOINT_CSR(1));\r
+ if(AT91C_BASE_UDP->UDP_CSR[1] & AT91C_UDP_RX_DATA_BK1) {\r
+ len = UDP_CSR_BYTES_RECEIVED(AT91C_BASE_UDP->UDP_CSR[1]);\r
\r
for(i = 0; i < len; i++) {\r
- UsbBuffer[UsbSoFarCount] = UDP_ENDPOINT_FIFO(1);\r
+ UsbBuffer[UsbSoFarCount] = AT91C_BASE_UDP->UDP_FDR[1];\r
UsbSoFarCount++;\r
}\r
\r
- UDP_ENDPOINT_CSR(1) &= ~UDP_CSR_RX_PACKET_RECEIVED_BANK_1;\r
- while(UDP_ENDPOINT_CSR(1) & UDP_CSR_RX_PACKET_RECEIVED_BANK_1)\r
+ AT91C_BASE_UDP->UDP_CSR[1] &= ~AT91C_UDP_RX_DATA_BK1;\r
+ while(AT91C_BASE_UDP->UDP_CSR[1] & AT91C_UDP_RX_DATA_BK1)\r
;\r
\r
if(UsbSoFarCount >= 64) {\r
\r
USB_D_PLUS_PULLUP_ON();\r
\r
- if(UDP_INTERRUPT_STATUS & UDP_INTERRUPT_END_OF_BUS_RESET) {\r
- UDP_INTERRUPT_CLEAR = UDP_INTERRUPT_END_OF_BUS_RESET;\r
+ if(AT91C_BASE_UDP->UDP_ISR & AT91C_UDP_ENDBUSRES) {\r
+ AT91C_BASE_UDP->UDP_ICR = AT91C_UDP_ENDBUSRES;\r
}\r
}\r
\r
BOOL UsbConnected()\r
{\r
- if (UDP_GLOBAL_STATE & UDP_GLOBAL_STATE_CONFIGURED)\r
+ if (AT91C_BASE_UDP->UDP_GLBSTATE & AT91C_UDP_CONFG)\r
return TRUE;\r
else\r
return FALSE;\r
{\r
BOOL ret = FALSE;\r
\r
- if(UDP_INTERRUPT_STATUS & UDP_INTERRUPT_END_OF_BUS_RESET) {\r
- UDP_INTERRUPT_CLEAR = UDP_INTERRUPT_END_OF_BUS_RESET;\r
+ if(AT91C_BASE_UDP->UDP_ISR & AT91C_UDP_ENDBUSRES) {\r
+ AT91C_BASE_UDP->UDP_ICR = AT91C_UDP_ENDBUSRES;\r
\r
// following a reset we should be ready to receive a setup packet\r
- UDP_RESET_ENDPOINT = 0xf;\r
- UDP_RESET_ENDPOINT = 0;\r
+ AT91C_BASE_UDP->UDP_RSTEP = 0xf;\r
+ AT91C_BASE_UDP->UDP_RSTEP = 0;\r
\r
- UDP_FUNCTION_ADDR = UDP_FUNCTION_ADDR_ENABLED;\r
+ AT91C_BASE_UDP->UDP_FADDR = AT91C_UDP_FEN;\r
\r
- UDP_ENDPOINT_CSR(0) = UDP_CSR_EPTYPE_CONTROL | UDP_CSR_ENABLE_EP;\r
+ AT91C_BASE_UDP->UDP_CSR[0] = AT91C_UDP_EPTYPE_CTRL | AT91C_UDP_EPEDS;\r
\r
CurrentConfiguration = 0;\r
\r
ret = TRUE;\r
}\r
\r
- if(UDP_INTERRUPT_STATUS & UDP_INTERRUPT_ENDPOINT(0)) {\r
- if(UDP_ENDPOINT_CSR(0) & UDP_CSR_RX_HAVE_READ_SETUP_DATA) {\r
+ if(AT91C_BASE_UDP->UDP_ISR & UDP_INTERRUPT_ENDPOINT(0)) {\r
+ if(AT91C_BASE_UDP->UDP_CSR[0] & AT91C_UDP_RXSETUP) {\r
HandleRxdSetupData();\r
ret = TRUE;\r
}\r
}\r
\r
- if(UDP_INTERRUPT_STATUS & UDP_INTERRUPT_ENDPOINT(1)) {\r
+ if(AT91C_BASE_UDP->UDP_ISR & UDP_INTERRUPT_ENDPOINT(1)) {\r
HandleRxdData();\r
ret = TRUE;\r
}\r