osi_trace.h 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407
  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 _OSI_TRACE_H_
  13. #define _OSI_TRACE_H_
  14. #include <stdint.h>
  15. #include <stdbool.h>
  16. #include <stddef.h>
  17. #include "osi_api.h"
  18. #include "quec_proj_config.h"
  19. OSI_EXTERN_C_BEGIN
  20. /**
  21. * \brief forward declaration for debug port
  22. */
  23. struct drvDebugPort;
  24. /**
  25. * \brief trace output device
  26. */
  27. typedef enum
  28. {
  29. OSI_TRACE_DEVICE_NONE = 0, ///< no output
  30. OSI_TRACE_DEVICE_DEBUGHOST = 0x01, ///< output through debughost
  31. OSI_TRACE_DEVICE_USBSERIAL = 0x02, ///< output through USB serial
  32. #ifndef CONFIG_QUEC_PROJECT_FEATURE
  33. OSI_TRACE_DEVICE_FILESYS = 0x04, ///< output to file system, usually on SDCARD
  34. #else
  35. OSI_TRACE_DEVICE_FILESYS_SD = 0x04, ///< output to file system, usually on SDCARD
  36. OSI_TRACE_DEVICE_FILESYS_NAND = 0x05, ///< output to file system, usually on NAND FLASH
  37. OSI_TRACE_DEVICE_FILESYS_EXTNOR = 0x6, ///< output to file system, usually on SPI4 EXT NOR FLASH,is not supported by default
  38. OSI_TRACE_DEVICE_FILESYS_EXT = 0x7, ///< output to file system, usually on SPI6 EXT NOR FLASH,is not supported by default
  39. #endif
  40. } osiTraceDevice_t;
  41. /**
  42. * \brief data structure of host packet
  43. *
  44. * *frame length* is the length of host packet, *exclude* header. So,
  45. * frame length is the packet length minus 4.
  46. */
  47. typedef struct
  48. {
  49. uint8_t sync; ///< sync byte, 0xAD
  50. uint8_t frame_len_msb; ///< MSB byte of frame length
  51. uint8_t frame_len_lsb; ///< LSB byte of frame length
  52. uint8_t flowid; ///< flow ID
  53. } osiHostPacketHeader_t;
  54. /**
  55. * \brief tra packet header data structure
  56. */
  57. typedef struct
  58. {
  59. uint16_t sync; ///< sync 16bits word, 0xBBBB
  60. uint8_t plat_id; ///< platform id, fill 1 at unsure.
  61. uint8_t type; ///< tra packet type
  62. uint32_t sn; ///< serial number
  63. uint32_t fn_wcdma; ///< WCDMA frame number, fill tick count when there are no WCDMA
  64. uint32_t fn_gge; ///< GSM frame number
  65. uint32_t fn_lte; ///< LTE frame number
  66. } osiTraPacketHeader_t;
  67. /**
  68. * \brief diag packet header
  69. */
  70. typedef struct
  71. {
  72. uint32_t seq_num; ///< Message sequence number, used for flow control
  73. uint16_t len; ///< The totoal size of the packet
  74. uint8_t type; ///< Main command type
  75. uint8_t subtype; ///< Sub command type
  76. } osiDiagPacketHeader_t;
  77. /**
  78. * \brief diag log packet header
  79. */
  80. typedef struct
  81. {
  82. uint16_t type; ///< log type
  83. uint16_t length; ///< log length
  84. } osiDiagLogHeader_t;
  85. #ifdef CONFIG_SOC_8910
  86. #define FSTRACE_SUPPORT_TIMESTAMP
  87. #elif defined(CONFIG_SOC_8850)
  88. #define FSTRACE_SUPPORT_TIMESTAMP
  89. #endif
  90. #ifdef CONFIG_KERNEL_HOST_TRACE
  91. /**
  92. * Application trace (Time) header
  93. */
  94. typedef struct
  95. {
  96. osiHostPacketHeader_t host;
  97. uint32_t date; ///< trace sequence
  98. uint32_t ms; ///< tick of trace
  99. } osiTraceTimeStampHeader_t;
  100. #elif defined(CONFIG_KERNEL_DIAG_TRACE)
  101. #pragma pack(4)
  102. typedef struct
  103. {
  104. osiDiagPacketHeader_t diag;
  105. uint64_t llUeTime;
  106. uint32_t u32tickcnt; //tick count
  107. } osiTraceDiagTimeStampHeader_t;
  108. typedef struct
  109. {
  110. //uint32_t u32size;
  111. osiTraceDiagTimeStampHeader_t stTimeStampheader;
  112. } osiTraceDiagTimeStamp;
  113. #pragma pack()
  114. #endif
  115. /**
  116. * \brief prototype for trace push callback
  117. */
  118. typedef void (*osiTracePushCallback_t)(void *param);
  119. /**
  120. * \brief global trace sequence number
  121. *
  122. * *Don't* modify it, unless in trace output engine.
  123. */
  124. extern uint32_t gTraceSequence;
  125. /**
  126. * \brief global variable for trace enable/disable
  127. *
  128. * *Don't* modify it. It is only for trace API for faster check,
  129. * to save a little cycles than calling API.
  130. */
  131. extern bool gTraceEnabled;
  132. /**
  133. * \brief tick value for trace
  134. *
  135. * The unit of tick is platform dependent, to adapt various trace tool.
  136. */
  137. uint32_t osiTraceTick(void);
  138. /**
  139. * \brief time in millisecond for trace
  140. */
  141. uint32_t osiTraceTimeMs(void);
  142. /**
  143. * \brief set trace enable or not
  144. *
  145. * After disable, trace calls won't put trace data to trace buffer. Also,
  146. * debug port will stop trace output (after the already started transfer
  147. * finished).
  148. *
  149. * There are multiple enable controls
  150. * - \p osiTraceSetEnable Enable control for log. When disabled, log message
  151. * won't come to trace buffer.
  152. * - \p osiTraceSetOutputEnable Enable control for log output. Other packets
  153. * are not affected by this. When disabled, debug port cannot get log
  154. * packets, but can get packets by \p osiTraceBufPutPacket, for example,
  155. * diag packets.
  156. * - \p osiTraceSetPushEnable Enable control for debug port. When disabled,
  157. * debug port cannot get any packets.
  158. *
  159. * \param enable false for disable, true for enable
  160. */
  161. void osiTraceSetEnable(bool enable);
  162. /**
  163. * \brief set trace output enable or not
  164. *
  165. * When trace output disabled, \p osiTraceBufFetch won't return trace
  166. * buffer, and will only return external buffer by \p osiTraceBufPutPacket.
  167. *
  168. * \param enable false for disable, true for enable
  169. */
  170. void osiTraceSetOutputEnable(bool enable);
  171. /**
  172. * \brief whether trace output is enable
  173. *
  174. * \return false for disable, true for enable
  175. */
  176. bool osiTraceIsOutputEnable(void);
  177. /**
  178. * \brief set trace push callback
  179. *
  180. * When there are new trace data, and there are no trace transfer in
  181. * progress, the push callback will be called.
  182. *
  183. * \param cb trace pusb callback, NULL for no callback
  184. * \param ctx trace push callback context
  185. */
  186. void osiTraceSetPushCallback(osiTracePushCallback_t cb, void *ctx);
  187. /**
  188. * \brief set trace push enable/diable
  189. *
  190. * Typically, it is needed to disable trace push at sleep procedure.
  191. * Otherwise, trace itself will affect sleep procedure.
  192. *
  193. * \param enable true to enable trace push, false to disable trace push
  194. */
  195. void osiTraceSetPushEnable(bool enable);
  196. /**
  197. * \brief get GSM frame number
  198. *
  199. * When GSM frame number is needed to be embedded into trace, this function
  200. * should be implemented outside trace module.
  201. *
  202. * \return GSM frame number
  203. */
  204. uint32_t osiTraceGsmFrameNumber(void);
  205. /**
  206. * \brief get LTE frame number
  207. *
  208. * When LTE frame number is needed to be embedded into trace, this function
  209. * should be implemented outside trace module.
  210. *
  211. * \return GSM frame number
  212. */
  213. uint32_t osiTraceLteFrameNumber(void);
  214. /**
  215. * \brief fill host packet header
  216. *
  217. * It is just a helper to fill host packet header.
  218. *
  219. * \param [in] header host packet header
  220. * \param [in] flowid host packet flowid
  221. * \param [in] frame_len host packet frame length
  222. */
  223. static inline void osiFillHostHeader(osiHostPacketHeader_t *header, uint8_t flowid, uint16_t frame_len)
  224. {
  225. header->sync = 0xAD;
  226. header->frame_len_msb = frame_len >> 8;
  227. header->frame_len_lsb = frame_len & 0xff;
  228. header->flowid = flowid;
  229. }
  230. /**
  231. * \brief trace buffer initialization
  232. *
  233. * It should be called only once at system boot. When this is called,
  234. * it is possible that RTOS hasn't initialized.
  235. */
  236. void osiTraceBufInit(void);
  237. /**
  238. * \brief put a trace packet into trace buffer
  239. *
  240. * Inside, packet data may be copied to global trace buffer or malloc-copy
  241. * to dynamic memory, depends on the packet size. After the call, \p data
  242. * won't be used any more.
  243. *
  244. * When diag trace is used, this is the real packet, rather than hdlc
  245. * encoded packet. Hdlc encoding will be performed inside.
  246. *
  247. * \param data packet data
  248. * \param size packet total size
  249. * \return
  250. * - true on success
  251. * - false on error, invalid paramters or trace buffer full
  252. */
  253. bool osiTraceBufPut(const void *data, unsigned size);
  254. /**
  255. * \brief put a trace packet into trace buffer
  256. *
  257. * It is similar to \p osiTraceBufPut, just the packet is described by
  258. * multiple pieces of buffer. It can save time for caller to combine them.
  259. *
  260. * When \p size is -1, the total size will be calculated. Otherwise it will be
  261. * used as total size. Total size will only be used to check whether space is
  262. * enough, and caller should ensure \p size matches the total size.
  263. *
  264. * \param bufs buffers of packet data
  265. * \param count buffer count
  266. * \param size total size, -1 means callee should calculate total size
  267. * \return
  268. * - true on success
  269. * - false on error, invalid paramters or trace buffer full
  270. */
  271. bool osiTraceBufPutMulti(const osiBuffer_t *bufs, unsigned count, int size);
  272. /**
  273. * \brief put an external trace packet into trace buffer
  274. *
  275. * Put a "reference" of packet to trace output. The data won't be copied,
  276. * so \p data will still be accessed after this returns. Only after
  277. * \p osiTraceBufPacketFinished returns true, the packet has been transfered,
  278. * and won't be accessed any more.
  279. *
  280. * For host packet, \p size should be 4 bytes aligned.
  281. *
  282. * For diag packet, it is hdlc encoded packet, with leading and trailing
  283. * sync byte.
  284. *
  285. * There is count limit of raw packets. When there are too many raw packets
  286. * are pending, it will return false.
  287. *
  288. * \param data raw packet data
  289. * \param size raw packet total size
  290. * \return
  291. * - true on success
  292. * - false on error, invalid paramters or too many raw packets
  293. */
  294. bool osiTraceBufPutPacket(const void *data, unsigned size);
  295. /**
  296. * \brief put an diag packet into trace buffer
  297. *
  298. * Put a "reference" of packet to trace output. The data won't be copied,
  299. * so \p data will still be accessed after this returns. Only after
  300. * \p osiTraceBufPacketFinished returns true, the packet has been transfered,
  301. * and won't be accessed any more.
  302. *
  303. *
  304. * For diag packet, it is hdlc encoded packet, with leading and trailing
  305. * sync byte.
  306. *
  307. * There is count limit of raw packets. When there are too many raw packets
  308. * are pending, it will return false.
  309. *
  310. * \param data raw packet data
  311. * \param size raw packet total size
  312. * \return
  313. * - true on success
  314. * - false on error, invalid paramters or too many raw packets
  315. */
  316. bool osiTraceBufPutDiagPacket(const void *data, unsigned size);
  317. /**
  318. * \brief whether the external trace packet is transfered
  319. *
  320. * \p data must be the pointer called by \p osiTraceBufPutPacket.
  321. *
  322. * \param data raw packet data
  323. * \return true if transfer done
  324. */
  325. bool osiTraceBufPacketFinished(const void *data);
  326. /**
  327. * \brief fetch a piece of trace buffer
  328. *
  329. * When trace buffer is empty, the returned size will be 0.
  330. *
  331. * The returned buffer may contain one or more packets, and it won't
  332. * contain partial packet.
  333. *
  334. * After \p osiTraceBufFetch is called, it is needed to call
  335. * \p osiTraceBufHandled before next call.
  336. *
  337. * It should be called by trace output only.
  338. *
  339. * \return buffer with trace data
  340. */
  341. osiBuffer_t osiTraceBufFetch(void);
  342. /**
  343. * \brief indicate trace buffer is handled
  344. *
  345. * It should be called by trace output only.
  346. */
  347. void osiTraceBufHandled(void);
  348. /**
  349. * \brief get existed trace data size
  350. *
  351. * In most cases, this shouldn't be cared. One excception is in usb trace,
  352. * when the remaining trace data is smaller than the threshold, usb
  353. * transfer should wait a while.
  354. *
  355. * \return existed trace data size
  356. */
  357. unsigned osiTraceDataSize(void);
  358. /**
  359. * \brief set trace debug port
  360. *
  361. * \p drvDebugPortSetTraceEnable will be called when the current enabled
  362. * state changed.
  363. *
  364. * \param port debug port for trace
  365. */
  366. void osiTraceSetDebugPort(struct drvDebugPort *port);
  367. OSI_EXTERN_C_END
  368. #endif