Shop OBEX P1 Docs P2 Docs Learn Events
Spin a good fit for the Propeller - Page 2 — Parallax Forums

Spin a good fit for the Propeller

2»

Comments

  • Heater.Heater. Posts: 21,230
    edited 2014-09-01 23:50
    ErNa,
    The only difference to "normal" interrupts is the mechanism to trigger the routine.

    Wait a minute.

    A function call is nothing like an interrupt diverting CPU attention. A function has parameters an interrupt does not. A function has return values an interrupt does not. A function happens when I want it to not at some random time as I run.

    A function call is nothing like a different process running on a different CPU. A function returns a process may not. For example.
  • ElectrodudeElectrodude Posts: 1,658
    edited 2014-09-02 09:51
    ErNa wrote: »
    A function call guarantees availability of a result the moment the program, interrupted by the function, resumes.

    That makes me wonder. If a cognew'd function returns (stopping the cog), can you find its result somewhere in its stack? This depends on which flavor of anchor is used, so I doubt it will work but will try to find out now.
  • Phil Pilgrim (PhiPi)Phil Pilgrim (PhiPi) Posts: 23,514
    edited 2014-09-02 10:19
    According to my test program here:
    CON
    
      _clkmode      = xtal1 + pll16x
      _xinfreq      = 5_000_000
    
    
    OBJ
    
      pst : "parallax serial terminal"
      
    VAR
    
      long stack[30]
    
    PUB start
    
      pst.start(115200)
      cognew(tester, @stack)
      waitcnt(cnt + clkfreq / 10)
      pst.dec(stack[3])
      repeat
    
    PUB tester
    
      return 1234567
    

    The result is returned on stack[3]

    -Phil
  • Dave HeinDave Hein Posts: 6,347
    edited 2014-09-02 10:26
    stack[3] is not the return location -- it's just the scratch area on the stack where the value of 1234567 was loaded temporarily. A return value is loaded on the stack only if the calling method requires a return value. This is indicated by a bit in the stack frame. I suspect the default stack frame that is used does not specify loading a return value. You could return a value through the RESULT variable, which is located at stack[2]. The following program demonstrates how that would work.
    con
      _clkmode = xtal1+pll16x
      _clkfreq = 80000000
    
    obj
      ser : "FullDuplexSerial"
    
    dat
      stack long 0[20]
    
    pub main
      waitcnt(clkfreq*3+cnt)
      ser.start(31, 30, 0, 115200)
      cognew(sub1, @stack)
      repeat until stack[2]
      ser.str(string("result = "))
      ser.hex(stack[2], 8)
      ser.tx(13)
      waitcnt(clkfreq/10+cnt)
    
    pub sub1
      result := $deadbeef
    
  • ElectrodudeElectrodude Posts: 1,658
    edited 2014-09-02 10:48
    Cool! I'm still stuck trying to figure out what the RUN (opcode $15 = %0101_01 = j5 nz_and_nc) PNUT bytecode does and how it has anything to do with strcomp.
  • Phil Pilgrim (PhiPi)Phil Pilgrim (PhiPi) Posts: 23,514
    edited 2014-09-02 10:49
    'Interesting, Dave. Thanks for clearing that up.

    -Phil
Sign In or Register to comment.