PM_GetBattery

Syntax

#include <nitro/spi.h>
u32 PM_GetBattery( PMBattery* batteryBuf );

Arguments

batteryBuf Buffer storing the remaining battery life for the battery pack.

Return Values

If PM_RESULT_SUCCESS, the command ran successfully.

If PM_RESULT_BUSY, the SPI was occupied by other processing and unable to process this function.

Information on the remaining battery life are placed in batteryBuf when the command is run successfully. A value of PM_BATTERY_HIGH indicates that there is a certain amount of remaining battery life, and PM_BATTERY_LOW indicates that the remaining battery life is low.

Description

Checks the remaining battery capacity of the battery pack.

The batteryBuf argument is a pointer to the PMBattery type, and the results are stored here.

If this function is called from the ARM9, a command is sent to the ARM7 using PXI. Upon receiving this command, the ARM7 checks the remaining battery life and returns it to the ARM9.

On NITRO, the ARM7 gets information on the remaining battery life from the PMIC. It returns 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.

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 PM_GetBatteryLevel function and returns a two-level result based on whether the result is between 0 to 1 or 2 to 5.

Value Stored in batteryBuf Description How to Get Data When Using NITRO Hardware
LED Status
How to Get Data When Using TWL Hardware
LED Status
PM_BATTERY_HIGH There is remaining battery capacity. VDET terminal's detection voltage is greater than or equal to threshold.
Steady green light.
The PM_GetBatteryLevel function returns a value in the range of 2-5.
Steady blue or red light.
PM_BATTERY_LOW
The remaining battery capacity is low. VDET terminal's detection voltage is greater than or equal to threshold.
Steady red light.
The PM_GetBatteryLevel function returns a value in the range of 0-1
Blinking red light.

The color and steady/blinking status of the LED cannot be controlled by applications.

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.

This function can be used from an interrupt handler. This function cannot be used in interrupt-prohibited states other than interrupt handlers.



About PM_RESULT_BUSY

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 PM_RESULT_BUSY is notified 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 PM_RESULT_BUSY. (In this case, the determination is made before notification is sent to the ARM7.)

Accordingly, if you want to ensure that this function succeeds, make it loop until it succeeds as shown below. (This example does not take into account mistakes such as wrong arguments.)

Example
while( PM_GetBattery( ... ) != PM_RESULT_SUCCESS )
{
}

Internal Operation

On NITRO:
Reads value of the PMIC register PMIC_STAT.
This function detects whether the voltage of the PMIC VDET terminal is above or below the threshold.

On TWL:
Returns a two-level result based on the remaining battery life obtained by the microprocessor.

See Also

PM_Init
PM_GetBatteryLevel

Revision History

2009/06/03 Removed a description of the PM_Init function (because OS_Init is now required).
2008/08/23 Discontinued use of PM_RESULT_ERROR and referred to PM_RESULT_BUSY.
2008/06/12 Explained how to get values on a TWL system.
2005/07/07 Mentioned the PM_RESULT_ERROR return value.
2004/08/09 Initial version.


CONFIDENTIAL