⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 pwr_liion_cha.c

📁 是一个手机功能的模拟程序
💻 C
📖 第 1 页 / 共 2 页
字号:
      /* informs the upper layer that the open test has failed */
      pwr_send_charge_not_possible_event(BAT_OPEN_TEST_FAILED);
      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 Name: pwr_cal_timer_process                                      */
/*                                                                              */
/*    Purpose:                                                                  */ 
/*                                                                              */
/*                                                                              */
/********************************************************************************/
void pwr_cal_timer_process(void)
{
   rvf_send_trace("TIMER0: Battery calibration",27, NULL_PARAM, RV_TRACE_LEVEL_WARNING, PWR_USE_ID);

   pwr_env_ctrl_blk->i2v_madc_offset = ABB_Read_Register_on_page(PAGE0, ICHGREG);

   rvf_send_trace("i2v offset (MADC code) ", 23, pwr_env_ctrl_blk->i2v_madc_offset, RV_TRACE_LEVEL_DEBUG_LOW, PWR_USE_ID);
   pwr_stop_charging();

#if (ANALOG == 2)
   if (pwr_env_ctrl_blk->i2v_madc_offset == 0)
   {
   /* IOTA: the offset can be made positive and minimized programming */
   /* the OFFEN and OFFSN bits in the BCICONF register */
      ABB_Write_Register_on_page(PAGE1, BCICONF, 0x001F);
      pwr_current_loop_cal();
   }
   else
   {
      /* the i2v calibration must be done before this initialization */
      pwr_env_ctrl_blk->madc_eoc_current_code = (UINT16)(1000 * END_OF_CHARGE_I / MADC_CURRENT_STEP) + pwr_env_ctrl_blk->i2v_madc_offset;

      rvf_send_trace("End of charge current (MADC code) ", 34, pwr_env_ctrl_blk->madc_eoc_current_code, RV_TRACE_LEVEL_DEBUG_LOW, PWR_USE_ID); 

      /* Start the fast charging cycle */
      pwr_start_fast_charge();
   }

#elif (ANALOG == 1)
   /* the i2v calibration must be done before this initialization */
   pwr_env_ctrl_blk->madc_eoc_current_code = (UINT16)(1000 * END_OF_CHARGE_I / MADC_CURRENT_STEP) + pwr_env_ctrl_blk->i2v_madc_offset;

   rvf_send_trace("End of charge current (MADC code) ", 34, pwr_env_ctrl_blk->madc_eoc_current_code, RV_TRACE_LEVEL_DEBUG_LOW, PWR_USE_ID); 

   /* Start the fast charging cycle */
   pwr_start_fast_charge();

#endif /* #if (ANALOG == 2) */
}




/********************************************************************************/
/*                                                                              */
/*    Function Name: pwr_CI_charge_process                                      */
/*                                                                              */
/*    Purpose:                                                                  */ 
/*                                                                              */
/*                                                                              */
/********************************************************************************/
void pwr_CI_charge_process(void)
{
   UINT16 vbat;
   UINT16 ichg;

   /* Check if the battery temperature is still correct */
   if (pwr_bat_temp_within_limits(pwr_env_ctrl_blk->bat_celsius_temp))
   {
      if (SPI_GBL_INFO_PTR->is_adc_on == FALSE)
      {
         /* start VBAT channel conversion by writing in the result register */
         ABB_Write_Register_on_page(PAGE0, VBATREG, 0x0000);
         rvf_delay(RVF_MS_TO_TICKS(5));
         vbat = ABB_Read_Register_on_page(PAGE0, VBATREG);
      }
      else
      {
         /* Use the ADC conversions results from the L1 */
         vbat = SPI_GBL_INFO_PTR->adc_result[0];
      }

      rvf_send_trace("TIMER1", 6, NULL_PARAM, RV_TRACE_LEVEL_WARNING, PWR_USE_ID);
      rvf_send_trace("Vbat (MADC code) ", 17, vbat, RV_TRACE_LEVEL_DEBUG_LOW, PWR_USE_ID); 

      if (vbat < pwr_env_ctrl_blk->max_voltage_code)
      {
         rvf_start_timer (SPI_TIMER1, RVF_MS_TO_TICKS (SPI_TIMER1_INTERVAL), FALSE);
      }
      else
      {
         pwr_stop_charging();
         pwr_send_CV_charge_start_event();
         pwr_start_CV_charging(CONSTANT_VOLTAGE_VALUE);
         rvf_start_timer (SPI_TIMER2, RVF_MS_TO_TICKS (SPI_TIMER2_INTERVAL), FALSE);
      }

      if (SPI_GBL_INFO_PTR->is_adc_on == FALSE)
      {
         /* start ICHG channel conversion  by writing in the result register */
         ABB_Write_Register_on_page(PAGE0, ICHGREG, 0x0000);
         rvf_delay(RVF_MS_TO_TICKS(5));
         ichg = ABB_Read_Register_on_page(PAGE0, ICHGREG);
      }
      else
      {
         ichg = SPI_GBL_INFO_PTR->adc_result[2];
      }

      rvf_send_trace("Ichg (MADC code) ", 17, ichg, RV_TRACE_LEVEL_DEBUG_LOW, PWR_USE_ID); 
   }

   else /* battery temperature not correct !!! */
      {
         pwr_stop_charging();
         rvf_send_trace("Battery temperature not correct! ",33, NULL_PARAM, RV_TRACE_LEVEL_WARNING, PWR_USE_ID); 

         /* 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();
         }
      }
   }




/********************************************************************************/
/*                                                                              */
/*    Function Name: pwr_CI_charge_timer_process                                */
/*                                                                              */
/*    Purpose:                                                                  */ 
/*                                                                              */
/*                                                                              */
/********************************************************************************/
void pwr_CI_charge_timer_process(void)
{
   UINT16 status_value;

   status_value = ABB_Read_Status();
   if (status_value & CHGPRES)   /* if the charger is still plugged */
   {
      pwr_get_battery_temperature();
   }
   else
   {
      /* informs the upper layer that the charging process has stopped */
      pwr_send_charge_stop_event();
   }
}




/********************************************************************************/
/*                                                                              */
/*    Function Name: pwr_CV_charge_process                                      */
/*                                                                              */
/*    Purpose:                                                                  */ 
/*                                                                              */
/*                                                                              */
/********************************************************************************/
void pwr_CV_charge_process(void)
{
   UINT16 vbat;
   UINT16 ichg;

   /* Check if the battery temperature is still correct */
   if (pwr_bat_temp_within_limits(pwr_env_ctrl_blk->bat_celsius_temp))
   {
      if (SPI_GBL_INFO_PTR->is_adc_on == FALSE)
      {
         /* start ICHG channel conversion by writing in the result register */
         ABB_Write_Register_on_page(PAGE0, ICHGREG, 0x0000);
         rvf_delay(RVF_MS_TO_TICKS(5));
         ichg = ABB_Read_Register_on_page(PAGE0, ICHGREG);
      }
      else
      {
         ichg = SPI_GBL_INFO_PTR->adc_result[2];
      }

      rvf_send_trace("TIMER2",6, NULL_PARAM, RV_TRACE_LEVEL_WARNING, PWR_USE_ID);
      rvf_send_trace("Ichg (MADC code) ", 17, ichg, RV_TRACE_LEVEL_DEBUG_LOW, PWR_USE_ID); 

      if (SPI_GBL_INFO_PTR->is_adc_on == FALSE)
      {
         /* start VBAT channel conversion by writing in the result register */
         ABB_Write_Register_on_page(PAGE0, VBATREG, 0x0000);
         rvf_delay(RVF_MS_TO_TICKS(5));
         vbat = ABB_Read_Register_on_page(PAGE0, VBATREG);
      }
      else
      {
         /* Use the ADC results asked for by the layer 1 */
         vbat = SPI_GBL_INFO_PTR->adc_result[0];
      }

      rvf_send_trace("Vbat (MADC code) ", 17, vbat, RV_TRACE_LEVEL_DEBUG_LOW, PWR_USE_ID);
         if (ichg > pwr_env_ctrl_blk->madc_eoc_current_code)
         {
            rvf_start_timer (SPI_TIMER2, RVF_MS_TO_TICKS (SPI_TIMER2_INTERVAL), FALSE);
         }
         else
         {
            pwr_stop_charging();
            /* informs the upper layer that the charging process has stopped */
            pwr_send_charge_stop_event();
            rvf_send_trace("Fast charge termination criterion",33, NULL_PARAM, 
                           RV_TRACE_LEVEL_DEBUG_LOW, PWR_USE_ID);

            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 /* Battery temperature not correct !!! */
   {
      pwr_stop_charging();
      rvf_send_trace("Battery temperature not correct! ",33, NULL_PARAM, RV_TRACE_LEVEL_WARNING, PWR_USE_ID); 

      /* 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();
      }
   }
}




/********************************************************************************/
/*                                                                              */
/*    Function Name: pwr_CV_charge_timer_process                                */
/*                                                                              */
/*    Purpose:                                                                  */ 
/*                                                                              */
/*                                                                              */
/********************************************************************************/
void pwr_CV_charge_timer_process(void)
{
   UINT16 status_value;

   status_value = ABB_Read_Status();
   if (status_value & CHGPRES)   /* if the charger is still plugged */
   {
      /* Control the battery temperature */
      pwr_get_battery_temperature();
   }
   else
   {
      /* informs the upper layer that the charging process has stopped */
      pwr_send_charge_stop_event();
   }
}




/********************************************************************************/
/*                                                                              */
/*    Function Name: pwr_bat_test_timer_process                                */
/*                                                                              */
/*    Purpose:                                                                  */ 
/*                                                                              */
/*                                                                              */
/********************************************************************************/
void pwr_bat_test_timer_process(void)
{
   if (pwr_env_ctrl_blk->timer0_state == BATTERY_TYPE_TEST)
   {
      pwr_type_test_timer_process();
   }
   else if (pwr_env_ctrl_blk->timer0_state == BATTERY_SHORT_TEST)
   {
      pwr_short_test_timer_process();
   }
   else if (pwr_env_ctrl_blk->timer0_state == BATTERY_OPEN_TEST)
   {
      pwr_open_test_timer_process();
   }
   else if (pwr_env_ctrl_blk->timer0_state == BATTERY_50UA_TEMP_TEST)
   {
      pwr_bat_50uA_temp_test_timer_process();
   }
   else if (pwr_env_ctrl_blk->timer0_state == BATTERY_10UA_TEMP_TEST)
   {
      pwr_bat_10uA_temp_test_timer_process();
   }
   else if (pwr_env_ctrl_blk->timer0_state == BATTERY_CALIBRATION)
   {
      /* end of current loop calibration */
      pwr_cal_timer_process();
   }
}

#endif /* #ifdef RVM_PWR_SWE */


⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -