Mercurial > public > ostc4
annotate Small_CPU/Src/baseCPU2.c @ 938:df87dbfc9c21 Evo_2_23
Update GPIO:
Splitted the init function and moved GPS deactivation into the sleep loop (deep sleep)
author | Ideenmodellierer |
---|---|
date | Tue, 10 Dec 2024 21:00:55 +0100 |
parents | 3029f0332f4f |
children | 4a406e873a95 |
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 ============================================================================== | |
286
733877ab87d9
Minor: Some Texts fixed, allign RTErequired* values with RTE firmware
heinrichsweikamp
parents:
280
diff
changeset
|
18 ##### What about hardware without 8 MHz oscillator ##### |
38 | 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 ============================================================================== | |
286
733877ab87d9
Minor: Some Texts fixed, allign RTErequired* values with RTE firmware
heinrichsweikamp
parents:
280
diff
changeset
|
36 [..] All realtime stuff and all what has to be done during sleep |
38 | 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 ============================================================================== | |
286
733877ab87d9
Minor: Some Texts fixed, allign RTErequired* values with RTE firmware
heinrichsweikamp
parents:
280
diff
changeset
|
67 The RTC is a separate part of hardware inside the CPU and is not affected |
38 | 68 by reset. Only power-on reset does change something. |
69 This is fine but the RTC is vital for the Sleep mode as Wakeuptimer. | |
70 This is the only date/time system in the OSTC. The main CPU is passive. | |
286
733877ab87d9
Minor: Some Texts fixed, allign RTErequired* values with RTE firmware
heinrichsweikamp
parents:
280
diff
changeset
|
71 Data transfer is done with localtime_rtc_tr and localtime_rtc_dr |
38 | 72 in HAL_RTC format to the main CPU and as HAL_RTC structs the way back for |
73 setting the actual time and date. | |
74 The RTC unit has 20 Byte of V_bat powered SRAM. It could be used | |
286
733877ab87d9
Minor: Some Texts fixed, allign RTErequired* values with RTE firmware
heinrichsweikamp
parents:
280
diff
changeset
|
75 for something useful in both CPUs. |
38 | 76 |
77 ============================================================================== | |
78 ##### File system ##### | |
79 ============================================================================== | |
80 [..] some files are used for both CPUs, like decom.c/.h, data_central.h, ... | |
81 | |
82 | |
83 ============================================================================== | |
84 ##### Unique device ID register (96 bits) ##### | |
85 ============================================================================== | |
86 [..] some files are used for both CPUs, like decom.c/.h, data_central.h, ... | |
87 | |
88 | |
89 ============================================================================== | |
90 ##### I2C ##### | |
91 ============================================================================== | |
92 [..] used for pressure, compass, (accelerator) and battery gauge | |
93 main cpu and pic (button) is spi | |
94 | |
95 | |
96 ============================================================================== | |
97 ##### Firmware Update Info ##### | |
98 ============================================================================== | |
99 V0.85 160531 scheduleCheck_pressure_reached_dive_mode_level() changes | |
286
733877ab87d9
Minor: Some Texts fixed, allign RTErequired* values with RTE firmware
heinrichsweikamp
parents:
280
diff
changeset
|
100 160606 global.no_fly_time_minutes is at least 24h after the dive |
38 | 101 160613 ambient light fixed |
102 160720 compass calib to Flash (8000 writes max. as erase has problems) | |
103 160829 do not reset main CPU on power on! | |
104 V0.91 161018 pressure_calculation_AN520_004_mod_MS5803_30BA__09_2015(); | |
105 V0.92+ 161020 global.sensorError[MAX_SENSORS] | |
106 fix missing init_pressure(); at powerUp of RTE | |
107 added HAL_StatusTypeDef for many functions in pressure.c | |
108 161024 no_fly_time_minutes Backup FIX | |
109 seconds_since_last_dive now related to RTC clock | |
110 161121 close to surface starts at 1 meter below last known surface pressure | |
286
733877ab87d9
Minor: Some Texts fixed, allign RTErequired* values with RTE firmware
heinrichsweikamp
parents:
280
diff
changeset
|
111 161121 in surface mode dive mode starts @1 mtr difference if surface 880 hPa instead of 700 hPa before |
38 | 112 V0.97+ 170213 added global.dataSendToSlave.diveModeInfo for DIVEMODE_Apnea |
113 added global.dataSendToSlave.setEndDive | |
114 DIVEMODE_Apnea special in scheduler.c (ticksdiff >= 1000) -> no tissue, cns, otu, no change in noFly Time etc. | |
115 V0.99 170320 new HAL Driver Repository | |
116 V1.01 170509 old HAL Driver Repository | |
117 | |
118 @endverbatim | |
119 ****************************************************************************** | |
120 * @attention | |
121 * | |
122 * <h2><center>© COPYRIGHT(c) 2017 heinrichs weikamp</center></h2> | |
123 * | |
124 ****************************************************************************** | |
125 */ | |
126 | |
127 //#define DEBUG_PIN_ACTIVE | |
128 /* Includes ------------------------------------------------------------------*/ | |
129 | |
130 #include "baseCPU2.h" | |
131 | |
132 // From Small_CPU/Inc: | |
133 #include "dma.h" | |
134 #include "i2c.h" | |
135 #include "spi.h" | |
136 #include "rtc.h" | |
137 #include "adc.h" | |
936 | 138 #include "gpio.h" |
38 | 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" | |
554
3328189786e7
Added external ADC interface functionality (MCP3424):
Ideenmodellierer
parents:
533
diff
changeset
|
145 #include "externalInterface.h" |
662 | 146 #include "uart.h" |
922 | 147 #include "uart_Internal.h" |
936 | 148 #include "uartProtocol_GNSS.h" |
889 | 149 #include "GNSS.h" |
938 | 150 #include "configuration.h" |
889 | 151 |
38 | 152 |
153 // From Common/Inc: | |
154 #include "calc_crush.h" | |
155 #include "decom.h" | |
156 #include "FirmwareData.h" | |
157 | |
158 // From Common/Drivers/ | |
159 #include <stdio.h> | |
160 | |
889 | 161 |
433 | 162 uint8_t coldstart __attribute__((section (".noinit"))); |
163 | |
89 | 164 uint8_t hasExternalClock(void) { |
165 if ((TM_OTP_Read(0, 0) > 0) && (TM_OTP_Read(0, 0) < 0xFF)) | |
166 return 1; | |
167 else | |
168 return 0; | |
38 | 169 } |
170 | |
171 // SHALL LOAD AT 0x08000000 + 0x00005000 = 0x08005000. | |
172 // See CPU2-RTE.ld | |
100 | 173 const SFirmwareData cpu2_FirmwareData __attribute__(( section(".firmware_data") ))= { |
728
5143e927219f
Added sensor map to Firmware <=> RTE inferface:
Ideenmodellierer
parents:
713
diff
changeset
|
174 .versionFirst = 3, |
899
2225c467f1e9
Added data path and visualization for position data:
Ideenmodellierer
parents:
890
diff
changeset
|
175 .versionSecond = 4, |
762 | 176 .versionThird = 0, |
843 | 177 .versionBeta = 1, |
38 | 178 |
89 | 179 /* 4 bytes with trailing 0 */ |
100 | 180 .signature = "mh", |
38 | 181 |
762 | 182 .release_year = 23, |
818 | 183 .release_month = 9, |
184 .release_day = 14, | |
100 | 185 .release_sub = 0, |
38 | 186 |
89 | 187 /* max 48 with trailing 0 */ |
188 //release_info ="12345678901234567890123456789012345678901" | |
768 | 189 .release_info = "stable April 2023", |
38 | 190 |
89 | 191 /* for safety reasons and coming functions */ |
192 .magic[0] = FIRMWARE_MAGIC_FIRST, .magic[1] = FIRMWARE_MAGIC_SECOND, | |
193 .magic[2] = FIRMWARE_MAGIC_CPU2_RTE, /* the magic byte for RTE */ | |
433 | 194 .magic[3] = FIRMWARE_MAGIC_END |
195 }; | |
196 | |
38 | 197 |
89 | 198 uint8_t firmwareVersionHigh(void) { |
199 return cpu2_FirmwareData.versionFirst; | |
38 | 200 } |
201 | |
89 | 202 uint8_t firmwareVersionLow(void) { |
203 return cpu2_FirmwareData.versionSecond; | |
38 | 204 } |
205 | |
206 /** @addtogroup OSTC4 | |
207 * @{ | |
208 */ | |
209 | |
210 /** @addtogroup CPU2 | |
211 * @{ | |
212 */ | |
213 | |
214 /* Private typedef -----------------------------------------------------------*/ | |
215 /* Private define ------------------------------------------------------------*/ | |
216 #define BUTTON_OSTC_GPIO_PIN GPIO_PIN_0 | |
217 #define BUTTON_OSTC_GPIO_PORT GPIOA | |
218 #define BUTTON_OSTC_HAL_RCC_GPIO_CLK_ENABLE() __HAL_RCC_GPIOA_CLK_ENABLE() | |
219 #define BUTTON_OSTC_IRQn EXTI0_IRQn | |
220 | |
662 | 221 |
38 | 222 /* Private macro -------------------------------------------------------------*/ |
223 | |
224 /* Private variables ---------------------------------------------------------*/ | |
225 uint32_t global_test_time_counter = 0; | |
226 SBackup backup; | |
227 | |
228 /* Private function prototypes -----------------------------------------------*/ | |
229 static void EXTI_Wakeup_Button_Init(void); | |
230 static void EXTI_Wakeup_Button_DeInit(void); | |
231 | |
183 | 232 #ifdef DEBUG_I2C_LINES |
38 | 233 void GPIO_test_I2C_lines(void); |
183 | 234 #endif |
38 | 235 |
236 void sleep_prepare(void); | |
237 | |
238 void SystemClock_Config(void); | |
239 void SystemClock_Config_HSI(void); | |
240 void SystemClock_Config_HSE(void); | |
241 void SYSCLKConfig_STOP_HSI(void); | |
242 void SYSCLKConfig_STOP_HSE(void); | |
243 | |
244 void GPIO_new_DEBUG_Init(void); | |
245 void GPIO_new_DEBUG_LOW(void); | |
246 void GPIO_new_DEBUG_HIGH(void); | |
247 | |
248 #define REGULAR_RUN | |
249 | |
89 | 250 int __io_putchar(int ch) { |
251 ITM_SendChar(ch); | |
252 return ch; | |
38 | 253 } |
254 | |
255 /* Private functions ---------------------------------------------------------*/ | |
256 | |
257 /** | |
258 * @brief Main program | |
259 * @param None | |
260 * @retval None | |
261 */ | |
120 | 262 /* #define DEBUG_RUNTIME TRUE */ |
263 #ifdef DEBUG_RUNTIME | |
264 #define MEASURECNT 60 /* number of measuremets to be stored */ | |
265 static uint32_t loopcnt[MEASURECNT]; | |
266 extern RTC_HandleTypeDef RTCHandle; | |
267 #endif | |
38 | 268 |
89 | 269 int main(void) { |
120 | 270 |
271 #ifdef DEBUG_RUNTIME | |
272 RTC_TimeTypeDef Stime; | |
273 uint8_t measurementindex = 0; | |
274 uint8_t lastsecond = 0xFF; | |
275 #endif | |
276 | |
917
0d6c4b40fae4
Bugfix external interface power up after sleep:
Ideenmodellierer
parents:
909
diff
changeset
|
277 uint8_t extInterfaceActive = 0; |
936 | 278 #if defined ENABLE_GNSS_SUPPORT || defined ENABLE_GPIO_V2 |
279 uint32_t shutdownTick = 0; | |
280 #endif | |
917
0d6c4b40fae4
Bugfix external interface power up after sleep:
Ideenmodellierer
parents:
909
diff
changeset
|
281 |
89 | 282 HAL_Init(); |
283 SystemClock_Config(); | |
38 | 284 |
89 | 285 HAL_SYSTICK_Config(HAL_RCC_GetHCLKFreq() / 1000); |
286 HAL_SYSTICK_CLKSourceConfig( SYSTICK_CLKSOURCE_HCLK); | |
287 HAL_NVIC_SetPriority(SysTick_IRQn, 0, 0); | |
38 | 288 |
89 | 289 MX_RTC_init(); |
880 | 290 GPIO_LEDs_VIBRATION_Init(); |
938 | 291 GPIO_GNSS_Init(); |
89 | 292 GPIO_new_DEBUG_Init(); // added 170322 hw |
293 initGlobals(); | |
38 | 294 |
120 | 295 /* printf("CPU2-RTE running...\n"); */ |
38 | 296 |
329 | 297 HAL_Delay(100); |
298 | |
89 | 299 MX_I2C1_Init(); |
329 | 300 if (global.I2C_SystemStatus != HAL_OK) |
301 { | |
89 | 302 if (MX_I2C1_TestAndClear() == GPIO_PIN_RESET) { |
303 MX_I2C1_TestAndClear(); // do it a second time | |
304 } | |
488
9eeab3fead8f
Added "I2C_DeInit();" in hardware detection routines. It's the recommended way
heinrichsweikamp
parents:
473
diff
changeset
|
305 HAL_Delay(100); |
9eeab3fead8f
Added "I2C_DeInit();" in hardware detection routines. It's the recommended way
heinrichsweikamp
parents:
473
diff
changeset
|
306 I2C_DeInit(); |
9eeab3fead8f
Added "I2C_DeInit();" in hardware detection routines. It's the recommended way
heinrichsweikamp
parents:
473
diff
changeset
|
307 HAL_Delay(100); |
89 | 308 MX_I2C1_Init(); |
488
9eeab3fead8f
Added "I2C_DeInit();" in hardware detection routines. It's the recommended way
heinrichsweikamp
parents:
473
diff
changeset
|
309 HAL_Delay(100); |
89 | 310 } |
38 | 311 |
329 | 312 |
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]; | |
329 | 318 if (global.I2C_SystemStatus != HAL_OK) |
319 { | |
89 | 320 if (MX_I2C1_TestAndClear() == GPIO_PIN_RESET) { |
321 MX_I2C1_TestAndClear(); // do it a second time | |
322 } | |
488
9eeab3fead8f
Added "I2C_DeInit();" in hardware detection routines. It's the recommended way
heinrichsweikamp
parents:
473
diff
changeset
|
323 HAL_Delay(100); |
9eeab3fead8f
Added "I2C_DeInit();" in hardware detection routines. It's the recommended way
heinrichsweikamp
parents:
473
diff
changeset
|
324 I2C_DeInit(); |
9eeab3fead8f
Added "I2C_DeInit();" in hardware detection routines. It's the recommended way
heinrichsweikamp
parents:
473
diff
changeset
|
325 HAL_Delay(100); |
89 | 326 MX_I2C1_Init(); |
488
9eeab3fead8f
Added "I2C_DeInit();" in hardware detection routines. It's the recommended way
heinrichsweikamp
parents:
473
diff
changeset
|
327 HAL_Delay(100); |
89 | 328 global.sensorError[SENSOR_PRESSURE_ID] = init_pressure(); |
329 global.I2C_SystemStatus = global.sensorError[SENSOR_PRESSURE_ID]; | |
330 } | |
38 | 331 |
89 | 332 global.dataSendToMaster.sensorErrors = |
333 global.sensorError[SENSOR_PRESSURE_ID]; | |
329 | 334 |
335 if(is_init_pressure_done()) | |
336 { | |
339
37f45300bc2e
Apply averaging to pressure measurement: In pre versions calculated pressure value jittered +/-10hPa. Since we measure the pressure several time a second but only use one value a second, calc average including not used values
ideenmodellierer
parents:
334
diff
changeset
|
337 init_surface_ring(0); |
329 | 338 } |
89 | 339 init_battery_gas_gauge(); |
340 HAL_Delay(10); | |
341 battery_gas_gauge_get_data(); | |
473
edfc1a464b42
Do not signal power on reset in case of a "warm" reset:
ideenmodellierer
parents:
439
diff
changeset
|
342 |
662 | 343 global.lifeData.battery_voltage = get_voltage(); |
344 global.lifeData.battery_charge = get_charge(); | |
345 copyBatteryData(); | |
346 | |
473
edfc1a464b42
Do not signal power on reset in case of a "warm" reset:
ideenmodellierer
parents:
439
diff
changeset
|
347 MX_SPI3_Init(); |
edfc1a464b42
Do not signal power on reset in case of a "warm" reset:
ideenmodellierer
parents:
439
diff
changeset
|
348 |
edfc1a464b42
Do not signal power on reset in case of a "warm" reset:
ideenmodellierer
parents:
439
diff
changeset
|
349 if(coldstart != 0xA5) /* Not reading a 0xA5 means the memory cells has not been initialized before => cold start */ |
433 | 350 { |
351 coldstart = 0xA5; | |
662 | 352 |
353 set_charge_state(Charger_ColdStart); | |
354 | |
473
edfc1a464b42
Do not signal power on reset in case of a "warm" reset:
ideenmodellierer
parents:
439
diff
changeset
|
355 global.dataSendToMaster.power_on_reset = 1; |
edfc1a464b42
Do not signal power on reset in case of a "warm" reset:
ideenmodellierer
parents:
439
diff
changeset
|
356 global.deviceDataSendToMaster.power_on_reset = 1; |
edfc1a464b42
Do not signal power on reset in case of a "warm" reset:
ideenmodellierer
parents:
439
diff
changeset
|
357 |
edfc1a464b42
Do not signal power on reset in case of a "warm" reset:
ideenmodellierer
parents:
439
diff
changeset
|
358 if (!scheduleSetButtonResponsiveness()) |
edfc1a464b42
Do not signal power on reset in case of a "warm" reset:
ideenmodellierer
parents:
439
diff
changeset
|
359 { |
763
aa6006975e76
increase HAL_Delay to 10ms for cold-start-button reset
heinrichsweikamp
parents:
762
diff
changeset
|
360 HAL_Delay(10); |
473
edfc1a464b42
Do not signal power on reset in case of a "warm" reset:
ideenmodellierer
parents:
439
diff
changeset
|
361 if (!scheduleSetButtonResponsiveness()) // send again, if problem it's not my problem here. |
edfc1a464b42
Do not signal power on reset in case of a "warm" reset:
ideenmodellierer
parents:
439
diff
changeset
|
362 { |
763
aa6006975e76
increase HAL_Delay to 10ms for cold-start-button reset
heinrichsweikamp
parents:
762
diff
changeset
|
363 HAL_Delay(10); |
473
edfc1a464b42
Do not signal power on reset in case of a "warm" reset:
ideenmodellierer
parents:
439
diff
changeset
|
364 scheduleSetButtonResponsiveness(); // init |
763
aa6006975e76
increase HAL_Delay to 10ms for cold-start-button reset
heinrichsweikamp
parents:
762
diff
changeset
|
365 HAL_Delay(10); |
473
edfc1a464b42
Do not signal power on reset in case of a "warm" reset:
ideenmodellierer
parents:
439
diff
changeset
|
366 } |
edfc1a464b42
Do not signal power on reset in case of a "warm" reset:
ideenmodellierer
parents:
439
diff
changeset
|
367 } |
433 | 368 } |
662 | 369 else |
370 { | |
371 set_charge_state(Charger_NotConnected); | |
372 } | |
38 | 373 |
89 | 374 ADCx_Init(); |
375 GPIO_Power_MainCPU_Init(); | |
662 | 376 |
377 externalInterface_InitPower33(); | |
378 | |
89 | 379 global.mode = MODE_POWERUP; |
38 | 380 #else |
89 | 381 init_pressure(); |
339
37f45300bc2e
Apply averaging to pressure measurement: In pre versions calculated pressure value jittered +/-10hPa. Since we measure the pressure several time a second but only use one value a second, calc average including not used values
ideenmodellierer
parents:
334
diff
changeset
|
382 init_surface_ring(0); |
38 | 383 |
89 | 384 ADCx_Init(); |
385 GPIO_Power_MainCPU_Init(); | |
386 global.mode = MODE_TEST; | |
38 | 387 #endif |
89 | 388 while (1) { |
120 | 389 /* printf("Global mode = %d\n", global.mode); */ |
38 | 390 |
89 | 391 switch (global.mode) { |
392 case MODE_POWERUP: | |
393 case MODE_BOOT: | |
394 // ReInit_battery_charger_status_pins(); | |
395 compass_init(0, 7); | |
396 accelerator_init(); | |
554
3328189786e7
Added external ADC interface functionality (MCP3424):
Ideenmodellierer
parents:
533
diff
changeset
|
397 externalInterface_Init(); |
181 | 398 |
89 | 399 if (global.mode == MODE_BOOT) { |
400 GPIO_Power_MainCPU_OFF(); | |
922 | 401 #ifdef ENABLE_GPIO_V2 |
880 | 402 GPIO_LED_GREEN_ON(); |
903
0f2e5a166d40
Disable GNSS operations using compile switch:
Ideenmodellierer
parents:
900
diff
changeset
|
403 #endif |
89 | 404 HAL_Delay(100); // for GPIO_Power_MainCPU_ON(); |
405 GPIO_Power_MainCPU_ON(); | |
922 | 406 #ifdef ENABLE_GPIO_V2 |
880 | 407 GPIO_LED_GREEN_OFF(); |
408 | |
409 GPIO_LED_RED_ON(); | |
900 | 410 GPIO_VIBRATION_ON(); |
903
0f2e5a166d40
Disable GNSS operations using compile switch:
Ideenmodellierer
parents:
900
diff
changeset
|
411 #endif |
880 | 412 HAL_Delay(100); |
922 | 413 #ifdef ENABLE_GPIO_V2 |
880 | 414 GPIO_LED_RED_OFF(); |
415 GPIO_VIBRATION_OFF(); | |
903
0f2e5a166d40
Disable GNSS operations using compile switch:
Ideenmodellierer
parents:
900
diff
changeset
|
416 #endif |
89 | 417 } |
922 | 418 #ifdef ENABLE_GPIO_V2 |
900 | 419 GPIO_LED_RED_OFF(); |
420 GPIO_LED_GREEN_OFF(); | |
421 GPIO_VIBRATION_OFF(); | |
903
0f2e5a166d40
Disable GNSS operations using compile switch:
Ideenmodellierer
parents:
900
diff
changeset
|
422 #endif |
89 | 423 SPI_synchronize_with_Master(); |
424 MX_DMA_Init(); | |
425 MX_SPI1_Init(); | |
134
0586ae83a243
Removed cyclic (by timer) send on slave side
Ideenmodellierer
parents:
120
diff
changeset
|
426 SPI_Start_single_TxRx_with_Master(); /* be prepared for the first data exchange */ |
207 | 427 Scheduler_Request_sync_with_SPI(SPI_SYNC_METHOD_HARD); |
889 | 428 |
922 | 429 #ifdef ENABLE_GPIO_V2 |
889 | 430 // GNSS tests |
431 GNSS_IO_init(); | |
900 | 432 GPIO_GPS_ON(); |
433 GPIO_GPS_BCKP_ON(); | |
889 | 434 MX_USART6_UART_Init(); |
435 GNSS_Init(&GNSS_Handle, &huart6); | |
932 | 436 #else |
437 #ifdef ENABLE_GNSS_SUPPORT | |
438 GNSS_Init(&GNSS_Handle, &huart1); | |
439 #endif | |
900 | 440 #endif |
899
2225c467f1e9
Added data path and visualization for position data:
Ideenmodellierer
parents:
890
diff
changeset
|
441 |
89 | 442 global.mode = MODE_SURFACE; |
443 break; | |
38 | 444 |
89 | 445 case MODE_CALIB: |
90 | 446 scheduleCompassCalibrationMode(); |
89 | 447 break; |
448 | |
449 case MODE_SURFACE: | |
450 scheduleSurfaceMode(); | |
451 break; | |
38 | 452 |
89 | 453 case MODE_TEST: |
454 break; | |
38 | 455 |
89 | 456 case MODE_DIVE: |
90 | 457 backup.no_fly_time_minutes = global.no_fly_time_minutes; |
458 backup.seconds_since_last_dive = global.seconds_since_last_dive; | |
459 | |
460 vpm_init( &global.vpm, global.conservatism, global.repetitive_dive, | |
461 global.seconds_since_last_dive ); | |
462 global.no_fly_time_minutes = 0; | |
463 global.lifeData.dive_time_seconds = 0; | |
464 global.lifeData.dive_time_seconds_without_surface_time = 0; | |
465 scheduleDiveMode(); | |
466 // done now in scheduler prior to change mode: global.seconds_since_last_dive = 1; | |
467 | |
468 if( global.lifeData.dive_time_seconds > 60 ) | |
469 { | |
470 //No Fly time 60% of desaturationtime after dive | |
471 global.no_fly_time_minutes = decom_calc_desaturation_time( | |
472 global.lifeData.tissue_nitrogen_bar, | |
473 global.lifeData.tissue_helium_bar, | |
474 global.lifeData.pressure_surface_bar ) * 60 / 100; | |
475 if( global.no_fly_time_minutes < (24 * 60) ) | |
476 global.no_fly_time_minutes = 24 * 60; | |
477 } | |
478 else | |
479 { | |
480 global.no_fly_time_minutes = backup.no_fly_time_minutes; | |
481 global.seconds_since_last_dive = backup.seconds_since_last_dive; | |
482 } | |
483 | |
484 global.lifeData.dive_time_seconds = 0; | |
485 global.lifeData.dive_time_seconds_without_surface_time = 0; | |
486 global.lifeData.counterSecondsShallowDepth = 0; | |
487 | |
488 backup.no_fly_time_minutes = 0; | |
489 backup.seconds_since_last_dive = 0; | |
89 | 490 break; |
38 | 491 |
89 | 492 case MODE_SHUTDOWN: |
493 HAL_Delay(200); | |
936 | 494 |
495 MX_SPI3_Init(); | |
496 | |
497 #if defined ENABLE_GNSS_SUPPORT || defined ENABLE_GPIO_V2 | |
498 if(shutdownTick == 0) | |
499 { | |
500 shutdownTick = HAL_GetTick(); | |
501 uartGnss_ReqPowerDown(1); | |
502 } | |
503 #ifdef ENABLE_GNSS_SUPPORT | |
504 externalInterface_HandleUART(); | |
505 #else | |
506 UART6_HandleUART(); | |
507 #endif | |
508 if((uartGnss_GetState() == UART_GNSS_INACTIVE) || (time_elapsed_ms(shutdownTick,HAL_GetTick()) > 5000)) | |
509 { | |
510 global.mode = MODE_SLEEP; | |
938 | 511 uartGnss_ReqPowerDown(0); /* release power down request */ |
936 | 512 } |
513 #else | |
89 | 514 global.mode = MODE_SLEEP; |
936 | 515 #endif |
516 | |
517 | |
89 | 518 break; |
519 | |
520 case MODE_SLEEP: | |
917
0d6c4b40fae4
Bugfix external interface power up after sleep:
Ideenmodellierer
parents:
909
diff
changeset
|
521 extInterfaceActive = externalInterface_isEnabledPower33(); |
839 | 522 externalInterface_SwitchUART(EXT_INTERFACE_UART_OFF); |
662 | 523 externalInterface_SwitchPower33(false); |
89 | 524 if (hasExternalClock()) |
525 SystemClock_Config_HSI(); | |
887 | 526 GPIO_LEDs_VIBRATION_Init(); |
89 | 527 sleep_prepare(); |
38 | 528 |
89 | 529 scheduleSleepMode(); |
530 if (hasExternalClock()) | |
531 SystemClock_Config_HSE(); | |
532 EXTI_Wakeup_Button_DeInit(); | |
533 ADCx_Init(); | |
534 GPIO_Power_MainCPU_Init(); | |
535 GPIO_Power_MainCPU_ON(); | |
536 compass_init(0, 7); | |
537 accelerator_init(); | |
148
ee744c7160ce
Use SPI TX callback to synchronize to main CPU
Ideenmodellierer
parents:
134
diff
changeset
|
538 SPI_synchronize_with_Master(); |
89 | 539 MX_DMA_Init(); |
540 MX_SPI1_Init(); | |
148
ee744c7160ce
Use SPI TX callback to synchronize to main CPU
Ideenmodellierer
parents:
134
diff
changeset
|
541 SPI_Start_single_TxRx_with_Master(); |
89 | 542 |
917
0d6c4b40fae4
Bugfix external interface power up after sleep:
Ideenmodellierer
parents:
909
diff
changeset
|
543 if(extInterfaceActive) |
662 | 544 { |
545 externalInterface_SwitchPower33(true); | |
546 } | |
738
30717de00f3a
Added data init function for external interface:
Ideenmodellierer
parents:
728
diff
changeset
|
547 externalInterface_InitDatastruct(); |
89 | 548 // EXTILine0_Button_DeInit(); not now, later after testing |
549 break; | |
550 } | |
120 | 551 |
552 #ifdef DEBUG_RUNTIME | |
553 HAL_RTC_GetTime(&RTCHandle, &Stime, RTC_FORMAT_BCD); | |
554 | |
555 if(lastsecond == 0xFF) | |
556 { | |
557 measurementindex = 0; | |
558 loopcnt[measurementindex] = 0; | |
559 lastsecond = Stime.Seconds; | |
560 } | |
561 loopcnt[measurementindex]++; | |
562 | |
563 if(lastsecond != Stime.Seconds) | |
564 { | |
565 measurementindex++; | |
566 if (measurementindex == MEASURECNT) measurementindex = 0; | |
567 loopcnt[measurementindex] = 0; | |
568 lastsecond = Stime.Seconds; | |
569 if(measurementindex +1 < MEASURECNT) loopcnt[measurementindex +1] = 0xffff; /* helps to identify the latest value */ | |
570 } | |
571 #endif | |
89 | 572 } |
38 | 573 } |
574 | |
575 /** @brief Button feedback - EXTI line detection callbacks | |
576 * @param GPIO_Pin: Specifies the pins connected EXTI line | |
577 * @retval None | |
578 */ | |
89 | 579 void HAL_GPIO_EXTI_Callback(uint16_t GPIO_Pin) { |
38 | 580 |
89 | 581 if (GPIO_Pin == BUTTON_OSTC_GPIO_PIN) { |
582 if (global.mode == MODE_SLEEP) { | |
583 global.mode = MODE_BOOT; | |
584 } | |
585 } | |
586 else | |
880 | 587 { |
588 | |
89 | 589 } |
38 | 590 } |
591 | |
592 /** | |
593 * @brief System Clock Configuration | |
594 * The system Clock is configured as follow : | |
595 * System Clock source = PLL (HSI) | |
596 * SYSCLK(Hz) = 100 MHz | |
597 * HCLK(Hz) = 100 MHz | |
598 * AHB Prescaler = 1 | |
599 * APB1 Prescaler = 2 | |
600 * APB2 Prescaler = 1 | |
601 * HSI Frequency(Hz) = 16 MHz | |
602 * PLL_M = 16 | |
603 * PLL_N = 400 | |
604 * PLL_P = 4 | |
605 * PLL_Q = 7 // no USB | |
606 * VDD(V) = 3.3 | |
607 * Main regulator output voltage = Scale1 mode | |
608 * Flash Latency(WS) = 3 | |
609 * @param None | |
610 * @retval None | |
611 */ | |
612 | |
89 | 613 void SystemClock_Config(void) { |
614 if (hasExternalClock()) | |
615 SystemClock_Config_HSE(); | |
616 else | |
617 SystemClock_Config_HSI(); | |
38 | 618 } |
619 | |
89 | 620 void SYSCLKConfig_STOP(void) { |
621 SYSCLKConfig_STOP_HSI(); | |
38 | 622 } |
623 | |
89 | 624 void SystemClock_Config_HSE(void) { |
625 RCC_OscInitTypeDef RCC_OscInitStruct; | |
626 RCC_ClkInitTypeDef RCC_ClkInitStruct; | |
38 | 627 // RCC_PeriphCLKInitTypeDef PeriphClkInitStruct; |
628 | |
89 | 629 __PWR_CLK_ENABLE(); // is identical to __HAL_RCC_PWR_CLK_ENABLE(); |
38 | 630 |
887 | 631 __HAL_PWR_VOLTAGESCALING_CONFIG(PWR_REGULATOR_VOLTAGE_SCALE1); |
38 | 632 |
89 | 633 RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSE; //|RCC_OSCILLATORTYPE_LSE; |
634 RCC_OscInitStruct.HSEState = RCC_HSE_ON; | |
635 //RCC_OscInitStruct.LSEState = RCC_LSE_ON; | |
636 RCC_OscInitStruct.PLL.PLLState = RCC_PLL_ON; | |
637 RCC_OscInitStruct.PLL.PLLSource = RCC_PLLSOURCE_HSE; | |
638 RCC_OscInitStruct.PLL.PLLM = 8; | |
639 RCC_OscInitStruct.PLL.PLLN = 320; | |
640 RCC_OscInitStruct.PLL.PLLP = RCC_PLLP_DIV4; | |
641 RCC_OscInitStruct.PLL.PLLQ = 4; | |
642 HAL_RCC_OscConfig(&RCC_OscInitStruct); | |
38 | 643 |
89 | 644 RCC_ClkInitStruct.ClockType = RCC_CLOCKTYPE_HCLK | RCC_CLOCKTYPE_SYSCLK |
645 | RCC_CLOCKTYPE_PCLK1 | RCC_CLOCKTYPE_PCLK2; | |
646 RCC_ClkInitStruct.SYSCLKSource = RCC_SYSCLKSOURCE_PLLCLK; | |
647 RCC_ClkInitStruct.AHBCLKDivider = RCC_SYSCLK_DIV1; | |
648 RCC_ClkInitStruct.APB1CLKDivider = RCC_HCLK_DIV2; | |
649 RCC_ClkInitStruct.APB2CLKDivider = RCC_HCLK_DIV1; | |
650 HAL_RCC_ClockConfig(&RCC_ClkInitStruct, FLASH_LATENCY_2); | |
38 | 651 |
652 // PeriphClkInitStruct.PeriphClockSelection = RCC_PERIPHCLK_RTC; | |
653 // PeriphClkInitStruct.RTCClockSelection = RCC_RTCCLKSOURCE_LSE; | |
654 // HAL_RCCEx_PeriphCLKConfig(&PeriphClkInitStruct); | |
655 | |
656 // HAL_SYSTICK_Config(HAL_RCC_GetHCLKFreq()/1000); | |
657 | |
658 // HAL_SYSTICK_CLKSourceConfig(SYSTICK_CLKSOURCE_HCLK); | |
659 | |
89 | 660 /* SysTick_IRQn interrupt configuration */ |
38 | 661 // HAL_NVIC_SetPriority(SysTick_IRQn, 0, 0); |
662 } | |
663 | |
89 | 664 void SystemClock_Config_HSI(void) { |
665 RCC_ClkInitTypeDef RCC_ClkInitStruct; | |
666 RCC_OscInitTypeDef RCC_OscInitStruct; | |
38 | 667 |
89 | 668 /* Enable Power Control clock */ |
669 __HAL_RCC_PWR_CLK_ENABLE(); | |
38 | 670 |
89 | 671 /* The voltage scaling allows optimizing the power consumption when the device is |
672 clocked below the maximum system frequency, to update the voltage scaling value | |
673 regarding system frequency refer to product datasheet. */ | |
887 | 674 __HAL_PWR_VOLTAGESCALING_CONFIG(PWR_REGULATOR_VOLTAGE_SCALE1); |
38 | 675 |
89 | 676 /* Enable HSI Oscillator and activate PLL with HSI as source */ |
677 RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSI; | |
678 RCC_OscInitStruct.HSIState = RCC_HSI_ON; | |
679 RCC_OscInitStruct.HSICalibrationValue = 0x10; | |
680 RCC_OscInitStruct.PLL.PLLState = RCC_PLL_ON; | |
681 RCC_OscInitStruct.PLL.PLLSource = RCC_PLLSOURCE_HSI; | |
682 RCC_OscInitStruct.PLL.PLLM = 16; | |
683 RCC_OscInitStruct.PLL.PLLN = 320; | |
684 RCC_OscInitStruct.PLL.PLLP = RCC_PLLP_DIV4; | |
685 RCC_OscInitStruct.PLL.PLLQ = 4; | |
686 HAL_RCC_OscConfig(&RCC_OscInitStruct); | |
38 | 687 |
89 | 688 /* Select PLL as system clock source and configure the HCLK, PCLK1 and PCLK2 |
689 clocks dividers */ | |
690 RCC_ClkInitStruct.ClockType = (RCC_CLOCKTYPE_SYSCLK | RCC_CLOCKTYPE_HCLK | |
691 | RCC_CLOCKTYPE_PCLK1 | RCC_CLOCKTYPE_PCLK2); | |
692 RCC_ClkInitStruct.SYSCLKSource = RCC_SYSCLKSOURCE_PLLCLK; | |
693 RCC_ClkInitStruct.AHBCLKDivider = RCC_SYSCLK_DIV1; | |
694 RCC_ClkInitStruct.APB1CLKDivider = RCC_HCLK_DIV2; | |
695 RCC_ClkInitStruct.APB2CLKDivider = RCC_HCLK_DIV1; | |
696 HAL_RCC_ClockConfig(&RCC_ClkInitStruct, FLASH_LATENCY_2); | |
38 | 697 } |
698 | |
699 | |
700 /** | |
701 * @brief Configures system clock after wake-up from STOP: enable HSI, PLL | |
702 * and select PLL as system clock source. | |
703 * @param None | |
704 * @retval None | |
705 */ | |
89 | 706 void SYSCLKConfig_STOP_HSE(void) { |
707 RCC_ClkInitTypeDef RCC_ClkInitStruct; | |
708 RCC_OscInitTypeDef RCC_OscInitStruct; | |
709 uint32_t pFLatency = 0; | |
38 | 710 |
89 | 711 /* Get the Oscillators configuration according to the internal RCC registers */ |
712 HAL_RCC_GetOscConfig(&RCC_OscInitStruct); | |
38 | 713 |
89 | 714 /* After wake-up from STOP reconfigure the system clock: Enable HSI and PLL */ |
715 RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSE; | |
716 RCC_OscInitStruct.HSIState = RCC_HSE_ON; | |
717 RCC_OscInitStruct.PLL.PLLState = RCC_PLL_ON; | |
718 HAL_RCC_OscConfig(&RCC_OscInitStruct); | |
38 | 719 |
89 | 720 /* Get the Clocks configuration according to the internal RCC registers */ |
721 HAL_RCC_GetClockConfig(&RCC_ClkInitStruct, &pFLatency); | |
38 | 722 |
89 | 723 /* Select PLL as system clock source and configure the HCLK, PCLK1 and PCLK2 |
724 clocks dividers */ | |
725 RCC_ClkInitStruct.ClockType = RCC_CLOCKTYPE_SYSCLK; | |
726 RCC_ClkInitStruct.SYSCLKSource = RCC_SYSCLKSOURCE_PLLCLK; | |
727 HAL_RCC_ClockConfig(&RCC_ClkInitStruct, pFLatency); | |
38 | 728 } |
729 | |
89 | 730 void SYSCLKConfig_STOP_HSI(void) { |
731 RCC_ClkInitTypeDef RCC_ClkInitStruct; | |
732 RCC_OscInitTypeDef RCC_OscInitStruct; | |
733 uint32_t pFLatency = 0; | |
38 | 734 |
89 | 735 /* Get the Oscillators configuration according to the internal RCC registers */ |
736 HAL_RCC_GetOscConfig(&RCC_OscInitStruct); | |
38 | 737 |
89 | 738 /* After wake-up from STOP reconfigure the system clock: Enable HSI and PLL */ |
739 RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSI; | |
740 RCC_OscInitStruct.HSIState = RCC_HSI_ON; | |
741 RCC_OscInitStruct.PLL.PLLState = RCC_PLL_ON; | |
742 RCC_OscInitStruct.HSICalibrationValue = 0x10; | |
743 HAL_RCC_OscConfig(&RCC_OscInitStruct); | |
38 | 744 |
89 | 745 /* Get the Clocks configuration according to the internal RCC registers */ |
746 HAL_RCC_GetClockConfig(&RCC_ClkInitStruct, &pFLatency); | |
38 | 747 |
89 | 748 /* Select PLL as system clock source and configure the HCLK, PCLK1 and PCLK2 |
749 clocks dividers */ | |
750 RCC_ClkInitStruct.ClockType = RCC_CLOCKTYPE_SYSCLK; | |
751 RCC_ClkInitStruct.SYSCLKSource = RCC_SYSCLKSOURCE_PLLCLK; | |
752 HAL_RCC_ClockConfig(&RCC_ClkInitStruct, pFLatency); | |
38 | 753 } |
754 | |
755 /** | |
756 * @brief SYSTICK callback | |
757 * @param None | |
758 * @retval None | |
759 */ | |
89 | 760 void HAL_SYSTICK_Callback(void) { |
761 HAL_IncTick(); | |
38 | 762 } |
763 | |
764 /** | |
765 * @brief Configures GPIO for LED | |
766 * Might move with STM32Cube usage | |
767 * @param None | |
768 * @retval None | |
769 */ | |
770 /* | |
771 void GPIO_test_I2C_lines(void) | |
772 { | |
773 GPIO_InitTypeDef GPIO_InitStructure; | |
774 __GPIOB_CLK_ENABLE(); | |
775 GPIO_InitStructure.Pin = GPIO_PIN_8; | |
776 GPIO_InitStructure.Mode = GPIO_MODE_OUTPUT_PP; | |
777 GPIO_InitStructure.Pull = GPIO_PULLUP; | |
778 GPIO_InitStructure.Speed = GPIO_SPEED_LOW; | |
779 HAL_GPIO_Init(GPIOB, &GPIO_InitStructure); | |
780 GPIO_InitStructure.Pin = GPIO_PIN_9; | |
781 HAL_GPIO_Init(GPIOB, &GPIO_InitStructure); | |
782 | |
783 HAL_GPIO_WritePin(GPIOB,GPIO_PIN_8,GPIO_PIN_SET); | |
784 HAL_GPIO_WritePin(GPIOB,GPIO_PIN_9,GPIO_PIN_RESET); | |
785 HAL_Delay(10); | |
786 HAL_GPIO_WritePin(GPIOB,GPIO_PIN_9,GPIO_PIN_SET); | |
787 HAL_GPIO_WritePin(GPIOB,GPIO_PIN_8,GPIO_PIN_RESET); | |
788 HAL_Delay(10); | |
789 } | |
790 */ | |
791 | |
89 | 792 void GPIO_new_DEBUG_Init(void) { |
38 | 793 #ifdef DEBUG_PIN_ACTIVE |
89 | 794 GPIO_InitTypeDef GPIO_InitStructure; |
38 | 795 |
89 | 796 __GPIOC_CLK_ENABLE(); |
662 | 797 GPIO_InitStructure.Pin = LED_CONTROL_PIN; |
89 | 798 GPIO_InitStructure.Mode = GPIO_MODE_OUTPUT_PP; |
799 GPIO_InitStructure.Pull = GPIO_PULLUP; | |
800 GPIO_InitStructure.Speed = GPIO_SPEED_FAST; | |
801 HAL_GPIO_Init(GPIOA, &GPIO_InitStructure); | |
38 | 802 #endif |
803 } | |
804 | |
89 | 805 void GPIO_new_DEBUG_LOW(void) { |
38 | 806 #ifdef DEBUG_PIN_ACTIVE |
662 | 807 HAL_GPIO_WritePin(GPIOC,LED_CONTROL_PIN,GPIO_PIN_RESET); |
38 | 808 #endif |
809 } | |
810 | |
89 | 811 void GPIO_new_DEBUG_HIGH(void) { |
38 | 812 #ifdef DEBUG_PIN_ACTIVE |
662 | 813 HAL_GPIO_WritePin(GPIOC,LED_CONTROL_PIN,GPIO_PIN_SET); |
38 | 814 #endif |
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 | |
849 /** | |
850 * @brief Wake Up Timer callback | |
851 * @param hrtc: RTC handle | |
852 * @retval None | |
853 */ | |
854 | |
855 /* | |
856 void HAL_RTCEx_WakeUpTimerEventCallback(RTC_HandleTypeDef *hrtc) | |
857 { | |
858 static uint8_t uwCounter = 0; | |
859 uwCounter = 1; | |
860 } | |
861 */ | |
862 | |
89 | 863 void HAL_I2C_MasterTxCpltCallback(I2C_HandleTypeDef *I2cHandle) { |
38 | 864 |
865 } | |
866 | |
89 | 867 void HAL_I2C_MasterRxCpltCallback(I2C_HandleTypeDef *I2cHandle) { |
38 | 868 |
869 } | |
870 | |
89 | 871 void HAL_I2C_ErrorCallback(I2C_HandleTypeDef *I2cHandle) { |
38 | 872 |
873 } | |
874 | |
89 | 875 void sleep_prepare(void) { |
876 EXTI_Wakeup_Button_Init(); | |
662 | 877 |
89 | 878 compass_sleep(); |
879 HAL_Delay(100); | |
880 accelerator_sleep(); | |
881 HAL_Delay(100); | |
38 | 882 |
89 | 883 I2C_DeInit(); |
884 MX_SPI_DeInit(); | |
885 MX_SPI3_DeInit(); | |
886 ADCx_DeInit(); | |
38 | 887 |
89 | 888 GPIO_InitTypeDef GPIO_InitStruct; |
38 | 889 |
89 | 890 __HAL_RCC_GPIOA_CLK_ENABLE(); |
891 __HAL_RCC_GPIOB_CLK_ENABLE(); | |
892 __HAL_RCC_GPIOC_CLK_ENABLE(); | |
893 __HAL_RCC_GPIOH_CLK_ENABLE(); | |
38 | 894 |
89 | 895 GPIO_InitStruct.Mode = GPIO_MODE_ANALOG; |
887 | 896 GPIO_InitStruct.Speed = GPIO_SPEED_LOW; |
89 | 897 GPIO_InitStruct.Pull = GPIO_NOPULL; |
898 GPIO_InitStruct.Pin = GPIO_PIN_All; | |
899 HAL_GPIO_Init( GPIOH, &GPIO_InitStruct); | |
938 | 900 #ifdef ENABLE_SLEEP_DEBUG |
89 | 901 GPIO_InitStruct.Pin = GPIO_PIN_All ^ ( GPIO_PIN_3 | GPIO_PIN_8 | GPIO_PIN_9); /* debug */ |
38 | 902 #endif |
887 | 903 |
936 | 904 /* |
887 | 905 GPIO_InitStruct.Pin = GPIO_PIN_All ^ (GPS_POWER_CONTROL_PIN | GPS_BCKP_CONTROL_PIN); |
89 | 906 HAL_GPIO_Init( GPIOB, &GPIO_InitStruct); |
936 | 907 */ |
887 | 908 GPIO_InitStruct.Pin = GPIO_PIN_All ^ ( MAINCPU_CONTROL_PIN | CHARGE_OUT_PIN | EXT33V_CONTROL_PIN); /* power off & charger in & charge out & OSC32 & ext33Volt */ |
662 | 909 |
89 | 910 HAL_GPIO_Init( GPIOC, &GPIO_InitStruct); |
38 | 911 |
887 | 912 GPIO_InitStruct.Pin = GPIO_PIN_All ^ ( GPIO_PIN_0 | VIBRATION_CONTROL_PIN | LED_CONTROL_PIN_RED | LED_CONTROL_PIN_GREEN); |
938 | 913 #ifdef ENABLE_SLEEP_DEBUG |
89 | 914 GPIO_InitStruct.Pin = GPIO_PIN_All ^ ( GPIO_PIN_0 | GPIO_PIN_13 | GPIO_PIN_14); /* wake up button & debug */ |
38 | 915 #endif |
89 | 916 HAL_GPIO_Init( GPIOA, &GPIO_InitStruct); |
38 | 917 |
89 | 918 GPIO_InitStruct.Pin = GPIO_PIN_All; |
919 HAL_GPIO_Init( GPIOH, &GPIO_InitStruct); | |
38 | 920 |
89 | 921 GPIO_Power_MainCPU_OFF(); |
922 | 922 #ifdef ENABLE_GPIO_V2 |
880 | 923 GPIO_LED_GREEN_OFF(); |
924 GPIO_LED_RED_OFF(); | |
887 | 925 GPIO_VIBRATION_OFF(); |
926 GPIO_GPS_BCKP_ON(); // mH : costs 100µA in sleep - beware | |
938 | 927 /* GPIO_GPS_OFF(); will be done in transition sleep => deep sleep */ |
880 | 928 |
890
651d21777b61
cleanup and disable function for GNSS uart and DMA
heinrichsweikamp
parents:
889
diff
changeset
|
929 MX_USART6_UART_DeInit(); |
903
0f2e5a166d40
Disable GNSS operations using compile switch:
Ideenmodellierer
parents:
900
diff
changeset
|
930 #endif |
938 | 931 #ifndef ENABLE_SLEEP_DEBUG |
932 /* | |
89 | 933 __HAL_RCC_GPIOB_CLK_DISABLE(); |
938 | 934 */ |
38 | 935 #endif |
89 | 936 __HAL_RCC_GPIOH_CLK_DISABLE(); |
38 | 937 |
89 | 938 HAL_Delay(1000); |
38 | 939 } |
940 | |
941 /* | |
942 void sleep_test(void) | |
943 { | |
944 GPIO_InitTypeDef GPIO_InitStruct; | |
945 | |
946 __HAL_RCC_GPIOA_CLK_ENABLE(); | |
947 __HAL_RCC_GPIOB_CLK_ENABLE(); | |
948 __HAL_RCC_GPIOC_CLK_ENABLE(); | |
949 __HAL_RCC_GPIOH_CLK_ENABLE(); | |
950 | |
951 GPIO_InitStruct.Mode = GPIO_MODE_ANALOG; | |
952 GPIO_InitStruct.Speed = GPIO_SPEED_HIGH; | |
953 GPIO_InitStruct.Pull = GPIO_NOPULL; | |
954 GPIO_InitStruct.Pin = GPIO_PIN_All; | |
955 HAL_GPIO_Init(GPIOH, &GPIO_InitStruct); | |
956 HAL_GPIO_Init(GPIOB, &GPIO_InitStruct); | |
957 | |
958 GPIO_InitStruct.Pin = GPIO_PIN_All ^ ( GPIO_PIN_0 | GPIO_PIN_15 | GPIO_PIN_14); | |
959 HAL_GPIO_Init(GPIOC, &GPIO_InitStruct); | |
960 | |
961 GPIO_InitStruct.Pin = GPIO_PIN_All ^ ( GPIO_PIN_0); | |
962 HAL_GPIO_Init(GPIOA, &GPIO_InitStruct); | |
963 | |
964 GPIO_Power_MainCPU_OFF(); | |
965 | |
966 GPIO_InitStruct.Pull = GPIO_PULLUP; | |
967 GPIO_InitStruct.Pin = GPIO_PIN_0; | |
968 HAL_GPIO_Init(GPIOA, &GPIO_InitStruct); | |
969 | |
970 // __HAL_RCC_GPIOA_CLK_DISABLE(); | |
971 __HAL_RCC_GPIOB_CLK_DISABLE(); | |
972 // __HAL_RCC_GPIOC_CLK_DISABLE(); | |
973 __HAL_RCC_GPIOH_CLK_DISABLE(); | |
974 | |
975 | |
976 HAL_Delay(5000); | |
977 while(1) | |
978 { | |
979 RTC_StopMode_2seconds(); | |
980 HAL_Delay(200); | |
981 } | |
982 } | |
983 */ | |
984 | |
985 #ifdef USE_FULL_ASSERT | |
986 | |
987 /** | |
988 * @brief Reports the name of the source file and the source line number | |
989 * where the assert_param error has occurred. | |
990 * @param file: pointer to the source file name | |
991 * @param line: assert_param error line source number | |
992 * @retval None | |
993 */ | |
994 void assert_failed(uint8_t* file, uint32_t line) | |
995 { | |
89 | 996 /* User can add his own implementation to report the file name and line number, |
997 ex: printf("Wrong parameters value: file %s on line %d\r\n", file, line) */ | |
38 | 998 |
89 | 999 /* Infinite loop */ |
1000 while (1) | |
1001 { | |
1002 } | |
38 | 1003 } |
1004 #endif | |
1005 | |
1006 /** | |
1007 * @} | |
1008 */ | |
104 | 1009 /** |
1010 * @brief This function handles SysTick Handler. | |
1011 * @param None | |
1012 * @retval None | |
1013 */ | |
38 | 1014 |
104 | 1015 /*TxRx only here. Every 100 ms.*/ |
1016 uint8_t ticks100ms=0; | |
1017 void SysTick_Handler(void) | |
1018 { | |
1019 HAL_IncTick(); | |
1020 if(ticks100ms<100){ | |
1021 ticks100ms++; | |
1022 }else | |
1023 { | |
1024 ticks100ms=0; | |
1025 } | |
1026 } | |
38 | 1027 /** |
1028 * @} | |
1029 */ | |
1030 | |
1031 /************************ (C) COPYRIGHT heinrichs weikamp *****END OF FILE****/ |