Shop OBEX P1 Docs P2 Docs Learn Events
Need help understanding wordmove between 2 objects / cogs — Parallax Forums

Need help understanding wordmove between 2 objects / cogs

Don MDon M Posts: 1,652
edited 2012-10-20 12:27 in Propeller 1
In my main cog I have 2 258 word buffers called buf1 and buf2. My main loop toggles back and forth between each buffer as each one reaches 254 words. After each toggle I want to transfer the whole buffer contents to another objects / cogs buffer called block (also a 258 word buffer) so that another method running independent of the Main method can use that data.

Can this be done and if so do I need to index through each of the 258 words from buf1 (or buf2) or is there a "wholesale" way to send the whole buffer?

I don't have all my code put together yet so I don't really have anything substantial to show... yet.

Does anyone have any or can think of any examples I can look at?

Thanks.

Comments

  • Mark_TMark_T Posts: 1,981
    edited 2012-10-19 14:21
    In Spin or PASM?

    If Spin then the buffers are all in hub RAM so all you need to do is pass the address - no need for another array to store it. You'd then use the word[var][index] syntax rather than buffer[index]
  • Don MDon M Posts: 1,652
    edited 2012-10-19 14:34
    In Spin. I'm not sure I follow what you mean by word[var][index]. Do I just tell the other method word[buf1][0] ?
  • Mike GreenMike Green Posts: 23,101
    edited 2012-10-19 14:43
    WORDMOVE will move a block of words from one part of hub memory to another. All you need is the address of each block (source and destination) plus the size of the block in words. Since the buffer "block" belongs to another object, the main object will not have the address of "block", but you can create a method in the child object that returns the address of "block" when called. The main object can get the address of "buf1" or "buf2" by using the @ operator.
    [U]main object[/U]
    ....
    OBJ child : ".... file name"
    VAR WORD tempAddress
    
    tempAddress := child.askForAddress
    if firstBuffer   ' tells which buffer is to be moved
       WORDMOVE(tempAddress, @buf1, 258)
    else
       WORDMOVE(tempAddress, @buf2, 258)
    
    [U]child object[/U]
    VAR WORD block[ 258 ]
    ....
    PUB askForAddress
       RETURN @block
    
  • Don MDon M Posts: 1,652
    edited 2012-10-20 07:16
    Ok thanks for the help. Got it working.
  • kwinnkwinn Posts: 8,697
    edited 2012-10-20 12:27
    @Don M

    Mark_T's suggested method of doing this is both simpler and faster. It is essentially transferring the ownership of the 3 buffers between the main loop and the object/cog by exchanging address pointers. When the main loop has filled buf1 it passes the address of buf1 to the object "block" and receives the address of the buffer the object has finished processing (probably buf3). Much faster than moving all the data in the buffers from one to the other.

    PS, Doing it this way may also let you get away with using only 2 buffers.
Sign In or Register to comment.