1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
|
//*****************************************************************************
//
// usb_serial_structs.c - Data structures defining this CDC USB device.
//
// Copyright (c) 2009-2014 Texas Instruments Incorporated. All rights reserved.
// Software License Agreement
//
// Texas Instruments (TI) is supplying this software for use solely and
// exclusively on TI's microcontroller products. The software is owned by
// TI and/or its suppliers, and is protected under applicable copyright
// laws. You may not combine this software with "viral" open-source
// software in order to form a larger program.
//
// THIS SOFTWARE IS PROVIDED "AS IS" AND WITH ALL FAULTS.
// NO WARRANTIES, WHETHER EXPRESS, IMPLIED OR STATUTORY, INCLUDING, BUT
// NOT LIMITED TO, IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
// A PARTICULAR PURPOSE APPLY TO THIS SOFTWARE. TI SHALL NOT, UNDER ANY
// CIRCUMSTANCES, BE LIABLE FOR SPECIAL, INCIDENTAL, OR CONSEQUENTIAL
// DAMAGES, FOR ANY REASON WHATSOEVER.
//
// This is part of revision 2.1.0.12573 of the EK-TM4C1294XL Firmware Package.
//
//*****************************************************************************
#include <stdbool.h>
#include <stdint.h>
#include "inc/hw_types.h"
#include "driverlib/usb.h"
#include "usblib/usblib.h"
#include "usblib/usbcdc.h"
#include "usblib/usb-ids.h"
#include "usblib/device/usbdevice.h"
#include "usblib/device/usbdcdc.h"
#include "usblib/device/usbdcomp.h"
#include "usb_structs.h"
//*****************************************************************************
//
// The languages supported by this device.
//
//*****************************************************************************
const uint8_t g_pui8LangDescriptor[] =
{
4,
USB_DTYPE_STRING,
USBShort(USB_LANG_EN_US)
};
//*****************************************************************************
//
// The manufacturer string.
//
//*****************************************************************************
const uint8_t g_pui8ManufacturerString[] =
{
(17 + 1) * 2,
USB_DTYPE_STRING,
'T', 0, 'e', 0, 'x', 0, 'a', 0, 's', 0, ' ', 0, 'I', 0, 'n', 0, 's', 0,
't', 0, 'r', 0, 'u', 0, 'm', 0, 'e', 0, 'n', 0, 't', 0, 's', 0,
};
//*****************************************************************************
//
// The product string.
//
//*****************************************************************************
const uint8_t g_pui8ProductString[] =
{
2 + (16 * 2),
USB_DTYPE_STRING,
'V', 0, 'i', 0, 'r', 0, 't', 0, 'u', 0, 'a', 0, 'l', 0, ' ', 0,
'C', 0, 'O', 0, 'M', 0, ' ', 0, 'P', 0, 'o', 0, 'r', 0, 't', 0
};
//*****************************************************************************
//
// The serial number string.
//
//*****************************************************************************
const uint8_t g_pui8SerialNumberString[] =
{
2 + (8 * 2),
USB_DTYPE_STRING,
'1', 0, '2', 0, '3', 0, '4', 0, '5', 0, '6', 0, '7', 0, '8', 0
};
//*****************************************************************************
//
// The control interface description string.
//
//*****************************************************************************
const uint8_t g_pui8ControlInterfaceString[] =
{
2 + (21 * 2),
USB_DTYPE_STRING,
'A', 0, 'C', 0, 'M', 0, ' ', 0, 'C', 0, 'o', 0, 'n', 0, 't', 0,
'r', 0, 'o', 0, 'l', 0, ' ', 0, 'I', 0, 'n', 0, 't', 0, 'e', 0,
'r', 0, 'f', 0, 'a', 0, 'c', 0, 'e', 0
};
//*****************************************************************************
//
// The configuration description string.
//
//*****************************************************************************
const uint8_t g_pui8ConfigString[] =
{
2 + (26 * 2),
USB_DTYPE_STRING,
'S', 0, 'e', 0, 'l', 0, 'f', 0, ' ', 0, 'P', 0, 'o', 0, 'w', 0,
'e', 0, 'r', 0, 'e', 0, 'd', 0, ' ', 0, 'C', 0, 'o', 0, 'n', 0,
'f', 0, 'i', 0, 'g', 0, 'u', 0, 'r', 0, 'a', 0, 't', 0, 'i', 0,
'o', 0, 'n', 0
};
//*****************************************************************************
//
// The descriptor string table.
//
//*****************************************************************************
const uint8_t * const g_pui8StringDescriptors[] =
{
g_pui8LangDescriptor,
g_pui8ManufacturerString,
g_pui8ProductString,
g_pui8SerialNumberString,
g_pui8ControlInterfaceString,
g_pui8ConfigString
};
#define NUM_STRING_DESCRIPTORS (sizeof(g_pui8StringDescriptors) / \
sizeof(uint8_t *))
//*****************************************************************************
//
// The CDC device initialization and customization structures. In this case,
// we are using USBBuffers between the CDC device class driver and the
// application code. The function pointers and callback data values are set
// to insert a buffer in each of the data channels, transmit and receive.
//
// With the buffer in place, the CDC channel callback is set to the relevant
// channel function and the callback data is set to point to the channel
// instance data. The buffer, in turn, has its callback set to the application
// function and the callback data set to our CDC instance structure.
//
//*****************************************************************************
tUSBDCDCDevice g_psCDCDevice[NUM_SERIAL_DEVICES] =
{
{
USB_VID_TI_1CBE,
USB_PID_SERIAL,
0,
USB_CONF_ATTR_SELF_PWR,
ControlHandler,
(void *)&g_psCDCDevice[0],
USBBufferEventCallback,
(void *)&g_psRxBuffer[0],
USBBufferEventCallback,
(void *)&g_psTxBuffer[0],
g_pui8StringDescriptors,
NUM_STRING_DESCRIPTORS
},
{
USB_VID_TI_1CBE,
USB_PID_SERIAL,
0,
USB_CONF_ATTR_SELF_PWR,
ControlHandler,
(void *)&g_psCDCDevice[1],
USBBufferEventCallback,
(void *)&g_psRxBuffer[1],
USBBufferEventCallback,
(void *)&g_psTxBuffer[1],
g_pui8StringDescriptors,
NUM_STRING_DESCRIPTORS
}
};
//*****************************************************************************
//
// Receive buffer (from the USB perspective).
//
//*****************************************************************************
uint8_t g_ppui8USBRxBuffer[NUM_SERIAL_DEVICES][UART_BUFFER_SIZE];
uint8_t g_ppui8RxBufferWorkspace[NUM_SERIAL_DEVICES][USB_BUFFER_WORKSPACE_SIZE];
const tUSBBuffer g_psRxBuffer[NUM_SERIAL_DEVICES] =
{
{
false, // This is a receive buffer.
RxHandlerEcho, // pfnCallback
(void *)&g_psCDCDevice[0], // Callback data is our device pointer.
USBDCDCPacketRead, // pfnTransfer
USBDCDCRxPacketAvailable, // pfnAvailable
(void *)&g_psCDCDevice[0], // pvHandle
g_ppui8USBRxBuffer[0], // pcBuffer
UART_BUFFER_SIZE, // ulBufferSize
g_ppui8RxBufferWorkspace[0] // pvWorkspace
},
{
false, // This is a receive buffer.
RxHandlerCmd, // pfnCallback
(void *)&g_psCDCDevice[1], // Callback data is our device pointer.
USBDCDCPacketRead, // pfnTransfer
USBDCDCRxPacketAvailable, // pfnAvailable
(void *)&g_psCDCDevice[1], // pvHandle
g_ppui8USBRxBuffer[1], // pcBuffer
UART_BUFFER_SIZE, // ulBufferSize
g_ppui8RxBufferWorkspace[1] // pvWorkspace
}
};
//*****************************************************************************
//
// Transmit buffer (from the USB perspective).
//
//*****************************************************************************
uint8_t g_ppcUSBTxBuffer[NUM_SERIAL_DEVICES][UART_BUFFER_SIZE];
uint8_t g_ppucTxBufferWorkspace[NUM_SERIAL_DEVICES][USB_BUFFER_WORKSPACE_SIZE];
const tUSBBuffer g_psTxBuffer[NUM_SERIAL_DEVICES] =
{
{
true, // This is a transmit buffer.
TxHandlerEcho, // pfnCallback
(void *)&g_psCDCDevice[0], // Callback data is our device pointer.
USBDCDCPacketWrite, // pfnTransfer
USBDCDCTxPacketAvailable, // pfnAvailable
(void *)&g_psCDCDevice[0], // pvHandle
g_ppcUSBTxBuffer[0], // pcBuffer
UART_BUFFER_SIZE, // ulBufferSize
g_ppucTxBufferWorkspace[0] // pvWorkspace
},
{
true, // This is a transmit buffer.
TxHandlerCmd, // pfnCallback
(void *)&g_psCDCDevice[1], // Callback data is our device pointer.
USBDCDCPacketWrite, // pfnTransfer
USBDCDCTxPacketAvailable, // pfnAvailable
(void *)&g_psCDCDevice[1], // pvHandle
g_ppcUSBTxBuffer[1], // pcBuffer
UART_BUFFER_SIZE, // ulBufferSize
g_ppucTxBufferWorkspace[1] // pvWorkspace
}
};
//****************************************************************************
//
// The memory allocated to hold the composite descriptor that is created by
// the call to USBDCompositeInit().
//
//****************************************************************************
uint8_t g_pui8DescriptorData[DESCRIPTOR_DATA_SIZE];
tCompositeEntry g_psCompEntries[NUM_SERIAL_DEVICES];
//****************************************************************************
//
// Allocate the Device Data for the top level composite device class.
//
//****************************************************************************
tUSBDCompositeDevice g_sCompDevice =
{
//
// Stellaris VID.
//
USB_VID_TI_1CBE,
//
// Stellaris PID for composite serial device.
//
USB_PID_COMP_SERIAL,
//
// This is in 2mA increments so 500mA.
//
250,
//
// Bus powered device.
//
USB_CONF_ATTR_BUS_PWR,
//
// There is no need for a default composite event handler.
//
0,
//
// The string table.
//
g_pui8StringDescriptors,
NUM_STRING_DESCRIPTORS,
//
// The Composite device array.
//
2,
g_psCompEntries
};
|