Shop OBEX P1 Docs P2 Docs Learn Events
Passing address of array from parent object to new cog in child object — Parallax Forums

Passing address of array from parent object to new cog in child object

DonRaczDonRacz Posts: 13
edited 2014-06-27 17:44 in Propeller 1
Hello to All

I'm trying to find out if it is possible to start a new cog in a child object with the address of an array in the parent.

I know I can start many cogs from the same child and give them a common address from the child so they can all share. I'm hoping to be able to keep separate child object files if for no other reason than to keep it neat and clean.

Some sample code..

Parent Code.

con
_clkmode = xtal1 + pll16x
_xinfreq = 5_000_000
CLK_FREQ = ((_clkmode - xtal1) >> 6) * _xinfreq


obj
Child : "Child"


var
Long Some_var_1
Long Some_var_2
Long Parent_Array[100]


pub main | OK
Child.Start(Some_var_1, Some_Var_2, @Parent_Array)


' Various and sundry code follows

Child Code

var
Long Var1
Long Var2
Long Array_Address

Long Stack
byte Cog1

pub Start(Vari1,Vari2,Address) 'This is where the wheels start to come off

cog1 := cognew(@Entry, @Address) + 1 'This is where the wheels actually start flying around


dat
org 0
entry mov tmp1, par ' start of structure
rdlong Array_item, tmp1 ' read ticks per ms
' More code
tmp1 res 1
Array_Item res 1


I want to be able to update the array from multiple cogs without have to pass the data back and forth through the parent.

Is it possible to do this? If so can someone Please help me with the correct syntax.

Is it a good idea to do this?

Thanks Don

Comments

  • Duane DegnDuane Degn Posts: 10,588
    edited 2014-06-27 17:42
    The main problem I see is the use of the address symbol "@" when you want the value of the variable. "@Address" should be "Address".

    And yes this sort of thing is done all the time.

    I have a link to Phil's tutorial on how to post code in the forum in post #3 of my index.
  • DonRaczDonRacz Posts: 13
    edited 2014-06-27 17:44
    Thanks , I had no idea how to make it look pretty.
Sign In or Register to comment.