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