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