N900 Software BME
This page is to bring together efforts and links for those working on understanding BME - the battery managment entity.
This is required to implement user friendly Host Mode
BME is divided into three parts.
- Kernel driver that handles all of the low-level interaction with the hardware.
- hald-addon-bme - an add-on process for HAL that reports status.
- bme_RX-51 - Process started early in boot, with watchdogs to reboot the device if it malfunctions.
The kernel driver is split over several files.
http://mxr.maemo.org/fremantle/source/kernel/include/linux/i2c/twl4030-madc.h This handles reading various ADCs to readout voltages and currents.
Unsorted adds:
- Then there's also /usr/lib/hal/hald-addon-bme, which seems not to be completely out of order (according to lshal) even when bme_RX-51 is stopped.
- Mer 'replacement hald-addon-bme': http://gitorious.org/mer-toggles/hald-addon-bme/blobs/master/hald-addon-bme.c Mer/Documentation/BME_Protocol (N810!)
-
lsof -p `pidof bme_RX-51`
gives an idea about what BME is actually interfering/interfacing with, and a strace will show it talks to dsme_lib probably to implement the watchdog timers.
- BME process/file is called
/usr/sbin/bme_RX-51
and killing or sigstop'ing it will cause immediate or delayed reboot. It is easily suspended though through upstart process management by:~>stop bme
and resumed any time by:~>start bme
A nice little experiment to investigate the bq24150 USB Battery Charger chip's abilities is to
- plug in Nokia wallwart charger
-
->stop bme
- wait max 32s until bq24150 internal watchdog timer expires (due to bme not resetting it), which will cause bq24150 to reset to defaults, which are a mostly sane, safe charging without any software support. You can tell this by bq24150 firing up the hardwired steady yellow indicator LED
I'm about to write a first draft little script to somewhat replace bme's basic functions, eventually turning this into a real project Just-Replaces-BME aka jrbme (some say it's "JRBME replaces BME", according to an age old tradition of linux self referencing ETLA [like GNU=="GNU Not Unix", KDE=="KDE Desktop Environment"])
Joerg's script can be found here. It should not be used by anyone who has not read and understood all relevant datasheets, and understands why it does what it does.
Editing this without understanding can CAUSE YOUR N900 TO CATCH FIRE.
Contents |
Replacement Goals
Alpha
- Not make the battery explode.
- Charge from any 5V source, assuming the battery is in a safe condition, just setting the charger chip to the end voltage, and resetting the watchdog.
Beta
- Watch the state of the battery, and charge taking into account device load.
- Battery charger chip should be configured to float the battery at a current which slightly exceeds the desired float current, and the charge normally terminated when the actual battery current measured by the bq27200 reaches the 'taper' value. A simple way to measure this is if the 'time till full' field goes to 65535. This ensures a consistent shutoff taper current, which the battery charger alone cannot do.
Gamma
- Charge at appropriate limits for USB chargers, and USB hosts we are plugged into.
- Monitor and reset from abnormal conditions - incorrect 'battery missing' and other error codes. Capacity and charge data from bq27200 can be very inaccurate if the phone has not appropriately learned the capacity of the battery, or if it erroneously detects battery full due to a high impedence battery or poor contact.
- If phone is in active use, and charger or USB is plugged in, maintain a constant battery voltage somewhat under the peak charge voltage, without regards to taper current. (To keep phone charged, but not degrade battery with pointless micro-cycling, or high float voltage
)