Shop OBEX P1 Docs P2 Docs Learn Events
sndCogLut0 long sndCogLut0 whats up with this — Parallax Forums

sndCogLut0 long sndCogLut0 whats up with this

The following code compiles . The Data declaration "sndCogLut0 long sndCogLut0" I would have thought the address value would be substituted but it something totally different. Using @sndCogLut0
does something different also. Whats' up?
Regards and Thanks
Bob (WRD)

CON
    _clkfreq = 200_000_000    'system clock
    CogNum   = 1              'Cog to run
PUB main()
    COGINIT(COGEXEC+CogNUM,@CogCode,@HubCode)
    waitms(5000)
    debug(udec(HubCode))
    debug(udec(HubDataTable))
    debug(udec(sndHubLut0))
   repeat
DAT
                       ORG 0            'COG RAM
CogCode            nop
                           debug(udec(CogCode))
                           debug(udec(CogDataTable))
                           debug(udec(sndCogLut0))
Loop0                nop
                           jmp       #Loop0      'Jump to HubCode
CogDataTable            long       CogDataTable
sndCogLut0               long        sndCogLut0
DAT
                       ORGH              'HUB RAM
HubCode        nop
Loop1              nop
                         jmp       #Loop1
HubDataTable            long       HubCode          '@HubCode start of HUBEXEC PASM
sndHubLut0                 long       sndHubLut0

Comments

  • yeah that is sort of a pitfall.

    Spin Code is relocatable and all addresses are relative to some base pointers relative to the object containing the code.

    And here comes the dilemma with @ @@ and @@@

    At compiletime aka
    myAdr LONG @whatever gives you the offset not the actual Hub Address.
    At runtime
    myAddr:= @whatever gives you the actual HUB address

    BST invented @@@ to give you a HUB address at compile time so

    myAdr LONG @@@whatever would give a Hub Address, but not supported by PropTool/Pnut, I think FlexProp does it.

    I do not really remember what @@ was for, - Offset inside Object, something.

    So getting hold of a absolute Hub Address is quite a challenge when using Spin.

    Mike

  • Thanks for Reply. Who is BST?
    Regards
    Bob (WRD)

  • @"Bob Drury" said:
    Thanks for Reply. Who is BST?
    Regards
    Bob (WRD)

    http://www.fnarfbargle.com/bst.html

  • Hello on the other side:
    Starting with COGEXEC then HUBEXEC works for loading DAT initial values. But if you need to have the address of HUB values it gets messy. How do you get a second pointer address for using HUB RAM with RDLONG and WRLONG. The following is one way that seems to work but it wouldn't be relocatable as and object. The code requires calculating the HubCode address .
    The code is reading HUB RAM variable to COG RAM variable then COG RAM variable LUT RAM then LUT RAM To COG RAM then COG RAM Back to HUB RAM(seems to work).
    is there a better way for loading the HubCodeAddress then having to calculate it?

    CON
        _clkfreq = 200_000_000    'system clock
        CogNum   = 1              'Cog to run
        HubCodeAddress = 4_308
    PUB main()
        debug("-------------------------")
        debug(udec(HubCode))
        debug(udec(HubDataTable))
        debug(udec(sndHubLut0))
        debug(udec(sndHubLut1))
        debug(udec(rcvHubLut0))
        debug(udec(rcvHubLut1))
        COGINIT(COGEXEC+CogNUM,@CogCode,@HubDataTable)  'To Determine @HubCode (HubCodeAddress)
        waitms(5000)                                                                                  'replace use sndHubLut0 with @HubCode and replace
        debug("@HubCode= HubCodeAddress = 4_308")                   'replace jmp ptrb with jmp #Loop0 to determine address @HubCode
        debug(udec(HubDataTable))
        debug(udec(sndHubLut0))
        debug(udec(sndHubLut1))
        debug(udec(rcvHubLut0))
        debug(udec(rcvHubLut1))
        debug("-------------------------")
        repeat
    
    '------------------------------------------------------------------------------
    DAT
                           ORG 0            'COG RAM
    CogCode                nop
                           debug("-------------------------------")
                           debug("Enter COGEXEC code")
                           debug("HubDataTable Address= ",udec(ptra))
                           mov    ptrb,##HubCodeAddress
                           debug("HubCode= ",udec(ptrb))
                           mov    CogDataTable,ptrb
                           debug("@HubCode= ",udec(CogDataTable))
    Loop0             nop
                           jmp   ptrb                   '#Loop0 'ptrb      'Jump to HubCode Use #Loop jmp to determine HubCodeAddress
    CogDataTable              long       0
    sndCogLut0                  long       0
    sndCogLut1                  long       0
    rcvCogLut0                   long       0
    rcvCogLut1                   long       0
    LutRamAddress           long       $200  'address of Look Up Table LUT RAM
    
    DAT
                           ORGH              'HUB RAM
    HubCode                nop
                           debug("--------------------------------")
                           debug("Enter HUBEXEC code")
                           add ptra,#4
                           debug("sndHubLut0 Address= ",udec(ptra))
                           mov pa,LutRamAddress          'pa   = address $200
                           rdlong sndCogLut0,ptra        'ptra = @sndHubLut0  0 => address sndCogLut0
                           wrlut  sndCogLut0,pa          'pa   = address $200   0 => address sndCogLut0
                           rdlut  rcvCogLut0,pa          'pa   = address $200   5 => address rcvCogLut0
                           debug("LUT RAM address $200 = ",udec(rcvCogLut0))
                           add ptra,#8                  'ptra = rcvHubLut0
                           wrlong rcvCogLut0,ptra        'ptra = @rcvHubLut0  5=> @rcvCogLut0
                           debug(udec(sndCogLut0),udec(rcvCogLut0))
                           sub ptra,#8                   'ptra = @sndHubLut0
                           add ptra,#4                   'ptra = @sndHubLut1
                           add pa,#1                     'pa   = address $201
                           rdlong sndCogLut1,ptra        'ptra = @sndHubLut1  1 => address sndCogLut1
                           wrlut  sndCogLut1,pa          'pa   = address $201 1 => address sndCogLut1
                           rdlut  rcvCogLut1,pa          'pa   = address $201 6 => address rcvCogLut1
                           debug("LUT RAM address $201 = ",udec(rcvCogLut1))
                           add ptra,#8                   'ptra = @rcvHubLut1
                           wrlong rcvCogLut1,ptra        'ptra = @rcvHubLut1  6 => address rcvCogLut1
                           debug(udec(sndCogLut1),udec(rcvCogLut1))
                           sub ptra,#12                   'ptra = @SndHubLut0
                           sub ptra,#4                    'ptra = @HubDataTable
                           debug("HubDataTable= ",udec(ptra))
                           wrlong ptra,ptra
                           debug("------------------------------")
    Loop1             nop
                           jmp #Loop1
    HubDataTable           long       0          '@HubCode start of HUBEXEC PASM
    sndHubLut0              long       1111
    sndHubLut1              long       2222
    rcvHubLut0               long       0
    rcvHubLut1               long       0
    '------------------------------------------------------------------------------
    

    Regards and Thanks
    Bob (WRD)

  • AribaAriba Posts: 2,682

    If you use @Label in DAT sections, the hubaddress you get is relative to the object base address. You can get this baseaddress with @@0.
    The following code passes this baseaddress in ptra, and has a (single instruction) subroutine to calculate the hubaddress from it.

      _clkfreq = 20_000_000
    
    PUB main()
      coginit(16, @cogcode, @@0)
      repeat
    
    DAT
            org   0
    cogcode mov   hubbase,ptra        'save hub baseaddr
            callpa #@hubcode,#hubadr  'calc absolute hubaddr into pa
            debug(uhex(pa))
            jmp   pa                  'jump to hubcode
    
    hubadr  _ret_ add   pa,hubbase    'subroutine to calc hubaddr
    
    hubbase long  0
    Delay   long  10_000_000
    Led     long  60
    
    hubcode drvnot Led
            waitx  Delay
            callpa #@Const1,#hubadr    'get hubaddr of Const1 into pa
            rdlong pb,pa               'read Const1 value
            debug(uhex(pb))
            jmp    #hubcode
    
    Const1  long   $1234
    
  • That would help in determining multiple address locations. I will try out tomorrow. That would then allow code to be relocatable as an object.
    Thanks and Regards
    Bob (WRD)

  • Used @@0 and obtaining hubBase address addiing this to the symbol offset value @hubCode gives absolute address of huBCode. Works as stated thanks.
    Is there synopsis of how the Propeller Tool compiles program?
    By this I mean how the Spin2 code is compiled creating object addresses and how DAT file gets stored. I would think this would contain the definition of @@0 .

    What I have found in the documentation is:

    Str0        BYTE    "Monkeys",0   'strings with symbols
    Str1        BYTE    "Gorillas",0
    Str2        BYTE    "Chimpanzees",0
    Str3        BYTE    "Humanzees",0
    
    StrList     WORD    @Str0    'in Spin2, these are offsets of strings relative to start of object
                    WORD    @Str1    'in Spin2, @@StrList[i] will return address of Str0..Str3 for i = 0..3
                    WORD    @Str2    'in PASM-only programs, these are absolute addresses of strings
                    WORD    @Str3     '(use of WORD supposes offsets/addresses are under 64KB)
    'Note: Long can be used if address is greater than 64k suggest using Long always    
    

    The @ ins and the friends @@ and @@@ are usually a Spin-syntax but often used in DAT sections thus also valid for assembler.
    So in the case of REP the @ has a complete different meaning. @ instructs the compiler to See how many instructions follow the REP instruction to the symbol pointed to with @Symbol.

    Regards and Thanks
    Bob (WRD)

Sign In or Register to comment.