📄 pwr_cust.c
字号:
{
/* start ADIN2REG channel conversion by writing in the result register */
ABB_Write_Register_on_page(PAGE0, ADIN2REG, 0x0000);
rvf_start_timer (SPI_TIMER0,
RVF_MS_TO_TICKS (SPI_TIMER0_INTERVAL_1),
FALSE);
}
else /* The L1 asks for ADC conversions */
{
/* Let time for the L1 to ask for new AD conversions */
rvf_start_timer (SPI_TIMER0,
RVF_MS_TO_TICKS (SPI_TIMER0_INTERVAL_2),
FALSE);
}
}
else
{
/* The battery temp is inside the 50uA temp range */
/* Turn OFF the current source */
ABB_Write_Register_on_page(PAGE0, BCICTL1, MESBAT);
/* Go ahead */
if (pwr_env_ctrl_blk->charging_state == CI_CHARGE_STARTED)
{
/* temperature measurement during CI charge */
pwr_CI_charge_process();
}
else if (pwr_env_ctrl_blk->charging_state == CV_CHARGE_STARTED)
{
/* temperature measurement during CV charge */
pwr_CV_charge_process();
}
else if (pwr_env_ctrl_blk->charging_state == TESTING_BATTERY)
{
/* temperature measurement before calibration */
pwr_calibration_process();
}
else
{
/* temperature measurement for battery information */
pwr_get_bat_info();
}
}
}
/*******************************************************************************
** Function pwr_bat_10uA_temp_test_timer_process
**
** Description
**
**
*******************************************************************************/
void pwr_bat_10uA_temp_test_timer_process(void)
{
UINT16 bat_madc_temp;
rvf_send_trace("TIMER0: Battery 10uA temp test",30, NULL_PARAM, RV_TRACE_LEVEL_WARNING, PWR_USE_ID);
pwr_env_ctrl_blk->bat_celsius_temp = (INT16)(0xFFFF);
bat_madc_temp = ABB_Read_Register_on_page(PAGE0, ADIN2REG);
/* MADC value to Celsius degrees conversion */
if (!pwr_madc_to_Celsius_conv(THEN_10uA, bat_madc_temp, &(pwr_env_ctrl_blk->bat_celsius_temp)))
{
/* ERROR: Reading out of limits */
rvf_send_trace("Battery temperature reading out of limits", 41, NULL_PARAM, RV_TRACE_LEVEL_WARNING, PWR_USE_ID);
/* turn OFF the current source */
ABB_Write_Register_on_page(PAGE0, BCICTL1, MESBAT);
pwr_stop_charging();
/* informs the upper layer that the battery temperature is not correct */
pwr_send_charge_not_possible_event(BAT_TEMP_OUTSIDE_LIMITS);
if (SPI_GBL_INFO_PTR->is_gsm_on == FALSE) /* GSM OFF */
{
#if (ANALOG == 1)
ABB_Write_Register_on_page(PAGE0, VRPCCTL2, 0x00EE);
#elif (ANALOG == 2)
ABB_Write_Register_on_page(PAGE0, VRPCDEV, 0x0001);
#endif
}
else
{
pwr_handle_discharge();
}
}
else
{
/* The battery temperature is inside the 10uA temp range */
/* turn OFF the current source */
ABB_Write_Register_on_page(PAGE0, BCICTL1, MESBAT);
/* Go ahead */
if (pwr_env_ctrl_blk->charging_state == CI_CHARGE_STARTED)
{
/* temperature measurement during CI charge */
pwr_CI_charge_process();
}
else if (pwr_env_ctrl_blk->charging_state == CV_CHARGE_STARTED)
{
/* temperature measurement during CV charge */
pwr_CV_charge_process();
}
else if (pwr_env_ctrl_blk->charging_state == TESTING_BATTERY)
{
/* temperature measurement before calibration */
pwr_calibration_process();
}
else
{
/* temperature measurement for battery information */
pwr_get_bat_info();
}
}
}
/*******************************************************************************
** Function pwr_get_battery_type
**
** Description Return the type of the battery
**
** Note If the used battery does not allow to make a battery type
** SW detection, the body of this function can be replaced
** by the last 2 lines
**
*******************************************************************************/
void pwr_get_battery_type(void)
{
/* enable bias current for main battery type reading
ABB_Write_Register_on_page(PAGE0, BCICTL1, 0x0081);
rvf_delay(RVF_MS_TO_TICKS(5));
pwr_env_ctrl_blk->timer0_state = BATTERY_TYPE_TEST;
if (SPI_GBL_INFO_PTR->is_adc_on == FALSE)
{
/* start ADIN1REG channel conversion by writing in the result register
ABB_Write_Register_on_page(PAGE0, ADIN1REG, 0x0000);
rvf_start_timer (SPI_TIMER0,
RVF_MS_TO_TICKS (SPI_TIMER0_INTERVAL_1),
FALSE);
}
else /* The L1 asks for ADC conversions
{
/* Let time for the L1 to ask for new AD conversions
rvf_start_timer (SPI_TIMER0,
RVF_MS_TO_TICKS (SPI_TIMER0_INTERVAL_2),
FALSE);
}
*/
/****************************************/
/* If the battery can not be detected, */
/* the code above has to be replaced by */
/* those 2 lines (with the type of the */
/* used battery). */
/****************************************/
pwr_env_ctrl_blk->bat_type = LI_ION;
/* Check if the battery is OK */
pwr_battery_qualification();
}
/*******************************************************************************
** Function pwr_type_test_timer_process
**
** Description
**
**
*******************************************************************************/
void pwr_type_test_timer_process(void)
{
UINT16 bat_type_voltage;
rvf_send_trace("TIMER0: Battery type test",25, NULL_PARAM, RV_TRACE_LEVEL_WARNING, PWR_USE_ID);
bat_type_voltage = ABB_Read_Register_on_page(PAGE0, ADIN1REG);
/* turn OFF the current source */
ABB_Write_Register_on_page(PAGE0, BCICTL1, MESBAT);
if ((bat_type_voltage >= BAT_TYPE_LI_ION_MIN) &&
(bat_type_voltage <= BAT_TYPE_LI_ION_MAX)) /* Li-ion batteries */
{
pwr_env_ctrl_blk->bat_type = LI_ION;
/* Check if the battery is OK */
pwr_battery_qualification();
}
else /* battery type unknown */
{
pwr_env_ctrl_blk->bat_type = UNKNOWN;
/* informs the upper layer that the battery type is unknown */
pwr_send_charge_not_possible_event(BAT_TYPE_UNKNOWN);
if (SPI_GBL_INFO_PTR->is_gsm_on == FALSE) /* GSM OFF */
{
#if (ANALOG == 1)
ABB_Write_Register_on_page(PAGE0, VRPCCTL2, 0x00EE);
#elif (ANALOG == 2)
ABB_Write_Register_on_page(PAGE0, VRPCDEV, 0x0001);
#endif
}
else
{
pwr_handle_discharge();
}
}
}
/*******************************************************************************
** Function pwr_get_capacity_vs_voltage
**
** Description Compares the battery voltage with the thresholds given in the
** a_pwr_thresholds array and returns the remaining capacity
** corresponding to the threshold above this voltage.
**
** Parameters: UINT16 bat_voltage: battery voltage in mV !!!
**
*******************************************************************************/
T_PWR_PERCENT pwr_get_capacity_vs_voltage(UINT16 bat_voltage)
{
volatile UINT16 i;
T_PWR_PERCENT remaining_capacity;
for(i=0; i<NB_THRESHOLDS; i++)
{
if(bat_voltage > a_pwr_thresholds[i].bat_voltage)
{
if(i==0)
{
remaining_capacity = a_pwr_thresholds[0].remain_capa;
}
else
{
remaining_capacity = a_pwr_thresholds[i-1].remain_capa;
}
return (remaining_capacity);
}
/* else, try the next threshold */
}
if(i==NB_THRESHOLDS)
{
/* battery voltage below the last threshold */
remaining_capacity = a_pwr_thresholds[i-1].remain_capa;
return (remaining_capacity);
}
return 0; /* dummy return */
}
#endif /* #ifdef RVM_PWR_SWE */
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -