Shop OBEX P1 Docs P2 Docs Learn Events
Is there a way to simulate a #ifdef directive in PASM/SPIN? — Parallax Forums

Is there a way to simulate a #ifdef directive in PASM/SPIN?

One of the beauties of C/C++ compilers is the #ifdef directive.

What I would like to do is define certain longs like VSCL configs, etc. for different oscillator frequencies.

For example:
#ifdef OSC6_25MHZ
   vscl_front_porch = 120
#endif

#ifdef OSC5_00MHZ
   vscl_front_porch = 86
#endif


I *might* be able to simulate this behavior with Sublime Text using a custom build process. Perhaps dynamically generate a file and then load that into Propeller IDE.

I'm interested in knowing if anyone else has done something like this.

I'd rather not do a bunch of if/else statements in SPIN if I don't have to. It's not the end of the world but when you're counting bytes, everything matters. :-)

Thanks.

Comments

  • PropellerIDE uses OpenSpin if I'm not mistaken, which supports basic preprocessor options:
    https://github.com/parallaxinc/OpenSpin/wiki/Preprocessor
  • Ah, I see that now.

    Thanks for the tip!

  • I've done things like that in Spin by having objects that are just CON blocks with constants. In the client code, you do something like this:
    OBJ:
      Constants : "Con_5mhz.spin"
    
    ...
    
      vscl_front_porch := Constants#FrontPorchSetting
    

    By just switching that "Constants" object to reference another file, you can have access to a different bank of constants with identical names, but different values. It's not as flexible as #defines, but for Spin it's not bad, and it'll work in pasm or spin code.

    J
  • kwinnkwinn Posts: 8,697
    JasonDorie wrote: »
    I've done things like that in Spin by having objects that are just CON blocks with constants. In the client code, you do something like this:
    OBJ:
      Constants : "Con_5mhz.spin"
    
    ...
    
      vscl_front_porch := Constants#FrontPorchSetting
    

    By just switching that "Constants" object to reference another file, you can have access to a different bank of constants with identical names, but different values. It's not as flexible as #defines, but for Spin it's not bad, and it'll work in pasm or spin code.

    J

    Great idea. Thanks for sharing it.
  • Cluso99Cluso99 Posts: 18,069
    You can use clkfreq as a variable. This way your code can run correctly as an object without knowing the frequency in advance.
  • Another choice is to simply compute the values. Once the computation is done, if the driver is intended to be static, overwrite the computation with some other data, or just ignore it.

    If the driver is dynamic, then the computation can be used when changes are needed. For video, a good time to perform this is during the VBLANK, so that new parameters can take effect next frame.

  • kwinnkwinn Posts: 8,697
    potatohead wrote: »
    Another choice is to simply compute the values. Once the computation is done, if the driver is intended to be static, overwrite the computation with some other data, or just ignore it.

    If the driver is dynamic, then the computation can be used when changes are needed. For video, a good time to perform this is during the VBLANK, so that new parameters can take effect next frame.

    Or it could be calculated in spin and stored in hub ram so the resolution could be updated on the fly.
  • Indeed it could.
  • Here is what I ended up doing. I now just use Sublime Text and a build system that runs a script pointed to BST. Works GREAT.

    So I just pre-compute the values and use it like:
    #define MHZ500
    
    #ifdef MHZ500
    	FRQA_Calculation			= $16E8_B9FE		' 80 MHz
    #endif
    #ifdef MHZ625
    	FRQA_Calculation			= $1253_C7FE		' 100 MHz
    #endif
    
    
  • Is there a reason you couldn't use OpenSpin? BST is no longer supported. You'd be better off moving to OpenSpin.
  • David Betz wrote: »
    Is there a reason you couldn't use OpenSpin? BST is no longer supported. You'd be better off moving to OpenSpin.

    I'm sorry, I misspoke. I actually use OpenSpin for compiling the source. But I use BST to upload to the propeller.

    Is there a better way to upload/run from a batch file?

    Thanks.
  • cbmeeks wrote: »
    David Betz wrote: »
    Is there a reason you couldn't use OpenSpin? BST is no longer supported. You'd be better off moving to OpenSpin.

    I'm sorry, I misspoke. I actually use OpenSpin for compiling the source. But I use BST to upload to the propeller.

    Is there a better way to upload/run from a batch file?

    Thanks.
    You should be able to use propeller-load that comes with SimpleIDE or my p1load program that you will have to build from sources on github.

  • Cool, I will give those a shot.

    Thanks again.
Sign In or Register to comment.