/**
******************************************************************************************************************************************************************************************
*@file                       cpu_sysctrl.c
*@author         
*@data                       
*@version                    v1.0
*@par Copyright(c):
*
*@par History:
*     version:author,date,desc
*     v1.0   :create this file
*
*******************************************************************************************************************************************************************************************
*/
#include "cpu_sysctrl.h"
#include "cpu_gpio.h"

/*******************************************************************************
* 函数名   : crm_cmd_periphclock.
* 说明     : sysctrl时钟门控使能
* 参数     : -crm_periph_clock,       外设时钟位选择
             -new_state,              使能或不使能,参考 functional_state_t 定义
* 返回值   : None.
* 示例     : crm_cmd_periphclock(CRM_CG_CTRL_GPIO, ENABLE );
*******************************************************************************/
void crm_cmd_periphclock(uint32_t crm_periph_clock, functional_state_t new_state)
{    
    if (new_state != DISABLE)
  {
    CRM->CG_CTRL |= crm_periph_clock;
  }
  else
  {
    CRM->CG_CTRL &= ~crm_periph_clock;
  }
    
    
    
}

/*******************************************************************************
* 函数名   : crm_reset_periph.
* 说明     : 外设软复位
* 参数     : -crm_periph_reset,      外设选择位
* 返回值   : None.
* 示例     : crm_reset_periph(CRM_CG_CTRL_BT);
*******************************************************************************/
void crm_reset_periph(uint32_t crm_periph_reset)
{
    if(crm_periph_reset)
    {
        CRM->SOFT_RST = crm_periph_reset;
    }    
}


/*******************************************************************************
* 函数名   : syscfg_deepsleep_cmd_wakeup_source.
* 说明     : sysctrl时钟深度睡眠使能唤醒源
* 参数     : -syscfg_deepsleep_wakeup_src,        唤醒源选择，参考   deepsleep_wakeup 定义
			 -new_state,                          使能或不使能,参考 functional_state_t 定义
* 返回值   : None.
* 示例     : syscfg_deepsleep_cmd_wakeup_source(SYSCFG_DeepSleepWakeUpSource_GPIO ,ENABLE);
*******************************************************************************/
void syscfg_deepsleep_cmd_wakeup_source(deepsleep_wakeup syscfg_deepsleep_wakeup_src,functional_state_t new_state)
{
	if (new_state != DISABLE)
	{
		SYSCFG->SLEEP_CTRL |= syscfg_deepsleep_wakeup_src;
	}
	else
	{
		SYSCFG->SLEEP_CTRL &= ~syscfg_deepsleep_wakeup_src;
	}
}

/*******************************************************************************
* 函数名   : syscfg_set_oscxtal_config.
* 说明     : 配置晶振匹配电容，外部无须电容
* 参数     : -xtal_cfg,        晶振匹配电容参数
* 返回值   : None.
* 示例     : syscfg_set_oscxtal_config(0x37);
*******************************************************************************/
void syscfg_set_oscxtal_config(uint8_t xtal_cfg)
{
    SYSCFG->TEST4 = 0x0000D100;
    SYSCFG->TEST4 |= xtal_cfg;
}

/************ operation definition for DMA SYSCTRL REGISTER ************/
#define SYSCTRL_PHER_CTRL_DMA_CH0_IF_Pos                    (0)
#define SYSCTRL_PHER_CTRL_DMA_CH0_IF_Mask                   (0x0FU<<SYSCTRL_PHER_CTRL_DMA_CH0_IF_Pos)

#define SYSCTRL_PHER_CTRL_DMA_CH1_IF_Pos                    (4)
#define SYSCTRL_PHER_CTRL_DMA_CH1_IF_Mask                   (0x0FU<<SYSCTRL_PHER_CTRL_DMA_CH1_IF_Pos)

#define SYSCTRL_PHER_CTRL_DMA_CH2_IF_Pos                    (8)
#define SYSCTRL_PHER_CTRL_DMA_CH2_IF_Mask                   (0x0FU<<SYSCTRL_PHER_CTRL_DMA_CH2_IF_Pos)

#define SYSCTRL_PHER_CTRL_DMA_CH3_IF_Pos                    (12)
#define SYSCTRL_PHER_CTRL_DMA_CH3_IF_Mask                   (0x0FU<<SYSCTRL_PHER_CTRL_DMA_CH3_IF_Pos)


#define SYSCTRL_PHER_CTRL_DMA_CHx_IF_UART0_TX               (0x00)
#define SYSCTRL_PHER_CTRL_DMA_CHx_IF_UART0_RX               (0x01)
#define SYSCTRL_PHER_CTRL_DMA_CHx_IF_UART1_TX               (0x02)
#define SYSCTRL_PHER_CTRL_DMA_CHx_IF_UART1_RX               (0x03)
#define SYSCTRL_PHER_CTRL_DMA_CHx_IF_SPI0_TX                (0x04)
#define SYSCTRL_PHER_CTRL_DMA_CHx_IF_SPI0_RX                (0x05)
#define SYSCTRL_PHER_CTRL_DMA_CHx_IF_SPI1_TX                (0x06)
#define SYSCTRL_PHER_CTRL_DMA_CHx_IF_SPI1_RX                (0x07)
#define SYSCTRL_PHER_CTRL_DMA_CHx_IF_I2C_TX                 (0x08)
#define SYSCTRL_PHER_CTRL_DMA_CHx_IF_I2C_RX                 (0x09)


/*******************************************************************************
* 函数名   : sysctrl_dma_channel_config.
* 说明     : DMA通道配置
* 参数     : -dma_channelx,        DMA通道选择，参考 cpu.h 定义
			 -dma_peripheral，     DMA外设选择，参考 dma_peripheral 定义
			 -dma_dir，			   传输方向，参考 dma_diriction 定义
* 返回值   : None.
* 示例     : sysctrl_dma_channel_config(DMA_Channel_0，DMA_Peripheral_UART0，DMA_RX); 配置串口0 RX DMA
*******************************************************************************/
void sysctrl_dma_channel_config(dma_type_def* dma_channelx, dma_peripheral dma_periph, dma_diriction dma_dir)
{
    uint32_t tempdma_chx_ifx = 0;
    
    if (1 == dma_dir)
    {
        switch (dma_periph)
        {
        case I2C_BASE:
            tempdma_chx_ifx = SYSCTRL_PHER_CTRL_DMA_CHx_IF_I2C_RX;      
            break;
        case UART0_BASE:
            tempdma_chx_ifx = SYSCTRL_PHER_CTRL_DMA_CHx_IF_UART0_RX;     
            break;
        case UART1_BASE: 
            tempdma_chx_ifx = SYSCTRL_PHER_CTRL_DMA_CHx_IF_UART1_RX;     
            break;
        case SPI0_BASE:
            tempdma_chx_ifx = SYSCTRL_PHER_CTRL_DMA_CHx_IF_SPI0_RX;      
            break;
        case SPI1_BASE:
            tempdma_chx_ifx = SYSCTRL_PHER_CTRL_DMA_CHx_IF_SPI1_RX;      
            break;

        }
    }
    else if (2 == dma_dir)
    {
        switch (dma_periph)
        {
        case I2C_BASE:
            tempdma_chx_ifx = SYSCTRL_PHER_CTRL_DMA_CHx_IF_I2C_TX;      
            break;
        case UART0_BASE:
            tempdma_chx_ifx = SYSCTRL_PHER_CTRL_DMA_CHx_IF_UART0_TX;     
            break;
        case UART1_BASE:
            tempdma_chx_ifx = SYSCTRL_PHER_CTRL_DMA_CHx_IF_UART1_TX;     
            break;
        case SPI0_BASE:
            tempdma_chx_ifx = SYSCTRL_PHER_CTRL_DMA_CHx_IF_SPI0_TX;      
            break;
        case SPI1_BASE:
            tempdma_chx_ifx = SYSCTRL_PHER_CTRL_DMA_CHx_IF_SPI1_TX;      
            break;

        }
    }
    if(dma_channelx == DMA_Channel_0)
    {
        SYSCFG->DMA_CH_HS &= ~SYSCTRL_PHER_CTRL_DMA_CH0_IF_Mask;
        SYSCFG->DMA_CH_HS |= tempdma_chx_ifx << SYSCTRL_PHER_CTRL_DMA_CH0_IF_Pos;
    }
    else if(dma_channelx == DMA_Channel_1)
    {
        SYSCFG->DMA_CH_HS &= ~SYSCTRL_PHER_CTRL_DMA_CH1_IF_Mask;
        SYSCFG->DMA_CH_HS |= tempdma_chx_ifx << SYSCTRL_PHER_CTRL_DMA_CH1_IF_Pos;
    }
    else if(dma_channelx == DMA_Channel_2)
    {
        SYSCFG->DMA_CH_HS &= ~SYSCTRL_PHER_CTRL_DMA_CH2_IF_Mask;
        SYSCFG->DMA_CH_HS |= tempdma_chx_ifx << SYSCTRL_PHER_CTRL_DMA_CH2_IF_Pos;
    }
    else if(dma_channelx == DMA_Channel_3)
    {
        SYSCFG->DMA_CH_HS &= ~SYSCTRL_PHER_CTRL_DMA_CH3_IF_Mask;
        SYSCFG->DMA_CH_HS |= tempdma_chx_ifx << SYSCTRL_PHER_CTRL_DMA_CH3_IF_Pos;
    }
}

/*******************************************************************************
* 函数名   : crm_get_sysclockfreq.
* 说明     : 获取系统时钟频率
* 参数     : None.
* 返回值   : -SystemCoreClock.        系统时钟   
* 示例     : crm_get_sysclockfreq();
*******************************************************************************/
uint32_t crm_get_sysclockfreq(void)
{
    return SystemCoreClock;
}



/*****************************************************************************
 函 数 名  : syscfg_cpusleep_cmd_wakeup_src
 功能描述  : 唤醒浅睡眠低功耗的唤醒源
 输入参数  :  -syscfg_wakeup_src   :唤醒源 参考定义 wakeup_mcu_type
 			  -new_state ：         使能或不使能，参考定义 functional_state_t
 输出参数  : 无
* 返回值   : None.
* 示例     : syscfg_cpusleep_cmd_wakeup_src(src_int0_wakeup_mcu,ENABLE); 使能第一组gpio唤醒源
*****************************************************************************/
void syscfg_cpusleep_cmd_wakeup_src(wakeup_mcu_type syscfg_wakeup_src, functional_state_t new_state)
{   
    if (new_state != DISABLE)
  	{
    	SYSCFG->WAKE_MCU_CTRL |= syscfg_wakeup_src;
  	}
  	else
  	{
    	SYSCFG->WAKE_MCU_CTRL &= ~syscfg_wakeup_src;
  	}
}

/*******************************************************************************
* 函数名   : syscfg_deepsleep_set_mode.
* 说明     : 设置sysctrl深度休眠模式
* 参数     : -syscfg_deepsleep_mode 	休眠模式 参考定义 deepsleep_mode
* 返回值   : None.
* 示例     : syscfg_deepsleep_set_mode(SYSCFG_DeepSleepMode_DEEPSLEEP); 配置deepsleep 模式
*******************************************************************************/
void syscfg_deepsleep_set_mode(deepsleep_mode syscfg_deepsleep_mode)
{
    SYSCFG->SLEEP_CTRL &= ~SYSCFG_SLEEP_CTRL_deep_slp_sel;
    SYSCFG->SLEEP_CTRL |= syscfg_deepsleep_mode;
}

/*******************************************************************************
* 函数名   : syscfg_deepsleep_set_ram_retention.
* 说明     : 设置深度休眠Retention_SRAM大小
* 参数     : -retention_sram_x 		Retention_SRAM大小
* 返回值   : None.
* 示例     : syscfg_deepsleep_set_ram_retention(SYSCFG_Retention_Sram_16k); 配置16K保留内存的方式
*******************************************************************************/
void syscfg_deepsleep_set_ram_retention(deep_sleep_retain retention_sram_x)
{
	if(SYSCFG_noRetention_Sram == retention_sram_x)
		return;
	
	SYSCFG->SLEEP_CTRL &= ~SYSCFG_SLEEP_CTRL_sram_ret_sel;
	SYSCFG->SLEEP_CTRL |= retention_sram_x;
}

/*******************************************************************************
* 函数名   : syscfg_deepsleep_set_gpiopin_wakeup_src.
* 说明     : 设置深度休眠唤醒gpio引脚
* 参数     : -syscfg_gpio_wakeup_source 		gpio唤醒源
			 -syscfg_gpio_wakeup_type			gpio唤醒类型
			 -syscfg_gpiox_pinx					gpio引脚
* 返回值   : None.
* 示例     : syscfg_deepsleep_set_gpiopin_wakeup_src(GPIO_Int0,WakeUpType_32K_AntiShake,GPIOB_Pin2); 选择第0组中断，配置PB2 经过滤波唤醒
*******************************************************************************/
void syscfg_deepsleep_set_gpiopin_wakeup_src(irq_bank syscfg_gpio_wakeup_source,gpio_wk_type syscfg_gpio_wakeup_type,gpio_pin syscfg_gpiox_pinx)
{
    uint32_t idx = syscfg_gpio_wakeup_source - GPIO_Int0;
    uint32_t mask = (0x03U)<<(idx*8);
    SYSCFG->WKUP_TYPE &= ~mask;
    SYSCFG->WKUP_TYPE |= (syscfg_gpio_wakeup_type<<(idx*8));
    
    mask = (0x1fU)<<(idx*8);
    SYSCFG->WKUP_SRC  &= ~mask;
    SYSCFG->WKUP_SRC  |= (syscfg_gpiox_pinx<<(idx*8));
}


/*******************************************************************************
* 函数名   : syscfg_deepsleep_set_gpiopin_wakeup_src.
* 说明     : 设置深度休眠唤醒gpio引脚
* 参数     : -syscfg_gpio_wakeup_source 		gpio唤醒源
			 -syscfg_gpio_wakeup_type			gpio唤醒类型
			 -syscfg_gpiox_pinx					gpio引脚
* 返回值   : None.
* 示例     : syscfg_deepsleep_set_gpiopin_wakeup_src(SYSCFG_GPIOWakeUpSource_GPIO_INT0,SYSCFG_GPIOWakeUpType_One32KCycle_AntiShake,SYSCFG_GPIOB_Pin2);
*******************************************************************************/
void deepsleep_set_wakeup_gpio(irq_bank wakeup_bank,gpio_wk_type wakeup_type,gpio_irq_type irq_type,gpio_pin gpiox_pinx)
{
    uint32_t idx = wakeup_bank - GPIO_Int0;
    uint32_t mask = (0x03U)<<(idx*8);

// =======================配置唤醒源=====================================================	
    SYSCFG->WKUP_TYPE &= ~mask;
    SYSCFG->WKUP_TYPE |= (wakeup_type<<(idx*8));
    
    mask = (0x1fU)<<(idx*8);
    SYSCFG->WKUP_SRC  &= ~mask;
	
	if(WakeUpType_Disable != wakeup_type)
	{
    	SYSCFG->WKUP_SRC  |= (gpiox_pinx<<(idx*8));
	}
	
// =======================配置中断源=====================================================	
	mask = (0x03U)<<(idx*8);
	GPIO_MODULE->INTP_TYPE &= ~mask;
	
	if(WakeUpType_Disable != wakeup_type)
	{
		GPIO_MODULE->INTP_TYPE |= (irq_type<<(idx*8));
	}

	mask = (0x1fU)<<(idx*8);
	GPIO_MODULE->INTP_SRC  &= ~mask;
	
	if(WakeUpType_Disable != wakeup_type)
	{
		GPIO_MODULE->INTP_SRC  |= (gpiox_pinx<<(idx*8));
	}
}


/*******************************************************************************
* 函数名   : syscfg_external_16M_xtal.
* 说明     : 外部16M晶振设置
* 参数     : None.		
* 返回值   : None.
* 示例     : syscfg_external_16M_xtal();
*******************************************************************************/
void syscfg_external_16M_xtal(void)
{
    /* 16M xtal, hclk=Xtal, pclk = hclk, bt_core = hclk */
    SYSCFG->HFCLK_SEL |= (BIT9 + BIT0);         
    SYSCFG->HFCLK_SEL &= ~(BIT8 + BIT1);
    SYSCFG->FREQ_SEL = 0; 
}

/*******************************************************************************
* 函数名   : syscfg_external_32M_xtal.
* 说明     : 外部32M晶振设置
* 参数     : None.		
* 返回值   : None.
* 示例     : syscfg_external_32M_xtal();
*******************************************************************************/
void syscfg_external_32M_xtal(void)
{
    /* 32M xtal , hclk=Xtal,  pclk = hclk/2, bt_core = hclk/2 */
    SYSCFG->HFCLK_SEL |= (BIT9 + BIT0 + BIT1);
    SYSCFG->HFCLK_SEL &= ~BIT8;
    SYSCFG->FREQ_SEL = (BIT2 + BIT4);
}

/*******************************************************************************
* 函数名   : syscfg_external_32k_xtal.
* 说明     : 外部32K晶振设置
* 参数     : None.		
* 返回值   : None.
* 示例     : syscfg_external_32k_xtal();
*******************************************************************************/
void syscfg_external_32k_xtal(void)
{
    SYSCFG->LFCLK_SEL |= (BIT9 + BIT0);
    SYSCFG->LFCLK_SEL &= ~BIT8; 
}

/*******************************************************************************
* 函数名   : syscfg_internal_32k_rc.
* 说明     : 内部32K RC时钟设置
* 参数     : None.		
* 返回值   : None.
* 示例     : syscfg_internal_32k_rc();
*******************************************************************************/
void syscfg_internal_32k_rc(void)
{
    SYSCFG->LFCLK_SEL |= BIT8;
    SYSCFG->LFCLK_SEL &= ~(BIT9 + BIT0);    
}

/*******************************************************************************
* 函数名   : syscfg_calib32k.
* 说明     : 内部32K RC时钟设置
* 参数     : -cnt32k 			
			 -cnt16m		

* 返回值   : None.
* 示例     : syscfg_calib32k();
*******************************************************************************/
uint32_t  syscfg_calib32k(uint32_t cnt32k,uint32_t * cnt16m)
{   
    syscfg_internal_32k_rc();
    SYSCFG->TEST4 |= BIT12;    
    SYSCFG->CNT32K_VAL = 0;
    SYSCFG->CNT32K_VAL |= (0x07000000 & (cnt32k<<24));
    SYSCFG->CNT32K_VAL |= BIT27;
	for(uint32_t i = 0;i < 100;i++);
	while(SYSCFG->CNT32K_VAL & BIT27);
    *cnt16m = SYSCFG->CNT32K_VAL & 0x001fffff;

    return TRUE;
}


/*******************************************************************************
* 函数名   : syscfg_calib32k_start.
* 说明     : 启动32K时钟校准
* 参数     : -cnt32k 			
			 -cnt16m		

* 返回值   : None.
* 示例     : syscfg_calib32k_start();
*******************************************************************************/
void  syscfg_calib32k_start(uint32_t cnt32k)
{   
    syscfg_internal_32k_rc();
    SYSCFG->TEST4 |= BIT12;        
    SYSCFG->CNT32K_VAL = 0;
    SYSCFG->CNT32K_VAL |= (0x07000000 & (cnt32k<<24));
    SYSCFG->CNT32K_VAL |= BIT27;

}

uint32_t  syscfg_calib32k_check_end(void)
{   
    if(SYSCFG->CNT32K_VAL & BIT27)
    {
        return 0;
    }

    return SYSCFG->CNT32K_VAL & 0x001fffff;
}

/*****************************************************************************
 函 数 名  : rc_get_32k_rtc_value
 功能描述  : 获取内部rtc 秒值
 参数      : uint32_t cnt32k  
 输出参数  : 无
 返 回 值  : 
 示例      : 
*****************************************************************************/
uint32_t rc_get_32k_rtc_value(uint32_t cnt32k)
{
	uint32_t cnt16m = 0;
	uint32_t freq = 0;
	uint32_t cnt32ktable[8]={32,64,128,256,512,1024,2048,2048};
	if(syscfg_calib32k(cnt32k,&cnt16m)){
		freq = cnt32ktable[cnt32k] * 16000000.0/cnt16m;
		return freq;	
	}
	return 0;
}


/*******************************************************************************
* 函数名   : syscfg_calib32k_start.
* 说明     : 切换深度低功耗唤醒源
* 参数     : -deepsleep_wakeup_src 		唤醒源，参考 deepsleep_wakeup	
			 -p_param						
			 		0:		独立唤醒源，			关闭其它唤醒源
					1:		保持蓝牙唤醒源			
					2:		仅仅改变当前的唤醒源
			 -new_state      使能或不使能，参考定义 functional_state_t
* 返回值   : None.
* 示例     : syscfg_calib32k_start();
* fix note 测试
*******************************************************************************/
void deepsleep_wakeup_source_config(deepsleep_wakeup deepsleep_wakeup_src,uint32_t p_param,functional_state_t new_state)
{
//  仅能配置 电源常开域外设
	switch(deepsleep_wakeup_src){
		case src_deep_sleep_ctrl_gpio_wk_en:
//		参数说明 p_param：唤醒类型 取值范围
/*
		0:		独立唤醒源，			关闭其它唤醒源
		1:		保持蓝牙唤醒源			
		2:		仅仅改变当前的唤醒源
*/
			if(p_param == 0){
				SYSCFG->SLEEP_CTRL &= ~(0x0F << 8);
				SYSCFG->SLEEP_CTRL |= src_deep_sleep_ctrl_ble_extwkupdsb;	//禁用蓝牙唤醒
				if (new_state != DISABLE)
				{
					SYSCFG->SLEEP_CTRL |= deepsleep_wakeup_src;
				}
				else
				{
					SYSCFG->SLEEP_CTRL &= ~deepsleep_wakeup_src;
				}
			}else if(p_param == 1){
				SYSCFG->SLEEP_CTRL &= ~(0x0F << 8);						 	//允许蓝牙唤醒
				SYSCFG->SLEEP_CTRL &= ~deepsleep_wakeup_src;
			}else if(p_param == 2){
				if (new_state != DISABLE)
				{
					if(SYSCFG->SLEEP_CTRL & src_deep_sleep_ctrl_ble_extwkupdsb){
						return;
					}
					SYSCFG->SLEEP_CTRL |= deepsleep_wakeup_src;
				}
				else
				{
					SYSCFG->SLEEP_CTRL &= ~deepsleep_wakeup_src;
				}
			}
			break;
		case src_deep_sleep_ctrl_ble_extwkupdsb:
		case src_deep_sleep_kpc_wk_en:
		case src_deep_sleep_rtc_wk_en:
	//		参数说明 p_param：唤醒类型 取值范围
	/*
			0:		独立唤醒源，			关闭其它唤醒源
			1:		保持蓝牙唤醒源			
			2:		仅仅改变当前的唤醒源
	*/
			if(p_param == 0){
				SYSCFG->SLEEP_CTRL &= ~(0x0F << 8);
				SYSCFG->SLEEP_CTRL |= src_deep_sleep_ctrl_ble_extwkupdsb;	//禁用蓝牙唤醒
				if (new_state != DISABLE)
				{
					SYSCFG->SLEEP_CTRL |= deepsleep_wakeup_src;
				}
				else
				{
					SYSCFG->SLEEP_CTRL &= ~deepsleep_wakeup_src;
				}
			}else if(p_param == 1){
				SYSCFG->SLEEP_CTRL &= ~(0x07 << 8);
				if (new_state != DISABLE)
				{
					SYSCFG->SLEEP_CTRL |= deepsleep_wakeup_src;
				}
				else
				{
					SYSCFG->SLEEP_CTRL &= ~deepsleep_wakeup_src;
				}
			}else if(p_param == 2){
				if (new_state != DISABLE)
				{
					SYSCFG->SLEEP_CTRL |= deepsleep_wakeup_src;
				}
				else
				{
					SYSCFG->SLEEP_CTRL &= ~deepsleep_wakeup_src;
				}
			}
	}
}

void mcu_osc_configure(void)
{
	*(uint32_t volatile *)0x40000220 = 0x024D415E;
	*(uint32_t volatile *)0x40000224 = 0x96000000;
	*(uint32_t volatile *)0x40000228 = 0x0400000A;
	*(uint32_t volatile *)0x4000022C = 0x07FC7E0E;
	
	*(uint32_t volatile *)0x40000230 = 0x01446438;
	*(uint32_t volatile *)0x4000023C = 0x00420C2C;

	*(uint32_t volatile *)0x40000200 = 0x08034014;
	*(uint32_t volatile *)0x40000204 = 0xD840DA7A;
	*(uint32_t volatile *)0x40000208 = 0x00600002;
	*(uint32_t volatile *)0x4000020C = 0x91517F6B;
	*(uint32_t volatile *)0x400002A0 = 0x500086B9;

	*(uint32_t volatile *)0x400001D0 |= BIT3;

	SYSCFG->TEST2 |= BIT8 + BIT21 + BIT22;
	SYSCFG->TEST3 |= 0x51A00000;

	SYSCFG->DEV_PARAM 			= 0x00594001;
	SYSCFG->RSSI_TEM_CAL 		= 0x002C200E;
	SYSCFG->RSSI_RFGAIN_ERR1	= 0x1E1D191D;
	SYSCFG->RSSI_RFGAIN_ERR2 	= 0x10010617;
}

