PSoC 3 Code Optimization | Cypress Semiconductor
PSoC 3 Code Optimization
Summary: 0 Replies, Latest post by Gautam Das on 20 Nov 2011 03:47 AM PST
Verified Answers: 0
20 Nov 2011 03:47 AM PST#1
Are you running out of 8051 code space in your PSoC 3, even after applying all of the Keil C51 compiler's optimizations? If you're using PSoC Creator's default mode, you're probably not taking advantage of many features of the 8051 architecture, which can greatly increase your code efficiency.
One common misconception when programming the 8051 is that the only way to get optimal code is to use 8051 assembler. This is not true, mainly because of the high performance capabilities of the Keil C51 compiler. Most if not all PSoC 3 8051 code can be written in C, and it can be made to be small, fast, and efficient. The cost is that you must use Keil-specific keywords, and C code containing these keywords may not be easily portable to other processors such as the Cortex-M3 in PSoC 5. However, PSoC Creator offers equivalent macros that make porting easier.
In any case, by using these keywords or macros, and with knowledge of some code architecture issues, you can make your 8051 code faster and smaller, and avoid using the PSoC 3 8051 in its slowest and least efficient mode.
The 8051 core is a 256-byte address space that contains 256 bytes of SRAM plus a large set of registers called Special Function Registers (SFRs). A lot of functionality is packed into this “internal space” and the 8051 is most efficient when it works in this space.
The Keil C compiler defines three memory models—small, compact, and large. The default model for PSoC Creator is large (to maintain compatibility with PSoC 5), but that default can be overridden for individual variables, functions, and even entire modules. The following code illustrates how this works.
The keywords ‘data’, ‘idata’, and 'pdata' are used to designate other models besides the (default) large model. In the above code, you can see that successively larger models require more flash bytes and more CPU cycles. So one of the most important methods to reduce code size if to place your most often-used variables in one of the internal data spaces.
In addition to the above tip, AN60630 provides a wealth of information on how to further reduce your code size by using the 8051 to its fullest capability.