summaryrefslogtreecommitdiff
path: root/rtc/stm32_rtc.h
blob: d1e1c0285e7e5d8b403637546adbeefb72f9d970 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
#pragma once

#include <mmio/mmio.h>

struct STM32_RTC_reg_v2ss_t {
	volatile uint32_t TR;
	volatile uint32_t DR;
	volatile uint32_t CR;
	volatile uint32_t ISR;
	volatile uint32_t PRER;
	volatile uint32_t WUTR;
	uint32_t _reserved1;
	volatile uint32_t ALRMAR;
	volatile uint32_t ALRMBR;
	volatile uint32_t WPR;
	volatile uint32_t SSR;
	volatile uint32_t SHIFTR;
	volatile uint32_t TSTR;
	volatile uint32_t TSDR;
	volatile uint32_t TSSSR;
	volatile uint32_t CALR;
	volatile uint32_t TAMPCR;
	volatile uint32_t ALRMASSR;
	volatile uint32_t ALRMBSSR;
	volatile uint32_t OR;
	volatile uint32_t BKP[32]; /* max known 32, might be less, check DS */
};

struct STM32_RTC_reg_v3_t {
	volatile uint32_t TR;
	volatile uint32_t DR;
	volatile uint32_t SSR;
	volatile uint32_t ICSR;
	volatile uint32_t PRER;
	volatile uint32_t WUTR;
	volatile uint32_t CR;
	uint32_t _reserved1[2];
	volatile uint32_t WPR;
	volatile uint32_t CALR;
	volatile uint32_t SHIFTR;
	volatile uint32_t TSTR;
	volatile uint32_t TSDR;
	volatile uint32_t TSSSR;
	volatile uint32_t ALRMAR;
	volatile uint32_t ALRMASSR;
	volatile uint32_t ALRMBR;
	volatile uint32_t ALRMBSSR;
	volatile uint32_t SR;
	volatile uint32_t MISR;
	volatile uint32_t SCR;
};


template <typename T>
class STM32_RTC_t : public mmio_ptr<T> {
	public:
		using mmio_ptr<T>::ptr;

		void lock(void) const {
			ptr()->WPR = 0x99;  // Doesn't matter...
		}

		void unlock(void) const {
			ptr()->WPR = 0xCA;
			ptr()->WPR = 0x53;
		}

};