osi_api_inside.h 8.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287
  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_API_INSIDE_H_
  13. #define _OSI_API_INSIDE_H_
  14. #include "osi_compiler.h"
  15. #ifdef __cplusplus
  16. extern "C" {
  17. #endif
  18. // NOTE: It is not recommended to use APIs in this file, unless you really
  19. // know what you are doing.
  20. /**
  21. * \brief opaque data struct for static semaphore
  22. */
  23. typedef osiSemaphore_t osiSemaphoreStatic_t;
  24. /**
  25. * thread state
  26. */
  27. typedef enum
  28. {
  29. OSI_THREAD_STATE_RUNNING, ///< running
  30. OSI_THREAD_STATE_READY, ///< ready, and there are higher priority task in running
  31. OSI_THREAD_STATE_BLOCKED, ///< waiting temporal or external events
  32. OSI_THREAD_STATE_SUSPENDED, ///< suspend explicitly
  33. OSI_THREAD_STATE_DELETED, ///< deleted but not release resources
  34. OSI_THREAD_STATE_INVALID, ///< placeholder for invalid
  35. } osiThreadState_t;
  36. /**
  37. * thread status
  38. */
  39. typedef struct osiThreadStatus
  40. {
  41. void *handler; ///< implementation dependent handler
  42. const char *name; ///< thread name
  43. unsigned thread_number; ///< numeric number
  44. osiThreadState_t state; ///< state
  45. unsigned curr_priority; ///< current priority, may be inherited
  46. unsigned base_priority; ///< base priority
  47. void *stack_base; ///< stack base address (lowest address)
  48. unsigned stack_alloc_size; ///< satck allocation size
  49. unsigned stack_min_remained; ///< minimal unused stack size
  50. } osiThreadStatus_t;
  51. /**
  52. * \brief semaphore data struct size
  53. *
  54. * This returns semaphore implementation size at runtime. It is by design
  55. * not to expose semaphore size in compiling time to ease binary
  56. * compatibility.
  57. *
  58. * \return
  59. * - semaphore implementation size
  60. */
  61. unsigned osiSemaphoreSize(void);
  62. /**
  63. * \brief create a semaphore with static memory
  64. *
  65. * When the semaphore won't be used later, \p osiSemaphoreDelete must be
  66. * called still to avoid resource leakage.
  67. *
  68. * Usually, the return pointer is the same as \p buf.
  69. *
  70. * Due to the implementation size is not exposed, \p alloca is needed to
  71. * use static semaphore. For example:
  72. *
  73. * \code{cpp}
  74. * osiSemaphoreStatic_t *buf_sema = alloca(osiSemaphoreSize());
  75. * osiSemaphore_t *sema = osiSemaphoreCreateStatic(buf_sema, 1, 0);
  76. * // ......
  77. * osiSemaphoreDelete(sema);
  78. * \endcode
  79. *
  80. * \param buf static memory for semaphore
  81. * \param max_count maximum count of the semaphore
  82. * \param init_count initial count of the semaphore
  83. * \return
  84. * - semaphore pointer
  85. * - NULL on invalid parameter
  86. */
  87. osiSemaphore_t *osiSemaphoreCreateStatic(osiSemaphoreStatic_t *buf, uint32_t max_count, uint32_t init_count);
  88. /**
  89. * \brief opaque data struct for static timer
  90. */
  91. typedef osiTimer_t osiTimerStatic_t;
  92. /**
  93. * \brief timer data struct size
  94. *
  95. * This returns timer implementation size at runtime. It is by design not
  96. * to expose timer size in compiling time to ease binary compatibility.
  97. *
  98. * \return
  99. * - timer implementation size
  100. */
  101. unsigned osiTimerSize(void);
  102. /**
  103. * \brief create a timer with static memory
  104. *
  105. * When the timer won't be used later, \p osiTimerDelete must be called
  106. * still to avoid resource leakage.
  107. *
  108. * Usually, the return pointer is the same as \p buf.
  109. *
  110. * Due to the implementation size is not exposed, \p alloca is needed to
  111. * use static timer. For example:
  112. *
  113. * \code{cpp}
  114. * osiTimerStatic_t *buf_timer = alloca(osiTimerSize());
  115. * osiTimer_t *timer = osiTimerCreateStatic(buf_timer, ...);
  116. * // ......
  117. * osiTimerDelete(timer);
  118. * \endcode
  119. *
  120. * \param buf static memory for timer
  121. * \param thread thread to execute the callback
  122. * \param cb callback to be executed after timer expire
  123. * \param ctx callback context
  124. * \return
  125. * - the created timer instance
  126. * - NULL at invalid parameter
  127. */
  128. osiTimer_t *osiTimerCreateStatic(osiTimerStatic_t *buf, osiThread_t *thread, osiCallback_t cb, void *ctx);
  129. /**
  130. * \brief start a timer with relaxed timeout, in unit of hardware tick
  131. *
  132. * **Don't** call this in application code. It is only for legacy codes.
  133. *
  134. * The frequency of hardware tick is chip dependent, and implementation dependent.
  135. *
  136. * \param timer the timer to be started
  137. * \param ticks normal timeout period in hardware tick
  138. * \param relax_ticks relaxed timeout period in hardware tick
  139. * \return
  140. * - true on success
  141. * - false on invalid parameter
  142. */
  143. bool osiTimerStartHWTickRelaxed(osiTimer_t *timer, int64_t ticks, int64_t relax_ticks);
  144. /**
  145. * \brief dump timer information to memory
  146. *
  147. * It is for debug only. The data format of timer information dump is
  148. * not stable, and may change. When \p mem is NULL, it will return the
  149. * estimated dump size.
  150. *
  151. * \param mem memory for timer information dump
  152. * \param size provided memory size
  153. * \return
  154. * - dump memory size
  155. * - -1 if memory size of not enough
  156. */
  157. int osiTimerDump(void *mem, unsigned size);
  158. /**
  159. * \brief monoclinic system hardware tick
  160. *
  161. * **Don't** call this in application code. It is only for legacy codes.
  162. *
  163. * The frequency of hardware tick is chip dependent, and implementation
  164. * dependent.
  165. *
  166. * \return monoclinic system hardware tick
  167. */
  168. int64_t osiUpHWTick(void);
  169. /**
  170. * \brief monoclinic system hardware tick
  171. *
  172. * **Don't** call this in application code. It is only for legacy codes.
  173. *
  174. * Similar to \p osiUpHWTick, just with less instruction. It can be used
  175. * when performance is really cared.
  176. *
  177. * \return monoclinic system hardware tick
  178. */
  179. uint32_t osiUpHWTick32(void);
  180. /**
  181. * \brief hardware tick count in 16384Hz
  182. *
  183. * The return value should be fulll 32bits value. That is, the next tick
  184. * of 0xffffffff will be 0. Then the simple substract will always provide
  185. * the tick delta.
  186. *
  187. * This is only for legacy codes. \p osiUpTime or \p osiUpTimeUS are
  188. * recommended to get monoclinic time, and \p osiHWTick32 is recommended
  189. * for timing measrement when performance is sensitive.
  190. *
  191. * \return hardware tick count
  192. */
  193. uint32_t osiHWTick16K(void);
  194. /**
  195. * \brief dump PM source information to memory
  196. *
  197. * It is for debug only. The data format of pm source information dump is
  198. * not stable, and may change. When \p mem is NULL, it will return the
  199. * estimated dump size.
  200. *
  201. * \param mem memory for PM source information dump
  202. * \param size provided memory size
  203. * \return
  204. * - dump memory size
  205. * - -1 if memory size of not enough
  206. */
  207. int osiPmSourceDump(void *mem, unsigned size);
  208. /**
  209. * \brief dump interrupt information to memory
  210. *
  211. * It is for debug only. The data format of interrupt information dump is
  212. * not stable, and may change. When \p mem is NULL, it will return the
  213. * estimated dump size.
  214. *
  215. * \param mem memory for interrupt information dump
  216. * \param size provided memory size
  217. * \return
  218. * - dump memory size
  219. * - -1 if memory size of not enough
  220. */
  221. int osiIrqDump(void *mem, unsigned size);
  222. /**
  223. * get current thread count
  224. *
  225. * \return thread count
  226. */
  227. uint32_t osiThreadCount(void);
  228. /**
  229. * get all thread status
  230. *
  231. * The memory of \p status should be enough to hold thread status of \p count.
  232. *
  233. * \param status memory for thread status output
  234. * \param count maximum thread count
  235. * \return actual filled thread count
  236. */
  237. int osiThreadGetAllStatus(osiThreadStatus_t *status, uint32_t count);
  238. /**
  239. * get active pm sources
  240. *
  241. * It should be only used for DEBUG.
  242. *
  243. * \param tags output active pm source tags
  244. * \param count maximum output count
  245. * \return
  246. * - real written active pm source count
  247. */
  248. int osiGetActivePmSources(uint32_t *tags, unsigned count);
  249. /**
  250. * get clk_sys request sources
  251. *
  252. * It should be only used for DEBUG.
  253. *
  254. * \param tags output clk_sys request tags
  255. * \param count maximum output count
  256. * \return
  257. * - real written clk_sys request count
  258. */
  259. int osiGetSysClkRequestSources(uint32_t *tags, unsigned count);
  260. #ifdef __cplusplus
  261. }
  262. #endif
  263. #endif