1 /* 2 * Copyright (c) 2022 OpenLuat & AirM2M 3 * 4 * Permission is hereby granted, free of charge, to any person obtaining a copy of 5 * this software and associated documentation files (the "Software"), to deal in 6 * the Software without restriction, including without limitation the rights to 7 * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of 8 * the Software, and to permit persons to whom the Software is furnished to do so, 9 * subject to the following conditions: 10 * 11 * The above copyright notice and this permission notice shall be included in all 12 * copies or substantial portions of the Software. 13 * 14 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS 16 * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR 17 * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER 18 * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 19 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 20 */ 21 22 23 24 #ifndef __AIR105_SYSCTRL_H 25 #define __AIR105_SYSCTRL_H 26 27 #ifdef __cplusplus 28 extern "C" { 29 #endif 30 31 /* Includes ------------------------------------------------------------------*/ 32 #include "air105.h" 33 34 #define SYSCTRL_FREQ_SEL_POWERMODE_Pos (24) 35 #define SYSCTRL_FREQ_SEL_POWERMODE_Mask (0x07 << SYSCTRL_FREQ_SEL_POWERMODE_Pos) 36 #define SYSCTRL_FREQ_SEL_POWERMODE_CLOSE_CPU (0x00 << SYSCTRL_FREQ_SEL_POWERMODE_Pos) 37 #define SYSCTRL_FREQ_SEL_POWERMODE_CLOSE_CPU_MEM (0x01 << SYSCTRL_FREQ_SEL_POWERMODE_Pos) 38 39 40 /** @defgroup SYSCTRL_Exported_Types 41 * @{ 42 */ 43 typedef struct 44 { 45 uint32_t PLL_Frequency; /*!< returns PLL frequency expressed in Hz */ 46 uint32_t CPU_Frequency; /*!< returns CPU frequency expressed in Hz */ 47 uint32_t HCLK_Frequency; /*!< returns HCLK frequency expressed in Hz */ 48 uint32_t PCLK_Frequency; /*!< returns PCLK frequency expressed in Hz */ 49 }SYSCTRL_ClocksTypeDef; 50 51 typedef enum 52 { 53 SleepMode_CpuOff = 0, /*!< CPU Sleep */ 54 SleepMode_DeepSleep, /*!< Deep Sleep */ 55 SleepMode_Invalid 56 }SleepMode_TypeDef; 57 #define IS_ALL_SLEEP_MODE(MODE) ((MODE) < SleepMode_Invalid) 58 59 typedef enum 60 { 61 SELECT_EXT12M, 62 SELECT_INC12M 63 } SYSCLK_SOURCE_TypeDef; 64 #define IS_SYSCLK_SOURCE(FREQ) (((FREQ) == SELECT_EXT12M) || \ 65 ((FREQ) == SELECT_INC12M)) 66 typedef enum 67 { 68 SYSCTRL_PLL_108MHz = (uint32_t)0x01, 69 SYSCTRL_PLL_120MHz = (uint32_t)0x02, 70 SYSCTRL_PLL_132MHz = (uint32_t)0x03, 71 SYSCTRL_PLL_144MHz = (uint32_t)0x04, 72 SYSCTRL_PLL_156MHz = (uint32_t)0x05, 73 SYSCTRL_PLL_168MHz = (uint32_t)0x06, 74 SYSCTRL_PLL_180MHz = (uint32_t)0x07, 75 SYSCTRL_PLL_192MHz = (uint32_t)0x08, 76 SYSCTRL_PLL_204MHz = (uint32_t)0x09 77 }SYSCTRL_PLL_TypeDef; 78 #define IS_PLL_FREQ(FREQ) (((FREQ) == SYSCTRL_PLL_108MHz) || \ 79 ((FREQ) == SYSCTRL_PLL_120MHz) || \ 80 ((FREQ) == SYSCTRL_PLL_132MHz) || \ 81 ((FREQ) == SYSCTRL_PLL_144MHz) || \ 82 ((FREQ) == SYSCTRL_PLL_156MHz) || \ 83 ((FREQ) == SYSCTRL_PLL_168MHz) || \ 84 ((FREQ) == SYSCTRL_PLL_180MHz) || \ 85 ((FREQ) == SYSCTRL_PLL_192MHz) || \ 86 ((FREQ) == SYSCTRL_PLL_204MHz)) 87 /** 88 * @} 89 */ 90 91 #define SYSCTRL_PLL_Div_None ((uint32_t)0x00) 92 #define SYSCTRL_PLL_Div2 ((uint32_t)0x01) 93 #define SYSCTRL_PLL_Div4 ((uint32_t)0x10) 94 #define IS_GET_SYSCTRL_PLL_DIV(DIV) (((DIV) == SYSCTRL_PLL_Div_None) || \ 95 ((DIV) == SYSCTRL_PLL_Div2) || \ 96 ((DIV) == SYSCTRL_PLL_Div4)) 97 98 #define SYSCTRL_HCLK_Div_None ((uint32_t)0x00) 99 #define SYSCTRL_HCLK_Div2 ((uint32_t)0x01) 100 #define IS_GET_SYSCTRL_HCLK_DIV(DIV) (((DIV) == SYSCTRL_HCLK_Div_None) || \ 101 ((DIV) == SYSCTRL_HCLK_Div2)) 102 103 #define SYSCTRL_PCLK_Div2 ((uint32_t)0x01) 104 #define SYSCTRL_PCLK_Div4 ((uint32_t)0x02) 105 #define IS_GET_SYSCTRL_PCLK_DIV(DIV) (((DIV) == SYSCTRL_PCLK_Div2) || \ 106 ((DIV) == SYSCTRL_PCLK_Div4)) 107 108 #define SYSCTRL_CHIP_SN_ADDR ((uint32_t)0x40008804) 109 #define SYSCTRL_CHIP_SN_LEN ((uint32_t)0x10) 110 111 #define SYSCTRL_USB_DOWNLOAD_FLAG ((uint32_t)0X55) 112 113 void SYSCTRL_AHBPeriphClockCmd(uint32_t SYSCTRL_AHBPeriph, FunctionalState NewState); 114 void SYSCTRL_AHBPeriphResetCmd(uint32_t SYSCTRL_AHBPeriph, FunctionalState NewState); 115 void SYSCTRL_APBPeriphClockCmd(uint32_t SYSCTRL_APBPeriph, FunctionalState NewState); 116 void SYSCTRL_APBPeriphResetCmd(uint32_t SYSCTRL_APBPeriph, FunctionalState NewState); 117 118 void SYSCTRL_EnterSleep(SleepMode_TypeDef SleepMode); 119 120 void SYSCTRL_SYSCLKSourceSelect(SYSCLK_SOURCE_TypeDef source_select); 121 void SYSCTRL_PLLConfig(SYSCTRL_PLL_TypeDef PLL_Freq); 122 void SYSCTRL_PLLDivConfig(uint32_t PLL_Div); 123 void SYSCTRL_HCLKConfig(uint32_t HCLK_Div); 124 void SYSCTRL_PCLKConfig(uint32_t PCLK_Div); 125 126 void SYSCTRL_GetClocksFreq(SYSCTRL_ClocksTypeDef* SYSCTRL_Clocks); 127 void SYSCTRL_GetChipSN(unsigned char *ChipSN); 128 129 void SYSCTRL_SoftReset(void); 130 void SYSCTRL_EnterUSBDownload(void); 131 132 #ifdef __cplusplus 133 } 134 #endif 135 136 #endif 137 138 /************************** (C) COPYRIGHT Megahunt *****END OF FILE****/ 139