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