#include "aem_os_dev.h" #include "aem_log.h" #ifdef CONFIG_SYS_WAKELOCK #include #include #endif #include #include "sys_manager.h" #include static int check_screen_lock_time(void) { int ref_cnt = 0; #ifdef CONFIG_SYS_WAKELOCK ref_cnt = sys_wakelocks_check(FULL_WAKE_LOCK); #endif return ref_cnt; } static void force_screen_lock_time_reset(void) { #ifdef CONFIG_SYS_WAKELOCK sys_wake_lock(FULL_WAKE_LOCK); sys_wake_unlock(FULL_WAKE_LOCK); #endif } static void os_sys_wake_lock(void) { #ifdef CONFIG_SYS_WAKELOCK sys_wake_lock(FULL_WAKE_LOCK); #endif } static void os_sys_wake_unlock(void) { #ifdef CONFIG_SYS_WAKELOCK int ref_cnt = check_screen_lock_time(); if (ref_cnt > 0) { sys_wake_unlock(FULL_WAKE_LOCK); } #endif } static void os_sys_partial_wake_lock(void) { #ifdef CONFIG_SYS_WAKELOCK sys_wake_lock(PARTIAL_WAKE_LOCK); #endif } static void os_sys_partial_wake_unlock(void) { #ifdef CONFIG_SYS_WAKELOCK sys_wake_unlock(PARTIAL_WAKE_LOCK); #endif } static void disable_screen_lock_time(void) { int ref_cnt = check_screen_lock_time(); #ifdef CONFIG_SYS_WAKELOCK if (ref_cnt == 0) { sys_wake_lock(FULL_WAKE_LOCK); } #endif } static void screen_force_off(void) { #ifndef CONFIG_SIMULATOR system_request_fast_standby(); #endif } static void enable_screen_lock_time(void) { int ref_cnt = check_screen_lock_time(); #ifdef CONFIG_SYS_WAKELOCK if (ref_cnt != 0) { sys_wake_unlock(FULL_WAKE_LOCK); } #endif } #ifndef CONFIG_SIMULATOR extern void system_set_autosleep_time(uint32_t timeout); #endif static void set_screen_lock_time(uint32_t s) { // disable_screen_lock_time(); // enable_screen_lock_time(); #ifndef CONFIG_SIMULATOR system_set_auto_sleep_time(s); #endif } static uint32_t sys_cycle; static uint32_t sys_time_ms; static uint32_t get_sys_time_ms(void) { #ifndef CONFIG_SIMULATOR uint32_t cycle = k_cycle_get_32(); sys_time_ms += k_cyc_to_ms_floor32(cycle - sys_cycle); sys_cycle = cycle; #endif return sys_time_ms; } static bool is_in_isr(void) { return os_is_in_isr(); } static void set_aod_mode(bool is_aod) { AEM_LOG_I("set_aod_mode %d \r\n", is_aod); #ifndef CONFIG_SIMULATOR soc_set_aod_mode(is_aod); #endif } static bool get_aod_mode(void) { #ifndef CONFIG_SIMULATOR return soc_get_aod_mode(); #endif return false; } static void sys_power_reboot(int reason) { AEM_LOG_I("sys_power_reboot %d \r\n", reason); #ifndef CONFIG_SIMULATOR system_power_reboot(reason); #endif } static void sys_power_off(void) { AEM_LOG_I("sys_power_off \r\n"); #ifndef CONFIG_SIMULATOR system_power_off(); #endif } static uint32_t get_current_thread_id(void) { #ifndef CONFIG_SIMULATOR return (uint32_t)os_current_get(); #endif return 0; } static bool is_sys_screen_on(void) { #ifndef CONFIG_SIMULATOR return system_is_screen_on(); #endif return false; } static uint32_t get_hw_cycle_tick(void) { return k_cycle_get_32(); } static uint32_t get_hw_cycle_tick_elaps(uint32_t prev_tick) { uint32_t curr_time = k_cycle_get_32(); uint32_t elaps = k_cyc_to_us_floor32(curr_time - prev_tick) / 1000; return elaps; } static const aem_sys_os_ops_t s_sys_os_ops = { .force_screen_lock_time_reset = force_screen_lock_time_reset, .disable_screen_lock_time = disable_screen_lock_time, .enable_screen_lock_time = enable_screen_lock_time, .check_screen_lock_time = check_screen_lock_time, .screen_force_off = screen_force_off, .set_screen_lock_time = set_screen_lock_time, .sys_wake_lock = os_sys_wake_lock, .sys_wake_unlock = os_sys_wake_unlock, .sys_partial_wake_lock = os_sys_partial_wake_lock, .sys_partial_wake_unlock = os_sys_partial_wake_unlock, .get_sys_time_ms = get_sys_time_ms, .is_in_isr = is_in_isr, .set_aod_mode = set_aod_mode, .get_aod_mode = get_aod_mode, .sys_power_off = sys_power_off, .sys_power_reboot = sys_power_reboot, .get_current_thread_id = get_current_thread_id, .is_sys_screen_on = is_sys_screen_on, .get_hw_cycle_tick = get_hw_cycle_tick, .get_hw_cycle_tick_elaps = get_hw_cycle_tick_elaps, }; const aem_sys_os_ops_t *aem_get_sys_os_ops(void) { return &s_sys_os_ops; }