• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2021 Huawei Device Co., Ltd.
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at
6  *
7  *     http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  */
15 
16 #ifndef USB_CDCACM_TEST_H
17 #define USB_CDCACM_TEST_H
18 
19 #include <stdio.h>
20 #include <unistd.h>
21 #include <stdlib.h>
22 #include <string.h>
23 #include "usbfn_device.h"
24 #include "usbfn_request.h"
25 #include "usbfn_interface.h"
26 #include "osal_atomic.h"
27 #include "osal_mutex.h"
28 #include "osal_time.h"
29 
30 #define DEV_MASTER_SERVICE_NAME "usbfn_master"
31 #define TEST_TIMES  10
32 #define BUFFER_LEN 64
33 #define WAIT_10MS 10
34 #define SYNC_5000MS 500
35 #define CDC_ACM
36 #define QUEUE_SIZE              8
37 #define PORT_RATE       9600
38 #define CHAR_FORMAT     8
39 
40 #define SS_MAX_PACKET_SIZE 1024
41 #define MAX_PACKET_SIZE 512
42 #define EP_ADD_NOTIFY   1
43 #define EP_ADD_DATA_IN  2
44 #define EP_ADD_DATA_OUT 3
45 #define DATA_EP_NUM     2
46 #define NOTIFY_EP_NUM   1
47 #define INTF_COUNT      2
48 
49 #define ACM_NOTIFY_INTERVAL     32 /* ms */
50 #define ACM_HS_NOTIFY_INTERVAL  9  /* ms */
51 #define ACM_NOTIFY_MAXPACKET    10 /* notification + 2 bytes */
52 
53 #define ACM_CTRL_IDX            1
54 #define ACM_DATA_IDX            2
55 #define ACM_IAD_IDX             3
56 
57 
58 struct Serial {
59     struct AcmDevice         *acm;
60     struct UsbCdcLineCoding     lineCoding;
61     struct OsalMutex            lock;
62     struct DListHead            readPool;
63     struct DListHead            readQueue;
64     int32_t                     readStarted;
65     int32_t                     readAllocated;
66     struct DListHead            writePool;
67     int32_t                     writeStarted;
68     int32_t                     writeAllocated;
69     bool                        writeBusy;
70 
71     bool                        suspended;
72     bool                        startDelayed;
73     int                         refCount;
74 };
75 
76 struct AcmNotifyMethod {
77     void (*Connect)(struct AcmDevice *acm);
78     void (*Disconnect)(struct AcmDevice *acm);
79     int (*SendBreak)(struct AcmDevice *acm, int duration);
80 };
81 
82 struct AcmPipe {
83     uint8_t                     id;
84     uint16_t                    maxPacketSize;
85     struct UsbFnInterface       *ctrlIface;
86 };
87 
88 struct AcmInterface {
89     struct UsbFnInterface       *fn;
90     UsbFnInterfaceHandle                   handle;
91 };
92 
93 struct AcmDevice {
94     struct UsbFnDevice          *fnDev;
95     struct AcmInterface      ctrlIface;
96     struct AcmInterface      dataIface;
97     struct AcmPipe           notifyPipe;
98     struct AcmPipe           dataInPipe;
99     struct AcmPipe           dataOutPipe;
100     struct DListHead            ctrlPool;
101     int32_t                     ctrlReqNum;
102     struct UsbFnRequest         *notifyReq;
103     struct OsalMutex            lock;
104     bool                        pending;
105     uint32_t                    enableEvtCnt;
106     char                        *udcName;
107     char                        submit;
108     char                        submitExit;
109     struct Serial               *port;
110     struct UsbCdcLineCoding     lineCoding;
111     uint16_t                    serialState;
112 #define SERIAL_STATE_DCD        (1 << 0)
113 #define SERIAL_STATE_DSR        (1 << 1)
114 #define SERIAL_STATE_BREAK      (1 << 2)
115 #define SERIAL_STATE_RING       (1 << 3)
116 #define SERIAL_STATE_FRAMING    (1 << 4)
117 #define SERIAL_STATE_PARITY     (1 << 5)
118 #define SERIAL_STATE_OVERRUN    (1 << 6)
119 
120     uint16_t                    handshakeBits;
121     /* notification callbacks */
122     struct AcmNotifyMethod      *notify;
123 };
124 
125 struct CtrlInfo {
126     uint8_t      request;
127     struct AcmDevice         *acm;
128 };
129 
130 extern struct UsbFnDeviceDesc g_acmFnDevice;
131 struct AcmDevice * SetUpAcmDevice(void);
132 void ReleaseAcmDevice(struct AcmDevice *acm);
133 void AcmEventCallback(struct UsbFnEvent *event);
134 void AcmDeviceRelease(struct AcmDevice *acmDevice);
135 int XtsRemoveDevice(void);
136 
137 #endif
138