Freescale 高级S12系列单片机编程
合集下载
相关主题
- 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
- 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
- 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。
Freescale and the Freescale logo are trademarks of Freescale Semiconductor, Inc. All other product or service names are the property of their respective owners. Freescale Semiconductor, Inc. 2006.
TM
8
Banked Memory Model
Freescale and the Freescale logo are trademarks of Freescale Semiconductor, Inc. All other product or service names are the property of their respective owners. Freescale Semiconductor, Inc. 2006.
TM
13
__near and __far applied to variables or data
char __far variable; A variable declared __far is considered by the compiler to be allocated in a banked memory segment an has to be accessed through a page switch routine. (Like in the large memory model) In what scenarios would we have banked data ? The only banked internal memory resource is Flash (read-only). Therefore if using only internal resources, only constant data (read-only data) can be paged. The other scenario is where we have external RAM accessed through a paged area.
Advanced C programming for 16-bit MCUs
Austin, Texas 25-29 September, 2006
TM
Freescale and the Freescale logo are trademarks of Freescale Semiconductor, Inc. All other product or service names are the property of their respective owners. Freescale Semiconductor, Inc. 2006.
Freescale and the Freescale logo are trademarks of Freescale Semiconductor, Inc. All other product or service names are the property of their respective owners. Freescale Semiconductor, Inc. 2006.
LARGE (Suited when using both code and data in banked memory)
both code and data are accessed using paged conventions Be careful, This causes great overhead.
1
Introduction
What is this training about ?
TM
Agenda
Memory
Models functions calls by hand
Optimizing Running Running
routines in RAM a function from the Stack
TM
3
Memory Models
Models! Where?
TM
What is a memory model ?
Memory Models
A memory model is a set of rules that changes the default behavior of the compiler. It tells the compiler what instructions to generate when accessing data and calling functions. The Compiler for the 16 bits MCU’s supports three different memory models.
Freescale and the Freescale logo are trademarks of Freescale Semiconductor, Inc. All other product or service names are the property of their respective owners. Freescale Semiconductor, Inc. 2006.
TM
12
Overriding default access to variables
__near and __far keywords can also be applied to variable declarations : char __near variable; A variable declared __near is considered by the compiler to be allocated in the zero page (first 256 bytes of the memory space, address range 0x00 – 0xFF) Accessing variables in the zero page generates less code and executes faster since the address used to access them is only one byte long.
Freescale and the Freescale logo are trademarks of Freescale Semiconductor, Inc. All other product or service names are the property of their respective owners. Freescale Semiconductor, Inc. 2006.
A call to a banked function is more expensive both in codesize and execution time.
Freescale and the Freescale logo are trademarks of Freescale Semiconductor, Inc. All other product or service names are the property of their respective owners. Freescale Semiconductor, Inc. 2006.
SMALL ( code and data fit in 64Kb )
Data and functions are accessed by default with 16 bit addresses.
BANKED (code in banked memory)
Data is also accessed with 16 bit addresses, functions are called using banked calls
TM
7
Small Memory Model
Freescale and the Freescale logo are trademarks of Freescale Semiconductor, Inc. All other product or service names are the property of their respective owners. Freescale Semiconductor, Inc. 2006.
TM
6
Comparison between memory models
Let’s compare the assembly instructions generated by the compiler with the following simple code:
Freescale and the Freescale logo are trademarks of Freescale Semiconductor, Inc. All other product or service names are the property of their respective owners. Freescale Semiconductor, Inc. 2006.
1. 2. 3. 4.
The current PPAGE page number has to be saved The called function’s page number has to be written to the PPAGE register The function has to be called. When the function returns, the PPAGE value has to be restored.
TM
5
Memory Models
Differences when calling banked and non-banked functions
If a function is in banked memory, it has to be called differently than a function in non–banked memory. In particular:
TM
9
Large Memory Model
Freescale and the Freescale logo are trademarks of Freescale Semiconductor, Inc. All other product or service names are the property of their respective owners. Freescale Semiconductor, Inc. 2006.
TM
10
wk.baidu.com
How to change default behavior locally
Remember that any memory model allows accesses to banked code or data, It is only the default behavior that changes ! The keywords __far and __near specify the calling convention for functions. Far function calls can “cross” pages. Near function calls must stay in the same page. How to override the calling convention of a function ? using keywords __near and __far ! In the SMALL memory model, functions are near, data is near. In the BANKED memory model functions are far, data is near. In the LARGE memory model functions and data are far by default.
TM
11
Overriding calling convention with __near and __far
Freescale and the Freescale logo are trademarks of Freescale Semiconductor, Inc. All other product or service names are the property of their respective owners. Freescale Semiconductor, Inc. 2006.