system_ac780x.h 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229
  1. /* Copyright Statement:
  2. *
  3. * This software/firmware and related documentation ("AutoChips Software") are
  4. * protected under relevant copyright laws. The information contained herein is
  5. * confidential and proprietary to AutoChips Inc. and/or its licensors. Without
  6. * the prior written permission of AutoChips inc. and/or its licensors, any
  7. * reproduction, modification, use or disclosure of AutoChips Software, and
  8. * information contained herein, in whole or in part, shall be strictly
  9. * prohibited.
  10. *
  11. * AutoChips Inc. (C) 2020. All rights reserved.
  12. *
  13. * BY OPENING THIS FILE, RECEIVER HEREBY UNEQUIVOCALLY ACKNOWLEDGES AND AGREES
  14. * THAT THE SOFTWARE/FIRMWARE AND ITS DOCUMENTATIONS ("AUTOCHIPS SOFTWARE")
  15. * RECEIVED FROM AUTOCHIPS AND/OR ITS REPRESENTATIVES ARE PROVIDED TO RECEIVER
  16. * ON AN "AS-IS" BASIS ONLY. AUTOCHIPS EXPRESSLY DISCLAIMS ANY AND ALL
  17. * WARRANTIES, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED
  18. * WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE OR
  19. * NONINFRINGEMENT. NEITHER DOES AUTOCHIPS PROVIDE ANY WARRANTY WHATSOEVER WITH
  20. * RESPECT TO THE SOFTWARE OF ANY THIRD PARTY WHICH MAY BE USED BY,
  21. * INCORPORATED IN, OR SUPPLIED WITH THE AUTOCHIPS SOFTWARE, AND RECEIVER AGREES
  22. * TO LOOK ONLY TO SUCH THIRD PARTY FOR ANY WARRANTY CLAIM RELATING THERETO.
  23. * RECEIVER EXPRESSLY ACKNOWLEDGES THAT IT IS RECEIVER'S SOLE RESPONSIBILITY TO
  24. * OBTAIN FROM ANY THIRD PARTY ALL PROPER LICENSES CONTAINED IN AUTOCHIPS
  25. * SOFTWARE. AUTOCHIPS SHALL ALSO NOT BE RESPONSIBLE FOR ANY AUTOCHIPS SOFTWARE
  26. * RELEASES MADE TO RECEIVER'S SPECIFICATION OR TO CONFORM TO A PARTICULAR
  27. * STANDARD OR OPEN FORUM. RECEIVER'S SOLE AND EXCLUSIVE REMEDY AND AUTOCHIPS'S
  28. * ENTIRE AND CUMULATIVE LIABILITY WITH RESPECT TO THE AUTOCHIPS SOFTWARE
  29. * RELEASED HEREUNDER WILL BE, AT AUTOCHIPS'S OPTION, TO REVISE OR REPLACE THE
  30. * AUTOCHIPS SOFTWARE AT ISSUE, OR REFUND ANY SOFTWARE LICENSE FEES OR SERVICE
  31. * CHARGE PAID BY RECEIVER TO AUTOCHIPS FOR SUCH AUTOCHIPS SOFTWARE AT ISSUE.
  32. */
  33. #ifndef _SYSTEM_AC780X_H
  34. #define _SYSTEM_AC780X_H
  35. /*!
  36. * @file system_ac780x.h
  37. *
  38. * @brief This file provides system clock config integration functions interfaces.
  39. *
  40. */
  41. #ifdef __cplusplus
  42. extern "C" {
  43. #endif
  44. /* =========================================== Includes =========================================== */
  45. #include "ac780x_ckgen.h"
  46. #include "ac780x_spm.h"
  47. #include "device_assert.h"
  48. #include "ac780x_debugout.h"
  49. /* ============================================ Define ============================================ */
  50. /*!< global interrupt control */
  51. #define EnableInterrupts __ASM(" CPSIE i");
  52. #define DisableInterrupts __ASM(" CPSID i");
  53. /*!< global fault control */
  54. #define EnableFatules __ASM(" CPSIE F");
  55. #define DisableFatules __ASM(" CPSID F");
  56. #define IC_CLOCK_SRC_HSI 0U /*!< High speed internal RC(HSI): The internal RC OSC to provide 8MHz clock source */
  57. #define IC_CLOCK_SRC_HSE 1U /*!< The external OSC to provide 4MHZ ~30MHz crystal */
  58. #define IC_CLOCK_SRC_XOSC 2U /*!< The external OSC to provide 4MHZ ~30MHz oscillator */
  59. #define IC_CLOCK_SRC_XOSC_BYPASS 3U /*!< The external OSC to provide 4MHZ ~30MHz oscillator */
  60. #define AC780X_CLOCK_SRC IC_CLOCK_SRC_HSI /*!< define mcu clock source */
  61. #define HSI_FREQ 8000000UL /*!< Internal 8M RC clock */
  62. #define XTAL_16M 16000000UL /*!< extern crystal oscillator 16m */
  63. #define XTAL_12M 12000000UL /*!< extern crystal oscillator 12m */
  64. #define XTAL_8M 8000000UL /*!< extern crystal oscillator 8m */
  65. #define XTAL_4M 4000000UL /*!< extern crystal oscillator 4m */
  66. #define XTAL_30M 30000000UL /*!< extern crystal oscillator 30m */
  67. #define USE_XTAL XTAL_8M /*!< Select the actual crystal frequency */
  68. /*!< PLL available in HSE & HSI mode */
  69. #if USE_XTAL == XTAL_16M
  70. #define PLL_POSDIV PLL_POSDIV_16
  71. #define PLL_FBKDIV 96U
  72. #define PLL_PREDIV PLL_PREDIV_2
  73. #elif USE_XTAL == XTAL_12M
  74. #define PLL_POSDIV PLL_POSDIV_12
  75. #define PLL_FBKDIV 96U
  76. #define PLL_PREDIV PLL_PREDIV_2
  77. #elif USE_XTAL == XTAL_8M
  78. #define PLL_POSDIV PLL_POSDIV_24
  79. #define PLL_FBKDIV 48U
  80. #define PLL_PREDIV PLL_PREDIV_1
  81. #elif USE_XTAL == XTAL_4M
  82. #define PLL_POSDIV PLL_POSDIV_16
  83. #define PLL_FBKDIV 192U
  84. #define PLL_PREDIV PLL_PREDIV_1
  85. #elif USE_XTAL == XTAL_30M
  86. #define PLL_POSDIV PLL_POSDIV_30
  87. #define PLL_FBKDIV 48U
  88. #define PLL_PREDIV PLL_PREDIV_1
  89. #else
  90. #error
  91. #endif
  92. /*!< VCO = (USE_XTAL * PLL_FBKDIV) / PLL_PREDIV;
  93. SYSCLK_FREQ = VCO / PLL_POSDIV / SYSCLK_DIV;
  94. APB_BUS_FREQ = SYSCLK_FREQ / APBCLK_DIVIDER_2
  95. */
  96. #define SYSCLK_DIV SYSCLK_DIVIDER_1
  97. #define APBCLK_DIV APBCLK_DIVIDER_2
  98. #define SYSCLK_FREQ 16000000UL
  99. #define APB_BUS_FREQ 8000000UL
  100. #define __SYSTEM_CLOCK SYSCLK_FREQ
  101. /* =========================================== Typedef ============================================ */
  102. /* ========================================== Variables =========================================== */
  103. extern uint32_t SystemCoreClock; /*!< System Clock Frequency (Core Clock) */
  104. extern uint32_t g_periphAPBClock; /*!< APB Clock Frequency */
  105. /* ==================================== Functions declaration ===================================== */
  106. /*!
  107. * @brief Setup the microcontroller system. Initialize the System.
  108. *
  109. * @param[in] none
  110. * @return none
  111. */
  112. extern void SystemInit (void);
  113. /*!
  114. * @brief get system clock frequence
  115. *
  116. * @param[in] none
  117. * @return none
  118. */
  119. extern void SystemCoreClockUpdate(void);
  120. /*!
  121. * @brief Init Delay count factor, 1s = TICKS * (1/f) s;
  122. *
  123. * @param[in] none
  124. * @return none
  125. */
  126. extern void udelay(uint32_t us);
  127. /*!
  128. * @brief delay ms
  129. *
  130. * @param[in] param : ms, us for delay
  131. * @return none
  132. */
  133. extern void mdelay(uint32_t ms);
  134. /*!
  135. * @brief Init Delay count factor, 1s = TICKS * (1/f) s;
  136. *
  137. * @param[in] none
  138. * @return none
  139. */
  140. extern void InitDelay(void);
  141. /*!
  142. * @brief enter the Sleep mode
  143. *
  144. * @param[in] none
  145. * @return none
  146. */
  147. extern void SysSleep(void);
  148. /*!
  149. * @brief enter the Stop mode
  150. *
  151. * @param[in] none
  152. * @return none
  153. */
  154. extern void SysStop(void);
  155. /*!
  156. * @brief enter the Standby mode
  157. *
  158. * @param[in] none
  159. * @return none
  160. */
  161. extern void SysStandby(void);
  162. /*!
  163. * @brief get uuid from devie
  164. *
  165. * @param[in] uuidBuffer: uuid buffer
  166. * @return none
  167. */
  168. extern void GetUUID(uint32_t *uuidBuffer);
  169. /*!
  170. * @brief get cpu type from device
  171. *
  172. * @param[in] none
  173. * @return cpu type: AC7801(0xFFAC7801)/AC7811(0xFFAC7811)
  174. */
  175. extern uint32_t GetCpuType(void);
  176. /*!
  177. * @brief get reset status
  178. *
  179. * @param[in] none
  180. * @return reset status
  181. * - bit0: POR_RESET_STATUS
  182. * - bit1: LVD_RESET_STATUS
  183. * - bit2: EXT_RESET_STATUS
  184. * - bit4: WDT_RESET_STATUS
  185. * - bit5: WDT_32K_RESET_STATUS
  186. * - bit6: CPU_SYSRESET_STATUS
  187. * - bit7: CPU_LOCKUP_RST_STATUS
  188. * - bit8: PLL_UNLOCK_RST_STATUS
  189. * - bit9: XOSC_LOSS_STATUS
  190. * - bit16: CLEAR_ALL_RESET_STATUS
  191. */
  192. extern uint32_t GetResetStatus(void);
  193. /*!
  194. * @brief clear all reset status
  195. *
  196. * @param[in] none
  197. * @return none
  198. */
  199. extern void ClearAllResetStatus(void);
  200. #ifdef __cplusplus
  201. }
  202. #endif
  203. #endif /* _SYSTEM_AC780X_H */
  204. /* ============================================= EOF ============================================== */