Mercurial > public > ostc4
annotate Small_CPU/Src/baseCPU2.c @ 250:822416168585 bm-2
Buelmann: new implementation for ceiling
Since my first functional fix in the ceiling computation in
commit ceecabfddb57, I noticed that the computation used a
linear search, that became rather computational expensive after
that commit. The simple question is: why not a binary search?
So, this commit implements the binary search. But there is a long
story attached to this. Comparing ceiling results from hwOS and this
OSTC4 code were very different. Basically, the original OSTC4
algorithm computed the ceiling using the same GFlow to GFhigh
slope, in such a way, that the ceiling was in sync with the
presented deco stops, where the hwOS code presents a GFhigh
based ceiling.
This said, it is more logical when the OSTC4 and hwOS code give
similar results. This new recursive algorithm gives very similar
results for the ceiling compared to hwOS.
To be complete here, the Buelmann ceiling is the depth to which
you can ascend, so that the leading tissue reaches GFhigh. This
also explains why the deepest deco stop is normally deeper than
the ceiling (unless one dives with GF like 80/80).
The code implemented here is rather straightforward recursion.
Signed-off-by: Jan Mulder <jlmulder@xs4all.nl>
author | Jan Mulder <jlmulder@xs4all.nl> |
---|---|
date | Thu, 11 Apr 2019 17:48:48 +0200 |
parents | e4207f0aaa4b |
children | 2f0eb65df557 |
rev | line source |
---|---|
38 | 1 /** |
2 ****************************************************************************** | |
3 * @copyright heinrichs weikamp | |
4 * @file base.c including main() | |
5 * @author heinrichs weikamp gmbh | |
6 * @date 15-Aug-2014 | |
7 * @version V1.0.3 | |
8 * @since 21-Nov-2014 | |
9 * @brief The beginning of it all. main() is part of this. | |
10 * + Do the inits for hardware | |
11 * + Do the inits for sub-systems like menu, dive screen etc. | |
12 * + Start IRQs | |
13 * + Start MainTasks not in IRQs | |
14 * @bug | |
15 * @warning | |
16 @verbatim | |
17 ============================================================================== | |
18 ##### What about hardware without 8 MHz oscilator ##### | |
19 ============================================================================== | |
20 [..] modify OTP Byte 1 at 0x1FFF7800 with ST-Link utility | |
21 | |
22 ============================================================================== | |
23 ##### Where is the RTE Firmware version ##### | |
24 ============================================================================== | |
25 [..] in baseCPU2.c <just here below :-> | |
26 | |
27 ============================================================================== | |
28 ##### What to do with the RTE Firmware version ##### | |
29 ============================================================================== | |
30 [..] change the values RTErequiredHigh and RTErequiredLow in settings.c | |
31 to start warning via the firmware if not updated | |
32 | |
33 ============================================================================== | |
34 ##### What it does ##### | |
35 ============================================================================== | |
36 [..] All realtime stuff und all what has to be done during sleep | |
37 | |
38 [..] RealTimeClock. The entire time and date handling (including divetime) | |
39 [..] Hardware control for pressure sensor, compass, battery monitor | |
40 [..] Calculations of tissue load, critical radius, otu, cns | |
41 [..] Switching off the power of the main CPU after request from it. | |
42 | |
43 ============================================================================== | |
44 ##### IRQs ##### | |
45 ============================================================================== | |
46 [..] The IRQs are are only used for SystemTick and SPI TransferComplete after | |
47 DMA data reception. | |
48 | |
49 [..] HAL_SPI_TxRxCpltCallback() restarts DMA and will call | |
50 scheduleSpecial_Evaluate_DataSendToSlave() only if it is not blocked | |
239
e4207f0aaa4b
cleanup: factor out dataSendToSlaveStopEval
Jan Mulder <jlmulder@xs4all.nl>
parents:
207
diff
changeset
|
51 by I2C. |
38 | 52 If the evaluation is blocked it has to be tested and executed afterwards. |
53 I2C is executed _without_ the usage of interrupts. | |
54 | |
55 ============================================================================== | |
56 ##### Main loop ##### | |
57 ============================================================================== | |
58 [..] is a combination of the while loop below in main.c and code in scheduler.c | |
59 It is similar to the DR5 code / logic - in contrast to the main CPU | |
60 Switching the state is done via global.mode | |
61 The loops in scheduler all run in the main execution thread without | |
62 any job stacks (like it was in the DR5). | |
63 | |
64 ============================================================================== | |
65 ##### Real Time Clock ##### | |
66 ============================================================================== | |
67 [..] Wehe sie zickt statt tickt! | |
68 The RTC is a seperate part of hardware inside the CPU and is not affected | |
69 by reset. Only power-on reset does change something. | |
70 This is fine but the RTC is vital for the Sleep mode as Wakeuptimer. | |
71 This is the only date/time system in the OSTC. The main CPU is passive. | |
72 Data transfer is done with localtime_rtc_tr und localtime_rtc_dr | |
73 in HAL_RTC format to the main CPU and as HAL_RTC structs the way back for | |
74 setting the actual time and date. | |
75 The RTC unit has 20 Byte of V_bat powered SRAM. It could be used | |
76 for something usefull in both CPUs. | |
77 | |
78 ============================================================================== | |
79 ##### File system ##### | |
80 ============================================================================== | |
81 [..] some files are used for both CPUs, like decom.c/.h, data_central.h, ... | |
82 | |
83 | |
84 ============================================================================== | |
85 ##### Unique device ID register (96 bits) ##### | |
86 ============================================================================== | |
87 [..] some files are used for both CPUs, like decom.c/.h, data_central.h, ... | |
88 | |
89 | |
90 ============================================================================== | |
91 ##### I2C ##### | |
92 ============================================================================== | |
93 [..] used for pressure, compass, (accelerator) and battery gauge | |
94 main cpu and pic (button) is spi | |
95 | |
96 | |
97 ============================================================================== | |
98 ##### Firmware Update Info ##### | |
99 ============================================================================== | |
100 V0.85 160531 scheduleCheck_pressure_reached_dive_mode_level() changes | |
101 160606 global.no_fly_time_minutes ist at least 24h after the dive | |
102 160613 ambient light fixed | |
103 160720 compass calib to Flash (8000 writes max. as erase has problems) | |
104 160829 do not reset main CPU on power on! | |
105 V0.91 161018 pressure_calculation_AN520_004_mod_MS5803_30BA__09_2015(); | |
106 V0.92+ 161020 global.sensorError[MAX_SENSORS] | |
107 fix missing init_pressure(); at powerUp of RTE | |
108 added HAL_StatusTypeDef for many functions in pressure.c | |
109 161024 no_fly_time_minutes Backup FIX | |
110 seconds_since_last_dive now related to RTC clock | |
111 161121 close to surface starts at 1 meter below last known surface pressure | |
112 161121 in surface mode dive mode starts @1 mtr difference if surface 880 mbar instead of 700 mbar before | |
113 V0.97+ 170213 added global.dataSendToSlave.diveModeInfo for DIVEMODE_Apnea | |
114 added global.dataSendToSlave.setEndDive | |
115 DIVEMODE_Apnea special in scheduler.c (ticksdiff >= 1000) -> no tissue, cns, otu, no change in noFly Time etc. | |
116 V0.99 170320 new HAL Driver Repository | |
117 V1.01 170509 old HAL Driver Repository | |
118 | |
119 @endverbatim | |
120 ****************************************************************************** | |
121 * @attention | |
122 * | |
123 * <h2><center>© COPYRIGHT(c) 2017 heinrichs weikamp</center></h2> | |
124 * | |
125 ****************************************************************************** | |
126 */ | |
127 | |
128 //#define DEBUG_PIN_ACTIVE | |
129 /* Includes ------------------------------------------------------------------*/ | |
130 | |
131 #include "baseCPU2.h" | |
132 | |
133 // From Small_CPU/Inc: | |
134 #include "dma.h" | |
135 #include "i2c.h" | |
136 #include "spi.h" | |
137 #include "rtc.h" | |
138 #include "adc.h" | |
139 #include "compass.h" | |
140 #include "pressure.h" | |
141 #include "batteryGasGauge.h" | |
142 #include "batteryCharger.h" | |
143 #include "scheduler.h" | |
144 #include "tm_stm32f4_otp.h" | |
145 | |
146 // From Common/Inc: | |
147 #include "calc_crush.h" | |
148 #include "decom.h" | |
149 #include "FirmwareData.h" | |
150 | |
151 // From Common/Drivers/ | |
152 #include "stm32f4xx_hal.h" | |
153 #include <stdio.h> | |
154 | |
89 | 155 uint8_t hasExternalClock(void) { |
156 if ((TM_OTP_Read(0, 0) > 0) && (TM_OTP_Read(0, 0) < 0xFF)) | |
157 return 1; | |
158 else | |
159 return 0; | |
38 | 160 } |
161 | |
162 // SHALL LOAD AT 0x08000000 + 0x00005000 = 0x08005000. | |
163 // See CPU2-RTE.ld | |
100 | 164 const SFirmwareData cpu2_FirmwareData __attribute__(( section(".firmware_data") ))= { |
165 .versionFirst = 1, | |
148
ee744c7160ce
Use SPI TX callback to synchronize to main CPU
Ideenmodellierer
parents:
134
diff
changeset
|
166 .versionSecond = 7, |
134
0586ae83a243
Removed cyclic (by timer) send on slave side
Ideenmodellierer
parents:
120
diff
changeset
|
167 .versionThird = 0, |
100 | 168 .versionBeta = 0, |
38 | 169 |
89 | 170 /* 4 bytes with trailing 0 */ |
100 | 171 .signature = "mh", |
38 | 172 |
172
c659fda83e44
Minor: Button defaults, release date adjusted, use SPI_SHOW_SYNC_STATS
heinrichsweikamp
parents:
148
diff
changeset
|
173 .release_year = 19, |
c659fda83e44
Minor: Button defaults, release date adjusted, use SPI_SHOW_SYNC_STATS
heinrichsweikamp
parents:
148
diff
changeset
|
174 .release_month = 3, |
c659fda83e44
Minor: Button defaults, release date adjusted, use SPI_SHOW_SYNC_STATS
heinrichsweikamp
parents:
148
diff
changeset
|
175 .release_day = 10, |
100 | 176 .release_sub = 0, |
38 | 177 |
89 | 178 /* max 48 with trailing 0 */ |
179 //release_info ="12345678901234567890123456789012345678901" | |
180 .release_info = "compass stuff", | |
38 | 181 |
89 | 182 /* for safety reasons and coming functions */ |
183 .magic[0] = FIRMWARE_MAGIC_FIRST, .magic[1] = FIRMWARE_MAGIC_SECOND, | |
184 .magic[2] = FIRMWARE_MAGIC_CPU2_RTE, /* the magic byte for RTE */ | |
185 .magic[3] = FIRMWARE_MAGIC_END }; | |
38 | 186 |
89 | 187 uint8_t firmwareVersionHigh(void) { |
188 return cpu2_FirmwareData.versionFirst; | |
38 | 189 } |
190 | |
89 | 191 uint8_t firmwareVersionLow(void) { |
192 return cpu2_FirmwareData.versionSecond; | |
38 | 193 } |
194 | |
195 /** @addtogroup OSTC4 | |
196 * @{ | |
197 */ | |
198 | |
199 /** @addtogroup CPU2 | |
200 * @{ | |
201 */ | |
202 | |
203 /* Private typedef -----------------------------------------------------------*/ | |
204 /* Private define ------------------------------------------------------------*/ | |
205 #define BUTTON_OSTC_GPIO_PIN GPIO_PIN_0 | |
206 #define BUTTON_OSTC_GPIO_PORT GPIOA | |
207 #define BUTTON_OSTC_HAL_RCC_GPIO_CLK_ENABLE() __HAL_RCC_GPIOA_CLK_ENABLE() | |
208 #define BUTTON_OSTC_IRQn EXTI0_IRQn | |
209 | |
210 #define BUTTON_TEST_GPIO_PIN GPIO_PIN_3 | |
211 #define BUTTON_TEST_GPIO_PORT GPIOA | |
212 #define BUTTON_TEST_GPIO_CLK_ENABLE() __GPIOA_CLK_ENABLE() | |
213 #define BUTTON_TEST_IRQn EXTI3_IRQn | |
214 | |
215 #define WIRELSS_RISING_GPIO_PIN GPIO_PIN_1 | |
216 #define WIRELSS_RISING_GPIO_PORT GPIOA | |
217 #define WIRELSS_RISING_HAL_RCC_GPIO_CLK_ENABLE() __HAL_RCC_GPIOA_CLK_ENABLE() | |
218 #define WIRELSS_RISING_IRQn EXTI1_IRQn | |
219 | |
220 #define WIRELSS_FALLING_GPIO_PIN GPIO_PIN_2 | |
221 #define WIRELSS_FALLING_GPIO_PORT GPIOA | |
222 #define WIRELSS_FALLING_HAL_RCC_GPIO_CLK_ENABLE() __HAL_RCC_GPIOA_CLK_ENABLE() | |
223 #define WIRELSS_FALLING_IRQn EXTI2_IRQn | |
224 | |
225 #define WIRELSS_POWER_GPIO_PIN GPIO_PIN_12 | |
226 #define WIRELSS_POWER_GPIO_PORT GPIOB | |
227 #define WIRELSS_POWER_HAL_RCC_GPIO_CLK_ENABLE() __HAL_RCC_GPIOB_CLK_ENABLE() | |
228 | |
229 /* Private macro -------------------------------------------------------------*/ | |
230 | |
231 /* Private variables ---------------------------------------------------------*/ | |
232 uint32_t global_test_time_counter = 0; | |
233 SBackup backup; | |
234 | |
235 /* Private function prototypes -----------------------------------------------*/ | |
236 static void EXTI_Wakeup_Button_Init(void); | |
237 static void EXTI_Wakeup_Button_DeInit(void); | |
238 | |
239 static void EXTI_Test_Button_Init(void); | |
240 static void EXTI_Test_Button_DeInit(void); | |
241 | |
242 static void GPIO_LED_Init(void); | |
243 static void GPIO_Power_MainCPU_Init(void); | |
244 static void GPIO_Power_MainCPU_ON(void); | |
245 static void GPIO_Power_MainCPU_OFF(void); | |
246 | |
183 | 247 #ifdef DEBUG_I2C_LINES |
38 | 248 void GPIO_test_I2C_lines(void); |
183 | 249 #endif |
38 | 250 |
251 void sleep_prepare(void); | |
252 | |
253 void SystemClock_Config(void); | |
254 void SystemClock_Config_HSI(void); | |
255 void SystemClock_Config_HSE(void); | |
256 void SYSCLKConfig_STOP_HSI(void); | |
257 void SYSCLKConfig_STOP_HSE(void); | |
258 | |
259 void GPIO_new_DEBUG_Init(void); | |
260 void GPIO_new_DEBUG_LOW(void); | |
261 void GPIO_new_DEBUG_HIGH(void); | |
262 | |
263 #define REGULAR_RUN | |
264 | |
89 | 265 int __io_putchar(int ch) { |
266 ITM_SendChar(ch); | |
267 return ch; | |
38 | 268 } |
269 | |
270 /* Private functions ---------------------------------------------------------*/ | |
271 | |
272 /** | |
273 * @brief Main program | |
274 * @param None | |
275 * @retval None | |
276 */ | |
120 | 277 /* #define DEBUG_RUNTIME TRUE */ |
278 #ifdef DEBUG_RUNTIME | |
279 #define MEASURECNT 60 /* number of measuremets to be stored */ | |
280 static uint32_t loopcnt[MEASURECNT]; | |
281 extern RTC_HandleTypeDef RTCHandle; | |
282 #endif | |
38 | 283 |
89 | 284 int main(void) { |
120 | 285 |
286 #ifdef DEBUG_RUNTIME | |
287 RTC_TimeTypeDef Stime; | |
288 uint8_t measurementindex = 0; | |
289 uint8_t lastsecond = 0xFF; | |
290 #endif | |
291 | |
89 | 292 HAL_Init(); |
293 SystemClock_Config(); | |
38 | 294 |
89 | 295 HAL_SYSTICK_Config(HAL_RCC_GetHCLKFreq() / 1000); |
296 HAL_SYSTICK_CLKSourceConfig( SYSTICK_CLKSOURCE_HCLK); | |
297 HAL_NVIC_SetPriority(SysTick_IRQn, 0, 0); | |
38 | 298 |
89 | 299 MX_RTC_init(); |
300 GPIO_LED_Init(); | |
301 GPIO_new_DEBUG_Init(); // added 170322 hw | |
302 initGlobals(); | |
38 | 303 |
120 | 304 /* printf("CPU2-RTE running...\n"); */ |
38 | 305 |
89 | 306 MX_I2C1_Init(); |
307 if (global.I2C_SystemStatus != HAL_OK) { | |
308 if (MX_I2C1_TestAndClear() == GPIO_PIN_RESET) { | |
309 MX_I2C1_TestAndClear(); // do it a second time | |
310 } | |
311 MX_I2C1_Init(); | |
312 } | |
38 | 313 |
89 | 314 //dangerous: TM_OTP_Write(0,0, 0x01); |
38 | 315 #ifdef REGULAR_RUN |
89 | 316 global.sensorError[SENSOR_PRESSURE_ID] = init_pressure(); |
317 global.I2C_SystemStatus = global.sensorError[SENSOR_PRESSURE_ID]; | |
318 if (global.I2C_SystemStatus != HAL_OK) { | |
319 if (MX_I2C1_TestAndClear() == GPIO_PIN_RESET) { | |
320 MX_I2C1_TestAndClear(); // do it a second time | |
321 } | |
322 MX_I2C1_Init(); | |
323 global.sensorError[SENSOR_PRESSURE_ID] = init_pressure(); | |
324 global.I2C_SystemStatus = global.sensorError[SENSOR_PRESSURE_ID]; | |
325 } | |
38 | 326 |
89 | 327 global.dataSendToMaster.sensorErrors = |
328 global.sensorError[SENSOR_PRESSURE_ID]; | |
329 init_surface_ring(); | |
330 init_battery_gas_gauge(); | |
331 HAL_Delay(10); | |
332 battery_gas_gauge_get_data(); | |
38 | 333 // battery_gas_gauge_set(0); |
334 | |
89 | 335 global.lifeData.battery_voltage = get_voltage(); |
336 global.lifeData.battery_charge = get_charge(); | |
337 copyBatteryData(); | |
38 | 338 |
89 | 339 MX_SPI3_Init(); |
340 if (!scheduleSetButtonResponsiveness()) { | |
341 HAL_Delay(1); | |
342 scheduleSetButtonResponsiveness(); // init | |
343 HAL_Delay(1); | |
344 if (!scheduleSetButtonResponsiveness()) // send again, if problem it's not my problem here. | |
345 { | |
346 HAL_Delay(1); | |
347 scheduleSetButtonResponsiveness(); // init | |
348 HAL_Delay(1); | |
349 } | |
350 } | |
38 | 351 |
89 | 352 ADCx_Init(); |
353 GPIO_Power_MainCPU_Init(); | |
354 global.mode = MODE_POWERUP; | |
38 | 355 #else |
89 | 356 init_pressure(); |
357 init_surface_ring(); | |
38 | 358 |
89 | 359 ADCx_Init(); |
360 GPIO_Power_MainCPU_Init(); | |
361 global.mode = MODE_TEST; | |
38 | 362 #endif |
89 | 363 while (1) { |
120 | 364 /* printf("Global mode = %d\n", global.mode); */ |
38 | 365 |
89 | 366 switch (global.mode) { |
367 case MODE_POWERUP: | |
368 case MODE_BOOT: | |
369 // ReInit_battery_charger_status_pins(); | |
370 compass_init(0, 7); | |
371 accelerator_init(); | |
181 | 372 |
89 | 373 if (global.mode == MODE_BOOT) { |
374 GPIO_Power_MainCPU_OFF(); | |
375 HAL_Delay(100); // for GPIO_Power_MainCPU_ON(); | |
376 GPIO_Power_MainCPU_ON(); | |
377 } | |
378 SPI_synchronize_with_Master(); | |
379 MX_DMA_Init(); | |
380 MX_SPI1_Init(); | |
134
0586ae83a243
Removed cyclic (by timer) send on slave side
Ideenmodellierer
parents:
120
diff
changeset
|
381 SPI_Start_single_TxRx_with_Master(); /* be prepared for the first data exchange */ |
207 | 382 Scheduler_Request_sync_with_SPI(SPI_SYNC_METHOD_HARD); |
89 | 383 EXTI_Test_Button_Init(); |
384 global.mode = MODE_SURFACE; | |
385 break; | |
38 | 386 |
89 | 387 case MODE_CALIB: |
90 | 388 scheduleCompassCalibrationMode(); |
89 | 389 break; |
390 | |
391 case MODE_SURFACE: | |
392 scheduleSurfaceMode(); | |
393 break; | |
38 | 394 |
89 | 395 case MODE_TEST: |
396 break; | |
38 | 397 |
89 | 398 case MODE_DIVE: |
90 | 399 backup.no_fly_time_minutes = global.no_fly_time_minutes; |
400 backup.seconds_since_last_dive = global.seconds_since_last_dive; | |
401 | |
402 vpm_init( &global.vpm, global.conservatism, global.repetitive_dive, | |
403 global.seconds_since_last_dive ); | |
404 global.no_fly_time_minutes = 0; | |
405 global.lifeData.dive_time_seconds = 0; | |
406 global.lifeData.dive_time_seconds_without_surface_time = 0; | |
407 scheduleDiveMode(); | |
408 // done now in scheduler prior to change mode: global.seconds_since_last_dive = 1; | |
409 | |
410 if( global.lifeData.dive_time_seconds > 60 ) | |
411 { | |
412 //No Fly time 60% of desaturationtime after dive | |
413 global.no_fly_time_minutes = decom_calc_desaturation_time( | |
414 global.lifeData.tissue_nitrogen_bar, | |
415 global.lifeData.tissue_helium_bar, | |
416 global.lifeData.pressure_surface_bar ) * 60 / 100; | |
417 if( global.no_fly_time_minutes < (24 * 60) ) | |
418 global.no_fly_time_minutes = 24 * 60; | |
419 } | |
420 else | |
421 { | |
422 global.no_fly_time_minutes = backup.no_fly_time_minutes; | |
423 global.seconds_since_last_dive = backup.seconds_since_last_dive; | |
424 } | |
425 | |
426 global.lifeData.dive_time_seconds = 0; | |
427 global.lifeData.dive_time_seconds_without_surface_time = 0; | |
428 global.lifeData.counterSecondsShallowDepth = 0; | |
429 | |
430 backup.no_fly_time_minutes = 0; | |
431 backup.seconds_since_last_dive = 0; | |
89 | 432 break; |
38 | 433 |
89 | 434 case MODE_SHUTDOWN: |
435 HAL_Delay(200); | |
436 global.mode = MODE_SLEEP; | |
437 MX_SPI3_Init(); | |
438 break; | |
439 | |
440 case MODE_SLEEP: | |
441 /* | |
442 sleep_prepare(); | |
443 scheduleSleepMode_test(); | |
444 */ | |
445 /* | |
446 GPIO_Power_MainCPU_OFF(); | |
447 EXTI_Test_Button_DeInit(); | |
448 EXTI_Wakeup_Button_Init(); | |
449 NOT_USED_AT_THE_MOMENT_scheduleSleepMode(); | |
450 */ | |
451 EXTI_Test_Button_DeInit(); | |
452 if (hasExternalClock()) | |
453 SystemClock_Config_HSI(); | |
454 sleep_prepare(); | |
38 | 455 |
89 | 456 GPIO_LED_Init(); |
38 | 457 |
89 | 458 scheduleSleepMode(); |
459 if (hasExternalClock()) | |
460 SystemClock_Config_HSE(); | |
461 GPIO_LED_Init(); | |
462 EXTI_Wakeup_Button_DeInit(); | |
463 ADCx_Init(); | |
464 GPIO_Power_MainCPU_Init(); | |
465 GPIO_Power_MainCPU_ON(); | |
466 compass_init(0, 7); | |
467 accelerator_init(); | |
148
ee744c7160ce
Use SPI TX callback to synchronize to main CPU
Ideenmodellierer
parents:
134
diff
changeset
|
468 SPI_synchronize_with_Master(); |
89 | 469 MX_DMA_Init(); |
470 MX_SPI1_Init(); | |
148
ee744c7160ce
Use SPI TX callback to synchronize to main CPU
Ideenmodellierer
parents:
134
diff
changeset
|
471 SPI_Start_single_TxRx_with_Master(); |
89 | 472 |
473 // EXTILine0_Button_DeInit(); not now, later after testing | |
474 break; | |
475 } | |
120 | 476 |
477 #ifdef DEBUG_RUNTIME | |
478 HAL_RTC_GetTime(&RTCHandle, &Stime, RTC_FORMAT_BCD); | |
479 | |
480 if(lastsecond == 0xFF) | |
481 { | |
482 measurementindex = 0; | |
483 loopcnt[measurementindex] = 0; | |
484 lastsecond = Stime.Seconds; | |
485 } | |
486 loopcnt[measurementindex]++; | |
487 | |
488 if(lastsecond != Stime.Seconds) | |
489 { | |
490 measurementindex++; | |
491 if (measurementindex == MEASURECNT) measurementindex = 0; | |
492 loopcnt[measurementindex] = 0; | |
493 lastsecond = Stime.Seconds; | |
494 if(measurementindex +1 < MEASURECNT) loopcnt[measurementindex +1] = 0xffff; /* helps to identify the latest value */ | |
495 } | |
496 #endif | |
89 | 497 } |
38 | 498 } |
499 | |
500 /** @brief Button feedback - EXTI line detection callbacks | |
501 * @param GPIO_Pin: Specifies the pins connected EXTI line | |
502 * @retval None | |
503 */ | |
89 | 504 void HAL_GPIO_EXTI_Callback(uint16_t GPIO_Pin) { |
38 | 505 |
89 | 506 if (GPIO_Pin == BUTTON_OSTC_GPIO_PIN) { |
507 if (global.mode == MODE_SLEEP) { | |
508 global.mode = MODE_BOOT; | |
509 } | |
510 } | |
511 else | |
512 if (GPIO_Pin == BUTTON_TEST_GPIO_PIN) { | |
513 if (!global.demo_mode && (global.mode == MODE_SURFACE)) { | |
514 global.demo_mode = 1; | |
515 global.mode = MODE_DIVE; | |
516 } else if (global.demo_mode && (global.mode == MODE_DIVE) | |
517 && (global.lifeData.dive_time_seconds > 10)) { | |
518 global.demo_mode = 0; | |
519 global.dataSendToMaster.mode = MODE_ENDDIVE; | |
520 global.deviceDataSendToMaster.mode = MODE_ENDDIVE; | |
521 } | |
522 } | |
38 | 523 } |
524 | |
525 /** | |
526 * @brief System Clock Configuration | |
527 * The system Clock is configured as follow : | |
528 * System Clock source = PLL (HSI) | |
529 * SYSCLK(Hz) = 100 MHz | |
530 * HCLK(Hz) = 100 MHz | |
531 * AHB Prescaler = 1 | |
532 * APB1 Prescaler = 2 | |
533 * APB2 Prescaler = 1 | |
534 * HSI Frequency(Hz) = 16 MHz | |
535 * PLL_M = 16 | |
536 * PLL_N = 400 | |
537 * PLL_P = 4 | |
538 * PLL_Q = 7 // no USB | |
539 * VDD(V) = 3.3 | |
540 * Main regulator output voltage = Scale1 mode | |
541 * Flash Latency(WS) = 3 | |
542 * @param None | |
543 * @retval None | |
544 */ | |
545 | |
89 | 546 void SystemClock_Config(void) { |
547 if (hasExternalClock()) | |
548 SystemClock_Config_HSE(); | |
549 else | |
550 SystemClock_Config_HSI(); | |
38 | 551 } |
552 | |
89 | 553 void SYSCLKConfig_STOP(void) { |
554 SYSCLKConfig_STOP_HSI(); | |
38 | 555 } |
556 | |
89 | 557 void SystemClock_Config_HSE(void) { |
558 RCC_OscInitTypeDef RCC_OscInitStruct; | |
559 RCC_ClkInitTypeDef RCC_ClkInitStruct; | |
38 | 560 // RCC_PeriphCLKInitTypeDef PeriphClkInitStruct; |
561 | |
89 | 562 __PWR_CLK_ENABLE(); // is identical to __HAL_RCC_PWR_CLK_ENABLE(); |
38 | 563 |
89 | 564 __HAL_PWR_VOLTAGESCALING_CONFIG(PWR_REGULATOR_VOLTAGE_SCALE2); |
38 | 565 |
89 | 566 RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSE; //|RCC_OSCILLATORTYPE_LSE; |
567 RCC_OscInitStruct.HSEState = RCC_HSE_ON; | |
568 //RCC_OscInitStruct.LSEState = RCC_LSE_ON; | |
569 RCC_OscInitStruct.PLL.PLLState = RCC_PLL_ON; | |
570 RCC_OscInitStruct.PLL.PLLSource = RCC_PLLSOURCE_HSE; | |
571 RCC_OscInitStruct.PLL.PLLM = 8; | |
572 RCC_OscInitStruct.PLL.PLLN = 320; | |
573 RCC_OscInitStruct.PLL.PLLP = RCC_PLLP_DIV4; | |
574 RCC_OscInitStruct.PLL.PLLQ = 4; | |
575 HAL_RCC_OscConfig(&RCC_OscInitStruct); | |
38 | 576 |
89 | 577 RCC_ClkInitStruct.ClockType = RCC_CLOCKTYPE_HCLK | RCC_CLOCKTYPE_SYSCLK |
578 | RCC_CLOCKTYPE_PCLK1 | RCC_CLOCKTYPE_PCLK2; | |
579 RCC_ClkInitStruct.SYSCLKSource = RCC_SYSCLKSOURCE_PLLCLK; | |
580 RCC_ClkInitStruct.AHBCLKDivider = RCC_SYSCLK_DIV1; | |
581 RCC_ClkInitStruct.APB1CLKDivider = RCC_HCLK_DIV2; | |
582 RCC_ClkInitStruct.APB2CLKDivider = RCC_HCLK_DIV1; | |
583 HAL_RCC_ClockConfig(&RCC_ClkInitStruct, FLASH_LATENCY_2); | |
38 | 584 |
585 // PeriphClkInitStruct.PeriphClockSelection = RCC_PERIPHCLK_RTC; | |
586 // PeriphClkInitStruct.RTCClockSelection = RCC_RTCCLKSOURCE_LSE; | |
587 // HAL_RCCEx_PeriphCLKConfig(&PeriphClkInitStruct); | |
588 | |
589 // HAL_SYSTICK_Config(HAL_RCC_GetHCLKFreq()/1000); | |
590 | |
591 // HAL_SYSTICK_CLKSourceConfig(SYSTICK_CLKSOURCE_HCLK); | |
592 | |
89 | 593 /* SysTick_IRQn interrupt configuration */ |
38 | 594 // HAL_NVIC_SetPriority(SysTick_IRQn, 0, 0); |
595 } | |
596 | |
89 | 597 void SystemClock_Config_HSI(void) { |
598 RCC_ClkInitTypeDef RCC_ClkInitStruct; | |
599 RCC_OscInitTypeDef RCC_OscInitStruct; | |
38 | 600 |
89 | 601 /* Enable Power Control clock */ |
602 __HAL_RCC_PWR_CLK_ENABLE(); | |
38 | 603 |
89 | 604 /* The voltage scaling allows optimizing the power consumption when the device is |
605 clocked below the maximum system frequency, to update the voltage scaling value | |
606 regarding system frequency refer to product datasheet. */ | |
607 __HAL_PWR_VOLTAGESCALING_CONFIG(PWR_REGULATOR_VOLTAGE_SCALE2); | |
38 | 608 |
89 | 609 /* Enable HSI Oscillator and activate PLL with HSI as source */ |
610 RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSI; | |
611 RCC_OscInitStruct.HSIState = RCC_HSI_ON; | |
612 RCC_OscInitStruct.HSICalibrationValue = 0x10; | |
613 RCC_OscInitStruct.PLL.PLLState = RCC_PLL_ON; | |
614 RCC_OscInitStruct.PLL.PLLSource = RCC_PLLSOURCE_HSI; | |
615 RCC_OscInitStruct.PLL.PLLM = 16; | |
616 RCC_OscInitStruct.PLL.PLLN = 320; | |
617 RCC_OscInitStruct.PLL.PLLP = RCC_PLLP_DIV4; | |
618 RCC_OscInitStruct.PLL.PLLQ = 4; | |
619 HAL_RCC_OscConfig(&RCC_OscInitStruct); | |
38 | 620 |
89 | 621 /* Select PLL as system clock source and configure the HCLK, PCLK1 and PCLK2 |
622 clocks dividers */ | |
623 RCC_ClkInitStruct.ClockType = (RCC_CLOCKTYPE_SYSCLK | RCC_CLOCKTYPE_HCLK | |
624 | RCC_CLOCKTYPE_PCLK1 | RCC_CLOCKTYPE_PCLK2); | |
625 RCC_ClkInitStruct.SYSCLKSource = RCC_SYSCLKSOURCE_PLLCLK; | |
626 RCC_ClkInitStruct.AHBCLKDivider = RCC_SYSCLK_DIV1; | |
627 RCC_ClkInitStruct.APB1CLKDivider = RCC_HCLK_DIV2; | |
628 RCC_ClkInitStruct.APB2CLKDivider = RCC_HCLK_DIV1; | |
629 HAL_RCC_ClockConfig(&RCC_ClkInitStruct, FLASH_LATENCY_2); | |
38 | 630 } |
631 /* | |
632 RCC_OscInitTypeDef RCC_OscInitStruct; | |
633 RCC_ClkInitTypeDef RCC_ClkInitStruct; | |
634 | |
635 __HAL_RCC_PWR_CLK_ENABLE(); | |
636 | |
637 //__PWR_CLK_ENABLE(); | |
638 | |
639 __HAL_PWR_VOLTAGESCALING_CONFIG(PWR_REGULATOR_VOLTAGE_SCALE2); | |
640 | |
641 RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSI|RCC_OSCILLATORTYPE_LSE; | |
642 RCC_OscInitStruct.LSEState = RCC_LSE_ON; | |
643 RCC_OscInitStruct.HSIState = RCC_HSI_ON; | |
644 RCC_OscInitStruct.HSICalibrationValue = 16; | |
645 RCC_OscInitStruct.PLL.PLLState = RCC_PLL_ON; | |
646 RCC_OscInitStruct.PLL.PLLSource = RCC_PLLSOURCE_HSI; | |
647 RCC_OscInitStruct.PLL.PLLM = 16; | |
648 RCC_OscInitStruct.PLL.PLLN = 320; | |
649 RCC_OscInitStruct.PLL.PLLP = RCC_PLLP_DIV4; | |
650 RCC_OscInitStruct.PLL.PLLQ = 4; | |
651 HAL_RCC_OscConfig(&RCC_OscInitStruct); | |
652 | |
653 RCC_ClkInitStruct.ClockType = RCC_CLOCKTYPE_SYSCLK|RCC_CLOCKTYPE_PCLK1; | |
654 RCC_ClkInitStruct.SYSCLKSource = RCC_SYSCLKSOURCE_PLLCLK; | |
655 RCC_ClkInitStruct.AHBCLKDivider = RCC_SYSCLK_DIV1; | |
656 RCC_ClkInitStruct.APB1CLKDivider = RCC_HCLK_DIV2; | |
657 RCC_ClkInitStruct.APB2CLKDivider = RCC_HCLK_DIV1; | |
658 HAL_RCC_ClockConfig(&RCC_ClkInitStruct, FLASH_LATENCY_2); | |
659 } | |
660 | |
661 static void RtcClock_Config(void) | |
662 { | |
663 RCC_PeriphCLKInitTypeDef PeriphClkInitStruct; | |
664 PeriphClkInitStruct.PeriphClockSelection = RCC_PERIPHCLK_RTC; | |
665 PeriphClkInitStruct.RTCClockSelection = RCC_RTCCLKSOURCE_LSE; | |
666 HAL_RCCEx_PeriphCLKConfig(&PeriphClkInitStruct); | |
667 } | |
668 */ | |
669 | |
670 /** | |
671 * @brief Configures system clock after wake-up from STOP: enable HSI, PLL | |
672 * and select PLL as system clock source. | |
673 * @param None | |
674 * @retval None | |
675 */ | |
89 | 676 void SYSCLKConfig_STOP_HSE(void) { |
677 RCC_ClkInitTypeDef RCC_ClkInitStruct; | |
678 RCC_OscInitTypeDef RCC_OscInitStruct; | |
679 uint32_t pFLatency = 0; | |
38 | 680 |
89 | 681 /* Get the Oscillators configuration according to the internal RCC registers */ |
682 HAL_RCC_GetOscConfig(&RCC_OscInitStruct); | |
38 | 683 |
89 | 684 /* After wake-up from STOP reconfigure the system clock: Enable HSI and PLL */ |
685 RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSE; | |
686 RCC_OscInitStruct.HSIState = RCC_HSE_ON; | |
687 RCC_OscInitStruct.PLL.PLLState = RCC_PLL_ON; | |
688 HAL_RCC_OscConfig(&RCC_OscInitStruct); | |
38 | 689 |
89 | 690 /* Get the Clocks configuration according to the internal RCC registers */ |
691 HAL_RCC_GetClockConfig(&RCC_ClkInitStruct, &pFLatency); | |
38 | 692 |
89 | 693 /* Select PLL as system clock source and configure the HCLK, PCLK1 and PCLK2 |
694 clocks dividers */ | |
695 RCC_ClkInitStruct.ClockType = RCC_CLOCKTYPE_SYSCLK; | |
696 RCC_ClkInitStruct.SYSCLKSource = RCC_SYSCLKSOURCE_PLLCLK; | |
697 HAL_RCC_ClockConfig(&RCC_ClkInitStruct, pFLatency); | |
38 | 698 } |
699 | |
89 | 700 void SYSCLKConfig_STOP_HSI(void) { |
701 RCC_ClkInitTypeDef RCC_ClkInitStruct; | |
702 RCC_OscInitTypeDef RCC_OscInitStruct; | |
703 uint32_t pFLatency = 0; | |
38 | 704 |
89 | 705 /* Get the Oscillators configuration according to the internal RCC registers */ |
706 HAL_RCC_GetOscConfig(&RCC_OscInitStruct); | |
38 | 707 |
89 | 708 /* After wake-up from STOP reconfigure the system clock: Enable HSI and PLL */ |
709 RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSI; | |
710 RCC_OscInitStruct.HSIState = RCC_HSI_ON; | |
711 RCC_OscInitStruct.PLL.PLLState = RCC_PLL_ON; | |
712 RCC_OscInitStruct.HSICalibrationValue = 0x10; | |
713 HAL_RCC_OscConfig(&RCC_OscInitStruct); | |
38 | 714 |
89 | 715 /* Get the Clocks configuration according to the internal RCC registers */ |
716 HAL_RCC_GetClockConfig(&RCC_ClkInitStruct, &pFLatency); | |
38 | 717 |
89 | 718 /* Select PLL as system clock source and configure the HCLK, PCLK1 and PCLK2 |
719 clocks dividers */ | |
720 RCC_ClkInitStruct.ClockType = RCC_CLOCKTYPE_SYSCLK; | |
721 RCC_ClkInitStruct.SYSCLKSource = RCC_SYSCLKSOURCE_PLLCLK; | |
722 HAL_RCC_ClockConfig(&RCC_ClkInitStruct, pFLatency); | |
38 | 723 } |
724 | |
725 /** | |
726 * @brief SYSTICK callback | |
727 * @param None | |
728 * @retval None | |
729 */ | |
89 | 730 void HAL_SYSTICK_Callback(void) { |
731 HAL_IncTick(); | |
38 | 732 } |
733 | |
734 /** | |
735 * @brief Configures GPIO for LED | |
736 * Might move with STM32Cube usage | |
737 * @param None | |
738 * @retval None | |
739 */ | |
740 /* | |
741 void GPIO_test_I2C_lines(void) | |
742 { | |
743 GPIO_InitTypeDef GPIO_InitStructure; | |
744 __GPIOB_CLK_ENABLE(); | |
745 GPIO_InitStructure.Pin = GPIO_PIN_8; | |
746 GPIO_InitStructure.Mode = GPIO_MODE_OUTPUT_PP; | |
747 GPIO_InitStructure.Pull = GPIO_PULLUP; | |
748 GPIO_InitStructure.Speed = GPIO_SPEED_LOW; | |
749 HAL_GPIO_Init(GPIOB, &GPIO_InitStructure); | |
750 GPIO_InitStructure.Pin = GPIO_PIN_9; | |
751 HAL_GPIO_Init(GPIOB, &GPIO_InitStructure); | |
752 | |
753 HAL_GPIO_WritePin(GPIOB,GPIO_PIN_8,GPIO_PIN_SET); | |
754 HAL_GPIO_WritePin(GPIOB,GPIO_PIN_9,GPIO_PIN_RESET); | |
755 HAL_Delay(10); | |
756 HAL_GPIO_WritePin(GPIOB,GPIO_PIN_9,GPIO_PIN_SET); | |
757 HAL_GPIO_WritePin(GPIOB,GPIO_PIN_8,GPIO_PIN_RESET); | |
758 HAL_Delay(10); | |
759 } | |
760 */ | |
761 | |
89 | 762 static void GPIO_LED_Init(void) { |
763 GPIO_InitTypeDef GPIO_InitStructure; | |
38 | 764 |
89 | 765 __GPIOC_CLK_ENABLE(); |
766 GPIO_InitStructure.Pin = GPIO_PIN_3; | |
767 GPIO_InitStructure.Mode = GPIO_MODE_OUTPUT_PP; | |
768 GPIO_InitStructure.Pull = GPIO_PULLUP; | |
769 GPIO_InitStructure.Speed = GPIO_SPEED_FAST; | |
770 HAL_GPIO_Init( GPIOC, &GPIO_InitStructure); | |
38 | 771 } |
772 | |
89 | 773 void GPIO_new_DEBUG_Init(void) { |
38 | 774 #ifdef DEBUG_PIN_ACTIVE |
89 | 775 GPIO_InitTypeDef GPIO_InitStructure; |
38 | 776 |
89 | 777 __GPIOC_CLK_ENABLE(); |
778 GPIO_InitStructure.Pin = GPIO_PIN_3; | |
779 GPIO_InitStructure.Mode = GPIO_MODE_OUTPUT_PP; | |
780 GPIO_InitStructure.Pull = GPIO_PULLUP; | |
781 GPIO_InitStructure.Speed = GPIO_SPEED_FAST; | |
782 HAL_GPIO_Init(GPIOA, &GPIO_InitStructure); | |
38 | 783 #endif |
784 } | |
785 | |
89 | 786 void GPIO_new_DEBUG_LOW(void) { |
38 | 787 #ifdef DEBUG_PIN_ACTIVE |
89 | 788 HAL_GPIO_WritePin(GPIOC,GPIO_PIN_3,GPIO_PIN_RESET); |
38 | 789 #endif |
790 } | |
791 | |
89 | 792 void GPIO_new_DEBUG_HIGH(void) { |
38 | 793 #ifdef DEBUG_PIN_ACTIVE |
89 | 794 HAL_GPIO_WritePin(GPIOC,GPIO_PIN_3,GPIO_PIN_SET); |
38 | 795 #endif |
796 } | |
797 | |
89 | 798 static void GPIO_Power_MainCPU_Init(void) { |
799 GPIO_InitTypeDef GPIO_InitStructure; | |
800 __GPIOC_CLK_ENABLE(); | |
801 GPIO_InitStructure.Pin = GPIO_PIN_0; | |
802 GPIO_InitStructure.Mode = GPIO_MODE_OUTPUT_PP; | |
803 GPIO_InitStructure.Pull = GPIO_PULLUP; | |
804 GPIO_InitStructure.Speed = GPIO_SPEED_LOW; | |
805 HAL_GPIO_Init( GPIOC, &GPIO_InitStructure); | |
806 HAL_GPIO_WritePin( GPIOC, GPIO_PIN_0, GPIO_PIN_RESET); | |
38 | 807 } |
808 | |
89 | 809 static void GPIO_Power_MainCPU_ON(void) { |
810 HAL_GPIO_WritePin( GPIOC, GPIO_PIN_0, GPIO_PIN_RESET); | |
38 | 811 } |
812 | |
89 | 813 static void GPIO_Power_MainCPU_OFF(void) { |
814 HAL_GPIO_WritePin( GPIOC, GPIO_PIN_0, GPIO_PIN_SET); | |
38 | 815 } |
816 | |
817 /** | |
818 * @brief Configures EXTI Line0 (connected to PA0 + PA1 pin) in interrupt mode | |
819 * @param None | |
820 * @retval None | |
821 */ | |
822 | |
89 | 823 static void EXTI_Wakeup_Button_Init(void) { |
824 GPIO_InitTypeDef GPIO_InitStructure; | |
38 | 825 |
89 | 826 __HAL_RCC_GPIOA_CLK_ENABLE(); |
827 BUTTON_OSTC_HAL_RCC_GPIO_CLK_ENABLE(); | |
828 GPIO_InitStructure.Pin = BUTTON_OSTC_GPIO_PIN; | |
829 GPIO_InitStructure.Mode = GPIO_MODE_IT_FALLING; | |
830 GPIO_InitStructure.Pull = GPIO_NOPULL; | |
831 HAL_GPIO_Init( BUTTON_OSTC_GPIO_PORT, &GPIO_InitStructure); | |
38 | 832 |
89 | 833 HAL_NVIC_SetPriority( BUTTON_OSTC_IRQn, 0x0F, 0); |
834 HAL_NVIC_EnableIRQ( BUTTON_OSTC_IRQn); | |
38 | 835 } |
836 | |
89 | 837 static void EXTI_Wakeup_Button_DeInit(void) { |
838 GPIO_InitTypeDef GPIO_InitStructure; | |
38 | 839 |
89 | 840 GPIO_InitStructure.Mode = GPIO_MODE_ANALOG; |
841 GPIO_InitStructure.Speed = GPIO_SPEED_LOW; | |
842 GPIO_InitStructure.Pull = GPIO_NOPULL; | |
38 | 843 |
89 | 844 GPIO_InitStructure.Pin = BUTTON_OSTC_GPIO_PIN; |
845 HAL_GPIO_Init( BUTTON_OSTC_GPIO_PORT, &GPIO_InitStructure); | |
846 HAL_NVIC_DisableIRQ( BUTTON_OSTC_IRQn); | |
38 | 847 } |
848 | |
89 | 849 static void EXTI_Test_Button_Init(void) { |
850 GPIO_InitTypeDef GPIO_InitStructure; | |
38 | 851 |
89 | 852 BUTTON_TEST_GPIO_CLK_ENABLE(); |
853 GPIO_InitStructure.Pin = BUTTON_TEST_GPIO_PIN; | |
854 GPIO_InitStructure.Mode = GPIO_MODE_IT_FALLING; | |
855 GPIO_InitStructure.Pull = GPIO_PULLUP; | |
856 HAL_GPIO_Init( BUTTON_TEST_GPIO_PORT, &GPIO_InitStructure); | |
857 HAL_NVIC_SetPriority( BUTTON_TEST_IRQn, 0x0F, 0); | |
858 HAL_NVIC_EnableIRQ( BUTTON_TEST_IRQn); | |
38 | 859 } |
860 | |
89 | 861 static void EXTI_Test_Button_DeInit(void) { |
862 GPIO_InitTypeDef GPIO_InitStructure; | |
38 | 863 |
89 | 864 GPIO_InitStructure.Mode = GPIO_MODE_ANALOG; |
865 GPIO_InitStructure.Speed = GPIO_SPEED_LOW; | |
866 GPIO_InitStructure.Pull = GPIO_NOPULL; | |
38 | 867 |
89 | 868 GPIO_InitStructure.Pin = BUTTON_TEST_GPIO_PIN; |
869 HAL_GPIO_Init( BUTTON_TEST_GPIO_PORT, &GPIO_InitStructure); | |
870 HAL_NVIC_DisableIRQ( BUTTON_TEST_IRQn); | |
38 | 871 } |
872 | |
873 /* NUCLEO C 13 | |
874 KEY_BUTTON_GPIO_CLK_ENABLE(); | |
875 GPIO_InitStructure.Mode = GPIO_MODE_IT_FALLING; | |
876 GPIO_InitStructure.Pull = GPIO_NOPULL; | |
877 GPIO_InitStructure.Pin = KEY_BUTTON_PIN; | |
878 HAL_GPIO_Init(KEY_BUTTON_GPIO_PORT, &GPIO_InitStructure); | |
879 HAL_NVIC_SetPriority(KEY_BUTTON_EXTI_IRQn, 2, 0); | |
880 HAL_NVIC_EnableIRQ(KEY_BUTTON_EXTI_IRQn); | |
881 */ | |
882 | |
883 /** | |
884 * @brief Wake Up Timer callback | |
885 * @param hrtc: RTC handle | |
886 * @retval None | |
887 */ | |
888 | |
889 /* | |
890 void HAL_RTCEx_WakeUpTimerEventCallback(RTC_HandleTypeDef *hrtc) | |
891 { | |
892 static uint8_t uwCounter = 0; | |
893 uwCounter = 1; | |
894 } | |
895 */ | |
896 | |
89 | 897 void HAL_I2C_MasterTxCpltCallback(I2C_HandleTypeDef *I2cHandle) { |
38 | 898 |
899 } | |
900 | |
89 | 901 void HAL_I2C_MasterRxCpltCallback(I2C_HandleTypeDef *I2cHandle) { |
38 | 902 |
903 } | |
904 | |
89 | 905 void HAL_I2C_ErrorCallback(I2C_HandleTypeDef *I2cHandle) { |
38 | 906 |
907 } | |
908 | |
89 | 909 void sleep_prepare(void) { |
910 EXTI_Wakeup_Button_Init(); | |
911 /* | |
912 GPIO_InitStruct.Pull = GPIO_PULLUP; | |
913 GPIO_InitStruct.Pin = GPIO_PIN_0; | |
914 HAL_GPIO_Init(GPIOA, &GPIO_InitStruct); | |
915 */ | |
916 compass_sleep(); | |
917 HAL_Delay(100); | |
918 accelerator_sleep(); | |
919 HAL_Delay(100); | |
38 | 920 |
89 | 921 I2C_DeInit(); |
922 MX_SPI_DeInit(); | |
923 MX_SPI3_DeInit(); | |
924 ADCx_DeInit(); | |
38 | 925 |
89 | 926 GPIO_InitTypeDef GPIO_InitStruct; |
38 | 927 |
89 | 928 __HAL_RCC_GPIOA_CLK_ENABLE(); |
929 __HAL_RCC_GPIOB_CLK_ENABLE(); | |
930 __HAL_RCC_GPIOC_CLK_ENABLE(); | |
931 __HAL_RCC_GPIOH_CLK_ENABLE(); | |
38 | 932 |
89 | 933 GPIO_InitStruct.Mode = GPIO_MODE_ANALOG; |
934 GPIO_InitStruct.Speed = GPIO_SPEED_HIGH; | |
935 GPIO_InitStruct.Pull = GPIO_NOPULL; | |
936 GPIO_InitStruct.Pin = GPIO_PIN_All; | |
937 HAL_GPIO_Init( GPIOH, &GPIO_InitStruct); | |
38 | 938 #ifdef DEBUGMODE |
89 | 939 GPIO_InitStruct.Pin = GPIO_PIN_All ^ ( GPIO_PIN_3 | GPIO_PIN_8 | GPIO_PIN_9); /* debug */ |
38 | 940 #endif |
89 | 941 HAL_GPIO_Init( GPIOB, &GPIO_InitStruct); |
38 | 942 |
89 | 943 GPIO_InitStruct.Pin = |
944 GPIO_PIN_All | |
945 ^ ( GPIO_PIN_0 | GPIO_PIN_1 | GPIO_PIN_2 | GPIO_PIN_14 | |
946 | GPIO_PIN_15); /* power off & charger in & charge out & OSC32*/ | |
947 HAL_GPIO_Init( GPIOC, &GPIO_InitStruct); | |
38 | 948 |
89 | 949 GPIO_InitStruct.Pin = GPIO_PIN_All ^ ( GPIO_PIN_0); |
38 | 950 #ifdef DEBUGMODE |
89 | 951 GPIO_InitStruct.Pin = GPIO_PIN_All ^ ( GPIO_PIN_0 | GPIO_PIN_13 | GPIO_PIN_14); /* wake up button & debug */ |
38 | 952 #endif |
89 | 953 HAL_GPIO_Init( GPIOA, &GPIO_InitStruct); |
38 | 954 |
89 | 955 GPIO_InitStruct.Pin = GPIO_PIN_All; |
956 HAL_GPIO_Init( GPIOH, &GPIO_InitStruct); | |
38 | 957 |
89 | 958 GPIO_Power_MainCPU_OFF(); |
38 | 959 |
960 #ifndef DEBUGMODE | |
89 | 961 __HAL_RCC_GPIOB_CLK_DISABLE(); |
38 | 962 #endif |
89 | 963 __HAL_RCC_GPIOH_CLK_DISABLE(); |
38 | 964 |
89 | 965 HAL_Delay(1000); |
38 | 966 } |
967 | |
968 /* | |
969 void sleep_test(void) | |
970 { | |
971 GPIO_InitTypeDef GPIO_InitStruct; | |
972 | |
973 __HAL_RCC_GPIOA_CLK_ENABLE(); | |
974 __HAL_RCC_GPIOB_CLK_ENABLE(); | |
975 __HAL_RCC_GPIOC_CLK_ENABLE(); | |
976 __HAL_RCC_GPIOH_CLK_ENABLE(); | |
977 | |
978 GPIO_InitStruct.Mode = GPIO_MODE_ANALOG; | |
979 GPIO_InitStruct.Speed = GPIO_SPEED_HIGH; | |
980 GPIO_InitStruct.Pull = GPIO_NOPULL; | |
981 GPIO_InitStruct.Pin = GPIO_PIN_All; | |
982 HAL_GPIO_Init(GPIOH, &GPIO_InitStruct); | |
983 HAL_GPIO_Init(GPIOB, &GPIO_InitStruct); | |
984 | |
985 GPIO_InitStruct.Pin = GPIO_PIN_All ^ ( GPIO_PIN_0 | GPIO_PIN_15 | GPIO_PIN_14); | |
986 HAL_GPIO_Init(GPIOC, &GPIO_InitStruct); | |
987 | |
988 GPIO_InitStruct.Pin = GPIO_PIN_All ^ ( GPIO_PIN_0); | |
989 HAL_GPIO_Init(GPIOA, &GPIO_InitStruct); | |
990 | |
991 GPIO_Power_MainCPU_OFF(); | |
992 | |
993 GPIO_InitStruct.Pull = GPIO_PULLUP; | |
994 GPIO_InitStruct.Pin = GPIO_PIN_0; | |
995 HAL_GPIO_Init(GPIOA, &GPIO_InitStruct); | |
996 | |
997 // __HAL_RCC_GPIOA_CLK_DISABLE(); | |
998 __HAL_RCC_GPIOB_CLK_DISABLE(); | |
999 // __HAL_RCC_GPIOC_CLK_DISABLE(); | |
1000 __HAL_RCC_GPIOH_CLK_DISABLE(); | |
1001 | |
1002 | |
1003 HAL_Delay(5000); | |
1004 while(1) | |
1005 { | |
1006 RTC_StopMode_2seconds(); | |
1007 HAL_Delay(200); | |
1008 } | |
1009 } | |
1010 */ | |
1011 | |
1012 #ifdef USE_FULL_ASSERT | |
1013 | |
1014 /** | |
1015 * @brief Reports the name of the source file and the source line number | |
1016 * where the assert_param error has occurred. | |
1017 * @param file: pointer to the source file name | |
1018 * @param line: assert_param error line source number | |
1019 * @retval None | |
1020 */ | |
1021 void assert_failed(uint8_t* file, uint32_t line) | |
1022 { | |
89 | 1023 /* User can add his own implementation to report the file name and line number, |
1024 ex: printf("Wrong parameters value: file %s on line %d\r\n", file, line) */ | |
38 | 1025 |
89 | 1026 /* Infinite loop */ |
1027 while (1) | |
1028 { | |
1029 } | |
38 | 1030 } |
1031 #endif | |
1032 | |
1033 /** | |
1034 * @} | |
1035 */ | |
104 | 1036 /** |
1037 * @brief This function handles SysTick Handler. | |
1038 * @param None | |
1039 * @retval None | |
1040 */ | |
38 | 1041 |
104 | 1042 /*TxRx only here. Every 100 ms.*/ |
1043 uint8_t ticks100ms=0; | |
1044 void SysTick_Handler(void) | |
1045 { | |
1046 HAL_IncTick(); | |
1047 if(ticks100ms<100){ | |
1048 ticks100ms++; | |
1049 }else | |
1050 { | |
1051 ticks100ms=0; | |
1052 } | |
1053 } | |
38 | 1054 /** |
1055 * @} | |
1056 */ | |
1057 | |
1058 /************************ (C) COPYRIGHT heinrichs weikamp *****END OF FILE****/ |