Shop OBEX P1 Docs P2 Docs Learn Events
How would I COMPILE for 2 DIFFERENT versions of hardware? — Parallax Forums

How would I COMPILE for 2 DIFFERENT versions of hardware?

DavidMDavidM Posts: 630
edited 2010-08-09 19:13 in Propeller 1
HI,

I currently have a (BIG) SPIN PROJECT which is compiled for MODEL 1,

I also need to compile for MODEL 2 . ( its 95 percent the same code )

I would like to change at COMPILE TIME the "Model Number" I want to compile for, so I only have to maintain ONE PROJECT for both versions

My code will work with both models, but there are some differences,

such as..

A few Pin Definitions, Variable Array Sizes, System Parameters etc.

For example..

I have a constant called "kMyDataSize" which is set different for each model

eg
for Model 1 , kMyDataSize = 100

for Model 2 , kMyDataSize = 250
I then calculate the size of some byte arrays & some long arrays based on the value of that constant.

eg..
LONG MyData[kMyDataSize*2]
The ONLY solution I can think of is to have 3 SETS OF CONSTANTS in my MAIN OBJECT!

1 set for the Common constants and 1 set each for the 2 different models, which before I compile, I turn ON or OFF using comment symbols, but this seems messy.

I would like to just set, say 1 CONSTANT at the start of the constants block to indicate which model I want to compile for..

i.e 1 or 2.


Does anyone have a SMARTER way of doing this?
NOTE: some CONSTANTS need to be set so they can be used for the BYTE & LONG array size calculations used in the VAR Block ( which I have described above).

regards

Dave M

Comments

  • Heater.Heater. Posts: 21,230
    edited 2010-08-08 23:38
    BST is a clone of the Propeller Spin Tool. It supports conditional compilation to do exactly what you want. So you can write in your Spin code something like this:

    #ifdef MODEL_1

    #elsifdef MODEL_2

    #endif

    You can define MODEL_1 or MODEL_2 in the code OR in the IDE compile options.

    Search this forum for BST* by BradC.

    Edit: Try here http://forums.parallax.com/showthread.php?t=107051&page=143
  • T ChapT Chap Posts: 4,223
    edited 2010-08-08 23:45
    What I do in a similar situation (older and newer hardware revisions) is to have one program, but use an on board LCD with some buttons to choose which version to work with. You could also use jumpers on a header or other hardwire method. So for example if the pins are different:
    If version == new
       xpin := 16
    elseif version == old
       xpin := 21
    
    

    This is a simplified example but you can use IF or CASE to select the right values for the right board. In my experience, dealing with changes to the code itself becomes a big hassle(commenting out parts). At some point you end up with multiple versions, forget which has been updated with newest features/bug fixes etc, and you end up in a full time process of keeping track of what version software someone has. In hindsight, one version is far better even though it is often a bit of work to create code that can coexist.
  • DavidMDavidM Posts: 630
    edited 2010-08-08 23:59
    Hi T Chap,

    I already thought of that, its easy to set up variables that are a FIXED SIZE, but my main concern is the setting up of the ARRAYS, My model 2 used a lot more MEMORY which has to be declared at COMPILE TIME,

    So HEATER's idea , that is, using BST wood be an answer, even though I am a MAC USER, I would hate to say I have tried the BST on the MAC, but because it does not have any "INDENTATION LINES", I find it very difficult to use, I understand that this is a big ask of Brad to do this in BST, but I just can't "get to like it" , because of this missing feature, so I am stuck with the PC Version of SPIN IDE.

    thanks
    Dave M
  • DavidMDavidM Posts: 630
    edited 2010-08-09 00:57
    Hi All,

    OK , for now I have sorted it out,

    I am just going to have 1 LINE for each model in the CONSTANTS BLOCK, which I will turn on or off during compile time.

    In this line I will have the Model Number , And the Array size.
    CON
        kMyModelNo = 1, kMyArraySize = 100
        'kMyModelNo = 2, kMyArraySize = 250 ' This is turned OFF in this example
    

    The key is that the kMyArraySize constant must be declared before the VAR BLOCK variables are declared, That constant is used in a few array size calculations, I just modified my code and it works.

    The rest of the SYSTEMS SETTING are done with a CASE STATEMENT, in my INIT Method and this is easy to do and easy to read! the case statement just needs the ModelNoConstant, and I can then set heaps of parameters.


    Regards

    Dave M
  • Duane DegnDuane Degn Posts: 10,588
    edited 2010-08-09 07:41
    @David M

    Okay, now I'm dying of curiosity. What kind of models? Model airplanes, boats, submarines, Ts?
    Sorry for being a bit off topic.

    Duane
  • lonesocklonesock Posts: 917
    edited 2010-08-09 08:17
    You can reference a sub-object's constants in the parent object by using the subobj#constname syntax. That way you can do something like:

    ProjectA.spin
    CON
      array_len = 128
      random_thing = 17
    

    Main.spin
    OBJ
      const: "ProjectA"
      'const: "ProjectB"
    
    VAR
      long demo_array[ const#array_len ]
    

    Just select the sub-object you want to define all the constants inside your main program. Another easy way to do this is use the block comment brackets.
    CON
    
    ' Project A is selected
    '{ Project A
      array_len = 128
      random_thing = 17
    ' Project A }
    
    ' Project B is _NOT_ selected
    { Project B
      array_len = 16
      random_thing = 3
    ' Project B }
    
    Just a single ' will enable a block.

    Jonathan
  • jazzedjazzed Posts: 11,803
    edited 2010-08-09 08:31
    Additionally using Lonesock's model which I use often, one can also have different main "top object" file wrappers.

    MainA.spin
    OBJ
      const: "ProjectA"
    
    VAR
      long demo_array[ const#array_len ]
    
    ' common code
    

    MainB.spin
    OBJ
      const: "ProjectB"
    
    VAR
      long demo_array[ const#array_len ]
    
    ' common code
    

    I still like #defines better up to a point.
  • T ChapT Chap Posts: 4,223
    edited 2010-08-09 08:31
    I don't understand why you can't have BOTH arrays in the code, and just use some simple code to choose which array is being used in the beginning or on a case by case base with IF statements at the time the arrays are accessed? Also, why doesn't the larger array work as the only array for large and small requirements?
  • DavidMDavidM Posts: 630
    edited 2010-08-09 16:34
    Duane Degn wrote: »
    @David M

    Okay, now I'm dying of curiosity. What kind of models? Model airplanes, boats, submarines, Ts?
    Sorry for being a bit off topic.

    Duane

    Hi Duane, I can tell you that they are definitely NOT SUPER-MODELS!

    No, seriously, For the purpose of my question it does not matter, ( its confidential until my products are released) sorry about that, I try to word my questions in a GENERIC FORM so that they can be useful to other people.

    regards

    Dave M
  • DavidMDavidM Posts: 630
    edited 2010-08-09 16:41
    T Chap wrote: »
    Also, why doesn't the larger array work as the only array for large and small requirements?

    Good Point T Chap, Well ONE ARRAY size would work with both models! But I have solved the issue anyway.

    Just a note, THE ARRAY DATA takes up about 80% of the eprom space ( at least for the larger model)
    In the Smaller model, clearing and reading the arrays can take some time if the array was big, for the larger model, this extra time is expected. But I could probably work on that issue anyhow,

    Also, The array size variable is used in MANY OTHER CALCULATIONS as I have generic code for most of my project.

    regards

    Dave M
  • DavidMDavidM Posts: 630
    edited 2010-08-09 16:44
    jazzed wrote: »
    Additionally using Lonesock's model which I use often, one can also have different main "top object" file wrappers.

    Let me look into that, sounds interesting, "DIFFERENT TOP OBJECTS",


    thanks

    Dave M
  • Cluso99Cluso99 Posts: 18,069
    edited 2010-08-09 19:13
    As has already been said, try bst and you will be pleasantly surprised how good this compiler & IDE is. ZiCog uses it with all the hardware variants defined.
Sign In or Register to comment.