utils.h 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187
  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 2019
  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. #ifdef ES32F36xx
  25. #include "es32f36xx.h"
  26. #elif ES32F39xx
  27. #include "es32f39xx.h"
  28. #elif ES32F336x
  29. #include "es32f336x.h"
  30. #endif
  31. /** @addtogroup ES32FXXX_ALD
  32. * @{
  33. */
  34. /** @addtogroup UTILS
  35. * @{
  36. */
  37. /** @defgroup ALD_Public_Types Public Types
  38. * @{
  39. */
  40. /**
  41. * @brief SysTick interval
  42. */
  43. extern uint32_t __systick_interval;
  44. /**
  45. * @brief ALD Status structures definition
  46. */
  47. typedef enum {
  48. OK = 0x0, /**< OK */
  49. ERROR = 0x1, /**< ERROR */
  50. BUSY = 0x2, /**< BUSY */
  51. TIMEOUT = 0x3 /**< TIMEOUT */
  52. } ald_status_t;
  53. /**
  54. * @brief NVIC Preemption Priority Group
  55. */
  56. typedef enum {
  57. NVIC_PRIORITY_GROUP_0 = 0x7, /**< 0-bits for pre-emption priority 4-bits for subpriority */
  58. NVIC_PRIORITY_GROUP_1 = 0x6, /**< 1-bits for pre-emption priority 3-bits for subpriority */
  59. NVIC_PRIORITY_GROUP_2 = 0x5, /**< 2-bits for pre-emption priority 2-bits for subpriority */
  60. NVIC_PRIORITY_GROUP_3 = 0x4, /**< 3-bits for pre-emption priority 1-bits for subpriority */
  61. NVIC_PRIORITY_GROUP_4 = 0x3, /**< 4-bits for pre-emption priority 0-bits for subpriority */
  62. } nvic_priority_group_t;
  63. /**
  64. * @brief SysTick interval definition
  65. */
  66. typedef enum {
  67. SYSTICK_INTERVAL_1MS = 1000, /**< Interval is 1ms */
  68. SYSTICK_INTERVAL_10MS = 100, /**< Interval is 10ms */
  69. SYSTICK_INTERVAL_100MS = 10, /**< Interval is 100ms */
  70. SYSTICK_INTERVAL_1000MS = 1, /**< Interval is 1s */
  71. } systick_interval_t;
  72. /**
  73. * @}
  74. */
  75. /** @defgroup ALD_Public_Macros Public Macros
  76. * @{
  77. */
  78. #define ALD_MAX_DELAY 0xFFFFFFFF
  79. #define IS_BIT_SET(reg, bit) (((reg) & (bit)) != RESET)
  80. #define IS_BIT_CLR(reg, bit) (((reg) & (bit)) == RESET)
  81. #define RESET_HANDLE_STATE(x) ((x)->state = 0)
  82. #define DWT_CR *(uint32_t *)0xE0001000
  83. #define DWT_CYCCNT *(volatile uint32_t *)0xE0001004
  84. #define DEM_CR *(uint32_t *)0xE000EDFC
  85. #define DEM_CR_TRCENA (1U << 24)
  86. #define DWT_CR_CYCCNTEA (1U << 0)
  87. #define __LOCK(x) \
  88. do { \
  89. if ((x)->lock == LOCK) { \
  90. return BUSY; \
  91. } \
  92. else { \
  93. (x)->lock = LOCK; \
  94. } \
  95. } while (0)
  96. #define __UNLOCK(x) \
  97. do { \
  98. (x)->lock = UNLOCK; \
  99. } while (0)
  100. #define ALD_PANIC() \
  101. do { \
  102. while (1) \
  103. ; \
  104. } while (0)
  105. /**
  106. * @}
  107. */
  108. /** @defgroup ALD_Private_Macros Private Macros
  109. * @{
  110. */
  111. #define IS_PREEMPT_PRIO(x) ((x) < 16)
  112. #define IS_SUB_PRIO(x) ((x) < 16)
  113. #define IS_SYSTICK_INTERVAL(x) (((x) == SYSTICK_INTERVAL_1MS) || \
  114. ((x) == SYSTICK_INTERVAL_10MS) || \
  115. ((x) == SYSTICK_INTERVAL_100MS) || \
  116. ((x) == SYSTICK_INTERVAL_1000MS))
  117. /**
  118. * @}
  119. */
  120. /** @addtogroup ALD_Public_Functions
  121. * @{
  122. */
  123. /** @addtogroup ALD_Public_Functions_Group1
  124. * @{
  125. */
  126. /* Initialization functions */
  127. void ald_cmu_init(void);
  128. void ald_tick_init(uint32_t prio);
  129. void ald_systick_interval_select(systick_interval_t value);
  130. /**
  131. * @}
  132. */
  133. /** @addtogroup ALD_Public_Functions_Group2
  134. * @{
  135. */
  136. /* Peripheral Control functions */
  137. void ald_inc_tick(void);
  138. void ald_systick_irq_cbk(void);
  139. void ald_delay_ms(__IO uint32_t delay);
  140. uint32_t ald_get_tick(void);
  141. void ald_suspend_tick(void);
  142. void ald_resume_tick(void);
  143. uint32_t ald_get_ald_version(void);
  144. ald_status_t ald_wait_flag(uint32_t *reg, uint32_t bit, flag_status_t status, uint32_t timeout);
  145. void ald_mcu_irq_config(IRQn_Type irq, uint8_t preempt_prio, uint8_t sub_prio, type_func_t status);
  146. uint32_t ald_mcu_get_cpu_id(void);
  147. void ald_mcu_timestamp_init(void);
  148. uint32_t ald_mcu_get_timestamp(void);
  149. /**
  150. * @}
  151. */
  152. /**
  153. * @}
  154. */
  155. /**
  156. * @}
  157. */
  158. /**
  159. * @}
  160. */
  161. #ifdef __cplusplus
  162. }
  163. #endif
  164. #endif /* __UTILS_H__ */