[openfirmware] [commit] r2063 - dev/olpc/kb3700
repository service
svn at openfirmware.info
Fri Dec 3 07:37:41 CET 2010
Author: wmb
Date: Fri Dec 3 07:37:40 2010
New Revision: 2063
URL: http://tracker.coreboot.org/trac/openfirmware/changeset/2063
Log:
XO-1.75 - added battery status reporting (checkin an additional file).
Modified:
dev/olpc/kb3700/battery.fth
Modified: dev/olpc/kb3700/battery.fth
==============================================================================
--- dev/olpc/kb3700/battery.fth Fri Dec 3 07:35:59 2010 (r2062)
+++ dev/olpc/kb3700/battery.fth Fri Dec 3 07:37:40 2010 (r2063)
@@ -25,15 +25,12 @@
h# 15 constant ec-debugflag4
: ec-ram@ ec-rambase + ec@ ;
-: wextend ( w -- n ) dup h# 8000 and if h# ffff.0000 or then ;
: rr ec@ . ;
: ww ec! ;
: bat-b@ ec-batrambase + ec@ ;
: bat-b! ec-batrambase + ec! ;
: bat-w@ dup 1+ bat-b@ swap bat-b@ bwjoin ;
: eram-w@ h# f400 + dup 1+ ec@ swap ec@ bwjoin ;
-\ Base unit for temperature is 1/256 degrees C
-: >degrees-c 7 rshift 1+ 2/ ; \ Round to nearest degree
\ : uvolt@ 0 bat-w@ d# 9760 d# 32 */ ;
\ : cur@ 2 bat-w@ wextend d# 15625 d# 120 */ ;
\ : pcb-temp 8 bat-w@ >degrees-c ;
@@ -42,126 +39,6 @@
: bat-state h# 11 bat-b@ ;
: bat-cause@ h# 70 bat-b@ ;
-: uvolt@ bat-voltage@ d# 9760 d# 32 */ ;
-: cur@ bat-current@ wextend d# 15625 d# 120 */ ;
-: pcb-temp ambient-temp@ >degrees-c ;
-: bat-temp bat-temp@ >degrees-c ;
-: soc bat-soc@ ;
-
-string-array bat-causes
-( 00) ," "
-( 01) ," Bus Stuck at Zero"
-( 02) ," Pack info"
-( 03) ," NiMH Temp"
-( 04) ," NiMH Over Voltage"
-( 05) ," NiMH Over Current"
-( 06) ," NiMH No voltage change during use"
-( 07) ," "
-( 08) ," NiMH Pre-charge fail"
-( 09) ," No Battery ID"
-( 0a) ," LiFe Over Voltage"
-( 0b) ," LiFe Over Temp"
-( 0c) ," LiFe No voltage change during use"
-( 0d) ," "
-( 0e) ," "
-( 0f) ," "
-( 10) ," ACR error"
-( 11) ," NIMH 0xFF count"
-( 12) ," FF count"
-( 13) ," Voltage Invalid"
-( 14) ," Bank 0 Invalid"
-( 15) ," Bank 1 Invalid"
-( 16) ," Bank 2 Invalid"
-end-string-array
-
-: .bat-cause ( -- )
- bat-cause@ bat-causes count type cr
-;
-
-: .bat-error .bat-cause ;
-
-string-array bat-states
- ," no-battery "
- ," charging-idle "
- ," charging-normal "
- ," charging-equalize "
- ," charging-learning "
- ," charging-temp-wait"
- ," charging-full "
- ," discharge "
- ," abnormal: "
- ," trickle "
-end-string-array
-
-: .bat-type ( -- )
- bat-type@ dup 4 rshift case ( type )
- 0 of ." " endof
- 1 of ." GPB " endof
- 2 of ." BYD " endof
- ." UnknownVendor "
- endcase ( type )
-
- h# 0f and case ( )
- 0 of ." " endof
- 1 of ." NiMH " endof
- 2 of ." LiFePO4 " endof
- ." UnknownType "
- endcase
-;
-
-: .milli ( -- )
- push-decimal
- dup abs d# 10,000 / <# u# u# [char] . hold u#s swap sign u#> type
- pop-base
-;
-
-: .mppt-active?
- h# 3d ec-cmd-b@ h# d and
- if ." MPPT" then
-;
-
-\needs 2.d : 2.d ( n -- ) push-decimal <# u# u#s u#> type pop-base ;
-: .% ( n -- ) 2.d ." %" ;
-: .bat ( -- )
- bat-status@ ( stat )
- ." AC:" dup h# 10 and if ." on " else ." off " then ( stat )
-
-\ PCB temp was nver really valid and was removed in Gen 1.5
-\ ." PCB: " pcb-temp 2.d ." C "
-
- dup h# 81 and if
- ." Battery: "
- .bat-type
- soc .% ." "
- uvolt@ .milli ." V "
- cur@ .milli ." A "
- bat-temp 2.d ." C "
- dup 2 and if ." full " then
- dup 4 and if ." low " then
- dup 8 and if ." error " then
- dup h# 20 and if ." charging " then
- dup h# 40 and if ." discharging " then
- dup h# 80 and if ." trickle " then
- else
- ." No battery "
- then
- drop
- .mppt-active?
-;
-
-: ?enough-power ( )
- bat-status@ ( stat )
- dup h# 10 and 0= abort" No external power" ( stat )
- dup 1 and 0= abort" No battery" ( stat )
- 4 and abort" Battery low"
-;
-
-: watch-battery ( -- )
- begin (cr .bat kill-line d# 1000 ms key? until
- key drop
- bat-status@ 8 and if cr .bat-error then
-;
-
\ A few commands for looking at what the EC is doing in
\ the battery state machine.
\ Unless you are on a serial console with stdout turned off
@@ -795,131 +672,7 @@
h# 10 invert and ec-debugflag4 bat-b!
;
-: mppt-off h# 40 ec-cmd ;
-: mppt-on h# 41 ec-cmd ;
-: mppt-pct 255 * 100 / h# 3f ec-cmd-b! ;
-
-: .mppt
- h# 3e ec-cmd-b@ ( pwr_limit )
- h# 42 ec-cmd-b@ ( pwr_limit VA2 )
- ." Vsa: " d# 14927 * d# 158 / >sd.ddd type ." PWM: " .
-;
-
-: watch-mppt ( -- )
- begin (cr .mppt kill-line d# 500 ms key? until
- key drop
-;
-
-
-dev /
-new-device
-" battery" device-name
-0 0 reg \ Needed so test-all will run the selftest
-
-\ Test that the battery is inserted and not broken.
-: test-battery ( -- error? )
- bat-status@ h# 01 and 0= if
- ." Insert battery to continue.. "
- begin d# 100 ms bat-status@ h# 01 and until
- cr
- then
- ." Testing battery status.. "
- bat-status@ h# 04 and if
- ." error: battery broken" cr
- true
- else
- ." ok: " cr .bat cr
- false
- then
-;
-
-: wait-no-ac ( -- error? )
- ." Disconnect AC power to continue.. "
- begin
- bat-status@ h# 10 and ( ac-connected? )
- while
- d# 100 ms
-
- key? if
- key h# 1b = if
- ." ERROR: AC still connected" cr
- true exit
- then
- then
- repeat
- cr
- false
-;
-
-\ Test that we can run without AC power.
-: test-discharging ( -- error? )
- bat-status@ h# 10 and 0<> if
- wait-no-ac if true exit then
- then
- ." Test running from battery.. "
- d# 2000 ms
- bat-status@ h# 40 and if
- ." ok: battery discharging" cr
- false
- else
- ." ERROR: battery not discharging" cr
- true
- then
-;
-
-: wait-ac ( -- error? )
- ." Connect AC power to continue.. "
- begin
- bat-status@ h# 10 and 0= ( ac-disconnected? )
- while
- d# 100 ms
-
- key? if
- key h# 1b = if
- ." ERROR: AC not connected" cr
- true exit
- then
- then
- repeat
- cr
- false
-;
-
-: test-charging ( -- error? )
- bat-status@ h# 10 and 0= if
- wait-ac if true exit then
- then
- ." Test running from AC.. "
- d# 4000 ms
- bat-status@ h# 40 and 0= if
- ." ok: battery is not discharging" cr
- false
- else
- ." ERROR: battery is discharging" cr
- true
- then
-;
-
-: interactive-test ( -- error? )
- test-battery if true exit then
- " test-station" $find if execute else 2drop 0 then ( station# )
- 1 <> if \ Skip this test in SMT
- test-discharging if true exit then
- then
- test-charging if true exit then
- false
-;
-
-: selftest ( -- error? )
- diagnostic-mode? if
- interactive-test
- else
- .bat false
- then
-;
-
-finish-device
-device-end
+fload ${BP}/dev/olpc/kb3700/batstat.fth
\ LICENSE_BEGIN
\ Copyright (c) 2006 FirmWorks
More information about the openfirmware
mailing list