blob: a1784deab0278083c8b06f19032e5d93817c6f4c [file] [log] [blame]
yu.dongc33b3072024-08-21 23:14:49 -07001/*****************************************************************************
2* Copyright Statement:
3* --------------------
4* This software is protected by Copyright and the information contained
5* herein is confidential. The software may not be copied and the information
6* contained herein may not be used or disclosed except with the written
7* permission of MediaTek Inc. (C) 2005
8*
9* BY OPENING THIS FILE, BUYER HEREBY UNEQUIVOCALLY ACKNOWLEDGES AND AGREES
10* THAT THE SOFTWARE/FIRMWARE AND ITS DOCUMENTATIONS ("MEDIATEK SOFTWARE")
11* RECEIVED FROM MEDIATEK AND/OR ITS REPRESENTATIVES ARE PROVIDED TO BUYER ON
12* AN "AS-IS" BASIS ONLY. MEDIATEK EXPRESSLY DISCLAIMS ANY AND ALL WARRANTIES,
13* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED WARRANTIES OF
14* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE OR NONINFRINGEMENT.
15* NEITHER DOES MEDIATEK PROVIDE ANY WARRANTY WHATSOEVER WITH RESPECT TO THE
16* SOFTWARE OF ANY THIRD PARTY WHICH MAY BE USED BY, INCORPORATED IN, OR
17* SUPPLIED WITH THE MEDIATEK SOFTWARE, AND BUYER AGREES TO LOOK ONLY TO SUCH
18* THIRD PARTY FOR ANY WARRANTY CLAIM RELATING THERETO. MEDIATEK SHALL ALSO
19* NOT BE RESPONSIBLE FOR ANY MEDIATEK SOFTWARE RELEASES MADE TO BUYER'S
20* SPECIFICATION OR TO CONFORM TO A PARTICULAR STANDARD OR OPEN FORUM.
21*
22* BUYER'S SOLE AND EXCLUSIVE REMEDY AND MEDIATEK'S ENTIRE AND CUMULATIVE
23* LIABILITY WITH RESPECT TO THE MEDIATEK SOFTWARE RELEASED HEREUNDER WILL BE,
24* AT MEDIATEK'S OPTION, TO REVISE OR REPLACE THE MEDIATEK SOFTWARE AT ISSUE,
25* OR REFUND ANY SOFTWARE LICENSE FEES OR SERVICE CHARGE PAID BY BUYER TO
26* MEDIATEK FOR SUCH MEDIATEK SOFTWARE AT ISSUE.
27*
28* THE TRANSACTION CONTEMPLATED HEREUNDER SHALL BE CONSTRUED IN ACCORDANCE
29* WITH THE LAWS OF THE STATE OF CALIFORNIA, USA, EXCLUDING ITS CONFLICT OF
30* LAWS PRINCIPLES. ANY DISPUTES, CONTROVERSIES OR CLAIMS ARISING THEREOF AND
31* RELATED THERETO SHALL BE SETTLED BY ARBITRATION IN SAN FRANCISCO, CA, UNDER
32* THE RULES OF THE INTERNATIONAL CHAMBER OF COMMERCE (ICC).
33*
34*****************************************************************************/
35
36
37#ifdef DCL_DEFINITION_STRUCT
38#ifndef __DCL_MTAD_STRUCT__
39#define __DCL_MTAD_STRUCT__
40
41//#include "dcl.h"
42
43#if 0
44/* under construction !*/
45/* under construction !*/
46/* under construction !*/
47/* under construction !*/
48/* under construction !*/
49/* under construction !*/
50/* under construction !*/
51/* under construction !*/
52/* under construction !*/
53/* under construction !*/
54/* under construction !*/
55/* under construction !*/
56/* under construction !*/
57/* under construction !*/
58/* under construction !*/
59/* under construction !*/
60/* under construction !*/
61/* under construction !*/
62/* under construction !*/
63/* under construction !*/
64/* under construction !*/
65/* under construction !*/
66/* under construction !*/
67/* under construction !*/
68#endif
69
70
71#define FAKE_MTU_SIZE (2048)
72
73//UART_CMD_OPEN
74typedef struct
75{
76 DCL_UINT32 u4OwenrId;
77}MTAD_CTRL_OPEN_T;
78
79//UART_CMD_CLOSE
80typedef struct
81{
82 DCL_UINT32 u4OwenrId;
83}MTAD_CTRL_CLOSE_T;
84
85typedef struct
86{
87 DCL_UINT32 u4OwenrId;
88} MTAD_CTRL_CLR_BUFFER_T;
89
90//UART_CMD_PUT_ISR_BYTES
91typedef struct
92{
93 DCL_UINT16 u2Length;
94 DCL_UINT32 u4OwenrId;
95 DCL_UINT16 u2RetSize;
96 DCL_UINT8* puBuffaddr;
97}MTAD_CTRL_PUT_BYTES_T;
98
99typedef struct
100{
101 DCL_UINT32 u4OwnerId;
102 void *putIor;
103}MTAD_CTRL_PUT_BYTES_IOR_T;
104
105
106//TTY_CMD_GET_CHUNK_SIZE
107typedef struct
108{
109 DCL_UINT32 chunkSize;
110} MTAD_CTRL_GET_CHUNK_SIZE_T;
111
112//TTY_CMD_NEED_TX_DONE_CB
113typedef struct
114{
115 DCL_UINT32 u4OwnerId;
116 DCL_BOOL needTxDoneCb;
117} MTAD_CTRL_NEED_TX_DONE_CB_T;
118
119//TTY_CMD_GET_MTU_SIZE
120typedef struct
121{
122 DCL_UINT32 ulmtu_sz;
123 DCL_UINT32 dlmtu_sz;
124} MTAD_CTRL_GET_MTU_SIZE_T;
125
126/*!
127 * @brief TTY driver state
128 */
129typedef enum _tty_drv_mtad_state {
130 /*!
131 * @brief driver detached state
132 */
133 DRV_MTAD_ST_DETACHED = 0,
134 /*!
135 * @brief driver attached state
136 */
137 DRV_MTAD_ST_ATTACHED
138} tty_drv_mtad_state_e;
139
140//TTY_CMD_GET_DRV_STATE
141typedef struct
142{
143 DCL_UINT32 u4OwnerId;
144 tty_drv_mtad_state_e drv_state;
145} MTAD_CTRL_GET_DRV_STATE_T;
146
147
148//TTY_CMD_ASSIGN_RX_IOR
149typedef struct
150{
151 DCL_UINT32 u4OwnerId;
152 void *ior;
153} MTAD_CTRL_ASSIGN_RX_IOR_T;
154
155
156
157
158#define MTAD_CTRLS \
159 MTAD_CTRL_OPEN_T rMTADCtrlOPEN;\
160 MTAD_CTRL_CLOSE_T rMTADCtrlCLOSE;\
161 MTAD_CTRL_CLR_BUFFER_T rMTADCtrlCLRBUFFER;\
162 MTAD_CTRL_PUT_BYTES_T rMTADCtrlPUTBYTES;\
163 MTAD_CTRL_GET_MTU_SIZE_T rMTADCtrlGETMTUSIZE;\
164 MTAD_CTRL_GET_CHUNK_SIZE_T rMTADCtrlGETCHUNKSIZE;\
165 MTAD_CTRL_ASSIGN_RX_IOR_T rMTADCtrlAssignRxIor;\
166 MTAD_CTRL_NEED_TX_DONE_CB_T rMTADCtrlNeedTxDoneCb;\
167 MTAD_CTRL_GET_DRV_STATE_T rMTADCtrlGetDrvState;\
168 MTAD_CTRL_PUT_BYTES_IOR_T rMTADCtrlPUTBYTESIOR;\
169
170
171
172typedef enum
173{
174 DCL_MTAD_TYPE = 0x00,
175
176}MTAD_SIO_TYPE_T;
177
178
179#endif // DCL_DEFINITION_STRUCT
180#endif // __DCL_MTAD_STRUCT__
181
182
183#ifdef DCL_DEFINITION_PROTOTYPE
184
185typedef DCL_STATUS(*mtad_handler_cb)(DCL_DEV dev, DCL_CTRL_CMD cmd, DCL_CTRL_DATA_T *data);
186
187typedef struct
188{
189 MTAD_SIO_TYPE_T DevType;
190 mtad_handler_cb mtadHandlerCb;
191}MTAD_HANDLER_T;
192
193
194/*!
195* @function DclSerialPort_Open
196* @brief This function is to open the UART module and get a handle.
197* @param dev Port number. it can take DCL_UART_DEV as reference
198* @param flags module_type | FLAGS_UART_USE_VFIFO
199* module_type: KAL module type enum value
200* FLAGS_UART_USE_VFIFO: flags that specifies to use Virtual FIFO or not for UART device. Note that it's only valide for eDev with DCL_UART1, DCL_UART2, DCL_UART3(if exists)
201* [Note] Currently TTY doesn't handle flags!! This parameter is kept for backward compatible.
202* @result STATUS_FAIL Open failed.
203* @result STATUS_ALREADY_OPENED This device has already been opened.
204* @result STATUS_INVALID_DEVICE The device is not valid.
205* @result STATUS_SET_VFIFO_FAIL Fail to use Vitual FIFO for the UART port.
206* @result other value a valid handle
207*
208*/
209extern DCL_HANDLE DclSerialPort_Open(DCL_DEV dev, DCL_FLAGS flags);
210
211 /*!
212 * @function DclSerialPort_Control
213 * @brief This function is support UART module commands. It is called to send command to control the UART module.
214 * @param handle a valid handle return by DclSerialPort_Open()
215 * @param cmd dcl uart commands
216 * @param data pointer to the corresponding data structure of command
217 * @result STATUS_OK command is executed successfully.
218 * @result STATUS_INVALID_CMD It's a invalid command.
219 * @result STATUS_INVALID_HANDLE It's a invalid handle.
220 */
221 extern DCL_STATUS DclSerialPort_Control(DCL_HANDLE handle, DCL_CTRL_CMD cmd, DCL_CTRL_DATA_T *data);
222
223
224/* ----------------------------------- Export to upper layer --------------------------------------- */
225
226/*!
227* @function [New TTY API] DclSerialPort_UpModuleInit
228* @brief This function is to initialize/start designated COM Port for upper module.
229* @param handle a valid handle return by DclSerialPort_Open()
230* @param module_id upper module id
231* @param flag TTY COM Port attribute. Currently they are TTY_FLAG_NEW_TX or TTY_FLAG_NEW_RX.
232* Upper module can initialize flag with new Tx/Rx flow (gpd based) or conventional Tx/Rx (buffer/length based) flow.
233* ex. New Tx and Conventional Rx - DclSerialPort_UpModuleReinit(handle, module_id, TTY_FLAG_NEW_TX);
234* @result STATUS_OK Init COM Port device successfully.
235* @result STATUS_INVALID_HANDLE It's a invalid handle.
236* @result STATUS_ALREADY_OPENED The COM Port has been initialized by other module.
237* @result STATUS_DEVICE_NOT_EXIST The corresponding device driver of COM Port has not been initialized.
238*/
239extern DCL_STATUS DclSerialPort_UpModuleInit(DCL_HANDLE handle, module_type module_id, int flag);
240
241/*!
242* @function [New TTY API] DclSerialPort_UpModuleDeinit
243* @brief This function is to de-init/de-register COM Port.
244* @param handle a valid handle return by DclSerialPort_Open()
245* @result STATUS_OK Deinit COM Port device successfully.
246* @result STATUS_INVALID_HANDLE It's a invalid handle.
247* @result STATUS_NOT_OPENED The COM Port has not been initialized.
248* @result STATUS_DEVICE_NOT_EXIST The corresponding device driver of COM Port has not been initialized.
249*/
250extern DCL_STATUS DclSerialPort_UpModuleDeinit(DCL_HANDLE handle);
251
252
253
254/*!
255* @function [New TTY API] DclSerialPort_UpModuleRegisterCb
256* @brief This function is for upper layer module to register callback function.
257* @param handle a valid handle return by DclSerialPort_Open()
258* @param rx_cb rx callback function, driver send receiving data to upper layer through this rx callback function
259* @param tx_done_cb tx done callback function, this callback function will be called when data has been sent
260* @param drv_state_change_cb driver state change callback function, it notify the upper layer module when driver state is changed, ex. USB disconnect
261* @result STATUS_OK Register callback function successfully.
262* @result STATUS_INVALID_HANDLE It's a invalid handle.
263* @result STATUS_NOT_OPENED The COM Port has not been initialized.
264* @result STATUS_DEVICE_NOT_EXIST The corresponding device driver of COM Port has not been initialized.
265* @result STATUS_FAIL Failed for other reasons.
266*/
267extern DCL_STATUS DclSerialPort_UpModuleRegisterCb(DCL_HANDLE handle, tty_rx_cb rx_cb, tty_txdone_cb tx_done_cb, tty_drv_state_change_cb drv_state_change_cb);
268
269
270/*!
271* @function [New TTY API] DclSerialPort_UpModuleTransmit
272* @brief This function is to transmit data to COM Port in ior format.
273* @param handle a valid handle return by DclSerialPort_Open()
274* @param ior pointer to tx io request which is sent to COM Port driver
275* @result STATUS_OK Transmit ior successfully.
276* @result STATUS_INVALID_HANDLE It's a invalid handle.
277* @result STATUS_FAIL Failed for other reasons.
278*/
279extern DCL_STATUS DclSerialPort_UpModuleTransmit(DCL_HANDLE handle, tty_io_request_t *ior);
280
281
282/*!
283* @function [New TTY API] DclSerialPort_UpModuleTransmitLight
284* @brief This function is to transmit data to COM Port in ior format and light-weight.
285* Before user use this Tx function, it must calculate tx checksum and flush GPD in advance.
286* @param handle a valid handle return by DclSerialPort_Open()
287* @param ior pointer to tx io request which is sent to COM Port driver
288* @result STATUS_OK Transmit ior successfully.
289* @result STATUS_INVALID_HANDLE It's a invalid handle.
290* @result STATUS_FAIL Failed for other reasons.
291*/
292extern DCL_STATUS DclSerialPort_UpModuleTransmitLight(DCL_HANDLE handle, tty_io_request_t *ior);
293
294/*!
295* @function [New TTY API] DclSerialPort_UpModuleAssignRxIor
296* @brief This function is to assign empty Rx ior to driver for data receiving.
297* @param handle a valid handle return by DclSerialPort_Open()
298* @param rx_ior pointer to rx io request for data receiving
299* @result STATUS_OK Assign Rx ior successfully.
300* @result STATUS_INVALID_HANDLE It's a invalid handle.
301* @result STATUS_FAIL Failed for other reasons.
302*/
303extern DCL_STATUS DclSerialPort_UpModuleAssignRxIor(DCL_HANDLE handle, tty_io_request_t *rx_ior);
304
305
306/* ------------------------------------ Export to driver ------------------------------------------- */
307/*!
308* @function DclSerialPort_DrvRegisterCb
309* @brief This function is to register callback funtion for the UART module or COM Port class driver.
310* @param handle a valid handle return by DclSerialPort_Open()
311* @param seriport_handler the structure contains callback function and device type.
312 TTY would send commands (SIO/UART/USB/TTY/...) to driver through this callback function when the corresponding event happens.
313* @result STATUS_OK successful.
314* @result STATUS_INVALID_HANDLE It's a invalid handle.
315* @result STATUS_ALREADY_OPENED This device has already been opened.
316* @result STATUS_INVALID_ARGUMENT The parameter is invalid, ex. uart_handler_cb is NULL.
317*/
318extern DCL_STATUS DclSerialPort_DrvRegisterCb(DCL_HANDLE handle, Seriport_HANDLER_T* seriport_handler);
319
320/*!
321* @function DclSerialPort_DrvDeRegisterCb
322* @brief This function is to De-register callback funtion for the UART module or COM Port class driver.
323* @param handle a valid handle return by DclSerialPort_Open()
324*
325* @result STATUS_OK successful.
326* @result STATUS_INVALID_HANDLE It's a invalid handle.
327* @result STATUS_INVALID_OPERATION This device has already been de-registered or driver state is attached.
328*/
329extern DCL_STATUS DclSerialPort_DrvDeRegisterCb(DCL_HANDLE handle);
330
331/*!
332* @function [New TTY API] DclSerialPort_DrvAttach
333* @brief This function is for driver to inform TTY that the device is attached/connected.
334* @param handle a valid handle return by DclSerialPort_Open()
335* @result STATUS_OK successful.
336* @result STATUS_INVALID_HANDLE It's a invalid handle.
337* @result STATUS_DEVICE_NOT_EXIST The corresponding device driver of COM Port has not been initialized.
338*/
339extern DCL_STATUS DclSerialPort_DrvAttach(DCL_HANDLE handle);
340
341/*!
342* @function [New TTY API] DclSerialPort_DrvDetach
343* @brief This function is for driver to inform TTY that the device is detached/disconnected.
344* @param handle a valid handle return by DclSerialPort_Open()
345* @result STATUS_OK successful.
346* @result STATUS_INVALID_HANDLE It's a invalid handle.
347* @result STATUS_DEVICE_NOT_EXIST The corresponding device driver of COM Port has not been initialized.
348*/
349extern DCL_STATUS DclSerialPort_DrvDetach(DCL_HANDLE handle);
350
351/*!
352* @function [New TTY API] DclSerialPort_DrvRx
353* @brief This function is for driver to send back the received data to TTY/upper layer.
354* @param handle a valid handle return by DclSerialPort_Open()
355* @param source_id driver module id
356* @param rx_ior received data with ior format
357* @result STATUS_OK successfully register the callback function.
358* @result STATUS_INVALID_HANDLE It's a invalid handle.
359* @result STATUS_NOT_OPENED The COM Port is not opened by upper layer.
360*/
361extern DCL_STATUS DclSerialPort_DrvRx(DCL_HANDLE handle, module_type source_id, void *rx_ior);
362
363/*!
364* @function [New TTY API] DclSerialPort_DrvTxDone
365* @brief This function is for driver to send back the transmitted (tx done) data to TTY/upper layer.
366* This function is called if "need tx done callback" is configured YES.
367* @param handle a valid handle return by DclSerialPort_Open()
368* @param source_id driver module id
369* @param tx_ior transmitted data with ior format
370* @result STATUS_OK successful.
371* @result STATUS_INVALID_HANDLE It's a invalid handle.
372* @result STATUS_NOT_OPENED The COM Port is not opened by upper layer.
373*/
374extern DCL_STATUS DclSerialPort_DrvTxDone(DCL_HANDLE handle, module_type source_id, void *tx_ior);
375
376#endif // DCL_DEFINITION_PROTOTYPE
377
378