drv_debug_port.h 8.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284
  1. /* Copyright (C) 2018 RDA Technologies Limited and/or its affiliates("RDA").
  2. * All rights reserved.
  3. *
  4. * This software is supplied "AS IS" without any warranties.
  5. * RDA assumes no responsibility or liability for the use of the software,
  6. * conveys no license or title under any patent, copyright, or mask work
  7. * right to the product. RDA reserves the right to make changes in the
  8. * software without notification. RDA also make no representation or
  9. * warranty that such application will be suitable for the specified use
  10. * without further testing or modification.
  11. */
  12. #ifndef _DRV_DEBUG_PORT_H_
  13. #define _DRV_DEBUG_PORT_H_
  14. #include "osi_api.h"
  15. #include "drv_names.h"
  16. #include <sys/queue.h>
  17. OSI_EXTERN_C_BEGIN
  18. /**
  19. * \brief forward declaration
  20. */
  21. struct drvDebugPort;
  22. /**
  23. * \brief debug port operations
  24. *
  25. * It is by design that there are no delete API. All debug port instances
  26. * doesn't support delete.
  27. */
  28. typedef struct
  29. {
  30. /** refer to \p drvDebugPortSendPacket */
  31. bool (*send_packet)(struct drvDebugPort *d, const void *data, unsigned size);
  32. /** refer to \p drvDebugPortRead */
  33. int (*read)(struct drvDebugPort *d, void *data, unsigned size);
  34. /** refer to \p drvDebugPortSetRxCallback */
  35. void (*set_rx_callback)(struct drvDebugPort *d, osiCallback_t cb, void *param);
  36. /** refer to \p drvDebugPortSetTraceEnable */
  37. void (*set_trace_enable)(struct drvDebugPort *d, bool enable);
  38. /** refer to \p drvDebugPortWorkEnable */
  39. void (*work_enable)(struct drvDebugPort *d, bool enable);
  40. } drvDebugPortOps_t;
  41. /**
  42. * \brief debug port protocol
  43. */
  44. typedef enum
  45. {
  46. DRV_DEBUG_PROTOCOL_HOST = 1, ///< host protocol, trace and command
  47. DRV_DEBUG_PROTOCOL_DIAG, ///< diag protocol, trace and command
  48. DRV_DEBUG_PROTOCOL_MODEM_LOG = 0x10, ///< modem log
  49. DRV_DEBUG_PROTOCOL_MOS_LOG, ///< mos log
  50. } drvDebugPortProtocol_t;
  51. /**
  52. * \brief debug port working mode
  53. */
  54. typedef union {
  55. struct
  56. {
  57. uint8_t protocol; ///< refer to \p drvDebugPortProtocol_t
  58. bool trace_enable : 1; ///< whether trace is enabled
  59. bool cmd_enable : 1; ///< whether command is enabled
  60. bool bs_enable : 1; ///< whether to work under blue screen
  61. bool bs_only : 1; ///< whether to work under blue screen only
  62. };
  63. uint32_t mode; ///< combined mode word
  64. } drvDebugPortMode_t;
  65. /**
  66. * \brief debug port status
  67. */
  68. typedef union {
  69. struct
  70. {
  71. bool usb_enabled : 1; ///< for usb debug port only, whether is enabled
  72. bool usb_host_opened : 1; ///< for usb debug port only, whether host has opened
  73. };
  74. uint32_t status; ///< combined status word
  75. } drvDebugPortStatus_t;
  76. /**
  77. * \brief debug port base data struct
  78. *
  79. * This is base of debug port. That means the operation pointer must be
  80. * the first member, and private data can follow.
  81. */
  82. typedef struct drvDebugPort
  83. {
  84. /** operations */
  85. const drvDebugPortOps_t *ops;
  86. /** debug port device name */
  87. unsigned name;
  88. /** baud rate for uart */
  89. unsigned baud;
  90. /** debug port mode */
  91. drvDebugPortMode_t mode;
  92. /** debug port status */
  93. drvDebugPortStatus_t status;
  94. /** iterator for the global debug port list */
  95. /**/ SLIST_ENTRY(drvDebugPort) iter;
  96. } drvDebugPort_t;
  97. /**
  98. * \brief send packet through debug port
  99. *
  100. * The packet can be host protocol or diag protocol, depends on the debug
  101. * mode at creation.
  102. *
  103. * Usually, it is called by the host command processing or diag command
  104. * processing.
  105. *
  106. * When host protocol is used, the packet should be a complete host packet.
  107. * \p data should be 4 bytes aligned, and there are no alignment requirement
  108. * for \p size.
  109. *
  110. * When diag protocol is used, the packet should be a complete hdlc encoded
  111. * packet, with leading and trailing sync byte. \p data should be 4 bytes
  112. * aligned, and there are no erquirement for \p size.
  113. *
  114. * When trace is enabled in the debug port, the packet will be mixed with
  115. * trace data.
  116. *
  117. * \param d debug port instance, must be valid
  118. * \param data packet data
  119. * \param size packet size
  120. * \return
  121. * - true on success
  122. * - false on error, invalid parameters or send timeout
  123. */
  124. bool drvDebugPortSendPacket(drvDebugPort_t *d, const void *data, unsigned size);
  125. /**
  126. * \brief set rx callback
  127. *
  128. * \p cb will be called when there are rx data arrived. Most likely, it
  129. * will be called in ISR. So, the recommended callback is to enqueue a
  130. * work for the real processing.
  131. *
  132. * \param d debug port instance, must be valid
  133. * \param cb rx arrive callback
  134. * \param param callback context
  135. */
  136. void drvDebugPortSetRxCallback(drvDebugPort_t *d, osiCallback_t cb, void *param);
  137. /**
  138. * \brief set trace enable
  139. *
  140. * It may be called for the registered debug port at \p osiTraceSetEnable.
  141. *
  142. * \param d debug port instance, must be valid
  143. * \param enable trace enable
  144. */
  145. void drvDebugPortSetTraceEnable(drvDebugPort_t *d, bool enable);
  146. /**
  147. * \brief work enable
  148. *
  149. * It may be called for the registered debugHost port at \p osiTraceSetPushEnable.
  150. *
  151. * \param d debug port instance, must be valid
  152. * \param enable debughost to tx log from ifc to fifo output
  153. */
  154. void drvDebugPortWorkEnable(drvDebugPort_t *d, bool enable);
  155. /**
  156. * \brief read from debug port
  157. *
  158. * \p cb will be called when there are rx data arrived. Most likely, it
  159. * will be called in ISR. So, the recommended callback is to enqueue a
  160. * work for the real processing.
  161. *
  162. * \param d debug port instance, must be valid
  163. * \param data memory for read
  164. * \param size maximum read size
  165. * \return
  166. * - read size, 0 for no rx data available
  167. * - -1 on error
  168. */
  169. int drvDebugPortRead(drvDebugPort_t *d, void *data, unsigned size);
  170. /**
  171. * \brief get debug port device name
  172. *
  173. * \param d debug port instance, must be valid
  174. * \return device name
  175. */
  176. static inline unsigned drvDebugPortGetName(drvDebugPort_t *d) { return d->name; }
  177. /**
  178. * \brief get debug port mode
  179. *
  180. * \param d debug port instance, must be valid
  181. * \return debug port mode
  182. */
  183. static inline drvDebugPortMode_t drvDebugPortGetMode(drvDebugPort_t *d) { return d->mode; }
  184. /**
  185. * \brief whether the debug port is on usb serial
  186. *
  187. * \param d debug port instance, must be valid
  188. * \return true if debug port on usb
  189. */
  190. static inline bool drvDebugPortIsUsb(drvDebugPort_t *d) { return DRV_NAME_IS_USRL(d->name); }
  191. /**
  192. * \brief whether trace is enabled on the debug port
  193. *
  194. * \param d debug port instance, must be valid
  195. * \return true if trace is enabled
  196. */
  197. static inline bool drvDebugPortIsTraceEnabled(drvDebugPort_t *d) { return d->mode.trace_enable; }
  198. /**
  199. * \brief whether the usb serial debug port is opened by host
  200. *
  201. * \param d debug port instance, must be valid
  202. * \return true if opened by host
  203. */
  204. static inline bool drvDebugPortIsUsbHostOpened(drvDebugPort_t *d) { return d->status.usb_host_opened; }
  205. /**
  206. * \brief register the debug port to global list
  207. *
  208. * \param d debug port instance, must be valid
  209. */
  210. void drvDebugPortRegister(drvDebugPort_t *d);
  211. /**
  212. * \brief find debug port by deivce name
  213. *
  214. * \param name device name
  215. * \return
  216. * - debug port instance
  217. * - NULL if there are no debug port on the device
  218. */
  219. drvDebugPort_t *drvDebugPortFindByName(uint32_t name);
  220. /**
  221. * \brief create debug port on debughost
  222. *
  223. * Usually, there is only one debughost in system. So, it is not needed
  224. * to specify the device name. Also, the configuration of debughost is
  225. * fixed.
  226. *
  227. * \param mode debugging mode
  228. * \return
  229. * - debughost instance
  230. */
  231. drvDebugPort_t *drvDhostCreate(drvDebugPortMode_t mode);
  232. /**
  233. * \brief create debug port on uart
  234. *
  235. * \param name uart device name
  236. * \param mode debugging mode
  237. * \param baud baud rate
  238. * \return
  239. * - debug uart instance
  240. */
  241. drvDebugPort_t *drvDebugUartPortCreate(unsigned name, drvDebugPortMode_t mode, unsigned baud);
  242. /**
  243. * \brief create debug port on usb serial
  244. *
  245. * \param name usb serial device name
  246. * \param mode debugging mode
  247. * \return
  248. * - debug uart instance
  249. */
  250. drvDebugPort_t *drvDebugUserialPortCreate(unsigned name, drvDebugPortMode_t mode);
  251. /**
  252. * \brief restore debughost configuration
  253. *
  254. * It is for debug purpose only.
  255. */
  256. void drvDhostRestoreConfig(void);
  257. OSI_EXTERN_C_END
  258. #endif