This is a follow on to my previous two posts Power managment on Beaglebone AM335x platform part 1 and Power management on Beaglebone part 2-Battery for the community IoT BSP at BeagleBone BSP.

The first two parts I discussed the background of battery support and some of the hardware modifications that are needed for the BeagleBone Black platform. I also talked about the AM335x’s on chip analog to digital converter (A/D or ADC) and how it can be used to measure voltage signals like battery voltage. We developed an A/D converter driver and test program and integrated it into the BSP.

The next step in the process is to pull it altogether by developing a battery driver. The battery driver will, of course, be dependent on the A/D driver so we must make sure the A/C driver is loaded first. We can do this by modifying the drivers “Order” setting. For example here are the ADC registry setting:

IF BSP_AM33X_ADC
[HKEY_LOCAL_MACHINE\Drivers\BuiltIn\ADC1]
    "Prefix"="ADC"
    "Dll"="am33x_adc"
    "Index"=dword:1
   "order"=dword:9                ; Should be loaded before battery or touch
ENDIF BSP_AM33X_ADC

And here are the battery drivers:

; @CESYSGEN IF CE_MODULES_BATTDRVR
; @CESYSGEN IF PM_PMSTUBS !
IF BSP_BATTERY

; HIVE BOOT SECTION
[HKEY_LOCAL_MACHINE\System\Events]
    "SYSTEM/BatteryAPIsReady"="Battery Interface APIs"
; END HIVE BOOT SECTION
[HKEY_LOCAL_MACHINE\Drivers\BuiltIn\Battery]
    "Prefix"="BAT"
    "Dll"="battdrvr.dll"
    "Flags"=dword:8                    ; DEVFLAGS_NAKEDENTRIES
    "Index"=dword:1
    "Order"=dword:13         
    "Ioctl"=dword:290418            ; IOCTL to use for PostInit callback
;    "PollInterval"=dword:7d0        ; Battery poll interval (ms) ..default 5 sec if not specified
;    "BatADCchannel"=dword:6            ; CHANNEL_6  ..default if not specified
    "BatHigh"=dword:dac                ; 3500 mv
    "BatLow"=dword:d48                ; 3400
    "IClass"="{DD176277-CD34-4980-91EE-67DBEF3D8913}"    ; WM7 only BATTERY_DRIVER_CLASS

; do not show low battery dialog
;[HKEY_LOCAL_MACHINE\Software\Microsoft\Power]
;    "ShowWarnings"= dword:0

; @CESYSGEN IF PM_PM_DEFAULT_PDD
[HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Power\Timeouts]
    "ACUserIdle"=dword:0        ; in seconds
    "ACSystemIdle"=dword:0        ; in seconds
    "ACSuspend"=dword:0            ; in seconds
    "BattUserIdle"=dword:0        ; in seconds
    "BattSystemIdle"=dword:0    ; in seconds
    "BattSuspend"=dword:0        ; in seconds

; Make sure the system power management thread runs at a higher priority than
; driver ISTs (PWRKEY) that may call SetSystemPowerState().  This is to avoid race conditions
; between the PM and drivers or applications that may want to update the system power
; state.  Most drivers don't run above THREAD_PRIORITY_HIGHEST (249); if any that
; might call SetSystemPowerState() have a higher priority than this, adjust
; the PM's SystemPriority256 value accordingly.
;
[HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Power]
        "SystemPriority256"=dword:F8                    ; 248 - THREAD_PRIORITY_TIME_CRITICAL
; @CESYSGEN ENDIF PM_PM_DEFAULT_PDD

ENDIF BSP_BATTERY
; @CESYSGEN ENDIF PM_PMSTUBS !
; @CESYSGEN ENDIF CE_MODULES_BATTDRVR

We can also set different timeouts, based on state as you can see.

You can down load the source from the Codeplex site and study the actual implementation.

When done correctly the UI shell in WEC2013 or the taskbar in WEC7 should look like the following depending on battery state.

WEC2013 running on battery:

bat8 1

WEC2013 charging:

bat8 4

 

WEC2013 fully charged AC still plugged in:

bat8 3

 

WEC2013 AC only, no battery:

bat8 2

 

 

And the equivalent WEC7 taskbar icons:

 

Charging:

batchrg7

 

Running on AC:

batplug7

 

WEC7 Control Panel power status:

cectrlbat

 

I also wrote a simple managed (C#) test program which shows the charger status and measured system voltages:

batapp