SpinForth
http://code.google.com/p/spinforth/
This forth is very useful for interactive hardware and software development. It is optimized for as many free registers as possible in the cogs.
The stacks are in the cogs, and there is stack checking.
While SpinForth is fast enough for many tasks, it is not fast enough for all.
So there is a built in assembler. The assembler has not been used for any large projects, but I have one over the next couple of months, so it will get shaken out.
This forth is very useful for interactive hardware and software development. It is optimized for as many free registers as possible in the cogs.
The stacks are in the cogs, and there is stack checking.
While SpinForth is fast enough for many tasks, it is not fast enough for all.
So there is a built in assembler. The assembler has not been used for any large projects, but I have one over the next couple of months, so it will get shaken out.
Comments
Looks great!
I'll play with it some more.
Thanks!
*Peter*
*Peter*
Leon
·
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Amateur radio callsign: G1HSM
Suzuki SV1000S motorcycle
Post Edited (Leon) : 12/10/2007 3:23:13 PM GMT
I have heard alot about the Forth lingo over the years.
Seems to be used in alot of real time apps.
But never seen any real code examples..
Can somebody drop an example of what it looks like.
For example to sample an A/D chip simple 8 bit SPI loop .. clock collect store type stuff.
Does not have to be in detail just a short blurb ..
cheers Ron Mel OZ
This is just a quick example of writing 8-bits in SPI fashion. With a very minor change this routine can read in the data as well but for this example I have kept it simple.
Notice that SpinForth is not a full Forth so simple operations such as SET and RESET bits have to be done the old fashioned way unless we create a definition of course.
*Peter*
Post Edited (Peter Jakacki) : 12/10/2007 11:30:05 PM GMT
*Peter*
Thnx for the quick tutorial on Forth.
As you said the speed seems a little slow... whats the problem there ?
You would expect the speed to be much better than Spin ??
Propeller Spin nearly beats it..
cheers Ron Mel OZ
is the url of the wiki. Documentation, and this project, could use help, any volunteers
Amateur radio call sign: VE3SDC
Suzuki SV650S Motorcycle
As for the speed:
hex
\ set bit 0 as an output
0 pxo
\ ( num_loops -- num_loops )
: forth_flip dup 0 do outa @ 1 or outa ! outa @ FFFFFFFE and outa ! loop ;
:asm asm_flip
mov treg1 , stTOS
__1
or outa , # 1
andn outa , # 1
djnz treg1 , # __1
;asm
: test_result swap cnt @ swap - 2dup
." COUNT of " . ." for " . ." flips -- "
swap u/ . ." clocks/flip " cr ;
: test_forth cnt @ 100000 forth_flip test_result ;
: test_asm cnt @ 100000 asm_flip test_result ;
: test test_forth test_asm ;
decimal
test
Produces:
COUNT of 1862272112 for 1048576 flips -- 1776 clocks/flip
COUNT of 12583536 for 1048576 flips -- 12 clocks/flip
Cog2 ok
So... as I wrote somewhere the built in assembler, which I have not yet really shaken down, or really documented is what you want to use for speed.
The normal pattern is to write in forth, and replace the forth words which need to go fast with assembler.
Hope this helps
before you try to use the assembler
Thanks for the Forth, I'm evaluating it at present to see if I can use it in a project. Straight away I can see I need a method of autostarting an application plus I haven't yet seen where I can fire-up tasks from the program. I did add a cut down hires text driver plus I am looking at integrating an SD card driver with the higher level stuff in Forth.
*Peter*
One thing I haven't figured out is why the nfa of secondaries get $10 added.
But I think I spotted one optimization -- move the setting of lstatus outside of the push/pop routines. Let them have separate jump points in front of the a_reset routine where each particular lstatus value can be or'ed in.
Post Edited (Fred Hawkins) : 12/11/2007 7:33:09 PM GMT
Perhaps someone way more familiar with spin than I can comment.
As for auto starting,
You can replace the fstart routine and recompile,
or load a file called 2 or 3 or 4 or ... 7 into the eeprom which will be loaded by that cog every time it starts.
BTW I was transplanted to Vancouver a while ago and recently to Victoria, so the VE3 is a bit old.
Sal
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Paul Baker
Propeller Applications Engineer
Parallax, Inc.
ps. does deSilva's dead cat bounce?
200 f_write
...3
\ ( pin -- )
: blink
dup pxo \ pin out
begin
dup pxh \ pin hi
100 delay_ms
dup pxl \ pin lo
100 delay_ms
0 until drop ;
: blink_start
cogid 1+ connectcog \ give the console to the next cog
0 blink ;
blink_start
\ eof
Now if you type really fast...
Which is·the famous (justifiably) Graham Stabler's Good Thread Index (New and Improved)·
I have been shaking down the assembler. So far so good.
One item I found in writing an SPI driver, testing a bit I needed to load ina to a temp reg and then check, verified this with spin assembler and got the same thing. Am I doing something way wrong??
\ read in bit
\ test ina , # _em_miso wc doing this directly does not seem to work
mov treg5 , ina
test treg5 , # _em_miso wc
rcl stTOS , # 1