osi_api.h 75 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625
  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_H_
  13. #define _OSI_API_H_
  14. #include <stdint.h>
  15. #include <stdbool.h>
  16. #include <stddef.h>
  17. #include "kernel_config.h"
  18. #include "osi_compiler.h"
  19. #include "osi_vsmap.h"
  20. #include "osi_clock.h"
  21. #ifdef __cplusplus
  22. extern "C" {
  23. #endif
  24. #define OSI_WAIT_FOREVER (-1U)
  25. #define OSI_DELAY_MAX (-1U)
  26. /**
  27. * Special value to indicate timer callback will be invoked in
  28. * timer ISR.
  29. */
  30. #define OSI_TIMER_IN_ISR ((osiThread_t *)NULL)
  31. /**
  32. * Special value to indicate timer callback will be invoked in
  33. * timer service thread.
  34. */
  35. #define OSI_TIMER_IN_SERVICE ((osiThread_t *)0xffffffff)
  36. /**
  37. * reserved event id to indicate quit event loop
  38. */
  39. #define OSI_EVENT_ID_QUIT (8)
  40. /**
  41. * elapsed timer for couting elapsed time
  42. */
  43. typedef uint32_t osiElapsedTimer_t;
  44. /**
  45. * opaque data structure for timer
  46. */
  47. typedef struct osiTimer osiTimer_t;
  48. /**
  49. * opaque data structure for timer pool
  50. */
  51. typedef struct osiTimerPool osiTimerPool_t;
  52. /**
  53. * opaque data structure for thread
  54. */
  55. typedef struct osiThread osiThread_t;
  56. /**
  57. * opaque data structure for message queue
  58. */
  59. typedef struct osiMessageQueue osiMessageQueue_t;
  60. /**
  61. * opaque data structure for event queue
  62. *
  63. * Event queue is just a message queue, and the message is \p osiEvent_t
  64. * (event itself rather than pointer).
  65. */
  66. typedef struct osiEventQueue osiEventQueue_t;
  67. /**
  68. * opaque data structure for mutex
  69. */
  70. typedef struct osiMutex osiMutex_t;
  71. /**
  72. * opaque data structure for semaphore
  73. */
  74. typedef struct osiSemaphore osiSemaphore_t;
  75. /**
  76. * opaque data structure for work
  77. */
  78. typedef struct osiWork osiWork_t;
  79. /**
  80. * opaque data structure for work queue
  81. */
  82. typedef struct osiWorkQueue osiWorkQueue_t;
  83. /**
  84. * opaque data structure for thread notify
  85. */
  86. typedef struct osiNotify osiNotify_t;
  87. /**
  88. * function type of callback
  89. */
  90. typedef void (*osiCallback_t)(void *ctx);
  91. /**
  92. * function type of thread entry
  93. */
  94. typedef void (*osiThreadEntry_t)(void *argument);
  95. /**
  96. * function type of interrupt handler
  97. */
  98. typedef void (*osiIrqHandler_t)(void *ctx);
  99. /**
  100. * event, with ID and 3 parameters
  101. */
  102. typedef struct osiEvent
  103. {
  104. uint32_t id; ///< event identifier
  105. uint32_t param1; ///< 1st parameter
  106. uint32_t param2; ///< 2nd parameter
  107. uint32_t param3; ///< 3rd parameter
  108. } osiEvent_t;
  109. /**
  110. * thread priority
  111. *
  112. * The definition is independent of implementation. Though some
  113. * implementation will use larger value for higher priority and
  114. * others will use smaller value for highe priority, this enum will
  115. * use larger value for higher priority.
  116. *
  117. * \p OSI_PRIORITY_IDLE and \p OSI_PRIORITY_HISR are reserved, can't
  118. * be used.
  119. *
  120. * The definition is the same as CMSIS-RTOS.
  121. */
  122. typedef enum osiThreadPriority
  123. {
  124. OSI_PRIORITY_IDLE = 1, // reserved
  125. OSI_PRIORITY_LOW = 8,
  126. OSI_PRIORITY_BELOW_NORMAL = 16,
  127. OSI_PRIORITY_NORMAL = 24,
  128. OSI_PRIORITY_ABOVE_NORMAL = 32,
  129. OSI_PRIORITY_HIGH = 40,
  130. OSI_PRIORITY_REALTIME = 48,
  131. OSI_PRIORITY_HISR = 56, // reserved
  132. } osiThreadPriority_t;
  133. /**
  134. * suspend mode
  135. *
  136. * System behavior of suspend modes will be diffrent among underlay
  137. * platform. Driver shall take care the difference, and most likely
  138. * application won't take care it.
  139. */
  140. typedef enum osiSuspendMode
  141. {
  142. OSI_SUSPEND_PM1, ///< 1st level suspend mode
  143. OSI_SUSPEND_PM2 ///< 2nd level suspend mode
  144. } osiSuspendMode_t;
  145. /**
  146. * resume wakeup source
  147. *
  148. * Resume wakeup source depends on platform. They should be defined in
  149. * \p hal_chip.h. One bit indicates one source, and multiple sources are
  150. * possible. \p OSI_RESUME_ABORT is reserved to indicate suspend is
  151. * aborted.
  152. */
  153. typedef enum osiResumeSource
  154. {
  155. OSI_RESUME_ABORT = (1 << 31), ///< resume by suspend aborted
  156. } osiResumeSource_t;
  157. /**
  158. * \brief boot cause
  159. *
  160. * This list is for cold boot cause. Though it is rare, it is possible
  161. * there exist multiple boot causes simultanuously.
  162. *
  163. * Usually boot cause is determined from hardware status registers.
  164. */
  165. typedef enum osiBootCause
  166. {
  167. OSI_BOOTCAUSE_UNKNOWN = 0, ///< placeholder for unknown reason
  168. OSI_BOOTCAUSE_PWRKEY = (1 << 0), ///< boot by power key
  169. OSI_BOOTCAUSE_PIN_RESET = (1 << 1), ///< boot by pin reset
  170. OSI_BOOTCAUSE_ALARM = (1 << 2), ///< boot by alarm
  171. OSI_BOOTCAUSE_CHARGE = (1 << 3), ///< boot by charge in
  172. OSI_BOOTCAUSE_WDG = (1 << 4), ///< boot by watchdog
  173. OSI_BOOTCAUSE_PIN_WAKEUP = (1 << 5), ///< boot by wakeup
  174. OSI_BOOTCAUSE_PSM_WAKEUP = (1 << 6), ///< boot from PSM wakeup
  175. /*+\NEW\zhuwangbin\2020.04.04\区分软件重启和reset按键重启*/
  176. OSI_BOOTCAUSE_RESET = (1 << 7),
  177. /*-\NEW\zhuwangbin\2020.04.04\区分软件重启和reset按键重启*/
  178. } osiBootCause_t;
  179. /**
  180. * boot mode
  181. *
  182. * Besides normal boot, there are several other boot modes. For each
  183. * platform, not all boot modes are supported.
  184. *
  185. * Usually, boot mode can be determined by hardware (for example, some
  186. * GPIO) or software (for example, by flags written at \p osiShutdown).
  187. */
  188. typedef enum osiBootMode
  189. {
  190. OSI_BOOTMODE_NORMAL = 0, ///< normal boot
  191. OSI_BOOTMODE_DOWNLOAD = 0x444e, ///< 'DN' boot to download mode
  192. OSI_BOOTMODE_CALIB = 0x434c, ///< 'CL' boot to calibration mode
  193. OSI_BOOTMODE_CALIB_POST = 0x4350, ///< 'CP' boot to calibration post mode
  194. OSI_BOOTMODE_NB_CALIB = 0x4e43, ///< 'NC' boot to NB calibration mode
  195. OSI_BOOTMODE_BBAT = 0x4241, ///< 'BA' boot to BBAT mode
  196. OSI_BOOTMODE_UPGRADE = 0x4654, ///< 'FT' boot to bootloader upgrade
  197. OSI_BOOTMODE_PSM_RESTORE = 0x5053, ///< 'PS' boot to PSM restore
  198. } osiBootMode_t;
  199. /**
  200. * shudown mode
  201. *
  202. * For each platform, not all shutdown modes are supported.
  203. */
  204. typedef enum osiShutdownMode
  205. {
  206. OSI_SHUTDOWN_RESET = 0, ///< normal reset
  207. OSI_SHUTDOWN_FORCE_DOWNLOAD = 0x5244, ///< 'RD' reset to force download mode
  208. OSI_SHUTDOWN_DOWNLOAD = 0x444e, ///< 'DN' reset to download mode
  209. OSI_SHUTDOWN_CALIB_MODE = 0x434c, ///< 'CL' reset to calibration mode
  210. OSI_SHUTDOWN_NB_CALIB_MODE = 0x4e43, ///< 'NC' reset to NB calibration mode
  211. OSI_SHUTDOWN_BBAT_MODE = 0x4241, ///< 'BA' reset to BBAT mode
  212. OSI_SHUTDOWN_UPGRADE = 0x4654, ///< 'FT' reset to upgrade mode
  213. OSI_SHUTDOWN_POWER_OFF = 0x4f46, ///< 'OF' power off
  214. OSI_SHUTDOWN_PSM_SLEEP = 0x5053, ///< 'PS' power saving mode
  215. } osiShutdownMode_t;
  216. /**
  217. * PSM data owner
  218. */
  219. typedef enum osiPsmDataOwner
  220. {
  221. OSI_PSMDATA_OWNER_KERNEL, ///< kernel
  222. OSI_PSMDATA_OWNER_STACK, ///< stack
  223. OSI_PSMDATA_OWNER_AT, ///< AT engine
  224. OSI_PSMDATA_OWNER_USER = 100, ///< start owner for user application
  225. } osiPsmDataOwner_t;
  226. /**
  227. * shuwdown callback function type
  228. *
  229. * Before shutdown, the registered callbacks will be invokes. The callbacks
  230. * are executed in system high priority work queue, and with interrupt
  231. * disabled. So, the callbacks shouldn't rely on system high priority work
  232. * queue and interrupts. However, thread schedule is still working and
  233. * multi-thread can work still.
  234. */
  235. typedef void (*osiShutdownCallback_t)(void *ctx, osiShutdownMode_t mode);
  236. /**
  237. * invoke global constructors
  238. *
  239. * Global constructors are not called during boot. Rather, they will be called
  240. * in \p osiInvokeGlobalCtors, and it shall be called in \p osiAppStart.
  241. *
  242. * At \p osiAppStart, RTOS is ready. So, it is permitted to call more OSI
  243. * APIs at global constructors.
  244. *
  245. * Though global constructors are supported. It is not encouraged to use this
  246. * feature. Only use this feature when you really know what you are doing.
  247. */
  248. void osiInvokeGlobalCtors(void);
  249. /**
  250. * kernel start
  251. *
  252. * Start the kernel. This API will create system threads (at least,
  253. * idle thread) and start thread scheduler. So, it won't return.
  254. *
  255. * Before \p osiKernelStart is called, kernel data structure may be
  256. * uninitialized, and many osi APIs can be called. Including
  257. *
  258. * - timer
  259. * - IRQ
  260. * - power management
  261. */
  262. OSI_NO_RETURN void osiKernelStart(void);
  263. /**
  264. * suspend thread scheduler
  265. *
  266. * After scheduler is suspended, there are no thread context switch.
  267. * However, interrupt handlers will be executed.
  268. *
  269. * The meaning of return flag depends on underlay RTOS. Don't assume the
  270. * meaning of the return value.
  271. *
  272. * \return scheduler suspend flag.
  273. */
  274. uint32_t osiSchedulerSuspend(void);
  275. /**
  276. * resume thread scheduler
  277. *
  278. * Scheduler suspend and resume is not *recursive*. That is, after
  279. * \p osiSchedulerResume is called, scheduler is resumed no matter
  280. * how many times \p osiSchedulerSuspend are called.
  281. *
  282. * \param [in] flag scheduler suspend flag returned by the latest
  283. * \p osiSchedulerSuspend
  284. */
  285. void osiSchedulerResume(uint32_t flag);
  286. /**
  287. * \brief enter critical section
  288. *
  289. * The underlay RTOS may have different implementation for critical
  290. * section. It may manipulate CPU IRQ enable bit(s), or manipulate
  291. * IRQ mask.
  292. *
  293. * This can be called in ISR.
  294. *
  295. * \return critical section flags
  296. */
  297. uint32_t osiEnterCritical(void);
  298. /**
  299. * \brief exit critical section
  300. *
  301. * Critical section flags is implementation depend. It should be the value
  302. * returned by \p osiEnterCritical, and don't change the value manually.
  303. *
  304. * Critical section is *recursive*. That is, after \p osiExitCritical is
  305. * called, it doesn't mean system will enter *unprotected* state. Rather,
  306. * it will return to state before last call of \p osiEnterCritical.
  307. * For example:
  308. *
  309. * \code{.cpp}
  310. * uint32_t critical1 = osiEnterCritical();
  311. * uint32_t critical2 = osiEnterCritical();
  312. * // ...
  313. * osiExitCritical(critical2);
  314. * osiExitCritical(critical1);
  315. * \endcode
  316. *
  317. * After the first call of \p osiExitCritical, system is in *protected*
  318. * state still.
  319. *
  320. * In recursive, the exit order must be the reverse order of enter. For
  321. * example, the following codes are wrong:
  322. *
  323. * \code{.cpp}
  324. * uint32_t critical1 = osiEnterCritical();
  325. * uint32_t critical2 = osiEnterCritical();
  326. * // ...
  327. * osiExitCritical(critical1);
  328. * osiExitCritical(critical2);
  329. * \endcode
  330. *
  331. * This can be called in ISR.
  332. *
  333. * \param critical critical section flags
  334. */
  335. void osiExitCritical(uint32_t critical);
  336. /**
  337. * \brief get IRQ flags and disable IRQ
  338. *
  339. * This will always manipulate CPU IRQ enable bit(s).
  340. *
  341. * After this call, \p osiEnterCritical can't be called. When
  342. * \p osiEnterCritical manipulates IRQ mask, it is very possible that
  343. * it will change CPU IRQ enable bit(s) without protection.
  344. *
  345. * In most cases, \p osiIrqSave and \p osiIrqRestore shouldn't be
  346. * used, unless you really know what you are doing.
  347. *
  348. * \return IRQ flags before disable IRQ
  349. */
  350. uint32_t osiIrqSave(void);
  351. /**
  352. * \brief restore IRQ flags
  353. *
  354. * IRQ flags is arch and implementation depend. It should be the value
  355. * returned by \p osiIrqSave, and don't change the value manually.
  356. *
  357. * \param flags IRQ flags
  358. */
  359. void osiIrqRestore(uint32_t flags);
  360. /**
  361. * set interrupt handler
  362. *
  363. * When interrupt arrived, the registered handler will be called with
  364. * the registered context pointer.
  365. *
  366. * For each interrupt, only one handler can be registered. When a handler
  367. * is already registered for an interrupt, \p osiIrqSetHandler will
  368. * replace the old one.
  369. *
  370. * \p irqn depends on interrupt controller in system. When GIC is used,
  371. * it is the number in GIC.
  372. *
  373. * \param irqn IRQ number
  374. * \param handler IRQ handler
  375. * \param ctx IRQ handler context pointer
  376. * \return
  377. * - true on success
  378. * - false on invalid parameters
  379. */
  380. bool osiIrqSetHandler(uint32_t irqn, osiIrqHandler_t handler, void *ctx);
  381. /**
  382. * enable interrupt
  383. *
  384. * \param irqn IRQ number
  385. * \return
  386. * - true on success
  387. * - false on invalid parameters
  388. */
  389. bool osiIrqEnable(uint32_t irqn);
  390. /**
  391. * disable interrupt
  392. *
  393. * \param irqn IRQ number
  394. * \return
  395. * - true on success
  396. * - false on invalid parameters
  397. */
  398. bool osiIrqDisable(uint32_t irqn);
  399. /**
  400. * whether interrupt is enabled
  401. *
  402. * \param irqn IRQ number
  403. * \return
  404. * - true if interrupt is enabled
  405. * - false if interrupt is disabled
  406. */
  407. bool osiIrqEnabled(uint32_t irqn);
  408. /**
  409. * set interrupt priority
  410. *
  411. * \p priority depends on interrupt controller used on system. When GIC
  412. * is used, \p priority should follow GIC requirement and meaning.
  413. *
  414. * \param irqn IRQ number
  415. * \param priority IRQ priority
  416. * \return
  417. * - true on success
  418. * - false on invalid parameters
  419. */
  420. bool osiIrqSetPriority(uint32_t irqn, uint32_t priority);
  421. /**
  422. * get interrupt priority
  423. *
  424. * When \p irqn is invalid, 0x80000000U will be returned.
  425. *
  426. * \param irqn IRQ number
  427. * \return IRQ priority
  428. */
  429. uint32_t osiIrqGetPriority(uint32_t irqn);
  430. /**
  431. * check whether there are pending interrupt
  432. *
  433. * This is for special purpose. It shall be called with interrupt disabled
  434. * (not masked off).
  435. *
  436. * This may be unimplemented in some chips.
  437. *
  438. * \return
  439. * - true if there are interrupt pending.
  440. */
  441. bool osiIrqPending(void);
  442. /**
  443. * enable D-cache
  444. *
  445. * Usually, it shouldn't be called in application. It will only be called
  446. * once in boot code.
  447. *
  448. * Not all platforms implement this API.
  449. */
  450. void osiDCacheEnable(void);
  451. /**
  452. * disable D-cache
  453. *
  454. * Usually, it shouldn't be called in application. And most likely it will
  455. * never be called. It is provided for completeness.
  456. *
  457. * Not all platforms implement this API.
  458. */
  459. void osiDCacheDisable(void);
  460. /**
  461. * enable I-cache
  462. *
  463. * Usually, it shouldn't be called in application. It will only be called
  464. * once in boot code.
  465. *
  466. * Not all platforms implement this API.
  467. */
  468. void osiICacheEnable(void);
  469. /**
  470. * disable I-cache
  471. *
  472. * Usually, it shouldn't be called in application. And most likely it will
  473. * never be called. It is provided for completeness.
  474. *
  475. * Not all platforms implement this API.
  476. */
  477. void osiICacheDisable(void);
  478. /**
  479. * clean (write back) D-cache
  480. *
  481. * Usually it shall be called **before** the cachable memory will be read by
  482. * not cache coherent hardware.
  483. *
  484. * D-cache clean will operate by cache line. So, is the memory range is
  485. * not cache line aligned, other memory on the cache line will be cleaned
  486. * also. For example, assuming D-cache line size is 32 byte,
  487. * \p osiDCacheClean((void *)8, 32) will clean [0-8], [40-64] also.
  488. *
  489. * When D-cache coherence is needed to be considered, it is recommended to
  490. * declare or allocate memory by the following:
  491. *
  492. * \code{.cpp}
  493. * char mem1[SIZE] OSI_CACHE_LINE_ALIGNED;
  494. * void *mem2 = memalign(CONFIG_CACHE_LINE_SIZE, size);
  495. * \endcode
  496. *
  497. * \param address starting address to be cleaned
  498. * \param size size to be cleaned
  499. */
  500. void osiDCacheClean(const void *address, size_t size);
  501. /**
  502. * invalidate D-cache
  503. *
  504. * Usually it shall be called **before** the cachable memory will be write by
  505. * not cache coherent hardware.
  506. *
  507. * D-cache line alignment is very important for \p osiDCacheInvalidate.
  508. * Otherwise, other memory on the cache line will be changed randomly.
  509. *
  510. * \param address starting address to be cleaned
  511. * \param size size to be cleaned
  512. */
  513. void osiDCacheInvalidate(const void *address, size_t size);
  514. /**
  515. * clean and invalidate D-cache
  516. *
  517. * \param address starting address to be cleaned
  518. * \param size size to be cleaned
  519. */
  520. void osiDCacheCleanInvalidate(const void *address, size_t size);
  521. /**
  522. * invalidate D-cache range
  523. *
  524. * \param address starting address to be cleaned
  525. * \param size size to be cleaned
  526. */
  527. void osiICacheInvalidate(const void *address, size_t size);
  528. /**
  529. * sync D-cahce with I-cache
  530. *
  531. * It shall be called after code memory is operated as data (such as,
  532. * copy codes from flash to RAM).
  533. *
  534. * \param address starting address to be cleaned
  535. * \param size size to be cleaned
  536. */
  537. void osiICacheSync(const void *address, size_t size);
  538. /**
  539. * clean all D-cache
  540. */
  541. void osiDCacheCleanAll(void);
  542. /**
  543. * invalidate all D-cache
  544. */
  545. void osiDCacheInvalidateAll(void);
  546. /**
  547. * clean and invalidate all D-cache
  548. */
  549. void osiDCacheCleanInvalidateAll(void);
  550. /**
  551. * invalidate all I-cache
  552. */
  553. void osiICacheInvalidateAll(void);
  554. /**
  555. * sync D-cahce with I-cache for all
  556. */
  557. void osiICacheSyncAll(void);
  558. /**
  559. * create a thread
  560. *
  561. * Each \p osiThread_t will have an event queue. So, the event queue
  562. * depth should be specified at creation.
  563. *
  564. * \p name will be copied to thread control block. So, \p name can be dynamic
  565. * memory.
  566. *
  567. * After a thread is created, it will be executed immediately. So, it is
  568. * possible that \p entry will be executed before the return value is
  569. * assigned to some variable, if the new thread priority is higher than
  570. * current thread priority. Pay attention to use thread pointer in
  571. * \p entry.
  572. *
  573. * \code{.cpp}
  574. * void entry(void *argument) {
  575. * osiThread_t *thread = osiThreadCurrent();
  576. * for (;;) {
  577. * osiEvent_t event = {};
  578. * osiEventWait(thread, &event);
  579. * ......
  580. * }
  581. * }
  582. * \endcode
  583. *
  584. * In some underlay RTOS, there are limitation on maximum stack size.
  585. * For example, when \p configSTACK_DEPTH_TYPE is defined as \p uint16_t,
  586. * the stack size must be less than 64KB*4.
  587. *
  588. * \param name thread name
  589. * \param entry thread entry function
  590. * \param argument thread entry function argument
  591. * \param priority thread priority
  592. * \param stack_size thread stack size in byte
  593. * \param event_count thread event queue depth (count of events can be hold)
  594. * \return
  595. * - thread pointer
  596. * - NULL if failed
  597. */
  598. osiThread_t *osiThreadCreate(const char *name, osiThreadEntry_t entry, void *argument,
  599. uint32_t priority, uint32_t stack_size,
  600. uint32_t event_count);
  601. /*+\new\rww\2020.4.14\添加线程创建接口*/
  602. osiThread_t *osiThreadCreateNotSuspendScheduler(const char *name, osiCallback_t func, void *argument,
  603. uint32_t priority, uint32_t stack_size,
  604. uint32_t event_count);
  605. /*-\new\rww\2020.4.14\添加线程创建接口*/
  606. /**
  607. * create a thread with specified stack
  608. *
  609. * It is similar to \p osiThreadCreate, and the stack won't be dynamic created.
  610. * Rather, the specified buffer \p stack will be used at the stack of the
  611. * thread. Typical usage is to create performance sensitive thread, and set stack
  612. * in SRAM to improve performance.
  613. *
  614. * Application should always use \p osiThreadCreate. It may be unimplemented on
  615. * some platforms.
  616. *
  617. * \param name thread name
  618. * \param entry thread entry function
  619. * \param argument thread entry function argument
  620. * \param priority thread priority
  621. * \param stack thread stack buffer, must be valid
  622. * \param stack_size thread stack size in byte
  623. * \param event_count thread event queue depth (count of events can be hold)
  624. * \return
  625. * - thread pointer
  626. * - NULL if failed
  627. */
  628. osiThread_t *osiThreadCreateWithStack(const char *name, osiThreadEntry_t entry, void *argument,
  629. uint32_t priority, void *stack, uint32_t stack_size,
  630. uint32_t event_count);
  631. /**
  632. * get event queue of thread
  633. *
  634. * When \p thread is NULL, return the event queue of current thread.
  635. *
  636. * \param thread thread pointer
  637. * \return event queue of the thread
  638. */
  639. osiEventQueue_t *osiThreadEventQueue(osiThread_t *thread);
  640. /**
  641. * get current thread pointer
  642. *
  643. * \return current thread pointer
  644. */
  645. osiThread_t *osiThreadCurrent(void);
  646. /**
  647. * set whether current thread need FPU
  648. *
  649. * By default, FPU isn't permitted for new created thread. To enable FPU,
  650. * \p osiThreadSetFPUEnabled(true) should be called before floating point
  651. * instructions.
  652. *
  653. * Though it is possible to call \p osiThreadSetFPUEnabled(false) if it is
  654. * known that floating point instructions won't be used any more, it is not
  655. * necessary. It will only increase a little context save and restore cycles.
  656. * Typical usage it to call \p osiThreadSetFPUEnabled(true) at the beginning
  657. * of thread entry.
  658. *
  659. * It is undefined if thread uses floating point instructions whthout call
  660. * of \p osiThreadSetFPUEnabled(true).
  661. *
  662. * \param enabled true for enable FPU, false for disable FPU.
  663. */
  664. void osiThreadSetFPUEnabled(bool enabled);
  665. /**
  666. * get thread priority
  667. *
  668. * When \p thread is NULL, return the priotity of current thread.
  669. *
  670. * \param thread thread pointer
  671. * \return priotity of the thread
  672. */
  673. uint32_t osiThreadPriority(osiThread_t *thread);
  674. /**
  675. * set thread priority
  676. *
  677. * When \p thread is NULL, set the priotity of current thread.
  678. *
  679. * After the priority changed, it is possible thread context switch
  680. * will occur. However, don't depend on this feature.
  681. *
  682. * \param thread thread pointer
  683. * \param priority priority to be set
  684. * \return
  685. * - true on success
  686. * - false on invalid parameter
  687. */
  688. bool osiThreadSetPriority(osiThread_t *thread, uint32_t priority);
  689. /**
  690. * suspend a thread
  691. *
  692. * When \p thread is NULL, suspend current thread.
  693. *
  694. * \param thread thread pointer
  695. */
  696. void osiThreadSuspend(osiThread_t *thread);
  697. /**
  698. * resume a thread
  699. *
  700. * \p thread can't be NULL.
  701. *
  702. * \param thread thread pointer
  703. */
  704. void osiThreadResume(osiThread_t *thread);
  705. /**
  706. * current thread yield
  707. *
  708. * When there are threads with the same priority, other threads will
  709. * be scheduled.
  710. */
  711. void osiThreadYield(void);
  712. /**
  713. * current thread sleep
  714. *
  715. * Change current thread into sleep mode, and will be rescheduled
  716. * after the specified period.
  717. *
  718. * This will use the underlay RTOS mechanism. It is possible the sleep
  719. * time precision is the tick of underlay RTOS.
  720. *
  721. * \param ms sleep time in milliseconds
  722. */
  723. void osiThreadSleep(uint32_t ms);
  724. /**
  725. * current thread sleep with relaxed timeout
  726. *
  727. * It is a power optimization version of \p osiThreadSleep. Due to power
  728. * saving, it is possible that current thread will be wakeup later then
  729. * *normal timeout*, but it will wakeup no later than *relaxed timeout*
  730. * even system will enter suspend.
  731. *
  732. * When \p relax_ms is \p OSI_DELAY_MAX, it means it can be ignored
  733. * completed for power saving. However, after system is awoken, the thread
  734. * will be wakeup still if the *normal timeout* is expired.
  735. *
  736. * \param ms sleep time in milliseconds
  737. * \param relax_ms relaxed sleep time in milliseconds
  738. */
  739. void osiThreadSleepRelaxed(uint32_t ms, uint32_t relax_ms);
  740. /**
  741. * thread stack unused space
  742. *
  743. * It needs underlay RTOS support. When the underlay RTOS doesn't support
  744. * this feature, it returns 0.
  745. *
  746. * The typical method to support this feature in underlay RTOS is to check
  747. * stack content, and comparing with preset magic byte or word.
  748. *
  749. * It is recommended to use it only for debug.
  750. *
  751. * \param thread thread pointer, NULL for current thread
  752. * \return
  753. * - thread stack unused space in bytes
  754. * - 0 if the underlay RTOS doesn't support this feature
  755. */
  756. uint32_t osiThreadStackUnused(osiThread_t *thread);
  757. /**
  758. * space from current stack pointer to current thread stack end
  759. *
  760. * When \p refill is true, the current stack space will be fill with magic
  761. * byte or word for measuring unused stack. When underlay RTOS doesn't
  762. * support feature to measure stack remain, \p refill will be ignored.
  763. *
  764. * It is recommended to use it only for debug.
  765. *
  766. * \return
  767. * - space to current thread stack end, in bytes
  768. */
  769. uint32_t osiThreadStackCurrentSpace(bool refill);
  770. /**
  771. * current thread exit
  772. *
  773. * When a thread is finished, \p osiThreadExit must be called. And
  774. * kernel will release thread resources at appropriate time.
  775. */
  776. OSI_NO_RETURN void osiThreadExit(void);
  777. /**
  778. * show thread information through trace
  779. *
  780. * It is for debug purpose only.
  781. */
  782. void osiShowThreadState(void);
  783. /**
  784. * send an event to a thread
  785. *
  786. * At send, the body of \p event will be copied to event queue
  787. * rather then send the pointer of \p event.
  788. *
  789. * When event queue of the target thread is full, the caller thread
  790. * will be block until there are rooms in target thread event queue.
  791. *
  792. * \param thread thread pointer, can't be NULL
  793. * \param event event to be sent
  794. * \return
  795. * - true on success
  796. * - false on invalid parameter
  797. */
  798. bool osiEventSend(osiThread_t *thread, const osiEvent_t *event);
  799. /**
  800. * send event loop quit event to a thread
  801. *
  802. * This is the normalized method to notify a thread to quit. When \p thread
  803. * is the current thread, \p wait can't be true.
  804. *
  805. * \code{.cpp}
  806. * // caller thread
  807. * osiSendQuitEvent(thread);
  808. *
  809. * // thread to quit
  810. * for (;;) {
  811. * osiEvent_t event = {};
  812. * osiEventWait(thread, &event);
  813. * if (event.id == OSI_EVENT_ID_QUIT)
  814. * break;
  815. *
  816. * // ......
  817. * }
  818. * osiThreadExit();
  819. * \endcode
  820. *
  821. * \param thread thread pointer, can't be NULL
  822. * \param wait whether to wait thread exit
  823. * \return
  824. * - true on success
  825. * - false on invalid parameter
  826. */
  827. bool osiSendQuitEvent(osiThread_t *thread, bool wait);
  828. /**
  829. * send an event to a thread with timeout
  830. *
  831. * When \p timeout is 0, this will return false immediately. When \p timeout
  832. * is \p OSI_WAIT_FOREVER, this will wait forever until there are
  833. * rooms in target thread event queue.
  834. *
  835. * This can be called in ISR. And in ISR, \p timeout must be 0.
  836. *
  837. * \param thread thread pointer, can't be NULL
  838. * \param event event to be sent
  839. * \param timeout timeout in milliseconds
  840. * \return
  841. * - true on success
  842. * - false on invalid parameter, or timeout
  843. */
  844. bool osiEventTrySend(osiThread_t *thread, const osiEvent_t *event, uint32_t timeout);
  845. /**
  846. * wait an event
  847. *
  848. * Wait an event from current thread event queue. When current thread
  849. * event queue is empty, it will be blocked forever until there are
  850. * event in event queue.
  851. *
  852. * The event body will be copied to \p event.
  853. *
  854. * There are some event ID used by system. After system event is received
  855. * and process, this will return an event with ID of 0. Application can
  856. * ignore event ID 0 safely.
  857. *
  858. * \param thread thread pointer, can't be NULL
  859. * \param event event pointer
  860. * \return
  861. * - true on success
  862. * - false on invalid parameter
  863. */
  864. bool osiEventWait(osiThread_t *thread, osiEvent_t *event);
  865. /**
  866. * wait an event with timeout
  867. *
  868. * When \p timeout is 0, this will return false immediately. When \p timeout
  869. * is \p OSI_WAIT_FOREVER, this will wait forever until there are
  870. * events in target thread event queue.
  871. *
  872. * \param thread thread pointer, can't be NULL
  873. * \param event event pointer
  874. * \param timeout timeout in milliseconds
  875. * \return
  876. * - true on success
  877. * - false on invalid parameter, or timeout
  878. */
  879. bool osiEventTryWait(osiThread_t *thread, osiEvent_t *event, uint32_t timeout);
  880. /**
  881. * whether there are pending event in event queue
  882. *
  883. * \param thread thread pointer, can't be NULL
  884. * \return
  885. * - true if there are pending event
  886. * - false if not
  887. */
  888. bool osiEventPending(osiThread_t *thread);
  889. /**
  890. * set callback to be executed on thread
  891. *
  892. * Thread callback is implemented by \p osiEvent_t.
  893. *
  894. * This can be called in ISR. In ISR, the callback event will be lost when
  895. * the event queue of target thread is full.
  896. *
  897. * \param thread thread pointer, can't be NULL
  898. * \param cb callback to be executed
  899. * \param cb_ctx callback context
  900. * \return
  901. * - true on success
  902. * - false on invalid parameter, or event queue is full in ISR
  903. */
  904. bool osiThreadCallback(osiThread_t *thread, osiCallback_t cb, void *cb_ctx);
  905. /**
  906. * \brief create a work
  907. *
  908. * \p run can't be NULL, and \p complete can be NULL.
  909. *
  910. * \param run execute function of the work
  911. * \param complete callback to be invoked after the work is finished
  912. * \param ctx context of \p run and \p complete
  913. * \return
  914. * - the created work
  915. * - NULL if invalid parameter or out of memory
  916. */
  917. osiWork_t *osiWorkCreate(osiCallback_t run, osiCallback_t complete, void *ctx);
  918. /**
  919. * \brief delete the work
  920. *
  921. * When \p work is running when it is called, it will be deleted after the
  922. * current run finished.
  923. *
  924. * \param work the work to be deleted
  925. */
  926. void osiWorkDelete(osiWork_t *work);
  927. /**
  928. * \brief enqueue a work in specified work queue
  929. *
  930. * When \p work is running, it will be queued to \wq again and then it
  931. * will be invoked again.
  932. *
  933. * When \p work is queued, and \p wq is the same as original work queue,
  934. * nothing will be done. When \p wq is not the same as the original
  935. * work queue, it will be removed from the original work queue, and
  936. * queue the work into the specified work queue.
  937. *
  938. * This can be called in ISR.
  939. *
  940. * \param work the work pointer, must be valid
  941. * \param wq work queue to run the work, must be valid
  942. * \return
  943. * - true on success
  944. * - false for invalid parameter, or work is running
  945. */
  946. bool osiWorkEnqueue(osiWork_t *work, osiWorkQueue_t *wq);
  947. /**
  948. * \brief enqueue a work in the last of specified work queue
  949. *
  950. * It is similar to \p osiWorkEnqueue, except it will consider work order.
  951. * For example:
  952. *
  953. * \code{.cpp}
  954. * osiWorkEnqueue(work1, wq);
  955. * osiWorkEnqueue(work2, wq);
  956. * osiWorkEnqueue(work1, wq);
  957. * \encode
  958. *
  959. * If work queue is busy on another work during these calls, and when work
  960. * queue processing these works, it will:
  961. * - execute work1->callback
  962. * - execute work2->callback
  963. *
  964. * So, even the order of works aren't preserved. \p work1 is the last queued
  965. * work, and the real last executed work is \p work2.
  966. *
  967. * With \p osiWorkEnqueueLast, it will ensure that the last queued work will
  968. * be executed at the last.
  969. *
  970. * \param work the work pointer, must be valid
  971. * \param wq work queue to run the work, must be valid
  972. * \return
  973. * - true on success
  974. * - false for invalid parameter, or work is running
  975. */
  976. bool osiWorkEnqueueLast(osiWork_t *work, osiWorkQueue_t *wq);
  977. /**
  978. * \brief cancel a work
  979. *
  980. * When \p work is running, the current execution won't be interrupted.
  981. *
  982. * \param work the work pointer, must be valid
  983. */
  984. void osiWorkCancel(osiWork_t *work);
  985. /**
  986. * \brief wait a work finish
  987. *
  988. * When \p work is running or enqued, this will wait the work finish.
  989. * When \p timeout is 0, it will return immediately. When \p timeout
  990. * is \p OSI_WAIT_FOREVER, it will wait infinitely until the work is
  991. * finished.
  992. *
  993. * \param work the work pointer, must be valid
  994. * \param timeout wait timeout
  995. * \return
  996. * - true if the work is finished
  997. * - false on invalid parameter, or wait timeout
  998. */
  999. bool osiWorkWaitFinish(osiWork_t *work, unsigned timeout);
  1000. /**
  1001. * \brief create work queue
  1002. *
  1003. * Multiple threads can be created to reduce work execution latency. For
  1004. * example, when one thread in a work queue is blocked, other threads of
  1005. * the work queue can execute other works queued to the work queue.
  1006. *
  1007. * The maximum thread count is implementation dependent. So, it is possible
  1008. * that the created thread count is less than \p thread_count. And also it is
  1009. * possible that \p thread_count is ignored.
  1010. *
  1011. * The created threads have the same priority and stack size.
  1012. *
  1013. * The work queue thread entry function can't be customized
  1014. *
  1015. * \param name work queue name
  1016. * \param thread_count thread count to be created for the work queue
  1017. * \param priority work queue thread priority
  1018. * \param stack_size thread stack size in byte
  1019. * \return
  1020. * - the work queue pointer
  1021. * - NULL if failed
  1022. */
  1023. osiWorkQueue_t *osiWorkQueueCreate(const char *name, size_t thread_count, uint32_t priority, uint32_t stack_size);
  1024. /**
  1025. * \brief delete work queue
  1026. *
  1027. * All resources of the work queue will be deleted.
  1028. *
  1029. * The works in running will continue, and \p complete will be invoked as
  1030. * normal. However, queued work in the work queue won't be executed any more.
  1031. *
  1032. * \param wq work queue to be deleted
  1033. */
  1034. void osiWorkQueueDelete(osiWorkQueue_t *wq);
  1035. /**
  1036. * \brief get the system high priority work queue
  1037. *
  1038. * A work queue with priority \p OSI_PRIORITY_HIGH will be created at kernel
  1039. * start.
  1040. *
  1041. * \return the system high priority work queue
  1042. */
  1043. osiWorkQueue_t *osiSysWorkQueueHighPriority(void);
  1044. /**
  1045. * \brief get the system low priority work queue
  1046. *
  1047. * A work queue with priority \p OSI_PRIORITY_LOW will be created at kernel
  1048. * start.
  1049. *
  1050. * \return the system low priority work queue
  1051. */
  1052. osiWorkQueue_t *osiSysWorkQueueLowPriority(void);
  1053. /**
  1054. * \brief get the system work queue for asynchronuous file system write
  1055. *
  1056. * A work queue with priority \p OSI_PRIORITY_BELOW_NORMAL will be created
  1057. * at kernel start. This work queue shall be used for asynchronuous file
  1058. * system write.
  1059. *
  1060. * Usually file write is slow, especially for file system on NOR flash.
  1061. * When faster response is needed, file write can be deferred to this
  1062. * work queue. Also, the work queue will be flushed before system shutdown.
  1063. *
  1064. * \return the system file write work queue
  1065. */
  1066. osiWorkQueue_t *osiSysWorkQueueFileWrite(void);
  1067. /**
  1068. * \brief create a thread notify
  1069. *
  1070. * Thread notify is thread callback with state to avoid duplicated event
  1071. * to be sent to thread event queue.
  1072. *
  1073. * \param thread thread to execute the callback, can't be NULL
  1074. * \param cb callback to be executed, can't be NULL
  1075. * \param ctx callback context
  1076. * \return
  1077. * - created notify
  1078. * - NULL if parameters are invalid or out of memory
  1079. */
  1080. osiNotify_t *osiNotifyCreate(osiThread_t *thread, osiCallback_t cb, void *ctx);
  1081. /**
  1082. * \brief delete a thread notify
  1083. *
  1084. * The memory of the thread notify will be released.
  1085. *
  1086. * When the thread notify is already in thread event queue, the callback
  1087. * won't be invoked, and the memory may be released delayed.
  1088. *
  1089. * \param notify thread notify pointer, must be valid
  1090. */
  1091. void osiNotifyDelete(osiNotify_t *notify);
  1092. /**
  1093. * \brief trigger a thread notify
  1094. *
  1095. * When the thread notify event isn't in thread event queue, an event for
  1096. * thread notify will be queued to the tail of thread event queue.
  1097. *
  1098. * \param notify thread notify pointer, must be valid
  1099. */
  1100. void osiNotifyTrigger(osiNotify_t *notify);
  1101. /**
  1102. * \brief cancel a thread notify
  1103. *
  1104. * When the thread notify event has already sent to thread event queue,
  1105. * the invocation of the callback will be cancelled.
  1106. *
  1107. * \param notify thread notify pointer, must be valid
  1108. */
  1109. void osiNotifyCancel(osiNotify_t *notify);
  1110. /**
  1111. * \brief create a timer
  1112. *
  1113. * Create a timer with specified callback and callback context. After create,
  1114. * the timer is in stop state. Application can start it in various mode.
  1115. *
  1116. * When \p thread is \p OSI_TIMER_IN_ISR, the callback will be executed in
  1117. * timer ISR. So, the callback should follow ISR programming guide. This is
  1118. * **not** recommended unless it is absolutely needed.
  1119. *
  1120. * When \p thread is \p OSI_TIMER_IN_SERVICE, the callback will be executed
  1121. * in timer service thread.
  1122. *
  1123. * Otherwise, the callback will be executed in the specified thread through
  1124. * *event* mechanism.
  1125. *
  1126. * It is needed to call \p osiTimerDelete to free resources.
  1127. *
  1128. * \param thread thread to execute the callback
  1129. * \param cb callback to be executed after timer expire
  1130. * \param ctx callback context
  1131. * \return
  1132. * - the created timer instance
  1133. * - NULL at out of memory, or invalid parameter
  1134. */
  1135. osiTimer_t *osiTimerCreate(osiThread_t *thread, osiCallback_t cb, void *ctx);
  1136. /**
  1137. * \brief create a timer, enqueue a work on expiration
  1138. *
  1139. * Create a timer with specified callback and callback context. After create,
  1140. * the timer is in stop state. Application can start it in various mode.
  1141. *
  1142. * At expiration, \p work will be enqueued to \p wq.
  1143. *
  1144. * It is needed to call \p osiTimerDelete to free resources.
  1145. *
  1146. * \param work work to be enqueued at expiration
  1147. * \param wq work queue to be enqueued at expiration
  1148. * \return
  1149. * - the created timer instance
  1150. * - NULL at out of memory, or invalid parameter
  1151. */
  1152. osiTimer_t *osiTimerCreateWork(osiWork_t *work, osiWorkQueue_t *wq);
  1153. /**
  1154. * \brief create a timer, EV_TIMER on expiration
  1155. *
  1156. * This is for legacy codes only. **Don't** use it except at porting
  1157. * legacy codes.
  1158. *
  1159. * Create a timer with specified timerid. After the timer expired, the
  1160. * specified thread will receive an event { EV_TIMER, timerid, 0, 0}.
  1161. *
  1162. * It is needed to call \p osiTimerDelete to free resources.
  1163. *
  1164. * \param thread thread to execute the callback, it can't be NULL
  1165. * \param timerid timerid in expiration event
  1166. * \return
  1167. * - the created timer instance
  1168. * - NULL at out of memory, or invalid parameter
  1169. */
  1170. osiTimer_t *osiTimerEventCreate(osiThread_t *thread, uint32_t timerid);
  1171. /**
  1172. * \brief set/change callback of timer
  1173. *
  1174. * In most cases, timer callback set at create is not needed to be changed.
  1175. *
  1176. * \p timer should be created by \p osiTimerCreate. Special values of
  1177. * \p thread follow \p osiTimerCreate.
  1178. *
  1179. * It is permitted to change \p thread of timer, including special values.
  1180. * For example, it is permitted to change a timer executing in timer service
  1181. * to timer executing in specified thread. However, it is not recommended.
  1182. *
  1183. * This can only be called when \p timer is stopped. Otherwise, it will
  1184. * return false.
  1185. *
  1186. * \param timer timer to be changed
  1187. * \param thread thread to execute the callback
  1188. * \param cb callback to be executed after timer expire
  1189. * \param ctx callback context
  1190. * \return
  1191. * - true on success
  1192. * - false on invalid parameter
  1193. */
  1194. bool osiTimerSetCallback(osiTimer_t *timer, osiThread_t *thread, osiCallback_t cb, void *ctx);
  1195. /**
  1196. * \brief set/change work and work queue of timer
  1197. *
  1198. * In most cases, timer work and work queue set at create is not needed to be changed.
  1199. *
  1200. * \p timer should be created by \p osiTimerCreateWork, to enqueue work to work
  1201. * queue at expiration.
  1202. *
  1203. * \param timer timer to be changed
  1204. * \param work work to be enqueued at expiration
  1205. * \param wq work queue to be enqueued at expiration
  1206. * \return
  1207. * - true on success
  1208. * - false on invalid parameter
  1209. */
  1210. bool osiTimerSetWork(osiTimer_t *timer, osiWork_t *work, osiWorkQueue_t *wq);
  1211. /**
  1212. * \brief set/change timer event
  1213. *
  1214. * In most cases, timer thread and id set at create is not needed to be changed.
  1215. *
  1216. * \p timer should be created by \p osiTimerEventCreate.
  1217. *
  1218. * \param thread thread to execute the callback, it can't be NULL
  1219. * \param timerid timerid in expiration event
  1220. * \return
  1221. * - true on success
  1222. * - false on invalid parameter
  1223. */
  1224. bool osiTimerSetEvent(osiTimer_t *timer, osiThread_t *thread, uint32_t timerid);
  1225. /**
  1226. * \brief delete a timer
  1227. *
  1228. * Delete the timer, and free associated resources.
  1229. *
  1230. * When the timer callback will be executed in thread rather than ISR, and the
  1231. * event for timer expiration has been sent, some resources won't be freed
  1232. * immediately. Rather, they will be freed after the timer expiration event
  1233. * is popped out from thread event queue. However, the callback won't be
  1234. * executed even delete is delayed.
  1235. *
  1236. * Refer to document about corner case of timer thread callback.
  1237. *
  1238. * \param timer the timer to be deleted
  1239. */
  1240. void osiTimerDelete(osiTimer_t *timer);
  1241. /**
  1242. * \brief change timer relaxed timeout for running timer
  1243. *
  1244. * When the timer is not running, it will return false.
  1245. *
  1246. * When the timer is started, this will change the relaxed timeout
  1247. * specified at start.
  1248. *
  1249. * This can be called for both one shot timer and periodic timer.
  1250. *
  1251. * \p relaxed_ms is the additional time based on normal timeout. It will
  1252. * only be used for sleep. When \p relaxed_ms is 0, this timer will wakeup
  1253. * system even system enter sleep mode. When \p relaxed_ms is
  1254. * \p OSI_DELAY_MAX, this timer will not wakeup system when system enter
  1255. * sleep mode. Otherwise, system will process the timer no later than the
  1256. * normal timeout plus additional timeout.
  1257. *
  1258. * For example, when the period of a timer is 100ms, and relaxed timeout
  1259. * is 500ms, system will process the timer no later than 600ms. This can
  1260. * make system sleep more time, and reduce power consumption.
  1261. *
  1262. * For periodic timer, the additional timeout is add to normal timeout of
  1263. * earch run. For example, a periodic timer period is 100ms, and relaxed
  1264. * timeout is 50ms, then system will process the timer no later than 150ms.
  1265. * And even the timer is delayed to 150ms due to system sleep, the next
  1266. * timeout is 200ms unchanged. Another example, a periodic timer period
  1267. * is 100ms, and relaxed timeout is 500ms, then system will process the
  1268. * timer no later than 600ms. When the timer is delayed to 600ms due to
  1269. * system sleep, the callback will be invoked only once even 6 periods are
  1270. * elapsed. The next timeout is at 700ms.
  1271. *
  1272. * \param timer the timer to be set
  1273. * \param relaxed_ms relaxed timeout in milliseconds
  1274. * \return
  1275. * - true on success
  1276. * - false on invalid parameter, or timer is not running
  1277. */
  1278. bool osiTimerChangeRelaxed(osiTimer_t *timer, uint32_t relaxed_ms);
  1279. /**
  1280. * \brief set timer period for next call
  1281. *
  1282. * The properties will be used by next \p osiTimerStartLast. It can only be
  1283. * called when the timer is not running.
  1284. *
  1285. * It is the same as \p osiTimerSetPeriodRelaxed, with \p relaxed_ms
  1286. * as 0.
  1287. *
  1288. * \param timer the timer to be set
  1289. * \param ms period in milliseconds
  1290. * \param periodic true for periodic, false for one shot
  1291. * \return
  1292. * - true on success
  1293. * - false on invalid parameter, or timer is started
  1294. */
  1295. bool osiTimerSetPeriod(osiTimer_t *timer, uint32_t ms, bool periodic);
  1296. /**
  1297. * \brief set timer period for next call, with relaxed timeout
  1298. *
  1299. * The properties will be used by next \p osiTimerStartLast. It can only be
  1300. * called when the timer is not running.
  1301. *
  1302. * \param timer the timer to be set
  1303. * \param ms period in milliseconds
  1304. * \param relaxed relaxed timeout in milliseconds
  1305. * \param periodic true for periodic, false for one shot
  1306. * \return
  1307. * - true on success
  1308. * - false on invalid parameter
  1309. */
  1310. bool osiTimerSetPeriodRelaxed(osiTimer_t *timer, uint32_t ms, uint32_t relaxed_ms, bool periodic);
  1311. /**
  1312. * \brief whether timer is started
  1313. *
  1314. * \param timer the timer to be set
  1315. * \return
  1316. * - true if the timer is started
  1317. * - false if not started, or invalid parameter
  1318. */
  1319. bool osiTimerIsRunning(osiTimer_t *timer);
  1320. /**
  1321. * \brief get remaining time of timer in milliseconds
  1322. *
  1323. * Even the timer is already timed out, it will return 0 rather then negative
  1324. * value. For example, thread callback timer is already timed out, but the
  1325. * callback hasn't invoked in the specified thread.
  1326. *
  1327. * \param timer the timer to be set
  1328. * \return
  1329. * - remaining time
  1330. * - timer is not started, or invalid parameter
  1331. */
  1332. int64_t osiTimerRemaining(osiTimer_t *timer);
  1333. /**
  1334. * \brief timer expiration time in milliseconds
  1335. *
  1336. * The expiration time is in the same coordinate of \p osiUpTime.
  1337. *
  1338. * When the timer is not running, it will return -1. For already timeed out
  1339. * timer, the return value may be smaller than \p osiUpTime.
  1340. *
  1341. * \param timer the timer to be checked
  1342. * \return
  1343. * - expiration time
  1344. * - -1 if the timer is not running
  1345. */
  1346. int64_t osiTimerExpiration(osiTimer_t *timer);
  1347. /**
  1348. * \brief start a timer with last period
  1349. *
  1350. * The last period is the period set by \p osiTimerSetPeriod, or other start
  1351. * APIs with period parameter.
  1352. *
  1353. * It is recommended that not to mixing start API with period parameter, and
  1354. * start API without period parameter. Though the behavior is determinstic,
  1355. * it is harder to be understood.
  1356. *
  1357. * \param timer the timer to be started
  1358. * \return
  1359. * - true on success
  1360. * - false on invalid parameter
  1361. */
  1362. bool osiTimerStartLast(osiTimer_t *timer);
  1363. /**
  1364. * \brief start a timer
  1365. *
  1366. * Start a timer, and the timer will be expired in specified period from
  1367. * now. After the callback is executed, the timer will come to stopped state
  1368. * automatically.
  1369. *
  1370. * When the timer is in stated state before this function, the previous
  1371. * expiration won't be executed.
  1372. *
  1373. * Refer to document about corner case of timer thread callback.
  1374. *
  1375. * It is valid that the timeout period is 0. In this case, the timer will
  1376. * expire very soon.
  1377. *
  1378. * Due to timeout is 32bits of milliseconds, The maximum timeout period is
  1379. * ~50 days.
  1380. *
  1381. * It is the same as \p osiTimerStartRelaxed, with \p relaxed_ms is 0.
  1382. *
  1383. * \param timer the timer to be started
  1384. * \param ms timeout period
  1385. * \return
  1386. * - true on success
  1387. * - false on invalid parameter
  1388. */
  1389. bool osiTimerStart(osiTimer_t *timer, uint32_t ms);
  1390. /**
  1391. * \brief start a timer with relaxed timeout
  1392. *
  1393. * It is a power optimization version of \p osiTimerStart.
  1394. *
  1395. * Refer to \p osiTimerChangeRelaxed for explaination of \p relaxed_ms.
  1396. *
  1397. * \param timer the timer to be started
  1398. * \param ms normal timeout period
  1399. * \param relax_ms relaxed timeout period
  1400. * \return
  1401. * - true on success
  1402. * - false on invalid parameter
  1403. */
  1404. bool osiTimerStartRelaxed(osiTimer_t *timer, uint32_t ms, uint32_t relax_ms);
  1405. /**
  1406. * \brief start a timer with relaxed timeout, in unit of hardware tick
  1407. *
  1408. * **Don't** call this in application code. It is only for legacy codes.
  1409. *
  1410. * The frequency of hardware tick is chip dependent, and implementation dependent.
  1411. *
  1412. * \param timer the timer to be started
  1413. * \param ticks normal timeout period in hardware tick
  1414. * \param relax_ticks relaxed timeout period in hardware tick
  1415. * \return
  1416. * - true on success
  1417. * - false on invalid parameter
  1418. */
  1419. bool osiTimerStartHWTickRelaxed(osiTimer_t *timer, uint32_t ticks, uint32_t relax_ticks);
  1420. /**
  1421. * \brief start a timer, timeout in unit of microseconds
  1422. *
  1423. * Timeout in microseconds can support higher precision. However, the maximum
  1424. * timeout is shorter, ~1.2 hours.
  1425. *
  1426. * The real precision depends on hardware.
  1427. * \param timer the timer to be started
  1428. * \param us timeout period in microseconds
  1429. * \return
  1430. * - true on success
  1431. * - false on invalid parameter
  1432. */
  1433. bool osiTimerStartMicrosecond(osiTimer_t *timer, uint32_t us);
  1434. /**
  1435. * \brief start a periodic timer
  1436. *
  1437. * Internally, the period may be aligned to hardware tick (larger than
  1438. * 16384Hz), there may exist accumulated error in long run. So, don't use
  1439. * periodic timer count for long time time, \p osiUpTime is a better choice.
  1440. *
  1441. * When the period of periodic timer is too small, it will have serious impact
  1442. * on system. Internally, the period taking effect will no less than
  1443. * \p CONFIG_KERNEL_PERIODIC_TIMER_MIN_PERIOD.
  1444. *
  1445. * It is the same as \p osiTimerStartPeriodicRelaxed, with \p relaxed_ms is 0.
  1446. *
  1447. * \param timer the timer to be started
  1448. * \param ms interval in microseconds
  1449. * \return
  1450. * - true on success
  1451. * - false on invalid parameter
  1452. */
  1453. bool osiTimerStartPeriodic(osiTimer_t *timer, uint32_t ms);
  1454. /**
  1455. * \brief start a periodic timer with relaxed timeout
  1456. *
  1457. * It is a power optimization version of \p osiTimerStartPeriodic.
  1458. *
  1459. * Refer to \p osiTimerChangeRelaxed for explaination of \p relaxed_ms.
  1460. *
  1461. * \param timer the timer to be started
  1462. * \param ms interval in microseconds
  1463. * \param relaxed_ms relaxed timeout period
  1464. * \return
  1465. * - true on success
  1466. * - false on invalid parameter
  1467. */
  1468. bool osiTimerStartPeriodicRelaxed(osiTimer_t *timer, uint32_t ms, uint32_t relaxed_ms);
  1469. /**
  1470. * \brief stop a time
  1471. *
  1472. * Stop a not-started or stopped timer is valid, just do nothing.
  1473. *
  1474. * Refer to document about corner case of timer thread callback.
  1475. *
  1476. * \param timer the timer to be stopped
  1477. * \return
  1478. * - true on success
  1479. * - false on invalid parameter
  1480. */
  1481. bool osiTimerStop(osiTimer_t *timer);
  1482. /**
  1483. * \brief tickless light sleep for timer
  1484. *
  1485. * When OS tick is implemented in timer, \p idle_tick is the maximum
  1486. * idle OS tick count (not hardware tick count) for sleep.
  1487. *
  1488. * The timer interrupt will be moved to minimum of:
  1489. * * OS timer, after \p idle_tick
  1490. * * other timers timeout time
  1491. *
  1492. * When there are no timers, timer interrupt will be disabled.
  1493. *
  1494. * The normal timeout time of timer, rather than the relaxed timeout
  1495. * time of timer, will be used.
  1496. *
  1497. * When the timer interrupt is moved, it will return true. In that case,
  1498. * the timer interrupt will be moved back after light sleep.
  1499. *
  1500. * \param idle_tick OS tick sleep count
  1501. * \return
  1502. * - true if timer interrupt is moved
  1503. * = false if timer interrupt is not moved
  1504. */
  1505. bool osiTimerLightSleep(uint32_t idle_tick);
  1506. /**
  1507. * \brief calculate the deep sleep time of all timers
  1508. *
  1509. * When OS tick is implemented in timer, \p idle_tick is the maximum
  1510. * idle OS tick count (not hardware tick count) for sleep.
  1511. *
  1512. * When there are timers which will wakeup system, the return value is
  1513. * the earliest timer wakeup time from now in milliseconds.
  1514. *
  1515. * When there are no timer will wakeup system, return \p INT64_MAX.
  1516. *
  1517. * The relaxed timeout time of timer, rather than the normal timeout
  1518. * time, is used in checking sleep time.
  1519. *
  1520. * Usually, it will be called by system sleep module. And it is not
  1521. * prohibited to be called in other cases.
  1522. *
  1523. * It **must** be called with interrupt disabled. The implementation
  1524. * won't perform protection.
  1525. *
  1526. * \param idle_tick OS tick sleep count
  1527. * \return
  1528. * - the earliest sleep timer from now in milliseconds.
  1529. * \p INT64_MAX for no need to wakeup.
  1530. */
  1531. int64_t osiTimerDeepSleepTime(uint32_t idle_tick);
  1532. /**
  1533. * \brief calculate the PSM wakup time of all timers
  1534. *
  1535. * When OS tick is implemented in timer, OS tick is not considered.
  1536. * That is, PSM wont't be waken by OS tick.
  1537. *
  1538. * The there are times which will wakeup system, the return value is
  1539. * the earliest timer wakeup time in milliseconds.
  1540. *
  1541. * When there are no timer will wakeup system, return \p INT64_MAX.
  1542. *
  1543. * The relaxed timeout time of timer, rather than the normal timeout
  1544. * time, is used in checking sleep time.
  1545. *
  1546. * It **must** be called with interrupt disabled. The implementation
  1547. * won't perform protection.
  1548. *
  1549. * \return
  1550. * - the earliest wakeup timer from now in milliseconds.
  1551. * \p INT64_MAX for no need to wakeup.
  1552. */
  1553. int64_t osiTimerPsmWakeUpTime(void);
  1554. /**
  1555. * \brief timer module processing after wakeup
  1556. *
  1557. * In case \p osiUpHWTick will be discontinued at sleep, it should be called
  1558. * after \p osiUpHWTick is stable.
  1559. *
  1560. * Usually, it will be called by system sleep module. And it is not
  1561. * prohibited to be called in other cases.
  1562. *
  1563. * It **must** be called with interrupt disabled. The implementation
  1564. * won't perform protection.
  1565. */
  1566. void osiTimerWakeupProcess(void);
  1567. /**
  1568. * \brief dump timer information to memory
  1569. *
  1570. * It is for debug only. The data format of timer information dump is
  1571. * not stable, and may change. When the provided memory size is not
  1572. * enough for all timers, some timers will be absent in dump.
  1573. *
  1574. * \param mem memory for timer information dump
  1575. * \param size provided memory size
  1576. * \return
  1577. * - dump memory size
  1578. */
  1579. int osiTimerDump(void *mem, unsigned size);
  1580. /**
  1581. * create a message queue
  1582. *
  1583. * \param msg_count maximum message count can be hold in queue
  1584. * \param msg_size size of each message in bytes
  1585. * \return
  1586. * - message queue pointer
  1587. * - NULL on invalid parameter or out of memory
  1588. */
  1589. osiMessageQueue_t *osiMessageQueueCreate(uint32_t msg_count, uint32_t msg_size);
  1590. /**
  1591. * delete a message queue
  1592. *
  1593. * When \p mq is NULL, nothing will be done, just as \p free.
  1594. *
  1595. * \param mq message queue pointer
  1596. */
  1597. void osiMessageQueueDelete(osiMessageQueue_t *mq);
  1598. /**
  1599. * put a message to message queue
  1600. *
  1601. * \p msg should hold content size the same as \p msg_size specified at
  1602. * \p osiMessageQueueCreate.
  1603. *
  1604. * After put, the content of \p msg will be copied to message queue.
  1605. *
  1606. * When \p mq is full, it will be blocked until there are rooms.
  1607. *
  1608. * \param mq message queue pointer
  1609. * \param msg mesage pointer
  1610. * \return
  1611. * - true on success
  1612. * - false on invalid parameter
  1613. */
  1614. bool osiMessageQueuePut(osiMessageQueue_t *mq, const void *msg);
  1615. /**
  1616. * put a message to message queue with timeout
  1617. *
  1618. * This can be called in ISR. And in ISR, \p timeout must be 0.
  1619. *
  1620. * \param mq message queue pointer
  1621. * \param msg mesage pointer
  1622. * \param timeout timeout in milliseconds
  1623. * \return
  1624. * - true on success
  1625. * - false on invalid parameter or timeout
  1626. */
  1627. bool osiMessageQueueTryPut(osiMessageQueue_t *mq, const void *msg, uint32_t timeout);
  1628. /**
  1629. * get a message to message queue
  1630. *
  1631. * \p msg should be able tp hold content size of \p msg_size specified at
  1632. * \p osiMessageQueueCreate.
  1633. *
  1634. * After get, the content of message will be copied to \p msg.
  1635. *
  1636. * When \p mq is empty, it will be blocked until there are messages.
  1637. *
  1638. * \param mq message queue pointer
  1639. * \param msg mesage pointer
  1640. * \return
  1641. * - true on success
  1642. * - false on invalid parameter
  1643. */
  1644. bool osiMessageQueueGet(osiMessageQueue_t *mq, void *msg);
  1645. /**
  1646. * get a message to message queue with timeout
  1647. *
  1648. * This can be called in ISR. And in ISR, \p timeout must be 0.
  1649. *
  1650. * \param mq message queue pointer
  1651. * \param msg mesage pointer
  1652. * \param timeout timeout in milliseconds
  1653. * \return
  1654. * - true on success
  1655. * - false on invalid parameter or timeout
  1656. */
  1657. bool osiMessageQueueTryGet(osiMessageQueue_t *mq, void *msg, uint32_t timeout);
  1658. /**
  1659. * create a semaphore
  1660. *
  1661. * When \p max_count is 1, it is a binary semaphore. Otherwise, it is
  1662. * counting semaphore.
  1663. *
  1664. * \param max_count maximum count of the semaphore
  1665. * \param init_count initial count of the semaphore
  1666. * \return
  1667. * - semaphore pointer
  1668. * - NULL on invalid parameter or out of memory
  1669. */
  1670. osiSemaphore_t *osiSemaphoreCreate(uint32_t max_count, uint32_t init_count);
  1671. /**
  1672. * delete the semaphore
  1673. *
  1674. * When there are blocked thread on the semaphore, the behavior is undefined
  1675. * for \p osiSemaphoreDelete.
  1676. *
  1677. * \param semaphore semaphore pointer
  1678. */
  1679. void osiSemaphoreDelete(osiSemaphore_t *semaphore);
  1680. /**
  1681. * acquire from semaphore
  1682. *
  1683. * After acquire, the count of semaphore will be decreased by 1.
  1684. *
  1685. * When the count of semaphore is 0, it will be blocked until the count
  1686. * becomes non-zero (increased by \p osiSemaphoreRelease).
  1687. *
  1688. * \param semaphore semaphore pointer
  1689. */
  1690. void osiSemaphoreAcquire(osiSemaphore_t *semaphore);
  1691. /**
  1692. * acquire from semaphore with timeout
  1693. *
  1694. * This can be called in ISR. And in ISR, \p timeout must be 0.
  1695. *
  1696. * \param semaphore semaphore pointer
  1697. * \param timeout timeout in milliseconds
  1698. * \return
  1699. * - true on success
  1700. * - false on timeout
  1701. */
  1702. bool osiSemaphoreTryAcquire(osiSemaphore_t *semaphore, uint32_t timeout);
  1703. /**
  1704. * release to semaphore
  1705. *
  1706. * After release, the count of semaphore will be increased by 1.
  1707. * When there are blocked thread on the semaphore, one of the blocked
  1708. * thread will be unblocked.
  1709. *
  1710. * This can be called in ISR.
  1711. *
  1712. * \param semaphore semaphore pointer
  1713. */
  1714. void osiSemaphoreRelease(osiSemaphore_t *semaphore);
  1715. /**
  1716. * create a mutex
  1717. *
  1718. * After creation, the mutex is in *open* state.
  1719. *
  1720. * \return
  1721. * - mutex pointer
  1722. * - NULL on out of memory
  1723. */
  1724. osiMutex_t *osiMutexCreate(void);
  1725. /**
  1726. * delete the mutex
  1727. *
  1728. * When \p mutex is NULL, nothing will be done, just as \p free.
  1729. *
  1730. * \param mutex mutex pointer to be deleted
  1731. */
  1732. void osiMutexDelete(osiMutex_t *mutex);
  1733. /**
  1734. * lock the mutex
  1735. *
  1736. * When \p mutex is locked by another thread, it will wait forever
  1737. * until the mutex is unlocked.
  1738. *
  1739. * \param mutex mutex pointer to be locked
  1740. */
  1741. void osiMutexLock(osiMutex_t *mutex);
  1742. /**
  1743. * lock the mutex with timeout
  1744. *
  1745. * \param mutex mutex pointer to be locked
  1746. * \param timeout timeout in milliseconds
  1747. * \return
  1748. * - true on success
  1749. * - false on timeout
  1750. */
  1751. bool osiMutexTryLock(osiMutex_t *mutex, uint32_t timeout);
  1752. /**
  1753. * unlock the mutex
  1754. *
  1755. * \param mutex mutex pointer to be unlocked
  1756. */
  1757. void osiMutexUnlock(osiMutex_t *mutex);
  1758. /**
  1759. * \brief monoclinic system time
  1760. *
  1761. * It is a relative time from system boot. Even after suspend and resume,
  1762. * the monoclinic system time will be contiguous.
  1763. *
  1764. * \return monoclinic system time in milliseconds
  1765. */
  1766. int64_t osiUpTime(void);
  1767. /**
  1768. * \brief monoclinic system time in microsecond
  1769. *
  1770. * The monoclinic system time in unit of microsecond.
  1771. *
  1772. * \return monoclinic system time in microseconds
  1773. */
  1774. int64_t osiUpTimeUS(void);
  1775. /**
  1776. * \brief set monoclinic system time
  1777. *
  1778. * When it is known that the hardware resource for monoclinic system time
  1779. * is discontinued, such as power off during deep sleep, this is called to
  1780. * set monoclinic system time.
  1781. *
  1782. * When up time is changed, epoch time and local time aren't be changed.
  1783. *
  1784. * It should only be called in system integration.
  1785. *
  1786. * \param ms target monoclinic system time in microseconds
  1787. */
  1788. void osiSetUpTime(int64_t ms);
  1789. /**
  1790. * \brief get the epoch time
  1791. *
  1792. * The time is millisecond (1/1000 second) from 1970-01-01 UTC. To avoid
  1793. * overflow, the data type is 64 bits.
  1794. *
  1795. * Epoch time is not monoclinic time. For example, when system time is
  1796. * synchronized with network, there may exist a jump (forward or backward)
  1797. * of epoch time.
  1798. *
  1799. * In 2 cases, this system time may be not reliable:
  1800. * - During boot, and before RTC is initialized.
  1801. * - During wakeup, and the elapsed sleep time hasn't compensated.
  1802. *
  1803. * \return epoch time in milliseconds
  1804. */
  1805. int64_t osiEpochTime(void);
  1806. /**
  1807. * \brief get the epoch time in second
  1808. *
  1809. * The time is seconds from 1970-01-01 UTC. To avoid overflow, the data
  1810. * type is 64 bits.
  1811. * - signed 32bits will overflow at year 2038
  1812. * - unsigned 32bits will overflow at year 2106
  1813. *
  1814. * Epoch time is not monoclinic time. For example, when system time is
  1815. * synchronized with network, there may exist a jump (forward or backward)
  1816. * of epoch time.
  1817. *
  1818. * In 2 cases, this system time may be not reliable:
  1819. * - During boot, and before RTC is initialized.
  1820. * - During wakeup, and the elapsed sleep time hasn't compensated.
  1821. *
  1822. * \return epoch time in seconds
  1823. */
  1824. int64_t osiEpochSecond(void);
  1825. /**
  1826. * \brief set the monoclinic system time
  1827. *
  1828. * After the system time is changed, RTC won't be updated automatically.
  1829. * It is needed to call RTC API to sync system time to RTC.
  1830. *
  1831. * When epoch time is changed, the monoclilinc system up time isn't changed,
  1832. * and local time is changed correspondingly. The delta bewteen epoch time
  1833. * and local time is only affected by timezone.
  1834. *
  1835. * \param ms epoch time in milliseconds
  1836. *
  1837. * \return true on succeed else fail
  1838. */
  1839. bool osiSetEpochTime(int64_t ms);
  1840. /**
  1841. * \brief get time zone in second
  1842. *
  1843. * Time zone is the offset between local time and epoch time:
  1844. * local_time = epoch_time + time_zone
  1845. *
  1846. * OSI won't keep time zone at power off. Other module should store
  1847. * time zone in NVRAM, and set to OSI at boot.
  1848. *
  1849. * \return time zone in second
  1850. */
  1851. int osiTimeZoneOffset(void);
  1852. /**
  1853. * \brief set time zone in second
  1854. *
  1855. * Time zone is the offset between local time and epoch time:
  1856. * local_time = epoch_time + time_zone
  1857. *
  1858. * Time zone should be in [-12*3600, 12*3600]. However, it is not checked
  1859. * inside this. The caller should make sure the \p offset is reasonable.
  1860. *
  1861. * \param offset time zone in second
  1862. */
  1863. void osiSetTimeZoneOffset(int offset);
  1864. /**
  1865. * \brief get the local time
  1866. *
  1867. * It is just: epoch_time + time_zone
  1868. *
  1869. * \return local time in milliseconds
  1870. */
  1871. int64_t osiLocalTime(void);
  1872. /**
  1873. * \brief get the local time in seconds
  1874. *
  1875. * It is just: epoch_time + time_zone
  1876. *
  1877. * \return local time in seconds
  1878. */
  1879. int64_t osiLocalSecond(void);
  1880. /**
  1881. * \brief monoclinic system hardware tick
  1882. *
  1883. * **Don't** call this in application code. It is only for legacy codes.
  1884. *
  1885. * The frequency of hardware tick is chip dependent, and implementation dependent.
  1886. *
  1887. * \return monoclinic system hardware tick
  1888. */
  1889. int64_t osiUpHWTick(void);
  1890. /**
  1891. * \brief hardware tick count in 16384Hz
  1892. *
  1893. * The return value should be fulll 32bits value. That is, the next tick of
  1894. * 0xffffffff will be 0. Then the simple substract will always provide the tick
  1895. * delta.
  1896. *
  1897. * This is only for legacy codes. \p osiUpTime or \p osiUpTimeUS is recommended.
  1898. * On some platform, it may be un-implemented.
  1899. *
  1900. * \return hardware tick count
  1901. */
  1902. uint32_t osiHWTick16K(void);
  1903. /**
  1904. * \brief convert epoch time to up time
  1905. *
  1906. * When some values has special meanings, such as INT64_MAX means invalid or not
  1907. * exist, caller should check special values before call this.
  1908. *
  1909. * \param epoch epoch time in milliseconds
  1910. * \return up time in milliseconds
  1911. */
  1912. int64_t osiEpochToUpTime(int64_t epoch);
  1913. /**
  1914. * \brief start couting of elsapsed timer
  1915. *
  1916. * \param timer elapsed timer, must be valid
  1917. */
  1918. void osiElapsedTimerStart(osiElapsedTimer_t *timer);
  1919. /**
  1920. * \brief elapsed milliseconds after start
  1921. *
  1922. * \param timer elapsed timer, must be valid
  1923. * \return
  1924. * - elapsed milliseconds after start
  1925. */
  1926. uint32_t osiElapsedTime(osiElapsedTimer_t *timer);
  1927. /**
  1928. * \brief elapsed microseconds after start
  1929. *
  1930. * \param timer elapsed timer, must be valid
  1931. * \return
  1932. * - elapsed microseconds after start
  1933. */
  1934. uint32_t osiElapsedTimeUS(osiElapsedTimer_t *timer);
  1935. /**
  1936. * \brief convert uptime to epoch time
  1937. *
  1938. * When some values has special meanings, such as INT64_MAX means invalid or not
  1939. * exist, caller should check special values before call this.
  1940. *
  1941. * \param epoch up time in milliseconds
  1942. * \return epoch time in milliseconds
  1943. */
  1944. int64_t osiUpTimeToEpoch(int64_t uptime);
  1945. /**
  1946. * \brief CPU suspend
  1947. *
  1948. * Usually, it shouldn't be called directly by application. Rather, it is
  1949. * implemented by BSP, and called by \p osiPmSuspend.
  1950. *
  1951. * \param mode suspend mode
  1952. * \param ms suspend time in milliseconds
  1953. * \return
  1954. * suspend resume source. \p OSI_RESUME_ABORT bit indicates suspend
  1955. * aborted.
  1956. */
  1957. uint32_t osiPmCpuSuspend(osiSuspendMode_t mode, int64_t ms);
  1958. /**
  1959. * \brief PM source callbacks
  1960. *
  1961. * All the callbacks are called with interrupt disabled. So, it is not
  1962. * needed to call \p osiEnterCritical or \p osiIrqSave for protection.
  1963. * And it is not error to call them.
  1964. *
  1965. * Don't call blocking API in the callback.
  1966. */
  1967. typedef struct osiPmSourceOps
  1968. {
  1969. void (*suspend)(void *ctx, osiSuspendMode_t mode); ///< callback to be called before suspend
  1970. void (*resume)(void *ctx, osiSuspendMode_t mode, uint32_t source); ///< callback to be called after resume
  1971. bool (*prepare)(void *ctx); ///< callback to be called at suspend check
  1972. void (*prepare_abort)(void *ctx); ///< callback to be called at suspend check fail
  1973. } osiPmSourceOps_t;
  1974. /**
  1975. * PM source opaque data struct
  1976. */
  1977. typedef struct osiPmSource osiPmSource_t;
  1978. /**
  1979. * \brief power management module initialization
  1980. *
  1981. * It should be called in early stage of boot, due to many other modules
  1982. * may register suspend and resume callback at initialization.
  1983. */
  1984. void osiPmInit(void);
  1985. /**
  1986. * \brief power management core start
  1987. *
  1988. * To avoid suspend too early, PM core won't be started at initialization
  1989. * automatically. After system is initialized, and necessary PM sources
  1990. * are created, \p osiPmStart shall be called.
  1991. *
  1992. * Only after \p osiPmStart is called, PM core will check and enter suspend.
  1993. */
  1994. void osiPmStart(void);
  1995. /**
  1996. * \brief power management core stop
  1997. *
  1998. * Stop PM core, and systen will never suspend.
  1999. *
  2000. * It is only for debug. And it shouldn't be used in real application.
  2001. */
  2002. void osiPmStop(void);
  2003. /**
  2004. * \brief create PM source
  2005. *
  2006. * Modules are distinguished by FOURCC *tag*. So, tag should be unique
  2007. * system wise.
  2008. *
  2009. * When the *tag* is already registered, it will return existed PM source.
  2010. *
  2011. * \p ops is permitted to be NULL, and all callbacks inside it are permitted
  2012. * to be NULL.
  2013. *
  2014. * Resume callbacks are called in create order, suspend callbacks are called
  2015. * in revered order. When resume order does matter, call \p osiPmResumeReorder
  2016. * or \p osiPmResumeFirst to change resume order.
  2017. *
  2018. * The returned pointer should be destroyed and freed by \p osiPmSourceDelete.
  2019. *
  2020. * PM source lock and unlock is binary. That is, there is no *counter* inside.
  2021. * When \p osiPmWakeUnlock is called, the PM source won't prevent system
  2022. * suspend, no matter how many times of \p osiPmWakeLock is called.
  2023. *
  2024. * \param tag module tag
  2025. * \param ops callbacks during suspend and resume
  2026. * \param ctx callback context, shared by all callbacks
  2027. * \return
  2028. * - PM source pointer
  2029. * - NULL on out of memory
  2030. */
  2031. osiPmSource_t *osiPmSourceCreate(uint32_t tag, const osiPmSourceOps_t *ops, void *ctx);
  2032. /**
  2033. * \brief destroy PM source
  2034. *
  2035. * \param ps PM source
  2036. */
  2037. void osiPmSourceDelete(osiPmSource_t *ps);
  2038. /**
  2039. * \brief ensure resume callback order
  2040. *
  2041. * In cases that the resume callback order is important, this API will check
  2042. * and change resume callback order if needed. After the call, the resumed
  2043. * order is ensured.
  2044. *
  2045. * When resume callback order is changed, suspend callback order is changed
  2046. * also.
  2047. *
  2048. * It won't be checked whether the tags are valid.
  2049. *
  2050. * \param tag_later module tag to be resumed laster
  2051. * \param tag_earlier module tag to be resumed earlier
  2052. */
  2053. void osiPmResumeReorder(uint32_t tag_later, uint32_t tag_earlier);
  2054. /**
  2055. * \brief move PM source to the first in resume order
  2056. *
  2057. * Find the PM source, and move it to the head of resume list. When PM source
  2058. * with \p tag is not found in resume list, nothing will be done.
  2059. *
  2060. * \param tag module tag to be moved
  2061. */
  2062. void osiPmResumeFirst(uint32_t tag);
  2063. /**
  2064. * \brief wake lock to prevent suspend
  2065. *
  2066. * Indicate the PM source will prevent system suspend. PM source is *NOT*
  2067. * counting, \p osiPmWakeLock will just set the PM source state. Multiple
  2068. * calls of \p osiPmWakeLock is equivalent to a single call.
  2069. *
  2070. * When \p ops.prepare is not NULL, the internal state of PM source is
  2071. * *suspend possible* rather than *active*. When system wants to
  2072. * suspend, \p ops.prepare will be called to double check whether
  2073. * suspend is permitted.
  2074. *
  2075. * \param ps PM source
  2076. */
  2077. void osiPmWakeLock(osiPmSource_t *ps);
  2078. /**
  2079. * \brief wake unlock to permit suspend
  2080. *
  2081. * Indicate the PM source won't prevent system suspend. PM source is *NOT*
  2082. * counting. No matter how many calls of \p osiPmWakeLock are called,
  2083. * \p osiPmWakeUnlock will set the PM source to unlock state.
  2084. *
  2085. * \param ps PM source
  2086. */
  2087. void osiPmWakeUnlock(osiPmSource_t *ps);
  2088. /**
  2089. * \brief power management suspend
  2090. *
  2091. * Usually, it shouldn't be called directly by application. Rather, it will
  2092. * be called after suspend criteria are met.
  2093. */
  2094. void osiPmSleep(uint32_t idle_tick);
  2095. /**
  2096. * \brief dump PM source information to memory
  2097. *
  2098. * It is for debug only. The data format of timer information dump is
  2099. * not stable, and may change. Currently, there is 4 bytes header, and
  2100. * 4 bytes for each PM source.
  2101. *
  2102. * Caller should make sure \p mem is enough for hold PM source information
  2103. * of \p count.
  2104. *
  2105. * \param mem memory for PM source information dump
  2106. * \param count maximum PM source count to be dump
  2107. * \return
  2108. * - dump memory size
  2109. * - -1 if \p count is too small
  2110. */
  2111. int osiPmSourceDump(void *mem, int count);
  2112. /**
  2113. * \brief set 32K sleep flag
  2114. *
  2115. * For platforms support both 32K sleep and suspend, the default sleep
  2116. * mode is suspend. When it is needed to use 32K sleep forcedly, it is
  2117. * needed to call this API.
  2118. *
  2119. * Each bit of \p flag represents a request source. When there are any
  2120. * 32K sleep requests, system will use 32K sleep rather than suspend.
  2121. *
  2122. * The 32K sleep request sources depend on platform. And they are
  2123. * defined in platform dependent hal_chip.h.
  2124. *
  2125. * \param flag 32K sleep request flag
  2126. */
  2127. void osiSet32KSleepFlag(uint32_t flag);
  2128. /**
  2129. * \brief clear 32K sleep flag
  2130. *
  2131. * \param flag 32K sleep request flag
  2132. */
  2133. void osiClear32KSleepFlag(uint32_t flag);
  2134. /**
  2135. * \brief register a shutdown callback
  2136. *
  2137. * When the callback and context is already registered, it will return
  2138. * false.
  2139. *
  2140. * The order to invoke callbacks is undefined.
  2141. *
  2142. * *Don't* call \p osiRegisterShutdownCallback or
  2143. * \p osiUnregisterShutdownCallback inside the callbacks.
  2144. *
  2145. * \param cb shutdown callback to be registered, can't be NULL
  2146. * \param ctx shutdown callback context
  2147. * \return
  2148. * - true if callback registered
  2149. * - false if callback is already registered, or callback is NULL
  2150. */
  2151. bool osiRegisterShutdownCallback(osiShutdownCallback_t cb, void *ctx);
  2152. /**
  2153. * \brief unregister a shutdown callback
  2154. *
  2155. * \param cb shutdown callback to be unregistered, can't be NULL
  2156. * \param ctx shutdown callback context
  2157. * \return
  2158. * - true if callback unregistered
  2159. * - false if callback isn't found
  2160. */
  2161. bool osiUnregisterShutdownCallback(osiShutdownCallback_t cb, void *ctx);
  2162. /**
  2163. * \brief get PSM expiration time in uptime
  2164. *
  2165. * \return
  2166. * - PSM expiration time in uptime
  2167. * - INT64_MAX if PSM not enabled
  2168. */
  2169. int64_t osiGetPsmWakeUpTime(void);
  2170. /**
  2171. * \brief set PSM expiration time in uptime
  2172. *
  2173. * \param uptime PSM expiration time in uptime
  2174. * or INT64_MAX to disable PSM
  2175. */
  2176. void osiSetPsmWakeUpTime(int64_t uptime);
  2177. /**
  2178. * \brief set PSM sleep time from now
  2179. *
  2180. * \param ms PSM sleep time from now
  2181. * or INT64_MAX to disable PSM
  2182. */
  2183. void osiSetPsmSleepTime(int64_t ms);
  2184. /**
  2185. * \brief get PSM elapsed time in milliseconds
  2186. *
  2187. * The starting point is the time \p osiSetPsmWakeUpTime or
  2188. * \p osiSetPsmSleepTime is called. And this returns the elapsed time from
  2189. * the starting point to now.
  2190. *
  2191. * \return PSM elsapsed time
  2192. */
  2193. int64_t osiGetPsmElapsedTime(void);
  2194. /**
  2195. * \brief get cp deep sleep time in milliseconds
  2196. *
  2197. * \return cp deep sleep time
  2198. */
  2199. uint64_t osiCpDeepSleepTime(void);
  2200. /**
  2201. * \brief shutdown to specified mode
  2202. *
  2203. * When parameter is wrong, it will return false:
  2204. * - When \p mode is OSI_SHUTDOWN_PSM_SLEEP, and PSM isn't enabled.
  2205. * Caller should check whether PSM is enabled before calling
  2206. * \p osiShutdown.
  2207. * - When \p mode is not supported in the platform.
  2208. *
  2209. * It never return true.
  2210. *
  2211. * \param mode shutdown mode
  2212. * \return
  2213. * - false on parameter error
  2214. */
  2215. bool osiShutdown(osiShutdownMode_t mode);
  2216. /**
  2217. * \brief get boot causes
  2218. *
  2219. * It is possible there are multiple boot causes. The returned value is
  2220. * bit or of all boot causes.
  2221. *
  2222. * It is possible hardware registers will be cleared after accessed. So,
  2223. * always call \p osiGetBootCauses to get the boot causes, rather than
  2224. * accessing hardware registers directly.
  2225. *
  2226. * \return boot causes
  2227. */
  2228. uint32_t osiGetBootCauses(void);
  2229. /**
  2230. * \brief set a boot cause
  2231. *
  2232. * It is intended only for system integration.
  2233. *
  2234. * \param cause boot cause
  2235. */
  2236. void osiSetBootCause(osiBootCause_t cause);
  2237. /**
  2238. * \brief clear a boot cause
  2239. *
  2240. * It is intended only for system integration.
  2241. *
  2242. * \param cause boot cause
  2243. */
  2244. void osiClearBootCause(osiBootCause_t cause);
  2245. /**
  2246. * \brief get boot mode
  2247. *
  2248. * \return boot mode
  2249. */
  2250. osiBootMode_t osiGetBootMode(void);
  2251. /**
  2252. * \brief set boot mode
  2253. *
  2254. * It is intended only for system integration. At calling, caller should
  2255. * take care conflict of other boot mode detection.
  2256. *
  2257. * \param mode boot mode
  2258. */
  2259. void osiSetBootMode(osiBootMode_t mode);
  2260. /**
  2261. * \brief PSM save preparation
  2262. *
  2263. * It will be called before any \p osiPsmDataSave. Usually, it will prepare
  2264. * PSM data memory.
  2265. *
  2266. * \param mode shutdown mode
  2267. */
  2268. void osiPsmSavePrepare(osiShutdownMode_t mode);
  2269. /**
  2270. * \brief PSM save
  2271. *
  2272. * Save all owner's PSM data to persistent storage.
  2273. *
  2274. * \param mode shutdown mode
  2275. */
  2276. void osiPsmSave(osiShutdownMode_t mode);
  2277. /**
  2278. * \brief PSM restore
  2279. *
  2280. * It should be called in system initialization, after file system
  2281. * initialization.
  2282. */
  2283. void osiPsmRestore(void);
  2284. /**
  2285. * \brief save PSM data
  2286. *
  2287. * PSM data save is implemented in platform. PSM data should be saved in
  2288. * persistent storage, which can be flash or aon memory. Caller shouldn't
  2289. * assume the storage type.
  2290. *
  2291. * It should only be called in \p osiShutdown callbacks.
  2292. *
  2293. * For each owner, \p osiPsmDataSave shall be called only once at most.
  2294. *
  2295. * It is recommended to use fixed size buffer, which is the same at each
  2296. * PSM shutdown. However, variable size buffer is also supported.
  2297. *
  2298. * As a special case, \p size of 0 is permitted. It just keep record that
  2299. * the owner is saved without real data.
  2300. *
  2301. * \param owner PSM data owner
  2302. * \param buf owner's PSM data buffer
  2303. * \param size owner's PSM data buffer size
  2304. * \return
  2305. * - true on success
  2306. * - false on fail
  2307. * - duplicated owner
  2308. * - out of memory
  2309. */
  2310. bool osiPsmDataSave(osiPsmDataOwner_t owner, const void *buf, uint32_t size);
  2311. /**
  2312. * \brief restore PSM data
  2313. *
  2314. * Restore PSM data. At PSM resume boot, PSM data owner calls this to get
  2315. * the data saved by \p osiPsmDataSave
  2316. *
  2317. * The buffer size should be equal or larger than the saved size. If it is
  2318. * smaller than saved size, return -1.
  2319. *
  2320. * When \p buf is NULL, it will return PSM data size without copy. It can
  2321. * be used to get the PSM data size.
  2322. *
  2323. * \param owner PSM data owner
  2324. * \param buf buffer for owner's PSM data
  2325. * \param size buffer size
  2326. * \return
  2327. * - PSM data size on success
  2328. * - 0 if there are no PSM data
  2329. * - -1 on error
  2330. */
  2331. int osiPsmDataRestore(osiPsmDataOwner_t owner, void *buf, uint32_t size);
  2332. /**
  2333. * send out debug event to trace tool
  2334. *
  2335. * If system and trace tool support debug event, this will send
  2336. * a word to trace tool.
  2337. *
  2338. * It should be only used in quick debug. It is possible that platform
  2339. * can't support debug event, and debug event output may be turned off
  2340. * by compiling option.
  2341. *
  2342. * \param event word which will appear on trace tool
  2343. */
  2344. void osiDebugEvent(uint32_t event);
  2345. /**
  2346. * panic
  2347. *
  2348. * Called on fatal error, and system can't go on.
  2349. *
  2350. * It is different from \p assert. It will always cause system panic,
  2351. * and there are no compiling option to ignore it.
  2352. */
  2353. OSI_NO_RETURN void osiPanic(void);
  2354. /**
  2355. * whether system is in panic mode
  2356. *
  2357. * In panic mode, system will still run a small daemon. And there is no
  2358. * interrupt in panic mode. So, features used in panic daemon shall take
  2359. * care of this.
  2360. *
  2361. * \return
  2362. * - true if system is in panic mode
  2363. * - false if system is not in panic mode
  2364. */
  2365. bool osiIsPanic(void);
  2366. #ifdef CONFIG_KERNEL_ASSERT_ENABLED
  2367. /*+\NEW\zhuwangbin\2020.4.2\添加AT*exinfo指令*/
  2368. extern void osiPanicInfoFuncLineSet(const char *func, int line);
  2369. #define OSI_ASSERT(expect_true, info) OSI_DO_WHILE0(if (!(expect_true)) {osiPanicInfoFuncLineSet(__FUNCTION__,__LINE__);osiPanic();})
  2370. #else
  2371. #define OSI_ASSERT(expect_true, info)
  2372. #endif
  2373. /*-\NEW\zhuwangbin\2020.4.2\添加AT*exinfo指令*/
  2374. /**
  2375. * busy loop delay
  2376. *
  2377. * The precision of delay depends on platform. And it will ensure to delay
  2378. * at least the specified time.
  2379. *
  2380. * \param us delay time in microseconds
  2381. */
  2382. OSI_NO_MIPS16 void osiDelayUS(uint32_t us);
  2383. /**
  2384. * delay by CPU loop
  2385. *
  2386. * The absolute delay time depends on CPU frequency. \p count is the loop
  2387. * count, not the delayed instruction count.
  2388. *
  2389. * \param count delay loop count
  2390. */
  2391. void osiDelayLoops(uint32_t count);
  2392. /**
  2393. * call function with specified stack
  2394. *
  2395. * This will only be called with low level codes, and most likely, it is not
  2396. * needed for application.
  2397. *
  2398. * This function is located in SRAM. So, it can be called even the external
  2399. * RAM in unavailable.
  2400. *
  2401. * \p function shall have 2 parameters at most. It can return one word. When
  2402. * \p function doesn't return value, the return value of this wrapper is
  2403. * undefined.
  2404. *
  2405. * \p sp should be 8 bytes aligned.
  2406. *
  2407. * \param sp the stack to be used for \p function
  2408. * \param function the real function
  2409. * \param param0 the first parameter for \p function
  2410. * \param param1 the second parameter for \p function
  2411. * \return
  2412. * - the return value of \p function
  2413. */
  2414. uint32_t osiCallWithStack(void *sp, void *function, uint32_t param0, uint32_t param1);
  2415. #ifndef DOXYGEN
  2416. // it is needed to place such definitions in a better place
  2417. #define PM_TAG_ADI_BUS OSI_MAKE_TAG('A', 'D', 'I', 'B')
  2418. #define PM_TAG_IOMUX OSI_MAKE_TAG('I', 'O', 'M', 'X')
  2419. #define PM_TAG_GPIO OSI_MAKE_TAG('G', 'P', 'I', 'O')
  2420. #define PM_TAG_AXI_DMA OSI_MAKE_TAG('A', 'D', 'M', 'A')
  2421. #endif
  2422. #ifdef __cplusplus
  2423. }
  2424. #endif
  2425. #endif