Thread: [Flashforth-devel] execute word from interpret and stack
Brought to you by:
oh2aun
|
From: Max S. <max...@gm...> - 2013-03-18 19:05:04
|
Hello All !
Does anybody can help me with problem ?
for the 18F4685 board with f3.8 uart the task is to communicate with modem
, i ve wrote the word to process modem answers as words and execute them.
the first word from modem answer have to be interpreted with addr and
length of remaining string on stack
for ex an answer :
OK AAA
have to be interpreted as : execute word OK with addr and length of
string AAA on stack
here the test code :
------------------------------------------------------------------------------------------------------
-simcom
marker -simcom
hex ram
create fpd 2 allot
create inbuf 128 allot
create npd 2 allot
create outbuf 128 allot
\ xu ... x0 u -- xu ... x0 xu
: pick 2* 3 + sp@ swap - @ ;
\
\ process answer from modem first word interprets as command ,
\ and remaining string addr2 and length n2 on stack as parameters
\ to command
\
: A2> ( a n a1 n1 -- a n a2 n2 a1 n1 )
dup >r over >r
tuck + ( a n a1 n1 -- ... )
swap 2 pick
swap - ( ... -- a n a2 n2 )
r> r> ( ... -- a n a2 n2 a1 n1 )
;
: proc_answ ( a n -- a2 n2 )
\ save variables
'source 2@ >r >r >in @ >r
over over ( a n -- a n a n )
'source 2! 0 >in ! ( a n a n -- a n )
\ get first word
$20 parse ( a n c -- a n a1 n1 )
A2> ( a n a1 n1 -- a n a2 n2 a1 n1 )
cr ." Start INTERPRET: ------- " sp@ u. ." --------- " .s
interpret ( a n a2 n2 a1 n1 -- a n )
cr ." End INTERPRET: ------- " sp@ u. ." -------- " .s
\ restore variables
r> >in ! r> r> 'source 2!
;
\
\
: eee
90 ms
." AT+CPIN?"
inbuf dup 100 accept ( -- a n )
proc_answ ( a n -- a n )
cr ." TP1 AFTR PROC------------------- " cr
.s
cr
;
-testw
marker -testw
: LOG cr ." LOG s:" .s ;
: OK ( a n a2 n2 -- a n )
cr ." TP2 exec +CPIN? : "
cr .s
LOG
1 2 3 +
;
: OK2 ( a n a2 n2 -- a n )
cr ." TP2 exec +CPIN? : "
cr .s
LOG
;
-------------------------------------------------------------
the problem is :
when OK executes from eee via interpret and do something with
stack, it always change two bottom stack elements
0 0 0 0 0 eee
prompt >AT
answer >OK
........some debug output.........
ok<$,ram>1952 e 0 0 0 f178 2 f17a 0 1 5
0 0 0 0 0 eee
AT OK2
........some debug output .....
ok<$,ram>0 0 0 0 0 f178 2 f17a 0
Thank you in advance
|
|
From: <mik...@pp...> - 2013-03-22 08:40:08
|
Hi,
I would not use INTERPRET for handling text protocols. You will not get a
robust solution.
If an unknown word is received the interpreter will do an ABORT and QUIT so
that your program is interrupted.
I would instead parse the string and use N= or COMPARE to compare each received
string and execute a corresponding word.
BR Mikael
----------------------------------------------------------------------------------------------------------------------------------------------
Hello All !
Does anybody can help me with problem ?
for the 18F4685 board with f3.8 uart the task is to communicate with modem
, i ve wrote the word to process modem answers as words and execute them.
the first word from modem answer have to be interpreted with addr and
length of remaining string on stack
for ex an answer :
OK AAA
have to be interpreted as : execute word OK with addr and length of
string AAA on stack
here the test code :
------------------------------------------------------------------------------------------------------
-simcom
marker -simcom
hex ram
create fpd 2 allot
create inbuf 128 allot
create npd 2 allot
create outbuf 128 allot
\ xu ... x0 u -- xu ... x0 xu
: pick 2* 3 + sp@ swap - @ ;
\
\ process answer from modem first word interprets as command ,
\ and remaining string addr2 and length n2 on stack as parameters
\ to command
\
: A2> ( a n a1 n1 -- a n a2 n2 a1 n1 )
dup >r over >r
tuck + ( a n a1 n1 -- ... )
swap 2 pick
swap - ( ... -- a n a2 n2 )
r> r> ( ... -- a n a2 n2 a1 n1 )
;
: proc_answ ( a n -- a2 n2 )
\ save variables
'source 2@ >r >r >in @ >r
over over ( a n -- a n a n )
'source 2! 0 >in ! ( a n a n -- a n )
\ get first word
$20 parse ( a n c -- a n a1 n1 )
A2> ( a n a1 n1 -- a n a2 n2 a1 n1 )
cr ." Start INTERPRET: ------- " sp@ u. ." --------- " .s
interpret ( a n a2 n2 a1 n1 -- a n )
cr ." End INTERPRET: ------- " sp@ u. ." -------- " .s
\ restore variables
r> >in ! r> r> 'source 2!
;
\
\
: eee
90 ms
." AT+CPIN?"
inbuf dup 100 accept ( -- a n )
proc_answ ( a n -- a n )
cr ." TP1 AFTR PROC------------------- " cr
.s
cr
;
-testw
marker -testw
: LOG cr ." LOG s:" .s ;
: OK ( a n a2 n2 -- a n )
cr ." TP2 exec +CPIN? : "
cr .s
LOG
1 2 3 +
;
: OK2 ( a n a2 n2 -- a n )
cr ." TP2 exec +CPIN? : "
cr .s
LOG
;
-------------------------------------------------------------
the problem is :
when OK executes from eee via interpret and do something with
stack, it always change two bottom stack elements
0 0 0 0 0 eee
prompt >AT
answer >OK
........some debug output.........
ok<$,ram>1952 e 0 0 0 f178 2 f17a 0 1 5
0 0 0 0 0 eee
AT OK2
........some debug output .....
ok<$,ram>0 0 0 0 0 f178 2 f17a 0
Thank you in advance
|
|
From: Mikael N. <mik...@pp...> - 2013-04-20 14:59:34
|
Finally I had some time to look at this problem. Your code works well on the PIC24 FF4.8 so it seems to be fault in the FF3.8 for PIC18. I will check it further. BR Mikael |
|
From: Mikael N. <mik...@pp...> - 2013-04-20 15:14:46
|
The problem is that that the return stack save buffer is too small (15 cells). The TYPE in OK executes PAUSE which writes the HW return stack to the user area return stack buffer, which overflows to the beginning of the parameter stack. If you change in p18f-main.cfg: #define RETURN_STACK_SAVE_SIZE d'30' ; 15 cells return stack save area to #define RETURN_STACK_SAVE_SIZE d'62' ; 31 cells return stack save area Have not tried it, but I think this should fix your problem. Mikael On Sat, 2013-04-20 at 17:59 +0300, Mikael Nordman wrote: > Finally I had some time to look at this problem. > > Your code works well on the PIC24 FF4.8 so it seems to be fault in the > FF3.8 for PIC18. > > I will check it further. > > BR Mikael > > > > > ------------------------------------------------------------------------------ > Precog is a next-generation analytics platform capable of advanced > analytics on semi-structured data. The platform includes APIs for building > apps and a phenomenal toolset for data science. Developers can use > our toolset for easy data analysis & visualization. Get a free account! > http://www2.precog.com/precogplatform/slashdotnewsletter > _______________________________________________ > Flashforth-devel mailing list > Fla...@li... > https://lists.sourceforge.net/lists/listinfo/flashforth-devel |