Hello!
I wonder a bit about the macro structure in Flowcode.
When repeating things in the program will then wish to use the macros.
Is it okay to call 1) component macro from a macro.
2) Call the macro from a macro?
Can there be any problems?
Very thankful for all answers
Best Regards
Dmitry
Makro in makro
Moderator: Benj
-
- Flowcode V4 User
- Posts: 36
- Joined: Mon Sep 26, 2011 10:26 pm
- Has thanked: 9 times
- Been thanked: 2 times
- Contact:
- DavidA
- Matrix Staff
- Posts: 1076
- Joined: Fri Apr 23, 2010 2:18 pm
- Location: Matrix Multimedia Ltd
- Has thanked: 58 times
- Been thanked: 258 times
- Contact:
Re: Makro in makro
Hello Dimitry,
Im sure someone will correct me if im wrong but i think that every time you call a macro from within a macro you add to the call stack, which is an indication of how many times you have nested a macro, there is no problem with going deeper into the call stack but i think most microcontrollers have a maximum call stack depth. 8 rings a bell for some PICs.
Im sure someone will correct me if im wrong but i think that every time you call a macro from within a macro you add to the call stack, which is an indication of how many times you have nested a macro, there is no problem with going deeper into the call stack but i think most microcontrollers have a maximum call stack depth. 8 rings a bell for some PICs.
- Benj
- Matrix Staff
- Posts: 15312
- Joined: Mon Oct 16, 2006 10:48 am
- Location: Matrix TS Ltd
- Has thanked: 4803 times
- Been thanked: 4314 times
- Contact:
Re: Makro in makro
Hello,
On a 8-bit PIC there is a limitation of a 8 level hardware call stack. That is you can jump up to 8 macros away from main and still know where to return when leaving the macros. An interrupt and any macro calls from this also count as levels on the stack.
If you go over this count then the compiler should warn you about it. If you get the warnings then you can switch on the BoostC software call stack which uses a combination of hardware and software to extend the number of macro jumps possible without getting lost. This however will increase the amount of time to complete an operation.
AVRs, dsPICs and ARM do not have such a strict stack limitation.
On a 8-bit PIC there is a limitation of a 8 level hardware call stack. That is you can jump up to 8 macros away from main and still know where to return when leaving the macros. An interrupt and any macro calls from this also count as levels on the stack.
If you go over this count then the compiler should warn you about it. If you get the warnings then you can switch on the BoostC software call stack which uses a combination of hardware and software to extend the number of macro jumps possible without getting lost. This however will increase the amount of time to complete an operation.
AVRs, dsPICs and ARM do not have such a strict stack limitation.
Regards Ben Rowland - MatrixTSL
Flowcode Product Page - Flowcode Help Wiki - Flowcode Examples - Flowcode Blog - Flowcode Course - My YouTube Channel
Flowcode Product Page - Flowcode Help Wiki - Flowcode Examples - Flowcode Blog - Flowcode Course - My YouTube Channel
-
- Posts: 17
- Joined: Sat Sep 17, 2011 7:10 pm
- Location: Belgium
- Has thanked: 8 times
- Been thanked: 5 times
- Contact:
Re: Makro in makro
Macro's are often used in 3 contexts
- to reuse a block of code more than once and maintain this code in 1 place only
- a block of code called by an interupt. This is just a special case of the above
- help structuring your code regardless of the fact you are calling this macro only once.
My questions are about the 3th case.
- Is there a way to tell either flowcode or the compiler to un-nest any macro which is used only once ?
This would make a lot of sence to minimize the call stack as a lot of pics can handle only 8...
I know there is some software call stack you can use to increase the max stack size above 8, but it remains a waiste of scare pic resources not to un-nest single used macros.
- about the software call stack, where can i find more information about how to activate/use it ?
Regards,
Ivan
- to reuse a block of code more than once and maintain this code in 1 place only
- a block of code called by an interupt. This is just a special case of the above
- help structuring your code regardless of the fact you are calling this macro only once.
My questions are about the 3th case.
- Is there a way to tell either flowcode or the compiler to un-nest any macro which is used only once ?
This would make a lot of sence to minimize the call stack as a lot of pics can handle only 8...
I know there is some software call stack you can use to increase the max stack size above 8, but it remains a waiste of scare pic resources not to un-nest single used macros.
- about the software call stack, where can i find more information about how to activate/use it ?
Regards,
Ivan
- Enamul
- Posts: 1772
- Joined: Mon Mar 05, 2012 11:34 pm
- Location: Nottingham, UK
- Has thanked: 271 times
- Been thanked: 814 times
- Contact:
Re: Makro in makro
HI,
For your 2nd question...you can see the following post..
http://www.matrixmultimedia.com/mmforum ... ack#p36165
I have seen one post of Ben also but can't find straight way..
Main change is this compiler option..
For your 2nd question...you can see the following post..
http://www.matrixmultimedia.com/mmforum ... ack#p36165
I have seen one post of Ben also but can't find straight way..
Code: Select all
-ld "C:\Program Files\Flowcode\v5\Tools\BoostC\lib" libc.pic16.lib rand.pic16.lib float.pic16.lib -swcs 6 2 "%f.obj" -t PIC%p -d "%d" -p "%f"
-
- Posts: 17
- Joined: Sat Sep 17, 2011 7:10 pm
- Location: Belgium
- Has thanked: 8 times
- Been thanked: 5 times
- Contact:
Re: Makro in makro
Just for completeness and helping users how to implement BoostC software stack to avoid stack overflow :
1) In the FlowCode menu select Build, Compiler options
2) choose the tab Linker/Assembler
3) in the parameter box, scroll to the end and add the following parameter :
-swcs 6 2
This should do the trick, it did for me.
Regards,
Ivan
1) In the FlowCode menu select Build, Compiler options
2) choose the tab Linker/Assembler
3) in the parameter box, scroll to the end and add the following parameter :
-swcs 6 2
This should do the trick, it did for me.
Regards,
Ivan
- Enamul
- Posts: 1772
- Joined: Mon Mar 05, 2012 11:34 pm
- Location: Nottingham, UK
- Has thanked: 271 times
- Been thanked: 814 times
- Contact:
Re: Makro in makro
Hi,
I now remember Ben's post ...He told to add as you said. Thanks for the post. Now I can easily find for others..
I now remember Ben's post ...He told to add as you said. Thanks for the post. Now I can easily find for others..