utils.h 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164
  1. /**
  2. *********************************************************************************
  3. *
  4. * @file utils.h
  5. * @brief This file contains the Utilities functions/types for the driver.
  6. *
  7. * @version V1.0
  8. * @date 07 Nov 2017
  9. * @author AE Team
  10. * @note
  11. *
  12. * Copyright (C) Shanghai Eastsoft Microelectronics Co. Ltd. All rights reserved.
  13. *
  14. *********************************************************************************
  15. */
  16. #ifndef __UTILS_H__
  17. #define __UTILS_H__
  18. #ifdef __cplusplus
  19. extern "C" {
  20. #endif
  21. #include <stdlib.h>
  22. #include "ald_conf.h"
  23. #include "type.h"
  24. #include "es32f033x.h"
  25. /** @addtogroup ES32FXXX_ALD
  26. * @{
  27. */
  28. /** @addtogroup UTILS
  29. * @{
  30. */
  31. /** @defgroup ALD_Public_Types Public Types
  32. * @{
  33. */
  34. /**
  35. * @brief SysTick interval
  36. */
  37. extern uint32_t __systick_interval;
  38. /**
  39. * @brief ALD Status structures definition
  40. */
  41. typedef enum
  42. {
  43. OK = 0x0,
  44. ERROR = 0x1,
  45. BUSY = 0x2,
  46. TIMEOUT = 0x3
  47. } ald_status_t;
  48. /**
  49. * @brief SysTick interval definition
  50. */
  51. typedef enum
  52. {
  53. SYSTICK_INTERVAL_1MS = 1000, /**< Interval is 1ms */
  54. SYSTICK_INTERVAL_10MS = 100, /**< Interval is 10ms */
  55. SYSTICK_INTERVAL_100MS = 10, /**< Interval is 100ms */
  56. SYSTICK_INTERVAL_1000MS = 1, /**< Interval is 1s */
  57. } systick_interval_t;
  58. /**
  59. * @}
  60. */
  61. /** @defgroup ALD_Public_Macros Public Macros
  62. * @{
  63. */
  64. #define ALD_MAX_DELAY 0xFFFFFFFF
  65. #define IS_BIT_SET(reg, bit) (((reg) & (bit)) != RESET)
  66. #define IS_BIT_CLR(reg, bit) (((reg) & (bit)) == RESET)
  67. #define RESET_HANDLE_STATE(x) ((x)->state = 0)
  68. #define __LOCK(x) \
  69. do { \
  70. if ((x)->lock == LOCK) { \
  71. return BUSY; \
  72. } \
  73. else { \
  74. (x)->lock = LOCK; \
  75. } \
  76. } while (0)
  77. #define __UNLOCK(x) \
  78. do { \
  79. (x)->lock = UNLOCK; \
  80. } while (0)
  81. /**
  82. * @}
  83. */
  84. /** @defgroup ALD_Private_Macros Private Macros
  85. * @{
  86. */
  87. #define IS_PRIO(x) ((x) < 4)
  88. #define IS_SYSTICK_INTERVAL(x) (((x) == SYSTICK_INTERVAL_1MS) || \
  89. ((x) == SYSTICK_INTERVAL_10MS) || \
  90. ((x) == SYSTICK_INTERVAL_100MS) || \
  91. ((x) == SYSTICK_INTERVAL_1000MS))
  92. /**
  93. * @}
  94. */
  95. /** @addtogroup ALD_Public_Functions
  96. * @{
  97. */
  98. /** @addtogroup ALD_Public_Functions_Group1
  99. * @{
  100. */
  101. /* Initialization functions */
  102. void ald_cmu_init(void);
  103. void ald_tick_init(uint32_t prio);
  104. void ald_systick_interval_select(systick_interval_t value);
  105. /**
  106. * @}
  107. */
  108. /** @addtogroup ALD_Public_Functions_Group2
  109. * @{
  110. */
  111. /* Peripheral Control functions */
  112. void ald_inc_tick_weak(void);
  113. void ald_delay_ms(__IO uint32_t delay);
  114. uint32_t ald_get_tick(void);
  115. void ald_suspend_tick(void);
  116. void ald_resume_tick(void);
  117. void ald_systick_irq_cbk(void);
  118. void ald_inc_tick(void);
  119. uint32_t ald_get_ald_version(void);
  120. ald_status_t ald_wait_flag(uint32_t *reg, uint32_t bit, flag_status_t status, uint32_t timeout);
  121. void ald_mcu_irq_config(IRQn_Type irq, uint8_t prio, type_func_t status);
  122. uint32_t ald_mcu_get_tick(void);
  123. uint32_t ald_mcu_get_cpu_id(void);
  124. /**
  125. * @}
  126. */
  127. /**
  128. * @}
  129. */
  130. /**
  131. * @}
  132. */
  133. /**
  134. * @}
  135. */
  136. #ifdef __cplusplus
  137. }
  138. #endif
  139. #endif /* __UTILS_H__ */