Author: wmb
Date: Tue Mar 12 08:47:44 2013
New Revision: 3601
URL: http://tracker.coreboot.org/trac/openfirmware/changeset/3601
Log:
OLPC touchscreen test - linearity test improvements requested by manufacturing team.
Modified:
cpu/arm/olpc/nn-touchscreen.fth
Modified: cpu/arm/olpc/nn-touchscreen.fth
==============================================================================
--- cpu/arm/olpc/nn-touchscreen.fth Fri Mar 8 21:43:38 2013 (r3600)
+++ cpu/arm/olpc/nn-touchscreen.fth Tue Mar 12 08:47:44 2013 (r3601)
@@ -900,6 +900,8 @@
until drop ( )
;
+d# 50 value #skip \ Number of initial points to ignore for line
+0 value skipping? \ Current skip count
: ev(
configure
cursor-off
@@ -908,6 +910,7 @@
blacken
.tsmsg
-1 to remaining
+ #skip to skipping?
;
: )ev
@@ -940,7 +943,7 @@
: +w@ ( adr index -- w ) wa+ w@ ;
: +w! ( w adr index -- ) wa+ w! ;
-: add-pt ( w.x w.y -- )
+: add-pt ( w.x w.y -- )
#pts #pts-max u< if
ybuf #pts +w!
xbuf #pts +w!
@@ -1024,7 +1027,10 @@
swap - -rot ( intercept num den )
;
-: do-point ( x y -- ) 2dup add-pt dot ;
+: do-point ( x y -- )
+ skipping? ?dup if 1- to skipping? 2drop exit then
+ 2dup add-pt dot
+;
\ draw line across screen from left to right
: line-in-x ( intercept num den -- )
@@ -1044,7 +1050,7 @@
screen-h 0 do ( den num intercept )
3dup i swap - ( den num intercept den num y-b )
-rot */ ( den num intercept point-x )
- dup 1 screen-w within if ( den num intercept point-y )
+ dup 1 screen-w within if ( den num intercept point-x )
i dot ( den num intercept )
else ( den num intercept point-y )
drop ( den num intercept )
@@ -1058,6 +1064,7 @@
;
0 value err2
+0 [if]
: nonlinearity ( intercept num den -- mean-sq-nonlinearity )
0 to err2 ( intercept num den )
#pts 0 ?do ( intercept num den )
@@ -1071,6 +1078,66 @@
3drop ( )
err2 #pts / ( Serror2/#pts )
;
+[then]
+
+0 value this-#pts
+: short-nonlinearity ( intercept num den index #pts -- mean-sq-nonlinearity )
+ dup to this-#pts ( intercept num den index #pts )
+ 0 to err2 ( intercept num den index #pts )
+ bounds ?do ( intercept num den )
+ 3dup ( intercept num den intercept num den )
+ xbuf i +w@ ( intercept num den intercept num den x )
+ -rot */ + ( intercept num den predicted-y )
+ ybuf i +w@ - ( intercept num den error )
+ dup * ( intercept num den error^2 )
+ err2 + to err2 ( intercept num den )
+ loop ( intercept num den )
+ 3drop ( )
+ err2 this-#pts / ( Serror2/#pts )
+;
+
+: overall-nonlinearity ( intercept num den -- mean-sq )
+ 0 #pts short-nonlinearity
+;
+
+0 value nl-max 0 value nl-loc
+d# 60 value nl-span
+d# 30 value nl-stride
+: max-nonlinearity ( intercept num den -- nl )
+ 0 to nl-max ( intercept num den )
+ 0 to nl-loc
+ #pts 0 do ( intercept num den )
+ i nl-span + #pts > ?leave ( intercept num den )
+ 3dup i nl-span short-nonlinearity ( intercept num den nl )
+ dup nl-max > if ( intercept num den nl )
+ to nl-max i to nl-loc ( intercept num den )
+ else ( intercept num den nl )
+ drop ( intercept num den )
+ then ( intercept num den )
+ nl-stride +loop ( intercept num den )
+ 3drop nl-max ( nl )
+;
+: color-nl ( color -- )
+ pixcolor !
+ nl-loc nl-span bounds ?do
+ xbuf i +w@ ybuf i +w@ dot
+ loop
+;
+: erase-remainder ( -- )
+ #pts 0 do
+ i nl-loc dup nl-span + within 0= if
+ black pixcolor !
+ xbuf i +w@ ybuf i +w@ dot
+ then
+ loop
+;
+: show-nonlinearity ( -- )
+ erase-remainder
+ d# 8 0 do
+ yellow color-nl d# 500 ms
+ magenta color-nl d# 500 ms
+ loop
+;
\ TODO:
\ 1) Message and retry if slope and intercept not approximately correct
@@ -1082,14 +1149,19 @@
: scribble
alloc-bufs
- ev(
- 0 d# 27 at-xy ." Follow the line. Type a key to exit" cr
- screen-h 6 - screen-h negate screen-w blue draw-line
- ['] do-point ev
+ begin ev(
+ 0 to #pts
+ 0 d# 27 at-xy ." Follow the line. Type a key to exit " cr
+ screen-h 6 - screen-h negate screen-w blue draw-line
+ ['] do-point ev
+ #pts d# 500 < while
+ 0 d# 27 at-xy ." Too few points. Draw the line slowly" cr
+ d# 2000 ms
+ repeat
linear-least-squares ( intercept num den )
3dup red draw-line ( intercept num den )
- ." Nonlinearity: " nonlinearity .d cr
- d# 5000 ms
+ ." Nonlinearity: " max-nonlinearity .d cr
+ show-nonlinearity
)ev
free-bufs
;
Author: wmb
Date: Fri Mar 8 03:22:11 2013
New Revision: 3598
URL: http://tracker.coreboot.org/trac/openfirmware/changeset/3598
Log:
Neonode touchscreen - added nonlinearity test.
Modified:
cpu/arm/olpc/nn-touchscreen.fth
Modified: cpu/arm/olpc/nn-touchscreen.fth
==============================================================================
--- cpu/arm/olpc/nn-touchscreen.fth Thu Mar 7 10:10:51 2013 (r3597)
+++ cpu/arm/olpc/nn-touchscreen.fth Fri Mar 8 03:22:11 2013 (r3598)
@@ -916,11 +916,188 @@
['] (.tsmsg) to .tsmsg
;
+\ Nonlinearity test
+
+d# 2000 constant #pts-max
+
+#pts-max /w* value /buf
+0 value xbuf
+0 value ybuf
+0 value #pts
+
+: alloc-bufs ( -- )
+ /buf alloc-mem to xbuf
+ /buf alloc-mem to ybuf
+ 0 to #pts
+;
+
+: free-bufs ( -- )
+ xbuf /buf free-mem
+ ybuf /buf free-mem
+ 0 to #pts
+;
+
+: +w@ ( adr index -- w ) wa+ w@ ;
+: +w! ( w adr index -- ) wa+ w! ;
+
+: add-pt ( w.x w.y -- )
+ #pts #pts-max u< if
+ ybuf #pts +w!
+ xbuf #pts +w!
+ #pts 1+ to #pts
+ else
+ 2drop
+ then
+;
+
+: list-pts ( -- )
+ #pts 0 ?do
+ i . ." : " xbuf i +w@ . ybuf i +w@ . cr
+ loop
+;
+
+: sum-over ( buf size -- sum )
+ 0 -rot /w* bounds ?do ( sum )
+ i w@ + ( sum' )
+ /w +loop ( sum )
+;
+
+\ Maximum values, assuming max-x = 1200, max-y = 900, #pts = 2000
+\ max-x2 = 1200 * 1200 = 1,440,000
+\ max-xy = 1200 * 900 = 1,080,000
+\ max-Sx = 1200 * 2000 = 2,400,000
+\ max-Sy = 900 * 2000 = 1,800,000
+\ max-Sx2 = max-x2 * 2000 = 2,880,000,000
+\ max-Sxy = max-xy * 2000 = 2,160,000,000
+
+\ The max value for the denominator Sx2 - (Sx)2/n occurs when
+\ half the samples are 0 and the other half are max-x
+\ max-denom = max-Sx2 / 4 = 720,000,000
+
+\ A similar argument applies to the numerator, except that it
+\ can be either negative or positive. But its maximum absolute
+\ value is of the same order of magnitude as max-denom
+
+\ calculate the sum over x^2 (a double int)
+\ The maximum value is max-x * max-x * #pts
+\ For max-x = 1200 and #pts = 2000, max-Sx2 is 2,880,000,000
+: sum-x2 ( -- Sx2 )
+ 0 #pts 0 ?do ( Sx2 )
+ xbuf i +w@ ( Sx2 x )
+ dup u* + ( Sx2' )
+ loop ( Sx2 )
+;
+
+\ calculate the sum over xy (a double int)
+: sum-xy ( -- Sxy )
+ 0 #pts 0 ?do ( S )
+ xbuf i +w@ ( S x )
+ ybuf i +w@ ( S x y )
+ u* + ( S' )
+ loop ( S )
+;
+
+0 value sum-x
+0 value sum-y
+: linear-least-squares ( -- intercept num den )
+ xbuf #pts sum-over to sum-x
+ ybuf #pts sum-over to sum-y
+
+ \ Slope numerator: SUM(xy) - (SUM(x)*SUM(y) / #pts)
+
+ \ Sx max is #pts * xmax
+ \ Sy max is #pts * ymax
+ \ (Sx * Sy)/#pts max is xmax * ymax * #pts
+ sum-x sum-y #pts */ ( Sx*Sy/#pts )
+ sum-xy swap - ( num )
+
+ \ Slope denominator: SUM(x^2) - (SUM(x)^2 / #pts)
+ sum-x sum-x #pts */ ( num Sx*Sx/#pts )
+ sum-x2 swap - ( num den )
+ \ Avoid division by 0
+ dup 0= if 1+ then ( num den )
+
+ \ Calculate the intercept
+ 2dup sum-x #pts / -rot */ ( num den slope*Sx )
+
+ sum-y #pts / ( num den slope*Sx mean-y )
+ swap - -rot ( intercept num den )
+;
+
+: do-point ( x y -- ) 2dup add-pt dot ;
+
+\ draw line across screen from left to right
+: line-in-x ( intercept num den -- )
+ screen-w 0 do ( intercept num den )
+ 3dup i -rot */ + ( intercept num den point-y )
+ dup 1 screen-h within if ( intercept num den point-y )
+ i swap dot ( intercept num den )
+ else ( intercept num den point-y )
+ drop ( intercept num den )
+ then ( intercept num den )
+ loop ( intercept num den )
+ 3drop ( )
+;
+\ draw line from top to bottom of screen
+: line-in-y ( intercept num den -- )
+ swap rot ( den num intercept )
+ screen-h 0 do ( den num intercept )
+ 3dup i swap - ( den num intercept den num y-b )
+ -rot */ ( den num intercept point-x )
+ dup 1 screen-w within if ( den num intercept point-y )
+ i dot ( den num intercept )
+ else ( den num intercept point-y )
+ drop ( den num intercept )
+ then ( den num intercept )
+ loop ( den num intercept )
+ 3drop ( )
+;
+: draw-line ( intercept num den color -- )
+ pixcolor ! ( intercept num den )
+ 2 pick abs 2 pick abs > if line-in-y else line-in-x then
+;
+
+0 value err2
+: nonlinearity ( intercept num den -- mean-sq-nonlinearity )
+ 0 to err2 ( intercept num den )
+ #pts 0 ?do ( intercept num den )
+ 3dup ( intercept num den intercept num den )
+ xbuf i +w@ ( intercept num den intercept num den x )
+ -rot */ + ( intercept num den predicted-y )
+ ybuf i +w@ - ( intercept num den error )
+ dup * ( intercept num den error^2 )
+ err2 + to err2 ( intercept num den )
+ loop ( intercept num den )
+ 3drop ( )
+ err2 #pts / ( Serror2/#pts )
+;
+
+\ TODO:
+\ 1) Message and retry if slope and intercept not approximately correct
+\ slope can be checked with
+\ ( num den ) h# 10000 -rot */ LOW HIGH within
+\ ( expected slope is negative , so LOW and HIGH are negative )
+\ 2) Establish threshold for nonlinearity and fail if exceeded
+\ 3) Perhaps integrate the nonlinearity test with the targets test?
: scribble
- ev( ['] dot ev )ev
+ alloc-bufs
+ ev(
+ 0 d# 27 at-xy ." Follow the line. Type a key to exit" cr
+ screen-h 6 - screen-h negate screen-w blue draw-line
+ ['] do-point ev
+ linear-least-squares ( intercept num den )
+ 3dup red draw-line ( intercept num den )
+ ." Nonlinearity: " nonlinearity .d cr
+ d# 5000 ms
+ )ev
+ free-bufs
;
+\ : scribble
+\ ev( ['] dot ev )ev
+\ ;
+
0 value dx
0 value dy
Author: rsmith
Date: Thu Mar 7 10:10:51 2013
New Revision: 3597
URL: http://tracker.coreboot.org/trac/openfirmware/changeset/3597
Log:
Revert -mlittle-endian removal in r3596
The _real_ problem was user error. I was trying to compile the arm
execuatable with an x86 compiler. -mlittle-endian is a perfectly
valid option for the arm-elf-gcc compiler. Thankfully its the default
so the removal didn't actually cause a problem.
Same sort of thing for the xinflate change in r3596 but I didn't
revert that becuase it does make it clearer whats going on and that
there are 2 versions of the inflate object.
Modified:
cpu/arm/Linux/Makefile
Modified: cpu/arm/Linux/Makefile
==============================================================================
--- cpu/arm/Linux/Makefile Thu Mar 7 09:42:59 2013 (r3596)
+++ cpu/arm/Linux/Makefile Thu Mar 7 10:10:51 2013 (r3597)
@@ -2,8 +2,7 @@
BP=../../..
-CFLAGS = -O -DARM
-# -mlittle-endian
+CFLAGS = -O -DARM -mlittle-endian
WRTAIL = forth/wrapper
WRDIR = ${BP}/${WRTAIL}
Author: rsmith
Date: Thu Mar 7 09:42:59 2013
New Revision: 3596
URL: http://tracker.coreboot.org/trac/openfirmware/changeset/3596
Log:
arm/Linux/Makefile fixup for arm-elf-gcc 3.4.3
- Remove use of -mlittle-endian as it made gcc error.
- Use different rules for building the two different versions of inflate.o / xinflate.o - one to use in the wrapper, the other for standalone use in OFW images. Fixes the "ld: error in inflate.o(.eh_frame); no .eh_frame_hdr table will be created" message.
Modified:
cpu/arm/Linux/Makefile
Modified: cpu/arm/Linux/Makefile
==============================================================================
--- cpu/arm/Linux/Makefile Thu Mar 7 09:17:32 2013 (r3595)
+++ cpu/arm/Linux/Makefile Thu Mar 7 09:42:59 2013 (r3596)
@@ -2,7 +2,8 @@
BP=../../..
-CFLAGS = -O -DARM -mlittle-endian
+CFLAGS = -O -DARM
+# -mlittle-endian
WRTAIL = forth/wrapper
WRDIR = ${BP}/${WRTAIL}
@@ -13,7 +14,7 @@
OBJS = wrapper.o logger.o ${ZIPOBJS}
-all: forth inflate.bin
+all: forth ../build/inflate.bin
# Use forth when you just need to run Forth but don't care what
# native instruction set it is on.
@@ -30,13 +31,13 @@
armforth.static: ${OBJS}
${CC} ${CFLAGS} ${LFLAGS} -static -o $@ ${OBJS}
-inflate.lo: ${ZIPDIR}/inflate.c
+xinflate.lo: ${ZIPDIR}/inflate.c
${CC} -c ${CFLAGS} -O $< -o $@
-inflate.o: inflate.lo
+xinflate.o: xinflate.lo
${LD} -T inflate.ld $< -o $@
-../build/inflate.bin: inflate.o
+../build/inflate.bin: xinflate.o
objcopy -O binary $< $@
%.o: ${WRDIR}/%.c
Author: wmb
Date: Wed Mar 6 20:53:52 2013
New Revision: 3594
URL: http://tracker.coreboot.org/trac/openfirmware/changeset/3594
Log:
wrapper.c - added commentary telling another way to accomplish
the same result as mprotect()ing the dictionary memory to make
it executable.
Modified:
forth/wrapper/wrapper.c
Modified: forth/wrapper/wrapper.c
==============================================================================
--- forth/wrapper/wrapper.c Wed Mar 6 19:55:27 2013 (r3593)
+++ forth/wrapper/wrapper.c Wed Mar 6 20:53:52 2013 (r3594)
@@ -2201,6 +2201,13 @@
return 0L;
#endif
#if defined(__linux__) && defined(ARM)
+ /* There is another way to achieve the goal of making the */
+ /* dictionary executable. You can add "-Wl,-z,execstack" */
+ /* to the cc command line or add "-z execstack" to the ld */
+ /* command line. mprotect() is perhaps more precise, making */
+ /* only the dictionary executable while leaving the stack */
+ /* protected, although that is probably pointless since */
+ /* the whole point of this program is code injection. */
mprotect(adr, len, PROT_READ | PROT_WRITE | PROT_EXEC);
__clear_cache(adr, adr+len);
return 0L;