Shop OBEX P1 Docs P2 Docs Learn Events
BYTEMOVE between cog and hub — Parallax Forums

BYTEMOVE between cog and hub

BasilBasil Posts: 380
edited 2009-02-11 20:31 in Propeller 1
Hi All,

Long time no post :P

Anyway. I have an application where I am collecting data from x number of 8bit shift registers into a cog and once done I need to copy all of it into an array in the hub.

In the hub I have the following:
byte S88_Register[noparse][[/noparse]128].....holds 128bytes of data, ie. 128 shift registers
byte S88_Changes[noparse][[/noparse]128]....a '1' bit is placed in the location of any bits that change from 1 sample of S88_register to the next
long S88_number_of_modules...the number of 8bit shift registers I am collecting data from to put into S88_register

And in my cog I have the following (all longs as they are declared on the 'PRI' line of code)
S88_reg[noparse][[/noparse]32]....128 bytes containing the new shift register values.
cur_reg, i, temp_register.....working variables.

Here is my code, hope it makes sense! (Ignore the timing and clock cycles, thats not what im stuck on...at the moment [noparse]:D[/noparse]

    '*********************************
    'Get data from S88 shift register
    '********************************* 
   repeat cur_reg from 0 to S88_Number_of_modules 
      temp_register~ ' clear temp_register
      repeat 8
        Wait_us(40)
        temp_register <<= 1   
        temp_register += ina[noparse][[/noparse]S88_DATA]     'Clock data into temp_register                                
        outa[noparse][[/noparse]S88_CLOCK]~ 
        Wait_us(40)
        outa[noparse][[/noparse]S88_CLOCK]~~
      BYTEMOVE(@S88_reg[noparse][[/noparse]cur_reg],@temp_register,1)    'Copy the 8 LSBits into the next byte in S88_reg ***Is this ok?***
    
    outa[noparse][[/noparse]S88_LOAD]~
    outa[noparse][[/noparse]S88_RESET]~
    outa[noparse][[/noparse]S88_CLOCK]~
    '*********************************
    'Compare new data with previous and record changes
    '*********************************
    repeat cur_reg from 0 to S88_Number_of_modules
      S88_changes[noparse][[/noparse]cur_reg] := S88_register[noparse][[/noparse]cur_reg] ^ BYTE[noparse][[/noparse]@S88_reg][noparse][[/noparse]cur_reg]
      S88_register[noparse][[/noparse]cur_reg] := BYTE[noparse][[/noparse]@S88_reg][noparse][[/noparse]cur_reg]




My questions are:
1) See the **Is this ok?*** comment in the code above [noparse]:)[/noparse]
2) The last 3 lines, where I compare and update.

Can I replace that with:
    repeat cur_reg from 0 to S88_Number_of_modules
      S88_changes[noparse][[/noparse]cur_reg] := S88_register[noparse][[/noparse]cur_reg] ^ BYTE[noparse][[/noparse]@S88_reg][noparse][[/noparse]cur_reg]
    BYTEMOVE(@S88_register,@S88_reg[noparse][[/noparse]cur_reg], 128)




I am a bit confused with this last question because the manual keeps referencing the source and destination as address' in main memory. I want to copy 128 bytes from cog memory to hub memory... (Ie S88_reg to S88_register)

Thanks for taking the time to read this!

Alec

▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
-Alec

Velden in N scale

Post Edited (Basil) : 2/11/2009 8:17:54 PM GMT

Comments

  • Mike GreenMike Green Posts: 23,101
    edited 2009-02-11 20:22
    If your code is written in Spin, all of the variables are in hub memory (and copyable by any means you'd use for any Spin variables).· You have no access to cog memory from Spin except for the special function registers like OUTA, INA, etc.· If your Spin program is interfacing to a routine written in assembly language that stores data in the cog memory of the cog running the assembly language, then the assembly routine has to do the copying since Spin has no access to the cog memory.

    You're probably confusing the notion of cog memory with the notion of using a cog to run the Spin interpreter to interpret some Spin code.· In the latter case, there's no user data in cog memory (other than the special function registers), only the Spin interpreter itself.
  • BasilBasil Posts: 380
    edited 2009-02-11 20:26
    Oh [noparse]:)[/noparse] That answers all my questions then! Thanks Mike.

    Do you spot any problems with my method of storing bytes? Its the first time ive dealt with anything other then longs.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    -Alec

    Velden in N scale
  • BasilBasil Posts: 380
    edited 2009-02-11 20:31
    I just thought about the implications of what you said :P

    Does that mean my array S88_reg[noparse][[/noparse]32] which I thought would be in hub memory can now be declared in the VAR section as BYTE S88_reg[noparse][[/noparse]128]

    Not that it would make much difference I guess...

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    -Alec

    Velden in N scale
Sign In or Register to comment.