MonitoringSys_toukarui

Dependencies:   mbed SB1602E MSCFILESytem FatFileSystemCpp TextLCD

Committer:
MPPT51
Date:
Wed Apr 08 01:18:43 2020 +0000
Revision:
0:a6417f504b9d
MonitoringSys_includingToukarui

Who changed what in which revision?

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