Cosmic UK Cosmic US Cosmic Germany Cosmic Italia Cosmic France


Cosmic Software Frequently Asked Questions


How do I store a specific value at a specific memory location in ROM/Flash? Why Can't I use the absolute addressing feature?


This is a very common issue for interrupt vectors and their corresponding interrupt service routines because the start address of interrupt service routines must be stored at specific MCU defined locations. Since the compiler produces relocatable code, the location of such a data object is actually done by the linker. Cosmic compilers include a sample vector table (vector.c) and link file (.lkf) that demonstrates how to do this. Vector.c is just an array of function pointers that is located at a specific address by a link command file. See the section entitled "Writing Interrupt Handlers" in the Programming Environments Chapter of the Compiler User's Manual for more information. Alternatively, you can create a new named section using the "#pragma section" compiler extension. In order to store something in ROM/FLASH, it must be either code or a const variable otherwise it is stored in RAM. In this case, you would use the #pragma section definition to create a new const section and then initialize a const data object (variable) to the desired value and then create and locate a segment in your link command file using the new section name. Example:
// In a C module
#pragma section const {test} 
const unsigned char variable = 0x56;
const unsigned char variable2 = 0x76;
#pragma section const {} 
The above pragma sets a constant unsigned char equal to 0x56. To link this to address 0x1000, the link command file must contain the following line. See the section "Redefining Sections" in the Programming Environments Chapter of the compiler User's Manual for more information.
# In the application's link command file
+ seg .test –b0x1000
The example above will store the number 0x56 at address 0x1000 and 0x76 to address 0x1001. Since this is const data, they will be located in the ROMable image.