LPCOpen Platform
LPCOpen Platform for NXP LPC Microcontrollers
 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 typedef struct _st_Inquiry_String {
37  uint8_t VendorID[8];
38  uint8_t ProductID[16];
39  uint8_t RevisionID[4];
40 } ATTR_PACKED InquiryString;
41 InquiryString InquiryData = {
42  .VendorID = "NXP",
43  .ProductID = "Dataflash Disk",
44  .RevisionID = {'0', '.', '0', '0'},
45 };
46 USB_Descriptor_DeviceQualifier_t DeviceQualifierDescriptor = {
47  .Header = {.Size = sizeof(USB_Descriptor_DeviceQualifier_t), .Type = DTYPE_DeviceQualifier},
48 
49  .USBSpecification = VERSION_BCD(02.00),
50  .Class = USB_CSCP_NoDeviceClass,
51  .SubClass = USB_CSCP_NoDeviceSubclass,
52  .Protocol = USB_CSCP_NoDeviceProtocol,
53 
54  .Endpoint0Size = FIXED_CONTROL_ENDPOINT_SIZE,
55  .NumberOfConfigurations = FIXED_NUM_CONFIGURATIONS
56 };
57 uint8_t StringDescriptor[] = {
58  USB_STRING_LEN(1), /* LanguageString */
61 
62  USB_STRING_LEN(3), /* ManufacturerString */
64  WBVAL('N'), WBVAL('X'), WBVAL('P'),
65 
66  USB_STRING_LEN(22 + 5), /* ProductString */
68  WBVAL('L'), WBVAL('P'), WBVAL('C'), WBVAL('U'), WBVAL('S'), WBVAL('B'), WBVAL('l'), WBVAL('i'), WBVAL('b'), WBVAL(
69  ' '),
70  WBVAL('M'), WBVAL('a'), WBVAL('s'), WBVAL('s'), WBVAL(' '), WBVAL('S'), WBVAL('t'), WBVAL('o'), WBVAL('r'), WBVAL(
71  'a'), WBVAL('g'), WBVAL('e'), WBVAL(' '),
72  WBVAL('D'), WBVAL('e'), WBVAL('m'), WBVAL('o')
73 };
76 
77 extern uint8_t DiskImage[];
78 
79 void translate_rd(uint32_t offset, uint8_t * *buff_adr, uint32_t length);
80 
81 void translate_rd(uint32_t offset, uint8_t * *buff_adr, uint32_t length)
82 {
83  *buff_adr = &DiskImage[offset];
84 }
85 
86 void translate_wr(uint32_t offset, uint8_t * *buff_adr, uint32_t length);
87 
88 void translate_wr(uint32_t offset, uint8_t * *buff_adr, uint32_t length)
89 {
90  *buff_adr = &DiskImage[offset + length];
91 }
92 
93 void translate_GetWrBuf(uint32_t offset, uint8_t * *buff_adr, uint32_t length);
94 
95 void translate_GetWrBuf(uint32_t offset, uint8_t * *buff_adr, uint32_t length)
96 {
97  *buff_adr = &DiskImage[offset];
98 }
99 
100 ErrorCode_t translate_verify(uint32_t offset, uint8_t *src, uint32_t length);
101 
102 ErrorCode_t translate_verify(uint32_t offset, uint8_t *src, uint32_t length)
103 {
104  if (memcmp(&DiskImage[offset], src, length)) {
105  return ERR_FAILED;
106  }
107 
108  return LPC_OK;
109 
110 }
111 
113 {
114  return (uint32_t) &DeviceDescriptor;
115 }
116 
118 {
120 }
121 
123 {
124  return (uint32_t) StringDescriptor;
125 }
126 
128 {
129  return (uint32_t) &DeviceQualifierDescriptor;
130 }
131 
133 {
134  return 0;
135 }
136 
138 {
139  return (uint32_t) &InquiryData;
140 }
141 
143 {
144  return VIRTUAL_MEMORY_BLOCKS;
145 }
146 
148 {
150 }
151 
153 {
154  return VIRTUAL_MEMORY_BYTES;
155 }
156 
158 {
159  return (uint32_t) &(ConfigurationDescriptor.MS_Interface);
160 }
161 
163 {
164  return (uint32_t) translate_wr;
165 }
166 
168 {
169  return (uint32_t) translate_rd;
170 }
171 
173 {
174  return (uint32_t) translate_verify;
175 }
176 
178 {
179  return (uint32_t) translate_GetWrBuf;
180 }
181 
182 #endif