utils.h 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180
  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. * SPDX-License-Identifier: Apache-2.0
  15. *
  16. * Licensed under the Apache License, Version 2.0 (the License); you may
  17. * not use this file except in compliance with the License.
  18. * You may obtain a copy of the License at
  19. *
  20. * www.apache.org/licenses/LICENSE-2.0
  21. *
  22. * Unless required by applicable law or agreed to in writing, software
  23. * distributed under the License is distributed on an AS IS BASIS, WITHOUT
  24. * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  25. * See the License for the specific language governing permissions and
  26. * limitations under the License.
  27. *
  28. *********************************************************************************
  29. */
  30. #ifndef __UTILS_H__
  31. #define __UTILS_H__
  32. #ifdef __cplusplus
  33. extern "C" {
  34. #endif
  35. #include <stdlib.h>
  36. #include "ald_conf.h"
  37. #include "type.h"
  38. #include "es32f065x.h"
  39. /** @addtogroup ES32FXXX_ALD
  40. * @{
  41. */
  42. /** @addtogroup UTILS
  43. * @{
  44. */
  45. /** @defgroup ALD_Public_Types Public Types
  46. * @{
  47. */
  48. /**
  49. * @brief SysTick interval
  50. */
  51. extern uint32_t __systick_interval;
  52. /**
  53. * @brief ALD Status structures definition
  54. */
  55. typedef enum {
  56. OK = 0x0U, /**< Status: OK */
  57. ERROR = 0x1U, /**< Status: ERROR */
  58. BUSY = 0x2U, /**< Status: BUSY */
  59. TIMEOUT = 0x3U, /**< Status: TIMEOUT */
  60. } ald_status_t;
  61. /**
  62. * @brief SysTick interval definition
  63. */
  64. typedef enum {
  65. SYSTICK_INTERVAL_1MS = 1000U, /**< Interval is 1ms */
  66. SYSTICK_INTERVAL_10MS = 100U, /**< Interval is 10ms */
  67. SYSTICK_INTERVAL_100MS = 10U, /**< Interval is 100ms */
  68. SYSTICK_INTERVAL_1000MS = 1U, /**< Interval is 1s */
  69. } systick_interval_t;
  70. /**
  71. * @}
  72. */
  73. /** @defgroup ALD_Public_Macros Public Macros
  74. * @{
  75. */
  76. #define ALD_MAX_DELAY 0xFFFFFFFFU
  77. #define IS_BIT_SET(reg, bit) (((reg) & (bit)) != RESET)
  78. #define IS_BIT_CLR(reg, bit) (((reg) & (bit)) == RESET)
  79. #define RESET_HANDLE_STATE(x) ((x)->state = 0)
  80. #define __LOCK(x) \
  81. do { \
  82. if ((x)->lock == LOCK) { \
  83. return BUSY; \
  84. } \
  85. else { \
  86. (x)->lock = LOCK; \
  87. } \
  88. } while (0)
  89. #define __UNLOCK(x) \
  90. do { \
  91. (x)->lock = UNLOCK; \
  92. } while (0)
  93. /**
  94. * @}
  95. */
  96. /** @defgroup ALD_Private_Macros Private Macros
  97. * @{
  98. */
  99. #define MCU_UID0_ADDR 0x000403E0U
  100. #define MCU_UID1_ADDR 0x000403E8U
  101. #define MCU_UID2_ADDR 0x000403F0U
  102. #define MCU_CHIPID_ADDR 0x000403F8U
  103. #define IS_PRIO(x) ((x) < 4)
  104. #define IS_SYSTICK_INTERVAL(x) (((x) == SYSTICK_INTERVAL_1MS) || \
  105. ((x) == SYSTICK_INTERVAL_10MS) || \
  106. ((x) == SYSTICK_INTERVAL_100MS) || \
  107. ((x) == SYSTICK_INTERVAL_1000MS))
  108. /**
  109. * @}
  110. */
  111. /** @addtogroup ALD_Public_Functions
  112. * @{
  113. */
  114. /** @addtogroup ALD_Public_Functions_Group1
  115. * @{
  116. */
  117. /* Initialization functions */
  118. void ald_cmu_init(void);
  119. void ald_tick_init(uint32_t prio);
  120. void ald_systick_interval_select(systick_interval_t value);
  121. /**
  122. * @}
  123. */
  124. /** @addtogroup ALD_Public_Functions_Group2
  125. * @{
  126. */
  127. /* Peripheral Control functions */
  128. void ald_inc_tick_weak(void);
  129. void ald_delay_ms(__IO uint32_t delay);
  130. uint32_t ald_get_tick(void);
  131. void ald_suspend_tick(void);
  132. void ald_resume_tick(void);
  133. void ald_systick_irq_cbk(void);
  134. void ald_inc_tick(void);
  135. uint32_t ald_get_ald_version(void);
  136. ald_status_t ald_wait_flag(uint32_t *reg, uint32_t bit, flag_status_t status, uint32_t timeout);
  137. void ald_mcu_irq_config(IRQn_Type irq, uint8_t prio, type_func_t status);
  138. uint32_t ald_mcu_get_tick(void);
  139. uint32_t ald_mcu_get_cpu_id(void);
  140. void ald_mcu_get_uid(uint8_t *buf);
  141. uint32_t ald_mcu_get_chipid(void);
  142. /**
  143. * @}
  144. */
  145. /**
  146. * @}
  147. */
  148. /**
  149. * @}
  150. */
  151. /**
  152. * @}
  153. */
  154. #ifdef __cplusplus
  155. }
  156. #endif
  157. #endif /* __UTILS_H__ */