Line No. | Rev | Author | Line |
---|---|---|---|
1 | 32 | kaklik | /************************************************************************ |
2 | File Information: |
||
3 | FileName: usb_function_cdc.h |
||
4 | Dependencies: See INCLUDES section |
||
5 | Processor: PIC18 or PIC24 USB Microcontrollers |
||
6 | Hardware: The code is natively intended to be used on the following |
||
7 | hardware platforms: PICDEM FS USB Demo Board, |
||
8 | PIC18F87J50 FS USB Plug-In Module, or |
||
9 | Explorer 16 + PIC24 USB PIM. The firmware may be |
||
10 | modified for use on other USB platforms by editing the |
||
11 | HardwareProfile.h file. |
||
12 | Complier: Microchip C18 (for PIC18) or C30 (for PIC24) |
||
13 | Company: Microchip Technology, Inc. |
||
14 | |||
15 | Software License Agreement: |
||
16 | |||
17 | The software supplied herewith by Microchip Technology Incorporated |
||
18 | (the Company) for its PIC® Microcontroller is intended and |
||
19 | supplied to you, the Companys customer, for use solely and |
||
20 | exclusively on Microchip PIC Microcontroller products. The |
||
21 | software is owned by the Company and/or its supplier, and is |
||
22 | protected under applicable copyright laws. All rights are reserved. |
||
23 | Any use in violation of the foregoing restrictions may subject the |
||
24 | user to criminal sanctions under applicable laws, as well as to |
||
25 | civil liability for the breach of the terms and conditions of this |
||
26 | license. |
||
27 | |||
28 | THIS SOFTWARE IS PROVIDED IN AN AS IS CONDITION. NO WARRANTIES, |
||
29 | WHETHER EXPRESS, IMPLIED OR STATUTORY, INCLUDING, BUT NOT LIMITED |
||
30 | TO, IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A |
||
31 | PARTICULAR PURPOSE APPLY TO THIS SOFTWARE. THE COMPANY SHALL NOT, |
||
32 | IN ANY CIRCUMSTANCES, BE LIABLE FOR SPECIAL, INCIDENTAL OR |
||
33 | CONSEQUENTIAL DAMAGES, FOR ANY REASON WHATSOEVER. |
||
34 | |||
35 | Summary: |
||
36 | This file contains all of functions, macros, definitions, variables, |
||
37 | datatypes, etc. that are required for usage with the CDC function |
||
38 | driver. This file should be included in projects that use the CDC |
||
39 | \function driver. This file should also be included into the |
||
40 | usb_descriptors.c file and any other user file that requires access to the |
||
41 | CDC interface. |
||
42 | |||
43 | |||
44 | |||
45 | This file is located in the "\<Install Directory\>\\Microchip\\Include\\USB" |
||
46 | directory. |
||
47 | |||
48 | Description: |
||
49 | USB CDC Function Driver File |
||
50 | |||
51 | This file contains all of functions, macros, definitions, variables, |
||
52 | datatypes, etc. that are required for usage with the CDC function |
||
53 | driver. This file should be included in projects that use the CDC |
||
54 | \function driver. This file should also be included into the |
||
55 | usb_descriptors.c file and any other user file that requires access to the |
||
56 | CDC interface. |
||
57 | |||
58 | This file is located in the "\<Install Directory\>\\Microchip\\Include\\USB" |
||
59 | directory. |
||
60 | |||
61 | When including this file in a new project, this file can either be |
||
62 | referenced from the directory in which it was installed or copied |
||
63 | directly into the user application folder. If the first method is |
||
64 | chosen to keep the file located in the folder in which it is installed |
||
65 | then include paths need to be added so that the library and the |
||
66 | application both know where to reference each others files. If the |
||
67 | application folder is located in the same folder as the Microchip |
||
68 | folder (like the current demo folders), then the following include |
||
69 | paths need to be added to the application's project: |
||
70 | |||
71 | . |
||
72 | |||
73 | ..\\..\\Microchip\\Include |
||
74 | |||
75 | If a different directory structure is used, modify the paths as |
||
76 | required. An example using absolute paths instead of relative paths |
||
77 | would be the following: |
||
78 | |||
79 | C:\\Microchip Solutions\\Microchip\\Include |
||
80 | |||
81 | C:\\Microchip Solutions\\My Demo Application |
||
82 | |||
83 | ********************************************************************/ |
||
84 | |||
85 | /******************************************************************** |
||
86 | Change History: |
||
87 | Rev Description |
||
88 | ---- ----------- |
||
89 | 2.3 Decricated the mUSBUSARTIsTxTrfReady() macro. It is |
||
90 | replaced by the USBUSARTIsTxTrfReady() function. |
||
91 | |||
92 | 2.6 Minor defintion changes |
||
93 | 2.6a- No change |
||
94 | 2.7a |
||
95 | ********************************************************************/ |
||
96 | |||
97 | #ifndef CDC_H |
||
98 | #define CDC_H |
||
99 | |||
100 | /** I N C L U D E S **********************************************************/ |
||
101 | #include "GenericTypeDefs.h" |
||
102 | #include "USB\usb.h" |
||
103 | #include "usb_config.h" |
||
104 | |||
105 | /** D E F I N I T I O N S ****************************************************/ |
||
106 | |||
107 | /* Class-Specific Requests */ |
||
108 | #define SEND_ENCAPSULATED_COMMAND 0x00 |
||
109 | #define GET_ENCAPSULATED_RESPONSE 0x01 |
||
110 | #define SET_COMM_FEATURE 0x02 |
||
111 | #define GET_COMM_FEATURE 0x03 |
||
112 | #define CLEAR_COMM_FEATURE 0x04 |
||
113 | #define SET_LINE_CODING 0x20 |
||
114 | #define GET_LINE_CODING 0x21 |
||
115 | #define SET_CONTROL_LINE_STATE 0x22 |
||
116 | #define SEND_BREAK 0x23 |
||
117 | |||
118 | /* Notifications * |
||
119 | * Note: Notifications are polled over |
||
120 | * Communication Interface (Interrupt Endpoint) |
||
121 | */ |
||
122 | #define NETWORK_CONNECTION 0x00 |
||
123 | #define RESPONSE_AVAILABLE 0x01 |
||
124 | #define SERIAL_STATE 0x20 |
||
125 | |||
126 | |||
127 | /* Device Class Code */ |
||
128 | #define CDC_DEVICE 0x02 |
||
129 | |||
130 | /* Communication Interface Class Code */ |
||
131 | #define COMM_INTF 0x02 |
||
132 | |||
133 | /* Communication Interface Class SubClass Codes */ |
||
134 | #define ABSTRACT_CONTROL_MODEL 0x02 |
||
135 | |||
136 | /* Communication Interface Class Control Protocol Codes */ |
||
137 | #define V25TER 0x01 // Common AT commands ("Hayes(TM)") |
||
138 | |||
139 | |||
140 | /* Data Interface Class Codes */ |
||
141 | #define DATA_INTF 0x0A |
||
142 | |||
143 | /* Data Interface Class Protocol Codes */ |
||
144 | #define NO_PROTOCOL 0x00 // No class specific protocol required |
||
145 | |||
146 | |||
147 | /* Communication Feature Selector Codes */ |
||
148 | #define ABSTRACT_STATE 0x01 |
||
149 | #define COUNTRY_SETTING 0x02 |
||
150 | |||
151 | /* Functional Descriptors */ |
||
152 | /* Type Values for the bDscType Field */ |
||
153 | #define CS_INTERFACE 0x24 |
||
154 | #define CS_ENDPOINT 0x25 |
||
155 | |||
156 | /* bDscSubType in Functional Descriptors */ |
||
157 | #define DSC_FN_HEADER 0x00 |
||
158 | #define DSC_FN_CALL_MGT 0x01 |
||
159 | #define DSC_FN_ACM 0x02 // ACM - Abstract Control Management |
||
160 | #define DSC_FN_DLM 0x03 // DLM - Direct Line Managment |
||
161 | #define DSC_FN_TELEPHONE_RINGER 0x04 |
||
162 | #define DSC_FN_RPT_CAPABILITIES 0x05 |
||
163 | #define DSC_FN_UNION 0x06 |
||
164 | #define DSC_FN_COUNTRY_SELECTION 0x07 |
||
165 | #define DSC_FN_TEL_OP_MODES 0x08 |
||
166 | #define DSC_FN_USB_TERMINAL 0x09 |
||
167 | /* more.... see Table 25 in USB CDC Specification 1.1 */ |
||
168 | |||
169 | /* CDC Bulk IN transfer states */ |
||
170 | #define CDC_TX_READY 0 |
||
171 | #define CDC_TX_BUSY 1 |
||
172 | #define CDC_TX_BUSY_ZLP 2 // ZLP: Zero Length Packet |
||
173 | #define CDC_TX_COMPLETING 3 |
||
174 | |||
175 | #if defined(USB_CDC_SET_LINE_CODING_HANDLER) |
||
176 | #define LINE_CODING_TARGET &cdc_notice.SetLineCoding._byte[0] |
||
177 | #define LINE_CODING_PFUNC &USB_CDC_SET_LINE_CODING_HANDLER |
||
178 | #else |
||
179 | #define LINE_CODING_TARGET &line_coding._byte[0] |
||
180 | #define LINE_CODING_PFUNC NULL |
||
181 | #endif |
||
182 | |||
183 | #if defined(USB_CDC_SUPPORT_HARDWARE_FLOW_CONTROL) |
||
184 | #define CONFIGURE_RTS(a) UART_RTS = a; |
||
185 | #define CONFIGURE_DTR(a) UART_DTR = a; |
||
186 | #else |
||
187 | #define CONFIGURE_RTS(a) |
||
188 | #define CONFIGURE_DTR(a) |
||
189 | #endif |
||
190 | |||
191 | #if defined(USB_CDC_SUPPORT_ABSTRACT_CONTROL_MANAGEMENT_CAPABILITIES_D3) |
||
192 | #error This option is not currently supported. |
||
193 | #else |
||
194 | #define USB_CDC_SUPPORT_ABSTRACT_CONTROL_MANAGEMENT_CAPABILITIES_D3_VAL 0x00 |
||
195 | #endif |
||
196 | |||
197 | #if defined(USB_CDC_SUPPORT_ABSTRACT_CONTROL_MANAGEMENT_CAPABILITIES_D2) |
||
198 | #define USB_CDC_SUPPORT_ABSTRACT_CONTROL_MANAGEMENT_CAPABILITIES_D2_VAL 0x04 |
||
199 | #else |
||
200 | #define USB_CDC_SUPPORT_ABSTRACT_CONTROL_MANAGEMENT_CAPABILITIES_D2_VAL 0x00 |
||
201 | #endif |
||
202 | |||
203 | #if defined(USB_CDC_SUPPORT_ABSTRACT_CONTROL_MANAGEMENT_CAPABILITIES_D1) |
||
204 | #define USB_CDC_SUPPORT_ABSTRACT_CONTROL_MANAGEMENT_CAPABILITIES_D1_VAL 0x02 |
||
205 | #else |
||
206 | #define USB_CDC_SUPPORT_ABSTRACT_CONTROL_MANAGEMENT_CAPABILITIES_D1_VAL 0x00 |
||
207 | #endif |
||
208 | |||
209 | #if defined(USB_CDC_SUPPORT_ABSTRACT_CONTROL_MANAGEMENT_CAPABILITIES_D0) |
||
210 | #error This option is not currently supported. |
||
211 | #else |
||
212 | #define USB_CDC_SUPPORT_ABSTRACT_CONTROL_MANAGEMENT_CAPABILITIES_D0_VAL 0x00 |
||
213 | #endif |
||
214 | |||
215 | #define USB_CDC_ACM_FN_DSC_VAL \ |
||
216 | USB_CDC_SUPPORT_ABSTRACT_CONTROL_MANAGEMENT_CAPABILITIES_D3_VAL |\ |
||
217 | USB_CDC_SUPPORT_ABSTRACT_CONTROL_MANAGEMENT_CAPABILITIES_D2_VAL |\ |
||
218 | USB_CDC_SUPPORT_ABSTRACT_CONTROL_MANAGEMENT_CAPABILITIES_D1_VAL |\ |
||
219 | USB_CDC_SUPPORT_ABSTRACT_CONTROL_MANAGEMENT_CAPABILITIES_D0_VAL |
||
220 | |||
221 | /****************************************************************************** |
||
222 | Function: |
||
223 | void CDCSetBaudRate(DWORD baudRate) |
||
224 | |||
225 | Summary: |
||
226 | This macro is used set the baud rate reported back to the host during |
||
227 | a get line coding request. (optional) |
||
228 | |||
229 | Description: |
||
230 | This macro is used set the baud rate reported back to the host during |
||
231 | a get line coding request. |
||
232 | |||
233 | Typical Usage: |
||
234 | <code> |
||
235 | CDCSetBaudRate(19200); |
||
236 | </code> |
||
237 | |||
238 | This function is optional for CDC devices that do not actually convert |
||
239 | the USB traffic to a hardware UART. |
||
240 | |||
241 | PreCondition: |
||
242 | None |
||
243 | |||
244 | Parameters: |
||
245 | DWORD baudRate - The desired baudrate |
||
246 | |||
247 | Return Values: |
||
248 | None |
||
249 | |||
250 | Remarks: |
||
251 | None |
||
252 | |||
253 | *****************************************************************************/ |
||
254 | #define CDCSetBaudRate(baudRate) {line_coding.dwDTERate.Val=baudRate;} |
||
255 | |||
256 | /****************************************************************************** |
||
257 | Function: |
||
258 | void CDCSetCharacterFormat(BYTE charFormat) |
||
259 | |||
260 | Summary: |
||
261 | This macro is used manually set the character format reported back to |
||
262 | the host during a get line coding request. (optional) |
||
263 | |||
264 | Description: |
||
265 | This macro is used manually set the character format reported back to |
||
266 | the host during a get line coding request. |
||
267 | |||
268 | Typical Usage: |
||
269 | <code> |
||
270 | CDCSetCharacterFormat(19200); |
||
271 | </code> |
||
272 | |||
273 | This function is optional for CDC devices that do not actually convert |
||
274 | the USB traffic to a hardware UART. |
||
275 | |||
276 | PreCondition: |
||
277 | None |
||
278 | |||
279 | Parameters: |
||
280 | BYTE charFormat - number of stop bits. Available options are: |
||
281 | * NUM_STOP_BITS_1 - 1 Stop bit |
||
282 | * NUM_STOP_BITS_1_5 - 1.5 Stop bits |
||
283 | * NUM_STOP_BITS_2 - 2 Stop bits |
||
284 | |||
285 | Return Values: |
||
286 | None |
||
287 | |||
288 | Remarks: |
||
289 | None |
||
290 | |||
291 | *****************************************************************************/ |
||
292 | #define CDCSetCharacterFormat(charFormat) {line_coding.bCharFormat=charFormat;} |
||
293 | #define NUM_STOP_BITS_1 0 //1 stop bit - used by CDCSetLineCoding() and CDCSetCharacterFormat() |
||
294 | #define NUM_STOP_BITS_1_5 1 //1.5 stop bit - used by CDCSetLineCoding() and CDCSetCharacterFormat() |
||
295 | #define NUM_STOP_BITS_2 2 //2 stop bit - used by CDCSetLineCoding() and CDCSetCharacterFormat() |
||
296 | |||
297 | /****************************************************************************** |
||
298 | Function: |
||
299 | void CDCSetParity(BYTE parityType) |
||
300 | |||
301 | Summary: |
||
302 | This function is used manually set the parity format reported back to |
||
303 | the host during a get line coding request. (optional) |
||
304 | |||
305 | Description: |
||
306 | This macro is used manually set the parity format reported back to |
||
307 | the host during a get line coding request. |
||
308 | |||
309 | Typical Usage: |
||
310 | <code> |
||
311 | CDCSetParity(PARITY_NONE); |
||
312 | </code> |
||
313 | |||
314 | This function is optional for CDC devices that do not actually convert |
||
315 | the USB traffic to a hardware UART. |
||
316 | |||
317 | PreCondition: |
||
318 | None |
||
319 | |||
320 | Parameters: |
||
321 | BYTE parityType - Type of parity. The options are the following: |
||
322 | * PARITY_NONE |
||
323 | * PARITY_ODD |
||
324 | * PARITY_EVEN |
||
325 | * PARITY_MARK |
||
326 | * PARITY_SPACE |
||
327 | |||
328 | Return Values: |
||
329 | None |
||
330 | |||
331 | Remarks: |
||
332 | None |
||
333 | |||
334 | *****************************************************************************/ |
||
335 | #define CDCSetParity(parityType) {line_coding.bParityType=parityType;} |
||
336 | #define PARITY_NONE 0 //no parity - used by CDCSetLineCoding() and CDCSetParity() |
||
337 | #define PARITY_ODD 1 //odd parity - used by CDCSetLineCoding() and CDCSetParity() |
||
338 | #define PARITY_EVEN 2 //even parity - used by CDCSetLineCoding() and CDCSetParity() |
||
339 | #define PARITY_MARK 3 //mark parity - used by CDCSetLineCoding() and CDCSetParity() |
||
340 | #define PARITY_SPACE 4 //space parity - used by CDCSetLineCoding() and CDCSetParity() |
||
341 | |||
342 | /****************************************************************************** |
||
343 | Function: |
||
344 | void CDCSetDataSize(BYTE dataBits) |
||
345 | |||
346 | Summary: |
||
347 | This function is used manually set the number of data bits reported back |
||
348 | to the host during a get line coding request. (optional) |
||
349 | |||
350 | Description: |
||
351 | This function is used manually set the number of data bits reported back |
||
352 | to the host during a get line coding request. |
||
353 | |||
354 | Typical Usage: |
||
355 | <code> |
||
356 | CDCSetDataSize(8); |
||
357 | </code> |
||
358 | |||
359 | This function is optional for CDC devices that do not actually convert |
||
360 | the USB traffic to a hardware UART. |
||
361 | |||
362 | PreCondition: |
||
363 | None |
||
364 | |||
365 | Parameters: |
||
366 | BYTE dataBits - number of data bits. The options are 5, 6, 7, 8, or 16. |
||
367 | |||
368 | Return Values: |
||
369 | None |
||
370 | |||
371 | Remarks: |
||
372 | None |
||
373 | |||
374 | *****************************************************************************/ |
||
375 | #define CDCSetDataSize(dataBits) {line_coding.bDataBits=dataBits;} |
||
376 | |||
377 | /****************************************************************************** |
||
378 | Function: |
||
379 | void CDCSetLineCoding(DWORD baud, BYTE format, BYTE parity, BYTE dataSize) |
||
380 | |||
381 | Summary: |
||
382 | This function is used to manually set the data reported back |
||
383 | to the host during a get line coding request. (optional) |
||
384 | |||
385 | Description: |
||
386 | This function is used to manually set the data reported back |
||
387 | to the host during a get line coding request. |
||
388 | |||
389 | Typical Usage: |
||
390 | <code> |
||
391 | CDCSetLineCoding(19200, NUM_STOP_BITS_1, PARITY_NONE, 8); |
||
392 | </code> |
||
393 | |||
394 | This function is optional for CDC devices that do not actually convert |
||
395 | the USB traffic to a hardware UART. |
||
396 | |||
397 | PreCondition: |
||
398 | None |
||
399 | |||
400 | Parameters: |
||
401 | DWORD baud - The desired baudrate |
||
402 | BYTE format - number of stop bits. Available options are: |
||
403 | * NUM_STOP_BITS_1 - 1 Stop bit |
||
404 | * NUM_STOP_BITS_1_5 - 1.5 Stop bits |
||
405 | * NUM_STOP_BITS_2 - 2 Stop bits |
||
406 | BYTE parity - Type of parity. The options are the following: |
||
407 | * PARITY_NONE |
||
408 | * PARITY_ODD |
||
409 | * PARITY_EVEN |
||
410 | * PARITY_MARK |
||
411 | * PARITY_SPACE |
||
412 | BYTE dataSize - number of data bits. The options are 5, 6, 7, 8, or 16. |
||
413 | |||
414 | Return Values: |
||
415 | None |
||
416 | |||
417 | Remarks: |
||
418 | None |
||
419 | |||
420 | *****************************************************************************/ |
||
421 | #define CDCSetLineCoding(baud,format,parity,dataSize) {\ |
||
422 | CDCSetBaudRate(baud);\ |
||
423 | CDCSetCharacterFormat(format);\ |
||
424 | CDCSetParity(parity);\ |
||
425 | CDCSetDataSize(dataSize);\ |
||
426 | } |
||
427 | |||
428 | /****************************************************************************** |
||
429 | Function: |
||
430 | BOOL USBUSARTIsTxTrfReady(void) |
||
431 | |||
432 | Summary: |
||
433 | This macro is used to check if the CDC class is ready |
||
434 | to send more data. |
||
435 | |||
436 | Description: |
||
437 | This macro is used to check if the CDC class is ready |
||
438 | to send more data. |
||
439 | |||
440 | Typical Usage: |
||
441 | <code> |
||
442 | if(USBUSARTIsTxTrfReady()) |
||
443 | { |
||
444 | putrsUSBUSART("Hello World"); |
||
445 | } |
||
446 | </code> |
||
447 | |||
448 | PreCondition: |
||
449 | The return value of this function is only valid if the device is in a |
||
450 | configured state (i.e. - USBDeviceGetState() returns CONFIGURED_STATE) |
||
451 | |||
452 | Parameters: |
||
453 | None |
||
454 | |||
455 | Return Values: |
||
456 | None |
||
457 | |||
458 | Remarks: |
||
459 | None |
||
460 | |||
461 | *****************************************************************************/ |
||
462 | #define USBUSARTIsTxTrfReady() (cdc_trf_state == CDC_TX_READY) |
||
463 | |||
464 | /****************************************************************************** |
||
465 | Function: |
||
466 | void mUSBUSARTTxRam(BYTE *pData, BYTE len) |
||
467 | |||
468 | Description: |
||
469 | Depricated in MCHPFSUSB v2.3. This macro has been replaced by |
||
470 | USBUSARTIsTxTrfReady(). |
||
471 | *****************************************************************************/ |
||
472 | #define mUSBUSARTIsTxTrfReady() USBUSARTIsTxTrfReady() |
||
473 | |||
474 | /****************************************************************************** |
||
475 | Function: |
||
476 | void mUSBUSARTTxRam(BYTE *pData, BYTE len) |
||
477 | |||
478 | Description: |
||
479 | Use this macro to transfer data located in data memory. |
||
480 | Use this macro when: |
||
481 | 1. Data stream is not null-terminated |
||
482 | 2. Transfer length is known |
||
483 | Remember: cdc_trf_state must == CDC_TX_READY |
||
484 | Unlike putsUSBUSART, there is not code double checking |
||
485 | the transfer state. Unexpected behavior will occur if |
||
486 | this function is called when cdc_trf_state != CDC_TX_READY |
||
487 | |||
488 | PreCondition: |
||
489 | cdc_trf_state must be in the CDC_TX_READY state. |
||
490 | Value of 'len' must be equal to or smaller than 255 bytes. |
||
491 | |||
492 | Paramters: |
||
493 | pDdata : Pointer to the starting location of data bytes |
||
494 | len : Number of bytes to be transferred |
||
495 | |||
496 | Return Values: |
||
497 | None |
||
498 | |||
499 | Remarks: |
||
500 | This macro only handles the setup of the transfer. The |
||
501 | actual transfer is handled by CDCTxService(). |
||
502 | |||
503 | *****************************************************************************/ |
||
504 | #define mUSBUSARTTxRam(pData,len) \ |
||
505 | { \ |
||
506 | pCDCSrc.bRam = pData; \ |
||
507 | cdc_tx_len = len; \ |
||
508 | cdc_mem_type = USB_EP0_RAM; \ |
||
509 | cdc_trf_state = CDC_TX_BUSY; \ |
||
510 | } |
||
511 | |||
512 | /****************************************************************************** |
||
513 | Function: |
||
514 | void mUSBUSARTTxRom(rom BYTE *pData, BYTE len) |
||
515 | |||
516 | Description: |
||
517 | Use this macro to transfer data located in program memory. |
||
518 | Use this macro when: |
||
519 | 1. Data stream is not null-terminated |
||
520 | 2. Transfer length is known |
||
521 | |||
522 | Remember: cdc_trf_state must == CDC_TX_READY |
||
523 | Unlike putrsUSBUSART, there is not code double checking |
||
524 | the transfer state. Unexpected behavior will occur if |
||
525 | this function is called when cdc_trf_state != CDC_TX_READY |
||
526 | |||
527 | PreCondition: |
||
528 | cdc_trf_state must be in the CDC_TX_READY state. |
||
529 | Value of 'len' must be equal to or smaller than 255 bytes. |
||
530 | |||
531 | Parameters: |
||
532 | pDdata : Pointer to the starting location of data bytes |
||
533 | len : Number of bytes to be transferred |
||
534 | |||
535 | Return Values: |
||
536 | None |
||
537 | |||
538 | Remarks: |
||
539 | This macro only handles the setup of the transfer. The |
||
540 | actual transfer is handled by CDCTxService(). |
||
541 | |||
542 | *****************************************************************************/ |
||
543 | #define mUSBUSARTTxRom(pData,len) \ |
||
544 | { \ |
||
545 | pCDCSrc.bRom = pData; \ |
||
546 | cdc_tx_len = len; \ |
||
547 | cdc_mem_type = USB_EP0_ROM; \ |
||
548 | cdc_trf_state = CDC_TX_BUSY; \ |
||
549 | } |
||
550 | |||
551 | /** S T R U C T U R E S ******************************************************/ |
||
552 | |||
553 | /* Line Coding Structure */ |
||
554 | #define LINE_CODING_LENGTH 0x07 |
||
555 | |||
556 | typedef union _LINE_CODING |
||
557 | { |
||
558 | struct |
||
559 | { |
||
560 | BYTE _byte[LINE_CODING_LENGTH]; |
||
561 | }; |
||
562 | struct |
||
563 | { |
||
564 | DWORD_VAL dwDTERate; // Complex data structure |
||
565 | BYTE bCharFormat; |
||
566 | BYTE bParityType; |
||
567 | BYTE bDataBits; |
||
568 | }; |
||
569 | } LINE_CODING; |
||
570 | |||
571 | typedef union _CONTROL_SIGNAL_BITMAP |
||
572 | { |
||
573 | BYTE _byte; |
||
574 | struct |
||
575 | { |
||
576 | unsigned DTE_PRESENT:1; // [0] Not Present [1] Present |
||
577 | unsigned CARRIER_CONTROL:1; // [0] Deactivate [1] Activate |
||
578 | }; |
||
579 | } CONTROL_SIGNAL_BITMAP; |
||
580 | |||
581 | |||
582 | /* Functional Descriptor Structure - See CDC Specification 1.1 for details */ |
||
583 | |||
584 | /* Header Functional Descriptor */ |
||
585 | typedef struct __attribute__((packed)) _USB_CDC_HEADER_FN_DSC |
||
586 | { |
||
587 | BYTE bFNLength; |
||
588 | BYTE bDscType; |
||
589 | BYTE bDscSubType; |
||
590 | WORD bcdCDC; |
||
591 | } USB_CDC_HEADER_FN_DSC; |
||
592 | |||
593 | /* Abstract Control Management Functional Descriptor */ |
||
594 | typedef struct __attribute__((packed)) _USB_CDC_ACM_FN_DSC |
||
595 | { |
||
596 | BYTE bFNLength; |
||
597 | BYTE bDscType; |
||
598 | BYTE bDscSubType; |
||
599 | BYTE bmCapabilities; |
||
600 | } USB_CDC_ACM_FN_DSC; |
||
601 | |||
602 | /* Union Functional Descriptor */ |
||
603 | typedef struct __attribute__((packed)) _USB_CDC_UNION_FN_DSC |
||
604 | { |
||
605 | BYTE bFNLength; |
||
606 | BYTE bDscType; |
||
607 | BYTE bDscSubType; |
||
608 | BYTE bMasterIntf; |
||
609 | BYTE bSaveIntf0; |
||
610 | } USB_CDC_UNION_FN_DSC; |
||
611 | |||
612 | /* Call Management Functional Descriptor */ |
||
613 | typedef struct __attribute__((packed)) _USB_CDC_CALL_MGT_FN_DSC |
||
614 | { |
||
615 | BYTE bFNLength; |
||
616 | BYTE bDscType; |
||
617 | BYTE bDscSubType; |
||
618 | BYTE bmCapabilities; |
||
619 | BYTE bDataInterface; |
||
620 | } USB_CDC_CALL_MGT_FN_DSC; |
||
621 | |||
622 | typedef union __attribute__((packed)) _CDC_NOTICE |
||
623 | { |
||
624 | LINE_CODING GetLineCoding; |
||
625 | LINE_CODING SetLineCoding; |
||
626 | unsigned char packet[CDC_COMM_IN_EP_SIZE]; |
||
627 | } CDC_NOTICE, *PCDC_NOTICE; |
||
628 | |||
629 | /** E X T E R N S ************************************************************/ |
||
630 | extern BYTE cdc_rx_len; |
||
631 | extern USB_HANDLE lastTransmission; |
||
632 | |||
633 | extern BYTE cdc_trf_state; |
||
634 | extern POINTER pCDCSrc; |
||
635 | extern BYTE cdc_tx_len; |
||
636 | extern BYTE cdc_mem_type; |
||
637 | |||
638 | extern volatile FAR CDC_NOTICE cdc_notice; |
||
639 | extern LINE_CODING line_coding; |
||
640 | |||
641 | extern volatile CTRL_TRF_SETUP SetupPkt; |
||
642 | extern ROM BYTE configDescriptor1[]; |
||
643 | |||
644 | /** Public Prototypes *************************************************/ |
||
645 | void USBCheckCDCRequest(void); |
||
646 | void CDCInitEP(void); |
||
647 | BYTE getsUSBUSART(char *buffer, BYTE len); |
||
648 | void putrsUSBUSART(const ROM char *data); |
||
649 | void putUSBUSART(char *data, BYTE Length); |
||
650 | void putsUSBUSART(char *data); |
||
651 | void CDCTxService(void); |
||
652 | |||
653 | #endif //CDC_H |
Powered by WebSVN v2.8.3