1 /******************************************************************************
3 ** Author: Richard Yang *
5 ** Copyright: 2002 Spreatrum, Incoporated. All Rights Reserved. *
6 ** Description: This driver is for development board, Integrator/AP. *
7 ******************************************************************************
9 ******************************************************************************
11 ** ------------------------------------------------------------------------- *
12 ** DATE NAME DESCRIPTION *
13 ** 04/02/2002 Richard.Yang Create. *
14 ** 05/13/2002 Richard.Yang Add sio_send_packet, sio_send_log_packet *
15 ** 05/30/2003 Eric.zhou Add AT through channel server associated *
17 ** 08/25/2003 Zhemin.Lin Add MIX_MODE for COM_USER port, according MS00004213 *
18 ******************************************************************************/
23 /**---------------------------------------------------------------------------*
25 **---------------------------------------------------------------------------*/
26 #include "sci_types.h"
27 #include "com_drvapi.h"
31 /**---------------------------------------------------------------------------*
33 **---------------------------------------------------------------------------*/
39 #define SIO_PPP_SUCCESS 0
40 #define SIO_PPP_FAIL -1
42 #define SIO_RX_FLOW_CONTROL 0x1
43 #define SIO_TX_FLOW_CONTROL 0x2
47 Debug port communications protocol flag.
49 #define ESCAPE_BYTE 0x7D
50 #define FLAG_BYTE 0x7E
51 #define COMPLEMENT_BYTE 0x20
54 Uart/USB port definitions
67 #define MAX_SIO_PORT_NUM (9)
68 /* added @eddie.li end */
70 #define MAX_LOGICAL_SIO_PORT_NUM 2 //'COM_DATA', 'COM_DEBUG'
71 #define SIO_ALREADY_OPEN 0x55
74 #define LOG_FRM_NONE 1
78 #define DATA_MODE 0x02
86 // @Tao.Zhou, CR:MS00057325, 09/29/2006
87 /* We must send at least(FIFO_SIZE - FIFO_EMPTY - fifo_cnt) bytes during one interrupt */
90 #define GET_BUF_FREE_SIZE(free_size, _buf) \
91 if (_buf->start_point >= _buf->end_point) \
93 free_size = (int) ((int)_buf->size - _buf->start_point + _buf->end_point - 1);\
97 free_size = (int) (_buf->end_point - _buf->start_point - 1);\
100 #define GET_BUF_DATA_SIZE(data_size, _buf) \
101 if (_buf->start_point >= _buf->end_point) \
103 data_size = (int) (_buf->start_point - _buf->end_point);\
107 data_size = (int) ((int)(_buf->size) + _buf->start_point - _buf->end_point);\
110 #if defined(PLATFORM_SC8800H) || defined(PLATFORM_SC8800G) || defined(CONFIG_SC8810)//modified by tyler.song for compiling error.
111 #define ATC_REC_BUF_SIZE 2600
113 #define ATC_REC_BUF_SIZE 1600
133 } UARTSTAT_S, *UARTSTAT_PTR_T;
135 typedef void (* ATC_CALLBACK) (uint32);
144 uint32 size; // Total Size of the buffer.
145 volatile int start_point; // First data in the buffer.
146 volatile int end_point; // Last data in the buffer.
147 volatile uint32 status; // Indicate the buffer status.
149 uint8 *sio_buf_ptr; // Sio buffer address.
154 uint32 (*init) (uint32 port_num, UART_INIT_PARA_T * ,
155 UartCallback callback); /* drv com creat */
157 uint32 (*close) (uint32 port_num); /* drv com close */
159 uint32 (*get_fifocnt) (uint32 phy_port); /* get tx fifo cnt */
161 uint32 (*read) (uint32 port_num,uint8 *buffer,uint32 length); /* read data from drv */
163 uint32 (*write) (uint32 port_num,const uint8 *buffer,uint32 length); /*send data to drv*/
165 int32 (*get_char) (uint32 phy_port); /* read single char*/
167 void (*put_char) (uint32 phy_port, uint8 nchar); /* send signle char*/
169 void (*tx_enable) (uint32 phy_port,BOOLEAN is_enable); /* drv send enable */
171 void (*rx_enable) (uint32 phy_port,BOOLEAN is_enable); /* drv receive enable*/
173 void (*flush) (uint32 phy_port); /* only useful for usb virtual com */
174 /* flush data from local buffer to fifo*/
179 uint32 sio_port_index;
180 uint32 phy_port_index;
191 volatile unsigned mdm_stat; /* modem status at last change */
192 volatile uint32 last_tx; // Last time for tx
193 struct com_line *p_line; /* ptr to comline driver structure
194 no use for debug port, just for user port */
195 sio_operation_st sio_op; /* sio operation for COM_DEBUG/COM_DATA */
201 Functions definitions
203 /* Create a device control block.*/
204 PUBLIC HSIO SIO_Create (uint32 port,
208 PUBLIC uint32 SIO_SetBaudRate (uint32 port, uint32 baud_rate);
209 PUBLIC uint32 SIO_GetBaudRate (uint32 port);
210 PUBLIC void SIO_SetATCBuffer (uint8 *src,uint16 length);
211 PUBLIC uint32 SIO_ChangeMode (uint32 mode);
212 PUBLIC uint32 SIO_GetMode (void);
213 PUBLIC void SIO_Close (uint32 port);
214 PUBLIC void SIO_BuildDCB (
219 PUBLIC SIO_INFO_S *SIO_GetPPPPort (void);
220 PUBLIC int SIO_ReadPPPFrame (
221 uint32 port, // Port number COM_USER, COM_DEBUG
222 uint8 *src, // Data to receive
223 int size, // MAX size to receive
224 uint32 *dest_len // Actual size received
227 PUBLIC int SIO_WritePPPFrame (
233 PUBLIC int SIO_FastWritePPPFrame (
239 PUBLIC int SIO_GetChar (
243 PUBLIC int SIO_PutChar (
248 /*****************************************************************************/
249 // Description : this function changes userport from one mode to another,
250 // following mode transition can be done by this funcition:
251 // MIX_MODE-->ATC_MODE
252 // MIX_MODE-->DATA_MODE
253 // ATC_MODE-->MIX_MODE
254 // ATC_MODE-->DATA_MODE
255 // Global resource dependence :
256 // Author : Zhemin.Lin
258 /*****************************************************************************/
259 PUBLIC uint32 SIO_SetUserPortMode (
262 PUBLIC uint32 SIO_ClearError (
265 UARTSTAT_PTR_T *uart_stat_ptr
268 PUBLIC int SIO_SendLogPacket (
275 PUBLIC int SIO_SendPacket (
280 PUBLIC void SIO_ATC_SetMixMode (
284 PUBLIC int SIO_SendFrame (
289 PUBLIC uint16 SIO_GetFreePPPFrameCount (void);
291 PUBLIC int SIO_DumpGetChar (
294 PUBLIC void SIO_DumpPutChar (
299 PUBLIC void SIO_DumpPutCharEnd (
303 PUBLIC uint32 SIO_WaitEvent (
308 PUBLIC void SIO_ResetBuf (
312 PUBLIC void SIO_ATC_ReadCmdLine (
313 uint8 *data_ptr, // Output argument, point to the buf which is
315 uint length, // The length of cmd line which should be read from
317 uint *read_length_ptr // The actual read length
320 PUBLIC void SIO_ATC_WriteCmdRes (
321 uint8 *res_data_ptr, // Point to the response infomation buffer
322 uint length // The length of response infomation buffer
325 PUBLIC void SIO_ATC_ClrCmdLine (
329 void SIO_ATC_SetCmdLineTerminateChar (
330 uint8 terminate_char1, // Default terminate char is '\n'
331 uint8 terminate_char2 // Default terminate char is '\0'
333 PUBLIC void SIO_ATC_SetCmdLineBackSpaceChar (
334 uint8 back_space_char // Default backspace char value is 8
337 PUBLIC void SIO_ATC_SetDataMode (BOOLEAN mode);
338 PUBLIC void SIO_ATC_SetEcho (BOOLEAN IsEcho);
340 PUBLIC void SIO_ATC_SetCallback (
341 ATC_CALLBACK callback
344 PUBLIC void SIO_BuildDCB (
348 /*sio variable extern*/
349 #define MAX_PLUS_NUMBER 3
350 #define MODE_CHANGE_DELAY 1000 // 1000 milliseconds
351 #define BACKSPACE_CHAR 0x08
352 #define END_CHAR 0x0D
353 #define PLUS_CHAR '+'
356 #ifdef _U0_FLOW_CONTROL
357 #define SPACE_CHECK_DELAY 300 // time delay of space check of Rx buffer for COM_DATA
358 #define EMPTY_SPACE_WATER_MARK 258 // empty sapce water mark of rx buffer
361 #define XOFF 0x13 // Xoff of Software flow control.
362 #define XON 0x11 // Xon of Software flow control.
364 #define DO_ATC_CALLBACK(len) \
365 if ( NULL == AT_callback_ind) \
367 DefaultAtHandle(len);\
371 (*AT_callback_ind)(len);\
374 //@Zhemin.Lin, 08/15/2003
375 /*****************************************************************************/
376 // Description : Update clock divider value due to the change of system frequency
377 // Global resource dependence :
378 // Author : Zhemin.Lin
380 /*****************************************************************************/
381 PUBLIC void SIO_UpdateDividerValue (void);
383 //@Zhemin.Lin, CR:MS00004213, 08/22/2003, begin
385 //SIO communication error type
392 typedef void (*SIO_ERROR_HANDLE) (uint32 portid, SIO_LINK_ERROR_E linkerror);
400 typedef void (*SIO_NOTIFY_HANDLE) (uint32 notify_id, uint32 param);
402 /*****************************************************************************/
403 // Description : Register error handle, when sio link error, driver will call this handle to deal
405 // Global resource dependence :
406 // Author : Zhemin.Lin
408 /*****************************************************************************/
409 PUBLIC uint32 SIO_RegisterErrorHandle (SIO_ERROR_HANDLE errorhandle);
411 /*****************************************************************************/
412 // Description : Register notify handle, under the mix mode, when sio drv receive a ready
413 // package or busy package or status package, it will call the notify handle
414 // Global resource dependence :
415 // Author : Zhemin.Lin
417 /*****************************************************************************/
418 PUBLIC uint32 SIO_RegisterNotifyHandle (SIO_NOTIFY_HANDLE notifyhandle);
420 /*****************************************************************************/
421 // Description : Register data receive function
422 // Global resource dependence :
423 // Author : Zhemin.Lin
425 /*****************************************************************************/
426 PUBLIC uint32 SIO_RegisterDataRecvHandle (ATC_CALLBACK recvhandle);
428 /*****************************************************************************/
429 // Description : under the MIX_MODE, use this function to send data package
430 // Global resource dependence :
431 // Author : Zhemin.Lin
433 /*****************************************************************************/
434 PUBLIC uint32 SIO_SendDataPacket (uint8 *src, uint32 length);
436 /*****************************************************************************/
437 // Description : under the MIX_MODE, use this function to send status package
438 // Global resource dependence :
439 // Author : Zhemin.Lin
441 /*****************************************************************************/
442 PUBLIC uint32 SIO_SendStatusPacket (uint8 status);
444 /*****************************************************************************/
445 // Description : under the MIX_MODE, use this function to send ready package
446 // Global resource dependence :
447 // Author : Zhemin.Lin
449 /*****************************************************************************/
450 PUBLIC uint32 SIO_SendReadyPacket (void);
452 /*****************************************************************************/
453 // Description : under the MIX_MODE, use this function to send busy package
454 // Global resource dependence :
455 // Author : Zhemin.Lin
457 /*****************************************************************************/
458 PUBLIC uint32 SIO_SendBusyPacket (void);
460 /*****************************************************************************/
461 // Description : this function changes userport from one mode to another,
462 // following mode transition can be done by this funcition:
463 // MIX_MODE-->ATC_MODE
464 // MIX_MODE-->DATA_MODE
465 // ATC_MODE-->MIX_MODE
466 // ATC_MODE-->DATA_MODE
467 // Global resource dependence :
468 // Author : Zhemin.Lin
470 /*****************************************************************************/
471 PUBLIC uint32 SIO_SetUserPortMode (uint32 mode);
473 /*****************************************************************************/
474 // Description : get the mode of COM_USER port
475 // Global resource dependence :
476 // Author : Zhemin.Lin
478 /*****************************************************************************/
479 PUBLIC uint32 SIO_GetUserPortMode (void);
481 /*****************************************************************************/
482 // Description : get phy port no from logical port
483 // Global resource dependence :
484 // Author : weihua.wang
485 // Note : uint32 port: COM_DEUBG/COM_DATA
486 /*****************************************************************************/
487 PUBLIC uint32 SIO_GetPhyPortNo (uint32 port);
489 /*****************************************************************************/
490 // Description : get the mode of COM_USER port
491 // Global resource dependence :
492 // Author : hanjun.liu
494 /*****************************************************************************/
496 PUBLIC void SIO_SendRemainLogMessage (void);
497 //@Zhemin.Lin, CR:MS00004213, 08/22/2003, end
499 /*@jim.zhang CR:MS00008486 04/06/2004 */
500 /*****************************************************************************/
501 // Description : get the mix used state for GPRS.
502 // Global resource dependence :
503 // Author : Jim.zhang
504 // Note : return 1 means PPP and Log are mixed, 0 means not mixed.
505 /*****************************************************************************/
506 PUBLIC BOOLEAN SIO_IsPPPMixedLogel (void);
507 /* end CR:MS00008486 */
510 ** Send the char of PPP out.
511 ** It's the function called by PPP.
513 PUBLIC int uart_ppp_putc (int port, uint8 ch);
515 /*****************************************************************************/
516 // Description : Use the given baudrate to init the uart register.
517 // and can receivce/send data via it.
518 // Global resource dependence :
521 // port : uart port number, UART_COM0/1
522 // baudrate : the baudrate need to be set( 115200, 9600 etc ).
526 /*****************************************************************************/
527 PUBLIC void SIO_InitUartLowLevel (uint32 port, uint32 baudrate);
529 /*****************************************************************************/
530 // Description : get com_debug/com_data rx buffer max size;
531 // Global resource dependence :
533 // Input: COM_Port No.
535 // COM_DEBUG/Data rx buffer max size
537 /*****************************************************************************/
538 PUBLIC int32 SIO_GetRxBufMaxSize (uint32 port);
540 /*****************************************************************************/
541 // Description : Register COM operations to the table.
542 // Global resource dependence :
549 /*****************************************************************************/
550 PUBLIC void SIO_RegisterOpsToTab (uint32 port,
552 sio_operation_st ops);
555 PUBLIC uint32 SIO_PhyPortfromIndex (uint32 index);
557 /**---------------------------------------------------------------------------*
559 **---------------------------------------------------------------------------*/