/** ##########################################################################
**     Filename  : system_voltage_manage_cfg.c
**     Project   :
**     Module    :
**     Processor :
**     Version   : 1.0
**     Compiler  :
**     Date/Time :
**     Abstract  :
**     Contents  :
**     Note      :
**     (c) Copyright dmdz Co.,Ltd
**  --------------------------------------------------------------------------
**               R E V I S I O N   H I S T O R Y
**  --------------------------------------------------------------------------
**  Date        Ver      Author             Description

**  -20230620-  V01-- --Linboyi---            --初版--
** #########################################################################*/



/*****************************************************************************
* I N C L U D E   F I L E S
*****************************************************************************/
#include "system_voltage_manage_cfg.h"


/*****************************************************************************
* D E F I N E S / M A C R O S
*****************************************************************************/
#define NUM_OF_SYSTEM_VOLTAGE_CLASS  3u


#define SYSTEM_VOLTAGE_MANAGE_MV(a)       (a)
#define SYSTEM_VOLTAGE_MANAGE_DEBOUNCE_TIME(a)  (a /  SYSTEM_VOLTAGE_MANAGE_TASK_CYCLE_TIME)
/*****************************************************************************
* T Y P E   D E F I N I T I O N S
*****************************************************************************/
typedef struct
{
    uint8_t u8state;
    uint16_t u16min;
    uint16_t u16max;
    uint16_t u16debounce_time;
}system_voltage_manage_cfg_s;

/*****************************************************************************
* G L O B A L   V A R I A B L E S
* only configuration table allowed here,variables are not allowed!
*****************************************************************************/


/*****************************************************************************
* C O N S T A N T S
*****************************************************************************/
const static system_voltage_manage_cfg_s gs_system_voltage_manage_cfg[NUM_OF_SYSTEM_VOLTAGE_MANAGE][NUM_OF_SYSTEM_VOLTAGE_CLASS] =
{
    /* 功能电压等级管理 */
    {
        {SYSTEM_VOLTAGE_MODE_NORMAL, SYSTEM_VOLTAGE_MANAGE_MV(9000), SYSTEM_VOLTAGE_MANAGE_MV(16000),SYSTEM_VOLTAGE_MANAGE_DEBOUNCE_TIME(500)},
        {SYSTEM_VOLTAGE_MODE_LOW,    SYSTEM_VOLTAGE_MANAGE_MV(0),    SYSTEM_VOLTAGE_MANAGE_MV(8500), SYSTEM_VOLTAGE_MANAGE_DEBOUNCE_TIME(500)},
        {SYSTEM_VOLTAGE_MODE_HIGH,   SYSTEM_VOLTAGE_MANAGE_MV(16500),SYSTEM_VOLTAGE_MANAGE_MV(0xffffu),SYSTEM_VOLTAGE_MANAGE_DEBOUNCE_TIME(500)},
    },
     /* DTC电压等级管理 */
    {
        {SYSTEM_VOLTAGE_MODE_NORMAL, SYSTEM_VOLTAGE_MANAGE_MV(6000), SYSTEM_VOLTAGE_MANAGE_MV(18000),SYSTEM_VOLTAGE_MANAGE_DEBOUNCE_TIME(500)},
        {SYSTEM_VOLTAGE_MODE_LOW,    SYSTEM_VOLTAGE_MANAGE_MV(0),    SYSTEM_VOLTAGE_MANAGE_MV(5500), SYSTEM_VOLTAGE_MANAGE_DEBOUNCE_TIME(500)},
        {SYSTEM_VOLTAGE_MODE_HIGH,   SYSTEM_VOLTAGE_MANAGE_MV(18500),SYSTEM_VOLTAGE_MANAGE_MV(0xffffu),SYSTEM_VOLTAGE_MANAGE_DEBOUNCE_TIME(500)},
    },
    /* 通讯电压等级管理 */
    {
        {SYSTEM_VOLTAGE_MODE_NORMAL, SYSTEM_VOLTAGE_MANAGE_MV(7000), SYSTEM_VOLTAGE_MANAGE_MV(17500),SYSTEM_VOLTAGE_MANAGE_DEBOUNCE_TIME(500)},
        {SYSTEM_VOLTAGE_MODE_LOW,    SYSTEM_VOLTAGE_MANAGE_MV(0),    SYSTEM_VOLTAGE_MANAGE_MV(6500), SYSTEM_VOLTAGE_MANAGE_DEBOUNCE_TIME(500)},
        {SYSTEM_VOLTAGE_MODE_HIGH,   SYSTEM_VOLTAGE_MANAGE_MV(18000),SYSTEM_VOLTAGE_MANAGE_MV(0xffffu),SYSTEM_VOLTAGE_MANAGE_DEBOUNCE_TIME(500)},
    }
};



/*****************************************************************************
|Prototype			: system_voltage_cfg_min_get
|Called by			:
|Preconditions		:
|Input parameters	:
|Output parameters	:
|Return value		:
|Description		:
*****************************************************************************/
uint16_t system_voltage_cfg_min_get(uint8_t system_voltage_manage_id, uint8_t system_voltage_mode_id)
{
    uint16_t temp;

    temp = gs_system_voltage_manage_cfg[system_voltage_manage_id][system_voltage_mode_id].u16min;

    return (temp);
}


/*****************************************************************************
|Prototype			: system_voltage_cfg_max_get
|Called by			:
|Preconditions		:
|Input parameters	:
|Output parameters	:
|Return value		:
|Description		:
*****************************************************************************/
uint16_t system_voltage_cfg_max_get(uint8_t system_voltage_manage_id, uint8_t system_voltage_mode_id)
{
    uint16_t temp;

    temp = gs_system_voltage_manage_cfg[system_voltage_manage_id][system_voltage_mode_id].u16max;

    return (temp);
}


/*****************************************************************************
|Prototype			: system_voltage_cfg_debounce_time_get
|Called by			:
|Preconditions		:
|Input parameters	:
|Output parameters	:
|Return value		:
|Description		:
*****************************************************************************/
uint16_t system_voltage_cfg_debounce_time_get(uint8_t system_voltage_manage_id, uint8_t system_voltage_mode_id)
{
    uint16_t temp;

    temp = gs_system_voltage_manage_cfg[system_voltage_manage_id][system_voltage_mode_id].u16debounce_time;

    return (temp);
}



/*****************************************************************************
|Prototype          : system_voltage_cfg_get_sys_power
|Called by          :
|Preconditions      :
|Input parameters   :
|Output parameters  :
|Return value       :
|Description        :
*****************************************************************************/
#if (SYSTEM_VOLTAGE_MANAGE_DEBUG_EN == 1u)
u16 g_adc_sys_power = 16500u;
uint16_t system_voltage_cfg_get_sys_power(void)
{
    return g_adc_sys_power;  //实际调用，ADC的 系统电压接口
}
#endif