Shop OBEX P1 Docs P2 Docs Learn Events
Translating MCP251-SPI Engine to P2 — Parallax Forums

Translating MCP251-SPI Engine to P2

jay_harlowjay_harlow Posts: 43
edited 2022-12-29 00:37 in PASM2/Spin2 (P2)

When translating MCP2515 SPI Engine to P2, I get a compile error, this compile prevents me from creating an archive.

This is with Propeller Tool version 2.7.0 (Bata)
Jay

Comments

  • MOVD isn't a valid instruction.

  • hey thanks! need to remember that

    Jay

  • evanhevanh Posts: 15,915

    Prop2 is SETD

  • JonnyMacJonnyMac Posts: 9,102
    edited 2022-12-29 01:55

    You're doing a block transfer from hub to cog -- which is easier in Spin2. Have a look at Ada's online help file here:
    -- https://p2docs.github.io/hubmem.html#block-transfers

    This bit of code seems overwritten for simply reading two longs from the hub and writing them to cog variables arg0 and arg1.

                  movd    argP,#arg0                        ' get 2 arguments ; arg0 to arg1
                  mov     t2,t1                             '     │
                  mov     t3,#2                             ' ───┘
    argP          rdlong  arg0,t2
                  add     argP,d0                           ' point to next long in COG (incr COG ptr)
                  add     t2,#4                             ' point to next addr in MAIN (incr MAIN ptr)
                  djnz    t3,#argP
    

    It seems like it could be simplified to this:

                  mov     t2, t1
                  rdlong  arg0, t2
                  add     t2, #4
                  rdlong  arg1, t2 
    

    This accomplishes the same thing, modifies the same variables, and there are no shenanigans. This will also translate to Spin2.

    You could also it this way in the P2 which would be faster but less obvious (not tested -- I have only done this with ptra in the source position for rdlong).

                  setq    #2-1                              ' get 2 arguments
                  rdlong  arg0, t1
    
Sign In or Register to comment.