Re: [Flashforth-devel] FF and C interfacing
Brought to you by:
oh2aun
|
From: Mikael N. <mik...@pp...> - 2012-09-19 05:23:09
|
Hi Tovar, On 19.9.2012 4:30, Tovar wrote: > I read the posting about some of what's need to make C and FF co-exist. > Let's see if i'm on the right track and that this won't be too complex. > > For my purposes, i am assume that FF is largely in control of the computing > environment, the operating system, as you would say. I want to have FF call > C routines (probably via assembly hooks). I assume then that the assembly > hooks would preserve non-volatile registers that FF uses, and load up ones > that C expects to find. I assume that i only have limited use of the C > library and need to be very careful what routines i used. (If this were to > prove to be feasible, i would probaly make up a separate library which only > contain FF-safe routines.) > Sofar you are right. The only registers to be concerned about are the FSRn registers. FSRn is used by the C domain for stack handling. This means the all the interrupt code needs to be in the FF domain. No C interrupt code. > I also recognize that for the C routines to do certain things, it will have > to call at least FF internals to do things like acquire and release blocks > of memory, get time of day and probably do I/O operations as well. It would > be nice if i could invoke Forth words from C, but that's less essential. > It's best to never access the FF environment from the C environment. There is no heap support in FF. The C-lib would need to implement its own heap. All the needed resources (memory and I/O) should be statically allocated to the C-lib. The only thing that the C-lib could access from the FF domain is the TICKS counter for timeout support. Time of day support could be built upon TICKS or on a separate RTC chip. Any C-routines that regularly need to be executed can be called from the PAUSE word. At least the Microchip IP stack is polling the ethernet interface all the time. This can conviniently be done from PAUSE. The other adaption needed is to let KEY and EMIT (ACCEPT?) use Telnet for I/O. That is of course if you want to use Telnet for controlling the OPERATOR task. BR Mike |