power.h 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127
  1. /**
  2. * @file Power.h
  3. * @author Wang, Zhiyu(wangzy49@midea.com)
  4. * @brief Power Managemant of ebike
  5. * @version 0.1
  6. * @date 2021-09-29
  7. *
  8. * @copyright Copyright (c) 2021
  9. *
  10. */
  11. /************************************************************************
  12. Beginning of File, do not put anything above here except notes
  13. Compiler Directives:
  14. *************************************************************************/
  15. #ifndef POWER_H
  16. #define POWER_H
  17. #include "typedefine.h"
  18. typedef _Bool BOOL;
  19. /****************************************
  20. *
  21. * Definitions & Macros
  22. *
  23. ****************************************/
  24. #define POWERMINVOLT (250<<14)/480 //25V min volt
  25. #define POWER_START_TOUCHING_TIME 600 // ms
  26. #define POWER_START_FULLYON_TIME 1000 // ms
  27. #define POWER_SHUT_TOUCHING_TIME 20 // ms
  28. #define POWER_SHUT_FULLYOFF_TIME 1000 // ms
  29. #define POWER_ON2OFF_TIME 500 // ms
  30. #define POWER_START_TIMERUNIT 1 // ms
  31. #define POWER_SHUT_TIMERUNIT 1 // ms
  32. #define POWER_SHUT_STOPDELAY_TIME (2000/POWER_SHUT_TIMERUNIT) // ms
  33. #define POWER_OUT_DEFAULT \
  34. { \
  35. 0, 0, 0, FALSE, FALSE, POWER_START \
  36. } // Default value of BIKELIGHT_OUT
  37. #define POWER_COF_DEFAULT \
  38. { \
  39. 0, 0, 0, 0, 0 \
  40. }
  41. #define POWER_LOCK_PORT GPIOB // PC1
  42. #define POWER_LOCK_PIN GPIO_Pin_4 // PC1
  43. #define POWER_SWSTATE_PORT GPIOC // PC0
  44. #define POWER_SWSTATE_PIN GPIO_Pin_12 // PC1
  45. #define High_KEYVOL 2730 //2.2V
  46. #define LOW_KEYVOL 1241// 1V
  47. #define NULL_KEYMAXVOL 2730 //2.2V
  48. #define NULL_KEYMINVOL 2110 // 1.7V
  49. /***************************************
  50. *
  51. * Type Definations
  52. *
  53. ***************************************/
  54. /**
  55. * @brief Cadence FSM
  56. *
  57. */
  58. typedef enum
  59. {
  60. POWER_START = 0,
  61. POWER_ON = 1,
  62. POWER_ON_END = 2,
  63. POWER_OFF = 3,
  64. POWER_OFF_END = 4
  65. } POWER_STATE;
  66. /**
  67. * @brief Cadence FSM
  68. *
  69. */
  70. typedef struct
  71. {
  72. UWORD uwPowerStartupCnt; // Cnt of Startup
  73. UWORD uwPowerShutdnCnt; // Cnt of Shutdown
  74. UWORD uwPowerOn2OffCnt; // On 2 off Cnt
  75. UWORD uwPOwerForceShutdnCnt; // Cnt of Shutdown
  76. UWORD uwPowerKeySta; // key sta
  77. UWORD uwPowerKeyMode; //key high or low
  78. BOOL blPowerStartupFlg; // Flg of Startup
  79. BOOL blPowerShutdownFlg; // Flg of Shutdown
  80. POWER_STATE powerstate;
  81. } POWER_OUT;
  82. /**
  83. * @brief Cadence FSM
  84. *
  85. */
  86. typedef struct
  87. {
  88. UWORD uwPowerStartTouchTimeCnt; // Cnt of Startup button touching
  89. UWORD uwPowerShutTouchTimeCnt; // Cnt of Shutdown button touching
  90. UWORD uwPowerStartEndCnt; // Cnt of transfering to fully Power On
  91. UWORD uwPowerShutEndCnt; // Cnt of transfering to fully Power Off
  92. UWORD uwPowerOn2OffTimeCnt; // Cnt On 2 off Cnt
  93. SWORD uwPowerModeTime;
  94. } POWER_COF;
  95. /****************************************
  96. *
  97. * Exported variable
  98. *
  99. ****************************************/
  100. extern POWER_OUT power_stPowStateOut;
  101. /***************************************
  102. *
  103. * Function Definations
  104. *
  105. ***************************************/
  106. void power_voPowerInit(void);
  107. void power_voPowerManagement(BOOL ParaSaveEEFlg, BOOL PowerSleepFlg);
  108. /************************************************************************/
  109. #endif
  110. /************************************************************************
  111. End of this File (EOF):
  112. Do not put anything after this part!
  113. *************************************************************************/