gnupic: Thread: Optimiziing Forth compiler for mid-range PICs


[<<] [<] Page 1 of 1 [>] [>>]
Subject: Optimiziing Forth compiler for mid-range PICs
From: Francisco Rodrigo Escobedo Robles ####@####.####
Date: 5 Mar 2000 23:57:54 -0000
Message-Id: <200003052347.XAA02051@xinef.pepix.net>

Hello all.

I recently released an alpha but operational version of mary, an optimizing 
native code Forth compiler for PIC microcontrollers. There is a copy at http://
www.pepix.net/proyectos/glazz/mary/mary-1.0a50.tar.gz for everyone interested 
in trying it. It's released under GPL.

I mailed Scott Dattalo at the address listed in the gnupic.org pages, as I 
understood he's the current maintainer, but it seems the message didn't get 
trhough. Maybe he's reading this message and then we can arrange making a link 
from gnupic.org or even hosting the current version.

Any suggestion (and code patches :) are welcome. Right now, PIC models 
supported are 16C84 and 16C63, but adding more mid-range models is easy. 
Low-range PIC support is not planned. High-range may be supported in the 
future.

Regards.


---
Francisco Rodrigo Escobedo Robles - ####@####.####
El surrealismo vive en Pepix Labs - http://www.pepix.net/
Este mensaje expresa unicamente mi opinion en este momento


Subject: Re: Optimiziing Forth compiler for mid-range PICs
From: Scott Dattalo ####@####.####
Date: 6 Mar 2000 13:56:54 -0000
Message-Id: <Pine.LNX.4.05.10003060730530.14309-100000@tempest.blackhat.net>


On Sun, 5 Mar 2000, Francisco Rodrigo Escobedo Robles wrote:

> Hello all.
> 
> I recently released an alpha but operational version of mary, an optimizing 
> native code Forth compiler for PIC microcontrollers. There is a copy at http://
> www.pepix.net/proyectos/glazz/mary/mary-1.0a50.tar.gz for everyone interested 
> in trying it. It's released under GPL.

Now that sounds cool! 

 
> I mailed Scott Dattalo at the address listed in the gnupic.org pages, as I 

That page is hopelessly outdated. My current e-mail address is the one
where I'm sending this response.

> understood he's the current maintainer, but it seems the message didn't get 
> trhough. Maybe he's reading this message and then we can arrange making a link 
> from gnupic.org or even hosting the current version.

At one point I was going to fix all of the links at gnupic.org. Then back
in November, James Bowman told me he had the 'source' for the web pages
(I'm not sure in what format). We lost touch for a couple of months and
when we made contact again, I didn't ask him for the source... Let me go
ahead and start on that.

> Any suggestion (and code patches :) are welcome. Right now, PIC models 
> supported are 16C84 and 16C63, but adding more mid-range models is easy. 
> Low-range PIC support is not planned. High-range may be supported in the 
> future.


From what I can tell, the compiler is written Forth as well. I don't know
Forth at all. Could you perhaps provide some sample pic programs written
in Forth?

Scott

Subject: Re: Optimiziing Forth compiler for mid-range PICs
From: Wojciech Zabolotny ####@####.####
Date: 6 Mar 2000 21:47:56 -0000
Message-Id: <20000306221033.A18064@wzab.nasz.dom>

On Sun, Mar 05, 2000 at 11:47:13PM +0000, Francisco Rodrigo Escobedo Robles wrote:
> Hello all.
> 
> I recently released an alpha but operational version of mary, an optimizing 
> native code Forth compiler for PIC microcontrollers. There is a copy at http://
> www.pepix.net/proyectos/glazz/mary/mary-1.0a50.tar.gz for everyone interested 
> in trying it. It's released under GPL.
> 
> I mailed Scott Dattalo at the address listed in the gnupic.org pages, as I 
> understood he's the current maintainer, but it seems the message didn't get 
> trhough. Maybe he's reading this message and then we can arrange making a link 
> from gnupic.org or even hosting the current version.
> 
> Any suggestion (and code patches :) are welcome. Right now, PIC models 
> supported are 16C84 and 16C63, but adding more mid-range models is easy. 
> Low-range PIC support is not planned. High-range may be supported in the 
> future.
> 

Hi Francisco,

I've just printed the mary's manual and took a more thorough look at your
compiler. Let me ask you a few questions:

1) You wrote:

mary is part of the Glazz project, whose original aim was world
domination, later changed to the creation of a native code Forth system with
multiple targets.  

Does it mean that you are considering the 8051 support?
There is no good GPL'd Forth for those microcontrollers...

2) I'd like to add the 16F84 support. It seems to me, that it should be enough
   to change the MAXPICRAM0 definition from 2F to 4F in the 16c84-data.fs file.
   Am I right?

3) mary is GPL'd, so what license applies to the code compiled with it?
   If I use the code generated with mary in a commercial application, am I
   obliged to provide the end user with the sources of my code?
   Could you please state it explicitly in your documentation?

4) How could I implement the interrupt service routine in mary?

5) I'm sorry, but by mistake I've Cc'ed the first reply for your message
   to the ####@####.#### instead of gnupic list - so in result
   I've forwarded your message to that list :-(. However I hope you have
   no objections to announcing of mary there... 

Finally: you've done a wonderful work!
-- 
			TIA
			Wojciech Zabolotny
			http://www.ise.pw.edu.pl/~wzab

http://www.debian.org  Use Linux - an OS without "trojan horses" inside
Subject: Re: Optimiziing Forth compiler for mid-range PICs
From: Francisco Rodrigo Escobedo Robles ####@####.####
Date: 7 Mar 2000 02:46:02 -0000
Message-Id: <200003070233.CAA02085@xinef.pepix.net>

I noticed the small typo in the subject of my announce, but in order not to 
break the thread, i will not correct it :)

> > I mailed Scott Dattalo at the address listed in the gnupic.org pages, as I 
> 
> That page is hopelessly outdated. My current e-mail address is the one
> where I'm sending this response.

Thanks, it seems our messages get crossed, as I recently joined the list.

> > Any suggestion (and code patches :) are welcome. Right now, PIC models 
> > supported are 16C84 and 16C63, but adding more mid-range models is easy. 
> > Low-range PIC support is not planned. High-range may be supported in the 
> > future.
> 
> >From what I can tell, the compiler is written Forth as well. I don't know
> Forth at all. Could you perhaps provide some sample pic programs written
> in Forth?

It's my intention to make a sort of tutorial, but I lack the time right now. 
There is a very small example in the docs, and I have just sent a message to 
the list in response to Wojciech Zabolotny in which there is a snippet of code 
showing an interrupt service routine.

Some words about Forth (funny, because 'word' is the term for a callable 
routine, a variable, etc. Everything is a word in Forth):

 - Forth uses a stack for intermediate results, local variables and parameter
passing. This mechanism is not transparent to the user. Every word takes its 
parameters and leaves its results in the stack.

 - @ is used to fetch the value of a memory address. So, if PORTA is defined 
as the address of port A (in fact, it is in the currently supported processors), 
    PORTA @
   effectively leaves in the stack the current value at the port A pins.

 - ! stores the value in the second on stack into the address in the top of 
stack, so if PORTB is defined as the address of port B,
    PORTA @ PORTB !
  effectively copies the current value at the port A pins into port B.

 - there are high level flow control structures, as IF and loops as WHILE, 
UNTIL and infinite loops.

 - a word definition is like a subroutine, but in mary this is extended so a 
routine can have several entry points.

For example, suppose you want to make a toy in which a led bar "moves" in a 
ping-pong fashion (or a "Knight Rider" fashion, if you like). A possible (not 
complete) code could be:

----8<----
( AN EXAMPLE OF A PING-PONG LED BAR )

PICFORTH HEX

INIT-PIC

100 CONSTANT MYDELAY ( ALTER VALUE OF MYDELAY FOR CHANGING SPEED )
VARIABLE COUNTER

0 ORG            ( START OF MEMORY    )
FLABEL MAIN GOTO ( MAIN CODE          )

4 ORG            ( INTERRUPT VECTOR   )
FLABEL ISR GOTO  ( INCONDITIONAL JUMP )


( SUPPORT WORDS )

: DELAY ( N -- ) ( A TIMED DELAY )
    COUNTER !

    BEGIN
        COUNTER @        ( LOOPS UNTIL 0 )
    UNTIL
;


: PINGPONG ( -- ) ( A FULL CYCLE OF LED BAR PING PONG )
    1 CONST, ( INITIAL VALUE, FIRST HALF CYCLE )

    BEGIN
        DUP
    WHILE
        DUP PORTB !
        MYDELAY DELAY
        2*            ( EQUIVALENT TO A LEFT SHIFT )
    REPEAT

    40 CONST, ( INITIAL VALUE, SECOND HALF CYCLE )

    BEGIN
        DUP
    WHILE
        DUP PORTB !
        MYDELAY DELAY
        2/            ( EQUIVALENT TO A RIGHT SHIFT )
    REPEAT
;


( HERE COMES MAIN PROGRAM CODE )

MAIN

BEGIN
    PINGPONG
AGAIN


( INTERRUPT SERVICE ROUTINE. MUST BE CALLED PERIODICALLY )

ISR

COUNTER @ IF             ( IS COUNTER NON-ZERO? )
    -1 CONST, COUNTER +! ( YES, DECREMENT IT    )
THEN

RETFIE
----8<----

Again, too lazy of me for testing it right now (it's too late), the interrupts 
must be properly initialized, but they aren't in this code.

There are a pair of tricks in the example, one being the testing for the end 
of the WHILE loops, the other being the reliance on a periodic interrupt. 
There is a kludge in mary in the for of the (rather ugly) CONST, word, whose 
purpose is to push into the stack a previous unnamed constant. This will 
disappear in the future, but for the time being, we must live with this. 
Remember mary is in alpha state.

Oops, too long a message. Sorry.

Regards.


---
Francisco Rodrigo Escobedo Robles - ####@####.####
El surrealismo vive en Pepix Labs - http://www.pepix.net/
Este mensaje expresa unicamente mi opinion en este momento


Subject: Re: Optimiziing Forth compiler for mid-range PICs
From: Francisco Rodrigo Escobedo Robles ####@####.####
Date: 7 Mar 2000 02:46:26 -0000
Message-Id: <200003070141.BAA02037@xinef.pepix.net>

Hello.

First, thanks for your interest. As for 16F877 support, I am currently very 
busy, but it's not difficult to support new PICs in the mid-range, as long as 
one only use 2 (of 4 possible) RAM banks. I'll take a look and try to support 
it or give guidelines for that purpose.

It's my intention to support all PIC models in the mid-range, and try to move 
to high-range, but be patient, please :)

> I've just printed the mary's manual and took a more thorough look at your
> compiler. Let me ask you a few questions:
> 
> 1) You wrote:
> 
> mary is part of the Glazz project, whose original aim was world
> domination, later changed to the creation of a native code Forth system with
> multiple targets.  
> 
> Does it mean that you are considering the 8051 support?
> There is no good GPL'd Forth for those microcontrollers...

Right now, the main target is PIC, as they are the ones I know better and have 
hardware tools for. In the future, I intend to support mainstream processors 
(x86, 68k, maybe Z80), but 8051 et al is not planned nor discarded. Simply, I 
don't have right now the needed tools.

The idea is to make the compiler general enough to make as easy as practical 
support for other targets, so any help for supporting 8051, 6805 or any other 
family is welcome.

> 2) I'd like to add the 16F84 support. It seems to me, that it should be enough
>    to change the MAXPICRAM0 definition from 2F to 4F in the 16c84-data.fs file.
>    Am I right?

Yes, AFAIK, the only difference from the programming standpoint 
between the 16C84 and the 16F84 is the RAM amount. So your proposed change 
will do the trick. I will include that change in a new file for next version.

> 3) mary is GPL'd, so what license applies to the code compiled with it?
>    If I use the code generated with mary in a commercial application, am I
>    obliged to provide the end user with the sources of my code?
>    Could you please state it explicitly in your documentation?

A good question... As you have seen, docs are in alpha state, too :) My idea 
is to promote Forth and PIC programming with a useful tool. The way I envision 
this is making a good compiler and a good library, freely available for anybody.
If GPL is not free enough, I will move to a "better" licensing scheme.

The answer is: you can distribute your application without to give the source. 
The only case in which you must give sources to anything is when you modify 
the code for the compiler, and then I ask for patches or libraries or 
additions, in order to centralize and coordinate the distribution of the whole 
package. This way, everybody can benefit from the effort, and we all win.

> 4) How could I implement the interrupt service routine in mary?

This is one of the things I intend to cover in a forthcoming examples suite. 
But I think (not tested, sorry) this example can be usefule. Bear in mind that 
no "easy" support is implemented, but this will do:

----8<----
( AN EXAMPLE OF AN ISR )
( NO WORDS ARE DEFINED )


PICFORTH

INIT-PICFORTH   ( CLEAR ALL, THE PROGRAM IS SELF-CONTAINED )
INIT-PIC


VARIABLE MYVAR  ( INITIALIZED TO 0   )

4 ORG           ( INTERRUPT VECTOR   )
FLABEL ISR GOTO ( INCONDITIONAL JUMP )


( HERE COMES MAIN PROGRAM CODE )

BEGIN
    PORTB @ INVERT MYVAR !
AGAIN


( INTERRUPT SERVICE ROUTINE )

ISR
MYVAR @ PORTA !
RETFIE
----8<----

No words are defined in this example. Not the best code, but it shows another 
feature of mary: you can use it as a high-level assembler.

For all interested in Forth, the meaning of the example is: a main program 
continually reads port B and inverts every bit, storing result in variable 
MYVAR. An ISR takes the current value of MYVAR and outs to port A.

Of course, code for initializing peripherals, interrupt sources, etc, is 
missing. But you get the point.

> 5) I'm sorry, but by mistake I've Cc'ed the first reply for your message
>    to the ####@####.#### instead of gnupic list - so in result
>    I've forwarded your message to that list :-(. However I hope you have
>    no objections to announcing of mary there... 

Great, I'm glad to know more people is aware of mary. I announced at 
freshmeat.net, a software news site. So, any proper way is welcome.

> Finally: you've done a wonderful work!

Thanks, it's just my way of contributing and thanking all the people that make 
the wonderful tools I use daily.

Regards.


---
Francisco Rodrigo Escobedo Robles - ####@####.####
El surrealismo vive en Pepix Labs - http://www.pepix.net/
Este mensaje expresa unicamente mi opinion en este momento


Subject: Re: Optimiziing Forth compiler for mid-range PICs
From: Francisco Rodrigo Escobedo Robles ####@####.####
Date: 7 Mar 2000 23:56:01 -0000
Message-Id: <200003072343.XAA01468@xinef.pepix.net>

Oops. There were a pair of bugs in my code for the ping-pong led bar. The 
correct code for the PINGPONG word is:

-----8<-----
: PINGPONG ( -- ) ( A FULL CYCLE OF LED BAR PING PONG )
    2 CONST, ( INITIAL VALUE, FIRST HALF CYCLE )

    BEGIN
        DUP
    WHILE
        DUP PORTB !
        MYDELAY DELAY
        2*            ( EQUIVALENT TO A LEFT SHIFT )
    REPEAT

    DROP

    40 CONST, ( INITIAL VALUE, SECOND HALF CYCLE )

    BEGIN
        DUP
    WHILE
        DUP PORTB !
        MYDELAY DELAY
        2/            ( EQUIVALENT TO A RIGHT SHIFT )
    REPEAT

    DROP
;
-----8<-----

So, the 2 DROPs make sure the current value for the led bar is gone when not 
needed.

Alternatively, we can use a table, so we have total control of the pattern:

-----8<-----
TABLE PINGPONGPATTERN ( TABLE FOR LED BAR PINGPONG PATTERN )
01 , 02 , 04 , 08 , 10 , 20 , 40 , ( FIRST  HALF CYCLE )
80 , 40 , 20 , 10 , 08 , 04 , 02 , ( SECOND HALF CYCLE )

0E CONSTANT MAXPATTERN


: LEDPATTERN ( -- ) ( A FULL CYCLE OF LED BAR PATTERN )
    0 CONST, ( INITIAL VALUE )

    BEGIN
        DUP MAXPATTERN <
    WHILE
        DUP PINGPONGPATTERN PORTB !
        MYDELAY DELAY
    REPEAT

    DROP
;


( HERE COMES MAIN PROGRAM CODE )

MAIN

BEGIN
    LEDPATTERN
AGAIN
-----8<-----

Adding this code and deleting that of old PINGPONG we have a new, more general 
example.


---
Francisco Rodrigo Escobedo Robles - ####@####.####
El surrealismo vive en Pepix Labs - http://www.pepix.net/
Este mensaje expresa unicamente mi opinion en este momento


[<<] [<] Page 1 of 1 [>] [>>]


Powered by ezmlm-browse 0.20.