Introduction:
The following method applies only to the small (-ms) and banked (-MB) memory model, not to the large (-ML) memory model.
At the same time, Freescale recommended less than 32k code using small, greater than 32k code using banked, is not recommended to use large.
RAM: There are two methods of using banked RAM:
1. Use the Local address
2. Use global address (greater addressing)
First look at the local address method:
First, we need to define a variable in. c:
#pragma data_seg __rpage_seg paged_ram/* The description of Paged_ram is in PRM file */
unsigned char banked_var;
#pragma data_seg DEFAULT
Next, we also declare this variable in. h:
#pragma data_seg __rpage_seg paged_ram/* The description of Paged_ram is in PRM file */
extern unsigned char banked_var;
#pragma data_seg DEFAULT
In this way, we can use this variable.
For example: I can assign a value to this variable, Banked-var = 0x5, but if you want to use the pointer to point to this variable, you need to do the following:
unsigned char * __rptr ptr_var;/* The definition of this pointer does not need to be defined in Paged_ram and needs to be confirmed where the variable is defined. */
Ptr_var = &banked_var;
Note the point:
The segments of the PRM file must be written as the local address, as follows:
Segments
RAM_FB = Read_write 0xfb1000 to 0xfb1fff;
Ram_fc = Read_write 0xfc1000 to 0xfc1fff;
RAM_FD = Read_write 0xfd1000 to 0xfd1fff;
/* Other segment definition here*/
END
PLACEMENT
Paged_ram into RAM_FB, Ram_fc, RAM_FD;
/* Other Placement definition here*/
END
Finally, take a look at the global address approach:
First, we need to define a variable in. c:
#pragma data_seg __gpage_seg paged_ram/* The description of Paged_ram is in PRM file */
unsigned char banked_var;
#pragma data_seg DEFAULT
Next, we also declare this variable in. h:
#pragma data_seg __gpage_seg paged_ram/* The description of Paged_ram is in PRM file */
extern unsigned char banked_var;
#pragma data_seg DEFAULT
In this way, we can use this variable.
For example: I can assign a value to this variable, Banked-var = 0x5, but if you want to use the pointer to point to this variable, you need to do the following:
unsigned char * __far ptr_var;/* The definition of this pointer does not need to be defined in Paged_ram and needs to be confirmed where the variable is defined. */
Ptr_var = &banked_var;
Note the point:
The segments of the PRM file can be either local address or global address.
Eeprom/flash: (Operation const variable)
1. Local address form
Use #pragma const_seg __epage_seg paged_const/#pragma const_seg __ppage_seg paged_const definition
The pointer is defined with a const unsigned char *__eptr ptr_eeprom;/const unsigned char *__pptr ptr_eeprom;
2. Global Address format
Use #pragma const_seg __gpage_seg paged_const
Pointer with const unsigned char *__far ptr;
At the end of this article, it is important to note:
1. To add-d__far_data to the complier option
2. The address of all defined pointers is default_rom, but the address pointed to is the banked area. 3 bytes (Confirmation required)
3. The global address method does not have a local address to execute the command fast, unless the need for large addressing space, it is best not to use the global address.
4. This article has no global address for the HCS12X series CPU,HCS12.
Refer to the Freescale Technical manual: Datapage.c in tn238/tn240 and Freescale projects