Files
kunlun/plc/halmac/inc/mac_pm.h
2024-09-28 14:24:04 +08:00

155 lines
4.8 KiB
C
Executable File

/****************************************************************************
Copyright(c) 2019 by Aerospace C.Power (Chongqing) Microelectronics. ALL RIGHTS RESERVED.
This Information is proprietary to Aerospace C.Power (Chongqing) Microelectronics and MAY NOT
be copied by any method or incorporated into another program without
the express written consent of Aerospace C.Power. This Information or any portion
thereof remains the property of Aerospace C.Power. The Information contained herein
is believed to be accurate and Aerospace C.Power assumes no responsibility or
liability for its use in any way and conveys no license or title under
any patent or copyright and makes no representation or warranty that this
Information is free from patent or copyright infringement.
****************************************************************************/
#ifndef MAC_PM_H
#define MAC_PM_H
/* os shim includes */
#include "os_types.h"
#include "os_timer_api.h"
#include "iot_config.h"
#ifdef __cplusplus
extern "C" {
#endif
/* wake up to 75M or sleep to 25M */
#define DEEP_SLEEP_LEVEL_1 1
/* wake up to 150M */
#define DEEP_SLEEP_LEVEL_2 2
#define MAX_SLEEP_PERIOD_CNT 2
/* mac pm request awake module id */
#define MAC_PM_INIT_MODULE_ID (0x1 << 2)
#define MAC_PM_SCAN_MODULE_ID (0x1 << 3)
#define MAC_PM_UPLAYER_DEMAND_MODULE_ID (0x1 << 4)
#define MAC_PM_CERT_TEST_MODULE_ID (0x1 << 5)
#define MAC_HP_FOR_PWROFF (20000) // unit 1ms, 20 * 1000ms
typedef union _pm_status {
/* the union is intended, if fc ok received
* the bitmap would be also set, which makes
* pm stay awake.
*/
uint32_t bitmap;
uint32_t fc_ok_found : 1,
band_select_ok : 1,
/*
* NOTE: bitmap usage should not conflict
* with fc_ok_found and band_select_ok
* please refer to MAC_PM_INIT_MODULE_ID
* and MAC_PM_SCAN_MODULE_ID
* and MAC_PM_UPLAYER_DEMAND_MODULE_ID
*/
resv : 30;
} pm_status_t;
typedef enum {
DEEP_SLEEP,
WAKE_UP,
} PM_STATUS;
typedef struct _mac_pm {
uint8_t is_start : 1,
power_off_high_power : 1,
fc_ok_pm : 1,
is_check_freq : 1,
/* 1: some time off rf state, 0: normal state */
pm_war_state : 1,
resv : 3;
uint8_t mac_pm_flag; //flag for power off
uint8_t cur_status; //0 wake up, 1 sleep
uint8_t is_sleep_wakeup_valid; //0: sleep wakeup msg invalid,
uint32_t sleep_time_ms;
uint32_t wake_time_ms;
timer_id_t sleep_timer; //unit ms
timer_id_t pwroff_timer;
/* mac pm anchor timestamp */
uint32_t mac_pm_anchor_ts;
} mac_pm_t;
/**
* @brief the cb for prower off, notice mac msg. see
* iot_plc_pm_listener_func_t for more detail info.
* @param arg [arg]
* @param data [data]
* @return [none]
*/
void mac_pm_rx_power_off(uint32_t arg, uint32_t data);
/**
*@brief mac_pm_rx_power_off_internal to handle power off
*@param uint8_t pdev_id [pdev id]
*@param uint8_t vdev_id [vdev id]
*@return [done]
*/
uint32_t mac_pm_rx_power_off_internal(uint8_t pdev_id, uint8_t vdev_id);
/**
*@brief mac_pm_power_recover_internal to handle power recover
*@param uint8_t pdev_id [pdev id]
*@param uint8_t vdev_id [vdev id]
*@return [done]
*/
uint32_t mac_pm_power_recover_internal(uint8_t pdev_id, uint8_t vdev_id);
uint32_t mac_pm_init(void *pdev_in);
uint32_t mac_pm_start(void *pdev_in);
uint32_t mac_pm_stop(void *pdev_in);
void deep_sleep();
void mac_pm_init_wake_up();
uint32_t sleep(uint8_t sleep_level);
#if PM_USE_DSR
void mac_pm_dsr_sleep_cfg(void);
#else
uint32_t sleep_cfg_internal(void *arg);
#endif
uint32_t req_stay_awake(uint32_t module, uint32_t req_awake);
/**
*@brief low_pwr_for_powroff_cfg to handle power off, change tx power to
* low value when timer fired
*@param uint8_t timer_id [timer id]
*@param uint8_t arg [pdev ptr]
*@return [none]
*/
void low_pwr_for_powroff_cfg(timer_id_t timer_id, void * arg);
void low_pwr_for_powroff_cfg_internal(timer_id_t timer_id, void * arg);
/**
*@brief mac_pm_switch_by_fc_ok switch pm by fc ok
*@param mac_addr [mac addr]
*@return ret [1: on pm, 0: off pm]
*/
uint32_t mac_pm_switch_by_fc_ok(uint8_t *mac_addr);
/**
*@brief mac_pm_check_freq. mac pm check freq.
*
*@param cb [void]
*@exception [void]
*@return [void]
*/
void mac_pm_check_freq();
#ifdef __cplusplus
}
#endif
#endif