power.h 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  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. /****************************************
  18. *
  19. * Definitions & Macros
  20. *
  21. ****************************************/
  22. #define POWER_START_TOUCHING_TIME 1000 // ms
  23. #define POWER_START_FULLYON_TIME 1000 // ms
  24. #define POWER_SHUT_TOUCHING_TIME 20 // ms
  25. #define POWER_SHUT_FULLYOFF_TIME 10 // ms
  26. #define POWER_ON2OFF_TIME 3000 // ms
  27. #define POWER_START_TIMERUNIT 1 // ms
  28. #define POWER_SHUT_TIMERUNIT 1 // ms
  29. #define POWER_OUT_DEFAULT \
  30. { \
  31. 0, 0, 0, FALSE, FALSE, POWER_START \
  32. } // Default value of BIKELIGHT_OUT
  33. #define POWER_COF_DEFAULT \
  34. { \
  35. 0, 0, 0, 0, 0 \
  36. }
  37. #define POWER_LOCK_PORT 1 // PC1
  38. #define POWER_SWSTATE_PORT 0 // PC0
  39. /***************************************
  40. *
  41. * Type Definations
  42. *
  43. ***************************************/
  44. /**
  45. * @brief Cadence FSM
  46. *
  47. */
  48. typedef enum
  49. {
  50. POWER_START = 0,
  51. POWER_ON = 1,
  52. POWER_ON_END = 2,
  53. POWER_OFF = 3,
  54. POWER_OFF_END = 4,
  55. POWER_RESET = 5
  56. } POWER_STATE;
  57. /**
  58. * @brief Cadence FSM
  59. *
  60. */
  61. typedef struct
  62. {
  63. UWORD uwPowerStartupCnt; // Cnt of Startup
  64. UWORD uwPowerShutdnCnt; // Cnt of Shutdown
  65. UWORD uwPowerOn2OffCnt; // On 2 off Cnt
  66. BOOL blPowerStartupFlg; // Flg of Startup
  67. BOOL blPowerShutdownFlg; // Flg of Shutdown
  68. POWER_STATE powerstate;
  69. } POWER_OUT;
  70. /**
  71. * @brief Cadence FSM
  72. *
  73. */
  74. typedef struct
  75. {
  76. UWORD uwPowerStartTouchTimeCnt; // Cnt of Startup button touching
  77. UWORD uwPowerShutTouchTimeCnt; // Cnt of Shutdown button touching
  78. UWORD uwPowerStartEndCnt; // Cnt of transfering to fully Power On
  79. UWORD uwPowerShutEndCnt; // Cnt of transfering to fully Power Off
  80. UWORD uwPowerOn2OffTimeCnt; // Cnt On 2 off Cnt
  81. } POWER_COF;
  82. /****************************************
  83. *
  84. * Exported variable
  85. *
  86. ****************************************/
  87. extern POWER_OUT power_stPowStateOut;
  88. extern ULONG AutoPowerOffTimeCnt;
  89. extern ULONG PowerOffDTimeOut;
  90. /***************************************
  91. *
  92. * Function Definations
  93. *
  94. ***************************************/
  95. void power_voPowerInit(void);
  96. void power_voPowerManagement(UWORD uwPowerPara, ULONG SysTickCnt, ULONG OBC_ButtonSetTimeCnt, UWORD uwTorqueIn, UWORD CadenceIn, UWORD BikeSpeed, BOOL EESaveFinishFlg, BOOL ParaSaveEEFlg);
  97. /************************************************************************/
  98. #endif
  99. /************************************************************************
  100. End of this File (EOF):
  101. Do not put anything after this part!
  102. *************************************************************************/