1 /******************************************************************************
2 ** File Name: com_drvapi.h *
3 ** Author: weihua.wang *
5 ** Copyright: 2006 Spreadtrum, Incoporated. All Rights Reserved. *
6 ** Description: This file defines the common macro definiton and structure*
7 ** for uart drv and usb virtual com *
8 ******************************************************************************
10 ******************************************************************************
12 ** --------------------------------------------------------------------------*
13 ** DATE NAME DESCRIPTION *
14 ** 25/04/2006 weihua.wang creat *
15 ** 02/09/2008 Tao.Zhou driver arrangement *
16 ******************************************************************************/
17 #ifndef _COM_DRVAPI_H_
18 #define _COM_DRVAPI_H_
20 /**---------------------------------------------------------------------------*
22 **---------------------------------------------------------------------------*/
28 /**---------------------------------------------------------------------------*
30 **---------------------------------------------------------------------------*/
46 #define USB_MAX_NUM (2)
50 #define CARDCOM_MAX_NUM (2)
52 /* add for DUN COM @eddie.li */
54 #define DUN_MAX_NUM (1)
55 /* add for DUN COM @eddie.li end */
58 #define UART_SUCCESS (0)
59 #define UART_FAILURE (1)
60 #define UART_PORT_NUM_ERR (2)
61 #define UART_PORT_REOPEN_ERR (3)
62 #define UART_PORT_RECLOSE_ERR (4)
63 #define UART_CALLBACK_ERR (5)
66 #define EVENT_DATA_TO_READ (0)
67 #define EVENT_WRITE_COMPLETE (1)
68 #define EVENT_INIT_COMPLETE (2)
69 #define EVENT_SHUTDOWN_COMPLETE (3)
70 #define COM_MAX_EVENT (4)
72 //Baud Rate. (CLK = 12.998 MHz)
73 #define BAUD_1200 0x2A50
74 #define BAUD_2400 0x1528
75 #define BAUD_4800 0x0A94
76 #define BAUD_9600 0x054A
77 #define BAUD_19200 0x02A5
78 #define BAUD_38400 0x0152
79 #define BAUD_57600 0x00E2
80 #define BAUD_115200 0x0071
81 #define BAUD_230400 0x0038
82 #define BAUD_460800 0x001C
83 #define BAUD_921600 0x000E
85 //#define UART_GET_MUTEX_WAIT_TIME 500 //wait for 500ms at most
88 Uart software settings
90 #define TX_WATER_MARK 8
92 // Set uart register directly, for debug purpose, not commend
93 #define UART0_QUCIKCFG(ien, ctl0, ctl1, ctl2, ckd0, ckd1)\
95 *(volatile uint32 *)(ARM_UART0_BASE + ARM_UART_IEN) = (ien);\
96 *(volatile uint32 *)(ARM_UART0_BASE + ARM_UART_CTL0) = (ctl0);\
97 *(volatile uint32 *)(ARM_UART0_BASE + ARM_UART_CTL1) = (ctl1);\
98 *(volatile uint32 *)(ARM_UART0_BASE + ARM_UART_CTL2) = (ctl2);\
99 *(volatile uint32 *)(ARM_UART0_BASE + ARM_UART_CLKD0) = (ckd0);\
100 *(volatile uint32 *)(ARM_UART0_BASE + ARM_UART_CLKD1) = (ckd1);\
103 #define UART1_QUCIKCFG(ien, ctl0, ctl1, ctl2, ckd0, ckd1)\
105 *(volatile uint32 *)(ARM_UART1_BASE + ARM_UART_IEN) = (ien);\
106 *(volatile uint32 *)(ARM_UART1_BASE + ARM_UART_CTL0) = (ctl0);\
107 *(volatile uint32 *)(ARM_UART1_BASE + ARM_UART_CTL1) = (ctl1);\
108 *(volatile uint32 *)(ARM_UART1_BASE + ARM_UART_CTL2) = (ctl2);\
109 *(volatile uint32 *)(ARM_UART1_BASE + ARM_UART_CLKD0) = (ckd0);\
110 *(volatile uint32 *)(ARM_UART1_BASE + ARM_UART_CLKD1) = (ckd1);\
113 #define UART2_QUCIKCFG(ien, ctl0, ctl1, ctl2, ckd0, ckd1)\
115 *(volatile uint32 *)(ARM_UART2_BASE + ARM_UART_IEN) = (ien);\
116 *(volatile uint32 *)(ARM_UART2_BASE + ARM_UART_CTL0) = (ctl0);\
117 *(volatile uint32 *)(ARM_UART2_BASE + ARM_UART_CTL1) = (ctl1);\
118 *(volatile uint32 *)(ARM_UART2_BASE + ARM_UART_CTL2) = (ctl2);\
119 *(volatile uint32 *)(ARM_UART2_BASE + ARM_UART_CLKD0) = (ckd0);\
120 *(volatile uint32 *)(ARM_UART2_BASE + ARM_UART_CLKD1) = (ckd1);\
123 #define UART3_QUCIKCFG(ien, ctl0, ctl1, ctl2, ckd0, ckd1)\
125 *(volatile uint32 *)(ARM_UART3_BASE + ARM_UART_IEN) = (ien);\
126 *(volatile uint32 *)(ARM_UART3_BASE + ARM_UART_CTL0) = (ctl0);\
127 *(volatile uint32 *)(ARM_UART3_BASE + ARM_UART_CTL1) = (ctl1);\
128 *(volatile uint32 *)(ARM_UART3_BASE + ARM_UART_CTL2) = (ctl2);\
129 *(volatile uint32 *)(ARM_UART3_BASE + ARM_UART_CLKD0) = (ckd0);\
130 *(volatile uint32 *)(ARM_UART3_BASE + ARM_UART_CLKD1) = (ckd1);\
133 #define UART_INIT_UART_LOWLEVEL(reg_base, baudrate) {\
134 *(volatile uint32 *)((reg_base) + ARM_UART_IEN) = 0x00;\
135 *(volatile uint32 *)((reg_base)+ ARM_UART_CTL0) = 0x1C;\
136 *(volatile uint32 *)((reg_base) + ARM_UART_CTL1) = 0x00;\
137 *(volatile uint32 *)((reg_base) + ARM_UART_CLKD0) = \
138 (CHIP_GetAPBClk() + (baudrate / 2)) / (baudrate);\
139 *(volatile uint32 *)((reg_base) + ARM_UART_CLKD1) = 0x00;\
176 /* uart deepsleep wakeup control */
179 DS_WAKEUP_DISABLE = 0,
183 /* uart deepsleep wakeup conditon */
186 DS_WAKEUP_TYPE_START = 0,
189 DS_WAKEUP_BY_RXD_DSR ,
191 DS_WAKEUP_BY_CTS_RXD ,
192 DS_WAKEUP_BY_CTS_DSR ,
193 DS_WAKEUP_BY_CTS_DSR_RXD,
197 /**---------------------------------------------------------------------------*
198 ** Global Variables *
199 **---------------------------------------------------------------------------*/
200 /**---------------------------------------------------------------------------*
201 ** Constant Variables *
202 **---------------------------------------------------------------------------*/
204 /**---------------------------------------------------------------------------*
205 ** Struct definition *
206 **---------------------------------------------------------------------------*/
207 typedef void (*UartCallback) (uint32 event);
211 uint16 tx_watermark; // 0~127B
212 uint16 rx_watermark; // 0~127B
214 UART_PARITY_E parity;
215 UART_PARITY_SET_E parity_enable;
216 UART_BYTE_SIZE_E byte_size;
217 UART_STOP_BIT_E stop_bits;
218 UART_FLOW_CTR_E flow_control;
219 UART_DS_CTRL_E ds_wakeup_en;
220 UART_DS_TYPE_E ds_wakeup_type;
223 /**---------------------------------------------------------------------------*
224 ** Function Prototypes *
225 **---------------------------------------------------------------------------*/
227 /*****************************************************************************/
228 // Description: This function initilizes uart port, configure uart
229 // registers, interrupt service, and register callback
230 // function for notifying the status of uart read and write.
231 // Param: uint32 port_num: usb virtual com num USB_COM0/USB_COM1
232 // UART_INIT_PARA_T* :include param for uart, only useful for uart
233 // UartCallback func :uplayer callback
234 // Author: xingyun.he
236 /*****************************************************************************/
237 PUBLIC uint32 UART_Initilize (uint32 port_num,
238 UART_INIT_PARA_T *para,
241 /*****************************************************************************/
242 // Description: This function close uart port
243 // Author: weihua.wang
244 // Param : uint32 port_num: usb virtual com number
246 /*****************************************************************************/
247 PUBLIC uint32 UART_Close (uint32 port_num);
249 /*****************************************************************************/
250 // Description : Use the given baudrate to init the uart register.
251 // and can receivce/send data via it.
252 // Global resource dependence: NONE
255 // uart port num: UART_COM0, UART_COM1
256 // baudrate : the baudrate need to be set( 115200, 9600 etc ).
260 /*****************************************************************************/
261 PUBLIC void UART_InitUartLowLevel (uint32 port, uint32 baudrate);
263 /*****************************************************************************/
264 // Description: This function is used to get uart port deepsleep-awaken
265 // function status: enable or disable
266 // Author: zhengjiang.lei
269 /*****************************************************************************/
270 PUBLIC BOOLEAN UARTCOM_DslpFuncSts_Get (uint32 port_num);
272 /*****************************************************************************/
273 // Description : check the DSR and set the DTR to enable/disable deep sleep
274 // Global resource dependence: NONE
275 // Author : Jim.zhang
276 // Note : If DSR = 1: Disable deep sleep, DTR = 1
277 // If DSR = 0, Enable deep sleep, DTR = 0
278 /*****************************************************************************/
279 PUBLIC void UART_CheckDeepSleepFlag (void);
281 /*****************************************************************************/
282 // Description: This function read data from receiving buffer.It is called*
283 // when up layfer receives the event of "EVENT_DATA_TO_READ".*
284 // Author: weihua.wang *
285 // Param : uint32 port_num : uart com number index *
286 // uint8* buffer : des buffer header address *
287 // uint32 length : size to be read *
288 // Return: if success,return size read in effect *
290 /*****************************************************************************/
291 PUBLIC uint32 UART_ReadData (uint32 port_num,
295 /*****************************************************************************/
296 // Description: This function record data which will be written to *
297 // tx fifo and enable tx fifo empty interrupt. The length *
298 // of data should be not larger than FIFO_SIZE(127B). *
299 // Author: weihua.wang *
300 // Param : uint32 port_num : uart com number index *
301 // uint8* buffer : src buffer header address *
302 // uint32 length : size to be writed *
303 // Return: if success,return size writed in effect *
305 /*****************************************************************************/
306 PUBLIC uint32 UART_WriteData (uint32 port_num,
310 /*****************************************************************************/
311 // Description: This function record data which will be written to *
312 // tx fifo and enable tx fifo empty interrupt. The length *
313 // of data should be not larger than FIFO_SIZE . *
314 // Author: weihua.wang *
315 // Param : uint32 port_num : uart com number index *
316 // uint8* buffer : src buffer header address *
317 // uint32 length : size to be writed *
318 // Return: if success,return size writed in effect *
320 /*****************************************************************************/
321 PUBLIC uint32 UART_WriteDataEx (uint32 port_num,
325 /*****************************************************************************/
326 // Description: This function get char from uart receive register. *
327 // Author: xingyun.he *
328 // Return value: Returns a char from uart receive register. *
329 // Note: return -1 indicates that no char received from fifo *
330 /*****************************************************************************/
331 PUBLIC int32 UART_DumpGetChar (uint32 phy_port);
333 /*****************************************************************************/
334 // Description: This function put a char to the uart send register. *
335 // Author: xingyun.he *
336 // Return value: put a char from uart receive register. *
338 /*****************************************************************************/
339 PUBLIC void UART_DumpPutChar (uint32 phy_port, uint8 nchar);
341 /*****************************************************************************/
342 // Description: This function read data in sync mode. *
343 // Author: Tao.Zhou *
344 // Return value: Returns a char from uart receive register. *
345 // Note: return -1 indicates that no char received from fifo *
346 /*****************************************************************************/
347 PUBLIC uint32 UART_ReadDataSync (uint32 port_num, uint8 *buffer, uint32 length);
349 /*****************************************************************************/
350 // Description: This function write data in sync mode. *
351 // Author: Tao.Zhou *
352 // Return value: put a char from uart receive register. *
354 /*****************************************************************************/
355 PUBLIC void UART_WriteDataSync (uint32 port_num, const uint8 *buffer, uint32 length);
358 /*****************************************************************************/
359 // Description: This function set uart speed *
360 // Author: xingyun.he *
362 /*****************************************************************************/
363 PUBLIC void UART_SetBaudSpeed (uint32 port_num, uint32 speed);
366 /*****************************************************************************/
367 // Description: This function set uart parity parameter *
368 // Global resource dependence : NONE *
369 // Author: Tao.Zhou *
371 /*****************************************************************************/
372 PUBLIC void UART_SetParity (uint32 port_num, UART_PARITY_E parity);
375 /*****************************************************************************/
376 // Description: uart parity enable/disable *
377 // Global resource dependence : NONE *
378 // Author: Tao.Zhou *
380 /*****************************************************************************/
381 PUBLIC void UART_ParityEnable (uint32 port_num, UART_PARITY_SET_E is_enable);
384 /*****************************************************************************/
385 // Description: This function set uart byte size *
386 // Global resource dependence : NONE *
387 // Author: Tao.Zhou *
389 /*****************************************************************************/
390 PUBLIC void UART_SetByteSize (uint32 port_num, UART_BYTE_SIZE_E byte_size);
392 /*****************************************************************************/
393 // Description: This function set uart stop bits *
394 // Global resource dependence : NONE *
395 // Author: Tao.Zhou *
397 /*****************************************************************************/
398 PUBLIC void UART_SetStopBits (uint32 port_num, UART_STOP_BIT_E stop_bits);
401 /*****************************************************************************/
402 // Description: This function set uart tx water mark *
403 // Global resource dependence : NONE *
404 // Author: Tao.Zhou *
406 /*****************************************************************************/
407 PUBLIC void UART_SetTxWaterMark (uint32 port_num, uint16 tx_watermark);
409 /*****************************************************************************/
410 // Description: This function set uart rx water mark *
411 // Global resource dependence : NONE *
412 // Author: Tao.Zhou *
414 /*****************************************************************************/
415 PUBLIC void UART_SetRxWaterMark (uint32 port_num, uint16 rx_watermark);
417 /*****************************************************************************/
418 // Description: return the available size in uart fifo
419 // Global resource dependence: NONE
420 // Author: weihua.wang
421 // Param : uint32 port_num: usb virtual com number
423 /*****************************************************************************/
424 PUBLIC uint32 UART_GetTxFifoCnt (uint32 phy_port);
426 /*****************************************************************************/
427 // Description: return the Tx fifo is busy or idle
428 // Global resource dependence: NONE
430 // Param : uint32 port_num: usb virtual com number
431 // Return : 1 - busy, 0 - idle
432 // Note: This interface is just for 8801H platform currently
433 /*****************************************************************************/
434 PUBLIC BOOLEAN UART_IsTxFifoBusy (uint32 phy_port);
436 //@David.Jia 2007.7.4 cr82866 begin
437 /*****************************************************************************/
438 // Description: return the received bytes in uart fifo
439 // Global resource dependence: NONE
441 // Param : uint32 port_num: com number
443 /*****************************************************************************/
444 PUBLIC uint32 UART_GetRxFifoCnt (uint32 phy_port);
445 //@David.Jia 2007.7.4 cr82866 end
447 /*****************************************************************************/
448 // Description: uart hardware flow control enable/disable *
449 // Global resource dependence : NONE *
450 // Author: Tao.Zhou *
452 /*****************************************************************************/
453 PUBLIC void UART_FlowCtlEnable (uint32 port_num, UART_FLOW_CTR_E is_enable);
455 /*****************************************************************************/
456 // Description: uart fifo control by DAM enable/disable *
457 // Global resource dependence : NONE *
458 // Author: Tao.Zhou *
460 /*****************************************************************************/
461 PUBLIC void UART_DmaModeEnable (uint32 port_num, BOOLEAN is_enable);
463 /*****************************************************************************/
464 // Description: uart tx empty enable/disable
465 // Global resource dependence: NONE
466 // Author: weihua.wang
467 // Param : uint32 port_num: usb virtual com number
468 // BOOLEAN is_enable: TRUE/FALSE
470 /*****************************************************************************/
471 PUBLIC void UART_Tx_Int_Enable (uint32 phy_port, BOOLEAN is_enable);
473 /*****************************************************************************/
474 // Description: uart rx full enable/disable
475 // Global resource dependence: NONE
476 // Author: weihua.wang
477 // Param : uint32 port_num: usb virtual com number
478 // BOOLEAN is_enable: TRUE/FALSE
480 /*****************************************************************************/
481 PUBLIC void UART_Rx_Int_Enable (uint32 phy_port, BOOLEAN is_enable);
483 /*****************************************************************************/
484 // Description: enable/disable self loop mode *
485 // Global resource dependence : NONE *
486 // Author: Tao.Zhou *
488 /*****************************************************************************/
489 PUBLIC void UART_SelfLoopEnable (uint32 phy_port, BOOLEAN is_enable);
491 /*****************************************************************************/
492 // Description: uart callback function register *
493 // Global resource dependence : NONE *
494 // Author: Tao.Zhou *
496 /*****************************************************************************/
497 PUBLIC void UART_RegCallBack (uint32 port_num, UartCallback func);
499 /*****************************************************************************/
500 // Description: uart callback function unregister *
501 // Global resource dependence : NONE *
502 // Author: Tao.Zhou *
504 /*****************************************************************************/
505 PUBLIC void UART_UnRegCallBack (uint32 port_num);
507 /*****************************************************************************/
508 // Description: uart dma mode writing *
509 // Global resource dependence : NONE *
510 // Author: Tao.Zhou *
512 /*****************************************************************************/
513 PUBLIC void UART_DmaWriteData (uint32 port_num, const uint8 *buffer, uint32 length);
514 //PUBLIC uint32 UART_WriteData(uint32 port_num, const uint8* buffer, uint32 length);
516 /*****************************************************************************/
517 // Description: get the max number of UART
518 // Global resource dependence : NONE
519 // Author: hanjun.liu
521 /*****************************************************************************/
522 PUBLIC uint32 UART_MaxPortNum (void);
524 /*****************************************************************************/
525 // Description: get the of UART
526 // Global resource dependence : NONE
527 // Author: hanjun.liu
529 /*****************************************************************************/
530 PUBLIC uint32 UART_RxWaterMark (void);
532 PUBLIC void DSPLogUARTSwitchOn (void);
533 PUBLIC void DSPLogUARTSwitchOff (void);
535 uint32 GetUART0BaseAddr (void);
537 uint32 getRMUartBaseAddr (void);
538 /**---------------------------------------------------------------------------*
540 **---------------------------------------------------------------------------*/
545 #endif //ยข_COM_DRVAPI_H_