123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216 |
- #include "aem_os_dev.h"
- #include "aem_log.h"
- #ifdef CONFIG_SYS_WAKELOCK
- #include <sys_wakelock.h>
- #include <sys_manager.h>
- #endif
- #include <power_manager.h>
- #include "sys_manager.h"
- #include <soc.h>
- 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;
- }
|