source: dev/olpc/kb3700/eccmds.fth

Last change on this file was 3509, checked in by quozl, 16 months ago

OLPC XO-1.75 XO-4 - bat-status@ gave an EC command result timeout on XO-1.75, caused by EC API version being treated as cross-platform when it should not have been. XO-4 no longer needs EC API version 4 support, so remove it.

File size: 4.5 KB
Line 
1\ See license at end of file
2purpose: EC Commands for XO-1.75 and later
3
40 value ec-ih
5: $call-ec  ( ... adr len -- ... )  ec-ih $call-method  ;
6: do-ec-cmd  ( [ args ] #args #results cmd-code -- [ results ] )
7   " ec-command" $call-ec
8;
9: do-ec-cmd-buf  ( [ args ] #args #results cmd-code -- buf-adr )
10   " ec-command-buf" $call-ec
11;
12: open-ec  ( -- )
13   ec-ih  0=  if  " /ec-spi" open-dev to ec-ih  then
14;
15: close-ec  ( -- )
16   ec-ih  if  ec-ih close-dev  0 to ec-ih  then
17;
18stand-init: EC
19   open-ec
20;
21
22: too-many-retries  ( -- )  true abort" Too many EC command retries"  ;
23d# 10 constant #ec-retries
24
25: ec-cmd  ( cmd -- )   0 0 rot do-ec-cmd  ;
26: ec-cmd-b@  ( cmd -- b )   0 1 rot do-ec-cmd          ;
27: ec-cmd-w@  ( cmd -- w )   0 2 rot do-ec-cmd  bwjoin  ;
28: ec-cmd-l@  ( cmd -- l )   0 4 rot do-ec-cmd  bljoin  ;
29: ec-cmd-b!  ( b cmd -- )   1 0 rot do-ec-cmd  ;
30: ec-cmd-w!  ( w cmd -- )   >r wbsplit 2 0 r> do-ec-cmd  ;
31: ec-cmd-l!  ( l cmd -- )   >r lbsplit 4 0 r> do-ec-cmd  ;
32
33fload ${BP}/dev/olpc/kb3700/eccmdcom.fth  \ Common commands
34
35\ Commands that are different for XO-1.75
36: board-id@      ( -- n )  h# 19 ec-cmd-w@  ;
37: bat-cause@     ( -- b )  h# 1f ec-cmd-b@  ;
38
39: (bat-gauge-id@)  ( -- sn0 .. sn7 )  0 8 h# 17 do-ec-cmd  ;
40: bat-gauge-id@  ( -- sn0 .. sn7 )
41   #ec-retries  0  do
42      ['] (bat-gauge-id@) catch  0=  if  unloop exit  then
43   loop
44   too-many-retries
45;
46
47: bat-type@  ( -- b )  h# 2c ec-cmd-b@  ;
48
49: ec-wackup  ( ms -- )  lbsplit 4 0 h# 36 do-ec-cmd  ;
50
51: bat-gauge@  ( -- w )  h# 4e ec-cmd-w@  ;
52
53: cscount-max  ( adr maxlen -- adr len )
54   dup 0  ?do        ( adr maxlen )
55      over i + c@ 0=  if
56         drop i unloop exit
57      then
58   loop
59;
60: ec-name$  ( -- adr len )
61   0 d# 16 h# 4a do-ec-cmd-buf   ( adr )
62   d# 16 cscount-max
63;
64
65: ec-power-cycle ( -- ) h# 4b ec-cmd ;
66: ec-power-off   ( -- ) h# 4c ec-cmd ;
67
68: ec-echo  ( ... n -- ... )  dup h# 52 do-ec-cmd  ;
69
70: ec-date$  ( -- adr len )
71   0 d# 16 h# 53 do-ec-cmd-buf   ( adr )
72   d# 16 cscount-max
73;
74
75: ec-user$  ( -- adr len )
76   0 d# 16 h# 54 do-ec-cmd-buf   ( adr )
77   d# 16 cscount-max
78;
79
80: ec-hash$  ( -- adr len )
81   0 d# 16 h# 64 do-ec-cmd-buf   ( adr )
82   d# 16 cscount-max
83;
84
85: als@              ( -- w )  h# 56 ec-cmd-w@  ;
86: ols-led-on          ( -- )  h# 57 ec-cmd  ;
87: ols-led-off         ( -- )  h# 58 ec-cmd  ;
88: ols-led-ec-control  ( -- )  h# 5b ec-cmd  ;
89: ols-assy-mode-on    ( -- )  h# 59 ec-cmd  ;
90: ols-assy-mode-off   ( -- )  h# 5a ec-cmd  ;
91
92: ec-min-pwr  ( -- n )  h# 5d ec-cmd-w@ w->n  ;
93: ec-max-pwr  ( -- n )  h# 5e ec-cmd-w@ w->n  ;
94: ec-rst-pwr  ( -- )    h# 5f ec-cmd  ;
95: ec-sus-pwr  ( -- n )  h# 6d ec-cmd-w@ w->n  ;
96
97: ec-hub-pwr  ( b -- ) h# 6e ec-cmd-b! ;
98
99
100[ifdef] notdef  \ These commands are awaiting documentation on their interfaces
101#define CMD_READ_EXT_SCI_MASK            0x37
102#define CMD_WRITE_EXT_SCI_MASK           0x38
103#define CMD_CLEAR_EC_WAKEUP_TIMER        0x39
104#define CMD_ENABLE_RUNIN_DISCHARGE       0x3B
105#define CMD_DISABLE_RUNIN_DISCHARGE      0x3C
106#define CMD_EXT_SCI_QUERY                0x43
107#define CMD_READ_LOCATION                0x44
108#define CMD_WRITE_LOCATION               0x45
109#define RSP_KEYBOARD_DATA                0x48
110#define RSP_TOUCHPAD_DATA                0x49
111#define CMD_RESET_EC_SOFT                0x4d
112#define CMD_ENABLE_MOUSE                 0x4f
113[then]
114
115\ Commands that are different for XO-4
116
117[ifdef] olpc-xo4
118: bat-status16@  ( -- w )  h# 70 ec-cmd-w@  ;
119' bat-status16@  is bat-status@
120[then]
121
122\ LICENSE_BEGIN
123\ Copyright (c) 2010 FirmWorks
124\
125\ Permission is hereby granted, free of charge, to any person obtaining
126\ a copy of this software and associated documentation files (the
127\ "Software"), to deal in the Software without restriction, including
128\ without limitation the rights to use, copy, modify, merge, publish,
129\ distribute, sublicense, and/or sell copies of the Software, and to
130\ permit persons to whom the Software is furnished to do so, subject to
131\ the following conditions:
132\
133\ The above copyright notice and this permission notice shall be
134\ included in all copies or substantial portions of the Software.
135\
136\ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
137\ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
138\ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
139\ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
140\ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
141\ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
142\ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
143\
144\ LICENSE_END
Note: See TracBrowser for help on using the repository browser.