Author: rsmith Date: Mon Apr 5 21:30:34 2010 New Revision: 1776 URL: http://tracker.coreboot.org/trac/openfirmware/changeset/1776
Log: Merge branch 'richard'
Modified: cpu/x86/pc/olpc/charge.fth cpu/x86/pc/olpc/via/fw.bth dev/olpc/kb3700/battery.fth
Modified: cpu/x86/pc/olpc/charge.fth ============================================================================== --- cpu/x86/pc/olpc/charge.fth Mon Apr 5 05:54:49 2010 (r1775) +++ cpu/x86/pc/olpc/charge.fth Mon Apr 5 21:30:34 2010 (r1776) @@ -2,48 +2,61 @@ \ See license at end of file
\ Need the comma to be compatible with olpc-pwr-log stuff - : >sd, - <# " ," hold$ u#s u#> + base @ >r decimal + dup abs <# " ," hold$ u#s swap sign u#> + r> base ! ;
: >sd.dd, ( n -- formatted ) base @ >r decimal - dup abs <# " ," hold$ u# u# [char] . hold u#s rot sign u#> + dup abs <# " ," hold$ u# u# [char] . hold u#s swap sign u#> r> base ! ;
-: bat-log-append ( adr len -- ) - " sd:\charge.log" $append-open \ hardcode the path for now - ftype - fcr - ofd @ fclose -; +0 value start-acr +d# 60 value (wake-delay) +d# 0 value wake-delay
+: setup-rtc-wake ( delay -- ) + 0 acpi-l@ h# 400.0000 or 0 acpi-l! + ['] noop " set-alarm" clock-node @ $call-method +;
-0 value start-acr -d# 15 value wake-delay +: finish-rtc-wake ( -- ) 0 acpi-l@ h# 400.0000 invert and 0 acpi-l! ;
: bat-charge-dataf@ - base @ >r decimal 0 logstr c! time&date >unix-seconds >sd, logstr $cat soc >sd, logstr $cat - uvolt@ dup >sd, logstr $cat 100 / ( V__.1mV ) - cur@ dup >sd, logstr $cat 100 / ( V_.1mV I__.1mA ) - * drop ( W_mW ) - bat-temp >sd, logstr $cat - bat-acr@ s16>s32 dup >sd, logstr $cat + uvolt@ dup >sd, logstr $cat + cur@ dup >sd, logstr $cat + bat-temp >sd, logstr $cat + bat-acr@ s16>s32 dup >sd, logstr $cat start-acr - bg-acr>mAh >sd.dd, logstr $cat - r> base ! ;
-: bat-charge-log ( -- ) - " sd:\charge.log" $new-file \ Make sure the file exists and is empty. +h# 100 buffer: fname-buf + +: charge-log-append ( adr len -- ) + fname-buf $append-open + ftype + fcr + ofd @ fclose +; + +: charge-log ( "filename" -- ) \ filename is optional + ['] safe-parse-word catch if + fname-buf place + else + " sd:\charge.log" fname-buf place + then + ." Logging to: " fname-buf count type cr + fname-buf $new-file ofd @ fclose
- " chg_log Ver: 1.0" bat-log-append - " <StartData>" bat-log-append \ This makes us compatible with the processing scripts for use with olpc-pwr-log + " chg_log Ver: 1.0" charge-log-append + " <StartData>" charge-log-append \ This makes us compatible with the processing scripts for use with olpc-pwr-log
\ Allow for suspend to be super low power dcon-power-off @@ -53,17 +66,48 @@ bat-acr@ s16>s32 to start-acr begin bat-charge-dataf@ + \ Even though we have no screen still do console output + \ So it shows up on the serial port. logstr count type cr - logstr count bat-log-append - 0 acpi-l@ h# 400.0000 or 0 acpi-l! \ Enable RTC SCI - ['] noop wake-delay " set-alarm" clock-node @ $call-method + logstr count charge-log-append + wake-delay setup-rtc-wake + \ We don't want to do video restore. Only usb + suspend-usb s3 - 0 0 acpi-l! \ Disable RTC SCI + resume-usb + finish-rtc-wake key? until key drop ;
+: watch-charge ( -- ) + \ 5 seconds is the default unless the user sets wake-delay + wake-delay 0= if + d# 5 to (wake-delay) + ." Using default delay" cr + ." Set wake-delay fo a different value" cr + else + wake-delay to (wake-delay) + then + (wake-delay) + ." Sampling every " .d ." seconds" cr + sci-wakeup + bat-acr@ s16>s32 to start-acr + begin + bat-charge-dataf@ + logstr count type cr
+\ wake-delay setup-rtc-wake +\ s3-suspend +\ finish-rtc-wake + +\ RTC wake seems flaky. +\ use EC for now (only works on 1.5) + (wake-delay) d# 1000 * h# 36 ec-cmd-l! + s3-suspend + key? + until key drop +; \ LICENSE_BEGIN \ Copyright (c) 2007 FirmWorks \
Modified: cpu/x86/pc/olpc/via/fw.bth ============================================================================== --- cpu/x86/pc/olpc/via/fw.bth Mon Apr 5 05:54:49 2010 (r1775) +++ cpu/x86/pc/olpc/via/fw.bth Mon Apr 5 21:30:34 2010 (r1776) @@ -719,12 +719,25 @@ quit ;
+: enable-serial ( -- ) + serial-enabled? if exit then + + h# 40 h# 8846 config-b! + " com1" open-dev dup to fallback-in-ih add-input + " com1" open-dev dup to fallback-out-ih add-output +; +: disable-serial + fallback-in-ih ?dup if remove-input then + fallback-out-ih ?dup if remove-output then +; + : newrom + enable-serial " flash! http:\10.20.0.14\new.rom" eval \ " wifi media lab 802.11" eval \ " flash http:\18.85.46.172\new.rom" eval ; -: urom " flash! u:\new.rom" eval ; +: urom enable-serial " flash! u:\new.rom" eval ; : no-usb-delay " dev /usb false to delay? dend" evaluate ; : null-fsdisk " dev /null : write-blocks-start 3drop ; : write-blocks-finish ; dend" evaluate @@ -741,18 +754,6 @@ warning ! previous previous definitions
-: enable-serial ( -- ) - serial-enabled? if exit then - - h# 40 h# 8846 config-b! - " com1" open-dev dup to fallback-in-ih add-input - " com1" open-dev dup to fallback-out-ih add-output -; -: disable-serial - fallback-in-ih ?dup if remove-input then - fallback-out-ih ?dup if remove-output then -; - tag-file @ fclose tag-file off
.( --- Saving fw.dic ...)
Modified: dev/olpc/kb3700/battery.fth ============================================================================== --- dev/olpc/kb3700/battery.fth Mon Apr 5 05:54:49 2010 (r1775) +++ dev/olpc/kb3700/battery.fth Mon Apr 5 21:30:34 2010 (r1776) @@ -110,6 +110,12 @@ 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 ( -- ) @@ -133,9 +139,10 @@ dup h# 40 and if ." discharging " then dup h# 80 and if ." trickle " then else - ." No battery" + ." No battery " then drop + .mppt-active? ;
: ?enough-power ( ) @@ -157,17 +164,6 @@ \ (stdout off) this will miss some state changes. \
-: .mppt - ec-pwr_limit ec-ram@ ( pwr_limit ) - ec-rambase ec-va2 + ecw@ ( pwr_limit VA2 ) - ." VA2: " .d ." PWM: " . -; - -: watch-mppt ( -- ) - begin (cr .mppt kill-line d# 500 ms key? until - key drop -; - : next-bstate begin f780 ec@ tuck <> @@ -442,6 +438,28 @@ d# 16 << d# 16 >>a ;
+: >sd + base @ >r decimal + dup abs <# u#s swap sign u#> + r> base ! +; + +: >sdx + <# " " hold$ u#s " 0x" hold$ u#> +; + +: >sd.ddd ( n -- formatted ) + base @ >r decimal + dup abs <# u# u# u# [char] . hold u# u#s swap sign u#> + r> base ! +; + +: >sd.dd ( n -- formatted ) + base @ >r decimal + dup abs <# u# u# [char] . hold u# u#s swap sign u#> + r> base ! +; + : bat-save ( -- ) " disk:\battery.dmp" 2dup ['] $delete catch if 2drop then ( name$ ) @@ -533,6 +551,42 @@ 1w-reset ;
+\ Retrieve the key battery stats in bulk and put it on the stack +\ sign extending the values that are 2's complement. +: bg-charge-info@ + ds-bank-buf 6 h# 0c 1w-read ( ) + ds-bank-buf c@ 8 << ( voltage_msb ) + ds-bank-buf 1 + c@ or s16>s32 ( voltage ) + ds-bank-buf 2 + c@ 8 << ( voltage current_msb ) + ds-bank-buf 3 + c@ or s16>s32 ( voltage current ) + ds-bank-buf 4 + c@ 8 << ( voltage current ACR_msb ) + ds-bank-buf 5 + c@ or s16>s32 ( voltage current ACR ) +; + +: bg-net-addr@ + 1w-reset + h# 33 1w-write-byte + 1w-read-byte + 0 7 bounds ?do 1w-read-byte loop +; + +: bg-acr>mAh ( raw-value -- acr_in_mAh ) + d# 625 ( mV ) * d# 15 ( mOhm ) / +; + +: bg-V>V ( raw-value - V_in_mV ) + d# 488 ( mV ) * 2* d# 100 / 5 >> +; + +: bg-I>mA ( raw-value -- I_in_mA ) + 3 >>a + d# 15625 ( nV ) * d# 15 ( mOhm ) / d# 10 / +; + +: bg-temp>degc ( raw-value -- temp_in_degc ) + d# 125 * d# 10 / 5 >> +; + : .bg-eeprom base @ >r decimal @@ -548,6 +602,40 @@ r> base ! ;
+: .bg-acr ( raw_acr_in_s32 -- ) + bg-acr>mAh >sd.dd type +; + +: .bg-current ( raw_I_in_s32 -- ) + bg-I>mA >sd.dd type +; + +: .bg-volt ( raw_V_in_s32 -- ) + bg-V>V >sd.ddd type +; + +: .bg-net-addr ( -- ) + bg-net-addr@ + 0 8 bounds ?do . loop cr +; + +0 value bg-last-acr +0 value bg-v_avg + +: bg-watch ( -- ) + bg-acr@ + begin + bg-charge-info@ + dup to bg-last-acr + ." ACR:" .bg-acr ." I:" .bg-current ." V:" .bg-volt + dup bg-last-acr swap - ." Chg:" .bg-acr + cr + 500 ms + key? + until + drop +; + : bat-set-default-status ( val -- ) ds-bank0 1w-recall ds-default-status 1w-write-start @@ -573,55 +661,7 @@ then ;
-\ Retrieve the key battery stats in bulk and put it on the stack -\ sign extending the values that are 2's complement. -: bg-charge-info@ - ds-bank-buf 6 h# 0c 1w-read ( ) - ds-bank-buf c@ 8 << ( voltage_msb ) - ds-bank-buf 1 + c@ or s16>s32 ( voltage ) - ds-bank-buf 2 + c@ 8 << ( voltage current_msb ) - ds-bank-buf 3 + c@ or s16>s32 ( voltage current ) - ds-bank-buf 4 + c@ 8 << ( voltage current ACR_msb ) - ds-bank-buf 5 + c@ or s16>s32 ( voltage current ACR ) -; - -: >sd.ddd ( n -- formatted ) - base @ >r decimal - dup abs <# u# u# u# [char] . hold u# u#s swap sign u#> - r> base ! -; - -: >sd.dd ( n -- formatted ) - base @ >r decimal - dup abs <# u# u# [char] . hold u# u#s swap sign u#> - r> base ! -; - -: bg-acr>mAh ( raw-value -- acr_in_mAh ) - d# 625 ( mV ) * d# 15 ( mOhm ) / -; - -: bg-V>V ( raw-value - V_in_mV ) - d# 488 ( mV ) * 2* d# 100 / 5 >> -; - -: bg-I>mA ( raw-value -- I_in_mA ) - 3 >>a - d# 15625 ( nV ) * d# 15 ( mOhm ) / d# 10 / -; - -: bg-temp>degc ( raw-value -- temp_in_degc ) - d# 125 * d# 10 / 5 >> -; - h# 90 buffer: logstr -: >sd - <# " " hold$ u#s u#> -; - -: >sdx - <# " " hold$ u#s " 0x" hold$ u#> -;
\ Read values directly rather than using the ec-cmd
@@ -685,35 +725,6 @@ r> base ! ;
-: .bg-acr ( raw_acr_in_s32 -- ) - bg-acr>mAh >sd.dd type -; - -: .bg-current ( raw_I_in_s32 -- ) - bg-I>mA >sd.dd type -; - -: .bg-volt ( raw_V_in_s32 -- ) - bg-V>V >sd.ddd type -; - -0 value bg-last-acr -0 value bg-v_avg - -: bg-watch ( -- ) - bg-acr@ - begin - bg-charge-info@ - dup to bg-last-acr - ." ACR:" .bg-acr ." I:" .bg-current ." V:" .bg-volt - dup bg-last-acr swap - ." Chg:" .bg-acr - cr - 500 ms - key? - until - drop -; - : bat-debug begin bat-lfp-dataf@ @@ -737,7 +748,7 @@ ;
-: bat-charge ( -- ) +: bat-force-charge ( -- ) batman-init? bat-enable-charge bg-acr@ @@ -774,6 +785,22 @@ 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
openfirmware@openfirmware.info