Mercurial > public > ostc4
annotate Small_CPU/Src/rtc.c @ 240:625d20070261 div-fixes-5
Improvement SPI stability/recoverability
The core part of this commit comes from careful code reading. The core is the
swap of Scheduler_Request_sync_with_SPI(SPI_SYNC_METHOD_SOFT) and
SPI_Start_single_TxRx_with_Master(). This code is sitting in an if-clause
that is triggered on SPI comms failure. Instead of blindly trying to
communicate again (which will very likely fail again), first try to reset
the comms link, and then try to communicate again. That simply makes
more sense in this case.
This is heavily tested, on 2 simple dives, and 5 very long deco schedules
from the simulator (10+ hour deco's), and a lot of small simulated dives
(upto 2h runtime). Of all these tests, only one long session failed after
9 out of 11h runtime. Analyzing that one failure, suggests that the
RTE is looping in some error handler, which (obviously) results in
a SPI comms failure as a result. I consider this not part of this change.
Additionally, some more cleanup is done in this code.
Signed-off-by: Jan Mulder <jlmulder@xs4all.nl>
author | Jan Mulder <jlmulder@xs4all.nl> |
---|---|
date | Mon, 08 Apr 2019 11:49:13 +0200 |
parents | f0069f002c55 |
children |
rev | line source |
---|---|
38 | 1 /** |
2 ****************************************************************************** | |
3 * @file rtc.c | |
4 * @author heinrichs weikamp gmbh | |
5 * @version V0.0.1 | |
6 * @date 10-Oct-2014 | |
7 * @brief Source code for rtc control | |
8 * | |
9 @verbatim | |
10 ============================================================================== | |
11 ##### How to use ##### | |
12 ============================================================================== | |
13 @endverbatim | |
14 ****************************************************************************** | |
15 * @attention | |
16 * | |
17 * <h2><center>© COPYRIGHT(c) 2015 heinrichs weikamp</center></h2> | |
18 * | |
19 ****************************************************************************** | |
20 */ | |
21 /* Includes ------------------------------------------------------------------*/ | |
22 #include "rtc.h" | |
23 #include "stm32f4xx_hal.h" | |
24 #include "stm32f4xx_hal_conf.h" | |
25 #include "baseCPU2.h" | |
26 | |
27 RTC_HandleTypeDef RTCHandle; | |
28 | |
29 static void RTC_Error_Handler(void); | |
30 | |
31 | |
32 void RTC_SetTime(RTC_TimeTypeDef stimestructure) | |
33 { | |
34 | |
35 stimestructure.SubSeconds = 0; | |
232
f0069f002c55
Bugfix: make date/time setting work over reboots
Jan Mulder <jlmulder@xs4all.nl>
parents:
38
diff
changeset
|
36 stimestructure.TimeFormat = RTC_HOURFORMAT_24; |
38 | 37 stimestructure.DayLightSaving = RTC_DAYLIGHTSAVING_NONE ; |
38 stimestructure.StoreOperation = RTC_STOREOPERATION_RESET; | |
39 | |
40 if(HAL_RTC_SetTime(&RTCHandle, &stimestructure, FORMAT_BIN) != HAL_OK) | |
41 { | |
42 RTC_Error_Handler(); | |
43 } | |
44 } | |
45 | |
46 | |
47 void RTC_SetDate(RTC_DateTypeDef sdatestructure) | |
48 { | |
49 if(HAL_RTC_SetDate(&RTCHandle, &sdatestructure, FORMAT_BIN) != HAL_OK) | |
50 { | |
51 RTC_Error_Handler(); | |
52 } | |
53 } | |
54 | |
55 | |
56 /* | |
57 static void RTC_CalendarConfig(void) | |
58 { | |
59 RTC_DateTypeDef sdatestructure; | |
60 RTC_TimeTypeDef stimestructure; | |
61 | |
62 //##-1- Configure the Date ################################################# | |
63 // Set Date: Monday April 14th 2014 | |
64 sdatestructure.Year = 0; | |
65 sdatestructure.Month = RTC_MONTH_JANUARY; | |
66 sdatestructure.Date = 1; | |
67 sdatestructure.WeekDay = RTC_WEEKDAY_MONDAY; | |
68 | |
69 if(HAL_RTC_SetDate(&RTCHandle,&sdatestructure,FORMAT_BCD) != HAL_OK) | |
70 { | |
71 RTC_Error_Handler(); | |
72 } | |
73 | |
74 //##-2- Configure the Time ################################################# | |
75 // Set Time: 02:00:00 | |
76 stimestructure.Hours = 0; | |
77 stimestructure.Minutes = 0; | |
78 stimestructure.Seconds = 0; | |
79 stimestructure.DayLightSaving = RTC_DAYLIGHTSAVING_NONE ; | |
80 stimestructure.StoreOperation = RTC_STOREOPERATION_RESET; | |
81 | |
82 if(HAL_RTC_SetTime(&RTCHandle,&stimestructure,FORMAT_BCD) != HAL_OK) | |
83 { | |
84 RTC_Error_Handler(); | |
85 } | |
86 | |
87 //##-3- Writes a data in a RTC Backup data Register0 ####################### | |
88 // HAL_RTCEx_BKUPWrite(&RTCHandle,RTC_BKP_DR0,0x32F2); | |
89 } | |
90 */ | |
91 | |
92 | |
93 /* ##-1- Configure the RTC peripheral ####################################### | |
94 Configure RTC prescaler and RTC data registers | |
95 RTC configured as follow: | |
96 - Hour Format = Format 24 | |
97 - Asynch Prediv = Value according to source clock | |
98 - Synch Prediv = Value according to source clock | |
99 - OutPut = Output Disable | |
100 - OutPutPolarity = High Polarity | |
101 - OutPutType = Open Drain | |
102 */ | |
103 | |
104 | |
105 void MX_RTC_init(void) | |
106 { | |
232
f0069f002c55
Bugfix: make date/time setting work over reboots
Jan Mulder <jlmulder@xs4all.nl>
parents:
38
diff
changeset
|
107 /* Initialize RTC */ |
38 | 108 RTCHandle.Instance = RTC; |
109 RTCHandle.Init.HourFormat = RTC_HOURFORMAT_24; | |
110 RTCHandle.Init.AsynchPrediv = 127; | |
111 RTCHandle.Init.SynchPrediv = 255; | |
112 RTCHandle.Init.OutPut = RTC_OUTPUT_DISABLE; | |
113 RTCHandle.Init.OutPutPolarity = RTC_OUTPUT_POLARITY_HIGH; | |
114 RTCHandle.Init.OutPutType = RTC_OUTPUT_TYPE_OPENDRAIN; | |
115 HAL_RTC_Init(&RTCHandle); | |
116 } | |
117 | |
118 | |
119 void RTC_StopMode_2seconds(void) | |
120 { | |
121 /* Enable Power Control clock */ | |
122 __HAL_RCC_PWR_CLK_ENABLE(); | |
123 | |
124 /* Disable Wake-up timer */ | |
125 HAL_RTCEx_DeactivateWakeUpTimer(&RTCHandle); | |
126 | |
127 /* Enable Wake-up timer */ | |
128 HAL_RTCEx_SetWakeUpTimer_IT(&RTCHandle, (0x1000-1), RTC_WAKEUPCLOCK_RTCCLK_DIV16); | |
129 | |
130 /* FLASH Deep Power Down Mode enabled */ | |
131 HAL_PWREx_EnableFlashPowerDown(); | |
132 | |
133 /*## Enter Stop Mode #######################################################*/ | |
134 HAL_PWR_EnterSTOPMode(PWR_LOWPOWERREGULATOR_ON, PWR_STOPENTRY_WFI); | |
135 | |
136 /* Configures system clock after wake-up from STOP: enable HSI, PLL and select | |
137 PLL as system clock source (HSI and PLL are disabled in STOP mode) */ | |
138 SYSCLKConfig_STOP(); | |
139 | |
140 HAL_RTCEx_DeactivateWakeUpTimer(&RTCHandle); | |
141 } | |
142 | |
143 | |
144 void RTC_Stop_11ms(void) | |
145 { | |
146 /* Disable Wake-up timer */ | |
147 HAL_RTCEx_DeactivateWakeUpTimer(&RTCHandle); | |
148 | |
149 /* Enable Wake-up timer */ | |
150 HAL_RTCEx_SetWakeUpTimer_IT(&RTCHandle, (0x18-1), RTC_WAKEUPCLOCK_RTCCLK_DIV16); | |
151 | |
152 /* FLASH Deep Power Down Mode enabled */ | |
153 HAL_PWREx_DisableFlashPowerDown(); | |
154 | |
155 /*## Enter Stop Mode #######################################################*/ | |
156 HAL_PWR_EnterSTOPMode(PWR_MAINREGULATOR_ON, PWR_STOPENTRY_WFI); | |
157 | |
158 /* Configures system clock after wake-up from STOP: enable HSI, PLL and select | |
159 PLL as system clock source (HSI and PLL are disabled in STOP mode) */ | |
160 SYSCLKConfig_STOP(); | |
161 | |
162 HAL_RTCEx_DeactivateWakeUpTimer(&RTCHandle); | |
163 } | |
164 | |
165 | |
166 static void RTC_Error_Handler(void) | |
167 { | |
168 while(1); | |
169 } | |
170 | |
171 | |
172 /************************ (C) COPYRIGHT heinrichs weikamp *****END OF FILE****/ |