57 lines
956 B
C
57 lines
956 B
C
/*
|
|
* rtc.h
|
|
*
|
|
* Created on: Oct 16, 2024
|
|
* Author: true
|
|
*/
|
|
|
|
#ifndef USER_PERIPH_RTC_H_
|
|
#define USER_PERIPH_RTC_H_
|
|
|
|
|
|
#include <stdint.h>
|
|
|
|
|
|
|
|
/* a small note about backup registers:
|
|
*
|
|
* the datasheet clearly states there are 42 16-bit registers.
|
|
* it does not cut out any exception for CH32V203 except CH32V203RB.
|
|
* however, the reference manual states that registers 11-42 are only
|
|
* for the _D8 chips, and not the _D6 V4B chips like this one.
|
|
* thus we only have _10_ backup registers, not 42.
|
|
*/
|
|
#define RTC_INIT_DR BKP_DR1
|
|
#define RTC_STATE_DR BKP_DR2
|
|
|
|
|
|
|
|
enum RTCState {
|
|
RTC_STATE_UNINITIALIZED = 0,
|
|
RTC_STATE_CLOCK_NOT_SET,
|
|
RTC_STATE_OK = 0x7f
|
|
};
|
|
|
|
typedef struct RTClock {
|
|
uint16_t year;
|
|
uint8_t mon;
|
|
uint8_t day;
|
|
uint8_t h;
|
|
uint8_t m;
|
|
uint8_t s;
|
|
} RTClock;
|
|
|
|
|
|
|
|
extern uint8_t rtc_state;
|
|
|
|
|
|
|
|
int8_t rtc_init();
|
|
|
|
int8_t rtc_set_clock(struct RTClock *c);
|
|
|
|
|
|
|
|
#endif /* USER_PERIPH_RTC_H_ */
|