Shop OBEX P1 Docs P2 Docs Learn Events
Problem with passing HUB RAM address to PASM executed in different COG — Parallax Forums

Problem with passing HUB RAM address to PASM executed in different COG

Hey there,
it's me again ^^ I'm entcountering a problem(only 0 read) when trying to pass a HUB RAM address to PASM executed in a different COG. Here's an example I've made up to show what I'm doing(I saw something like this in the CMUCam4 firmware):
CON _EXAMPLE_LONG_ARRAY_SIZE = 20

VAR long testArray[_EXAMPLE_LONG_ARRAY_SIZE]

PUB main

  testArrayPointer := @testArray
  cognew(@EXAMPLE_PASM, 0)

DAT
                        org 0

EXAMPLE_PASM            rdlong  tmp,            testArrayPointer

' work with the tmp buffer

                        djnz    counter,        #EXAMPLE_PASM

testArrayPointer        long    0
counter                 long    _EXAMPLE_LONG_ARRAY_SIZE

tmp                     res     1

Thanks in advance if you can help me,
DragonRaider5

Comments

  • kwinnkwinn Posts: 8,697
    edited 2016-02-20 14:23
    Your code should loop continuously and put the first long of testArray in tmp. If you want to transfer the entire array you need to increment testArrayPointer and the destination address of the rdlong instruction each time through the loop. That means a loop counter is also needed.
  • Hey kwinn,
    actually I'm incrementing the pointer by 4 every time I loop. The problem is, that I write to the long array in a different COG, then I stop the COG, read the long from my main SPIN code(where it displays me valid data) and then when I read it again in the way which is shown in the example it only reads 0s :/
  • kwinnkwinn Posts: 8,697
    Better to post all the code if you want help.
  • Parameters (including addresses in hub memory) are passed to assembly language cogs using the PAR register (or more correctly, using a pointer passed in PAR). There is a pretty good explanation in the Reference manual under PAR.
  • You can use par, but the way you passed the array pointer is also correct, although some my quibble with it from a stylistic standpoint.

    'Better to show more of your code.

    -Phil
  • In my actual code I used the par register for a different array ;) now I just arranged them in memory in a way which allows me to pass the first addr using par and then to add the size of it in order to get the addr of the other array xD
Sign In or Register to comment.