/******************************************************************************* * @file power_control.c * @brief Device power sequence control * * Power-up sequence state machine with k_timer (single-shot 20ms intervals) ******************************************************************************/ #include #include "main.h" #include "power_control.h" #include "debug_print.h" #define POWER_LOOP_INTERVAL 20 /* ms */ static struct k_timer m_power_timer; static uint8_t p_order; static bool lock_check = false; extern volatile bool processing; static void power_loop_expiry(struct k_timer *timer) { power_loop(timer); } int device_sleep_mode(void) { k_msleep(2); DBG_PRINTF("Device_Sleep_Mode OK!\r\n"); k_msleep(10); processing = false; return 0; } int device_activated(void) { p_order = 0; lock_check = true; power_timer_start(); return 0; } void power_loop(struct k_timer *timer) { power_timer_stop(); // Sensor init not needed - imu_read_direct() handles it per measurement p_order = 2; if (p_order < 2) { p_order++; power_timer_start(); } else { DBG_PRINTF("[PWR] Device Activated OK!\r\n"); } } int device_reactivated(void) { // sw_i2c_init_once() will be added in Stage 3 k_msleep(10); lock_check = true; p_order = 0; power_timer_start(); return 0; } void power_timer_start(void) { k_timer_start(&m_power_timer, K_MSEC(POWER_LOOP_INTERVAL), K_NO_WAIT); } void power_timer_stop(void) { k_timer_stop(&m_power_timer); } void power_timer_init(void) { k_timer_init(&m_power_timer, power_loop_expiry, NULL); }