|
|
#include <inttypes.h>#include <stdbool.h>#include <stddef.h>#include <stdio.h>#include "main.h"#include "acc_integration.h"#include "acc_reg_protocol.h"#include "i2c_application_system.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 | I2C_SLAVE_BUFFER_SIZE 4 |
| #define | WAIT_FOR_IDLE_RETRIES 10U |
| #define | WAIT_FOR_IDLE_RETRY_INTERNAL_MS 10U |
| #define | GPIO_BANK_COUNT 3U |
| #define | I2C_ADDRESS_FLOATING (0x52) |
| #define | I2C_ADDRESS_LOW (0x51) |
| #define | I2C_ADDRESS_HIGH (0x53) |
Enumerations | |
| enum | pin_state_t { PIN_STATE_LOW, PIN_STATE_HIGH, PIN_STATE_FLOATING } |
Functions | |
| static void | disable_interrupts (void) |
| Disable interrupts. More... | |
| static void | enable_interrupts (void) |
| Enable interrupts. More... | |
| static void | prepare_power_down (void) |
| Prepare power down state. More... | |
| static void | resume_power_down (void) |
| Resume power down state. More... | |
| static uint32_t | get_rtc_tick (void) |
| Get RTC ticks based on current RTC time. More... | |
| static void | rtc_tick_to_time (uint32_t tick, RTC_TimeTypeDef *time) |
| Convert RTC ticks to RTC time. More... | |
| static void | rtc_set_next_wakeup_time (void) |
| Function for setting the next wakeup time from the RTC interrupt. More... | |
| static void | wait_for_i2c_idle (void) |
| Wait for I2C interface to be idle. More... | |
| static void | prepare_register_data (I2C_HandleTypeDef *hi2c) |
| Helper function to prepare transmit of register data. More... | |
| static uint32_t | get_i2c_address (void) |
| Helper function to get i2c address from I2C_ADDRESS pin pin state. More... | |
| static pin_state_t | get_pin_state (GPIO_TypeDef *gpio_port, uint32_t gpio_pin) |
| Helper function to the state (HIGH/LOW/FLOATING) of a gpio pin. More... | |
| void | i2c_application_system_init (void) |
| Init the system. More... | |
| void | i2c_application_system_reset (void) |
| Reset the system. More... | |
| void | i2c_application_system_wait_for_interrupt (void) |
| Wait for interrupt to occur. More... | |
| bool | i2c_application_system_test_wakeup_pin (void) |
| Check if wakeup pin is high. More... | |
| void | i2c_application_system_set_ready_pin (bool enable) |
| Set the ready pin state. More... | |
| void | i2c_application_system_setup_generic_gpio_pin (bool enable) |
| Setup the generic gpio pin. More... | |
| void | i2c_application_system_set_generic_gpio_pin (bool enable) |
| Set the generic gpio pin output state. More... | |
| void | i2c_application_enter_low_power_state (void) |
| Make the MCU enter its low power state. More... | |
| void | i2c_application_set_periodic_wakeup (uint32_t period_ms) |
| Set up a periodic timer used to wake up the system from sleep. More... | |
| bool | i2c_application_is_periodic_wakeup (void) |
| Test if a periodic wake up has occurred. More... | |
| void | HAL_RTCEx_AlarmBEventCallback (RTC_HandleTypeDef *rtc) |
| IRQ Handler for RTC B Alarm. More... | |
| void | HAL_I2C_AddrCallback (I2C_HandleTypeDef *hi2c, uint8_t TransferDirection, uint16_t AddrMatchCode) |
| void | HAL_I2C_SlaveTxCpltCallback (I2C_HandleTypeDef *hi2c) |
| void | HAL_I2C_SlaveRxCpltCallback (I2C_HandleTypeDef *hi2c) |
| void | HAL_I2C_ListenCpltCallback (I2C_HandleTypeDef *hi2c) |
| void | HAL_I2C_ErrorCallback (I2C_HandleTypeDef *hi2c) |
Variables | |
| SPI_HandleTypeDef | A121_SPI_HANDLE |
| I2C_HandleTypeDef | MODULE_I2C_HANDLE |
| UART_HandleTypeDef | MODULE_UART1_HANDLE |
| UART_HandleTypeDef | MODULE_UART2_HANDLE |
| RTC_HandleTypeDef | MODULE_RTC_HANDLE |
| static RCC_OscInitTypeDef | low_power_saved_rcc_oscinitstruct |
| static RCC_ClkInitTypeDef | low_power_saved_rcc_clkinitstruct |
| static uint32_t | low_power_saved_flatency |
| static gpio_config_t | low_power_saved_gpio_bank [3U] = {0} |
| static GPIO_TypeDef * | gpio_banks [3U] = {GPIOA, GPIOB, GPIOH} |
| static uint8_t | i2c_slave_buffer [4] |
| static volatile bool | i2c_idle = true |
| static uint32_t | rtc_period_time_ms = 0 |
| static volatile bool | rtc_wakeup_triggered = false |
| #define GPIO_BANK_COUNT 3U |
Definition at line 21 of file i2c_application_system_stm32.c.
| #define I2C_ADDRESS_FLOATING (0x52) |
Definition at line 23 of file i2c_application_system_stm32.c.
| #define I2C_ADDRESS_HIGH (0x53) |
Definition at line 25 of file i2c_application_system_stm32.c.
| #define I2C_ADDRESS_LOW (0x51) |
Definition at line 24 of file i2c_application_system_stm32.c.
| #define I2C_SLAVE_BUFFER_SIZE 4 |
Definition at line 18 of file i2c_application_system_stm32.c.
| #define WAIT_FOR_IDLE_RETRIES 10U |
Definition at line 19 of file i2c_application_system_stm32.c.
| #define WAIT_FOR_IDLE_RETRY_INTERNAL_MS 10U |
Definition at line 20 of file i2c_application_system_stm32.c.
| enum pin_state_t |
| Enumerator | |
|---|---|
| PIN_STATE_LOW | |
| PIN_STATE_HIGH | |
| PIN_STATE_FLOATING | |
Definition at line 27 of file i2c_application_system_stm32.c.
|
inlinestatic |
Disable interrupts.
Definition at line 268 of file i2c_application_system_stm32.c.
|
inlinestatic |
Enable interrupts.
Definition at line 275 of file i2c_application_system_stm32.c.
|
static |
Helper function to get i2c address from I2C_ADDRESS pin pin state.
Definition at line 503 of file i2c_application_system_stm32.c.
|
static |
Helper function to the state (HIGH/LOW/FLOATING) of a gpio pin.
| [in] | gpio_port | The GPIO port |
| [in] | gpio_pin | The GPIO pin |
Definition at line 525 of file i2c_application_system_stm32.c.
|
static |
Get RTC ticks based on current RTC time.
Definition at line 373 of file i2c_application_system_stm32.c.
| void HAL_I2C_AddrCallback | ( | I2C_HandleTypeDef * | hi2c, |
| uint8_t | TransferDirection, | ||
| uint16_t | AddrMatchCode | ||
| ) |
Calling this function with wrong parameters will return HAL_ERROR Calling this function when the i2c module is in the wrong state return HAL_BUSY
Definition at line 569 of file i2c_application_system_stm32.c.
| void HAL_I2C_ErrorCallback | ( | I2C_HandleTypeDef * | hi2c | ) |
The data NACK is the only valid error code
Definition at line 652 of file i2c_application_system_stm32.c.
| void HAL_I2C_ListenCpltCallback | ( | I2C_HandleTypeDef * | hi2c | ) |
Calling this function with wrong parameters will return HAL_ERROR Calling this function when the i2c module is in the wrong state return HAL_BUSY
Definition at line 637 of file i2c_application_system_stm32.c.
| void HAL_I2C_SlaveRxCpltCallback | ( | I2C_HandleTypeDef * | hi2c | ) |
Calling this function with wrong parameters will return HAL_ERROR Calling this function when the i2c module is in the wrong state return HAL_BUSY
Definition at line 604 of file i2c_application_system_stm32.c.
| void HAL_I2C_SlaveTxCpltCallback | ( | I2C_HandleTypeDef * | hi2c | ) |
Definition at line 598 of file i2c_application_system_stm32.c.
| void HAL_RTCEx_AlarmBEventCallback | ( | RTC_HandleTypeDef * | rtc | ) |
IRQ Handler for RTC B Alarm.
Definition at line 262 of file i2c_application_system_stm32.c.
| void i2c_application_enter_low_power_state | ( | void | ) |
Make the MCU enter its low power state.
This function is called by the i2c application when the MCU should power down.
Wait for the i2c interface to be idle, if not idle after retries, power down anyway!
Definition at line 215 of file i2c_application_system_stm32.c.
| bool i2c_application_is_periodic_wakeup | ( | void | ) |
Test if a periodic wake up has occurred.
Definition at line 244 of file i2c_application_system_stm32.c.
| void i2c_application_set_periodic_wakeup | ( | uint32_t | period_ms | ) |
Set up a periodic timer used to wake up the system from sleep.
If the time_msec is set to zero the periodic wakeup will be disabled.
| period_ms | Period time in milliseconds |
Definition at line 238 of file i2c_application_system_stm32.c.
| void i2c_application_system_init | ( | void | ) |
Init the system.
This function is called by the i2c application during initialization.
Calling this function with wrong parameters will return HAL_ERROR Calling this function when the i2c module is in the wrong state return HAL_BUSY
Definition at line 130 of file i2c_application_system_stm32.c.
| void i2c_application_system_reset | ( | void | ) |
Reset the system.
This function is called by the i2c application when the system should be restarted.
Wait for the i2c interface to be idle, if not idle after retries, reset anyway!
Definition at line 158 of file i2c_application_system_stm32.c.
| void i2c_application_system_set_generic_gpio_pin | ( | bool | enable | ) |
Set the generic gpio pin output state.
This function is used to set the output state of the generic gpio pin
| [in] | enable | pin output is set to high level when enable is true |
Definition at line 208 of file i2c_application_system_stm32.c.
| void i2c_application_system_set_ready_pin | ( | bool | enable | ) |
Set the ready pin state.
This function is used to set the state of the ready pin
| [in] | enable | pin is set to high level when enable is true |
Definition at line 181 of file i2c_application_system_stm32.c.
| void i2c_application_system_setup_generic_gpio_pin | ( | bool | enable | ) |
Setup the generic gpio pin.
This function is used to setup the generic gpio pin
| [in] | enable | pin is set to output driver when enable is true |
Definition at line 188 of file i2c_application_system_stm32.c.
| bool i2c_application_system_test_wakeup_pin | ( | void | ) |
Check if wakeup pin is high.
This function is used to test if the system should power down
Definition at line 174 of file i2c_application_system_stm32.c.
| void i2c_application_system_wait_for_interrupt | ( | void | ) |
Wait for interrupt to occur.
Definition at line 169 of file i2c_application_system_stm32.c.
|
inlinestatic |
Prepare power down state.
Definition at line 282 of file i2c_application_system_stm32.c.
|
static |
Helper function to prepare transmit of register data.
| [in] | hi2c | The I2C handle |
Calling this function with wrong parameters will return HAL_ERROR Calling this function when the i2c module is in the wrong state return HAL_BUSY
Definition at line 487 of file i2c_application_system_stm32.c.
|
inlinestatic |
Resume power down state.
Calling this function with wrong parameters will return HAL_ERROR Calling this function when the i2c module is in the wrong state return HAL_BUSY
Definition at line 333 of file i2c_application_system_stm32.c.
|
static |
Function for setting the next wakeup time from the RTC interrupt.
Definition at line 437 of file i2c_application_system_stm32.c.
|
static |
Convert RTC ticks to RTC time.
| [in] | tick | rtc ticks in ms |
| [out] | time | RTC time |
Definition at line 416 of file i2c_application_system_stm32.c.
|
static |
Wait for I2C interface to be idle.
Definition at line 468 of file i2c_application_system_stm32.c.
| SPI_HandleTypeDef A121_SPI_HANDLE |
|
static |
Definition at line 54 of file i2c_application_system_stm32.c.
|
static |
Definition at line 57 of file i2c_application_system_stm32.c.
|
static |
Definition at line 56 of file i2c_application_system_stm32.c.
|
static |
Definition at line 52 of file i2c_application_system_stm32.c.
|
static |
Definition at line 53 of file i2c_application_system_stm32.c.
|
static |
Definition at line 51 of file i2c_application_system_stm32.c.
|
static |
Definition at line 50 of file i2c_application_system_stm32.c.
| I2C_HandleTypeDef MODULE_I2C_HANDLE |
| RTC_HandleTypeDef MODULE_RTC_HANDLE |
| UART_HandleTypeDef MODULE_UART1_HANDLE |
| UART_HandleTypeDef MODULE_UART2_HANDLE |
|
static |
Definition at line 59 of file i2c_application_system_stm32.c.
|
static |
Definition at line 60 of file i2c_application_system_stm32.c.