kernel.h 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. /**
  2. * @file kernel.h
  3. * Furi Kernel primitives
  4. */
  5. #pragma once
  6. #include <core/base.h>
  7. #ifdef __cplusplus
  8. extern "C" {
  9. #endif
  10. /** Lock kernel, pause process scheduling
  11. *
  12. * @return previous lock state(0 - unlocked, 1 - locked)
  13. */
  14. int32_t furi_kernel_lock();
  15. /** Unlock kernel, resume process scheduling
  16. *
  17. * @return previous lock state(0 - unlocked, 1 - locked)
  18. */
  19. int32_t furi_kernel_unlock();
  20. /** Restore kernel lock state
  21. *
  22. * @param[in] lock The lock state
  23. *
  24. * @return new lock state or error
  25. */
  26. int32_t furi_kernel_restore_lock(int32_t lock);
  27. /** Get kernel systick frequency
  28. *
  29. * @return systick counts per second
  30. */
  31. uint32_t furi_kernel_get_tick_frequency();
  32. /** Delay execution
  33. *
  34. * Also keep in mind delay is aliased to scheduler timer intervals.
  35. *
  36. * @param[in] ticks The ticks count to pause
  37. */
  38. void furi_delay_tick(uint32_t ticks);
  39. /** Delay until tick
  40. *
  41. * @param[in] ticks The tick until which kerel should delay task execution
  42. *
  43. * @return The furi status.
  44. */
  45. FuriStatus furi_delay_until_tick(uint32_t tick);
  46. /** Get current tick counter
  47. *
  48. * System uptime, may overflow.
  49. *
  50. * @return Current ticks in milliseconds
  51. */
  52. uint32_t furi_get_tick(void);
  53. /** Convert milliseconds to ticks
  54. *
  55. * @param[in] milliseconds time in milliseconds
  56. * @return time in ticks
  57. */
  58. uint32_t furi_ms_to_ticks(uint32_t milliseconds);
  59. /** Delay in milliseconds
  60. *
  61. * This method uses kernel ticks on the inside, which causes delay to be aliased to scheduler timer intervals.
  62. * Real wait time will be between X+ milliseconds.
  63. * Special value: 0, will cause task yield.
  64. * Also if used when kernel is not running will fall back to `furi_delay_us`.
  65. *
  66. * @warning Cannot be used from ISR
  67. *
  68. * @param[in] milliseconds milliseconds to wait
  69. */
  70. void furi_delay_ms(uint32_t milliseconds);
  71. /** Delay in microseconds
  72. *
  73. * Implemented using Cortex DWT counter. Blocking and non aliased.
  74. *
  75. * @param[in] microseconds microseconds to wait
  76. */
  77. void furi_delay_us(uint32_t microseconds);
  78. #ifdef __cplusplus
  79. }
  80. #endif