rtc.h 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. #ifndef __RTC_H
  2. #define __RTC_H
  3. #include "at32f403a_407.h"
  4. #define TM_RTC_LEAP_YEAR(year) ((((year) % 4 == 0) && ((year) % 100 != 0)) || ((year) % 400 == 0))
  5. typedef struct
  6. {
  7. __IO uint8_t seconds; /*!< Seconds parameter, from 00 to 59 */
  8. __IO uint16_t subseconds; /*!< Subsecond downcounter. When it reaches zero, it's reload value is the same as
  9. @ref RTC_SYNC_PREDIV, so in our case 0x3FF = 1023, 1024 steps in one second */
  10. __IO uint8_t minutes; /*!< Minutes parameter, from 00 to 59 */
  11. __IO uint8_t hours; /*!< Hours parameter, 24Hour mode, 00 to 23 */
  12. __IO uint8_t day; /*!< Day in a week, from 1 to 7 */
  13. __IO uint8_t date; /*!< Date in a month, 1 to 31 */
  14. __IO uint8_t month; /*!< Month in a year, 1 to 12 */
  15. __IO uint8_t year; /*!< Year parameter, 00 to 99, 00 is 2000 and 99 is 2099 */
  16. __IO uint32_t unix; /*!< Seconds from 01.01.1970 00:00:00 */
  17. } TM_RTC_t;
  18. // RTC Result enumeration
  19. typedef enum {
  20. TM_RTC_Result_Ok, /*!< Everything OK */
  21. TM_RTC_Result_Error /*!< An error occurred */
  22. } TM_RTC_Result_t;
  23. // RTC date and time format
  24. typedef enum {
  25. TM_RTC_Format_BIN = 0x00, /*!< RTC data in binary format */
  26. TM_RTC_Format_BCD /*!< RTC data in binary-coded decimal format */
  27. } TM_RTC_Format_t;
  28. //
  29. uint8_t TM_RTC_Init(void);
  30. //
  31. void TM_RTC_SetDataTimeUnix(uint32_t unixTime);
  32. //
  33. TM_RTC_Result_t TM_RTC_SetDateTime(TM_RTC_t* data);
  34. //
  35. TM_RTC_Result_t TM_RTC_SetDateTimeString(char* str);
  36. //
  37. void TM_RTC_GetDateTime(TM_RTC_t* data, TM_RTC_Format_t format);
  38. //
  39. uint32_t TM_RTC_GetUnixTimeStamp(TM_RTC_t* data);
  40. //
  41. void TM_RTC_GetDateTimeFromUnix(TM_RTC_t* data, uint32_t unix);
  42. //
  43. void TM_RTC_PrintTime(void);
  44. //
  45. uint32_t RTC_GetUnixTime(void);
  46. //
  47. void rtc_subtim_init(void);
  48. //
  49. uint64_t rtc_get_ms(void);
  50. //
  51. uint32_t rtc_foo(void);
  52. //
  53. void rtc_set_in_ms(uint64_t ms);
  54. #endif