air105_sysctrl.h 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138
  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. #ifndef __AIR105_SYSCTRL_H
  22. #define __AIR105_SYSCTRL_H
  23. #ifdef __cplusplus
  24. extern "C" {
  25. #endif
  26. /* Includes ------------------------------------------------------------------*/
  27. #include "air105.h"
  28. #define SYSCTRL_FREQ_SEL_POWERMODE_Pos (24)
  29. #define SYSCTRL_FREQ_SEL_POWERMODE_Mask (0x07 << SYSCTRL_FREQ_SEL_POWERMODE_Pos)
  30. #define SYSCTRL_FREQ_SEL_POWERMODE_CLOSE_CPU (0x00 << SYSCTRL_FREQ_SEL_POWERMODE_Pos)
  31. #define SYSCTRL_FREQ_SEL_POWERMODE_CLOSE_CPU_MEM (0x01 << SYSCTRL_FREQ_SEL_POWERMODE_Pos)
  32. /** @defgroup SYSCTRL_Exported_Types
  33. * @{
  34. */
  35. typedef struct
  36. {
  37. uint32_t PLL_Frequency; /*!< returns PLL frequency expressed in Hz */
  38. uint32_t CPU_Frequency; /*!< returns CPU frequency expressed in Hz */
  39. uint32_t HCLK_Frequency; /*!< returns HCLK frequency expressed in Hz */
  40. uint32_t PCLK_Frequency; /*!< returns PCLK frequency expressed in Hz */
  41. }SYSCTRL_ClocksTypeDef;
  42. typedef enum
  43. {
  44. SleepMode_CpuOff = 0, /*!< CPU Sleep */
  45. SleepMode_DeepSleep, /*!< Deep Sleep */
  46. SleepMode_Invalid
  47. }SleepMode_TypeDef;
  48. #define IS_ALL_SLEEP_MODE(MODE) ((MODE) < SleepMode_Invalid)
  49. typedef enum
  50. {
  51. SELECT_EXT12M,
  52. SELECT_INC12M
  53. } SYSCLK_SOURCE_TypeDef;
  54. #define IS_SYSCLK_SOURCE(FREQ) (((FREQ) == SELECT_EXT12M) || \
  55. ((FREQ) == SELECT_INC12M))
  56. typedef enum
  57. {
  58. SYSCTRL_PLL_108MHz = (uint32_t)0x01,
  59. SYSCTRL_PLL_120MHz = (uint32_t)0x02,
  60. SYSCTRL_PLL_132MHz = (uint32_t)0x03,
  61. SYSCTRL_PLL_144MHz = (uint32_t)0x04,
  62. SYSCTRL_PLL_156MHz = (uint32_t)0x05,
  63. SYSCTRL_PLL_168MHz = (uint32_t)0x06,
  64. SYSCTRL_PLL_180MHz = (uint32_t)0x07,
  65. SYSCTRL_PLL_192MHz = (uint32_t)0x08,
  66. SYSCTRL_PLL_204MHz = (uint32_t)0x09
  67. }SYSCTRL_PLL_TypeDef;
  68. #define IS_PLL_FREQ(FREQ) (((FREQ) == SYSCTRL_PLL_108MHz) || \
  69. ((FREQ) == SYSCTRL_PLL_120MHz) || \
  70. ((FREQ) == SYSCTRL_PLL_132MHz) || \
  71. ((FREQ) == SYSCTRL_PLL_144MHz) || \
  72. ((FREQ) == SYSCTRL_PLL_156MHz) || \
  73. ((FREQ) == SYSCTRL_PLL_168MHz) || \
  74. ((FREQ) == SYSCTRL_PLL_180MHz) || \
  75. ((FREQ) == SYSCTRL_PLL_192MHz) || \
  76. ((FREQ) == SYSCTRL_PLL_204MHz))
  77. /**
  78. * @}
  79. */
  80. #define SYSCTRL_PLL_Div_None ((uint32_t)0x00)
  81. #define SYSCTRL_PLL_Div2 ((uint32_t)0x01)
  82. #define SYSCTRL_PLL_Div4 ((uint32_t)0x10)
  83. #define IS_GET_SYSCTRL_PLL_DIV(DIV) (((DIV) == SYSCTRL_PLL_Div_None) || \
  84. ((DIV) == SYSCTRL_PLL_Div2) || \
  85. ((DIV) == SYSCTRL_PLL_Div4))
  86. #define SYSCTRL_HCLK_Div_None ((uint32_t)0x00)
  87. #define SYSCTRL_HCLK_Div2 ((uint32_t)0x01)
  88. #define IS_GET_SYSCTRL_HCLK_DIV(DIV) (((DIV) == SYSCTRL_HCLK_Div_None) || \
  89. ((DIV) == SYSCTRL_HCLK_Div2))
  90. #define SYSCTRL_PCLK_Div2 ((uint32_t)0x01)
  91. #define SYSCTRL_PCLK_Div4 ((uint32_t)0x02)
  92. #define IS_GET_SYSCTRL_PCLK_DIV(DIV) (((DIV) == SYSCTRL_PCLK_Div2) || \
  93. ((DIV) == SYSCTRL_PCLK_Div4))
  94. #define SYSCTRL_CHIP_SN_ADDR ((uint32_t)0x40008804)
  95. #define SYSCTRL_CHIP_SN_LEN ((uint32_t)0x10)
  96. #define SYSCTRL_USB_DOWNLOAD_FLAG ((uint32_t)0X55)
  97. void SYSCTRL_AHBPeriphClockCmd(uint32_t SYSCTRL_AHBPeriph, FunctionalState NewState);
  98. void SYSCTRL_AHBPeriphResetCmd(uint32_t SYSCTRL_AHBPeriph, FunctionalState NewState);
  99. void SYSCTRL_APBPeriphClockCmd(uint32_t SYSCTRL_APBPeriph, FunctionalState NewState);
  100. void SYSCTRL_APBPeriphResetCmd(uint32_t SYSCTRL_APBPeriph, FunctionalState NewState);
  101. void SYSCTRL_EnterSleep(SleepMode_TypeDef SleepMode);
  102. void SYSCTRL_SYSCLKSourceSelect(SYSCLK_SOURCE_TypeDef source_select);
  103. void SYSCTRL_PLLConfig(SYSCTRL_PLL_TypeDef PLL_Freq);
  104. void SYSCTRL_PLLDivConfig(uint32_t PLL_Div);
  105. void SYSCTRL_HCLKConfig(uint32_t HCLK_Div);
  106. void SYSCTRL_PCLKConfig(uint32_t PCLK_Div);
  107. void SYSCTRL_GetClocksFreq(SYSCTRL_ClocksTypeDef* SYSCTRL_Clocks);
  108. void SYSCTRL_GetChipSN(unsigned char *ChipSN);
  109. void SYSCTRL_SoftReset(void);
  110. void SYSCTRL_EnterUSBDownload(void);
  111. #ifdef __cplusplus
  112. }
  113. #endif
  114. #endif
  115. /************************** (C) COPYRIGHT Megahunt *****END OF FILE****/