Page 1 of 1

Makro in makro

Posted: Mon Mar 12, 2012 10:19 am
by Dmitry Maximenko
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

Re: Makro in makro

Posted: Mon Mar 12, 2012 10:23 am
by DavidA
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.

Re: Makro in makro

Posted: Mon Mar 12, 2012 10:24 am
by Benj
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.

Re: Makro in makro

Posted: Sat Aug 18, 2012 8:04 pm
by IVL
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

Re: Makro in makro

Posted: Sat Aug 18, 2012 9:47 pm
by Enamul
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..

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"
Main change is this compiler option..

Re: Makro in makro

Posted: Sun Aug 19, 2012 9:22 am
by IVL
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

Re: Makro in makro

Posted: Sun Aug 19, 2012 11:19 am
by Enamul
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..