📄 power.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"
#include "l1sw.cfg"
#include "chipset.cfg"
#endif
#include "nucleus.h" // for NUCLEUS functions and types
#if (ANLG_FAM!=11)
#include "abb/abb.h"
#else
#include "sys_types.h"
#include "abb/bspTwl3029.h"
#include "abb/bspTwl3029_I2c.h"
#include "abb/bspTwl3029_Power.h"
#include "abb/bspTwl3029_IntC.h"
#endif
#include "rvm/rvm_use_id_list.h"
#if (ANLG_FAM!=11)
#include "spi/spi_env.h"
#endif
#include "power/power.h"
#include "rv/rv_defined_swe.h" // for RVM_PWR_SWE
#include "rvf/rvf_api.h" // Added by LI Xiaohan for shutting down UART in NO TRACE version 04/08/05
#include "lcc/lcc_api.h"//added by kathy
#include "lcc/lcc_trace.h" // Add by jiangbo
#ifndef _WINDOWS
#include "kpd/kpd_power_api.h"
#include "kpd/kpd_physical_key_def.h"
#include "ffs/ffs.h"
#include "abb.h"
#endif // _WINDOWS
#ifdef RVM_PWR_SWE
#include "spi/spi_task.h"
#ifndef _WINDOWS
#include "chipset.cfg"
#endif // _WINDOWS
#include "pwr/pwr_messages.h"
#include "pwr/pwr_liion_cha.h"
#include "pwr/pwr_disch.h"
#endif /* #ifdef RVM_PWR_SWE */
#include "inth/sys_inth.h" //added by TIsh Ellen for power-on failure issue
#include "ffs/ffs.h" // Andrew
#include "../../../drv_core/pin_config.h"
#ifdef LCD_DRV_DEBUG
#include "nucleus.h"
#include "rv/rv_trace.h"
#include "rvf/rvf_api.h"
#include "rvm/rvm_use_id_list.h"
#endif /*LCD_DRV_DEBUG*/
#if 0
void bim_save_bit(void); // Andrew
void btm_save_btt(void); // Andrew
#endif
#include "rv/rv_defined_swe.h"
#include "dar/dar_api.h" // lixhg
//added by kathy 0429
//#include "abb_inline.h"
//#include ".\r2d\lcds\customer\r2d_task_i.h"
//#include ".\r2d\lcds\customer\r2d_task_init_i.h"
//end.
#ifndef _WINDOWS
/* Declare the variable containing pressed and released callback. */
extern T_KPD_KEYPAD Kp;
/* wangwang : Because we want to add feature of rtc power on by user
decided,we should add one state to tell that.
0 : indicate normal power on way
1 : indicate charger or usb power on
2 : indicate RTC power on
060912 */
UINT16 pwron_way = 0;
extern effs_t ffs_exit(void);
#endif // _WINDOWS
/// The ABB status used to know the cause of the Switch ON event.
static SYS_UWORD16 Power_abb_status = 0;
#if (ANLG_FAM==11)
#define NU_Sleep(wait) wait_ARM_cycles(convert_nanosec_to_cycles((wait)*4.65*1000))
//SYS_UWORD8 power_state = FALSE;
t_power_state_e power_state = POWER_OFF;
SYS_UWORD8 is_power_loop=0; //added by TIsh Ellen for power-on failure issue
int is_mmi_want_poweroff=0; //added by TIsh Ellen for power-on failure issue
/****************************************************************/
/* Power ON/OFF key definition. */
/****************************************************************/
// If <ON/OFF> key is pressed more than 20 TDMAs, it's a Hook-ON
#define SHORT_OFF_KEY_PRESSED (60)
// If <ON/OFF> key is pressed more than 160 TDMAs, it's a Hook-ON AND then Power-OFF
#define OFF_LOOP_COUNT (8)
#define LONG_OFF_KEY_PRESSED (OFF_LOOP_COUNT * SHORT_OFF_KEY_PRESSED)
/*******************************************************************************
**
** Function Power_Key_Interrupt
**
** Description
**
**
*******************************************************************************/
extern T_RV_RET kpd_power_key_pressed(void);
static SYS_UWORD8 status_value, loop_count=0;
/*-------------------------------------------------------------------*/
/*wangwang : this fucntion give mmi a tip that the power button
is pressing how many times
060913*/
static SYS_UWORD8 canplay_powerring=0; // 0 indicate can not ring
// 1 indicate can ring
SYS_UWORD8 Can_Play_Ring_Tone_Of_Power(void)
{
return canplay_powerring;
}
SYS_UWORD8 Reset_Play_Ring_Tone_Of_Power_Flag(void)
{
canplay_powerring=0;
}
/*---------------------------------------------------------------------*/
static void power_callback(Uint8 i)
{
LCC_TRACE(TTrAll, "LCC: PWR: status=%x i=%d Ln:%d", status_value, status_value, i, __LINE__);
if (status_value & (1<<BSP_TWL3029_POWER_PWON_OFFSET
|1<<BSP_TWL3029_POWER_RPWON_OFFSET))
kpd_power_key_pressed();
else //added by TIsh Ellen for power-on failure issue
{
is_power_loop=0;
}
}
static void Power_Key_Interrupt(BspTwl3029_IntC_SourceId id)
{
LCC_TRACE(TTrAll, "LCC: PWR: Power ON key IQ, Ln:%d", __LINE__);
//modified by TIsh Ellen for power-on failure issue
if((is_power_loop==0)&&(is_mmi_want_poweroff==1))
{
if (power_state == POWER_ON)
{
loop_count=0;
canplay_powerring=0;
is_power_loop=1;
bspTwl3029_Power_SwitchOnStatusWithCallback(&status_value,power_callback);
}
else
{
canplay_powerring=0;
loop_count=0;
bspTwl3029_Power_SwitchOnStatusWithCallback(&status_value,power_callback);
}
}
}//modified by TIsh Ellen for power-on failure issue
T_RV_RET Power_handle_power_key_press(void)
{
/* Push Button from ON to OFF */
if (power_state == POWER_ON)
{
// WCP Patch
#if (OP_WCP == 0)
loop_count++;
if (loop_count<OFF_LOOP_COUNT)
{
rvf_delay(SHORT_OFF_KEY_PRESSED);
bspTwl3029_Power_SwitchOnStatusWithCallback(&status_value,power_callback);
kpd_process_key_pressed_i(KPD_SHORT_PRESS_PWR_KEY);
if (loop_count<=1)
{
canplay_powerring=1;
}
}
else
{
rvf_send_trace("IQ EXT: Power Off request",25, NULL_PARAM, RV_TRACE_LEVEL_DEBUG_LOW, SPI_USE_ID);
rvf_send_trace("CALLING POWER OF BUTTON",23, NULL_PARAM, RV_TRACE_LEVEL_ERROR, SPI_USE_ID);
is_mmi_want_poweroff=0; //added by TIsh Ellen for power-on failure issue
//F_INTH_DISABLE_ONE_IT(C_INTH_KEYBOARD_IT);//added by TIsh Ellen for power-on failure issue//marked by lifanc
Power_OFF_Button();
}
#endif //OP_WCP
}
/* wangwang : handle power off from charger poweron to normal
060901*/
else
{
loop_count++;
if (loop_count<OFF_LOOP_COUNT)
{
rvf_delay(SHORT_OFF_KEY_PRESSED);
bspTwl3029_Power_SwitchOnStatusWithCallback(&status_value,power_callback);
kpd_process_key_pressed_i(KPD_SHORT_PRESS_PWR_KEY);
if (loop_count<=1)
{
canplay_powerring=1;
}
}
else
{
rvf_send_trace("IQ EXT: Power Off request",25, NULL_PARAM, RV_TRACE_LEVEL_DEBUG_LOW, SPI_USE_ID);
rvf_send_trace("CALLING POWER ON BUTTON",23, NULL_PARAM, RV_TRACE_LEVEL_ERROR, SPI_USE_ID);
Power_ON_Button();
}
}
}
extern T_RV_RET dar_stop_watchdog_timer();
void Switch_Off(void)
{
SYS_UWORD8 status_value;
bspTwl3029_Power_SwitchOnStatus(&status_value);
/* FIXME : Revisit This After Charger */
#if 0
if ((status_value & (1<<BSP_TWL3029_POWER_CHG_OFFSET)))
{
// Charger present => Can't-Off the Board
return;
}
#endif
//Wait until all necessary actions are performed (write in FFS, etc...) to power-off the board (empirical value - 30 ticks).
NU_Sleep (30);
/* wangwang : Here we can assume it's in the process of normal power off and
impossible occuring the dar reset action.
so just stop dar watchdog timer
But there are some complicated situation that I have not met,
So the actually reason is not found,fixed later?????
060928*/
dar_stop_watchdog_timer();
// Wait also until <ON/OFF> key is released.
// This is needed to avoid, if the power key is pressed for a long time, to switch
// ON-switch OFF the mobile, until the power key is released.
while ((status_value & ((1<<BSP_TWL3029_POWER_PWON_OFFSET)
| (1<<BSP_TWL3029_POWER_RPWON_OFFSET))))
{
bspTwl3029_Power_SwitchOnStatus(&status_value);
NU_Sleep (1);
}
BZ_KeyBeep_OFF();
bspTwl3029_Power_SwitchOff();
}
#endif
/*******************************************************************************
**
** Function Power_ON_Button
**
** Description: Informs the Protocol Stack that the Power ON key has been
** pressed, and thus allows it to start.
**
*******************************************************************************/
void Power_ON_Button(void)
{
#ifndef _WINDOWS
#if (ANLG_FAM!=11)
SPI_GBL_INFO_PTR->is_gsm_on = TRUE;
#else
power_state=POWER_ON;
pwron_way = 0 ; // Added by jiangbo.
#endif
#if ((OP_WCP == 0) && (TEST == 0))
/* 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
#else
rvf_send_trace("Start from button", 17, NULL_PARAM, RV_TRACE_LEVEL_WARNING, LCC_USE_ID);
SPI_GBL_INFO_PTR->is_gsm_on = TRUE;
#endif // _WINDOWS
}
/*******************************************************************************
**
** 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)
{
T_RV_RET ret;
#if 0
// Andrew ///////////////////////////////////
/**** create the gbi fast-bootup ffs directory ****/
ret = ffs_mkdir("/gbi");
if ((ret != EFFS_OK) && (ret != EFFS_EXISTS))
{
rvf_send_trace("Fail to create gbi directory in POWER OFF", 31, NULL_PARAM, RV_TRACE_LEVEL_WARNING, LCC_USE_ID);
}
else
{
#if( (!defined(RVM_MC_SWE)) && (defined (RVM_NAN_SWE)) )
rvf_send_trace("Saving to NOR during POWER OFF",30, NULL_PARAM, RV_TRACE_LEVEL_ERROR, LCC_USE_ID);
bim_save_bit(); // Andrew
btm_save_btt(); // Andrew
#endif
}
// Andrew ///////////////////////////////////
rvf_send_trace("SAVED to NOR during POWER OFF",29, NULL_PARAM, RV_TRACE_LEVEL_ERROR, LCC_USE_ID);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -