| LPCOpen Platform v1.03 LPCOpen Platform for NXP LPC Microcontrollers

- Main Page
- Modules
- Data Structures
- Files
- Related Pages

- File List
- Globals

All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
UsbRom.c
Go to the documentation of this file.
1 /*
2 * @brief Mass Storage device class ROM based application's specific functions supporting core layer
3 *
4 * @note
5 * Copyright(C) NXP Semiconductors, 2012
6 * All rights reserved.
7 *
8 * @par
9 * Software that is described herein is for illustrative purposes only
10 * which provides customers with programming information regarding the
11 * LPC products. This software is supplied "AS IS" without any warranties of
12 * any kind, and NXP Semiconductors and its licensor disclaim any and
13 * all warranties, express or implied, including all implied warranties of
14 * merchantability, fitness for a particular purpose and non-infringement of
15 * intellectual property rights. NXP Semiconductors assumes no responsibility
16 * or liability for the use of the software, conveys no license or rights under any
17 * patent, copyright, mask work right, or any other intellectual property rights in
18 * or to any products. NXP Semiconductors reserves the right to make changes
19 * in the software without notification. NXP Semiconductors also makes no
20 * representation or warranty that such application will be suitable for the
21 * specified use without further testing or modification.
22 *
23 * @par
24 * Permission to use, copy, modify, and distribute this software and its
25 * documentation is hereby granted, under NXP Semiconductors' and its
26 * licensor's relevant copyrights in the software, without fee, provided that it
27 * is used in conjunction with NXP Semiconductors microcontrollers. This
28 * copyright, permission, and disclaimer notice must appear in all copies of
29 * this code.
30 */
31
32 #include "UsbRom.h"
33
34 #if defined(USB_DEVICE_ROM_DRIVER)
35
36 /*****************************************************************************
37 * Private types/enumerations/variables
38 ****************************************************************************/
39
40 /*****************************************************************************
41 * Public types/enumerations/variables
42 ****************************************************************************/
43
44 typedef struct _st_Inquiry_String {
45 uint8_t VendorID[8];
46 uint8_t ProductID[16];
47 uint8_t RevisionID[4];
48 } ATTR_PACKED InquiryString;
49
50 InquiryString InquiryData = {
51 .VendorID = "NXP",
52 .ProductID = "Dataflash Disk",
53 .RevisionID = {'0', '.', '0', '0'},
54 };
55
56 USB_Descriptor_DeviceQualifier_t DeviceQualifierDescriptor = {
57 .Header = {.Size = sizeof(USB_Descriptor_DeviceQualifier_t), .Type = DTYPE_DeviceQualifier},
58
59 .USBSpecification = VERSION_BCD(02.00),
60 .Class = USB_CSCP_NoDeviceClass,
61 .SubClass = USB_CSCP_NoDeviceSubclass,
62 .Protocol = USB_CSCP_NoDeviceProtocol,
63
64 .Endpoint0Size = FIXED_CONTROL_ENDPOINT_SIZE,
65 .NumberOfConfigurations = FIXED_NUM_CONFIGURATIONS
66 };
67
68 uint8_t StringDescriptor[] = {
69 USB_STRING_LEN(1), /* LanguageString */
70 DTYPE_String,
71 WBVAL(LANGUAGE_ID_ENG),
72
73 USB_STRING_LEN(3), /* ManufacturerString */
74 DTYPE_String,
75 WBVAL('N'), WBVAL('X'), WBVAL('P'),
76
77 USB_STRING_LEN(22 + 5), /* ProductString */
78 DTYPE_String,
79 WBVAL('L'), WBVAL('P'), WBVAL('C'), WBVAL('U'), WBVAL('S'), WBVAL('B'), WBVAL('l'), WBVAL('i'), WBVAL('b'), WBVAL(
80 ' '),
81 WBVAL('M'), WBVAL('a'), WBVAL('s'), WBVAL('s'), WBVAL(' '), WBVAL('S'), WBVAL('t'), WBVAL('o'), WBVAL('r'), WBVAL(
82 'a'), WBVAL('g'), WBVAL('e'), WBVAL(' '),
83 WBVAL('D'), WBVAL('e'), WBVAL('m'), WBVAL('o')
84 };
85 extern USB_Descriptor_Device_t DeviceDescriptor;
86 extern USB_Descriptor_Configuration_t ConfigurationDescriptor;
87
88 extern uint8_t DiskImage[];
89
90 /*****************************************************************************
91 * Private functions
92 ****************************************************************************/
93
94 /*****************************************************************************
95 * Public functions
96 ****************************************************************************/
97
98 void translate_rd(uint32_t offset, uint8_t * *buff_adr, uint32_t length);
99
100 void translate_rd(uint32_t offset, uint8_t * *buff_adr, uint32_t length)
101 {
102 *buff_adr = &DiskImage[offset];
103 }
104
105 void translate_wr(uint32_t offset, uint8_t * *buff_adr, uint32_t length);
106
107 void translate_wr(uint32_t offset, uint8_t * *buff_adr, uint32_t length)
108 {
109 *buff_adr = &DiskImage[offset + length];
110 }
111
112 void translate_GetWrBuf(uint32_t offset, uint8_t * *buff_adr, uint32_t length);
113
114 void translate_GetWrBuf(uint32_t offset, uint8_t * *buff_adr, uint32_t length)
115 {
116 *buff_adr = &DiskImage[offset];
117 }
118
119 ErrorCode_t translate_verify(uint32_t offset, uint8_t *src, uint32_t length);
120
121 ErrorCode_t translate_verify(uint32_t offset, uint8_t *src, uint32_t length)
122 {
123 if (memcmp(&DiskImage[offset], src, length)) {
124 return ERR_FAILED;
125 }
126
127 return LPC_OK;
128
129 }
130
131 uint32_t CALLBACK_UsbdRom_Register_DeviceDescriptor(void)
132 {
133 return (uint32_t) &DeviceDescriptor;
134 }
135
136 uint32_t CALLBACK_UsbdRom_Register_ConfigurationDescriptor(void)
137 {
138 return (uint32_t) &ConfigurationDescriptor;
139 }
140
141 uint32_t CALLBACK_UsbdRom_Register_StringDescriptor(void)
142 {
143 return (uint32_t) StringDescriptor;
144 }
145
146 uint32_t CALLBACK_UsbdRom_Register_DeviceQualifierDescriptor(void)
147 {
148 return (uint32_t) &DeviceQualifierDescriptor;
149 }
150
151 uint8_t CALLBACK_UsbdRom_Register_ConfigureEndpoint(void)
152 {
153 return 0;
154 }
155
156 uint32_t CALLBACK_UsbdMsc_Register_InquiryData(void)
157 {
158 return (uint32_t) &InquiryData;
159 }
160
161 uint32_t CALLBACK_UsbdMsc_Register_BlockCount(void)
162 {
163 return VIRTUAL_MEMORY_BLOCKS;
164 }
165
166 uint32_t CALLBACK_UsbdMsc_Register_BlockSize(void)
167 {
168 return VIRTUAL_MEMORY_BLOCK_SIZE;
169 }
170
171 uint32_t CALLBACK_UsbdMsc_Register_MemorySize(void)
172 {
173 return VIRTUAL_MEMORY_BYTES;
174 }
175
176 uint32_t CALLBACK_UsbdMsc_Register_InterfaceDescriptor(void)
177 {
178 return (uint32_t) &(ConfigurationDescriptor.MS_Interface);
179 }
180
181 uint32_t CALLBACK_UsbdMsc_Register_MSCWrite(void)
182 {
183 return (uint32_t) translate_wr;
184 }
185
186 uint32_t CALLBACK_UsbdMsc_Register_MSCRead(void)
187 {
188 return (uint32_t) translate_rd;
189 }
190
191 uint32_t CALLBACK_UsbdMsc_Register_MSCVerify(void)
192 {
193 return (uint32_t) translate_verify;
194 }
195
196 uint32_t CALLBACK_UsbdMsc_Register_MSCGetWriteBuf(void)
197 {
198 return (uint32_t) translate_GetWrBuf;
199 }
200
201 #endif