summaryrefslogtreecommitdiff
path: root/usblib/usbcdc.h
blob: b96fff72c152de167a9494e661f7a90e701aaf78 (plain)
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
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
//*****************************************************************************
//
// usbhid.h - Definitions used by Communication Device Class devices.
//
// Copyright (c) 2007-2012 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 9453 of the Stellaris USB Library.
//
//*****************************************************************************

//*****************************************************************************
//
// Note: This header contains definitions related to the USB Communication
//       Device Class specification.  The header is complete for ACM model
//       devices but request and notification definitions specific to other
//       modem types, ISDN, ATM and Ethernet are currently incomplete or
//       omitted.
//
//*****************************************************************************

#ifndef __USBCDC_H__
#define __USBCDC_H__

//*****************************************************************************
//
// If building with a C++ compiler, make all of the definitions in this header
// have a C binding.
//
//*****************************************************************************
#ifdef __cplusplus
extern "C"
{
#endif

//*****************************************************************************
//
//! \addtogroup cdc_device_class_api
//! @{
//
//*****************************************************************************

//*****************************************************************************
//
// Generic macros to read a byte, word or long from a character pointer.
//
//*****************************************************************************
#define BYTE(pucData)           (*(unsigned char *)(pucData))
#define SHORT(pucData)          (*(unsigned short *)(pucData))
#define LONG(pucData)           (*(unsigned long *)(pucData))

//*****************************************************************************
//
// USB CDC subclass codes.  Used in interface descriptor, bInterfaceClass
//
//*****************************************************************************
#define USB_CDC_SUBCLASS_DIRECT_LINE_MODEL          0x01
#define USB_CDC_SUBCLASS_ABSTRACT_MODEL             0x02
#define USB_CDC_SUBCLASS_TELEPHONE_MODEL            0x03
#define USB_CDC_SUBCLASS_MULTI_CHANNEL_MODEL        0x04
#define USB_CDC_SUBCLASS_CAPI_MODEL                 0x05
#define USB_CDC_SUBCLASS_ETHERNET_MODEL             0x06
#define USB_CDC_SUBCLASS_ATM_MODEL                  0x07

//*****************************************************************************
//
// USB CDC control interface protocols.  Used in control interface descriptor,
// bInterfaceProtocol
//
//*****************************************************************************
#define USB_CDC_PROTOCOL_NONE                       0x00
#define USB_CDC_PROTOCOL_V25TER                     0x01
#define USB_CDC_PROTOCOL_VENDOR                     0xFF

//*****************************************************************************
//
// USB CDC data interface protocols.  Used in data interface descriptor,
// bInterfaceProtocol
//
//*****************************************************************************
//      USB_CDC_PROTOCOL_NONE                       0x00
#define USB_CDC_PROTOCOL_I420                       0x30
#define USB_CDC_PROTOCOL_TRANSPARENT                0x32
#define USB_CDC_PROTOCOL_Q921M                      0x50
#define USB_CDC_PROTOCOL_Q921                       0x51
#define USB_CDC_PROTOCOL_Q921TM                     0x52
#define USB_CDC_PROTOCOL_V42BIS                     0x90
#define USB_CDC_PROTOCOL_Q921EURO                   0x91
#define USB_CDC_PROTOCOL_V120                       0x92
#define USB_CDC_PROTOCOL_CAPI20                     0x93
#define USB_CDC_PROTOCOL_HOST_DRIVER                0xFD
#define USB_CDC_PROTOCOL_CDC_SPEC                   0xFE
//      USB_CDC_PROTOCOL_VENDOR                     0xFF

//*****************************************************************************
//
// Functional descriptor definitions
//
//*****************************************************************************

//*****************************************************************************
//
// Functional descriptor types
//
//*****************************************************************************
#define USB_CDC_CS_INTERFACE                    0x24
#define USB_CDC_CS_ENDPOINT                     0x25

//*****************************************************************************
//
// Functional descriptor subtypes
//
//*****************************************************************************
#define USB_CDC_FD_SUBTYPE_HEADER               0x00
#define USB_CDC_FD_SUBTYPE_CALL_MGMT            0x01
#define USB_CDC_FD_SUBTYPE_ABSTRACT_CTL_MGMT    0x02
#define USB_CDC_FD_SUBTYPE_DIRECT_LINE_MGMT     0x03
#define USB_CDC_FD_SUBTYPE_TELEPHONE_RINGER     0x04
#define USB_CDC_FD_SUBTYPE_LINE_STATE_CAPS      0x05
#define USB_CDC_FD_SUBTYPE_UNION                0x06
#define USB_CDC_FD_SUBTYPE_COUNTRY              0x07
#define USB_CDC_FD_SUBTYPE_TELEPHONE_MODES      0x08
#define USB_CDC_FD_SUBTYPE_USB_TERMINAL         0x09
#define USB_CDC_FD_SUBTYPE_NETWORK_TERMINAL     0x0A
#define USB_CDC_FD_SUBTYPE_PROTOCOL_UNIT        0x0B
#define USB_CDC_FD_SUBTYPE_EXTENSION_UNIT       0x0C
#define USB_CDC_FD_SUBTYPE_MULTI_CHANNEL_MGMT   0x0D
#define USB_CDC_FD_SUBTYPE_CAPI_MGMT            0x0E
#define USB_CDC_FD_SUBTYPE_ETHERNET             0x0F
#define USB_CDC_FD_SUBTYPE_ATM                  0x10

//*****************************************************************************
//
// USB_CDC_FD_SUBTYPE_CALL_MGMT, Header functional descriptor, bmCapabilities
//
//*****************************************************************************
#define USB_CDC_CALL_MGMT_VIA_DATA              0x02
#define USB_CDC_CALL_MGMT_HANDLED               0x01

//*****************************************************************************
//
// USB_CDC_FD_SUBTYPE_ABSTRACT_CTL_MGMT, Abstract Control Management functional
// descriptor, bmCapabilities
//
//*****************************************************************************
#define USB_CDC_ACM_SUPPORTS_NETWORK_CONNECTION 0x08
#define USB_CDC_ACM_SUPPORTS_SEND_BREAK         0x04
#define USB_CDC_ACM_SUPPORTS_LINE_PARAMS        0x02
#define USB_CDC_ACM_SUPPORTS_COMM_FEATURE       0x01

//*****************************************************************************
//
// USB_CDC_FD_SUBTYPE_DIRECT_LINE_MGMT, Direct Line Management functional
// descriptor, bmCapabilities
//
//*****************************************************************************
#define USB_CDC_DLM_NEEDS_EXTRA_PULSE_SETUP     0x04
#define USB_CDC_DLM_SUPPORTS_AUX                0x02
#define USB_CDC_DLM_SUPPORTS_PULSE              0x01

//*****************************************************************************
//
// USB_CDC_FD_SUBTYPE_TELEPHONE_MODES, Telephone Operational Modes functional
// descriptor, bmCapabilities
//
//*****************************************************************************
#define USB_CDC_TELEPHONE_SUPPORTS_COMPUTER     0x04
#define USB_CDC_TELEPHONE_SUPPORTS_STANDALONE   0x02
#define USB_CDC_TELEPHONE_SUPPORTS_SIMPLE       0x01

//*****************************************************************************
//
// USB_CDC_FD_SUBTYPE_LINE_STATE_CAPS, Telephone Call and Line State Reporting
// Capabilities descriptor
//
//*****************************************************************************
#define USB_CDC_LINE_STATE_CHANGES_NOTIFIED     0x20
#define USB_CDC_LINE_STATE_REPORTS_DTMF         0x10
#define USB_CDC_LINE_STATE_REPORTS_DIST_RING    0x08
#define USB_CDC_LINE_STATE_REPORTS_CALLERID     0x04
#define USB_CDC_LINE_STATE_REPORTS_BUSY         0x02
#define USB_CDC_LINE_STATE_REPORTS_INT_DIALTONE 0x01

//*****************************************************************************
//
// USB_CDC_FD_SUBTYPE_USB_TERMINAL, USB Terminal functional descriptor,
// bmOptions
//
//*****************************************************************************
#define USB_CDC_TERMINAL_NO_WRAPPER_USED        0x00
#define USB_CDC_TERMINAL_WRAPPER_USED           0x01

//*****************************************************************************
//
// USB_CDC_FD_SUBTYPE_MULTI_CHANNEL_MGMT, Multi-Channel Management functional
// descriptor, bmCapabilities
//
//*****************************************************************************
#define USB_CDC_MCM_SUPPORTS_SET_UNIT_PARAM     0x04
#define USB_CDC_MCM_SUPPORTS_CLEAR_UNIT_PARAM   0x02
#define USB_CDC_MCM_UNIT_PARAMS_NON_VOLATILE    0x01

//*****************************************************************************
//
// USB_CDC_FD_SUBTYPE_CAPI_MGMT, CAPI Control Management functional descriptor,
// bmCapabilities
//
//*****************************************************************************
#define USB_CDC_CAPI_INTELLIGENT                0x01
#define USB_CDC_CAPI_SIMPLE                     0x00

//*****************************************************************************
//
// USB_CDC_FD_SUBTYPE_ETHERNET, Ethernet Networking functional descriptor,
// bmEthernetStatistics
//
//*****************************************************************************
#define USB_CDC_ETHERNET_XMIT_OK                0x01000000
#define USB_CDC_ETHERNET_RCV_OK                 0x02000000
#define USB_CDC_ETHERNET_XMIT_ERROR             0x04000000
#define USB_CDC_ETHERNET_RCV_ERROR              0x08000000
#define USB_CDC_ETHERNET_RCV_NO_BUFFER          0x10000000
#define USB_CDC_ETHERNET_DIRECTED_BYTES_XMIT    0x20000000
#define USB_CDC_ETHERNET_DIRECTED_FRAMES_XMIT   0x40000000
#define USB_CDC_ETHERNET_MULTICAST_BYTES_XMIT   0x80000000
#define USB_CDC_ETHERNET_MULTICAST_FRAMES_XMIT  0x00010000
#define USB_CDC_ETHERNET_BROADCAST_BYTES_XMIT   0x00020000
#define USB_CDC_ETHERNET_BROADCAST_FRAMES_XMIT  0x00040000
#define USB_CDC_ETHERNET_DIRECTED_BYTES_RCV     0x00080000
#define USB_CDC_ETHERNET_DIRECTED_FRAMES_RCV    0x00100000
#define USB_CDC_ETHERNET_MULTICAST_BYTES_RCV    0x00200000
#define USB_CDC_ETHERNET_MULTICAST_FRAMES_RCV   0x00400000
#define USB_CDC_ETHERNET_BROADCAST_BYTES_RCV    0x00800000
#define USB_CDC_ETHERNET_BROADCAST_FRAMES_RCV   0x00000100
#define USB_CDC_ETHERNET_RCV_CRC_ERROR          0x00000200
#define USB_CDC_ETHERNET_TRANSMIT_QUEUE_LENGTH  0x00000400
#define USB_CDC_ETHERNET_RCV_ERROR_ALIGNMENT    0x00000800
#define USB_CDC_ETHERNET_XMIT_ONE_COLLISION     0x00001000
#define USB_CDC_ETHERNET_XMIT_MORE_COLLISIONS   0x00002000
#define USB_CDC_ETHERNET_XMIT_DEFERRED          0x00004000
#define USB_CDC_ETHERNET_XMIT_MAX_COLLISIONS    0x00008000
#define USB_CDC_ETHERNET_RCV_OVERRUN            0x00000001
#define USB_CDC_ETHERNET_XMIT_UNDERRUN          0x00000002
#define USB_CDC_ETHERNET_XMIT_HEARTBEAT_FAILURE 0x00000004
#define USB_CDC_ETHERNET_XMIT_TIMES_CRS_LOST    0x00000008
#define USB_CDC_ETHERNET_XMIT_LATE_COLLISIONS   0x00000010

//*****************************************************************************
//
// USB_CDC_FD_SUBTYPE_ATM, ATM Networking functional descriptor,
// bmDataCapabilities
//
//*****************************************************************************
#define USB_CDC_ATM_TYPE_3                      0x08
#define USB_CDC_ATM_TYPE_2                      0x04
#define USB_CDC_ATM_TYPE_1                      0x02

//*****************************************************************************
//
// bmATMDeviceStatistics
//
//*****************************************************************************
#define USB_CDC_ATM_VC_US_CELLS_SENT            0x10
#define USB_CDC_ATM_VC_US_CELLS_RECEIVED        0x08
#define USB_CDC_ATM_DS_CELLS_HEC_ERR_CORRECTED  0x04
#define USB_CDC_ATM_US_CELLS_SENT               0x02
#define USB_CDC_ATM_US_CELLS_RECEIVED           0x01

//*****************************************************************************
//
// Management Element Requests (provided in tUSBRequest.ucRequest)
//
//*****************************************************************************
#define USB_CDC_SEND_ENCAPSULATED_COMMAND                       0x00
#define USB_CDC_GET_ENCAPSULATED_RESPONSE                       0x01
#define USB_CDC_SET_COMM_FEATURE                                0x02
#define USB_CDC_GET_COMM_FEATURE                                0x03
#define USB_CDC_CLEAR_COMM_FEATURE                              0x04
#define USB_CDC_SET_AUX_LINE_STATE                              0x10
#define USB_CDC_SET_HOOK_STATE                                  0x11
#define USB_CDC_PULSE_SETUP                                     0x12
#define USB_CDC_SEND_PULSE                                      0x13
#define USB_CDC_SET_PULSE_TIME                                  0x14
#define USB_CDC_RING_AUX_JACK                                   0x15
#define USB_CDC_SET_LINE_CODING                                 0x20
#define USB_CDC_GET_LINE_CODING                                 0x21
#define USB_CDC_SET_CONTROL_LINE_STATE                          0x22
#define USB_CDC_SEND_BREAK                                      0x23
#define USB_CDC_SET_RINGER_PARMS                                0x30
#define USB_CDC_GET_RINGER_PARMS                                0x31
#define USB_CDC_SET_OPERATION_PARMS                             0x32
#define USB_CDC_GET_OPERATION_PARMS                             0x33
#define USB_CDC_SET_LINE_PARMS                                  0x34
#define USB_CDC_GET_LINE_PARMS                                  0x35
#define USB_CDC_DIAL_DIGITS                                     0x36
#define USB_CDC_SET_UNIT_PARAMETER                              0x37
#define USB_CDC_GET_UNIT_PARAMETER                              0x38
#define USB_CDC_CLEAR_UNIT_PARAMETER                            0x39
#define USB_CDC_GET_PROFILE                                     0x3A
#define USB_CDC_SET_ETHERNET_MULTICAST_FILTERS                  0x40
#define USB_CDC_SET_ETHERNET_POWER_MANAGEMENT_PATTERN_FILTER    0x41
#define USB_CDC_GET_ETHERNET_POWER_MANAGEMENT_PATTERN_FILTER    0x42
#define USB_CDC_SET_ETHERNET_PACKET_FILTER                      0x43
#define USB_CDC_GET_ETHERNET_STATISTIC                          0x44
#define USB_CDC_SET_ATM_DATA_FORMAT                             0x50
#define USB_CDC_GET_ATM_DEVICE_STATISTICS                       0x51
#define USB_CDC_SET_ATM_DEFAULT_VC                              0x52
#define USB_CDC_GET_ATM_VC_STATISTICS                           0x53

//*****************************************************************************
//
// In cases where a request defined above results in the return of a fixed size
// data block, the following group of labels define the size of that block.  In
// each of these cases, an access macro is also provided to write the response
// data into an appropriately-sized array of unsigned characters.
//
//*****************************************************************************
#define USB_CDC_SIZE_COMM_FEATURE                                2
#define USB_CDC_SIZE_LINE_CODING                                 7
#define USB_CDC_SIZE_RINGER_PARMS                                4
#define USB_CDC_SIZE_OPERATION_PARMS                             2
#define USB_CDC_SIZE_UNIT_PARAMETER                              2
#define USB_CDC_SIZE_PROFILE                                     64
#define USB_CDC_SIZE_ETHERNET_POWER_MANAGEMENT_PATTERN_FILTER    2
#define USB_CDC_SIZE_ETHERNET_STATISTIC                          4
#define USB_CDC_SIZE_ATM_DEVICE_STATISTICS                       4
#define USB_CDC_SIZE_ATM_VC_STATISTICS                           4
#define USB_CDC_SIZE_LINE_PARMS                                  10

//*****************************************************************************
//
// NB: USB_CDC_SIZE_LINE_PARAMS assumes only a single call.  For multiple
// calls, add 4 bytes per additional call.
//
//*****************************************************************************

//*****************************************************************************
//
// USB_CDC_GET_COMM_FEATURE & USB_CDC_SET_COMM_FEATURE
//
//*****************************************************************************

//*****************************************************************************
//
// wValue (Feature Selector)
//
//*****************************************************************************
#define USB_CDC_ABSTRACT_STATE                  0x0001
#define USB_CDC_COUNTRY_SETTING                 0x0002

//*****************************************************************************
//
// Data when feature selector is USB_DCD_ABSTRACT_STATE
//
//*****************************************************************************
#define USB_CDC_ABSTRACT_CALL_DATA_MULTIPLEXED  0x0002
#define USB_CDC_ABSTRACT_ENDPOINTS_IDLE         0x0001

//*****************************************************************************
//
// Macros to populate the response data buffer (whose size in bytes is defined
// by USB_CDC_SIZE_COMM_FEATURE).
//
//*****************************************************************************
#define SetResponseCommFeature(pcBuf, usData)        \
        do                                           \
        {                                            \
            (*(unsigned short *)(pcBuf)) = (usData); \
        }                                            \
        while(0)

//*****************************************************************************
//
// USB_CDC_SET_AUX_LINE_STATE, wValue
//
//*****************************************************************************
#define USB_CDC_AUX_DISCONNECT                  0x0000
#define USB_CDC_AUX_CONNECT                     0x0001

//*****************************************************************************
//
// USB_CDC_SET_HOOK_STATE, wValue
//
//*****************************************************************************
#define USB_CDC_ON_HOOK                         0x0000
#define USB_CDC_OFF_HOOK                        0x0001
#define USB_CDC_SNOOPING                        0x0002

//*****************************************************************************
//
// USB_CDC_GET_LINE_CODING
//
//*****************************************************************************
#define USB_CDC_STOP_BITS_1                     0x00
#define USB_CDC_STOP_BITS_1_5                   0x01
#define USB_CDC_STOP_BITS_2                     0x02

#define USB_CDC_PARITY_NONE                     0x00
#define USB_CDC_PARITY_ODD                      0x01
#define USB_CDC_PARITY_EVEN                     0x02
#define USB_CDC_PARITY_MARK                     0x03
#define USB_CDC_PARITY_SPACE                    0x04

//*****************************************************************************
//
// Macro to populate the response data buffer (whose size in bytes is defined
// by USB_CDC_SIZE_LINE_CODING).
//
//*****************************************************************************
#define SetResponseLineCoding(pcBuf, ucRate, ucStop, ucParity, ucDatabits) \
        do                                                                 \
        {                                                                  \
            (*(unsigned long *)(pcBuf)) = (ucRate);                        \
            (*((unsigned char *)(pcBuf) + 4)) = (ucStop);                  \
            (*((unsigned char *)(pcBuf) + 5)) = (ucParity);                \
            (*((unsigned char *)(pcBuf) + 6)) = (ucDatabits);              \
        }                                                                  \
        while(0)

//*****************************************************************************
//
// USB_CDC_SET_CONTROL_LINE_STATE, wValue
//
//*****************************************************************************
#define USB_CDC_DEACTIVATE_CARRIER              0x00
#define USB_CDC_ACTIVATE_CARRIER                0x02
#define USB_CDC_DTE_NOT_PRESENT                 0x00
#define USB_CDC_DTE_PRESENT                     0x01

//*****************************************************************************
//
// USB_CDC_SET_RINGER_PARMS, USB_CDC_GET_RINGER_PARMS and
// USB_CDC_GET_LINE_PARMS (ulRingerBmp)
//
//*****************************************************************************
#define USB_CDC_RINGER_EXISTS                   0x80000000
#define USB_CDC_RINGER_DOES_NOT_EXIST           0x00000000

//*****************************************************************************
//
// Macro to populate the response data buffer to USB_CDC_GET_RINGER_PARMS.
// Parameter buf points to a buffer of size USB_CDC_SIZE_RINGER_PARMS bytes.
//
//*****************************************************************************
#define SetResponseRingerParms(pcBuf, ucPattern, ucVolume, ulExists)          \
        do                                                                    \
        {                                                                     \
            *(unsigned long *)(pcBuf) = ((ucPattern) +                        \
                                         ((ucVolume & 0xFF) << 8) +           \
                                         (ulExists & USB_CDC_RINGER_EXISTS)); \
        }                                                                     \
        while(0)

//*****************************************************************************
//
// Macros to extract fields from the USB_CDC_SET_RINGER_PARMS data
//
//*****************************************************************************
#define GetRingerVolume(pcData)  (BYTE((pcData)+1))
#define GetRingerPattern(pcData) (BYTE(pcData))
#define GetRingerExists(pcData)  ((LONG(pcData)) & USB_CDC_RINGER_EXISTS)

//*****************************************************************************
//
// USB_CDC_SET_OPERATION_PARMS, wValue
//
//*****************************************************************************
#define USB_CDC_SIMPLE_MODE                     0x0000
#define USB_CDC_STANDALONE_MODE                 0x0001
#define USB_CDC_HOST_CENTRIC_MODE               0x0002

//*****************************************************************************
//
// Macro to populate the response data buffer to USB_CDC_GET_OPERATION_PARMS.
// Parameter buf points to a buffer of size USB_CDC_SIZE_OPERATION_PARMS
// bytes.
//
//*****************************************************************************
#define SetResponseOperationParms(pBbuf, usData) \
        do                                       \
        {                                        \
            WORD(pcBuf) = (usData);              \
        }                                        \
        while(0)

//*****************************************************************************
//
// USB_CDC_SET_LINE_PARMS, wParam - Line State Change
//
//*****************************************************************************
#define USB_CDC_DROP_ACTIVE_CALL                0x0000
#define USB_CDC_START_NEW_CALL                  0x0001
#define USB_CDC_APPLY_RINGING                   0x0002
#define USB_CDC_REMOVE_RINGING                  0x0003
#define USB_CDC_SWITCH_CALL                     0x0004

//*****************************************************************************
//
// Line state bitmap in USB_CDC_GET_LINE_PARMS response
//
//*****************************************************************************
#define USB_CDC_LINE_IS_ACTIVE                  0x80000000
#define USB_CDC_LINE_IS_IDLE                    0x00000000
#define USB_CDC_LINE_NO_ACTIVE_CALL             0x000000FF

#define USB_CDC_CALL_ACTIVE                     0x80000000

//*****************************************************************************
//
// Call state value definitions
//
//*****************************************************************************
#define USB_CDC_CALL_IDLE                       0x00000000
#define USB_CDC_CALL_TYPICAL_DIALTONE           0x00000001
#define USB_CDC_CALL_INTERRUPTED_DIALTONE       0x00000002
#define USB_CDC_CALL_DIALING                    0x00000003
#define USB_CDC_CALL_RINGBACK                   0x00000004
#define USB_CDC_CALL_CONNECTED                  0x00000005
#define USB_CDC_CALL_INCOMING                   0x00000006

//*****************************************************************************
//
// Call state change value definitions
//
//*****************************************************************************
#define USB_CDC_CALL_STATE_IDLE                 0x01
#define USB_CDC_CALL_STATE_DIALING              0x02
#define USB_CDC_CALL_STATE_RINGBACK             0x03
#define USB_CDC_CALL_STATE_CONNECTED            0x04
#define USB_CDC_CALL_STATE_INCOMING             0x05

//*****************************************************************************
//
// Extra byte of data describing the connection type for
// USB_CDC_CALL_STATE_CONNECTED.
//
//*****************************************************************************
#define USB_CDC_VOICE                           0x00
#define USB_CDC_ANSWERING_MACHINE               0x01
#define USB_CDC_FAX                             0x02
#define USB_CDC_MODEM                           0x03
#define USB_CDC_UNKNOWN                         0xFF

//*****************************************************************************
//
// Macro to extract call index from request in cases where wParam is
// USB_CDC_SWITCH_CALL.
//
//*****************************************************************************
#define GetCallIndex(pcData) (BYTE(pcData))

//*****************************************************************************
//
// Macro to populate the CallState entries in response to request
// USB_CDC_GET_LINE_PARMS.  The ucIndex parameter is a zero based index
// indicating which call entry in the pcBuf response buffer to fill in.  Note
// that pcBuf points to the first byte of the buffer (the wLength field).
//
//*****************************************************************************
#define SetResponseCallState(pcBuf, ucIndex, ulActive, ucStateChange,   \
                             ucState)                                   \
        do                                                              \
        {                                                               \
            (LONG((unsigned char *)(pcBuf) + (10 + (4 * (ucIndex))))) = \
                (((ulActive) & USB_CDC_CALL_IS_ACTIVE) +                \
                 (((ucStateChange) & 0xFF) << 8) +                      \
                 ((ucState) & 0xFF));                                   \
        }                                                               \
        while(0)

//*****************************************************************************
//
// Macro to populate the response data buffer (whose size in bytes is defined
// by USB_CDC_SIZE_LINE_PARMS).  Note that this macro only populates fields for
// a single call.  If multiple calls are being managed, additional 4 byte
// fields must be appended to provide call state for each call after the first.
// This may be done using the SetResponseCallState macro with the appropriate
// call index supplied.
//
//*****************************************************************************
#define SetResponseLineParms(pcBuf, usLength,                              \
                             ucRingPattern, ucRingVolume, ulRingExists,    \
                             ulLineActive, ucLineCallIndex,                \
                             ulCallActive, ucCallStateChange, ucCallState) \
        do                                                                 \
        {                                                                  \
            (WORD(pcBuf)) = (usLength);                                    \
            SetResponseRingerParams(((unsigned char *)(pcBuf) + 2),        \
                                    (ucRingPattern), (ucRingVolume),       \
                                    (ulRingExists));                       \
            (LONG((unsigned char *)(pcBuf) + 6)) =                         \
                (((ulLineActive) & USB_CDC_LINE_IS_ACTIVE) +               \
                 ((ucLineCallIndex) & 0xFF)) ;                             \
            SetResponseCallState((pcBuf), 0, (ulCallActive),               \
                                 (ucCallStateChange), (ucCallState));      \
        }                                                                  \
        while(0)

//*****************************************************************************
//
// Notification Element definitions
//
//*****************************************************************************
#define USB_CDC_NOTIFY_NETWORK_CONNECTION               0x00
#define USB_CDC_NOTIFY_RESPONSE_AVAILABLE               0x01
#define USB_CDC_NOTIFY_AUX_JACK_HOOK_STATE              0x08
#define USB_CDC_NOTIFY_RING_DETECT                      0x09
#define USB_CDC_NOTIFY_SERIAL_STATE                     0x20
#define USB_CDC_NOTIFY_CALL_STATE_CHANGE                0x28
#define USB_CDC_NOTIFY_LINE_STATE_CHANGE                0x29
#define USB_CDC_NOTIFY_CONNECTION_SPEED_CHANGE          0x2A

//*****************************************************************************
//
// USB_CDC_NOTIFY_NETWORK_CONNECTION, wValue
//
//*****************************************************************************
#define USB_CDC_NETWORK_DISCONNECTED                    0x0000
#define USB_CDC_NETWORK_CONNECTED                       0x0001

//*****************************************************************************
//
// USB_CDC_NOTIFY_AUX_JACK_HOOK_STATE, wValue
//
//*****************************************************************************
#define USB_CDC_AUX_JACK_ON_HOOK                        0x0000
#define USB_CDC_AUX_JACK_OFF_HOOK                       0x0001

//*****************************************************************************
//
// USB_CDC_NOTIFY_SERIAL_STATE, Data
//
//*****************************************************************************

//*****************************************************************************
//
// Number of bytes of data returned alongside this notification.
//
//*****************************************************************************
#define USB_CDC_NOTIFY_SERIAL_STATE_SIZE                2

#define USB_CDC_SERIAL_STATE_OVERRUN                    0x0040
#define USB_CDC_SERIAL_STATE_PARITY                     0x0020
#define USB_CDC_SERIAL_STATE_FRAMING                    0x0010
#define USB_CDC_SERIAL_STATE_RING_SIGNAL                0x0008
#define USB_CDC_SERIAL_STATE_BREAK                      0x0004
#define USB_CDC_SERIAL_STATE_TXCARRIER                  0x0002
#define USB_CDC_SERIAL_STATE_RXCARRIER                  0x0001

//*****************************************************************************
//
// USB_CDC_NOTIFY_CALL_STATE_CHANGE, wValue
//
// Call state values are defined above in the group beginning
// USB_CDC_CALL_STATE_IDLE.  Note that the data returned alongside this
// notification are heavily dependent upon the call state being reported so no
// specific lengths or access macros are provided here.
//
// Macro to construct the correct wValue for this notification given a state
// and call index.
//
//*****************************************************************************
#define SetNotifyCallStatewValue(psResult, ucCallState, ucIndex) \
        do                                                       \
        {                                                        \
            (WORD(psResult)) = (((ucCallState) & 0xFF) +         \
                                (((ucIndex) & 0xFF) << 8));      \
        }                                                        \
        while(0)

//*****************************************************************************
//
// USB_CDC_NOTIFY_LINE_STATE_CHANGE, wValue
//
// Note that the data returned alongside this notification are heavily
// dependent upon the call state being reported so no specific lengths or
// access macros are provided here.
//
//*****************************************************************************
#define USB_CDC_LINE_STATE_IDLE                         0x0000
#define USB_CDC_LINE_STATE_HOLD                         0x0001
#define USB_CDC_LINE_STATE_OFF_HOOK                     0x0002
#define USB_CDC_LINE_STATE_ON_HOOK                      0x0003

//*****************************************************************************
//
// USB_CDC_NOTIFY_CONNECTION_SPEED_CHANGE, Data
//
// Macro to populate the 8 byte data structure returned alongside this
// notification.
//
//*****************************************************************************
#define SetNotifyConnectionSpeedChange(pcBuf, ulUSBitRate, ulDSBitRate) \
        do                                                              \
        {                                                               \
            LONG(pcBuf) = ulUSBitRate;                                  \
            LONG((unsigned char *)(pcBuf) + 4) = ulDSBitRate;           \
        }                                                               \
        while(0)

//*****************************************************************************
//
// Packed structure definitions for request/response data blocks
//
//*****************************************************************************

//*****************************************************************************
//
// All structures defined in this section of the header require byte packing of
// fields.  This is usually accomplished using the PACKED macro but, for IAR
// Embedded Workbench, this requires a pragma.
//
//*****************************************************************************
#ifdef ewarm
#pragma pack(1)
#endif

//*****************************************************************************
//
//! USB_CDC_GET/SET_LINE_CODING request-specific data.
//
//*****************************************************************************
typedef struct
{
    //
    //! The data terminal rate in bits per second.
    //
    unsigned long ulRate;

    //
    //! The number of stop bits.  Valid values are USB_CDC_STOP_BITS_1,
    //! USB_CDC_STOP_BITS_1_5 or USB_CDC_STOP_BITS_2
    //
    unsigned char ucStop;

    //
    //! The parity setting.  Valid values are USB_CDC_PARITY_NONE,
    //! USB_CDC_PARITY_ODD, USB_CDC_PARITY_EVEN, USB_CDC_PARITY_MARK and
    //! USB_CDC_PARITY_SPACE.
    //
    unsigned char ucParity;

    //
    //! The number of data bits per character.  Valid values are 5, 6, 7 and 8
    //! in this implementation.
    //
    unsigned char ucDatabits;
}
PACKED tLineCoding;

//*****************************************************************************
//
// Return to default packing when using the IAR Embedded Workbench compiler.
//
//*****************************************************************************
#ifdef ewarm
#pragma pack()
#endif

//*****************************************************************************
//
// Close the Doxygen group.
//! @}
//
//*****************************************************************************

//*****************************************************************************
//
// Mark the end of the C bindings section for C++ compilers.
//
//*****************************************************************************
#ifdef __cplusplus
}
#endif

#endif // __USBCDC_H__