Shop OBEX P1 Docs P2 Docs Learn Events
SOLVED: Launching PASM/SPIN in 8th cog. — Parallax Forums

SOLVED: Launching PASM/SPIN in 8th cog.

WurlitzerWurlitzer Posts: 237
edited 2015-06-13 13:47 in Propeller 1
Problem:
Current application which is running fine but using 7 cogs and need to add 2 programs which will be swapped out from time to time. One is a straight forward Spin program so no problem with that one but the other is a PASM program which originally used a small SPIN program to launch it but obviously with 7 other cogs already running that won't work.
===========================================================================================

I tried to just add the PASM as a 2nd DAT segment to my Top Object and changed the entry point name but the compiler complained about duplicate label and variable names.

As all my 7 PASM files are rather large and developed over time, there are duplicates of many label and variable names. No problem when they resided in separate files and all had their own Spin programs to launch them. I would simply start. launch PASM, then stop the SPIN program.

I certainly can go and rename everything so the compiler is happy but I wonder if I am missing something very elementary.

Using the Propeller Tool for programming.

Thanks.

Comments

  • Duane DegnDuane Degn Posts: 10,588
    edited 2015-06-13 11:33
    Wurlitzer wrote: »
    I certainly can go and rename everything so the compiler is happy but I wonder if I am missing something very elementary.

    Yes, I think you are. You can place the PASM code in a separate object and have it launched from the separate object.

    Remember there is no limit to the number of objects a single cog (running the Spin interpreter) can access.

    If you could post either your whole code of the part you're wondering about I'm sure we could help.
    'from top object
      Child.Start
    ' execution returns to top object once child object has started PASM cog
    
    'from child object
    Start
      cognew(@entry, @stack)
    'execution now returns to top object
    
  • WurlitzerWurlitzer Posts: 237
    edited 2015-06-13 12:20
    Thanks for the reply Duane!

    Here is where I get wrapped around the axle and since I began using the prop I have always fought launching something in the final available cog so I always tried to make that a Spin program without an associated PASM file.


    Let me try to explain in pseudo code.

    Top Object pseudo code:

    8 Cogs running

    1) Stop PASM_code_A 'now one cog is free

    2) Obj_Code_B.Start [pure spin code here so I only need 1 free cog and I have one]

    3) No longer need Obj_Code_B but now need PASM_code_A" to run.

    4) cogstop(Cog~ - 1) [stop Obj_Code_B and now 1 free cog remains].

    Now this is where I get lost in attempting to start PASM_code_A from the Top Object.

    With 1 free Cog how do I restart PASM_code_A again without the need of a Spin file and a cog unless PASM_code_A's code resides as a 2nd DAT segment in the Top Object file?

    Again, if I must, renaming all my labels/variables is not a huge thing but if I can get it through my thick skull how it should be done it would make things easier.
  • Duane DegnDuane Degn Posts: 10,588
    edited 2015-06-13 12:30
    How was PASM_code_A originally launched?

    As I showed earlier, the PASM code doesn't need to be in the top object for the cog running the top object to start it. If the DAT segment (containing the PASM code) is in another object, the top object just needs to call a Start method to get the PASM code launched and then control would return to the top object.
  • WurlitzerWurlitzer Posts: 237
    edited 2015-06-13 12:47
    Thanks again Duane I appreciate this.

    I had PASM_Code_A in its own Spin file with just a Start and Stop method and the spin portion would just launch the PASM then stop. This is why in this program I had 7 cogs used but now I need a way to get a PASM running with only 1 free cog.

    If I tried to now use the Top Object to re-launch this same program I am assuming I need 2 free cogs again.

    From Top Object:
    MIDI.start(7,@MasterArray)
    



    Midi Object:
    PUB start(_midiPin, _Ptr_HubRamStartAddr): okay  
    
     tmpCog :=cogid
      okay := cog := cognew(@entry, _Ptr_HubRamStartAddr) + 1                              
     WaitCnt(80_000_000 + Cnt)
    
    PUB stop
    
    '' Stop MIDI driver - frees a cog
    
      if cog
        cogstop(tmpCog~ - 1)
    
  • WurlitzerWurlitzer Posts: 237
    edited 2015-06-13 12:52
    I guess to put this in its simplest terms:

    What is the proper method to start a PASM program if you only have 1 free cog?
  • Phil Pilgrim (PhiPi)Phil Pilgrim (PhiPi) Posts: 23,514
    edited 2015-06-13 13:18
    I think you might be confusing objects and cogs. When you call a start method in another object, that method runs in the cog from which is was called, not in a new one. So that method can easily be used to start a PASM program in the remaining free cog.

    -Phil
  • WurlitzerWurlitzer Posts: 237
    edited 2015-06-13 13:25
    Thanks Phil, I have obviously from day 1 been assuming that calling Obj.start which was to launch PASM code required 2 cogs initially. One for the short spin code [even though it would be killed immediately] and one for the actual PASM so I always avoided PASM if I only had one cog free. Now the light has gone off with the method being run in my Top Object.

    Boy, I don't know if I can recover all the hair follicles I have lost over the years avoiding PASM if I only had 1 free cog.

    You have made my day!
  • Duane DegnDuane Degn Posts: 10,588
    edited 2015-06-13 13:26
    I agree with Phil, your top method can just use the same call:
    MIDI.start(7,@MasterArray)
    

    The act of calling the start method doesn't launch a new Spin cog. The call to "MIDI.start" only launches the single PASM cog. You only need one cog free when you call MIDI.start.

    Edit: I hadn't seen post #8. It looks like you understand now.
  • WurlitzerWurlitzer Posts: 237
    edited 2015-06-13 13:47
    Yes Duane, it is amazing I have done so much with the prop without realizing where the objects were physically executed from. You and Phil both have cleared up a major misconception which I have been coding around for years.

    Thanks again to both of you gentlemen.
Sign In or Register to comment.