acc_integration_stm32.c
Go to the documentation of this file.
1 // Copyright (c) Acconeer AB, 2019-2024
2 // All rights reserved
3 // This file is subject to the terms and conditions defined in the file
4 // 'LICENSES/license_acconeer.txt', (BSD 3-Clause License) which is part
5 // of this source code package.
6 
7 #include <stdint.h>
8 #include <stdio.h>
9 #include <string.h>
10 
11 #include "main.h"
12 
13 #include "acc_integration.h"
14 
15 /**
16  * @brief Maximum RTC time before wrapping occurs
17  */
18 #define RTC_MAX_TIME_MS (24 * 60 * 60 * 1000)
19 
20 /**
21  * @brief Set to true when RTC alarm interrupt has triggered
22  */
23 volatile bool rtc_alarm_triggered = false;
24 
25 /**
26  * @brief Set to true when RTC wakeup interrupt has triggered
27  */
28 volatile bool rtc_wakeup_triggered = false;
29 
30 /**
31  * @brief Variable that holds the periodic wakeup time
32  */
33 static uint32_t periodic_sleep_time_ms = 0;
34 
35 /**
36  * @brief GPIO config status, maps directly to the GPIO registers
37  */
38 typedef struct
39 {
40  uint32_t MODER; /*!< GPIO port mode register */
41  uint32_t OTYPER; /*!< GPIO port output type register */
42  uint32_t OSPEEDR; /*!< GPIO port output speed register */
43  uint32_t PUPDR; /*!< GPIO port pull-up/pull-down register */
44  uint32_t AFR[2]; /*!< GPIO alternate function registers */
45  uint32_t ASCR; /*!< GPIO analog switch control register */
46  uint32_t RCC_GPIO_CLK_ENABLE; /*!< GPIO Port Clock Enable */
48 
49 static inline void disable_interrupts(void)
50 {
51  __disable_irq();
52  __DSB();
53  __ISB();
54 }
55 
56 static inline void enable_interrupts(void)
57 {
58  __enable_irq();
59  __DSB();
60  __ISB();
61 }
62 
63 /**
64  * @brief GPIO status of the system before going to sleep
65  */
67 
68 /**
69  * @brief Handles for the blocks to control
70  */
71 extern RTC_HandleTypeDef MODULE_RTC_HANDLE;
72 extern SPI_HandleTypeDef A121_SPI_HANDLE;
73 extern I2C_HandleTypeDef MODULE_I2C_HANDLE;
74 extern UART_HandleTypeDef MODULE_UART1_HANDLE;
75 extern UART_HandleTypeDef MODULE_UART2_HANDLE;
76 
77 extern __IO uint32_t uwTick;
78 
79 static RCC_OscInitTypeDef prepare_saved_rcc_oscinitstruct;
80 static RCC_ClkInitTypeDef prepare_saved_rcc_clkinitstruct;
81 static uint32_t prepare_saved_flatency;
82 
83 static HAL_UART_StateTypeDef prepare_saved_uart1_rx_state;
84 static HAL_I2C_StateTypeDef prepare_saved_i2c_state;
85 
86 /**
87  * @brief Convert RTC time to RTC ticks
88  *
89  * @param[in] time RTC time
90  * @return rtc ticks in ms
91  */
92 static uint32_t rtc_time_to_tick(RTC_TimeTypeDef *time)
93 {
94  uint32_t rtc_ticks_ms = 0;
95 
96  if (time->Hours)
97  {
98  rtc_ticks_ms += time->Hours * 60 * 60 * 1000;
99  }
100 
101  if (time->Minutes)
102  {
103  rtc_ticks_ms += time->Minutes * 60 * 1000;
104  }
105 
106  if (time->Seconds)
107  {
108  rtc_ticks_ms += time->Seconds * 1000;
109  }
110 
111  rtc_ticks_ms += ((time->SecondFraction - time->SubSeconds) * 1000) / (time->SecondFraction + 1);
112 
113  return rtc_ticks_ms;
114 }
115 
116 /**
117  * @brief Convert RTC ticks to RTC time
118  *
119  * @param[in] tick rtc ticks in ms
120  * @param[out] time RTC time
121  */
122 static void rtc_tick_to_time(uint32_t tick, RTC_TimeTypeDef *time)
123 {
124  uint32_t rtc_ticks_ms = tick;
125 
126  time->SecondFraction = MODULE_RTC_HANDLE.Init.SynchPrediv;
127 
128  time->Hours = (rtc_ticks_ms / (60 * 60 * 1000)) % 24;
129 
130  rtc_ticks_ms = rtc_ticks_ms % (60 * 60 * 1000);
131 
132  time->Minutes = (rtc_ticks_ms / (60 * 1000)) % 60;
133 
134  rtc_ticks_ms = rtc_ticks_ms % (60 * 1000);
135 
136  time->Seconds = (rtc_ticks_ms / 1000) % 60;
137 
138  rtc_ticks_ms = rtc_ticks_ms % 1000;
139 
140  time->SubSeconds = time->SecondFraction - (rtc_ticks_ms * (time->SecondFraction + 1)) / 1000;
141 }
142 
143 /**
144  * @brief Get RTC ticks based on current RTC time
145  *
146  * @return The current RTC ticks in ms
147  */
148 static uint32_t get_rtc_tick(void)
149 {
150  RTC_DateTypeDef rtc_date = {0};
151  RTC_TimeTypeDef rtc_time = {0};
152 
153  /* Wait until any pending shift operation is completed */
154  while ((MODULE_RTC_HANDLE.Instance->ISR & RTC_ISR_SHPF) != RESET)
155  {
156  ;
157  }
158 
159  if (HAL_RTC_GetTime(&MODULE_RTC_HANDLE, &rtc_time, RTC_FORMAT_BIN) != HAL_OK)
160  {
161  Error_Handler();
162  }
163 
164  if (HAL_RTC_GetDate(&MODULE_RTC_HANDLE, &rtc_date, RTC_FORMAT_BIN) != HAL_OK)
165  {
166  Error_Handler();
167  }
168 
169  return rtc_time_to_tick(&rtc_time);
170 }
171 
172 /**
173  * @brief Update system tick based on RTC ticks during sleep
174  *
175  * @param[in] rtc_ticks_pre_sleep rtc ticks before sleep was entered
176  * @param[in] rtc_ticks_post_sleep rtc ticks after sleep was exited
177  */
178 static void update_system_tick(uint32_t rtc_ticks_pre_sleep, uint32_t rtc_ticks_post_sleep)
179 {
180  // Take care of wrapping which will occur every 24h
181  int32_t elapsed_ticks = (int32_t)rtc_ticks_post_sleep - rtc_ticks_pre_sleep;
182 
183  if (elapsed_ticks < 0)
184  {
185  elapsed_ticks = RTC_MAX_TIME_MS + elapsed_ticks;
186  }
187 
188  uwTick += (uint32_t)elapsed_ticks;
189 }
190 
191 /**
192  * @brief Function for setting the next wakeup time from the RTC interrupt.
193  */
194 static void rtc_set_next_wakeup_time(void)
195 {
196  RTC_AlarmTypeDef alarm = {{0}, 0, 0, 0, 0, 0, 0};
197 
198  if (periodic_sleep_time_ms != 0)
199  {
201 
202  alarm.Alarm = RTC_ALARM_A;
203  alarm.AlarmMask = RTC_ALARMMASK_DATEWEEKDAY;
204  alarm.AlarmSubSecondMask = RTC_ALARMSUBSECONDMASK_SS14;
205 
206  if (HAL_RTC_DeactivateAlarm(&MODULE_RTC_HANDLE, RTC_ALARM_A) != HAL_OK)
207  {
208  Error_Handler();
209  }
210 
211  if (HAL_RTC_SetAlarm_IT(&MODULE_RTC_HANDLE, &alarm, RTC_FORMAT_BIN) != HAL_OK)
212  {
213  Error_Handler();
214  }
215  }
216  else
217  {
218  if (HAL_RTC_DeactivateAlarm(&MODULE_RTC_HANDLE, RTC_ALARM_A) != HAL_OK)
219  {
220  Error_Handler();
221  }
222 
223  rtc_alarm_triggered = false;
224  }
225 }
226 
227 /**
228  * @brief Set the port clock status for a given GPIO bank
229  *
230  * @param[in] gpio_bank GPIO port clock to set
231  * @param[in] enable True to enable clock, False to disable
232  */
233 static void enable_gpio_port_clock(GPIO_TypeDef *gpio_bank, bool enable)
234 {
235  if (gpio_bank == GPIOA)
236  {
237  if (enable)
238  {
239  __HAL_RCC_GPIOA_CLK_ENABLE();
240  }
241  else
242  {
243  __HAL_RCC_GPIOA_CLK_DISABLE();
244  }
245  }
246  else if (gpio_bank == GPIOB)
247  {
248  if (enable)
249  {
250  __HAL_RCC_GPIOB_CLK_ENABLE();
251  }
252  else
253  {
254  __HAL_RCC_GPIOB_CLK_DISABLE();
255  }
256  }
257  else if (gpio_bank == GPIOH)
258  {
259  if (enable)
260  {
261  __HAL_RCC_GPIOH_CLK_ENABLE();
262  }
263  else
264  {
265  __HAL_RCC_GPIOH_CLK_DISABLE();
266  }
267  }
268 }
269 
270 /**
271  * @brief Get the port clock status for a given GPIO bank
272  *
273  * @param[in] gpio_bank GPIO bank to save
274  * @return True if the GPIO port clock is enabled
275  */
276 static bool get_gpio_port_clock(GPIO_TypeDef *gpio_bank)
277 {
278  if (gpio_bank == GPIOA)
279  {
280  return __HAL_RCC_GPIOA_IS_CLK_ENABLED();
281  }
282  else if (gpio_bank == GPIOB)
283  {
284  return __HAL_RCC_GPIOB_IS_CLK_ENABLED();
285  }
286  else if (gpio_bank == GPIOH)
287  {
288  return __HAL_RCC_GPIOH_IS_CLK_ENABLED();
289  }
290 
291  /* We should never end up here */
292  Error_Handler();
293  return false;
294 }
295 
296 /**
297  * @brief Save all registers for a given GPIO bank including the original GPIO port clock
298  *
299  * The GPIO port clock needs to be enabled before calling this function
300  *
301  * @param[in] gpio_bank GPIO bank to save
302  * @param[out] config Variable for storing the GPIO bank registers
303  */
304 static void save_gpio_bank(GPIO_TypeDef *gpio_bank, gpio_config_t *config)
305 {
306  config->MODER = READ_REG(gpio_bank->MODER);
307  config->OTYPER = READ_REG(gpio_bank->OTYPER);
308  config->OSPEEDR = READ_REG(gpio_bank->OSPEEDR);
309  config->PUPDR = READ_REG(gpio_bank->PUPDR);
310  config->AFR[0] = READ_REG(gpio_bank->AFR[0]);
311  config->AFR[1] = READ_REG(gpio_bank->AFR[1]);
312 }
313 
314 /**
315  * @brief Restore all registers for a given GPIO bank
316  *
317  * @param[in] gpio_bank GPIO bank to restore
318  * @param[in] config Variable that contains all the saved GPIO bank registers
319  */
320 static void restore_gpio_bank(GPIO_TypeDef *gpio_bank, gpio_config_t *config)
321 {
322  /* Enable GPIO port clock to be able to change the configuration */
323  enable_gpio_port_clock(gpio_bank, true);
324 
325  WRITE_REG(gpio_bank->MODER, config->MODER);
326  WRITE_REG(gpio_bank->OTYPER, config->OTYPER);
327  WRITE_REG(gpio_bank->OSPEEDR, config->OSPEEDR);
328  WRITE_REG(gpio_bank->PUPDR, config->PUPDR);
329  WRITE_REG(gpio_bank->AFR[0], config->AFR[0]);
330  WRITE_REG(gpio_bank->AFR[1], config->AFR[1]);
331 
332  /* Restore GPIO port clock to what it was prior to suspending */
333  enable_gpio_port_clock(gpio_bank, config->RCC_GPIO_CLK_ENABLE);
334 }
335 
336 /**
337  * @brief Suspend GPIO driver
338  *
339  * Set all GPIO pins in the lowest power consuming state according to AN4899
340  * and disable all the port clocks.
341  *
342  */
343 static void gpio_suspend(void)
344 {
345  GPIO_InitTypeDef GPIO_InitStructOff;
346 
347  /* Save Clocks */
351 
352  /* Enable all GPIO port clocks now when we have saved the status */
353  __HAL_RCC_GPIOA_CLK_ENABLE();
354  __HAL_RCC_GPIOB_CLK_ENABLE();
355  __HAL_RCC_GPIOH_CLK_ENABLE();
356 
357  /* Save all GPIO banks */
358  save_gpio_bank(GPIOA, &saved_gpio_status[0]);
359  save_gpio_bank(GPIOB, &saved_gpio_status[1]);
360  save_gpio_bank(GPIOH, &saved_gpio_status[2]);
361 
362  /* Set all unused GPIO pins in the lowest power consuming state according to AN4899*/
363  GPIO_InitStructOff.Mode = GPIO_MODE_ANALOG;
364  GPIO_InitStructOff.Pull = GPIO_NOPULL;
365 
366  GPIO_InitStructOff.Pin = GPIO_PIN_All;
367 
368  /* Leave the following pins on bank A unchanged */
369  GPIO_InitStructOff.Pin &= (uint16_t) ~(SPI_SCK_Pin | SPI_MISO_Pin | SPI_MOSI_Pin | MISC_GPIO1_Pin);
370 
371  HAL_GPIO_Init(GPIOA, &GPIO_InitStructOff);
372 
373  GPIO_InitStructOff.Pin = GPIO_PIN_All;
374 
375  /* Leave the following pins on bank B unchanged */
376  GPIO_InitStructOff.Pin &= (uint16_t) ~(INTERRUPT_Pin | ENABLE_Pin | MISC_GPIO0_Pin);
377 
378  HAL_GPIO_Init(GPIOB, &GPIO_InitStructOff);
379 
380  GPIO_InitStructOff.Pin = GPIO_PIN_All;
381 
382  /* Leave the following pins on bank H unchanged */
383  GPIO_InitStructOff.Pin &= (uint16_t) ~(I2C_ADDRESS_Pin | MISC_GPIO2_Pin);
384 
385  HAL_GPIO_Init(GPIOH, &GPIO_InitStructOff);
386 
387  /* Disable all GPIO port clocks */
388  __HAL_RCC_GPIOA_CLK_DISABLE();
389  __HAL_RCC_GPIOB_CLK_DISABLE();
390  __HAL_RCC_GPIOH_CLK_DISABLE();
391 }
392 
393 /**
394  * @brief Resume GPIO driver
395  */
396 static void gpio_resume(void)
397 {
398  /* Restore all GPIOS */
402 }
403 
404 /**
405  * @brief IRQ Handler for RTC Alarm
406  */
407 void HAL_RTC_AlarmAEventCallback(RTC_HandleTypeDef *rtc)
408 {
409  (void)rtc;
410 
411  rtc_alarm_triggered = true;
413 }
414 
415 /**
416  * @brief IRQ Handler for RTC Wakeup
417  */
418 void HAL_RTCEx_WakeUpTimerEventCallback(RTC_HandleTypeDef *rtc)
419 {
420  (void)rtc;
421 
422  rtc_wakeup_triggered = true;
423 }
424 
425 static void acc_integration_enable_wake_up(uint32_t time_usec)
426 {
427  uint32_t wakeup_clock;
428  uint32_t wakeup_counter;
429 
430  rtc_wakeup_triggered = false;
431 
432  // Calculate proper clock source and counter values from sleep time
433  // RTC_WAKEUPCLOCK_RTCCLK_DIV16 gives 1÷32000×16 = 500 us resolution and max 32s
434  // RTC_WAKEUPCLOCK_RTCCLK_DIV8 gives 1÷32000×8 = 250 us resolution and max 16s
435  // RTC_WAKEUPCLOCK_RTCCLK_DIV4 gives 1÷32000×4 = 125 us resolution and max 8s
436  // RTC_WAKEUPCLOCK_RTCCLK_DIV2 gives 1÷32000×2 = 62.5 us resolution and max 4s
437  // RTC_WAKEUPCLOCK_CK_SPRE_16BITS gives 1000 ms resolution and max 18h
438  if (time_usec > 30000000)
439  {
440  wakeup_clock = RTC_WAKEUPCLOCK_CK_SPRE_16BITS;
441  wakeup_counter = (time_usec / 1000000) - 1;
442  }
443  else if (time_usec > 100000)
444  {
445  wakeup_clock = RTC_WAKEUPCLOCK_RTCCLK_DIV16;
446  wakeup_counter = (time_usec * 2 / 1000) - 1;
447  }
448  else
449  {
450  wakeup_clock = RTC_WAKEUPCLOCK_RTCCLK_DIV2;
451  wakeup_counter = (time_usec * 16 / 1000) - 1;
452  }
453 
454  if (HAL_RTCEx_SetWakeUpTimer_IT(&MODULE_RTC_HANDLE, wakeup_counter, wakeup_clock) != HAL_OK)
455  {
456  Error_Handler();
457  }
458 }
459 
461 {
462  if (HAL_RTCEx_DeactivateWakeUpTimer(&MODULE_RTC_HANDLE) != HAL_OK)
463  {
464  Error_Handler();
465  }
466 }
467 
468 void acc_integration_sleep_ms(uint32_t time_msec)
469 {
470  acc_integration_sleep_us(time_msec * 1000);
471 }
472 
473 void acc_integration_sleep_us(uint32_t time_usec)
474 {
476 
477  while (!rtc_wakeup_triggered)
478  {
479  // Turn off interrupts
481 
483  {
484  __WFI();
485  }
486 
487  // Enable interrupt again, the ISR will execute directly after this
489  }
490 
491  rtc_wakeup_triggered = false;
492 
494 }
495 
496 void acc_integration_set_periodic_wakeup(uint32_t time_msec)
497 {
498  periodic_sleep_time_ms = time_msec;
500 }
501 
503 {
504  HAL_RCC_GetOscConfig(&prepare_saved_rcc_oscinitstruct);
505  HAL_RCC_GetClockConfig(&prepare_saved_rcc_clkinitstruct, &prepare_saved_flatency);
506 
508  HAL_I2C_DeInit(&MODULE_I2C_HANDLE);
509  HAL_SPI_DeInit(&A121_SPI_HANDLE);
511  HAL_UART_DeInit(&MODULE_UART1_HANDLE);
512  HAL_UART_DeInit(&MODULE_UART2_HANDLE);
513 
514  gpio_suspend();
515 
516  HAL_SuspendTick();
517 }
518 
520 {
521  HAL_ResumeTick();
522 
523  HAL_RCC_OscConfig(&prepare_saved_rcc_oscinitstruct);
525 
526  gpio_resume();
527 
528  HAL_I2C_Init(&MODULE_I2C_HANDLE);
529  if (prepare_saved_i2c_state == HAL_I2C_STATE_LISTEN)
530  {
531  HAL_I2C_EnableListen_IT(&MODULE_I2C_HANDLE);
532  }
533 
534  HAL_SPI_Init(&A121_SPI_HANDLE);
535  HAL_UART_Init(&MODULE_UART1_HANDLE);
536 
537  if (prepare_saved_uart1_rx_state == HAL_UART_STATE_BUSY_RX)
538  {
539  if (MODULE_UART1_HANDLE.hdmarx != NULL)
540  {
541  HAL_UART_Receive_DMA(&MODULE_UART1_HANDLE, MODULE_UART1_HANDLE.pRxBuffPtr, MODULE_UART1_HANDLE.RxXferSize);
542  }
543  else
544  {
545  HAL_UART_Receive_IT(&MODULE_UART1_HANDLE, MODULE_UART1_HANDLE.pRxBuffPtr, MODULE_UART1_HANDLE.RxXferSize);
546  }
547  }
548 
549  HAL_UART_Init(&MODULE_UART2_HANDLE);
550 }
551 
553 {
554  // The periodic timer must be set prior to invoking this function
555  if (periodic_sleep_time_ms != 0)
556  {
558 
559  uint32_t rtc_ticks_pre_sleep = get_rtc_tick();
560 
561  while (!rtc_alarm_triggered)
562  {
563  // Turn off interrupts
565 
566  if (!rtc_alarm_triggered)
567  {
568  HAL_PWR_EnterSTOPMode(PWR_LOWPOWERREGULATOR_ON, PWR_SLEEPENTRY_WFI);
569  }
570 
571  // Enable interrupt again, the ISR will execute directly after this
573  }
574 
575  rtc_alarm_triggered = false;
576 
577  update_system_tick(rtc_ticks_pre_sleep, get_rtc_tick());
578 
580  }
581  else
582  {
583  printf("acc_integration_set_periodic_wakeup must be called prior to calling this function\n");
584  }
585 }
586 
588 {
589  return HAL_GetTick();
590 }
591 
592 void *acc_integration_mem_alloc(size_t size)
593 {
594  return malloc(size);
595 }
596 
597 void *acc_integration_mem_calloc(size_t nmemb, size_t size)
598 {
599  return calloc(nmemb, size);
600 }
601 
603 {
604  free(ptr);
605 }
prepare_saved_flatency
static uint32_t prepare_saved_flatency
Definition: acc_integration_stm32.c:81
HAL_RTCEx_WakeUpTimerEventCallback
void HAL_RTCEx_WakeUpTimerEventCallback(RTC_HandleTypeDef *rtc)
IRQ Handler for RTC Wakeup.
Definition: acc_integration_stm32.c:418
MODULE_UART2_HANDLE
UART_HandleTypeDef MODULE_UART2_HANDLE
SPI_MISO_Pin
#define SPI_MISO_Pin
Definition: main.h:90
prepare_saved_uart1_rx_state
static HAL_UART_StateTypeDef prepare_saved_uart1_rx_state
Definition: acc_integration_stm32.c:83
MISC_GPIO1_Pin
#define MISC_GPIO1_Pin
Definition: main.h:100
A121_SPI_HANDLE
SPI_HandleTypeDef A121_SPI_HANDLE
enable_gpio_port_clock
static void enable_gpio_port_clock(GPIO_TypeDef *gpio_bank, bool enable)
Set the port clock status for a given GPIO bank.
Definition: acc_integration_stm32.c:233
rtc_alarm_triggered
volatile bool rtc_alarm_triggered
Set to true when RTC alarm interrupt has triggered.
Definition: acc_integration_stm32.c:23
SPI_SCK_Pin
#define SPI_SCK_Pin
Definition: main.h:92
gpio_resume
static void gpio_resume(void)
Resume GPIO driver.
Definition: acc_integration_stm32.c:396
prepare_saved_rcc_oscinitstruct
static RCC_OscInitTypeDef prepare_saved_rcc_oscinitstruct
Definition: acc_integration_stm32.c:79
update_system_tick
static void update_system_tick(uint32_t rtc_ticks_pre_sleep, uint32_t rtc_ticks_post_sleep)
Update system tick based on RTC ticks during sleep.
Definition: acc_integration_stm32.c:178
SPI_MOSI_Pin
#define SPI_MOSI_Pin
Definition: main.h:88
I2C_ADDRESS_Pin
#define I2C_ADDRESS_Pin
Definition: main.h:76
gpio_suspend
static void gpio_suspend(void)
Suspend GPIO driver.
Definition: acc_integration_stm32.c:343
acc_integration.h
config
cargo_config_t config
Definition: i2c_example_cargo.c:34
acc_integration_get_time
uint32_t acc_integration_get_time(void)
Get current time.
Definition: acc_integration_stm32.c:587
MISC_GPIO2_Pin
#define MISC_GPIO2_Pin
Definition: main.h:65
get_rtc_tick
static uint32_t get_rtc_tick(void)
Get RTC ticks based on current RTC time.
Definition: acc_integration_stm32.c:148
acc_integration_sleep_ms
void acc_integration_sleep_ms(uint32_t time_msec)
Sleep for a specified number of milliseconds.
Definition: acc_integration_stm32.c:468
rtc_time_to_tick
static uint32_t rtc_time_to_tick(RTC_TimeTypeDef *time)
Convert RTC time to RTC ticks.
Definition: acc_integration_stm32.c:92
acc_integration_disable_wake_up
static void acc_integration_disable_wake_up(void)
Definition: acc_integration_stm32.c:460
get_gpio_port_clock
static bool get_gpio_port_clock(GPIO_TypeDef *gpio_bank)
Get the port clock status for a given GPIO bank.
Definition: acc_integration_stm32.c:276
printf
#define printf
Definition: printf.h:60
acc_integration_set_periodic_wakeup
void acc_integration_set_periodic_wakeup(uint32_t time_msec)
Set up a periodic timer used to wake up the system from sleep.
Definition: acc_integration_stm32.c:496
gpio_config_t::RCC_GPIO_CLK_ENABLE
uint32_t RCC_GPIO_CLK_ENABLE
Definition: i2c_application_system_stm32.c:42
acc_integration_prepare_stop_1
static void acc_integration_prepare_stop_1(void)
Definition: acc_integration_stm32.c:502
acc_integration_mem_free
void acc_integration_mem_free(void *ptr)
Free dynamic memory.
Definition: acc_integration_stm32.c:602
MODULE_RTC_HANDLE
RTC_HandleTypeDef MODULE_RTC_HANDLE
Handles for the blocks to control.
disable_interrupts
static void disable_interrupts(void)
Definition: acc_integration_stm32.c:49
acc_integration_mem_alloc
void * acc_integration_mem_alloc(size_t size)
Allocate dynamic memory.
Definition: acc_integration_stm32.c:592
enable_interrupts
static void enable_interrupts(void)
Definition: acc_integration_stm32.c:56
ENABLE_Pin
#define ENABLE_Pin
Definition: main.h:84
RTC_MAX_TIME_MS
#define RTC_MAX_TIME_MS
Maximum RTC time before wrapping occurs.
Definition: acc_integration_stm32.c:18
main.h
: Header for main.c file. This file contains the common defines of the application.
Error_Handler
void Error_Handler(void)
acc_integration_sleep_us
void acc_integration_sleep_us(uint32_t time_usec)
Sleep for a specified number of microseconds.
Definition: acc_integration_stm32.c:473
gpio_config_t
GPIO config status, maps directly to the GPIO registers.
Definition: i2c_application_system_stm32.c:34
acc_integration_resume_stop_1
static void acc_integration_resume_stop_1(void)
Definition: acc_integration_stm32.c:519
acc_integration_enable_wake_up
static void acc_integration_enable_wake_up(uint32_t time_usec)
Definition: acc_integration_stm32.c:425
acc_integration_sleep_until_periodic_wakeup
void acc_integration_sleep_until_periodic_wakeup(void)
Put the system in sleep until the periodic timer triggers.
Definition: acc_integration_stm32.c:552
rtc_wakeup_triggered
volatile bool rtc_wakeup_triggered
Set to true when RTC wakeup interrupt has triggered.
Definition: acc_integration_stm32.c:28
rtc_set_next_wakeup_time
static void rtc_set_next_wakeup_time(void)
Function for setting the next wakeup time from the RTC interrupt.
Definition: acc_integration_stm32.c:194
save_gpio_bank
static void save_gpio_bank(GPIO_TypeDef *gpio_bank, gpio_config_t *config)
Save all registers for a given GPIO bank including the original GPIO port clock.
Definition: acc_integration_stm32.c:304
uwTick
__IO uint32_t uwTick
MISC_GPIO0_Pin
#define MISC_GPIO0_Pin
Definition: main.h:96
INTERRUPT_Pin
#define INTERRUPT_Pin
Definition: main.h:62
saved_gpio_status
static gpio_config_t saved_gpio_status[3]
GPIO status of the system before going to sleep.
Definition: acc_integration_stm32.c:66
rtc_tick_to_time
static void rtc_tick_to_time(uint32_t tick, RTC_TimeTypeDef *time)
Convert RTC ticks to RTC time.
Definition: acc_integration_stm32.c:122
MODULE_UART1_HANDLE
UART_HandleTypeDef MODULE_UART1_HANDLE
prepare_saved_i2c_state
static HAL_I2C_StateTypeDef prepare_saved_i2c_state
Definition: acc_integration_stm32.c:84
restore_gpio_bank
static void restore_gpio_bank(GPIO_TypeDef *gpio_bank, gpio_config_t *config)
Restore all registers for a given GPIO bank.
Definition: acc_integration_stm32.c:320
acc_integration_mem_calloc
void * acc_integration_mem_calloc(size_t nmemb, size_t size)
Allocate dynamic memory.
Definition: acc_integration_stm32.c:597
prepare_saved_rcc_clkinitstruct
static RCC_ClkInitTypeDef prepare_saved_rcc_clkinitstruct
Definition: acc_integration_stm32.c:80
periodic_sleep_time_ms
static uint32_t periodic_sleep_time_ms
Variable that holds the periodic wakeup time.
Definition: acc_integration_stm32.c:33
HAL_RTC_AlarmAEventCallback
void HAL_RTC_AlarmAEventCallback(RTC_HandleTypeDef *rtc)
IRQ Handler for RTC Alarm.
Definition: acc_integration_stm32.c:407
MODULE_I2C_HANDLE
I2C_HandleTypeDef MODULE_I2C_HANDLE