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