annotate Small_CPU/Src/rtc.c @ 955:9b29995d6619 Evo_2_23 tip

GNSS backup position: In the previous implementation a position had to be provided by the module in order to be stored in the log. This may cause a wrong position entry (default) in the log, for example if signal is lost while preparing for the dive in the water. To avoid this the last received position will be used for ~2 hours => Diver may take the dive side position before starting with the dive preparation. The last known position will be display in the GNSS position search window as well.
author Ideenmodellierer
date Wed, 01 Jan 2025 20:37:17 +0100
parents f0069f002c55
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
38
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1 /**
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2 ******************************************************************************
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
3 * @file rtc.c
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
4 * @author heinrichs weikamp gmbh
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
5 * @version V0.0.1
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
6 * @date 10-Oct-2014
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
7 * @brief Source code for rtc control
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
8 *
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
9 @verbatim
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
10 ==============================================================================
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
11 ##### How to use #####
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
12 ==============================================================================
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
13 @endverbatim
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
14 ******************************************************************************
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
15 * @attention
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
16 *
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
17 * <h2><center>&copy; COPYRIGHT(c) 2015 heinrichs weikamp</center></h2>
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
18 *
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
19 ******************************************************************************
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
20 */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
21 /* Includes ------------------------------------------------------------------*/
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
22 #include "rtc.h"
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
23 #include "stm32f4xx_hal.h"
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
24 #include "stm32f4xx_hal_conf.h"
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
25 #include "baseCPU2.h"
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
26
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
27 RTC_HandleTypeDef RTCHandle;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
28
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
29 static void RTC_Error_Handler(void);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
30
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
31
955
9b29995d6619 GNSS backup position:
Ideenmodellierer
parents: 232
diff changeset
32
9b29995d6619 GNSS backup position:
Ideenmodellierer
parents: 232
diff changeset
33 void RTC_GetTime(RTC_TimeTypeDef* pstimestructure)
9b29995d6619 GNSS backup position:
Ideenmodellierer
parents: 232
diff changeset
34 {
9b29995d6619 GNSS backup position:
Ideenmodellierer
parents: 232
diff changeset
35 HAL_RTC_GetTime(&RTCHandle, pstimestructure, RTC_FORMAT_BIN);
9b29995d6619 GNSS backup position:
Ideenmodellierer
parents: 232
diff changeset
36 }
9b29995d6619 GNSS backup position:
Ideenmodellierer
parents: 232
diff changeset
37
38
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
38 void RTC_SetTime(RTC_TimeTypeDef stimestructure)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
39 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
40
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
41 stimestructure.SubSeconds = 0;
232
f0069f002c55 Bugfix: make date/time setting work over reboots
Jan Mulder <jlmulder@xs4all.nl>
parents: 38
diff changeset
42 stimestructure.TimeFormat = RTC_HOURFORMAT_24;
38
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
43 stimestructure.DayLightSaving = RTC_DAYLIGHTSAVING_NONE ;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
44 stimestructure.StoreOperation = RTC_STOREOPERATION_RESET;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
45
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
46 if(HAL_RTC_SetTime(&RTCHandle, &stimestructure, FORMAT_BIN) != HAL_OK)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
47 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
48 RTC_Error_Handler();
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
49 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
50 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
51
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
52
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
53 void RTC_SetDate(RTC_DateTypeDef sdatestructure)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
54 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
55 if(HAL_RTC_SetDate(&RTCHandle, &sdatestructure, FORMAT_BIN) != HAL_OK)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
56 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
57 RTC_Error_Handler();
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
58 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
59 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
60
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
61
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
62 /*
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
63 static void RTC_CalendarConfig(void)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
64 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
65 RTC_DateTypeDef sdatestructure;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
66 RTC_TimeTypeDef stimestructure;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
67
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
68 //##-1- Configure the Date #################################################
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
69 // Set Date: Monday April 14th 2014
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
70 sdatestructure.Year = 0;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
71 sdatestructure.Month = RTC_MONTH_JANUARY;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
72 sdatestructure.Date = 1;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
73 sdatestructure.WeekDay = RTC_WEEKDAY_MONDAY;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
74
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
75 if(HAL_RTC_SetDate(&RTCHandle,&sdatestructure,FORMAT_BCD) != HAL_OK)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
76 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
77 RTC_Error_Handler();
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
78 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
79
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
80 //##-2- Configure the Time #################################################
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
81 // Set Time: 02:00:00
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
82 stimestructure.Hours = 0;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
83 stimestructure.Minutes = 0;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
84 stimestructure.Seconds = 0;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
85 stimestructure.DayLightSaving = RTC_DAYLIGHTSAVING_NONE ;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
86 stimestructure.StoreOperation = RTC_STOREOPERATION_RESET;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
87
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
88 if(HAL_RTC_SetTime(&RTCHandle,&stimestructure,FORMAT_BCD) != HAL_OK)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
89 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
90 RTC_Error_Handler();
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
91 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
92
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
93 //##-3- Writes a data in a RTC Backup data Register0 #######################
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
94 // HAL_RTCEx_BKUPWrite(&RTCHandle,RTC_BKP_DR0,0x32F2);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
95 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
96 */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
97
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
98
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
99 /* ##-1- Configure the RTC peripheral #######################################
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
100 Configure RTC prescaler and RTC data registers
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
101 RTC configured as follow:
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
102 - Hour Format = Format 24
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
103 - Asynch Prediv = Value according to source clock
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
104 - Synch Prediv = Value according to source clock
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
105 - OutPut = Output Disable
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
106 - OutPutPolarity = High Polarity
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
107 - OutPutType = Open Drain
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
108 */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
109
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
110
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
111 void MX_RTC_init(void)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
112 {
232
f0069f002c55 Bugfix: make date/time setting work over reboots
Jan Mulder <jlmulder@xs4all.nl>
parents: 38
diff changeset
113 /* Initialize RTC */
38
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
114 RTCHandle.Instance = RTC;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
115 RTCHandle.Init.HourFormat = RTC_HOURFORMAT_24;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
116 RTCHandle.Init.AsynchPrediv = 127;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
117 RTCHandle.Init.SynchPrediv = 255;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
118 RTCHandle.Init.OutPut = RTC_OUTPUT_DISABLE;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
119 RTCHandle.Init.OutPutPolarity = RTC_OUTPUT_POLARITY_HIGH;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
120 RTCHandle.Init.OutPutType = RTC_OUTPUT_TYPE_OPENDRAIN;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
121 HAL_RTC_Init(&RTCHandle);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
122 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
123
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
124
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
125 void RTC_StopMode_2seconds(void)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
126 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
127 /* Enable Power Control clock */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
128 __HAL_RCC_PWR_CLK_ENABLE();
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
129
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
130 /* Disable Wake-up timer */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
131 HAL_RTCEx_DeactivateWakeUpTimer(&RTCHandle);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
132
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
133 /* Enable Wake-up timer */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
134 HAL_RTCEx_SetWakeUpTimer_IT(&RTCHandle, (0x1000-1), RTC_WAKEUPCLOCK_RTCCLK_DIV16);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
135
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
136 /* FLASH Deep Power Down Mode enabled */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
137 HAL_PWREx_EnableFlashPowerDown();
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
138
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
139 /*## Enter Stop Mode #######################################################*/
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
140 HAL_PWR_EnterSTOPMode(PWR_LOWPOWERREGULATOR_ON, PWR_STOPENTRY_WFI);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
141
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
142 /* Configures system clock after wake-up from STOP: enable HSI, PLL and select
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
143 PLL as system clock source (HSI and PLL are disabled in STOP mode) */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
144 SYSCLKConfig_STOP();
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
145
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
146 HAL_RTCEx_DeactivateWakeUpTimer(&RTCHandle);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
147 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
148
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
149
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
150 void RTC_Stop_11ms(void)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
151 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
152 /* Disable Wake-up timer */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
153 HAL_RTCEx_DeactivateWakeUpTimer(&RTCHandle);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
154
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
155 /* Enable Wake-up timer */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
156 HAL_RTCEx_SetWakeUpTimer_IT(&RTCHandle, (0x18-1), RTC_WAKEUPCLOCK_RTCCLK_DIV16);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
157
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
158 /* FLASH Deep Power Down Mode enabled */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
159 HAL_PWREx_DisableFlashPowerDown();
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
160
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
161 /*## Enter Stop Mode #######################################################*/
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
162 HAL_PWR_EnterSTOPMode(PWR_MAINREGULATOR_ON, PWR_STOPENTRY_WFI);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
163
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
164 /* Configures system clock after wake-up from STOP: enable HSI, PLL and select
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
165 PLL as system clock source (HSI and PLL are disabled in STOP mode) */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
166 SYSCLKConfig_STOP();
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
167
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
168 HAL_RTCEx_DeactivateWakeUpTimer(&RTCHandle);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
169 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
170
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
171
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
172 static void RTC_Error_Handler(void)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
173 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
174 while(1);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
175 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
176
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
177
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
178 /************************ (C) COPYRIGHT heinrichs weikamp *****END OF FILE****/