|
#include <stdint.h>
#include <stdio.h>
#include <string.h>
#include "main.h"
#include "acc_integration.h"
Go to the source code of this file.
Data Structures | |
struct | gpio_config_t |
GPIO config status, maps directly to the GPIO registers. More... | |
Macros | |
#define | RTC_MAX_TIME_MS (24*60*60*1000) |
Maximum RTC time before wrapping occurs. More... | |
Functions | |
static void | disable_interrupts (void) |
static void | enable_interrupts (void) |
static uint32_t | rtc_time_to_tick (RTC_TimeTypeDef *time) |
Convert RTC time to RTC ticks. More... | |
static void | rtc_tick_to_time (uint32_t tick, RTC_TimeTypeDef *time) |
Convert RTC ticks to RTC time. More... | |
static uint32_t | get_rtc_tick (void) |
Get RTC ticks based on current RTC time. More... | |
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. More... | |
static void | rtc_set_next_wakeup_time (void) |
Function for setting the next wakeup time from the RTC interrupt. More... | |
static void | enable_gpio_port_clock (GPIO_TypeDef *gpio_bank, bool enable) |
Set the port clock status for a given GPIO bank. More... | |
static bool | get_gpio_port_clock (GPIO_TypeDef *gpio_bank) |
Get the port clock status for a given GPIO bank. More... | |
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. More... | |
static void | restore_gpio_bank (GPIO_TypeDef *gpio_bank, gpio_config_t *config) |
Restore all registers for a given GPIO bank. More... | |
static void | gpio_suspend (void) |
Suspend GPIO driver. More... | |
static void | gpio_resume (void) |
Resume GPIO driver. More... | |
void | HAL_RTC_AlarmAEventCallback (RTC_HandleTypeDef *rtc) |
IRQ Handler for RTC Alarm. More... | |
void | HAL_RTCEx_WakeUpTimerEventCallback (RTC_HandleTypeDef *rtc) |
IRQ Handler for RTC Wakeup. More... | |
static void | acc_integration_enable_wake_up (uint32_t time_usec) |
static void | acc_integration_disable_wake_up (void) |
void | acc_integration_sleep_ms (uint32_t time_msec) |
Sleep for a specified number of milliseconds. More... | |
void | acc_integration_sleep_us (uint32_t time_usec) |
Sleep for a specified number of microseconds. More... | |
void | acc_integration_set_periodic_wakeup (uint32_t time_msec) |
Set up a periodic timer used to wake up the system from sleep. More... | |
static void | acc_integration_prepare_stop_1 (void) |
static void | acc_integration_resume_stop_1 (void) |
void | acc_integration_sleep_until_periodic_wakeup (void) |
Put the system in sleep until the periodic timer triggers. More... | |
uint32_t | acc_integration_get_time (void) |
Get current time. More... | |
void * | acc_integration_mem_alloc (size_t size) |
Allocate dynamic memory. More... | |
void * | acc_integration_mem_calloc (size_t nmemb, size_t size) |
Allocate dynamic memory. More... | |
void | acc_integration_mem_free (void *ptr) |
Free dynamic memory. More... | |
Variables | |
volatile bool | rtc_alarm_triggered = false |
Set to true when RTC alarm interrupt has triggered. More... | |
volatile bool | rtc_wakeup_triggered = false |
Set to true when RTC wakeup interrupt has triggered. More... | |
static uint32_t | periodic_sleep_time_ms = 0 |
Variable that holds the periodic wakeup time. More... | |
static gpio_config_t | saved_gpio_status [3] |
GPIO status of the system before going to sleep. More... | |
RTC_HandleTypeDef | MODULE_RTC_HANDLE |
Handles for the blocks to control. More... | |
SPI_HandleTypeDef | A121_SPI_HANDLE |
I2C_HandleTypeDef | MODULE_I2C_HANDLE |
UART_HandleTypeDef | MODULE_UART1_HANDLE |
UART_HandleTypeDef | MODULE_UART2_HANDLE |
__IO uint32_t | uwTick |
static RCC_OscInitTypeDef | prepare_saved_rcc_oscinitstruct |
static RCC_ClkInitTypeDef | prepare_saved_rcc_clkinitstruct |
static uint32_t | prepare_saved_flatency |
static HAL_UART_StateTypeDef | prepare_saved_uart1_rx_state |
static HAL_I2C_StateTypeDef | prepare_saved_i2c_state |
#define RTC_MAX_TIME_MS (24*60*60*1000) |
Maximum RTC time before wrapping occurs.
Definition at line 19 of file acc_integration_stm32.c.
|
static |
Definition at line 492 of file acc_integration_stm32.c.
|
static |
Definition at line 456 of file acc_integration_stm32.c.
uint32_t acc_integration_get_time | ( | void | ) |
Get current time.
It is important that this value wraps correctly and uses all bits. I.e. it should count upwards to 2^32 - 1 and then 0 again.
Definition at line 626 of file acc_integration_stm32.c.
void* acc_integration_mem_alloc | ( | size_t | size | ) |
Allocate dynamic memory.
[in] | size | The bytesize of the reuested memory block |
Definition at line 632 of file acc_integration_stm32.c.
void* acc_integration_mem_calloc | ( | size_t | nmemb, |
size_t | size | ||
) |
Allocate dynamic memory.
Allocate an array of nmemb elements of size bytes each.
[in] | nmemb | The number of elements in the array |
[in] | size | The bytesize of the element |
Definition at line 638 of file acc_integration_stm32.c.
void acc_integration_mem_free | ( | void * | ptr | ) |
Free dynamic memory.
[in] | ptr | A pointer to the memory space to be freed |
Definition at line 644 of file acc_integration_stm32.c.
|
static |
Definition at line 538 of file acc_integration_stm32.c.
|
static |
Definition at line 556 of file acc_integration_stm32.c.
void acc_integration_set_periodic_wakeup | ( | uint32_t | time_msec | ) |
Set up a periodic timer used to wake up the system from sleep.
This function will start a periodic timer with the specified time. This is useful when the drift of the wakeup interval should be kept at a minimum.
If the time_msec is set to zero the periodic wakeup will be disabled.
time_msec | Time in milliseconds |
Definition at line 531 of file acc_integration_stm32.c.
void acc_integration_sleep_ms | ( | uint32_t | time_msec | ) |
Sleep for a specified number of milliseconds.
time_msec | Time in milliseconds to sleep |
Definition at line 501 of file acc_integration_stm32.c.
void acc_integration_sleep_until_periodic_wakeup | ( | void | ) |
Put the system in sleep until the periodic timer triggers.
The periodic timer must be started using acc_integration_set_periodic_wakeup prior to invoking this function. The target specific implementation of this function will determine the sleep depth based on the set sleep interval and it will be a trade-off between wake-up latency and power consumption.
Definition at line 590 of file acc_integration_stm32.c.
void acc_integration_sleep_us | ( | uint32_t | time_usec | ) |
Sleep for a specified number of microseconds.
time_usec | Time in microseconds to sleep |
Definition at line 507 of file acc_integration_stm32.c.
|
inlinestatic |
Definition at line 55 of file acc_integration_stm32.c.
|
static |
Set the port clock status for a given GPIO bank.
[in] | gpio_bank | GPIO port clock to set |
[in] | enable | True to enable clock, False to disable |
Definition at line 248 of file acc_integration_stm32.c.
|
inlinestatic |
Definition at line 63 of file acc_integration_stm32.c.
|
static |
Get the port clock status for a given GPIO bank.
[in] | gpio_bank | GPIO bank to save |
Definition at line 292 of file acc_integration_stm32.c.
|
static |
Get RTC ticks based on current RTC time.
Definition at line 160 of file acc_integration_stm32.c.
|
static |
|
static |
Suspend GPIO driver.
Set all GPIO pins in the lowest power consuming state according to AN4899 and disable all the port clocks.
Definition at line 362 of file acc_integration_stm32.c.
void HAL_RTC_AlarmAEventCallback | ( | RTC_HandleTypeDef * | rtc | ) |
IRQ Handler for RTC Alarm.
Definition at line 436 of file acc_integration_stm32.c.
void HAL_RTCEx_WakeUpTimerEventCallback | ( | RTC_HandleTypeDef * | rtc | ) |
IRQ Handler for RTC Wakeup.
Definition at line 448 of file acc_integration_stm32.c.
|
static |
Restore all registers for a given GPIO bank.
[in] | gpio_bank | GPIO bank to restore |
[in] | config | Variable that contains all the saved GPIO bank registers |
Definition at line 338 of file acc_integration_stm32.c.
|
static |
Function for setting the next wakeup time from the RTC interrupt.
Definition at line 208 of file acc_integration_stm32.c.
|
static |
Convert RTC ticks to RTC time.
[in] | tick | rtc ticks in ms |
[out] | time | RTC time |
Definition at line 133 of file acc_integration_stm32.c.
|
static |
Convert RTC time to RTC ticks.
[in] | time | RTC time |
Definition at line 102 of file acc_integration_stm32.c.
|
static |
Save all registers for a given GPIO bank including the original GPIO port clock.
The GPIO port clock needs to be enabled before calling this function
[in] | gpio_bank | GPIO bank to save |
[out] | config | Variable for storing the GPIO bank registers |
Definition at line 321 of file acc_integration_stm32.c.
|
static |
Update system tick based on RTC ticks during sleep.
[in] | rtc_ticks_pre_sleep | rtc ticks before sleep was entered |
[in] | rtc_ticks_post_sleep | rtc ticks after sleep was exited |
Definition at line 191 of file acc_integration_stm32.c.
SPI_HandleTypeDef A121_SPI_HANDLE |
I2C_HandleTypeDef MODULE_I2C_HANDLE |
RTC_HandleTypeDef MODULE_RTC_HANDLE |
Handles for the blocks to control.
UART_HandleTypeDef MODULE_UART1_HANDLE |
UART_HandleTypeDef MODULE_UART2_HANDLE |
|
static |
Variable that holds the periodic wakeup time.
Definition at line 37 of file acc_integration_stm32.c.
|
static |
Definition at line 90 of file acc_integration_stm32.c.
|
static |
Definition at line 93 of file acc_integration_stm32.c.
|
static |
Definition at line 89 of file acc_integration_stm32.c.
|
static |
Definition at line 88 of file acc_integration_stm32.c.
|
static |
Definition at line 92 of file acc_integration_stm32.c.
volatile bool rtc_alarm_triggered = false |
Set to true when RTC alarm interrupt has triggered.
Definition at line 25 of file acc_integration_stm32.c.
volatile bool rtc_wakeup_triggered = false |
Set to true when RTC wakeup interrupt has triggered.
Definition at line 31 of file acc_integration_stm32.c.
|
static |
GPIO status of the system before going to sleep.
Definition at line 74 of file acc_integration_stm32.c.
__IO uint32_t uwTick |