µOS++ IIIe Reference 7.0.0
The third edition of µOS++, a POSIX inspired open source framework, written in C++
Loading...
Searching...
No Matches
startup.cpp File Reference
#include <cmsis-plus/rtos/os.h>
#include <cmsis-plus/diag/trace.h>
#include <cmsis_device.h>
#include <stdint.h>
#include <stdlib.h>
#include <sys/types.h>

Go to the source code of this file.

Macros

#define OS_BOOL_STARTUP_GUARD_CHECKS   (true)
 

Functions

void _start (void)
 The standard C application entry point.
 
int main (int argc, char *argv[])
 Default implementation of main().
 
static void os_initialize_bss (unsigned int *region_begin, unsigned int *region_end)
 
static void os_initialize_data (unsigned int *from, unsigned int *region_begin, unsigned int *region_end)
 
void os_run_fini_array (void)
 
static void os_run_init_array (void)
 
void os_startup_initialize_args (int *p_argc, char ***p_argv)
 Initialise arguments.
 

Variables

unsigned int __bss_end__
 
unsigned int __bss_start__
 
void(* __fini_array_end [])(void)
 
void(* __fini_array_start [])(void)
 
void(* __init_array_end [])(void)
 
void(* __init_array_start [])(void)
 
void(* __preinit_array_end [])(void)
 
void(* __preinit_array_start [])(void)
 
unsigned long int __stack
 
unsigned int _edata
 
unsigned int _Heap_Begin
 
unsigned long int _Heap_Limit
 
unsigned int _sdata
 
unsigned int _sidata
 

Macro Definition Documentation

◆ OS_BOOL_STARTUP_GUARD_CHECKS

#define OS_BOOL_STARTUP_GUARD_CHECKS   (true)

Definition at line 63 of file startup.cpp.

Function Documentation

◆ main()

int main ( int  argc,
char *  argv[] 
)

Definition at line 113 of file os-main.cpp.

114{
115 using namespace os::rtos;
116
117 trace::printf ("\nµOS++ IIIe version " OS_STRING_RTOS_IMPL_VERSION "\n");
118 trace::printf ("Copyright (c) 2007-" OS_STRING_RTOS_IMPL_YEAR
119 " Liviu Ionescu\n");
120
121 port::scheduler::greeting ();
122
123 trace::printf ("Scheduler frequency: %u ticks/sec\n",
125 trace::printf ("Default stack size: %u bytes\n",
126 thread::stack::default_size ());
127#if defined(OS_HAS_INTERRUPTS_STACK)
128 trace::printf ("Interrupts stack size: %u bytes\n",
129 interrupts::stack ()->size ());
130#endif /* defined(OS_HAS_INTERRUPTS_STACK) */
131
132#if defined(__clang__)
133 trace::printf ("Built with clang " __VERSION__);
134#else
135 trace::printf ("Built with GCC " __VERSION__);
136#endif
137
138#if defined(__EXCEPTIONS)
139 trace::printf (", with exceptions");
140#else
141 trace::printf (", no exceptions");
142#endif
143 trace::puts ("\n");
144
145 scheduler::initialize ();
146
147 // Store the parameters in the static structure, to be used by os_main().
148 main_args.argc = argc;
149 main_args.argv = argv;
150
151#if defined(OS_EXCLUDE_DYNAMIC_MEMORY_ALLOCATIONS)
152
153 // Running the constructor manually has the additional advantage of
154 // not registering any destructor, and for main this is important,
155 // since the destructors are executed on its context, and it cannot
156 // destruct itself.
157 new (&os_main_thread_)
158 main_thread{ "main", reinterpret_cast<thread::func_t> (_main_trampoline),
159 nullptr };
160
161 os_main_thread = reinterpret_cast<rtos::thread*> (&os_main_thread_);
162
163#else
164
165 thread::attributes attr = thread::initializer;
167#pragma GCC diagnostic push
168#if defined(__clang__)
169#pragma clang diagnostic ignored "-Wcast-function-type-strict"
170#endif
171 os_main_thread = new thread (
172 "main", reinterpret_cast<thread::func_t> (_main_trampoline), nullptr,
173 attr);
174#pragma GCC diagnostic pop
175
176#endif /* defined(OS_EXCLUDE_DYNAMIC_MEMORY_ALLOCATIONS) */
177
178#if !defined(OS_USE_RTOS_PORT_SCHEDULER)
180#endif /* !defined(OS_USE_RTOS_PORT_SCHEDULER) */
181
182 // Execution will proceed to first registered thread, possibly
183 // "idle", which will immediately lower its priority,
184 // and at a certain moment will reach os_main().
185 scheduler::start ();
186
187 /* NOTREACHED */
188}
static constexpr uint32_t frequency_hz
SysTick frequency in Hz.
Definition os-clocks.h:471
Thread attributes.
Definition os-thread.h:800
std::size_t th_stack_size_bytes
Size of the user defined storage for the thread stack, in bytes.
Definition os-thread.h:861
POSIX compliant thread, using the default RTOS allocator.
Definition os-thread.h:251
void *(*)(func_args_t args) func_t
Type of thread function.
Definition os-thread.h:423
Standard thread.
#define OS_INTEGER_RTOS_MAIN_STACK_SIZE_BYTES
Define the main thread stack size, in bytes.
void os_startup_create_thread_idle(void)
Create the idle thread.
int puts(const char *s)
Write the string and a line terminator to the trace device.
Definition trace.cpp:102
int printf(const char *format,...)
Write a formatted string to the trace device.
Definition trace.cpp:59
RTOS namespace.
Definition os-flags.h:37
rtos::thread * os_main_thread
Definition os-main.cpp:92
#define OS_STRING_RTOS_IMPL_YEAR
Definition os-versions.h:42
#define OS_STRING_RTOS_IMPL_VERSION
Definition os-versions.h:44

References os::rtos::clock_systick::frequency_hz, OS_INTEGER_RTOS_MAIN_STACK_SIZE_BYTES, os_main_thread, os_startup_create_thread_idle(), OS_STRING_RTOS_IMPL_VERSION, OS_STRING_RTOS_IMPL_YEAR, os::trace::printf(), os::trace::puts(), and os::rtos::thread::attributes::th_stack_size_bytes.

Referenced by _start().

◆ os_initialize_bss()

void os_initialize_bss ( unsigned int *  region_begin,
unsigned int *  region_end 
)
inlinestatic

Definition at line 142 of file startup.cpp.

143{
144 // Iterate and clear word by word.
145 // It is assumed that the pointers are word aligned.
146 unsigned int* p = region_begin;
147 while (p < region_end)
148 {
149 *p++ = 0;
150 }
151}

Referenced by _start().

◆ os_initialize_data()

void os_initialize_data ( unsigned int *  from,
unsigned int *  region_begin,
unsigned int *  region_end 
)
inlinestatic

Definition at line 129 of file startup.cpp.

131{
132 // Iterate and copy word by word.
133 // It is assumed that the pointers are word aligned.
134 unsigned int* p = region_begin;
135 while (p < region_end)
136 {
137 *p++ = *from++;
138 }
139}

Referenced by _start().

◆ os_run_fini_array()

void os_run_fini_array ( void  )

Definition at line 187 of file startup.cpp.

188{
189 trace_printf ("%s()\n", __func__);
190
192 for (int i = count; i > 0; i--)
193 {
194 __fini_array_start[i - 1]();
195 }
196
197 // If the application needs to run the code in the .fini section,
198 // please use the startup files, since this requires the code in
199 // crti.o and crtn.o to add the function prologue/epilogue.
200 //_fini(); // DO NOT ENABLE THIS!
201}
void(* __fini_array_start[])(void)
void(* __fini_array_end[])(void)
int trace_printf(const char *format,...)

References __fini_array_end, __fini_array_start, and trace_printf().

Referenced by exit().

◆ os_run_init_array()

void os_run_init_array ( void  )
inlinestatic

Definition at line 163 of file startup.cpp.

164{
165 trace_printf ("%s()\n", __func__);
166
168 for (int i = 0; i < count; i++)
169 {
171 }
172
173 // If the application needs to run the code in the .init section,
174 // please use the startup files, since this requires the code in
175 // crti.o and crtn.o to add the function prologue/epilogue.
176 //_init(); // DO NOT ENABE THIS!
177
179 for (int i = 0; i < count; i++)
180 {
182 }
183}
void(* __init_array_start[])(void)
void(* __init_array_end[])(void)
void(* __preinit_array_start[])(void)
void(* __preinit_array_end[])(void)

References __init_array_end, __init_array_start, __preinit_array_end, __preinit_array_start, and trace_printf().

Referenced by _start().

Variable Documentation

◆ __bss_end__

unsigned int __bss_end__
extern

Referenced by _start().

◆ __bss_start__

unsigned int __bss_start__
extern

Referenced by _start().

◆ __fini_array_end

void(* __fini_array_end[])(void) ( void  )
extern

Referenced by os_run_fini_array().

◆ __fini_array_start

void(* __fini_array_start[])(void) ( void  )
extern

Referenced by os_run_fini_array().

◆ __init_array_end

void(* __init_array_end[])(void) ( void  )
extern

Referenced by os_run_init_array().

◆ __init_array_start

void(* __init_array_start[])(void) ( void  )
extern

Referenced by os_run_init_array().

◆ __preinit_array_end

void(* __preinit_array_end[])(void) ( void  )
extern

Referenced by os_run_init_array().

◆ __preinit_array_start

void(* __preinit_array_start[])(void) ( void  )
extern

Referenced by os_run_init_array().

◆ __stack

unsigned long int __stack
extern

Referenced by _start().

◆ _edata

unsigned int _edata
extern

Referenced by _start().

◆ _Heap_Begin

unsigned int _Heap_Begin
extern

Referenced by _sbrk(), and _start().

◆ _Heap_Limit

unsigned long int _Heap_Limit
extern

Referenced by _start().

◆ _sdata

unsigned int _sdata
extern

Referenced by _start().

◆ _sidata

unsigned int _sidata
extern

Referenced by _start().