Daniel,
- When using the "one big __near function from 0x4000...0xFFFF" approach, load PPAGE at the beginning with the page chosen for the 0x8000..0xBFFF block (naturally 0xFE).
Do you mean setting PPAGE=0xFE at the beginning of big function, before PC reached page window? Wow, that's hard.
- This way the code does not have any limitations in respect to call other banked functions at all.
Yes, I was wrong, it's quite safe to call paged functions from big function.
- An alternative would be to use a __far function and make the compiler using PPAGE==0xFE when calling it. This might however cause issues when debugging it as the debugger might not find the function at the address it is looking for it.
I tried it. Do you mean placing big function to segment like = READ_ONLY 0xFE4000 TO 0xFEBFFF? CW debugger complained it can't load code to FE4000. I think making burner reallocate 0xFE4000-0xFE7FFF to 0xFD8000-0xFDBFFF and loading produced S-records to the target will work. But it's not only hard to debug, but also more difficult to download to the target.
To make CW burning big function, I made it nonbanked, placed in segment 0x4000 TO 0xBFFF. Small nonbanked routine is used to save current PPAGE, switch PPAGE to page of foo(), call big foo() and restore PPAGE. Seems working.
Nick,
Certainly 22k routine will fit small memory model. I think I mentioned you have to edit default PRM file to define single nonbanked segment 0x4000-0xFFFF. Default PRM file defines two 16k segments 0x4000-0x7fff and 0xc000-0xffff. Of course your 22k routine doesn't fit them.
Do you have >12k of RAM variables and stack? If more than that, then you have to use paged RAM.
I think you should either switch to more suitable MCU like Coldfire, ARM etc.
Yes, you can have big function with large model. See my example attached.
Modifications made to default XDT512 PRM file:
1) remove 0x4000-0x7fff segment and all references to it.
2) remove 0xFE8000-0xFEBFFF segment and all references to it
3) create segment for big function 0x4000-0xBFFF. Currently 32k. If that won't suffice later, try moving upper end of this big segment up, along with moving bottom end of 0xC000-0xFxxx segment.
4) define placement into segment 0x4000-0xBFFF
5) In the code you have to use pragma CODE_SEG to place big function in segment defined at step 4.
Since you are trying to not touch generated code and since some #pragmas are unavoidable, you may remove generated code from project tree and #include it in small C file, like this:
--- some C file
#pragma push
#pragma CODE_SEG __NEAR_SEG BIGFUNC
#include "generated.c"
#pragma pop
----------
Code, which is calling big function must either see big function declared with near keyword, or, you may include generated
header file the same like above in your own header file, and include it in calling code.
Small function is required to save/restore PPAGE when calling big function from banked routine.