1 /******************************************************************************
2  *
3  *  Copyright (C) 2001-2012 Broadcom Corporation
4  *
5  *  Licensed under the Apache License, Version 2.0 (the "License");
6  *  you may not use this file except in compliance with the License.
7  *  You may obtain a copy of the License at:
8  *
9  *  http://www.apache.org/licenses/LICENSE-2.0
10  *
11  *  Unless required by applicable law or agreed to in writing, software
12  *  distributed under the License is distributed on an "AS IS" BASIS,
13  *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  *  See the License for the specific language governing permissions and
15  *  limitations under the License.
16  *
17  ******************************************************************************/
18 
19 /******************************************************************************
20  *
21  *  This file contains serial definitions from WIDCOMM's Universal Embedded
22  *  Drivers API.
23  *
24  ******************************************************************************/
25 
26 #ifndef USERIAL_H
27 #define USERIAL_H
28 
29 /*******************************************************************************
30 ** Serial APIs
31 *******************************************************************************/
32 
33 /**** port IDs ****/
34 #define USERIAL_PORT_1 0
35 #define USERIAL_PORT_2 1
36 #define USERIAL_PORT_3 2
37 #define USERIAL_PORT_4 3
38 #define USERIAL_PORT_5 4
39 #define USERIAL_PORT_6 5
40 #define USERIAL_PORT_7 6
41 #define USERIAL_PORT_8 7
42 #define USERIAL_PORT_9 8
43 #define USERIAL_PORT_10 9
44 #define USERIAL_PORT_11 10
45 #define USERIAL_PORT_12 11
46 #define USERIAL_PORT_13 12
47 #define USERIAL_PORT_14 13
48 #define USERIAL_PORT_15 14
49 #define USERIAL_PORT_16 15
50 #define USERIAL_PORT_17 16
51 #define USERIAL_PORT_18 17
52 
53 typedef uint8_t tUSERIAL_PORT;
54 
55 /**** baud rates ****/
56 #define USERIAL_BAUD_300 0
57 #define USERIAL_BAUD_600 1
58 #define USERIAL_BAUD_1200 2
59 #define USERIAL_BAUD_2400 3
60 #define USERIAL_BAUD_9600 4
61 #define USERIAL_BAUD_19200 5
62 #define USERIAL_BAUD_57600 6
63 #define USERIAL_BAUD_115200 7
64 #define USERIAL_BAUD_230400 8
65 #define USERIAL_BAUD_460800 9
66 #define USERIAL_BAUD_921600 10
67 #define USERIAL_BAUD_1M 11
68 #define USERIAL_BAUD_1_5M 12
69 #define USERIAL_BAUD_2M 13
70 #define USERIAL_BAUD_3M 14
71 #define USERIAL_BAUD_4M 15
72 #define USERIAL_BAUD_AUTO 16
73 
74 /**** Data Format ****/
75 
76 /* Stop Bits */
77 #define USERIAL_STOPBITS_1 1
78 #define USERIAL_STOPBITS_1_5 (1 << 1)
79 #define USERIAL_STOPBITS_2 (1 << 2)
80 
81 /* Parity Bits */
82 #define USERIAL_PARITY_NONE (1 << 3)
83 #define USERIAL_PARITY_EVEN (1 << 4)
84 #define USERIAL_PARITY_ODD (1 << 5)
85 
86 /* Data Bits */
87 #define USERIAL_DATABITS_5 (1 << 6)
88 #define USERIAL_DATABITS_6 (1 << 7)
89 #define USERIAL_DATABITS_7 (1 << 8)
90 #define USERIAL_DATABITS_8 (1 << 9)
91 
92 /**** Flow Control ****/
93 #define USERIAL_FC_NONE 0
94 #define USERIAL_FC_HW 1
95 #define USERIAL_FC_SW 2
96 
97 /**** Data Buffering Mechanism ****/
98 #define USERIAL_BUF_BYTE 0
99 #define USERIAL_BUF_GKI 1
100 
101 /**** Signals ****/
102 #define USERIAL_SIG_RTSCTS 1
103 #define USERIAL_SIG_DSRDTR (1 << 1)
104 #define USERIAL_SIG_RI (1 << 2)
105 #define USERIAL_SIG_CD (1 << 3)
106 #define USERIAL_SIG_DTE_DEVICE (1 << 4)
107 
108 /**** Errors *****/
109 #define USERIAL_ERR_OVERRUN 1
110 #define USERIAL_ERR_PARITY (1 << 1)
111 #define USERIAL_ERR_FRAMING (1 << 2)
112 #define USERIAL_ERR_BREAK (1 << 3)
113 
114 /**** Serial Operations ****/
115 #define USERIAL_OP_FLUSH 0
116 #define USERIAL_OP_FLUSH_RX 1
117 #define USERIAL_OP_FLUSH_TX 2
118 #define USERIAL_OP_BREAK_OFF 3
119 #define USERIAL_OP_BREAK_ON 4
120 #define USERIAL_OP_BAUD_RD 5
121 #define USERIAL_OP_BAUD_WR 6
122 #define USERIAL_OP_FMT_RD 7
123 #define USERIAL_OP_FMT_WR 8
124 #define USERIAL_OP_SIG_RD 9
125 #define USERIAL_OP_SIG_WR 10
126 #define USERIAL_OP_FC_RD 11
127 #define USERIAL_OP_FC_WR 12
128 #define USERIAL_OP_CTS_AS_WAKEUP 13 /* H4IBSS */
129 #define USERIAL_OP_CTS_AS_FC 14     /* H4IBSS */
130 
131 #if (defined(LINUX_OS) && LINUX_OS == TRUE)
132 #define USERIAL_OP_SCO_UP 20   /* LINUX SCO */
133 #define USERIAL_OP_SCO_DOWN 21 /* LINUX SCO */
134 #endif
135 
136 typedef uint8_t tUSERIAL_OP;
137 
138 /**** Serial feature types ****/
139 #define USERIAL_FEAT_PORT_1 0
140 #define USERIAL_FEAT_PORT_2 1
141 #define USERIAL_FEAT_PORT_3 2
142 #define USERIAL_FEAT_PORT_4 3
143 #define USERIAL_FEAT_BAUD_AUTO 4
144 #define USERIAL_FEAT_BAUD_300 5
145 #define USERIAL_FEAT_BAUD_600 6
146 #define USERIAL_FEAT_BAUD_1200 7
147 #define USERIAL_FEAT_BAUD_2400 8
148 #define USERIAL_FEAT_BAUD_9600 9
149 #define USERIAL_FEAT_BAUD_19200 10
150 #define USERIAL_FEAT_BAUD_57600 11
151 #define USERIAL_FEAT_BAUD_115200 12
152 #define USERIAL_FEAT_BAUD_230400 13
153 #define USERIAL_FEAT_BAUD_460800 14
154 #define USERIAL_FEAT_BAUD_921600 15
155 #define USERIAL_FEAT_STOPBITS_1 16
156 #define USERIAL_FEAT_STOPBITS_1_5 17
157 #define USERIAL_FEAT_STOPBITS_2 18
158 #define USERIAL_FEAT_PARITY_NONE 19
159 #define USERIAL_FEAT_PARITY_EVEN 20
160 #define USERIAL_FEAT_PARITY_ODD 21
161 #define USERIAL_FEAT_DATABITS_5 22
162 #define USERIAL_FEAT_DATABITS_6 23
163 #define USERIAL_FEAT_DATABITS_7 24
164 #define USERIAL_FEAT_DATABITS_8 25
165 #define USERIAL_FEAT_FC_NONE 26
166 #define USERIAL_FEAT_FC_HW 27
167 #define USERIAL_FEAT_FC_SW 28
168 #define USERIAL_FEAT_BUF_BYTE 29
169 #define USERIAL_FEAT_BUF_GKI 30
170 #define USERIAL_FEAT_SIG_RTS 31
171 #define USERIAL_FEAT_SIG_CTS 32
172 #define USERIAL_FEAT_SIG_DSR 33
173 #define USERIAL_FEAT_SIG_DTR 34
174 #define USERIAL_FEAT_SIG_RI 35
175 #define USERIAL_FEAT_SIG_CD 36
176 #define USERIAL_FEAT_OP_FLUSH 37
177 #define USERIAL_FEAT_OP_FLUSH_RX 38
178 #define USERIAL_FEAT_OP_FLUSH_TX 39
179 #define USERIAL_FEAT_OP_BREAK 40
180 #define USERIAL_FEAT_OP_BAUD_RD 41
181 #define USERIAL_FEAT_OP_BAUD_WR 42
182 #define USERIAL_FEAT_OP_FMT_RD 43
183 #define USERIAL_FEAT_OP_FMT_WR 44
184 #define USERIAL_FEAT_OP_SIG_RD 45
185 #define USERIAL_FEAT_OP_SIG_WR 46
186 #define USERIAL_FEAT_OP_FC_RD 47
187 #define USERIAL_FEAT_OP_FC_WR 48
188 
189 typedef uint8_t tUSERIAL_FEATURE;
190 
191 /**** Event types ****/
192 #define USERIAL_RX_READY_EVT 0
193 #define USERIAL_TX_DONE_EVT 1
194 #define USERIAL_SIG_EVT 2
195 #define USERIAL_ERR_EVT 3
196 #define USERIAL_WAKEUP_EVT 4 /* H4IBSS */
197 
198 typedef uint8_t tUSERIAL_EVT;
199 
200 /* Structure used to configure serial port during open        */
201 typedef struct {
202   uint16_t fmt;    /* Data format                       */
203   uint8_t baud;    /* Baud rate                         */
204   uint8_t fc;      /* Flow control                      */
205   uint8_t buf;     /* Data buffering mechanism          */
206   uint8_t pool;    /* GKI buffer pool for received data */
207   uint16_t size;   /* Size of GKI buffer pool           */
208   uint16_t offset; /* Offset in GKI buffer pool         */
209 } tUSERIAL_OPEN_CFG;
210 
211 /* Union used to pass ioctl arguments */
212 typedef union {
213   uint16_t fmt;
214   uint8_t baud;
215   uint8_t fc;
216   uint8_t sigs;
217 #if (defined(LINUX_OS) && LINUX_OS == TRUE)
218   uint16_t sco_handle;
219 #endif
220 } tUSERIAL_IOCTL_DATA;
221 
222 /* Union to pass event data */
223 typedef union {
224   uint8_t sigs;
225   uint8_t error;
226 } tUSERIAL_EVT_DATA;
227 
228 /* callback for events */
229 typedef void(tUSERIAL_CBACK)(tUSERIAL_PORT, tUSERIAL_EVT, tUSERIAL_EVT_DATA*);
230 
231 /*******************************************************************************
232 ** Function Prototypes
233 *******************************************************************************/
234 
235 #ifdef __cplusplus
236 extern "C" {
237 #endif
238 
239 extern void USERIAL_Init(void*);
240 extern void USERIAL_Open(tUSERIAL_PORT, tUSERIAL_OPEN_CFG*, tUSERIAL_CBACK*);
241 extern void USERIAL_ReadBuf(tUSERIAL_PORT, NFC_HDR**);
242 extern uint16_t USERIAL_Read(tUSERIAL_PORT, uint8_t*, uint16_t);
243 extern bool USERIAL_WriteBuf(tUSERIAL_PORT, NFC_HDR*);
244 extern uint16_t USERIAL_Write(tUSERIAL_PORT, uint8_t*, uint16_t);
245 extern void USERIAL_Ioctl(tUSERIAL_PORT, tUSERIAL_OP, tUSERIAL_IOCTL_DATA*);
246 extern void USERIAL_Close(tUSERIAL_PORT);
247 extern bool USERIAL_Feature(tUSERIAL_FEATURE);
248 extern bool USERIAL_IsClosed();
249 extern void USERIAL_SetPowerOffDelays(int, int);
250 extern void USERIAL_PowerupDevice(tUSERIAL_PORT port);
251 
252 /*******************************************************************************
253  **
254  ** Function           USERIAL_GetLineSpeed
255  **
256  ** Description        This function convert USERIAL baud to line speed.
257  **
258  ** Output Parameter   None
259  **
260  ** Returns            line speed
261  **
262  *******************************************************************************/
263 extern uint32_t USERIAL_GetLineSpeed(uint8_t baud);
264 /*******************************************************************************
265  **
266  ** Function           USERIAL_GetBaud
267  **
268  ** Description        This function convert line speed to USERIAL baud.
269  **
270  ** Output Parameter   None
271  **
272  ** Returns            line speed
273  **
274  *******************************************************************************/
275 extern uint8_t USERIAL_GetBaud(uint32_t line_speed);
276 
277 #ifdef __cplusplus
278 }
279 #endif
280 
281 #endif /* USERIAL_H */
282