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

📄 power.c

📁 是一个手机功能的模拟程序
💻 C
字号:
/*******************************************************************************
*
* power.c
*
* Purpose: This file contains the functions used for power on and off 
*          management of the board.
*          In case of RVM_PWR_SWE, this file contains also the 
*          functions used for charger plug and unplug management. 
*          They are all called after the occurence of the ABB interrupt.
*																			
* Author:  Candice Bazanegue (c-brille@ti.com)						
*																			
*																			
* (C) Texas Instruments 2001
*
******************************************************************************/

#ifndef _WINDOWS
  #include "rv.cfg"
#endif

#include "abb.h"
#include "rvm_use_id_list.h"
#include "spi_env.h"
#include "power.h"
#include "rv_defined_swe.h"	   // for RVM_PWR_SWE

#ifndef _WINDOWS
  #include "kpd_power_api.h"
  #include "ffs.h"
#endif  // _WINDOWS

#ifdef RVM_PWR_SWE
  #include "spi_task.h"
  #ifndef _WINDOWS
    #include "chipset.cfg"
  #endif  // _WINDOWS
  #include "pwr_messages.h"
  #include "pwr_liion_cha.h"
  #include "pwr_disch.h"
#endif /* #ifdef RVM_PWR_SWE */

extern void MI_dbgPrintf(const char* const format, ...);
extern void lcd_backlight_init();


#ifndef _WINDOWS
  /* Declare the variable containing pressed and released callback.  */
  extern T_KPD_KEYPAD Kp;

  extern effs_t ffs_exit(void);
#endif  // _WINDOWS

extern g_switchon;

#define PWRKEY_CHECK_COUNT 6  //glowing,2007-07-20,import from M188A

/*******************************************************************************
**
** Function      Power_ON_Button
**
** Description:  Informs the Protocol Stack that the Power ON key has been  
**				 pressed, and thus allows it to start.
**
*******************************************************************************/
//#define SHORT_PRESS_POWER
void Power_ON_Button(void)
{
#ifdef SHORT_PRESS_POWER
	int nRet;  
    nRet = ABB_Read_Register_on_page(PAGE0, VRPCSTS);
   MI_dbgPrintf("GLOWING--- Power_ON_Button nRet=0x%x", nRet);

   #ifndef _WINDOWS
      SPI_GBL_INFO_PTR->is_gsm_on = TRUE;
   
      /* Wait until the pointers initialization by the SMI */
      while(!(Kp.pressed && Kp.released))
        rvf_delay(1);

   #ifndef TEST
      (Kp.pressed)(KPD_PWR);  /* tell key is pressed */
      rvf_delay(5);
      (Kp.released)();        /* allow protocol stack to start */
   #endif

  #else
     rvf_send_trace("Start from button", 17, NULL_PARAM, RV_TRACE_LEVEL_WARNING, PWR_USE_ID);
     SPI_GBL_INFO_PTR->is_gsm_on = TRUE;
   #endif  // _WINDOWS
   
#else

int nRet;  
    int nLoopCount;

    /* Wait until the pointers initialization by the SMI */
/* zhq, 2004/07/03, modified for we use long press power key to switch on. */
    for(nLoopCount = 0;nLoopCount < PWRKEY_CHECK_COUNT;nLoopCount++)
    {
        //sleep a moment and get the powerkey status
	    rvf_delay(10);   /* modified by zhq from 20->10 for fit GPRS platform */
        nRet = ABB_Read_Register_on_page(PAGE0, VRPCSTS);
   //MI_dbgPrintf("GLOWING--- Power_ON_Button nRet=0x%x", nRet);

        /* if the power key isn't pressed, then Shutdown machine */
        if(  ((nRet & ONREFLT) != NULL)  &&  (( nRet & CHGPRES ) == NULL )  &&  (( nRet & ONRSTS ) == NULL ) )
        {
             AI_Power(0);
              break;
	  }
    }    	  

   // if( ((nRet & ONREFLT) == NULL) || (( nRet & CHGPRES ) != NULL ) )  
    {
//        extern void lcd_backlight_init();
//	lcd_backlight_init();

//        rvf_send_trace("Start from button", 17, NULL_PARAM, RV_TRACE_LEVEL_WARNING, PWR_USE_ID);
	    SPI_GBL_INFO_PTR->is_gsm_on = TRUE;

    	/* Wait until the pointers initialization by the SMI */
   	    while(!(Kp.pressed && Kp.released))
	    rvf_delay(1);    

	    (Kp.pressed)(KPD_PWR);  /* tell key is pressed */
		rvf_delay(5);    
	    (Kp.released)();        /* allow protocol stack to start */
    }    

#endif
}



/*******************************************************************************
**
** Function      Power_OFF_Button
**
** Description:  Informs the Protocol Stack that the Power OFF key has been  
**				 pressed, and thus allows it to stop.
**
*******************************************************************************/
void Power_OFF_Button(void)
{
#ifndef _WINDOWS
   ffs_exit ();
#endif  // _WINDOWS
//TISH031204 shirely modify for compilation
//   rvf_send_trace("Power off button", 16, NULL_PARAM, RV_TRACE_LEVEL_WARNING, PWR_USE_ID);
   rvf_send_trace("Power off button", 16, NULL_PARAM, RV_TRACE_LEVEL_WARNING, LCC_USE_ID);
   SPI_GBL_INFO_PTR->is_gsm_on = FALSE;
#ifndef _WINDOWS
   (Kp.pressed)(KPD_PWR);  /* tell key is pressed */
   rvf_delay(5);
   (Kp.released)();        /* tell key is released */
#endif  // _WINDOWS
}



/*******************************************************************************
**
** Function      Switch_ON
**
** Description   This function is called by the spi task after the board is  
**               switched ON. It calls the appropriate function according
**               to the ABB status register.  
**
*******************************************************************************/
void Switch_ON(void)
{
   SYS_UWORD16 abb_status;

   abb_status = ABB_Read_Status();

   MI_dbgPrintf("GLOWING--- Switch_ON abb_status=0x%x", abb_status);

#if ((ANALOG == 1) || (ANALOG == 2))
   if (abb_status & ONBSTS)
#elif (ANALOG == 3)
   if (abb_status & PWONSTS)
#endif
   {
      /* Switch on Condition on ON BUTTON Push */
// TISH031204 shirely modify for compilation
//      rvf_send_trace("Push Button from OFF to ON",26, NULL_PARAM, RV_TRACE_LEVEL_DEBUG_LOW, PWR_USE_ID);
      rvf_send_trace("Push Button from OFF to ON",26, NULL_PARAM, RV_TRACE_LEVEL_DEBUG_LOW, LCC_USE_ID);
     g_switchon = 3;

	  Power_ON_Button();
      #ifdef RVM_PWR_SWE
      pwr_handle_discharge();
      #endif
   }

#if ((ANALOG == 1) || (ANALOG == 2))
   else if (abb_status & ONRSTS) 
#elif (ANALOG == 3)
   else if (abb_status & RPSTS)
#endif
   {
      /* Switch on Condition on ON REM transition 0->1 */
// TISH031204 shirely modify for compilation      
//      rvf_send_trace("ON Remote",9, NULL_PARAM, RV_TRACE_LEVEL_DEBUG_LOW, PWR_USE_ID); 
      rvf_send_trace("ON Remote",9, NULL_PARAM, RV_TRACE_LEVEL_DEBUG_LOW, LCC_USE_ID); 
      g_switchon = 1;
      Power_ON_Remote();
      #ifdef RVM_PWR_SWE
      pwr_handle_discharge();
      #endif
   }

   #ifdef RVM_PWR_SWE
   else if (abb_status & CHGSTS)
   {
      g_switchon = 2;
      /* Switch on Condition on CHARGER IC PLUG */
      rvf_send_trace("PWR: Charger Plug",17, NULL_PARAM, RV_TRACE_LEVEL_DEBUG_LOW, PWR_USE_ID); 
      if (abb_status & CHGPRES)
      {
         /* charger still present */
         PWR_Charger_Plug();
      }
   }
   #endif /* #ifdef RVM_PWR_SWE */

   else
   {
      // The reset should run the SW in the same way than a Power ON
// TISH031204 shirely modify for compilation       
//      rvf_send_trace("Start from reset",16, NULL_PARAM, RV_TRACE_LEVEL_DEBUG_LOW, PWR_USE_ID); 
      rvf_send_trace("Start from reset",16, NULL_PARAM, RV_TRACE_LEVEL_DEBUG_LOW, LCC_USE_ID); 
	  //Glowing,2004-07-25, replace Power_ON_Button with Power_ON_Reset
      //Power_ON_Button();
      Power_ON_Reset();
      #ifdef RVM_PWR_SWE
      pwr_handle_discharge();
      #endif
   }
}



/*******************************************************************************
**
** Function         Power_ON_Remote
**
** Description      
**
**
*******************************************************************************/
void Power_ON_Remote(void)
{
		lcd_backlight_init();
}



/*******************************************************************************
**
** Function         Power_OFF_Remote
**
** Description      
**
**
*******************************************************************************/
void Power_OFF_Remote(void)
{
}



/*******************************************************************************
**
** Function         Power_IT_WakeUp
**
** Description      
**
**
*******************************************************************************/
void Power_IT_WakeUp(void)
{
}


//glowing, 2004-07-25, add
void Power_ON_Reset(void)
{
	int nRet;  

   #ifndef _WINDOWS
      SPI_GBL_INFO_PTR->is_gsm_on = TRUE;
      lcd_backlight_init();
  
      /* Wait until the pointers initialization by the SMI */
      while(!(Kp.pressed && Kp.released))
        rvf_delay(1);

   #ifndef TEST
      (Kp.pressed)(KPD_PWR);  /* tell key is pressed */
      rvf_delay(5);
      (Kp.released)();        /* allow protocol stack to start */
   #endif

  #else
     rvf_send_trace("Start from Reset", 16, NULL_PARAM, RV_TRACE_LEVEL_WARNING, PWR_USE_ID);
     SPI_GBL_INFO_PTR->is_gsm_on = TRUE;
   #endif  // _WINDOWS
}

#ifdef RVM_PWR_SWE
/*******************************************************************************
**
** Function         PWR_Charger_Plug
**
** Description      
**
**
*******************************************************************************/
void PWR_Charger_Plug(void)
{

  /* Start the fast charging cycle */

  /* Since this function is called from the SPI task
   it can't be interrupt by another task
   so we can directly access the SPI through the low-level driver */

   if (SPI_GBL_INFO_PTR->is_gsm_on == FALSE) /* GSM OFF */
   {
      rvf_delay(RVF_MS_TO_TICKS(2000));
   }

   rvf_stop_timer(SPI_TIMER3);

   /* informs the upper layer that the charger has been plugged */
   pwr_send_charger_plug_event();

   /* get the type of the battery */
   pwr_get_battery_type();
}



/*******************************************************************************
**
** Function         PWR_Charger_Unplug
**
** Description      
**
**
*******************************************************************************/
void PWR_Charger_Unplug(void)
{
   /* informs the upper layer that the charger has been unplugged */
   pwr_send_charger_unplug_event(); 

   rvf_send_trace("Charger unplug", 14, NULL_PARAM, RV_TRACE_LEVEL_DEBUG_LOW, PWR_USE_ID );
   pwr_stop_charging();
   if (SPI_GBL_INFO_PTR->is_gsm_on == FALSE) /* GSM OFF */
   {
    #ifndef _WINDOWS
      #if (ANALOG == 1) 
      ABB_Write_Register_on_page(PAGE0, VRPCCTL2, 0x00EE);
      #elif ((ANALOG == 2) || (ANALOG == 3))
      ABB_Write_Register_on_page(PAGE0, VRPCDEV, 0x0001);
      #endif
    #else
      ABB_Write_Register_on_page(PAGE0, VRPCDEV, 0x00EE);
    #endif  // _WINDOWS
   }
   else
   {
      pwr_handle_discharge();
   }
}
#endif /* #ifdef RVM_PWR_SWE */





⌨️ 快捷键说明

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