gps_com.h 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  1. /******************************************************************************
  2. ** File Name: Gps_SiRF.h *
  3. ** Author: David.Jia *
  4. ** DATE: 7/11/2007 *
  5. ** Copyright: 2005 Spreatrum, Incoporated. All Rights Reserved. *
  6. ** Description: *
  7. *****************************************************************************/
  8. /******************************************************************************
  9. ** Edit History *
  10. **---------------------------------------------------------------------------*
  11. ** DATE NAME DESCRIPTION *
  12. ** 06/19/2007 David.Jia Test uartcom_drv interface.
  13. ** 06/23/2007 David.Jia add data to cycle queue, in the uartcom_drv's callback.
  14. ** 06/26/2007 David.Jia implement map application interface--Map_Read/Write,
  15. ** Calibration interface--Cal_Read/Write.
  16. ** 08/02/2007 David.Jia Change names of COM_Init/COM_Close/Map_Read/Map_Write
  17. ** to GPS_ComInit/GPS_ComClose/GPS_ComRead/GPS_ComWrite.
  18. *****************************************************************************/
  19. #include "com_drv.h"
  20. #ifndef GPS_COM_H
  21. #define GPS_COM_H
  22. #define COM_0 0
  23. #define COM_1 1 //uart port
  24. /*----------------------------------------------------------------------------*
  25. ** Data Structures *
  26. **---------------------------------------------------------------------------*/
  27. typedef enum
  28. {
  29. COM_SEND, //send complete
  30. COM_REC, //receive complete, no data in uart rx fifo
  31. COM_REMAINDER, //receive complete, remainder data in uart rx fifo
  32. COM_TIMEOUT //receive timeout, received data number less than expected
  33. } COM_EVENT;
  34. /*****************************************************************************/
  35. // FUNCTION: COM_CallBack
  36. // Description: callback function for com communication. called after
  37. // sent all bytes ,after received all bytes, receive timeout and error.
  38. // called in ISR, so only send a event to COM TASK and return.
  39. // INPUT: event--indetify which event occur, num--bytes done.
  40. // return: 0--ok, others--error.
  41. // Author: David.Jia
  42. // date: 2007.6.19
  43. // Note:
  44. /*****************************************************************************/
  45. typedef int (*COM_CallBack)(COM_EVENT event, uint32 num);
  46. typedef struct
  47. {
  48. uint32 port; //uart port
  49. uint8 *send_buf; //save send buffer address and size
  50. uint32 send_len;
  51. uint32 send_len_done; //already sent
  52. COM_CallBack send_callback;
  53. uint8 *rec_buf; //save receive buffer address and size
  54. uint32 rec_len;
  55. uint32 rec_len_done; //already received
  56. COM_CallBack rec_callback;
  57. int error; //lastest error code
  58. } COM_OBJ;
  59. extern COM_OBJ com1_ins;
  60. //@David.Jia 2007.6.23 begin
  61. //Cycle Queue struct
  62. typedef struct
  63. {
  64. uint8 *buf;
  65. uint32 size; //queue volume
  66. uint32 head;
  67. uint32 tail;
  68. unsigned empty : 1;
  69. unsigned full : 1;
  70. unsigned overflow : 1; //queue input after full, overwrite occur
  71. } CycleQueue;
  72. /*****************************************************************************/
  73. // FUNCTION: GPS_ComRead
  74. // Description: read string from uart (initialized by COM_Init)
  75. // INPUT: uint8* buf--data buffer alocated by caller, uint32 len--bytes number wish to read.
  76. // OUTPUT: read byte number in fact.
  77. // Author: David.Jia
  78. // date: 2007.6.26
  79. // Note:
  80. /*****************************************************************************/
  81. int GPS_ComRead(uint8 *buf, uint32 len);
  82. /*****************************************************************************/
  83. // FUNCTION: GPS_ComWrite
  84. // Description: write string to uart (initialized by COM_Init)
  85. // INPUT: uint8* buf--data buffer alocated by caller, uint32 len--bytes number wish to read.
  86. // OUTPUT: write byte number in fact.
  87. // Author: David.Jia
  88. // date: 2007.6.26
  89. // Note: if len > Output_Q.size, data will overwrite.
  90. /*****************************************************************************/
  91. int GPS_ComWrite(uint8 *buf, uint32 len);
  92. /*****************************************************************************/
  93. // FUNCTION: GPS_ComInit
  94. // Description: pin select of uart 1, and initialize uart 1.
  95. // return: 0--ok, others--error.
  96. // Author: David.Jia
  97. // date: 2007.6.19
  98. // Note: call before using uart 1.
  99. /*****************************************************************************/
  100. int GPS_ComInit(void);
  101. /*****************************************************************************/
  102. // FUNCTION: GPS_ComClose
  103. // Description: pin deselect of uart 1, and close uart 1.
  104. // return: 0--ok, others--error.
  105. // Author: David.Jia
  106. // date: 2007.6.19
  107. // Note: call after using uart 1.
  108. /*****************************************************************************/
  109. int GPS_ComClose(void);
  110. #endif //GPS_COM_H