In embedded system development, you can choose whether to use a C library as needed. If the application is large, you may need to use some of the functions in the C library, if you need to use dynamic allocation memory malloc, free, stdio.h Printf, Sprintf, strCMP, STRCPY, etc. in String.h. This is a good choice to move into the right C library. This article mainly tells some questions that need to be addressed in the SDT2.5 version of the ARM compilation development tool.
In the development environment of the SDT2.5, SemiHosted Ansi C Library or Embedded C Library, Embedded C is just a subset of ANSI C. ANSI C generally applies to early development efforts, can be used in conjunction with Angle, Armulator and other software debugging tools, so that the software development, before the user's own code is executed, all system initialization work must be completed. The latter is smaller because the code is smaller, and the underlying hardware resource is not used, it is suitable to be published with the final version when integrated with the application. Moreover, with some hardware debugging tools, it should be very convenient for program debugging.
With the Embedded C Library application execution process:
1. After the system starts, some of the underlying initialization,
Before jumping to the C procedure, some of the primary initialization work must be used to complete some of the underlying initialization. Only if the processing of the abnormal interrupt jump address is included, whether it uses REMAP, and the processing of the abnormal interrupt according to the needs of the embedded system, and the like.
2. Initializing embedded stack manager
In C procedures, dynamically allocate memory is usually required to invoke the heap manager in the embedded C library, initialize the pile according to the position and size of the heap, so that you can dynamically allocate memory with the malloc () function in the C program. The specific dynamic memory allocation algorithm will continue to explain.
The function of initialization call is:
Struct Heap_descriptor * __ rt_embeddedalloc_init (Void * Base, SIZE_T SIZE);
This function returns a pointer for a plurality of descriptors.
Since the embedded C library is designed to be fully reusable, the user must provide a callback function struct heap_descriptor * __ rt_heapdescriptor in its own code, the function returns the value of __rt_embeddedalloc_init (), so that The heap descriptor can be locked according to the return value.
3. Call the top object builder
If you use a C library in an embedded C library, you need to call the top-level object builder void __cpp_initialise (void)
4. Execute the main program
5. Call the top object destructor
Before the program is terminated, the top object destructor void _cpp_finalise (void) must be called.
Code instance:
#Include
EXTERN STRUCT Heap_Descriptor * __ rt_embeddedalloc_init (Void * Base, SIZE_T SIZE);
Void ApplicationCode (Void);
Struct Heap_descriptor * HP;
EXTERN STRUCT HEAP_DESCRIPTOR * __ rt_heapdescriptor (void) {
Return HP;
}
EXTERN VOID C_ENTRY (VOID) {
HP = __RT_EMBEDDEDALLOC_INIT ((void *) 0x2030000, 0x20000);
ApplicationCode ();
Use Embedded C Library Others Need Note:
1) In the SDT compilation environment, the library search path selection / ARM / lib / embedded /, which corresponds to 16 big, little, 32-bit Big, Little, Little, 32-bit BIG, Little.
2) The code must be re-implemented __main (), _ main (), otherwise compiling under the SDT.
3
)
c
The library function, it may be implemented as needed
__RT_TRAP, __RT_ERRNO_ADDR, __RT_FT_STATUS_ADDR
, Specific to the same
__RT_HEAPDESCRIPTOR (),
In
SDT
Don't compile errors, in
Symbol Table
In the middle
Undefinded
,
WEAK REFERENCE
information.