fw_rcc.h 2.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. // Copyright 2021 IOsetting <iosetting(at)outlook.com>
  2. //
  3. // Licensed under the Apache License, Version 2.0 (the "License");
  4. // you may not use this file except in compliance with the License.
  5. // You may obtain a copy of the License at
  6. //
  7. // http://www.apache.org/licenses/LICENSE-2.0
  8. //
  9. // Unless required by applicable law or agreed to in writing, software
  10. // distributed under the License is distributed on an "AS IS" BASIS,
  11. // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. // See the License for the specific language governing permissions and
  13. // limitations under the License.
  14. #ifndef ___FW_RCC_H___
  15. #define ___FW_RCC_H___
  16. #include "fw_conf.h"
  17. #include "fw_types.h"
  18. typedef enum
  19. {
  20. RCC_SYSCLKSource_HSI = 0x00, /* Internal high speed RC osc */
  21. RCC_SYSCLKSource_HSE = 0x01, /* External high speed osc */
  22. RCC_SYSCLKSource_LSE = 0x02, /* External 32KHz osc */
  23. RCC_SYSCLKSource_LSI = 0x03, /* Internal 32KHz RC osc */
  24. } RCC_SYSCLKSource_t;
  25. typedef enum
  26. {
  27. RCC_LowVoltResetPinAF_IO = 0x00, /* P5.4 as GPIO */
  28. RCC_LowVoltResetPinAF_Reset = 0x01, /* P5.4 as RESET */
  29. } RCC_LowVoltResetPinAF_t;
  30. /**
  31. * Low voltage threshold
  32. *
  33. * | | STC8H8K64U | Other |
  34. * | -- | ---------- | ---------- |
  35. * | 00 | 1.9V | 2.0V |
  36. * | 01 | 2.3V | 2.4V |
  37. * | 10 | 2.8V | 2.7V |
  38. * | 11 | 3.7V | 3.0V |
  39. */
  40. typedef enum
  41. {
  42. RCC_LowVoltThreshold_Lowest = 0x00,
  43. RCC_LowVoltThreshold_Low = 0x01,
  44. RCC_LowVoltThreshold_High = 0x02,
  45. RCC_LowVoltThreshold_Highest = 0x03,
  46. } RCC_LowVoltThreshold_t;
  47. #define RCC_SetSYSCLKSource(__SOURCE__) do { \
  48. SFRX_ON(); \
  49. (CKSEL) = (CKSEL) & ~(0x03) | (__SOURCE__); \
  50. SFRX_OFF(); \
  51. } while(0)
  52. #define RCC_SetCLKDivider(__DIV__) do {SFRX_ON(); CLKDIV = (__DIV__ & 0xFF); SFRX_OFF();} while(0)
  53. #define RCC_SetPowerDownMode(__STATE__) SFR_ASSIGN(PCON, 1, __STATE__)
  54. #define RCC_SetIdleMode(__STATE__) SFR_ASSIGN(PCON, 0, __STATE__)
  55. #define RCC_SetPowerDownWakeupTimerState(__STATE__) SFR_ASSIGN(WKTCH, 7, __STATE__)
  56. #define RCC_SetPowerDownWakeupTimerCountdown(__15BIT_COUNT__) do { \
  57. WKTCH = WKTCH & ~(0x7F) | (__15BIT_COUNT__ >> 8); \
  58. WKTCL = (__15BIT_COUNT__ & 0xFF); \
  59. }while(0)
  60. #define RCC_SetLowVoltResetState(__STATE__) SFR_ASSIGN(RSTCFG, 6, __STATE__)
  61. #define RCC_SetLowVoltResetPinAF(__PIN_AF__) SFR_ASSIGN(RSTCFG, 4, __PIN_AF__)
  62. #define RCC_SetLowVoltResetThreshold(__THRESHOLD__) (RSTCFG = RSTCFG & ~(0x03) | (__THRESHOLD__))
  63. #endif