1<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> 2<HTML> 3<HEAD> 4<META http-equiv="Content-Type" content="text/html; charset=windows-1252"> 5<META name="GENERATOR" content="IBM WebSphere Studio Homepage Builder Version 7.0.1.0 for Windows"> 6<META http-equiv="Content-Style-Type" content="text/css"> 7<TITLE>PM_GetBattery</TITLE> 8<LINK rel="stylesheet" href="../../css/nitro.css" type="text/css"> 9</HEAD> 10<BODY> 11<H1 align="left">PM_GetBattery <IMG src="../../image/NTR.gif" width="24" height="12" border="0" align="middle"><IMG src="../../image/TWL.gif" width="24" height="12" border="0" align="middle"></H1> 12<H2>Syntax</H2> 13<DL> 14 <DD> 15 <PRE><CODE>#include <nitro/spi.h></CODE></PRE> 16 <PRE><CODE>u32 PM_GetBattery( PMBattery* batteryBuf ); 17</CODE></PRE> 18</DL> 19<H2>Arguments</H2> 20<TABLE border="1" width="100%"> 21 <TBODY> 22 <TR> 23<TD width="13%"><EM><STRONG>batteryBuf</STRONG></EM></TD> 24<TD width="87%">Buffer storing the remaining battery life for the battery pack.</TD> 25 </TR> 26 </TBODY> 27</TABLE> 28<H2>Return Values</H2> 29<P>A value of <CODE>PM_RESULT_SUCCESS</CODE> indicates that the command was run successfully.</P> 30<P><CODE>PM_RESULT_BUSY</CODE> indicates that the SPI was occupied by other processing and unable to process this function.</P> 31<P>Information on the remaining battery life will be placed in <B><I>batteryBuf</I></B> when the command is run successfully. A value of <CODE>PM_BATTERY_HIGH</CODE> indicates that there is a certain amount of remaining battery life, and <CODE>PM_BATTERY_LOW</CODE> indicates that the remaining battery life is low.</P> 32<H2>Description</H2> 33<P>Checks the remaining battery capacity of the battery pack.</P> 34<P>The <em><strong><code>batteryBuf</code></strong></em> argument is a pointer to the <code>PMBattery</code> type, and the results are stored here.</P> 35<P>If this function is called from the ARM9, a command will be sent to the ARM7 using PXI. Upon receiving this command, the ARM7 will check the remaining battery life and return it to the ARM9.</P> 36<P>On NITRO, the ARM7 gets information on the remaining battery life from the PMIC. It will return a result that indicates one of two levels: either the voltage detected by the VDET terminal is greater than the threshold, or it is lower.</P> 37<P>On TWL, the ARM7 gets information on the remaining battery life from the microprocessor. Specifically, the ARM7 gets a value equivalent to that of the <A href="PM_GetBatteryLevel.html"><CODE>PM_GetBatteryLevel</CODE></A> function and returns a two-level result based on whether the result is between 0 to 1 or 2 to 5.<BR> <BR> 38</P> 39<TABLE border="1"> 40 <TBODY> 41 <TR> 42<TH>Value Stored in <SPAN class="argument">batteryBuf</SPAN></TH> 43<TH>Description</TH> 44<TH>How to Get Data When Using NITRO Hardware<BR>LED Status</TH> 45<TH>How to Get Data When Using TWL Hardware<BR>LED Status</TH> 46 </TR> 47 <TR> 48<TD><CODE>PM_BATTERY_HIGH</CODE></TD> 49<TD>There is remaining battery capacity.</TD> 50<TD>VDET terminal's detection voltage is greater than or equal to threshold.<BR><FONT color="#33cc00">■</FONT> Lights green.</TD> 51<TD>The <CODE><A href="PM_GetBatteryLevel.html">PM_GetBatteryLevel</A></CODE> function returns a value in the range of 2-5.<BR> <FONT color="#0099ff">■</FONT> Lights blue or <FONT color="#ff0000">■</FONT> lights red.</TD> 52 </TR> 53 <TR> 54<TD><CODE>PM_BATTERY_LOW</CODE></TD> 55<TD>The remaining battery capacity is low.</TD> 56<TD>VDET terminal's detection voltage is greater than or equal to threshold.<BR><FONT color="#ff0000">■</FONT> Lights red.</TD> 57<TD>The <CODE><A href="PM_GetBatteryLevel.html">PM_GetBatteryLevel</A></CODE> function returns a value in the range of 0-1<BR><FONT color="#ff0000">■</FONT><FONT color="#330000">■</FONT> Flashes red.</TD> 58 </TR> 59 </TBODY> 60</TABLE> 61<P>The color and lit/flashing status of the LED cannot be controlled by applications.</P> 62<P>When the remaining battery life is close to the threshold, the color of the power indicator LED may change temporarily when entering sleep mode. For example, when running on NITRO hardware, the LED may temporarily return to green when entering sleep mode with the LED lit red.</P> 63<P>Before you use this function, use the <A href="PM_Init.html"><CODE>PM_Init</CODE></A> function to initialize the PM library. The <code>PM_Init()</code> function has to be called only once. Also, when you call the <a href="../../os/init/OS_Init.html"><code>OS_Init</code></a> function, there is no need to call the <a href="PM_Init.html"><code>PM_Init</code></a> function separately because it is called from within <code>OS_Init</code>.)</P> 64<P><FONT color="#ff0000">This function can be used from an interrupt handler. This function cannot be used in interrupt-prohibited states other than interrupt handlers.</FONT></P> 65<P><BR> <BR> <B>About <CODE>PM_RESULT_BUSY</CODE></B></P> 66<P>The SPI is used for various other processes besides power management. If you call this function while another process is using it, this function sends a command to the ARM7. There, the SPI is determined to be BUSY, and <CODE>PM_RESULT_BUSY</CODE> is sent to the ARM9 without actually processing this function. Likewise, if you call this function while another PM process is running, that fact is determined on the ARM9 side and this function returns <CODE>PM_RESULT_BUSY</CODE>. (In this case, the determination is made before notification is sent to the ARM7.)</P> 67<P>Accordingly, if you want to make certain that this function will succeed, make it loop until it succeeds as shown below. (This example does not take into account mistakes such as wrong arguments.)</P> 68<BLOCKQUOTE style="background-color:#ffffcc"><B>Example</B><BR> <CODE>while( PM_GetBattery( ... ) != PM_RESULT_SUCCESS )<BR> {<BR> }</CODE></BLOCKQUOTE> 69<H2>Internal Operation</H2> 70<P>(On NITRO) <BR>Reads value of the PMIC register <CODE>PMIC_STAT</CODE>.<BR>This function detects whether the voltage of the PMIC VDET terminal is above or below the threshold.</P> 71<P>(On TWL) <BR>Returns a two-level result based on the remaining battery life obtained by the microprocessor.</P> 72<H2>See Also</H2> 73<P><A href="PM_Init.html"><CODE>PM_Init</CODE></A><BR> <A href="PM_GetBatteryLevel.html"><CODE>PM_GetBatteryLevel</CODE></A></P> 74<H2>Revision History</H2> 75<P>2008/08/23 Ended the use of <CODE>PM_RESULT_ERROR</CODE> and elaborated about <CODE>PM_RESULT_BUSY</CODE>.<BR> 2008/06/12 Described how to get data with TWL hardware.<BR> 2005/07/07 Elaborated about the <CODE>PM_RESULT_ERROR</CODE> return value.<BR> 2004/08/09 Initial version.</P> 76<hr><p>CONFIDENTIAL</p></body> 77</HTML>