amt630hv160_rtc.h 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  1. /*******************************************************************************
  2. * File Name : amt630hv160_rtc.h
  3. * Author : Sim
  4. * Date First Issued : 03/06/2024
  5. * Description : This file contains all the functions prototypes for the
  6. * RTC firmware library.
  7. ********************************************************************************
  8. * History:
  9. * 03/06/2024: V0.1
  10. *******************************************************************************/
  11. /* Define to prevent recursive inclusion -------------------------------------*/
  12. #ifndef __AMT630HV160_RTC_H
  13. #define __AMT630HV160_RTC_H
  14. /* Includes ------------------------------------------------------------------*/
  15. #include "amt630hv160_map.h"
  16. /* Exported types ------------------------------------------------------------*/
  17. typedef enum {
  18. RTC_PowerOff,
  19. RTC_DelayWakeUp,
  20. RTC_Clk32KSel,
  21. RTC_WDTEn,
  22. RTC_ISOOff,
  23. RTC_SleepMode,
  24. RTC_ISOForce,
  25. RTC_PMC,
  26. RTC_RAML,
  27. RTC_GPIO,
  28. RTC_RAMH,
  29. RTC_PARA,
  30. RTC_CNT,
  31. } eRTCCmd;
  32. typedef enum {
  33. RTC_WDT_250MS,
  34. RTC_WDT_500MS,
  35. RTC_WDT_1S,
  36. RTC_WDT_2S,
  37. RTC_WDT_NOCHANGE,
  38. } eRTCWdtTmo;
  39. typedef enum {
  40. RTC_WAKEUP_GPIO1,
  41. RTC_WAKEUP_GPIO0,
  42. RTC_WAKEUP_CAN1,
  43. RTC_WAKEUP_CAN0,
  44. RTC_WAKEUP_ACC,
  45. RTC_WAKEUP_RTC,
  46. } eRTCWakeupSource;
  47. typedef enum {
  48. RTC_WAKEUP_FALLING,
  49. RTC_WAKEUP_RISING,
  50. RTC_WAKEUP_HIGHLEVEL,
  51. RTC_WAKEUP_LOWLEVEL,
  52. RTC_WAKEUP_NOCHANGE,
  53. } eRTCWakeupMode;
  54. /*
  55. * The struct used to pass data via the following ioctl. Similar to the
  56. * struct tm in <time.h>, but it needs to be here so that the kernel
  57. * source is self contained, allowing cross-compiles, etc. etc.
  58. */
  59. typedef struct rtc_time {
  60. int tm_sec;
  61. int tm_min;
  62. int tm_hour;
  63. int tm_mday;
  64. int tm_mon;
  65. int tm_year;
  66. int tm_wday;
  67. int tm_yday;
  68. } SystemTime_t;
  69. /* Exported constants --------------------------------------------------------*/
  70. static inline int is_leap_year(unsigned int year)
  71. {
  72. return (!(year % 4) && (year % 100)) || !(year % 400);
  73. }
  74. #pragma section = "sleep_critical_data"
  75. /* Exported macro ------------------------------------------------------------*/
  76. /* STATUS_REG */
  77. #define RTC_STA_BUSY (1 << 2)
  78. #define RTC_STA_SLEEPMODE (1 << 3)
  79. #define RTC_STA_ISOFORCE (1 << 6)
  80. #define RTC_STA_GPIO0ACT (1 << 9)
  81. #define RTC_STA_GPIO1ACT (1 << 10)
  82. #define RTC_STA_CAN0ACT (1 << 11)
  83. #define RTC_STA_CAN1ACT (1 << 12)
  84. #define RTC_STA_ACCACT (1 << 13)
  85. #define RTC_STA_RTCACT (1 << 14)
  86. #define RTC_STA_GPIO0IN (1 << 15)
  87. #define IRAM_SLEEP_DATA_MAX_SIZE (0x2000 - 8)
  88. /* Exported functions ------------------------------------------------------- */
  89. // Sleep and wake-up related
  90. int RTC_SendCmd(eRTCCmd cmd, int enable);
  91. int RTC_WriteReg(eRTCCmd cmd, vu32 *reg, u32 value);
  92. void RTC_SetWatchdog(eRTCWdtTmo tmo, int enable);
  93. void RTC_PowerDown(int fastboot);
  94. void RTC_CanStbOut(int id, int value);
  95. void RTC_SetWakeup(eRTCWakeupSource src, eRTCWakeupMode mode, int enable);
  96. void RTC_WakeupDetect(void);
  97. int RTC_SaveSleepData(void);
  98. int RTC_ReadSleepData(void);
  99. // Real-time clock related
  100. int rtc_time_init(void);
  101. int iGetLocalTime(SystemTime_t *tm);
  102. void vSetLocalTime(SystemTime_t *tm);
  103. uint32_t CpuGetLocalTime(void);
  104. void CpuSetLocalTime(uint32_t time);
  105. #endif /* __AMT630HV160_RTC_H */