Shop OBEX P1 Docs P2 Docs Learn Events
GETREGS(HubAddr, CogAddr, Count) Spin2 Syntax Question — Parallax Forums

GETREGS(HubAddr, CogAddr, Count) Spin2 Syntax Question

Does someone have an example GETREGS. If you have 3 cogs running how is it bes to distinquish registers.
Regards and Thanks
Bob (WRD)

Comments

  • AribaAriba Posts: 2,690

    GETREGS copies registers from cog memory to hubmemory. You can only copy the registers from the cog that executes the GETREGS methode, there is no way to access registers from other cogs.
    If you want to pass registers between cogs you need to go over hubmemory and all the cogs must cooperate.

  • No Luck. I don't see what this command GETRGS(HubAdr0,CogAdr0,2) does. I would expect HubAdr0 and HubAdr1 would match
    CogAdr0 and CogAdr1. Could someone check below and see what is wrong.
    Regards
    Bob (WRD)

    CON
        _clkfreq = 200_000_000    'system clock
    PUB main()
       getregs(HubAdr0,CogAdr0,2)
       debug(udec(HubAdr0),udec(CogAdr0))
       debug(udec(HubAdr1),udec(CogAdr1))
       repeat
    DAT
                            org   0
    CogCode0       nop
                             drvl  #0
                             ret
    CogCode1        nop
                              drvh  #0
                             ret
    CogAdr0        long      11
    CogAdr1        long      22
    DAT                  orgh
    HubCode0     nop
                            drvl #1
                           ret
    HubCode1    nop
                          drvh #1
                          ret
    HubAdr0         long     111
    HubAdr1         long     222
    
  • AribaAriba Posts: 2,690

    You need to write the values first into the cogregs, I use inline assembly here, to not use SETREGS, that would be too easy ;)
    Then you need to pass the address of the hubvariables and the cogregs as parameters in GETREGS.
    And now an exercise for you: Why do you get the 55 and 66 for CogAdr0/1 at debug?

    CON
        _clkfreq = 200_000_000    'system clock
    
    PUB main()
     org
          mov     CogAdr0,#11            'write values to cogregs
          mov     CogAdr1,#22
     end     
     getregs(@HubAdr0,#CogAdr0,2)        'copy cogregs to hubram
     debug(udec(HubAdr0),udec(CogAdr0))
     debug(udec(HubAdr1),udec(CogAdr1))
     repeat
    
    DAT
                   org      0
    CogAdr0        long     55
    CogAdr1        long     66
    HubAdr0        long     333
    HubAdr1        long     444
    
  • I see that the key appears to be @ and # to get hubAdr you need @HubAdr0 and to get CogAdr you need #CogAdr0.
    I believe that debug will read the HUB RAM and the Inline assembly is writing to COG RAM and since the DAT table is in HUB RAM a wrlong would be require to load CogAddr0\1 in HUB RAM to get 11\22 present. Going to play with this tomorrow.
    I think I am missing something concerning how spin2 boots and what ORG 0 and ORG H do in both assembly and spin2. (actually I'm missing more than this but it's fun)
    thanks for info
    Regards
    Bob (WRD)

  • I think I am missing something concerning how spin2 boots and what ORG 0 and ORG H do in both assembly and spin2. (actually I'm missing more than this but it's fun)

    The key thing to remember is that "ORG n" does not actually place anything in COG memory -- it merely tells the assembler to prepare the code so that it could be loaded into COG memory at address n. Actually getting it into some COG's memory requires a COGINIT or similar call.

  • From the following code I believe the CALL instruction results in the HUBEXEC is the only mode running. ORG 0 does not come into play and ORG H doesn't matter also. Am I correct to say that if spin2 interperter is loaded only HUBEXEC can run or you must program a transfer of HUB RAM containing the Cog code to COG RAM then create a jmp to start of Cog program.

    CON
        _clkfreq = 200_000_000    'system clock
    
    PUB main()| a,b,c
       org
          mov     CogAdr0,#11            'write values to cogregs
          mov     CogAdr1,#22
       end     
       getregs(@HubAdr0,#CogAdr0,2)
       debug(udec(HubAdr0),udec(CogAdr0))
       debug(udec(HubAdr1),udec(CogAdr1))
       repeat
         call(@CogCode0)
         waitms(500)
         call(@CogCode1)
         waitms(500)
         call(@HubCode0)
         waitms(500)
         call(@HubCode1)
         waitms(500)
       repeat
    DAT
                org   0
    CogCode0    nop
                drvl  #0
                ret
    CogCode1    nop
                drvh  #0
                ret
    CogAdr0        long      345
    CogAdr1        long      678
    
    DAT         orgh
    HubCode0    nop
                drvl #1
                ret
    HubCode1    nop
                drvh #1
                ret
    HubAdr0         long     123
    HubAdr1         long     321
    

    thanks for looking at this
    Regards
    Bob (WRD)

  • I think I found out that it's true and you have to use REGLOAD\REGEXEC to get something into Cog 0 (ie DAT symbols) I look a little silly with above question
    Bob (WRD)

Sign In or Register to comment.