How would I COMPILE for 2 DIFFERENT versions of hardware?
DavidM
Posts: 630
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
eg..
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
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 = 250I 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
#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
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.
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
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.
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
Okay, now I'm dying of curiosity. What kind of models? Model airplanes, boats, submarines, Ts?
Sorry for being a bit off topic.
Duane
ProjectA.spin
Main.spin
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.
Just a single ' will enable a block.
Jonathan
MainA.spin
MainB.spin
I still like #defines better up to a point.
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
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
Let me look into that, sounds interesting, "DIFFERENT TOP OBJECTS",
thanks
Dave M