This package contains a simple test of tests for various elements of the SmartBoard hardware, which is a simple baseboard designed for easy embedding. It is able to run both a semi-automatic test suite as well as allow interactive testing.

Dependencies:   EthernetNetIf NTPClient_NetServices mbed

This program is most of what you need to test your SmartBoard baseboard hardware. It provides a means to test the following:

  • Two channels of CAN (with a loopback cable)
  • RS-232 Ports
  • Analog inputs
  • PWM outputs
  • Ethernet port
  • Real time clock
  • micro SD
  • USB Host port
Committer:
WiredHome
Date:
Thu Mar 31 11:22:00 2011 +0000
Revision:
4:ca93a8d4874d
Minor revisions to the help text

Who changed what in which revision?

UserRevisionLine numberNew contents of line
WiredHome 4:ca93a8d4874d 1 /*
WiredHome 4:ca93a8d4874d 2 **************************************************************************************************************
WiredHome 4:ca93a8d4874d 3 * NXP USB Host Stack
WiredHome 4:ca93a8d4874d 4 *
WiredHome 4:ca93a8d4874d 5 * (c) Copyright 2008, NXP SemiConductors
WiredHome 4:ca93a8d4874d 6 * (c) Copyright 2008, OnChip Technologies LLC
WiredHome 4:ca93a8d4874d 7 * All Rights Reserved
WiredHome 4:ca93a8d4874d 8 *
WiredHome 4:ca93a8d4874d 9 * www.nxp.com
WiredHome 4:ca93a8d4874d 10 * www.onchiptech.com
WiredHome 4:ca93a8d4874d 11 *
WiredHome 4:ca93a8d4874d 12 * File : usbhost_lpc17xx.c
WiredHome 4:ca93a8d4874d 13 * Programmer(s) : Ravikanth.P
WiredHome 4:ca93a8d4874d 14 * Version :
WiredHome 4:ca93a8d4874d 15 *
WiredHome 4:ca93a8d4874d 16 **************************************************************************************************************
WiredHome 4:ca93a8d4874d 17 */
WiredHome 4:ca93a8d4874d 18
WiredHome 4:ca93a8d4874d 19 /*
WiredHome 4:ca93a8d4874d 20 **************************************************************************************************************
WiredHome 4:ca93a8d4874d 21 * INCLUDE HEADER FILES
WiredHome 4:ca93a8d4874d 22 **************************************************************************************************************
WiredHome 4:ca93a8d4874d 23 */
WiredHome 4:ca93a8d4874d 24
WiredHome 4:ca93a8d4874d 25 #include "usbhost_lpc17xx.h"
WiredHome 4:ca93a8d4874d 26
WiredHome 4:ca93a8d4874d 27 // Added DEBUG_X to eliminate annoying print statements
WiredHome 4:ca93a8d4874d 28 // Copyright (c) 2011, David Smart
WiredHome 4:ca93a8d4874d 29
WiredHome 4:ca93a8d4874d 30 // define for additional details
WiredHome 4:ca93a8d4874d 31 //#define DEBUG_X
WiredHome 4:ca93a8d4874d 32
WiredHome 4:ca93a8d4874d 33 /*
WiredHome 4:ca93a8d4874d 34 **************************************************************************************************************
WiredHome 4:ca93a8d4874d 35 * GLOBAL VARIABLES
WiredHome 4:ca93a8d4874d 36 **************************************************************************************************************
WiredHome 4:ca93a8d4874d 37 */
WiredHome 4:ca93a8d4874d 38 int gUSBConnected;
WiredHome 4:ca93a8d4874d 39
WiredHome 4:ca93a8d4874d 40 volatile USB_INT32U HOST_RhscIntr = 0; /* Root Hub Status Change interrupt */
WiredHome 4:ca93a8d4874d 41 volatile USB_INT32U HOST_WdhIntr = 0; /* Semaphore to wait until the TD is submitted */
WiredHome 4:ca93a8d4874d 42 volatile USB_INT08U HOST_TDControlStatus = 0;
WiredHome 4:ca93a8d4874d 43 volatile HCED *EDCtrl; /* Control endpoint descriptor structure */
WiredHome 4:ca93a8d4874d 44 volatile HCED *EDBulkIn; /* BulkIn endpoint descriptor structure */
WiredHome 4:ca93a8d4874d 45 volatile HCED *EDBulkOut; /* BulkOut endpoint descriptor structure */
WiredHome 4:ca93a8d4874d 46 volatile HCTD *TDHead; /* Head transfer descriptor structure */
WiredHome 4:ca93a8d4874d 47 volatile HCTD *TDTail; /* Tail transfer descriptor structure */
WiredHome 4:ca93a8d4874d 48 volatile HCCA *Hcca; /* Host Controller Communications Area structure */
WiredHome 4:ca93a8d4874d 49 USB_INT16U *TDBufNonVol; /* Identical to TDBuffer just to reduce compiler warnings */
WiredHome 4:ca93a8d4874d 50 volatile USB_INT08U *TDBuffer; /* Current Buffer Pointer of transfer descriptor */
WiredHome 4:ca93a8d4874d 51
WiredHome 4:ca93a8d4874d 52 // USB host structures
WiredHome 4:ca93a8d4874d 53 // AHB SRAM block 1
WiredHome 4:ca93a8d4874d 54 #define HOSTBASEADDR 0x2007C000
WiredHome 4:ca93a8d4874d 55 // reserve memory for the linker
WiredHome 4:ca93a8d4874d 56 static USB_INT08U HostBuf[0x200] __attribute__((at(HOSTBASEADDR)));
WiredHome 4:ca93a8d4874d 57 /*
WiredHome 4:ca93a8d4874d 58 **************************************************************************************************************
WiredHome 4:ca93a8d4874d 59 * DELAY IN MILLI SECONDS
WiredHome 4:ca93a8d4874d 60 *
WiredHome 4:ca93a8d4874d 61 * Description: This function provides a delay in milli seconds
WiredHome 4:ca93a8d4874d 62 *
WiredHome 4:ca93a8d4874d 63 * Arguments : delay The delay required
WiredHome 4:ca93a8d4874d 64 *
WiredHome 4:ca93a8d4874d 65 * Returns : None
WiredHome 4:ca93a8d4874d 66 *
WiredHome 4:ca93a8d4874d 67 **************************************************************************************************************
WiredHome 4:ca93a8d4874d 68 */
WiredHome 4:ca93a8d4874d 69
WiredHome 4:ca93a8d4874d 70 void Host_DelayMS (USB_INT32U delay)
WiredHome 4:ca93a8d4874d 71 {
WiredHome 4:ca93a8d4874d 72 volatile USB_INT32U i;
WiredHome 4:ca93a8d4874d 73
WiredHome 4:ca93a8d4874d 74
WiredHome 4:ca93a8d4874d 75 for (i = 0; i < delay; i++) {
WiredHome 4:ca93a8d4874d 76 Host_DelayUS(1000);
WiredHome 4:ca93a8d4874d 77 }
WiredHome 4:ca93a8d4874d 78 }
WiredHome 4:ca93a8d4874d 79
WiredHome 4:ca93a8d4874d 80 /*
WiredHome 4:ca93a8d4874d 81 **************************************************************************************************************
WiredHome 4:ca93a8d4874d 82 * DELAY IN MICRO SECONDS
WiredHome 4:ca93a8d4874d 83 *
WiredHome 4:ca93a8d4874d 84 * Description: This function provides a delay in micro seconds
WiredHome 4:ca93a8d4874d 85 *
WiredHome 4:ca93a8d4874d 86 * Arguments : delay The delay required
WiredHome 4:ca93a8d4874d 87 *
WiredHome 4:ca93a8d4874d 88 * Returns : None
WiredHome 4:ca93a8d4874d 89 *
WiredHome 4:ca93a8d4874d 90 **************************************************************************************************************
WiredHome 4:ca93a8d4874d 91 */
WiredHome 4:ca93a8d4874d 92
WiredHome 4:ca93a8d4874d 93 void Host_DelayUS (USB_INT32U delay)
WiredHome 4:ca93a8d4874d 94 {
WiredHome 4:ca93a8d4874d 95 volatile USB_INT32U i;
WiredHome 4:ca93a8d4874d 96
WiredHome 4:ca93a8d4874d 97
WiredHome 4:ca93a8d4874d 98 for (i = 0; i < (4 * delay); i++) { /* This logic was tested. It gives app. 1 micro sec delay */
WiredHome 4:ca93a8d4874d 99 ;
WiredHome 4:ca93a8d4874d 100 }
WiredHome 4:ca93a8d4874d 101 }
WiredHome 4:ca93a8d4874d 102
WiredHome 4:ca93a8d4874d 103 // bits of the USB/OTG clock control register
WiredHome 4:ca93a8d4874d 104 #define HOST_CLK_EN (1<<0)
WiredHome 4:ca93a8d4874d 105 #define DEV_CLK_EN (1<<1)
WiredHome 4:ca93a8d4874d 106 #define PORTSEL_CLK_EN (1<<3)
WiredHome 4:ca93a8d4874d 107 #define AHB_CLK_EN (1<<4)
WiredHome 4:ca93a8d4874d 108
WiredHome 4:ca93a8d4874d 109 // bits of the USB/OTG clock status register
WiredHome 4:ca93a8d4874d 110 #define HOST_CLK_ON (1<<0)
WiredHome 4:ca93a8d4874d 111 #define DEV_CLK_ON (1<<1)
WiredHome 4:ca93a8d4874d 112 #define PORTSEL_CLK_ON (1<<3)
WiredHome 4:ca93a8d4874d 113 #define AHB_CLK_ON (1<<4)
WiredHome 4:ca93a8d4874d 114
WiredHome 4:ca93a8d4874d 115 // we need host clock, OTG/portsel clock and AHB clock
WiredHome 4:ca93a8d4874d 116 #define CLOCK_MASK (HOST_CLK_EN | PORTSEL_CLK_EN | AHB_CLK_EN)
WiredHome 4:ca93a8d4874d 117
WiredHome 4:ca93a8d4874d 118 /*
WiredHome 4:ca93a8d4874d 119 **************************************************************************************************************
WiredHome 4:ca93a8d4874d 120 * INITIALIZE THE HOST CONTROLLER
WiredHome 4:ca93a8d4874d 121 *
WiredHome 4:ca93a8d4874d 122 * Description: This function initializes lpc17xx host controller
WiredHome 4:ca93a8d4874d 123 *
WiredHome 4:ca93a8d4874d 124 * Arguments : None
WiredHome 4:ca93a8d4874d 125 *
WiredHome 4:ca93a8d4874d 126 * Returns :
WiredHome 4:ca93a8d4874d 127 *
WiredHome 4:ca93a8d4874d 128 **************************************************************************************************************
WiredHome 4:ca93a8d4874d 129 */
WiredHome 4:ca93a8d4874d 130 void Host_Init (void)
WiredHome 4:ca93a8d4874d 131 {
WiredHome 4:ca93a8d4874d 132 #ifdef DEBUG_X
WiredHome 4:ca93a8d4874d 133 PRINT_Log("In Host_Init\n");
WiredHome 4:ca93a8d4874d 134 #endif
WiredHome 4:ca93a8d4874d 135 NVIC_DisableIRQ(USB_IRQn); /* Disable the USB interrupt source */
WiredHome 4:ca93a8d4874d 136
WiredHome 4:ca93a8d4874d 137 // turn on power for USB
WiredHome 4:ca93a8d4874d 138 LPC_SC->PCONP |= (1UL<<31);
WiredHome 4:ca93a8d4874d 139 // Enable USB host clock, port selection and AHB clock
WiredHome 4:ca93a8d4874d 140 LPC_USB->USBClkCtrl |= CLOCK_MASK;
WiredHome 4:ca93a8d4874d 141 // Wait for clocks to become available
WiredHome 4:ca93a8d4874d 142 while ((LPC_USB->USBClkSt & CLOCK_MASK) != CLOCK_MASK)
WiredHome 4:ca93a8d4874d 143 ;
WiredHome 4:ca93a8d4874d 144
WiredHome 4:ca93a8d4874d 145 // it seems the bits[0:1] mean the following
WiredHome 4:ca93a8d4874d 146 // 0: U1=device, U2=host
WiredHome 4:ca93a8d4874d 147 // 1: U1=host, U2=host
WiredHome 4:ca93a8d4874d 148 // 2: reserved
WiredHome 4:ca93a8d4874d 149 // 3: U1=host, U2=device
WiredHome 4:ca93a8d4874d 150 // NB: this register is only available if OTG clock (aka "port select") is enabled!!
WiredHome 4:ca93a8d4874d 151 // since we don't care about port 2, set just bit 0 to 1 (U1=host)
WiredHome 4:ca93a8d4874d 152 LPC_USB->OTGStCtrl |= 1;
WiredHome 4:ca93a8d4874d 153
WiredHome 4:ca93a8d4874d 154 // now that we've configured the ports, we can turn off the portsel clock
WiredHome 4:ca93a8d4874d 155 LPC_USB->USBClkCtrl &= ~PORTSEL_CLK_EN;
WiredHome 4:ca93a8d4874d 156
WiredHome 4:ca93a8d4874d 157 // power pins are not connected on mbed, so we can skip them
WiredHome 4:ca93a8d4874d 158 /* P1[18] = USB_UP_LED, 01 */
WiredHome 4:ca93a8d4874d 159 /* P1[19] = /USB_PPWR, 10 */
WiredHome 4:ca93a8d4874d 160 /* P1[22] = USB_PWRD, 10 */
WiredHome 4:ca93a8d4874d 161 /* P1[27] = /USB_OVRCR, 10 */
WiredHome 4:ca93a8d4874d 162 /*LPC_PINCON->PINSEL3 &= ~((3<<4) | (3<<6) | (3<<12) | (3<<22));
WiredHome 4:ca93a8d4874d 163 LPC_PINCON->PINSEL3 |= ((1<<4)|(2<<6) | (2<<12) | (2<<22)); // 0x00802080
WiredHome 4:ca93a8d4874d 164 */
WiredHome 4:ca93a8d4874d 165
WiredHome 4:ca93a8d4874d 166 // configure USB D+/D- pins
WiredHome 4:ca93a8d4874d 167 /* P0[29] = USB_D+, 01 */
WiredHome 4:ca93a8d4874d 168 /* P0[30] = USB_D-, 01 */
WiredHome 4:ca93a8d4874d 169 LPC_PINCON->PINSEL1 &= ~((3<<26) | (3<<28));
WiredHome 4:ca93a8d4874d 170 LPC_PINCON->PINSEL1 |= ((1<<26)|(1<<28)); // 0x14000000
WiredHome 4:ca93a8d4874d 171
WiredHome 4:ca93a8d4874d 172 #ifdef DEBUG_X
WiredHome 4:ca93a8d4874d 173 PRINT_Log("Initializing Host Stack\n");
WiredHome 4:ca93a8d4874d 174 #endif
WiredHome 4:ca93a8d4874d 175
WiredHome 4:ca93a8d4874d 176 Hcca = (volatile HCCA *)(HostBuf+0x000);
WiredHome 4:ca93a8d4874d 177 TDHead = (volatile HCTD *)(HostBuf+0x100);
WiredHome 4:ca93a8d4874d 178 TDTail = (volatile HCTD *)(HostBuf+0x110);
WiredHome 4:ca93a8d4874d 179 EDCtrl = (volatile HCED *)(HostBuf+0x120);
WiredHome 4:ca93a8d4874d 180 EDBulkIn = (volatile HCED *)(HostBuf+0x130);
WiredHome 4:ca93a8d4874d 181 EDBulkOut = (volatile HCED *)(HostBuf+0x140);
WiredHome 4:ca93a8d4874d 182 TDBuffer = (volatile USB_INT08U *)(HostBuf+0x150);
WiredHome 4:ca93a8d4874d 183
WiredHome 4:ca93a8d4874d 184 /* Initialize all the TDs, EDs and HCCA to 0 */
WiredHome 4:ca93a8d4874d 185 Host_EDInit(EDCtrl);
WiredHome 4:ca93a8d4874d 186 Host_EDInit(EDBulkIn);
WiredHome 4:ca93a8d4874d 187 Host_EDInit(EDBulkOut);
WiredHome 4:ca93a8d4874d 188 Host_TDInit(TDHead);
WiredHome 4:ca93a8d4874d 189 Host_TDInit(TDTail);
WiredHome 4:ca93a8d4874d 190 Host_HCCAInit(Hcca);
WiredHome 4:ca93a8d4874d 191
WiredHome 4:ca93a8d4874d 192 Host_DelayMS(50); /* Wait 50 ms before apply reset */
WiredHome 4:ca93a8d4874d 193 LPC_USB->HcControl = 0; /* HARDWARE RESET */
WiredHome 4:ca93a8d4874d 194 LPC_USB->HcControlHeadED = 0; /* Initialize Control list head to Zero */
WiredHome 4:ca93a8d4874d 195 LPC_USB->HcBulkHeadED = 0; /* Initialize Bulk list head to Zero */
WiredHome 4:ca93a8d4874d 196
WiredHome 4:ca93a8d4874d 197 /* SOFTWARE RESET */
WiredHome 4:ca93a8d4874d 198 LPC_USB->HcCommandStatus = OR_CMD_STATUS_HCR;
WiredHome 4:ca93a8d4874d 199 LPC_USB->HcFmInterval = DEFAULT_FMINTERVAL; /* Write Fm Interval and Largest Data Packet Counter */
WiredHome 4:ca93a8d4874d 200
WiredHome 4:ca93a8d4874d 201 /* Put HC in operational state */
WiredHome 4:ca93a8d4874d 202 LPC_USB->HcControl = (LPC_USB->HcControl & (~OR_CONTROL_HCFS)) | OR_CONTROL_HC_OPER;
WiredHome 4:ca93a8d4874d 203 LPC_USB->HcRhStatus = OR_RH_STATUS_LPSC; /* Set Global Power */
WiredHome 4:ca93a8d4874d 204
WiredHome 4:ca93a8d4874d 205 LPC_USB->HcHCCA = (USB_INT32U)Hcca;
WiredHome 4:ca93a8d4874d 206 LPC_USB->HcInterruptStatus |= LPC_USB->HcInterruptStatus; /* Clear Interrrupt Status */
WiredHome 4:ca93a8d4874d 207
WiredHome 4:ca93a8d4874d 208
WiredHome 4:ca93a8d4874d 209 LPC_USB->HcInterruptEnable = OR_INTR_ENABLE_MIE |
WiredHome 4:ca93a8d4874d 210 OR_INTR_ENABLE_WDH |
WiredHome 4:ca93a8d4874d 211 OR_INTR_ENABLE_RHSC;
WiredHome 4:ca93a8d4874d 212
WiredHome 4:ca93a8d4874d 213 NVIC_SetPriority(USB_IRQn, 0); /* highest priority */
WiredHome 4:ca93a8d4874d 214 /* Enable the USB Interrupt */
WiredHome 4:ca93a8d4874d 215 NVIC_EnableIRQ(USB_IRQn);
WiredHome 4:ca93a8d4874d 216 #ifdef DEBUG_X
WiredHome 4:ca93a8d4874d 217 PRINT_Log("Host Initialized\n");
WiredHome 4:ca93a8d4874d 218 #endif
WiredHome 4:ca93a8d4874d 219 }
WiredHome 4:ca93a8d4874d 220
WiredHome 4:ca93a8d4874d 221 /*
WiredHome 4:ca93a8d4874d 222 **************************************************************************************************************
WiredHome 4:ca93a8d4874d 223 * INTERRUPT SERVICE ROUTINE
WiredHome 4:ca93a8d4874d 224 *
WiredHome 4:ca93a8d4874d 225 * Description: This function services the interrupt caused by host controller
WiredHome 4:ca93a8d4874d 226 *
WiredHome 4:ca93a8d4874d 227 * Arguments : None
WiredHome 4:ca93a8d4874d 228 *
WiredHome 4:ca93a8d4874d 229 * Returns : None
WiredHome 4:ca93a8d4874d 230 *
WiredHome 4:ca93a8d4874d 231 **************************************************************************************************************
WiredHome 4:ca93a8d4874d 232 */
WiredHome 4:ca93a8d4874d 233
WiredHome 4:ca93a8d4874d 234 void USB_IRQHandler (void) __irq
WiredHome 4:ca93a8d4874d 235 {
WiredHome 4:ca93a8d4874d 236 USB_INT32U int_status;
WiredHome 4:ca93a8d4874d 237 USB_INT32U ie_status;
WiredHome 4:ca93a8d4874d 238
WiredHome 4:ca93a8d4874d 239 int_status = LPC_USB->HcInterruptStatus; /* Read Interrupt Status */
WiredHome 4:ca93a8d4874d 240 ie_status = LPC_USB->HcInterruptEnable; /* Read Interrupt enable status */
WiredHome 4:ca93a8d4874d 241
WiredHome 4:ca93a8d4874d 242 if (!(int_status & ie_status)) {
WiredHome 4:ca93a8d4874d 243 return;
WiredHome 4:ca93a8d4874d 244 } else {
WiredHome 4:ca93a8d4874d 245
WiredHome 4:ca93a8d4874d 246 int_status = int_status & ie_status;
WiredHome 4:ca93a8d4874d 247 if (int_status & OR_INTR_STATUS_RHSC) { /* Root hub status change interrupt */
WiredHome 4:ca93a8d4874d 248 if (LPC_USB->HcRhPortStatus1 & OR_RH_PORT_CSC) {
WiredHome 4:ca93a8d4874d 249 if (LPC_USB->HcRhStatus & OR_RH_STATUS_DRWE) {
WiredHome 4:ca93a8d4874d 250 /*
WiredHome 4:ca93a8d4874d 251 * When DRWE is on, Connect Status Change
WiredHome 4:ca93a8d4874d 252 * means a remote wakeup event.
WiredHome 4:ca93a8d4874d 253 */
WiredHome 4:ca93a8d4874d 254 HOST_RhscIntr = 1;// JUST SOMETHING FOR A BREAKPOINT
WiredHome 4:ca93a8d4874d 255 }
WiredHome 4:ca93a8d4874d 256 else {
WiredHome 4:ca93a8d4874d 257 /*
WiredHome 4:ca93a8d4874d 258 * When DRWE is off, Connect Status Change
WiredHome 4:ca93a8d4874d 259 * is NOT a remote wakeup event
WiredHome 4:ca93a8d4874d 260 */
WiredHome 4:ca93a8d4874d 261 if (LPC_USB->HcRhPortStatus1 & OR_RH_PORT_CCS) {
WiredHome 4:ca93a8d4874d 262 if (!gUSBConnected) {
WiredHome 4:ca93a8d4874d 263 HOST_TDControlStatus = 0;
WiredHome 4:ca93a8d4874d 264 HOST_WdhIntr = 0;
WiredHome 4:ca93a8d4874d 265 HOST_RhscIntr = 1;
WiredHome 4:ca93a8d4874d 266 gUSBConnected = 1;
WiredHome 4:ca93a8d4874d 267 }
WiredHome 4:ca93a8d4874d 268 else {
WiredHome 4:ca93a8d4874d 269 #ifdef DEBUG_X
WiredHome 4:ca93a8d4874d 270 PRINT_Log("Spurious status change (connected)?\n");
WiredHome 4:ca93a8d4874d 271 #endif
WiredHome 4:ca93a8d4874d 272 }
WiredHome 4:ca93a8d4874d 273 } else {
WiredHome 4:ca93a8d4874d 274 if (gUSBConnected) {
WiredHome 4:ca93a8d4874d 275 LPC_USB->HcInterruptEnable = 0; // why do we get multiple disc. rupts???
WiredHome 4:ca93a8d4874d 276 HOST_RhscIntr = 0;
WiredHome 4:ca93a8d4874d 277 gUSBConnected = 0;
WiredHome 4:ca93a8d4874d 278 }
WiredHome 4:ca93a8d4874d 279 else {
WiredHome 4:ca93a8d4874d 280 #ifdef DEBUG_X
WiredHome 4:ca93a8d4874d 281 PRINT_Log("Spurious status change (disconnected)?\n");
WiredHome 4:ca93a8d4874d 282 #endif
WiredHome 4:ca93a8d4874d 283 }
WiredHome 4:ca93a8d4874d 284 }
WiredHome 4:ca93a8d4874d 285 }
WiredHome 4:ca93a8d4874d 286 LPC_USB->HcRhPortStatus1 = OR_RH_PORT_CSC;
WiredHome 4:ca93a8d4874d 287 }
WiredHome 4:ca93a8d4874d 288 if (LPC_USB->HcRhPortStatus1 & OR_RH_PORT_PRSC) {
WiredHome 4:ca93a8d4874d 289 LPC_USB->HcRhPortStatus1 = OR_RH_PORT_PRSC;
WiredHome 4:ca93a8d4874d 290 }
WiredHome 4:ca93a8d4874d 291 }
WiredHome 4:ca93a8d4874d 292 if (int_status & OR_INTR_STATUS_WDH) { /* Writeback Done Head interrupt */
WiredHome 4:ca93a8d4874d 293 HOST_WdhIntr = 1;
WiredHome 4:ca93a8d4874d 294 HOST_TDControlStatus = (TDHead->Control >> 28) & 0xf;
WiredHome 4:ca93a8d4874d 295 }
WiredHome 4:ca93a8d4874d 296 LPC_USB->HcInterruptStatus = int_status; /* Clear interrupt status register */
WiredHome 4:ca93a8d4874d 297 }
WiredHome 4:ca93a8d4874d 298 return;
WiredHome 4:ca93a8d4874d 299 }
WiredHome 4:ca93a8d4874d 300
WiredHome 4:ca93a8d4874d 301 /*
WiredHome 4:ca93a8d4874d 302 **************************************************************************************************************
WiredHome 4:ca93a8d4874d 303 * PROCESS TRANSFER DESCRIPTOR
WiredHome 4:ca93a8d4874d 304 *
WiredHome 4:ca93a8d4874d 305 * Description: This function processes the transfer descriptor
WiredHome 4:ca93a8d4874d 306 *
WiredHome 4:ca93a8d4874d 307 * Arguments : ed Endpoint descriptor that contains this transfer descriptor
WiredHome 4:ca93a8d4874d 308 * token SETUP, IN, OUT
WiredHome 4:ca93a8d4874d 309 * buffer Current Buffer Pointer of the transfer descriptor
WiredHome 4:ca93a8d4874d 310 * buffer_len Length of the buffer
WiredHome 4:ca93a8d4874d 311 *
WiredHome 4:ca93a8d4874d 312 * Returns : OK if TD submission is successful
WiredHome 4:ca93a8d4874d 313 * ERROR if TD submission fails
WiredHome 4:ca93a8d4874d 314 *
WiredHome 4:ca93a8d4874d 315 **************************************************************************************************************
WiredHome 4:ca93a8d4874d 316 */
WiredHome 4:ca93a8d4874d 317
WiredHome 4:ca93a8d4874d 318 USB_INT32S Host_ProcessTD (volatile HCED *ed,
WiredHome 4:ca93a8d4874d 319 volatile USB_INT32U token,
WiredHome 4:ca93a8d4874d 320 volatile USB_INT08U *buffer,
WiredHome 4:ca93a8d4874d 321 USB_INT32U buffer_len)
WiredHome 4:ca93a8d4874d 322 {
WiredHome 4:ca93a8d4874d 323 volatile USB_INT32U td_toggle;
WiredHome 4:ca93a8d4874d 324
WiredHome 4:ca93a8d4874d 325
WiredHome 4:ca93a8d4874d 326 if (ed == EDCtrl) {
WiredHome 4:ca93a8d4874d 327 if (token == TD_SETUP) {
WiredHome 4:ca93a8d4874d 328 td_toggle = TD_TOGGLE_0;
WiredHome 4:ca93a8d4874d 329 } else {
WiredHome 4:ca93a8d4874d 330 td_toggle = TD_TOGGLE_1;
WiredHome 4:ca93a8d4874d 331 }
WiredHome 4:ca93a8d4874d 332 } else {
WiredHome 4:ca93a8d4874d 333 td_toggle = 0;
WiredHome 4:ca93a8d4874d 334 }
WiredHome 4:ca93a8d4874d 335 TDHead->Control = (TD_ROUNDING |
WiredHome 4:ca93a8d4874d 336 token |
WiredHome 4:ca93a8d4874d 337 TD_DELAY_INT(0) |
WiredHome 4:ca93a8d4874d 338 td_toggle |
WiredHome 4:ca93a8d4874d 339 TD_CC);
WiredHome 4:ca93a8d4874d 340 TDTail->Control = 0;
WiredHome 4:ca93a8d4874d 341 TDHead->CurrBufPtr = (USB_INT32U) buffer;
WiredHome 4:ca93a8d4874d 342 TDTail->CurrBufPtr = 0;
WiredHome 4:ca93a8d4874d 343 TDHead->Next = (USB_INT32U) TDTail;
WiredHome 4:ca93a8d4874d 344 TDTail->Next = 0;
WiredHome 4:ca93a8d4874d 345 TDHead->BufEnd = (USB_INT32U)(buffer + (buffer_len - 1));
WiredHome 4:ca93a8d4874d 346 TDTail->BufEnd = 0;
WiredHome 4:ca93a8d4874d 347
WiredHome 4:ca93a8d4874d 348 ed->HeadTd = (USB_INT32U)TDHead | ((ed->HeadTd) & 0x00000002);
WiredHome 4:ca93a8d4874d 349 ed->TailTd = (USB_INT32U)TDTail;
WiredHome 4:ca93a8d4874d 350 ed->Next = 0;
WiredHome 4:ca93a8d4874d 351
WiredHome 4:ca93a8d4874d 352 if (ed == EDCtrl) {
WiredHome 4:ca93a8d4874d 353 LPC_USB->HcControlHeadED = (USB_INT32U)ed;
WiredHome 4:ca93a8d4874d 354 LPC_USB->HcCommandStatus = LPC_USB->HcCommandStatus | OR_CMD_STATUS_CLF;
WiredHome 4:ca93a8d4874d 355 LPC_USB->HcControl = LPC_USB->HcControl | OR_CONTROL_CLE;
WiredHome 4:ca93a8d4874d 356 } else {
WiredHome 4:ca93a8d4874d 357 LPC_USB->HcBulkHeadED = (USB_INT32U)ed;
WiredHome 4:ca93a8d4874d 358 LPC_USB->HcCommandStatus = LPC_USB->HcCommandStatus | OR_CMD_STATUS_BLF;
WiredHome 4:ca93a8d4874d 359 LPC_USB->HcControl = LPC_USB->HcControl | OR_CONTROL_BLE;
WiredHome 4:ca93a8d4874d 360 }
WiredHome 4:ca93a8d4874d 361
WiredHome 4:ca93a8d4874d 362 Host_WDHWait();
WiredHome 4:ca93a8d4874d 363
WiredHome 4:ca93a8d4874d 364 // if (!(TDHead->Control & 0xF0000000)) {
WiredHome 4:ca93a8d4874d 365 if (!HOST_TDControlStatus) {
WiredHome 4:ca93a8d4874d 366 return (OK);
WiredHome 4:ca93a8d4874d 367 } else {
WiredHome 4:ca93a8d4874d 368 return (ERR_TD_FAIL);
WiredHome 4:ca93a8d4874d 369 }
WiredHome 4:ca93a8d4874d 370 }
WiredHome 4:ca93a8d4874d 371
WiredHome 4:ca93a8d4874d 372 /*
WiredHome 4:ca93a8d4874d 373 **************************************************************************************************************
WiredHome 4:ca93a8d4874d 374 * ENUMERATE THE DEVICE
WiredHome 4:ca93a8d4874d 375 *
WiredHome 4:ca93a8d4874d 376 * Description: This function is used to enumerate the device connected
WiredHome 4:ca93a8d4874d 377 *
WiredHome 4:ca93a8d4874d 378 * Arguments : None
WiredHome 4:ca93a8d4874d 379 *
WiredHome 4:ca93a8d4874d 380 * Returns : None
WiredHome 4:ca93a8d4874d 381 *
WiredHome 4:ca93a8d4874d 382 **************************************************************************************************************
WiredHome 4:ca93a8d4874d 383 */
WiredHome 4:ca93a8d4874d 384
WiredHome 4:ca93a8d4874d 385 USB_INT32S Host_EnumDev (void)
WiredHome 4:ca93a8d4874d 386 {
WiredHome 4:ca93a8d4874d 387 USB_INT32S rc;
WiredHome 4:ca93a8d4874d 388
WiredHome 4:ca93a8d4874d 389 #ifdef DEBUG_X
WiredHome 4:ca93a8d4874d 390 PRINT_Log("Connect a Mass Storage device\n");
WiredHome 4:ca93a8d4874d 391 #endif
WiredHome 4:ca93a8d4874d 392 while (!HOST_RhscIntr)
WiredHome 4:ca93a8d4874d 393 __WFI();
WiredHome 4:ca93a8d4874d 394 Host_DelayMS(100); /* USB 2.0 spec says atleast 50ms delay beore port reset */
WiredHome 4:ca93a8d4874d 395 LPC_USB->HcRhPortStatus1 = OR_RH_PORT_PRS; // Initiate port reset
WiredHome 4:ca93a8d4874d 396 while (LPC_USB->HcRhPortStatus1 & OR_RH_PORT_PRS)
WiredHome 4:ca93a8d4874d 397 __WFI(); // Wait for port reset to complete...
WiredHome 4:ca93a8d4874d 398 LPC_USB->HcRhPortStatus1 = OR_RH_PORT_PRSC; // ...and clear port reset signal
WiredHome 4:ca93a8d4874d 399 Host_DelayMS(200); /* Wait for 100 MS after port reset */
WiredHome 4:ca93a8d4874d 400
WiredHome 4:ca93a8d4874d 401 EDCtrl->Control = 8 << 16; /* Put max pkt size = 8 */
WiredHome 4:ca93a8d4874d 402 /* Read first 8 bytes of device desc */
WiredHome 4:ca93a8d4874d 403 rc = HOST_GET_DESCRIPTOR(USB_DESCRIPTOR_TYPE_DEVICE, 0, TDBuffer, 8);
WiredHome 4:ca93a8d4874d 404 if (rc != OK) {
WiredHome 4:ca93a8d4874d 405 PRINT_Err(rc);
WiredHome 4:ca93a8d4874d 406 return (rc);
WiredHome 4:ca93a8d4874d 407 }
WiredHome 4:ca93a8d4874d 408 EDCtrl->Control = TDBuffer[7] << 16; /* Get max pkt size of endpoint 0 */
WiredHome 4:ca93a8d4874d 409 rc = HOST_SET_ADDRESS(1); /* Set the device address to 1 */
WiredHome 4:ca93a8d4874d 410 if (rc != OK) {
WiredHome 4:ca93a8d4874d 411 PRINT_Err(rc);
WiredHome 4:ca93a8d4874d 412 return (rc);
WiredHome 4:ca93a8d4874d 413 }
WiredHome 4:ca93a8d4874d 414 Host_DelayMS(2);
WiredHome 4:ca93a8d4874d 415 EDCtrl->Control = (EDCtrl->Control) | 1; /* Modify control pipe with address 1 */
WiredHome 4:ca93a8d4874d 416 /* Get the configuration descriptor */
WiredHome 4:ca93a8d4874d 417 rc = HOST_GET_DESCRIPTOR(USB_DESCRIPTOR_TYPE_CONFIGURATION, 0, TDBuffer, 9);
WiredHome 4:ca93a8d4874d 418 if (rc != OK) {
WiredHome 4:ca93a8d4874d 419 PRINT_Err(rc);
WiredHome 4:ca93a8d4874d 420 return (rc);
WiredHome 4:ca93a8d4874d 421 }
WiredHome 4:ca93a8d4874d 422 /* Get the first configuration data */
WiredHome 4:ca93a8d4874d 423 rc = HOST_GET_DESCRIPTOR(USB_DESCRIPTOR_TYPE_CONFIGURATION, 0, TDBuffer, ReadLE16U(&TDBuffer[2]));
WiredHome 4:ca93a8d4874d 424 if (rc != OK) {
WiredHome 4:ca93a8d4874d 425 PRINT_Err(rc);
WiredHome 4:ca93a8d4874d 426 return (rc);
WiredHome 4:ca93a8d4874d 427 }
WiredHome 4:ca93a8d4874d 428 rc = MS_ParseConfiguration(); /* Parse the configuration */
WiredHome 4:ca93a8d4874d 429 if (rc != OK) {
WiredHome 4:ca93a8d4874d 430 PRINT_Err(rc);
WiredHome 4:ca93a8d4874d 431 return (rc);
WiredHome 4:ca93a8d4874d 432 }
WiredHome 4:ca93a8d4874d 433 rc = USBH_SET_CONFIGURATION(1); /* Select device configuration 1 */
WiredHome 4:ca93a8d4874d 434 if (rc != OK) {
WiredHome 4:ca93a8d4874d 435 PRINT_Err(rc);
WiredHome 4:ca93a8d4874d 436 }
WiredHome 4:ca93a8d4874d 437 Host_DelayMS(100); /* Some devices may require this delay */
WiredHome 4:ca93a8d4874d 438 return (rc);
WiredHome 4:ca93a8d4874d 439 }
WiredHome 4:ca93a8d4874d 440
WiredHome 4:ca93a8d4874d 441 /*
WiredHome 4:ca93a8d4874d 442 **************************************************************************************************************
WiredHome 4:ca93a8d4874d 443 * RECEIVE THE CONTROL INFORMATION
WiredHome 4:ca93a8d4874d 444 *
WiredHome 4:ca93a8d4874d 445 * Description: This function is used to receive the control information
WiredHome 4:ca93a8d4874d 446 *
WiredHome 4:ca93a8d4874d 447 * Arguments : bm_request_type
WiredHome 4:ca93a8d4874d 448 * b_request
WiredHome 4:ca93a8d4874d 449 * w_value
WiredHome 4:ca93a8d4874d 450 * w_index
WiredHome 4:ca93a8d4874d 451 * w_length
WiredHome 4:ca93a8d4874d 452 * buffer
WiredHome 4:ca93a8d4874d 453 *
WiredHome 4:ca93a8d4874d 454 * Returns : OK if Success
WiredHome 4:ca93a8d4874d 455 * ERROR if Failed
WiredHome 4:ca93a8d4874d 456 *
WiredHome 4:ca93a8d4874d 457 **************************************************************************************************************
WiredHome 4:ca93a8d4874d 458 */
WiredHome 4:ca93a8d4874d 459
WiredHome 4:ca93a8d4874d 460 USB_INT32S Host_CtrlRecv ( USB_INT08U bm_request_type,
WiredHome 4:ca93a8d4874d 461 USB_INT08U b_request,
WiredHome 4:ca93a8d4874d 462 USB_INT16U w_value,
WiredHome 4:ca93a8d4874d 463 USB_INT16U w_index,
WiredHome 4:ca93a8d4874d 464 USB_INT16U w_length,
WiredHome 4:ca93a8d4874d 465 volatile USB_INT08U *buffer)
WiredHome 4:ca93a8d4874d 466 {
WiredHome 4:ca93a8d4874d 467 USB_INT32S rc;
WiredHome 4:ca93a8d4874d 468
WiredHome 4:ca93a8d4874d 469
WiredHome 4:ca93a8d4874d 470 Host_FillSetup(bm_request_type, b_request, w_value, w_index, w_length);
WiredHome 4:ca93a8d4874d 471 rc = Host_ProcessTD(EDCtrl, TD_SETUP, TDBuffer, 8);
WiredHome 4:ca93a8d4874d 472 if (rc == OK) {
WiredHome 4:ca93a8d4874d 473 if (w_length) {
WiredHome 4:ca93a8d4874d 474 rc = Host_ProcessTD(EDCtrl, TD_IN, TDBuffer, w_length);
WiredHome 4:ca93a8d4874d 475 }
WiredHome 4:ca93a8d4874d 476 if (rc == OK) {
WiredHome 4:ca93a8d4874d 477 rc = Host_ProcessTD(EDCtrl, TD_OUT, NULL, 0);
WiredHome 4:ca93a8d4874d 478 }
WiredHome 4:ca93a8d4874d 479 }
WiredHome 4:ca93a8d4874d 480 return (rc);
WiredHome 4:ca93a8d4874d 481 }
WiredHome 4:ca93a8d4874d 482
WiredHome 4:ca93a8d4874d 483 /*
WiredHome 4:ca93a8d4874d 484 **************************************************************************************************************
WiredHome 4:ca93a8d4874d 485 * SEND THE CONTROL INFORMATION
WiredHome 4:ca93a8d4874d 486 *
WiredHome 4:ca93a8d4874d 487 * Description: This function is used to send the control information
WiredHome 4:ca93a8d4874d 488 *
WiredHome 4:ca93a8d4874d 489 * Arguments : None
WiredHome 4:ca93a8d4874d 490 *
WiredHome 4:ca93a8d4874d 491 * Returns : OK if Success
WiredHome 4:ca93a8d4874d 492 * ERR_INVALID_BOOTSIG if Failed
WiredHome 4:ca93a8d4874d 493 *
WiredHome 4:ca93a8d4874d 494 **************************************************************************************************************
WiredHome 4:ca93a8d4874d 495 */
WiredHome 4:ca93a8d4874d 496
WiredHome 4:ca93a8d4874d 497 USB_INT32S Host_CtrlSend ( USB_INT08U bm_request_type,
WiredHome 4:ca93a8d4874d 498 USB_INT08U b_request,
WiredHome 4:ca93a8d4874d 499 USB_INT16U w_value,
WiredHome 4:ca93a8d4874d 500 USB_INT16U w_index,
WiredHome 4:ca93a8d4874d 501 USB_INT16U w_length,
WiredHome 4:ca93a8d4874d 502 volatile USB_INT08U *buffer)
WiredHome 4:ca93a8d4874d 503 {
WiredHome 4:ca93a8d4874d 504 USB_INT32S rc;
WiredHome 4:ca93a8d4874d 505
WiredHome 4:ca93a8d4874d 506
WiredHome 4:ca93a8d4874d 507 Host_FillSetup(bm_request_type, b_request, w_value, w_index, w_length);
WiredHome 4:ca93a8d4874d 508
WiredHome 4:ca93a8d4874d 509 rc = Host_ProcessTD(EDCtrl, TD_SETUP, TDBuffer, 8);
WiredHome 4:ca93a8d4874d 510 if (rc == OK) {
WiredHome 4:ca93a8d4874d 511 if (w_length) {
WiredHome 4:ca93a8d4874d 512 rc = Host_ProcessTD(EDCtrl, TD_OUT, TDBuffer, w_length);
WiredHome 4:ca93a8d4874d 513 }
WiredHome 4:ca93a8d4874d 514 if (rc == OK) {
WiredHome 4:ca93a8d4874d 515 rc = Host_ProcessTD(EDCtrl, TD_IN, NULL, 0);
WiredHome 4:ca93a8d4874d 516 }
WiredHome 4:ca93a8d4874d 517 }
WiredHome 4:ca93a8d4874d 518 return (rc);
WiredHome 4:ca93a8d4874d 519 }
WiredHome 4:ca93a8d4874d 520
WiredHome 4:ca93a8d4874d 521 /*
WiredHome 4:ca93a8d4874d 522 **************************************************************************************************************
WiredHome 4:ca93a8d4874d 523 * FILL SETUP PACKET
WiredHome 4:ca93a8d4874d 524 *
WiredHome 4:ca93a8d4874d 525 * Description: This function is used to fill the setup packet
WiredHome 4:ca93a8d4874d 526 *
WiredHome 4:ca93a8d4874d 527 * Arguments : None
WiredHome 4:ca93a8d4874d 528 *
WiredHome 4:ca93a8d4874d 529 * Returns : OK if Success
WiredHome 4:ca93a8d4874d 530 * ERR_INVALID_BOOTSIG if Failed
WiredHome 4:ca93a8d4874d 531 *
WiredHome 4:ca93a8d4874d 532 **************************************************************************************************************
WiredHome 4:ca93a8d4874d 533 */
WiredHome 4:ca93a8d4874d 534
WiredHome 4:ca93a8d4874d 535 void Host_FillSetup (USB_INT08U bm_request_type,
WiredHome 4:ca93a8d4874d 536 USB_INT08U b_request,
WiredHome 4:ca93a8d4874d 537 USB_INT16U w_value,
WiredHome 4:ca93a8d4874d 538 USB_INT16U w_index,
WiredHome 4:ca93a8d4874d 539 USB_INT16U w_length)
WiredHome 4:ca93a8d4874d 540 {
WiredHome 4:ca93a8d4874d 541 int i;
WiredHome 4:ca93a8d4874d 542 for (i=0;i<w_length;i++)
WiredHome 4:ca93a8d4874d 543 TDBuffer[i] = 0;
WiredHome 4:ca93a8d4874d 544
WiredHome 4:ca93a8d4874d 545 TDBuffer[0] = bm_request_type;
WiredHome 4:ca93a8d4874d 546 TDBuffer[1] = b_request;
WiredHome 4:ca93a8d4874d 547 WriteLE16U(&TDBuffer[2], w_value);
WiredHome 4:ca93a8d4874d 548 WriteLE16U(&TDBuffer[4], w_index);
WiredHome 4:ca93a8d4874d 549 WriteLE16U(&TDBuffer[6], w_length);
WiredHome 4:ca93a8d4874d 550 }
WiredHome 4:ca93a8d4874d 551
WiredHome 4:ca93a8d4874d 552
WiredHome 4:ca93a8d4874d 553
WiredHome 4:ca93a8d4874d 554 /*
WiredHome 4:ca93a8d4874d 555 **************************************************************************************************************
WiredHome 4:ca93a8d4874d 556 * INITIALIZE THE TRANSFER DESCRIPTOR
WiredHome 4:ca93a8d4874d 557 *
WiredHome 4:ca93a8d4874d 558 * Description: This function initializes transfer descriptor
WiredHome 4:ca93a8d4874d 559 *
WiredHome 4:ca93a8d4874d 560 * Arguments : Pointer to TD structure
WiredHome 4:ca93a8d4874d 561 *
WiredHome 4:ca93a8d4874d 562 * Returns : None
WiredHome 4:ca93a8d4874d 563 *
WiredHome 4:ca93a8d4874d 564 **************************************************************************************************************
WiredHome 4:ca93a8d4874d 565 */
WiredHome 4:ca93a8d4874d 566
WiredHome 4:ca93a8d4874d 567 void Host_TDInit (volatile HCTD *td)
WiredHome 4:ca93a8d4874d 568 {
WiredHome 4:ca93a8d4874d 569
WiredHome 4:ca93a8d4874d 570 td->Control = 0;
WiredHome 4:ca93a8d4874d 571 td->CurrBufPtr = 0;
WiredHome 4:ca93a8d4874d 572 td->Next = 0;
WiredHome 4:ca93a8d4874d 573 td->BufEnd = 0;
WiredHome 4:ca93a8d4874d 574 }
WiredHome 4:ca93a8d4874d 575
WiredHome 4:ca93a8d4874d 576 /*
WiredHome 4:ca93a8d4874d 577 **************************************************************************************************************
WiredHome 4:ca93a8d4874d 578 * INITIALIZE THE ENDPOINT DESCRIPTOR
WiredHome 4:ca93a8d4874d 579 *
WiredHome 4:ca93a8d4874d 580 * Description: This function initializes endpoint descriptor
WiredHome 4:ca93a8d4874d 581 *
WiredHome 4:ca93a8d4874d 582 * Arguments : Pointer to ED strcuture
WiredHome 4:ca93a8d4874d 583 *
WiredHome 4:ca93a8d4874d 584 * Returns : None
WiredHome 4:ca93a8d4874d 585 *
WiredHome 4:ca93a8d4874d 586 **************************************************************************************************************
WiredHome 4:ca93a8d4874d 587 */
WiredHome 4:ca93a8d4874d 588
WiredHome 4:ca93a8d4874d 589 void Host_EDInit (volatile HCED *ed)
WiredHome 4:ca93a8d4874d 590 {
WiredHome 4:ca93a8d4874d 591
WiredHome 4:ca93a8d4874d 592 ed->Control = 0;
WiredHome 4:ca93a8d4874d 593 ed->TailTd = 0;
WiredHome 4:ca93a8d4874d 594 ed->HeadTd = 0;
WiredHome 4:ca93a8d4874d 595 ed->Next = 0;
WiredHome 4:ca93a8d4874d 596 }
WiredHome 4:ca93a8d4874d 597
WiredHome 4:ca93a8d4874d 598 /*
WiredHome 4:ca93a8d4874d 599 **************************************************************************************************************
WiredHome 4:ca93a8d4874d 600 * INITIALIZE HOST CONTROLLER COMMUNICATIONS AREA
WiredHome 4:ca93a8d4874d 601 *
WiredHome 4:ca93a8d4874d 602 * Description: This function initializes host controller communications area
WiredHome 4:ca93a8d4874d 603 *
WiredHome 4:ca93a8d4874d 604 * Arguments : Pointer to HCCA
WiredHome 4:ca93a8d4874d 605 *
WiredHome 4:ca93a8d4874d 606 * Returns :
WiredHome 4:ca93a8d4874d 607 *
WiredHome 4:ca93a8d4874d 608 **************************************************************************************************************
WiredHome 4:ca93a8d4874d 609 */
WiredHome 4:ca93a8d4874d 610
WiredHome 4:ca93a8d4874d 611 void Host_HCCAInit (volatile HCCA *hcca)
WiredHome 4:ca93a8d4874d 612 {
WiredHome 4:ca93a8d4874d 613 USB_INT32U i;
WiredHome 4:ca93a8d4874d 614
WiredHome 4:ca93a8d4874d 615
WiredHome 4:ca93a8d4874d 616 for (i = 0; i < 32; i++) {
WiredHome 4:ca93a8d4874d 617
WiredHome 4:ca93a8d4874d 618 hcca->IntTable[i] = 0;
WiredHome 4:ca93a8d4874d 619 hcca->FrameNumber = 0;
WiredHome 4:ca93a8d4874d 620 hcca->DoneHead = 0;
WiredHome 4:ca93a8d4874d 621 }
WiredHome 4:ca93a8d4874d 622
WiredHome 4:ca93a8d4874d 623 }
WiredHome 4:ca93a8d4874d 624
WiredHome 4:ca93a8d4874d 625 /*
WiredHome 4:ca93a8d4874d 626 **************************************************************************************************************
WiredHome 4:ca93a8d4874d 627 * WAIT FOR WDH INTERRUPT
WiredHome 4:ca93a8d4874d 628 *
WiredHome 4:ca93a8d4874d 629 * Description: This function is infinite loop which breaks when ever a WDH interrupt rises
WiredHome 4:ca93a8d4874d 630 *
WiredHome 4:ca93a8d4874d 631 * Arguments : None
WiredHome 4:ca93a8d4874d 632 *
WiredHome 4:ca93a8d4874d 633 * Returns : None
WiredHome 4:ca93a8d4874d 634 *
WiredHome 4:ca93a8d4874d 635 **************************************************************************************************************
WiredHome 4:ca93a8d4874d 636 */
WiredHome 4:ca93a8d4874d 637
WiredHome 4:ca93a8d4874d 638 void Host_WDHWait (void)
WiredHome 4:ca93a8d4874d 639 {
WiredHome 4:ca93a8d4874d 640 while (!HOST_WdhIntr)
WiredHome 4:ca93a8d4874d 641 __WFI();
WiredHome 4:ca93a8d4874d 642
WiredHome 4:ca93a8d4874d 643 HOST_WdhIntr = 0;
WiredHome 4:ca93a8d4874d 644 }
WiredHome 4:ca93a8d4874d 645
WiredHome 4:ca93a8d4874d 646 /*
WiredHome 4:ca93a8d4874d 647 **************************************************************************************************************
WiredHome 4:ca93a8d4874d 648 * READ LE 32U
WiredHome 4:ca93a8d4874d 649 *
WiredHome 4:ca93a8d4874d 650 * Description: This function is used to read an unsigned integer from a character buffer in the platform
WiredHome 4:ca93a8d4874d 651 * containing little endian processor
WiredHome 4:ca93a8d4874d 652 *
WiredHome 4:ca93a8d4874d 653 * Arguments : pmem Pointer to the character buffer
WiredHome 4:ca93a8d4874d 654 *
WiredHome 4:ca93a8d4874d 655 * Returns : val Unsigned integer
WiredHome 4:ca93a8d4874d 656 *
WiredHome 4:ca93a8d4874d 657 **************************************************************************************************************
WiredHome 4:ca93a8d4874d 658 */
WiredHome 4:ca93a8d4874d 659
WiredHome 4:ca93a8d4874d 660 USB_INT32U ReadLE32U (volatile USB_INT08U *pmem)
WiredHome 4:ca93a8d4874d 661 {
WiredHome 4:ca93a8d4874d 662 USB_INT32U val = *(USB_INT32U*)pmem;
WiredHome 4:ca93a8d4874d 663 #ifdef __BIG_ENDIAN
WiredHome 4:ca93a8d4874d 664 return __REV(val);
WiredHome 4:ca93a8d4874d 665 #else
WiredHome 4:ca93a8d4874d 666 return val;
WiredHome 4:ca93a8d4874d 667 #endif
WiredHome 4:ca93a8d4874d 668 }
WiredHome 4:ca93a8d4874d 669
WiredHome 4:ca93a8d4874d 670 /*
WiredHome 4:ca93a8d4874d 671 **************************************************************************************************************
WiredHome 4:ca93a8d4874d 672 * WRITE LE 32U
WiredHome 4:ca93a8d4874d 673 *
WiredHome 4:ca93a8d4874d 674 * Description: This function is used to write an unsigned integer into a charecter buffer in the platform
WiredHome 4:ca93a8d4874d 675 * containing little endian processor.
WiredHome 4:ca93a8d4874d 676 *
WiredHome 4:ca93a8d4874d 677 * Arguments : pmem Pointer to the charecter buffer
WiredHome 4:ca93a8d4874d 678 * val Integer value to be placed in the charecter buffer
WiredHome 4:ca93a8d4874d 679 *
WiredHome 4:ca93a8d4874d 680 * Returns : None
WiredHome 4:ca93a8d4874d 681 *
WiredHome 4:ca93a8d4874d 682 **************************************************************************************************************
WiredHome 4:ca93a8d4874d 683 */
WiredHome 4:ca93a8d4874d 684
WiredHome 4:ca93a8d4874d 685 void WriteLE32U (volatile USB_INT08U *pmem,
WiredHome 4:ca93a8d4874d 686 USB_INT32U val)
WiredHome 4:ca93a8d4874d 687 {
WiredHome 4:ca93a8d4874d 688 #ifdef __BIG_ENDIAN
WiredHome 4:ca93a8d4874d 689 *(USB_INT32U*)pmem = __REV(val);
WiredHome 4:ca93a8d4874d 690 #else
WiredHome 4:ca93a8d4874d 691 *(USB_INT32U*)pmem = val;
WiredHome 4:ca93a8d4874d 692 #endif
WiredHome 4:ca93a8d4874d 693 }
WiredHome 4:ca93a8d4874d 694
WiredHome 4:ca93a8d4874d 695 /*
WiredHome 4:ca93a8d4874d 696 **************************************************************************************************************
WiredHome 4:ca93a8d4874d 697 * READ LE 16U
WiredHome 4:ca93a8d4874d 698 *
WiredHome 4:ca93a8d4874d 699 * Description: This function is used to read an unsigned short integer from a charecter buffer in the platform
WiredHome 4:ca93a8d4874d 700 * containing little endian processor
WiredHome 4:ca93a8d4874d 701 *
WiredHome 4:ca93a8d4874d 702 * Arguments : pmem Pointer to the charecter buffer
WiredHome 4:ca93a8d4874d 703 *
WiredHome 4:ca93a8d4874d 704 * Returns : val Unsigned short integer
WiredHome 4:ca93a8d4874d 705 *
WiredHome 4:ca93a8d4874d 706 **************************************************************************************************************
WiredHome 4:ca93a8d4874d 707 */
WiredHome 4:ca93a8d4874d 708
WiredHome 4:ca93a8d4874d 709 USB_INT16U ReadLE16U (volatile USB_INT08U *pmem)
WiredHome 4:ca93a8d4874d 710 {
WiredHome 4:ca93a8d4874d 711 USB_INT16U val = *(USB_INT16U*)pmem;
WiredHome 4:ca93a8d4874d 712 #ifdef __BIG_ENDIAN
WiredHome 4:ca93a8d4874d 713 return __REV16(val);
WiredHome 4:ca93a8d4874d 714 #else
WiredHome 4:ca93a8d4874d 715 return val;
WiredHome 4:ca93a8d4874d 716 #endif
WiredHome 4:ca93a8d4874d 717 }
WiredHome 4:ca93a8d4874d 718
WiredHome 4:ca93a8d4874d 719 /*
WiredHome 4:ca93a8d4874d 720 **************************************************************************************************************
WiredHome 4:ca93a8d4874d 721 * WRITE LE 16U
WiredHome 4:ca93a8d4874d 722 *
WiredHome 4:ca93a8d4874d 723 * Description: This function is used to write an unsigned short integer into a charecter buffer in the
WiredHome 4:ca93a8d4874d 724 * platform containing little endian processor
WiredHome 4:ca93a8d4874d 725 *
WiredHome 4:ca93a8d4874d 726 * Arguments : pmem Pointer to the charecter buffer
WiredHome 4:ca93a8d4874d 727 * val Value to be placed in the charecter buffer
WiredHome 4:ca93a8d4874d 728 *
WiredHome 4:ca93a8d4874d 729 * Returns : None
WiredHome 4:ca93a8d4874d 730 *
WiredHome 4:ca93a8d4874d 731 **************************************************************************************************************
WiredHome 4:ca93a8d4874d 732 */
WiredHome 4:ca93a8d4874d 733
WiredHome 4:ca93a8d4874d 734 void WriteLE16U (volatile USB_INT08U *pmem,
WiredHome 4:ca93a8d4874d 735 USB_INT16U val)
WiredHome 4:ca93a8d4874d 736 {
WiredHome 4:ca93a8d4874d 737 #ifdef __BIG_ENDIAN
WiredHome 4:ca93a8d4874d 738 *(USB_INT16U*)pmem = (__REV16(val) & 0xFFFF);
WiredHome 4:ca93a8d4874d 739 #else
WiredHome 4:ca93a8d4874d 740 *(USB_INT16U*)pmem = val;
WiredHome 4:ca93a8d4874d 741 #endif
WiredHome 4:ca93a8d4874d 742 }
WiredHome 4:ca93a8d4874d 743
WiredHome 4:ca93a8d4874d 744 /*
WiredHome 4:ca93a8d4874d 745 **************************************************************************************************************
WiredHome 4:ca93a8d4874d 746 * READ BE 32U
WiredHome 4:ca93a8d4874d 747 *
WiredHome 4:ca93a8d4874d 748 * Description: This function is used to read an unsigned integer from a charecter buffer in the platform
WiredHome 4:ca93a8d4874d 749 * containing big endian processor
WiredHome 4:ca93a8d4874d 750 *
WiredHome 4:ca93a8d4874d 751 * Arguments : pmem Pointer to the charecter buffer
WiredHome 4:ca93a8d4874d 752 *
WiredHome 4:ca93a8d4874d 753 * Returns : val Unsigned integer
WiredHome 4:ca93a8d4874d 754 *
WiredHome 4:ca93a8d4874d 755 **************************************************************************************************************
WiredHome 4:ca93a8d4874d 756 */
WiredHome 4:ca93a8d4874d 757
WiredHome 4:ca93a8d4874d 758 USB_INT32U ReadBE32U (volatile USB_INT08U *pmem)
WiredHome 4:ca93a8d4874d 759 {
WiredHome 4:ca93a8d4874d 760 USB_INT32U val = *(USB_INT32U*)pmem;
WiredHome 4:ca93a8d4874d 761 #ifdef __BIG_ENDIAN
WiredHome 4:ca93a8d4874d 762 return val;
WiredHome 4:ca93a8d4874d 763 #else
WiredHome 4:ca93a8d4874d 764 return __REV(val);
WiredHome 4:ca93a8d4874d 765 #endif
WiredHome 4:ca93a8d4874d 766 }
WiredHome 4:ca93a8d4874d 767
WiredHome 4:ca93a8d4874d 768 /*
WiredHome 4:ca93a8d4874d 769 **************************************************************************************************************
WiredHome 4:ca93a8d4874d 770 * WRITE BE 32U
WiredHome 4:ca93a8d4874d 771 *
WiredHome 4:ca93a8d4874d 772 * Description: This function is used to write an unsigned integer into a charecter buffer in the platform
WiredHome 4:ca93a8d4874d 773 * containing big endian processor
WiredHome 4:ca93a8d4874d 774 *
WiredHome 4:ca93a8d4874d 775 * Arguments : pmem Pointer to the charecter buffer
WiredHome 4:ca93a8d4874d 776 * val Value to be placed in the charecter buffer
WiredHome 4:ca93a8d4874d 777 *
WiredHome 4:ca93a8d4874d 778 * Returns : None
WiredHome 4:ca93a8d4874d 779 *
WiredHome 4:ca93a8d4874d 780 **************************************************************************************************************
WiredHome 4:ca93a8d4874d 781 */
WiredHome 4:ca93a8d4874d 782
WiredHome 4:ca93a8d4874d 783 void WriteBE32U (volatile USB_INT08U *pmem,
WiredHome 4:ca93a8d4874d 784 USB_INT32U val)
WiredHome 4:ca93a8d4874d 785 {
WiredHome 4:ca93a8d4874d 786 #ifdef __BIG_ENDIAN
WiredHome 4:ca93a8d4874d 787 *(USB_INT32U*)pmem = val;
WiredHome 4:ca93a8d4874d 788 #else
WiredHome 4:ca93a8d4874d 789 *(USB_INT32U*)pmem = __REV(val);
WiredHome 4:ca93a8d4874d 790 #endif
WiredHome 4:ca93a8d4874d 791 }
WiredHome 4:ca93a8d4874d 792
WiredHome 4:ca93a8d4874d 793 /*
WiredHome 4:ca93a8d4874d 794 **************************************************************************************************************
WiredHome 4:ca93a8d4874d 795 * READ BE 16U
WiredHome 4:ca93a8d4874d 796 *
WiredHome 4:ca93a8d4874d 797 * Description: This function is used to read an unsigned short integer from a charecter buffer in the platform
WiredHome 4:ca93a8d4874d 798 * containing big endian processor
WiredHome 4:ca93a8d4874d 799 *
WiredHome 4:ca93a8d4874d 800 * Arguments : pmem Pointer to the charecter buffer
WiredHome 4:ca93a8d4874d 801 *
WiredHome 4:ca93a8d4874d 802 * Returns : val Unsigned short integer
WiredHome 4:ca93a8d4874d 803 *
WiredHome 4:ca93a8d4874d 804 **************************************************************************************************************
WiredHome 4:ca93a8d4874d 805 */
WiredHome 4:ca93a8d4874d 806
WiredHome 4:ca93a8d4874d 807 USB_INT16U ReadBE16U (volatile USB_INT08U *pmem)
WiredHome 4:ca93a8d4874d 808 {
WiredHome 4:ca93a8d4874d 809 USB_INT16U val = *(USB_INT16U*)pmem;
WiredHome 4:ca93a8d4874d 810 #ifdef __BIG_ENDIAN
WiredHome 4:ca93a8d4874d 811 return val;
WiredHome 4:ca93a8d4874d 812 #else
WiredHome 4:ca93a8d4874d 813 return __REV16(val);
WiredHome 4:ca93a8d4874d 814 #endif
WiredHome 4:ca93a8d4874d 815 }
WiredHome 4:ca93a8d4874d 816
WiredHome 4:ca93a8d4874d 817 /*
WiredHome 4:ca93a8d4874d 818 **************************************************************************************************************
WiredHome 4:ca93a8d4874d 819 * WRITE BE 16U
WiredHome 4:ca93a8d4874d 820 *
WiredHome 4:ca93a8d4874d 821 * Description: This function is used to write an unsigned short integer into the charecter buffer in the
WiredHome 4:ca93a8d4874d 822 * platform containing big endian processor
WiredHome 4:ca93a8d4874d 823 *
WiredHome 4:ca93a8d4874d 824 * Arguments : pmem Pointer to the charecter buffer
WiredHome 4:ca93a8d4874d 825 * val Value to be placed in the charecter buffer
WiredHome 4:ca93a8d4874d 826 *
WiredHome 4:ca93a8d4874d 827 * Returns : None
WiredHome 4:ca93a8d4874d 828 *
WiredHome 4:ca93a8d4874d 829 **************************************************************************************************************
WiredHome 4:ca93a8d4874d 830 */
WiredHome 4:ca93a8d4874d 831
WiredHome 4:ca93a8d4874d 832 void WriteBE16U (volatile USB_INT08U *pmem,
WiredHome 4:ca93a8d4874d 833 USB_INT16U val)
WiredHome 4:ca93a8d4874d 834 {
WiredHome 4:ca93a8d4874d 835 #ifdef __BIG_ENDIAN
WiredHome 4:ca93a8d4874d 836 *(USB_INT16U*)pmem = val;
WiredHome 4:ca93a8d4874d 837 #else
WiredHome 4:ca93a8d4874d 838 *(USB_INT16U*)pmem = (__REV16(val) & 0xFFFF);
WiredHome 4:ca93a8d4874d 839 #endif
WiredHome 4:ca93a8d4874d 840 }