/**
 * \file    sys_low_power.h
 * \brief   System low power control header file
 * 
 * \par     Copyright (c) 2018 UWE Technologies Corp., Ltd. All Rights Reserved.
 * \author  James
 * \date    2018-03-29
 * \version 
 * 
 * \history 
 *  Date        Note
 *  2018-03-29  Original Creation
 * 
 */
 
#ifndef __SYS_LOW_POWER_H_
#define __SYS_LOW_POWER_H_

#include "arch.h"
#include "types.h"

#if LOW_POWER_ENABLED

/** \brief Initialize low power mode
 */
void sys_lpm_init(void);

/** \brief Activate system to avoid system sleep
 */
void sys_lpm_activate(void);

/** \brief Configure on wakeup handler
 *
 * The on_wakeup_handler will be called when system wake up, 
 * need to be configured before sys_lpm_init
 *
 * \param on_wakeup_handler   On wake up handler
 */
void sys_lpm_on_wakeup_handler_set(bool_t (*on_wakeup_handler)(void));

/** \brief Configure on sleep handler
 *
 * The on_sleep_handler will be called when system is going to sleep, 
 * if executes on_sleep_handler return FALSE, system will not go to sleep
 *
 * \param on_sleep_handler   On sleep handler
 */
void sys_lpm_on_sleep_handler_set(bool_t (*on_sleep_handler)(void));

/** \brief Configure idle hold time
 *
 * \param time      IDLE hold time
 */
void sys_lpm_idle_hold_time_set(u32_t time);

/** \brief Check whether system is running, system will go to sleep if 
 * there is no action in idle hold time
 */
sys_tick_t sys_lpm_get(void);

void sys_state_check_and_sleep(void);
#else
#define sys_lpm_init()
#define sys_lpm_activate()
#define sys_lpm_on_wakeup_handler_set(cb)
#define sys_lpm_on_sleep_handler_set(cb)
#define sys_lpm_idle_hold_time_set(v)
#define sys_state_check_and_sleep()
#endif /* LOW_POWER_ENABLED */


#endif /* #ifndef __SYS_LOW_POWER_H_ */

