/* * Copyright (c) 2006-2022, RT-Thread Development Team * * SPDX-License-Identifier: Apache-2.0 * * Change Logs: * Date Author Notes * 2021-10-13 AisinoChip first add to bsp */ #include "board.h" #include #if defined(RT_USING_PM) #define IWDT_SRC_CLK 32000 #define IWDT_CLK_PRESCALER IWDT_CLOCK_PRESCALER_32 #define IWDT_CLK (IWDT_SRC_CLK / (4<parent.user_data); if(timeout != RT_TICK_MAX) { tick = get_pm_tick_from_os_tick(timeout); phiwdt->Instance = IWDT; phiwdt->Init.Prescaler = IWDT_CLK_PRESCALER; phiwdt->Init.Reload = tick; phiwdt->Init.Window = tick; /* window function disabled when window >= reload */ phiwdt->Init.Wakeup = tick - 1; /* wakeup function disabled when wakeup >= reload */ HAL_IWDT_Init(phiwdt); } } static void _pm_timer_stop(struct rt_pm *pm) { RT_ASSERT(pm != RT_NULL); IWDT_HandleTypeDef *phiwdt = (IWDT_HandleTypeDef *)(pm->parent.user_data); phiwdt->Instance->CMDR = 0xFFFF; } static rt_tick_t _pm_timer_get_tick(struct rt_pm *pm) { rt_tick_t tick; RT_ASSERT(pm != RT_NULL); return get_os_tick_from_pm_tick(tick); } static const struct rt_pm_ops _pm_ops = { _pm_sleep, _pm_run, _pm_timer_start, _pm_timer_stop, _pm_timer_get_tick }; /** * This function initialize the power manager */ int drv_pm_hw_init(void) { rt_uint8_t timer_mask = 0; /* initialize timer mask */ timer_mask = (1UL << PM_SLEEP_MODE_DEEP) | (1UL << PM_SLEEP_MODE_STANDBY); /* initialize system pm module */ rt_system_pm_init(&_pm_ops, timer_mask, &hiwdt); return 0; } INIT_BOARD_EXPORT(drv_pm_hw_init); #endif /* RT_USING_PM */