Shop OBEX P1 Docs P2 Docs Learn Events
2 separately compiled objects — Parallax Forums

2 separately compiled objects

Don PomplunDon Pomplun Posts: 116
edited 2007-01-30 03:26 in Propeller 1
I have 2 separately compiled objects, listed below without all the fluff (I hope). The intent is that Top Level Object starts
X10Control's Start method in a new cog. Everything goes well until I load it , but all that happens is the PropStick resets.
Hopefully you'll see something OBVIOUSLY wrong ;=)
-- Don


{{
X10 Control
}}

var
byte Head, Tail

pub Start ( HeadPtr, BufLen )
Head := long [noparse][[/noparse]HeadPtr]
Tail := long [noparse][[/noparse]HeadPtr]
' repeat while Head == Tail

' *************************************


{ top level object }

con
_clkmode = xtal1 + pll16x
_xinfreq = 5_000_000
BufLen = 20 ' number of X10 commands that can be buffered

var
byte Buf[noparse][[/noparse]7]
long dummyStack[noparse][[/noparse]20]

obj
text : "tv_text"
X10 : "X10 Control"

pub start | TTdata
ParamNum := 0
bytefill ( @Buf, 0, 5 )
PoundsReqd := 0
ParamLen := 0

text.start(0) ' crt on pins 0-2
' TTdata := cognew ( X10.Start( @X10Head, BufLen ), @dummyStack) ' <<<<<<<<<<<<<
text.str ( string("new cog="))
text.dec(TTdata)
text.out(13)

repeat ' forever loop
repeat until ina[noparse][[/noparse]DV]~~ ' wait for DV to go high


repeat until ina[noparse][[/noparse]DV]==0 ' wait for DV to go low

dat
X10Head long 0
X10Tail long 0
X10Buf long 0[noparse][[/noparse]BufLen]

Post Edited By Moderator (Joshua Donelson (Parallax)) : 10/23/2009 4:45:10 AM GMT

Comments

  • asterickasterick Posts: 158
    edited 2007-01-29 19:39
    cognew\coginit only takes local functions, not object functions. If you try to pass a function from another object, it will actually execute that function and try to start a machine code cog at the location pointed to by the return value of the object function (huff huff huff)

    Other than that, I don't see anything wrong.
  • Don PomplunDon Pomplun Posts: 116
    edited 2007-01-30 02:21
    OK, so object#1 references object#2 in an OBJ block. Obj#1 then invokes a PUB method in obj#2. That method starts one of its local PUB methods in another cog.
    Does that PUB method, now running in another cog, have access to PRI methods from obj#2 ? (my guess is No).
    And none of the other PUB methods in obj#2 have any relevance to the new cog, eh?
    So you just have to be clever in how you write the method that runs in the new cog so it is self-contained?

    -- Don
  • Mike GreenMike Green Posts: 23,101
    edited 2007-01-30 03:26
    Don,
    Your guess is wrong. Try to think of the cogs separately from the objects. I think of the cogs as each carrying out an "execution thread". Any piece of code can be executed by any thread or even by several threads at once. The objects encapsulate a particular abstraction. Your object #1 references object #2 using an OBJ block definition. Object #1 can now reference any PUBlic method or named constant in object #2. None of this has anything to do with cogs. Object #2 can do its thing with or without the use of additional cogs. In your case, object #2's start (initialization) routine might "fork off" another execution thread to do stuff internal to the object. Object #1 doesn't even know if this has happened. It only has access to the PUBlic methods in object #2. Any method in object #2 has access to any other method, variable, constant in object #2. This doesn't mean they'll work properly if they're executing in separate threads (cogs). That depends on what variables they use and how they use them.
    Mike
Sign In or Register to comment.