Shop OBEX P1 Docs P2 Docs Learn Events
Starting a cog to execute SPIN from assembly — Parallax Forums

Starting a cog to execute SPIN from assembly

Andrey DemenevAndrey Demenev Posts: 377
edited 2009-10-26 14:41 in Propeller 1
Is it possible to start a cog to execute SPIN code from assembly? I have an application that requires all eight cogs to run assembly. At certain moment, I have to execute SPIN code to process data gathered by assembly code.

Comments

  • MagIO2MagIO2 Posts: 2,243
    edited 2009-10-26 08:14
    Of course it is possible. The bootloader of the propeller is written in PASM and has to start the SPIN interpreter as well. So, that's the place where I'd look for this information: booter.spin
    Found it in this thread: http://forums.parallax.com/forums/default.aspx?f=25&m=364841
    Maybe the also attached SpinStart helps as well - did not have a look into it so far.

    You really need all other 7 COGs to run continuously in parallel? Or do they spend most of the time waiting? I think it would be easier to swap COG-code instead of starting SPIN interpreters.
  • Andrey DemenevAndrey Demenev Posts: 377
    edited 2009-10-26 08:34
    MagIO2, thanks for the link, I'll have a look.

    I have to run all 8 cogs with identical PASM code. They gather data to hub memory for some time, at high speed, then stop. After that, I need to transfer the data to external device. Possibly, I will go "everything-PASM" way - but first want to check if I can start the communication routine written in SPIN from PASM - it would be easier to code the communication in SPIN
  • MagIO2MagIO2 Posts: 2,243
    edited 2009-10-26 09:32
    Is it just for reading input-pins or is there more work to do for each COG? What data (byte/word/long) do you read from which kind of device (I2C/...)?

    Maybe you can improve the PASM-code, so that in the end you don't need all 8 COGs. For example there is a serial port object which allows 4 serial interfaces.
  • Andrey DemenevAndrey Demenev Posts: 377
    edited 2009-10-26 09:43
    I do need all eight. Data gathering cycle accesses hub memory each 3 instructions, so each cog never misses its hub access window. The extra 2 instructions are used to advance memory pointer, check for stop conditions etc. Data is just a word read from input pins. What I need is maximum data rate, and equal time between data samples. So the options are to use 1, 2, 4 or 8 cogs - with 16, 8, 4 or 2 clock cycles sampling interval, respectively. Really, there is nothing to improve in assembly code - you just cannot access hub memory more frequently than each 16 cycles [noparse]:)[/noparse]

    Post Edited (Andrey Demenev) : 10/26/2009 9:48:37 AM GMT
  • MagIO2MagIO2 Posts: 2,243
    edited 2009-10-26 09:56
    But maybe you can gather two 16 bit values and write a long to HUB RAM, so you can get the same performance with half of the COGs.
  • Andrey DemenevAndrey Demenev Posts: 377
    edited 2009-10-26 10:26
    Yes, it would be nice if it was possible to read 2 words, pack them into long and advance memory pointer, and also execute at least one additional instruction to check stop condition - all within 11 cycles, leaving 5 cycles for hub access. But I doubt that is possible
  • Cluso99Cluso99 Posts: 18,069
    edited 2009-10-26 10:49
    Firstly, you can start a cog in spin from pasm. You have to setup the parameter to be passed in the cogstart function. Maybe someone else can tell you how this is done, but the booter (and spin interpreter) do exactly this.

    I am presuming you are sampling more than the available cog memory (480+ long samples)? I used 4 cogs to achieve a 12.5uS sample rate but only 480 x 4 samples. I was just sampling the 32 I/O pins. Of course 480 x 8 would be possible using all cogs.

    However, for more samples you will have to use the hub, which you are obviously doing. If you are sampling bytes, you may find it faster/easier to block the bytes into longs and then write a hub long.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Links to other interesting threads:

    · Home of the MultiBladeProps: TriBlade,·RamBlade,·SixBlade, website
    · Single Board Computer:·3 Propeller ICs·and a·TriBladeProp board (ZiCog Z80 Emulator)
    · Prop Tools under Development or Completed (Index)
    · Emulators: CPUs Z80 etc; Micros Altair etc;· Terminals·VT100 etc; (Index) ZiCog (Z80) , MoCog (6809)
    · Search the Propeller forums·(uses advanced Google search)
    My cruising website is: ·www.bluemagic.biz·· MultiBladeProp is: www.bluemagic.biz/cluso.htm
  • BeanBean Posts: 8,129
    edited 2009-10-26 11:23
    Has anyone actually done this ? I thought it couldn't be done ?
    I'd love to see how if anyone has acheived it.

    Bean.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
    Does that byte of memory hold "A", 65, $41 or %01000001 ?
    Yes it does...


    ·
  • Cluso99Cluso99 Posts: 18,069
    edited 2009-10-26 13:30
    Most definately it can be done. For reference, see the Spin Interpreter (or my faster undebugged version) thread in the tools index link in my signature.

    IIRC, the spin interpreter, which by the way is pasm, picks up the parameters (including the stack address), passes those the booter code which resides in hub ROM. So you have to emulate this sequence. The hardest part was figuring out where the spin code blocks reside to set the required parameters.

    I have successfully restarted multiple different versions of the spin interpreter, but not from pasm. So it's part way there. I don't know enough about the binary to know what parameters the spin code requires to setup the call. But it is all in the spin interpreter and booter code.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Links to other interesting threads:

    · Home of the MultiBladeProps: TriBlade,·RamBlade,·SixBlade, website
    · Single Board Computer:·3 Propeller ICs·and a·TriBladeProp board (ZiCog Z80 Emulator)
    · Prop Tools under Development or Completed (Index)
    · Emulators: CPUs Z80 etc; Micros Altair etc;· Terminals·VT100 etc; (Index) ZiCog (Z80) , MoCog (6809)
    · Search the Propeller forums·(uses advanced Google search)
    My cruising website is: ·www.bluemagic.biz·· MultiBladeProp is: www.bluemagic.biz/cluso.htm

    Post Edited (Cluso99) : 10/26/2009 1:37:23 PM GMT
  • MagIO2MagIO2 Posts: 2,243
    edited 2009-10-26 13:44
    '
    '
    ' Launch program in ram
    '
    launch rdword address,#$0004+2 'if pbase address invalid, shutdown
           cmp address,#$0010 wz
     if_nz jmp #shutdown
    
           rdbyte address,#$0004 'if xtal/pll enabled, start up now 
           and address,#$F8 '..while remaining in rcfast mode
           clkset address
    
    :delay djnz time_xtal,#:delay 'allow 20ms @20MHz for xtal/pll to settle
    
           rdbyte address,#$0004 'switch to selected clock
           clkset address
    
           coginit interpreter 'reboot cog with interpreter
    
    

    That's the code in booter.spin ... Should not be to hard to test that ...
  • Mike GreenMike Green Posts: 23,101
    edited 2009-10-26 13:49
    The I2C / SPI low level driver that's part of FemtoBasic (written in Pasm) has a routine that starts up a Spin interpreter after loading a program from EEPROM or an SD card. Download FemtoBasic from the ObEx and look at sdspiFemto.spin starting at the label "nowBootSpin".
  • MagIO2MagIO2 Posts: 2,243
    edited 2009-10-26 13:59
    I think what you need in the main of your SPIN program is a possibility to check that it is a restart. Say a variable in the dat section which is compiled to contain a 0, but changed before starting all the PASM-COGs to another value.

    if rerun==0
      ' do the setup
      rerun := 1
      ' start all the COGs
    else
      ' do whatever you wanna do after PASM finished
    



    PS: As you said all your COGs run the same code, so it might be wise to let only one restart the interpreter

    myId   mov      myId, COGID WZ
    if_NZ  cogstop  myId
     
           ' code for restarting interpreter
    



    Post Edited (MagIO2) : 10/26/2009 2:10:29 PM GMT
  • Andrey DemenevAndrey Demenev Posts: 377
    edited 2009-10-26 14:41
    Thak you guys (and gals maybe? - always hard to know at the forums [noparse]:)[/noparse] ) for your answers.

    I think, finally I will have everything in PASM - the data gathering loops are short, leaving plenty of COG memory for communication code. Anyway, I have learned from your answers here, thanks a lot.
Sign In or Register to comment.