N900 Software BME

(more)
 
(8 intermediate revisions not shown)
Line 2: Line 2:
This is required to implement user friendly [[N900_Hardware_USB_Host|Host Mode]]
This is required to implement user friendly [[N900_Hardware_USB_Host|Host Mode]]
 +
 +
See also the garage project [https://garage.maemo.org/projects/jrbme/ JR-BME].
BME is divided into three parts.
BME is divided into three parts.
-
* Kernel driver that handles all of the low-level interaction with the hardware.
+
* Kernel driver that handles all of the low-level interaction with the hardware. (basically just I2C IO)
* hald-addon-bme - an add-on process for HAL that reports status.
* 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.
+
* bme_RX-51 - Process started early in boot, with watchdog tickling of the watchdog in chip, configuring the charger chip, selecting charge current etc.
-
 
+
-
 
+
The kernel driver is split over several files.
The kernel driver is split over several files.
http://mxr.maemo.org/fremantle/source/kernel/include/linux/i2c/twl4030-madc.h
http://mxr.maemo.org/fremantle/source/kernel/include/linux/i2c/twl4030-madc.h
-
This handles reading various ADCs to readout voltages and currents.
+
This handles reading various ADCs to readout voltages, currents and BSI.
 +
'''BSI''', or battery size indicator is the third pin of the battery. Resistance between the - pin and third pin on battery is measured by BME through twl4030-madc, and mapped into a capacity in mAh. BME noticeably uses this as a reference "full" value for the battery meter, and possibly for other uses as well. Here are some experimental results, all resistance readings are to be considered inaccurate at best:
 +
 +
100 kΩ 1250mAh (Original BL-5J battery)
 +
  90 kΩ 1000mAh
 +
  80 kΩ  862mAh
 +
  78 kΩ  740mAh
Unsorted adds:
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.
+
* Then there's also <code>/usr/lib/hal/hald-addon-bme</code>, 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!)
* Mer 'replacement hald-addon-bme': http://gitorious.org/mer-toggles/hald-addon-bme/blobs/master/hald-addon-bme.c [[Mer/Documentation/BME_Protocol]] (N810!)
-
 
* <code>lsof -p `pidof bme_RX-51`</code> 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.
* <code>lsof -p `pidof bme_RX-51`</code> 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 <code>/usr/sbin/bme_RX-51</code> and killing or sigstop'ing it will cause immediate or delayed reboot. It is easily suspended though through upstart process management by:<br /><pre>~>stop bme</pre>and resumed any time by:<br /><pre>~>start bme</pre>
* BME process/file is called <code>/usr/sbin/bme_RX-51</code> and killing or sigstop'ing it will cause immediate or delayed reboot. It is easily suspended though through upstart process management by:<br /><pre>~>stop bme</pre>and resumed any time by:<br /><pre>~>start bme</pre>
-
A nice little experiment to investigate the bq24150 USB Battery Charger chip's abilities is to  
+
A nice little experiment to investigate the bq24150a USB Battery Charger chip's abilities is to  
* plug in Nokia wallwart charger
* plug in Nokia wallwart charger
* <pre>->stop bme</pre>
* <pre>->stop bme</pre>
-
* 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
+
* wait max 32s until bq24150a internal watchdog timer expires (due to bme not resetting it), which will cause bq24150a to reset to defaults, which are a mostly sane, safe charging without any software support. You can tell this by bq24150a 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"])
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"])
Line 38: Line 41:
Editing this without understanding can CAUSE YOUR N900 TO CATCH FIRE.
Editing this without understanding can CAUSE YOUR N900 TO CATCH FIRE.
-
=Replacement Goals=
+
==Replacement Goals==
-
==Alpha==
+
===Alpha===
* Not make the battery explode.
* 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.
* 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==
+
===Beta===
* Watch the state of the battery, and charge taking into account device load.
* Watch the state of the battery, and charge taking into account device load.
-
==Gamma==
+
** 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.
* 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)
-
[[category:N900_Hardware]]
+
[[Category:N900_Hardware]]

Latest revision as of 01:54, 24 June 2016

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

See also the garage project JR-BME.

BME is divided into three parts.

  • Kernel driver that handles all of the low-level interaction with the hardware. (basically just I2C IO)
  • hald-addon-bme - an add-on process for HAL that reports status.
  • bme_RX-51 - Process started early in boot, with watchdog tickling of the watchdog in chip, configuring the charger chip, selecting charge current etc.

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, currents and BSI.

BSI, or battery size indicator is the third pin of the battery. Resistance between the - pin and third pin on battery is measured by BME through twl4030-madc, and mapped into a capacity in mAh. BME noticeably uses this as a reference "full" value for the battery meter, and possibly for other uses as well. Here are some experimental results, all resistance readings are to be considered inaccurate at best:

100 kΩ 1250mAh (Original BL-5J battery)
 90 kΩ 1000mAh
 80 kΩ  862mAh
 78 kΩ  740mAh

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 bq24150a USB Battery Charger chip's abilities is to

  • plug in Nokia wallwart charger
  • ->stop bme
  • wait max 32s until bq24150a internal watchdog timer expires (due to bme not resetting it), which will cause bq24150a to reset to defaults, which are a mostly sane, safe charging without any software support. You can tell this by bq24150a 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

[edit] Replacement Goals

[edit] 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.

[edit] 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.

[edit] 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)