osal.h 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750
  1. /*
  2. ChibiOS - Copyright (C) 2006..2018 Giovanni Di Sirio
  3. Licensed under the Apache License, Version 2.0 (the "License");
  4. you may not use this file except in compliance with the License.
  5. You may obtain a copy of the License at
  6. http://www.apache.org/licenses/LICENSE-2.0
  7. Unless required by applicable law or agreed to in writing, software
  8. distributed under the License is distributed on an "AS IS" BASIS,
  9. WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  10. See the License for the specific language governing permissions and
  11. limitations under the License.
  12. */
  13. /**
  14. * @file osal.h
  15. * @brief OSAL module header.
  16. *
  17. * @addtogroup OSAL
  18. * @{
  19. */
  20. #ifndef OSAL_H
  21. #define OSAL_H
  22. #include <stddef.h>
  23. #include <stdint.h>
  24. #include <stdbool.h>
  25. #include "cmparams.h"
  26. #include "osalconf.h"
  27. /*===========================================================================*/
  28. /* Module constants. */
  29. /*===========================================================================*/
  30. /**
  31. * @name Common constants
  32. * @{
  33. */
  34. #if !defined(FALSE) || defined(__DOXYGEN__)
  35. #define FALSE 0
  36. #endif
  37. #if !defined(TRUE) || defined(__DOXYGEN__)
  38. #define TRUE 1
  39. #endif
  40. #define OSAL_SUCCESS false
  41. #define OSAL_FAILED true
  42. /** @} */
  43. /**
  44. * @name Messages
  45. * @{
  46. */
  47. #define MSG_OK (msg_t)0
  48. #define MSG_RESET (msg_t)-1
  49. #define MSG_TIMEOUT (msg_t)-2
  50. #define MSG_WAIT (msg_t)-10
  51. /** @} */
  52. /**
  53. * @name Special time constants
  54. * @{
  55. */
  56. #define TIME_IMMEDIATE ((sysinterval_t)0)
  57. #define TIME_INFINITE ((sysinterval_t)-1)
  58. /** @} */
  59. /**
  60. * @name Systick modes.
  61. * @{
  62. */
  63. #define OSAL_ST_MODE_NONE 0
  64. #define OSAL_ST_MODE_PERIODIC 1
  65. #define OSAL_ST_MODE_FREERUNNING 2
  66. /** @} */
  67. /**
  68. * @name Systick parameters.
  69. * @{
  70. */
  71. /**
  72. * @brief Size in bits of the @p systick_t type.
  73. */
  74. #define OSAL_ST_RESOLUTION 32
  75. /**
  76. * @brief Systick mode required by the underlying OS.
  77. */
  78. #define OSAL_ST_MODE OSAL_ST_MODE_PERIODIC
  79. /** @} */
  80. /**
  81. * @name IRQ-related constants
  82. * @{
  83. */
  84. /**
  85. * @brief Total priority levels.
  86. */
  87. #define OSAL_IRQ_PRIORITY_LEVELS (1U << CORTEX_PRIORITY_BITS)
  88. /**
  89. * @brief Highest IRQ priority for HAL drivers.
  90. */
  91. #if (CORTEX_MODEL == 0) || defined(__DOXYGEN__)
  92. #define OSAL_IRQ_MAXIMUM_PRIORITY 0
  93. #else
  94. #define OSAL_IRQ_MAXIMUM_PRIORITY 1
  95. #endif
  96. /** @} */
  97. /*===========================================================================*/
  98. /* Module pre-compile time settings. */
  99. /*===========================================================================*/
  100. /**
  101. * @brief Frequency in Hertz of the system tick.
  102. */
  103. #if !defined(OSAL_ST_FREQUENCY) || defined(__DOXYGEN__)
  104. #define OSAL_ST_FREQUENCY 1000
  105. #endif
  106. /**
  107. * @brief Enables OSAL assertions.
  108. */
  109. #if !defined(OSAL_DBG_ENABLE_ASSERTS) || defined(__DOXYGEN__)
  110. #define OSAL_DBG_ENABLE_ASSERTS FALSE
  111. #endif
  112. /**
  113. * @brief Enables OSAL functions parameters checks.
  114. */
  115. #if !defined(OSAL_DBG_ENABLE_CHECKS) || defined(__DOXYGEN__)
  116. #define OSAL_DBG_ENABLE_CHECKS FALSE
  117. #endif
  118. /**
  119. * @brief OSAL initialization hook.
  120. */
  121. #if !defined(OSAL_INIT_HOOK) || defined(__DOXYGEN__)
  122. #define OSAL_INIT_HOOK()
  123. #endif
  124. /**
  125. * @brief Idle loop hook macro.
  126. */
  127. #if !defined(OSAL_IDLE_HOOK) || defined(__DOXYGEN__)
  128. #define OSAL_IDLE_HOOK()
  129. #endif
  130. /*===========================================================================*/
  131. /* Derived constants and error checks. */
  132. /*===========================================================================*/
  133. /*===========================================================================*/
  134. /* Module data structures and types. */
  135. /*===========================================================================*/
  136. /**
  137. * @brief Type of a system status word.
  138. */
  139. typedef uint32_t syssts_t;
  140. /**
  141. * @brief Type of a message.
  142. */
  143. typedef int32_t msg_t;
  144. /**
  145. * @brief Type of system time counter.
  146. */
  147. typedef uint32_t systime_t;
  148. /**
  149. * @brief Type of system time interval.
  150. */
  151. typedef uint32_t sysinterval_t;
  152. /**
  153. * @brief Type of realtime counter.
  154. */
  155. typedef uint32_t rtcnt_t;
  156. /**
  157. * @brief Type of a thread.
  158. * @note The content of this structure is not part of the API and should
  159. * not be relied upon. Implementers may define this structure in
  160. * an entirely different way.
  161. */
  162. typedef struct {
  163. volatile msg_t message;
  164. } thread_t;
  165. /**
  166. * @brief Type of a thread reference.
  167. */
  168. typedef thread_t * thread_reference_t;
  169. /**
  170. * @brief Type of an event flags mask.
  171. */
  172. typedef uint32_t eventflags_t;
  173. /**
  174. * @brief Type of an event flags object.
  175. * @note The content of this structure is not part of the API and should
  176. * not be relied upon. Implementers may define this structure in
  177. * an entirely different way.
  178. * @note Retrieval and clearing of the flags are not defined in this
  179. * API and are implementation-dependent.
  180. */
  181. typedef struct event_source event_source_t;
  182. /**
  183. * @brief Type of an event source callback.
  184. * @note This type is not part of the OSAL API and is provided
  185. * exclusively as an example and for convenience.
  186. */
  187. typedef void (*eventcallback_t)(event_source_t *esp);
  188. /**
  189. * @brief Events source object.
  190. * @note The content of this structure is not part of the API and should
  191. * not be relied upon. Implementers may define this structure in
  192. * an entirely different way.
  193. * @note Retrieval and clearing of the flags are not defined in this
  194. * API and are implementation-dependent.
  195. */
  196. struct event_source {
  197. volatile eventflags_t flags; /**< @brief Stored event flags. */
  198. eventcallback_t cb; /**< @brief Event source callback. */
  199. void *param; /**< @brief User defined field. */
  200. };
  201. /**
  202. * @brief Type of a mutex.
  203. * @note If the OS does not support mutexes or there is no OS then them
  204. * mechanism can be simulated.
  205. */
  206. typedef uint32_t mutex_t;
  207. /**
  208. * @brief Type of a thread queue.
  209. * @details A thread queue is a queue of sleeping threads, queued threads
  210. * can be dequeued one at time or all together.
  211. * @note If the OSAL is implemented on a bare metal machine without RTOS
  212. * then the queue can be implemented as a single thread reference.
  213. */
  214. typedef struct {
  215. thread_reference_t tr;
  216. } threads_queue_t;
  217. /*===========================================================================*/
  218. /* Module macros. */
  219. /*===========================================================================*/
  220. /**
  221. * @name Debug related macros
  222. * @{
  223. */
  224. /**
  225. * @brief Condition assertion.
  226. * @details If the condition check fails then the OSAL panics with a
  227. * message and halts.
  228. * @note The condition is tested only if the @p OSAL_ENABLE_ASSERTIONS
  229. * switch is enabled.
  230. * @note The remark string is not currently used except for putting a
  231. * comment in the code about the assertion.
  232. *
  233. * @param[in] c the condition to be verified to be true
  234. * @param[in] remark a remark string
  235. *
  236. * @api
  237. */
  238. #define osalDbgAssert(c, remark) do { \
  239. /*lint -save -e506 -e774 [2.1, 14.3] Can be a constant by design.*/ \
  240. if (OSAL_DBG_ENABLE_ASSERTS != FALSE) { \
  241. if (!(c)) { \
  242. /*lint -restore*/ \
  243. osalSysHalt(__func__); \
  244. } \
  245. } \
  246. } while (false)
  247. /**
  248. * @brief Function parameters check.
  249. * @details If the condition check fails then the OSAL panics and halts.
  250. * @note The condition is tested only if the @p OSAL_ENABLE_CHECKS switch
  251. * is enabled.
  252. *
  253. * @param[in] c the condition to be verified to be true
  254. *
  255. * @api
  256. */
  257. #define osalDbgCheck(c) do { \
  258. /*lint -save -e506 -e774 [2.1, 14.3] Can be a constant by design.*/ \
  259. if (OSAL_DBG_ENABLE_CHECKS != FALSE) { \
  260. if (!(c)) { \
  261. /*lint -restore*/ \
  262. osalSysHalt(__func__); \
  263. } \
  264. } \
  265. } while (false)
  266. /**
  267. * @brief I-Class state check.
  268. * @note Implementation is optional.
  269. */
  270. #define osalDbgCheckClassI()
  271. /**
  272. * @brief S-Class state check.
  273. * @note Implementation is optional.
  274. */
  275. #define osalDbgCheckClassS()
  276. /** @} */
  277. /**
  278. * @name IRQ service routines wrappers
  279. * @{
  280. */
  281. /**
  282. * @brief Priority level verification macro.
  283. */
  284. #define OSAL_IRQ_IS_VALID_PRIORITY(n) \
  285. (((n) >= OSAL_IRQ_MAXIMUM_PRIORITY) && ((n) < OSAL_IRQ_PRIORITY_LEVELS))
  286. /**
  287. * @brief IRQ prologue code.
  288. * @details This macro must be inserted at the start of all IRQ handlers.
  289. */
  290. #define OSAL_IRQ_PROLOGUE()
  291. /**
  292. * @brief IRQ epilogue code.
  293. * @details This macro must be inserted at the end of all IRQ handlers.
  294. */
  295. #define OSAL_IRQ_EPILOGUE()
  296. /**
  297. * @brief IRQ handler function declaration.
  298. * @details This macro hides the details of an ISR function declaration.
  299. *
  300. * @param[in] id a vector name as defined in @p vectors.s
  301. */
  302. #define OSAL_IRQ_HANDLER(id) void id(void)
  303. /** @} */
  304. /**
  305. * @name Time conversion utilities
  306. * @{
  307. */
  308. /**
  309. * @brief Seconds to system ticks.
  310. * @details Converts from seconds to system ticks number.
  311. * @note The result is rounded upward to the next tick boundary.
  312. *
  313. * @param[in] secs number of seconds
  314. * @return The number of ticks.
  315. *
  316. * @api
  317. */
  318. #define OSAL_S2I(secs) \
  319. ((sysinterval_t)((uint32_t)(secs) * (uint32_t)OSAL_ST_FREQUENCY))
  320. /**
  321. * @brief Milliseconds to system ticks.
  322. * @details Converts from milliseconds to system ticks number.
  323. * @note The result is rounded upward to the next tick boundary.
  324. *
  325. * @param[in] msecs number of milliseconds
  326. * @return The number of ticks.
  327. *
  328. * @api
  329. */
  330. #define OSAL_MS2I(msecs) \
  331. ((sysinterval_t)((((((uint32_t)(msecs)) * \
  332. ((uint32_t)OSAL_ST_FREQUENCY)) - 1UL) / 1000UL) + 1UL))
  333. /**
  334. * @brief Microseconds to system ticks.
  335. * @details Converts from microseconds to system ticks number.
  336. * @note The result is rounded upward to the next tick boundary.
  337. *
  338. * @param[in] usecs number of microseconds
  339. * @return The number of ticks.
  340. *
  341. * @api
  342. */
  343. #define OSAL_US2I(usecs) \
  344. ((sysinterval_t)((((((uint32_t)(usecs)) * \
  345. ((uint32_t)OSAL_ST_FREQUENCY)) - 1UL) / 1000000UL) + 1UL))
  346. /** @} */
  347. /**
  348. * @name Time conversion utilities for the realtime counter
  349. * @{
  350. */
  351. /**
  352. * @brief Seconds to realtime counter.
  353. * @details Converts from seconds to realtime counter cycles.
  354. * @note The macro assumes that @p freq >= @p 1.
  355. *
  356. * @param[in] freq clock frequency, in Hz, of the realtime counter
  357. * @param[in] sec number of seconds
  358. * @return The number of cycles.
  359. *
  360. * @api
  361. */
  362. #define OSAL_S2RTC(freq, sec) ((freq) * (sec))
  363. /**
  364. * @brief Milliseconds to realtime counter.
  365. * @details Converts from milliseconds to realtime counter cycles.
  366. * @note The result is rounded upward to the next millisecond boundary.
  367. * @note The macro assumes that @p freq >= @p 1000.
  368. *
  369. * @param[in] freq clock frequency, in Hz, of the realtime counter
  370. * @param[in] msec number of milliseconds
  371. * @return The number of cycles.
  372. *
  373. * @api
  374. */
  375. #define OSAL_MS2RTC(freq, msec) (rtcnt_t)((((freq) + 999UL) / 1000UL) * (msec))
  376. /**
  377. * @brief Microseconds to realtime counter.
  378. * @details Converts from microseconds to realtime counter cycles.
  379. * @note The result is rounded upward to the next microsecond boundary.
  380. * @note The macro assumes that @p freq >= @p 1000000.
  381. *
  382. * @param[in] freq clock frequency, in Hz, of the realtime counter
  383. * @param[in] usec number of microseconds
  384. * @return The number of cycles.
  385. *
  386. * @api
  387. */
  388. #define OSAL_US2RTC(freq, usec) (rtcnt_t)((((freq) + 999999UL) / 1000000UL) * (usec))
  389. /** @} */
  390. /**
  391. * @name Sleep macros using absolute time
  392. * @{
  393. */
  394. /**
  395. * @brief Delays the invoking thread for the specified number of seconds.
  396. * @note The specified time is rounded up to a value allowed by the real
  397. * system tick clock.
  398. * @note The maximum specifiable value is implementation dependent.
  399. *
  400. * @param[in] secs time in seconds, must be different from zero
  401. *
  402. * @api
  403. */
  404. #define osalThreadSleepSeconds(secs) osalThreadSleep(OSAL_S2I(secs))
  405. /**
  406. * @brief Delays the invoking thread for the specified number of
  407. * milliseconds.
  408. * @note The specified time is rounded up to a value allowed by the real
  409. * system tick clock.
  410. * @note The maximum specifiable value is implementation dependent.
  411. *
  412. * @param[in] msecs time in milliseconds, must be different from zero
  413. *
  414. * @api
  415. */
  416. #define osalThreadSleepMilliseconds(msecs) osalThreadSleep(OSAL_MS2I(msecs))
  417. /**
  418. * @brief Delays the invoking thread for the specified number of
  419. * microseconds.
  420. * @note The specified time is rounded up to a value allowed by the real
  421. * system tick clock.
  422. * @note The maximum specifiable value is implementation dependent.
  423. *
  424. * @param[in] usecs time in microseconds, must be different from zero
  425. *
  426. * @api
  427. */
  428. #define osalThreadSleepMicroseconds(usecs) osalThreadSleep(OSAL_US2I(usecs))
  429. /** @} */
  430. /*===========================================================================*/
  431. /* External declarations. */
  432. /*===========================================================================*/
  433. extern const char *osal_halt_msg;
  434. #ifdef __cplusplus
  435. extern "C" {
  436. #endif
  437. void osalInit(void);
  438. void osalSysHalt(const char *reason);
  439. void osalSysPolledDelayX(rtcnt_t cycles);
  440. void osalOsTimerHandlerI(void);
  441. void osalOsRescheduleS(void);
  442. systime_t osalOsGetSystemTimeX(void);
  443. void osalThreadSleepS(sysinterval_t time);
  444. void osalThreadSleep(sysinterval_t time);
  445. msg_t osalThreadSuspendS(thread_reference_t *trp);
  446. msg_t osalThreadSuspendTimeoutS(thread_reference_t *trp, sysinterval_t timeout);
  447. void osalThreadResumeI(thread_reference_t *trp, msg_t msg);
  448. void osalThreadResumeS(thread_reference_t *trp, msg_t msg);
  449. msg_t osalThreadEnqueueTimeoutS(threads_queue_t *tqp, sysinterval_t timeout);
  450. void osalThreadDequeueNextI(threads_queue_t *tqp, msg_t msg);
  451. void osalThreadDequeueAllI(threads_queue_t *tqp, msg_t msg);
  452. void osalEventBroadcastFlagsI(event_source_t *esp, eventflags_t flags);
  453. void osalEventBroadcastFlags(event_source_t *esp, eventflags_t flags);
  454. void osalEventSetCallback(event_source_t *esp,
  455. eventcallback_t cb,
  456. void *param);
  457. void osalMutexLock(mutex_t *mp);
  458. void osalMutexUnlock(mutex_t *mp);
  459. #ifdef __cplusplus
  460. }
  461. #endif
  462. /*===========================================================================*/
  463. /* Module inline functions. */
  464. /*===========================================================================*/
  465. /**
  466. * @brief Disables interrupts globally.
  467. *
  468. * @special
  469. */
  470. static inline void osalSysDisable(void) {
  471. __disable_irq();
  472. }
  473. /**
  474. * @brief Enables interrupts globally.
  475. *
  476. * @special
  477. */
  478. static inline void osalSysEnable(void) {
  479. __enable_irq();
  480. }
  481. /**
  482. * @brief Enters a critical zone from thread context.
  483. * @note This function cannot be used for reentrant critical zones.
  484. *
  485. * @special
  486. */
  487. static inline void osalSysLock(void) {
  488. #if CORTEX_MODEL == 0
  489. __disable_irq();
  490. #else
  491. __set_BASEPRI(OSAL_IRQ_MAXIMUM_PRIORITY);
  492. #endif
  493. }
  494. /**
  495. * @brief Leaves a critical zone from thread context.
  496. * @note This function cannot be used for reentrant critical zones.
  497. *
  498. * @special
  499. */
  500. static inline void osalSysUnlock(void) {
  501. #if CORTEX_MODEL == 0
  502. __enable_irq();
  503. #else
  504. __set_BASEPRI(0);
  505. #endif
  506. }
  507. /**
  508. * @brief Enters a critical zone from ISR context.
  509. * @note This function cannot be used for reentrant critical zones.
  510. *
  511. * @special
  512. */
  513. static inline void osalSysLockFromISR(void) {
  514. #if CORTEX_MODEL == 0
  515. __disable_irq();
  516. #else
  517. __set_BASEPRI(OSAL_IRQ_MAXIMUM_PRIORITY);
  518. #endif
  519. }
  520. /**
  521. * @brief Leaves a critical zone from ISR context.
  522. * @note This function cannot be used for reentrant critical zones.
  523. *
  524. * @special
  525. */
  526. static inline void osalSysUnlockFromISR(void) {
  527. #if CORTEX_MODEL == 0
  528. __enable_irq();
  529. #else
  530. __set_BASEPRI(0);
  531. #endif
  532. }
  533. /**
  534. * @brief Returns the execution status and enters a critical zone.
  535. * @details This functions enters into a critical zone and can be called
  536. * from any context. Because its flexibility it is less efficient
  537. * than @p chSysLock() which is preferable when the calling context
  538. * is known.
  539. * @post The system is in a critical zone.
  540. *
  541. * @return The previous system status, the encoding of this
  542. * status word is architecture-dependent and opaque.
  543. *
  544. * @xclass
  545. */
  546. static inline syssts_t osalSysGetStatusAndLockX(void) {
  547. syssts_t sts;
  548. #if CORTEX_MODEL == 0
  549. sts = (syssts_t)__get_PRIMASK();
  550. __disable_irq();
  551. #else
  552. sts = (syssts_t)__get_BASEPRI();
  553. __set_BASEPRI(OSAL_IRQ_MAXIMUM_PRIORITY);
  554. #endif
  555. return sts;
  556. }
  557. /**
  558. * @brief Restores the specified execution status and leaves a critical zone.
  559. * @note A call to @p chSchRescheduleS() is automatically performed
  560. * if exiting the critical zone and if not in ISR context.
  561. *
  562. * @param[in] sts the system status to be restored.
  563. *
  564. * @xclass
  565. */
  566. static inline void osalSysRestoreStatusX(syssts_t sts) {
  567. #if CORTEX_MODEL == 0
  568. if ((sts & (syssts_t)1) == (syssts_t)0) {
  569. __enable_irq();
  570. }
  571. #else
  572. if (sts == (syssts_t)0) {
  573. __set_BASEPRI(0);
  574. }
  575. #endif
  576. }
  577. /**
  578. * @brief Adds an interval to a system time returning a system time.
  579. *
  580. * @param[in] systime base system time
  581. * @param[in] interval interval to be added
  582. * @return The new system time.
  583. *
  584. * @xclass
  585. */
  586. static inline systime_t osalTimeAddX(systime_t systime,
  587. sysinterval_t interval) {
  588. return systime + (systime_t)interval;
  589. }
  590. /**
  591. * @brief Subtracts two system times returning an interval.
  592. *
  593. * @param[in] start first system time
  594. * @param[in] end second system time
  595. * @return The interval representing the time difference.
  596. *
  597. * @xclass
  598. */
  599. static inline sysinterval_t osalTimeDiffX(systime_t start, systime_t end) {
  600. return (sysinterval_t)((systime_t)(end - start));
  601. }
  602. /**
  603. * @brief Checks if the specified time is within the specified time window.
  604. * @note When start==end then the function returns always true because the
  605. * whole time range is specified.
  606. * @note This function can be called from any context.
  607. *
  608. * @param[in] time the time to be verified
  609. * @param[in] start the start of the time window (inclusive)
  610. * @param[in] end the end of the time window (non inclusive)
  611. * @retval true current time within the specified time window.
  612. * @retval false current time not within the specified time window.
  613. *
  614. * @xclass
  615. */
  616. static inline bool osalTimeIsInRangeX(systime_t time,
  617. systime_t start,
  618. systime_t end) {
  619. return (bool)((time - start) < (end - start));
  620. }
  621. /**
  622. * @brief Initializes a threads queue object.
  623. *
  624. * @param[out] tqp pointer to the threads queue object
  625. *
  626. * @init
  627. */
  628. static inline void osalThreadQueueObjectInit(threads_queue_t *tqp) {
  629. osalDbgCheck(tqp != NULL);
  630. }
  631. /**
  632. * @brief Initializes an event source object.
  633. *
  634. * @param[out] esp pointer to the event source object
  635. *
  636. * @init
  637. */
  638. static inline void osalEventObjectInit(event_source_t *esp) {
  639. osalDbgCheck(esp != NULL);
  640. esp->flags = (eventflags_t)0;
  641. esp->cb = NULL;
  642. esp->param = NULL;
  643. }
  644. /**
  645. * @brief Initializes s @p mutex_t object.
  646. *
  647. * @param[out] mp pointer to the @p mutex_t object
  648. *
  649. * @init
  650. */
  651. static inline void osalMutexObjectInit(mutex_t *mp) {
  652. osalDbgCheck(mp != NULL);
  653. *mp = 0;
  654. }
  655. #endif /* OSAL_H */
  656. /** @} */