Using Pragma
Using Pragma
Pragma is a preprocessor directive that provides directions to the compiler about how to treat a
particular statement. The following example shows how the DATA_SECTION pragma is used
to put a specific buffer into a different section of RAM than other buffers.
The example shows two buffers, bufferA and bufferB. The first buffer, bufferA is treated
normally by the C compiler by placing the buffer (512 words) into the ".bss" section. The second,
bufferB is specifically directed to go into the “my_sect” portion of data memory. Global
variables, normally ".bss", can be redirected as desired.
When using CODE_SECTION, code that is normally linked as ".text", can be identified
otherwise by using the code section pragma (like .sect in assembly).
#
#
pragma
pragma
CODE_SECTION (
CODE_SECTION (
func
func
, ”section name”)
, ”section name”)
#
#
pragma
pragma
DATA_SECTION (symbol, “section name”)
DATA_SECTION (symbol, “section name”)
User defined sections from C :
User defined sections from C :
Pragma
Pragma
Examples
Examples
.global _
.global _
bufferA
bufferA
, _
, _
bufferB
bufferB
.
.
bss
bss
_bufferA,512
_bufferA,512
_
_
bufferB
bufferB
:
:
.
.
usect
usect
“my_sect”,512
“my_sect”,512
Resulting assembly file
Resulting assembly file
char bufferA[512];
char bufferA[512];
#
#
pragma
pragma
DATA_SECTION(
DATA_SECTION(
bufferB
bufferB
, ”my_sect”)
, ”my_sect”)
char bufferB[512];
char bufferB[512];
C source file
C source file
Example
Example
-
-
using the DATA_SECTION
using the DATA_SECTION
Pragma
Pragma
More #
More #
pragma
pragma
are defined in the C compiler UG
are defined in the C compiler UG
D- 8 C28x – C Programming