Shop OBEX P1 Docs P2 Docs Learn Events
ICCPROP and cognew_native — Parallax Forums

ICCPROP and cognew_native

WardWard Posts: 4
edited 2009-03-09 09:49 in Propeller 1
I am new to the Propeller and ICCPROP.· I am trying to run a native assembler cog via cognew_native.· I can make it work as long as I don't try to pass a parameter to the assembler cog.

I am trying to send a PIN number to the assembler cog.· This new cog is to blink the passed pin.

The following code·sometimes blinks·the pin a few times then stops or just lights up multiple pins.· I think my problem is related to the data variables in my Assembler code.· Any ideas?


#include <stdio.h>
#include <propeller.h>

extern void ScanPin(void*);

void main(void) {
·· pin = 23;
·· cognew_native(ScanPin, (void *)&pin);

while (1) {}
}



Assembler Code:

··········· .area cog(abs)

_ScanPin::
··········· mov····· ParPtr,par·········· //get PAR address

··········· rdlong·· Tmp,ParPtr·········· //get pin#
··········· mov····· Pin,#1·············· //Put 1 into PIN
··········· shl····· Pin,#Tmp··········· ·//Shift PIN left
··
·· ········ mov····· dira,Pin············ //Set dira

Loop1:····· xor····· outa,Pin··········· ·//flip PIN

············mov····· Tmp,cnt············· //delay
············add····· Tmp,Delay
············waitcnt· Tmp,Delay

············jmp ···· Loop1················//flip again


ParPtr:·····res·1
Pin:········res·1
Tmp:········res·1
Delay:······.long·5000000



Comments

  • Mike GreenMike Green Posts: 23,101
    edited 2009-03-08 16:20
    Your SHL shifts Pin left by the address of Tmp, not the content of Tmp. Leave out the "#".
  • WardWard Posts: 4
    edited 2009-03-08 17:01
    Thanks, I missed that.· The program still does not work.·

    I am sure that my variables in the Assembler module are not defined properly.· It runs very strange.· As an example, if I add the line· "Testing:· res· 10"· in front of my other reservations, the program fails very differently.
  • KyeKye Posts: 2,200
    edited 2009-03-08 17:58
    Note that that the par register zeros out the first two bits of anything put in it since it was made to hold the address of some long in memory. That said, if you are passing a pin number shift that left by two before launching the cog and then in asm shift the number right by two to restore it.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Nyamekye,
  • telluriantellurian Posts: 52
    edited 2009-03-08 18:00
    The res statements must be last, put your Delay: parameter ahead of the res statements.

    i.e. use:

    Delay:      .long 5000000
    ParPtr:     res 1
    Pin:        res 1
    Tmp:        res 1
    
    
  • WardWard Posts: 4
    edited 2009-03-08 18:43
    Thanks for the tips.· I am passing the address (* to a long int) to my assembler routine.· Therefore I don't need to shift around.· (good point though)

    I moved the Delay to then begining.· The code runs a bit better but still stops after a few seconds.



    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Ward M. Elder
  • WardWard Posts: 4
    edited 2009-03-08 19:28
    Well.. I figured it out...· My line:· JMP· LOOP1 was incorrect.· It is supposed to be· JMP #LOOP1.·· I was jumping all over the place.·· Thanks to everyone for the tips and good info.· Just too many different assemblers in my 50 year old brain... (even Mainframe assembler...wow...)

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Ward M. Elder
  • ImageCraftImageCraft Posts: 348
    edited 2009-03-09 07:42
    That's why I prefer to write in C smile.gif

    Lets see:
    mov src,dst
    or
    mov dst,src ?

    Or my favorite, under MSP430, it's
    call #name
    just like the jump above....
  • MagIO2MagIO2 Posts: 2,243
    edited 2009-03-09 09:49
    Didn't you forget the # in the jump?

    jmp #Loop1

    Stumbled over the same problem these days ;o)
    Or isn't it like in Propeller-Tools PASM?
Sign In or Register to comment.