Shop OBEX P1 Docs P2 Docs Learn Events
Help porting to PASM — Parallax Forums

Help porting to PASM

marzec309marzec309 Posts: 146
edited 2011-07-09 03:06 in Propeller 1
Would any one be willing to help port this little chunk of spin to PASM? I would owe you one. ;)
CON                                  

  SCLK_IN   = 5                                          
  DIN       = 6
  LOAD_IN   = 4 
   
      
VAR

  long  Cog
  long  InputBits
  long  stack[64]
      
PUB  Start(InputState) : Okay

  stop

  Okay := Cog := cognew(main(InputState),@stack) + 1

PUB  stop

  '' Stop switch driver - frees a cog

  if cog
    cogstop(cog~ - 1)

PRI  Main(InputState)  |  tmp

  'Setup register control bits
  outa[SCLK_IN]~~
  outa[LOAD_IN]~~
  dira[DIN]~
  dira[SCLK_IN]~~
  dira[LOAD_IN]~~

  repeat
    outa[LOAD_IN]~
    outa[LOAD_IN]~~
    repeat 8
      tmp := tmp << 1
      tmp := tmp ^ ina[DIN]
      outa[SCLK_IN]~
      outa[SCLK_IN]~~
    inputbits := tmp >< 8 
    bytemove(Inputstate,@inputbits,1) 

Comments

  • Mark_TMark_T Posts: 1,981
    edited 2011-07-08 03:07
    Something like this - untested but it compiles...

       
    VAR
      long  cog
    
    
          
    PUB  Start(InputState) : okay
      stop
      okay := cog := cognew (@entrypoint, InputState) + 1
    
    PUB  stop
      '' Stop switch driver - frees a cog
      if cog
        cogstop (cog~ - 1)
    
    
    DAT
    
                  org    0
    entrypoint    mov    inputstate_addr, par       ' save our parameter
    
                  or     outa, SCLK_IN              ' setting up pins state and directions
                  or     outa, LOAD_IN
                  andn   dira, DIN
                  or     dira, SCLK_IN
                  or     dira, LOAD_IN
    
    :loop         andn   outa, LOAD_IN              ' toggle LOAD_IN
                  nop                               ' slow down a little to 100ns pulse
                  or     outa, LOAD_IN
                  mov    n, #8                      ' loop count
    
    :bitloop      test   DIN, ina  wc               ' test input bit (ina doesn't work as destination, note), carry = parity = the bit
                  rcl    tmp, #1                    ' shift carry into tmp
                  andn   outa, SCLK_IN              ' toggle SCLK_IN
                  nop                               ' slow down a little to 100ns pulse
                  or     outa, SCLK_IN
                  djnz   n, #:bitloop
    
                  rev    tmp, #24                   ' reverse bottom 8 bits
                  wrbyte tmp, inputstate_addr       ' store into hub ram
    
                  jmp    #:loop                     ' loop forever
    
    
    SCLK_IN       long   1<<5                       ' pin mask values
    DIN           long   1<<6
    LOAD_IN       long   1<<4
    
    inputstate_addr res  1
    tmp           res    1
    n             res    1
    
    
    
  • marzec309marzec309 Posts: 146
    edited 2011-07-08 10:05
    Your awesome, I'll give it a try. It's something to start with even if it doesn't function correctly, I'm not to fluent in PASM and have a hard time writing code from scratch.
    thanks again.
  • marzec309marzec309 Posts: 146
    edited 2011-07-08 10:23
    Just tested it Out worked great except, I had to add #1 to the Inputstate_addr for some reason it was writing to the main hub one byte off.
  • kuronekokuroneko Posts: 3,623
    edited 2011-07-08 18:19
    marzec309 wrote: »
    Just tested it Out worked great except, I had to add #1 to the Inputstate_addr for some reason it was writing to the main hub one byte off.
    I was wondering yesterday whether I should mention it but Inputstate_addr has to be 4n aligned as you can only pass parameters of this nature to PASM. So even if you pass e.g. 4n+3 as an address the lower 2 bits are cleared and the wrbyte goes to 4n.
  • Duane DegnDuane Degn Posts: 10,588
    edited 2011-07-08 19:01
    kuroneko,

    Is this a way to fix the program?
    VAR
      long  cog, InputSPtr
     
     
    PUB  Start(InputState) : okay
      InputSPtr := InputState
     
      stop
      okay := cog := cognew (@entrypoint, @InputSPtr) + 1
    PUB  stop
      '' Stop switch driver - frees a cog
      if cog
        cogstop (cog~ - 1)
     
    DAT
                  org    0
    entrypoint    rdlong    inputstate_addr, par       ' save our parameter
                  or     outa, SCLK_IN              ' setting up pins state and directions
                  or     outa, LOAD_IN
                  andn   dira, DIN
                  or     dira, SCLK_IN
                  or     dira, LOAD_IN
    :loop         andn   outa, LOAD_IN              ' toggle LOAD_IN
                  nop                               ' slow down a little to 100ns pulse
                  or     outa, LOAD_IN
                  mov    n, #8                      ' loop count
    :bitloop      test   DIN, ina  wc               ' test input bit (ina doesn't work as destination, note), carry = parity = the bit
                  rcl    tmp, #1                    ' shift carry into tmp
                  andn   outa, SCLK_IN              ' toggle SCLK_IN
                  nop                               ' slow down a little to 100ns pulse
                  or     outa, SCLK_IN
                  djnz   n, #:bitloop
                  rev    tmp, #24                   ' reverse bottom 8 bits
                  wrbyte tmp, inputstate_addr       ' store into hub ram
                  jmp    #:loop                     ' loop forever
     
    SCLK_IN       long   1<<5                       ' pin mask values
    DIN           long   1<<6
    LOAD_IN       long   1<<4
    inputstate_addr res  1
    tmp           res    1
    n             res    1
     
    

    Move the address received by Start into a long which is then read by the PASM section?

    I'm pretty sure I wouldn't have caught the error myself but once it's pointed out it's easier to see why it causes an error (like most problems).

    It compiles.

    Duane
  • kuronekokuroneko Posts: 3,623
    edited 2011-07-08 19:14
    Duane Degn wrote: »
    Is this a way to fix the program?
    Yes, just don't use a local variable for InputSPtr or if you want/have to then you should wait for the PASM cog to take over.
  • Mark_TMark_T Posts: 1,981
    edited 2011-07-09 03:06
    Yes, that'll do it. I'd forgotten about the restrictions on par (its long-aligned and only 16 bits including the trailing zeroes.)
Sign In or Register to comment.