1 /** 2 ****************************************************************************** 3 * @file bl616_clock.h 4 * @version V1.0 5 * @date 6 * @brief This file is the standard driver header file 7 ****************************************************************************** 8 * @attention 9 * 10 * <h2><center>© COPYRIGHT(c) 2020 Bouffalo Lab</center></h2> 11 * 12 * Redistribution and use in source and binary forms, with or without modification, 13 * are permitted provided that the following conditions are met: 14 * 1. Redistributions of source code must retain the above copyright notice, 15 * this list of conditions and the following disclaimer. 16 * 2. Redistributions in binary form must reproduce the above copyright notice, 17 * this list of conditions and the following disclaimer in the documentation 18 * and/or other materials provided with the distribution. 19 * 3. Neither the name of Bouffalo Lab nor the names of its contributors 20 * may be used to endorse or promote products derived from this software 21 * without specific prior written permission. 22 * 23 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 24 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 25 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 26 * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE 27 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 28 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 29 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 30 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 31 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 32 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 33 * 34 ****************************************************************************** 35 */ 36 #ifndef __BL616_CLOCK_H__ 37 #define __BL616_CLOCK_H__ 38 39 #include "glb_reg.h" 40 #include "mcu_misc_reg.h" 41 #include "pds_reg.h" 42 #include "bl616_glb.h" 43 #include "bl616_hbn.h" 44 #include "bl616_common.h" 45 46 /** @addtogroup BL616_Peripheral_Driver 47 * @{ 48 */ 49 50 /** @addtogroup CLOCK 51 * @{ 52 */ 53 54 /** @defgroup CLOCK_Public_Types 55 * @{ 56 */ 57 58 /** 59 * @brief System clock type definition 60 */ 61 typedef enum { 62 BL_SYSTEM_CLOCK_MCU_ROOT_CLK, /*!< MCU root clock */ 63 BL_SYSTEM_CLOCK_MCU_CLK, /*!< MCU Fast clock/CPU clock */ 64 BL_SYSTEM_CLOCK_MCU_BCLK, /*!< MCU BUS clock */ 65 BL_SYSTEM_CLOCK_MCU_PBCLK, /*!< MCU peri BUS clock */ 66 BL_SYSTEM_CLOCK_F32K, /*!< F32K clock */ 67 BL_SYSTEM_CLOCK_XCLK, /*!< XCLK:RC32M or XTAL */ 68 BL_SYSTEM_CLOCK_XTAL, /*!< XTAL clock */ 69 BL_SYSTEM_CLOCK_MAX, /*!< MAX type of system clock */ 70 } BL_System_Clock_Type; 71 72 typedef enum { 73 BL_MTIMER_SOURCE_CLOCK_MCU_XCLK, /*!< MCU xclk clock */ 74 BL_MTIMER_SOURCE_CLOCK_MCU_CLK, /*!< MCU root clock */ 75 } BL_MTimer_Source_Clock_Type; 76 77 /** 78 * @brief SOC clock config type 79 */ 80 typedef struct 81 { 82 uint32_t magic; /*!< Clock config magic */ 83 uint32_t systemClock[BL_SYSTEM_CLOCK_MAX]; /*!< System lock value */ 84 uint32_t peripheralClock[BL_AHB_SLAVE1_MAX]; /*!< Pewripherals clock value */ 85 uint32_t i2sClock; /*!< I2S clock */ 86 } Clock_Cfg_Type; 87 88 typedef enum { 89 CLOCK_AUPLL_DIV1, 90 CLOCK_AUPLL_DIV2, 91 CLOCK_AUPLL_DIV2P5, 92 CLOCK_AUPLL_DIV3, 93 CLOCK_AUPLL_DIV4, 94 CLOCK_AUPLL_DIV5, 95 CLOCK_AUPLL_DIV6, 96 CLOCK_AUPLL_DIV10, 97 CLOCK_AUPLL_DIV15, 98 } CLOCK_AUPLL_Type; 99 /** 100 * @brief Peripheral clock type definition 101 */ 102 typedef enum { 103 BL_PERIPHERAL_CLOCK_UART0, /*!< UART0 clock */ 104 BL_PERIPHERAL_CLOCK_UART1, /*!< UART1 clock */ 105 BL_PERIPHERAL_CLOCK_UART2, /*!< UART2 clock */ 106 BL_PERIPHERAL_CLOCK_SPI, /*!< SPI clock */ 107 BL_PERIPHERAL_CLOCK_RESERVED, /*!< reserved clock */ 108 BL_PERIPHERAL_CLOCK_DBI, /*!< DBI clock */ 109 BL_PERIPHERAL_CLOCK_EMI, /*!< EMI clock */ 110 BL_PERIPHERAL_CLOCK_ISP, /*!< ISP clock */ 111 BL_PERIPHERAL_CLOCK_I2C0, /*!< I2C0 clock */ 112 BL_PERIPHERAL_CLOCK_I2C1, /*!< I2C1 clock */ 113 BL_PERIPHERAL_CLOCK_PSRAMB, /*!< PSRAMB clock */ 114 BL_PERIPHERAL_CLOCK_FLASH, /*!< FLASH clock */ 115 BL_PERIPHERAL_CLOCK_I2S, /*!< I2S clock */ 116 BL_PERIPHERAL_CLOCK_IR, /*!< IR clock */ 117 BL_PERIPHERAL_CLOCK_ADC, /*!< ADC clock */ 118 BL_PERIPHERAL_CLOCK_GPADC, /*!< GPADC clock */ 119 BL_PERIPHERAL_CLOCK_GPDAC, /*!< GPDAC clock */ 120 BL_PERIPHERAL_CLOCK_CAM, /*!< CAM clock */ 121 BL_PERIPHERAL_CLOCK_SDH, /*!< SDH clock */ 122 BL_PERIPHERAL_CLOCK_PKA, /*!< PKA clock */ 123 BL_PERIPHERAL_CLOCK_MAX, 124 } BL_Peripheral_Type; 125 126 /*@} end of group CLOCK_Public_Types */ 127 128 /** @defgroup CLOCK_Public_Constants 129 * @{ 130 */ 131 132 /** @defgroup BL_SYSTEM_CLOCK_TYPE 133 * @{ 134 */ 135 #define IS_BL_SYSTEM_CLOCK_TYPE(type) (((type) == BL_SYSTEM_CLOCK_MCU_ROOT_CLK) || \ 136 ((type) == BL_SYSTEM_CLOCK_MCU_CLK) || \ 137 ((type) == BL_SYSTEM_CLOCK_MCU_BCLK) || \ 138 ((type) == BL_SYSTEM_CLOCK_MCU_PBCLK) || \ 139 ((type) == BL_SYSTEM_CLOCK_DSP_ROOT_CLK) || \ 140 ((type) == BL_SYSTEM_CLOCK_DSP_CLK) || \ 141 ((type) == BL_SYSTEM_CLOCK_DSP_BCLK) || \ 142 ((type) == BL_SYSTEM_CLOCK_DSP_PBCLK) || \ 143 ((type) == BL_SYSTEM_CLOCK_LP_CLK) || \ 144 ((type) == BL_SYSTEM_CLOCK_F32K) || \ 145 ((type) == BL_SYSTEM_CLOCK_XCLK) || \ 146 ((type) == BL_SYSTEM_CLOCK_XTAL) || \ 147 ((type) == BL_SYSTEM_CLOCK_MAX)) 148 149 /*@} end of group CLOCK_Public_Constants */ 150 151 /** @defgroup CLOCK_Public_Macros 152 * @{ 153 */ 154 #define SYS_CLOCK_CFG_MAGIC (0x12345678) 155 #define SYS_CLOCK_CFG_ADDR (0x20010000 + 4 * 1024 - 512) 156 157 /*@} end of group CLOCK_Public_Macros */ 158 159 /** @defgroup CLOCK_Public_Functions 160 * @{ 161 */ 162 /*----------*/ 163 uint32_t Clock_System_Clock_Get(BL_System_Clock_Type type); 164 uint32_t Clock_Peripheral_Clock_Get(BL_Peripheral_Type type); 165 uint32_t Clock_Audio_ADC_Clock_Get(void); 166 uint32_t Clock_Audio_DAC_Clock_Get(void); 167 /*----------*/ 168 uint32_t SystemCoreClockGet(void); 169 /*----------*/ 170 BL_Err_Type CPU_Set_MTimer_RST(uint8_t rstEn); 171 BL_Err_Type CPU_Reset_MTimer(void); 172 BL_Err_Type CPU_Set_MTimer_CLK(uint8_t enable, BL_MTimer_Source_Clock_Type mTimerSourceClockType, uint16_t div); 173 uint32_t CPU_Get_MTimer_Source_Clock(void); 174 uint32_t CPU_Get_MTimer_Clock(void); 175 uint64_t CPU_Get_MTimer_Counter(void); 176 uint64_t CPU_Get_CPU_Cycle(void); 177 uint64_t CPU_Get_MTimer_US(void); 178 uint64_t CPU_Get_MTimer_MS(void); 179 BL_Err_Type CPU_MTimer_Delay_US(uint32_t cnt); 180 BL_Err_Type CPU_MTimer_Delay_MS(uint32_t cnt); 181 uint32_t Clock_Get_EMI_Clk(void); 182 uint32_t Clock_Get_ISP_Clk(void); 183 uint32_t Clock_Get_BLAI_Clk(void); 184 uint32_t Clock_Get_Display_Clk(void); 185 uint32_t Clock_Get_PSRAMB_Clk(void); 186 uint32_t Clock_Get_PSRAMB_Clk(void); 187 uint32_t Clock_Get_H264_Clk(void); 188 /*----------*/ 189 190 /*@} end of group CLOCK_Public_Functions */ 191 192 /*@} end of group CLOCK */ 193 194 /*@} end of group BL616_Peripheral_Driver */ 195 196 #endif /* __BL616_CLOCK_H__ */ 197