C Microkernel Realtime eXecutive
Realtime Operating System for Cortex-M based microcontrollers
 
Loading...
Searching...
No Matches
application.h
1#pragma once
2
16extern void cmrx_posix_register_application(const struct OS_process_definition_t * process);
17
27extern void cmrx_posix_register_thread(const struct OS_thread_create_t * thread);
28
49#ifndef APPLICATION_NAME
50# error "Application header included from something that is not an application!"
51#endif
52
53#define CMRX_VTABLE_SECTION_STR3(section_symbol) # section_symbol
54#define CMRX_VTABLE_SECTION_STR2(application_name) CMRX_VTABLE_SECTION_STR3(vtable_ ## application_name)
55#define CMRX_VTABLE_SECTION_STR(application_name) CMRX_VTABLE_SECTION_STR2(application_name)
56
57#define CMRX_VTABLE_SECTION_START2(application_name) __start_vtable_ ## application_name
58#define CMRX_VTABLE_SECTION_START(application_name) CMRX_VTABLE_SECTION_START2(application_name)
59
60#define CMRX_VTABLE_SECTION_STOP2(application_name) __stop_vtable_ ## application_name
61#define CMRX_VTABLE_SECTION_STOP(application_name) CMRX_VTABLE_SECTION_STOP2(application_name)
62
63#define CMRX_VTABLE_SECTION CMRX_VTABLE_SECTION_STR(APPLICATION_NAME)
64#ifdef __APPLE__
65# define CMRX_VTABLE_SPECIFIER const
66#else
67# define CMRX_VTABLE_SPECIFIER __attribute__((section(CMRX_VTABLE_SECTION))) const
68#endif
69
70#ifdef __APPLE__
71/* TODO: Just to make the code build. Apple doesn't support section start/stop symbols
72 emission. */
73long CMRX_VTABLE_SECTION_START(APPLICATION_NAME) __attribute__((weak));
74long CMRX_VTABLE_SECTION_STOP(APPLICATION_NAME) __attribute__((weak));
75#else
76extern long CMRX_VTABLE_SECTION_START(APPLICATION_NAME) __attribute__((weak));
77extern long CMRX_VTABLE_SECTION_STOP(APPLICATION_NAME) __attribute__((weak));
78#endif
79
85#define CMRX_APPLICATION_INSTANCE_CONSTRUCTOR(application) \
86void * __APPL_SYMBOL(application, data_start) = (void *) 1;\
87void * __APPL_SYMBOL(application, data_end) = (void *) 1;\
88void * __APPL_SYMBOL(application, bss_start) = (void *) 1;\
89void * __APPL_SYMBOL(application, bss_end) = (void *) 1;\
90void * __APPL_SYMBOL(application, shared_start) = (void *) 1;\
91void * __APPL_SYMBOL(application, shared_end) = (void *) 1;\
92void * __APPL_SYMBOL(application, vtable_start) = (void *) 1;\
93void * __APPL_SYMBOL(application, vtable_end) = (void *) 1;\
94\
95const struct OS_process_definition_t __APPL_SYMBOL(application, instance) = {\
96 {\
97 { &__APPL_SYMBOL(application, data_start), &__APPL_SYMBOL(application, data_end) },\
98 { &__APPL_SYMBOL(application, bss_start), &__APPL_SYMBOL(application, bss_end) },\
99 { __APPL_SYMBOL(application, mmio_start), __APPL_SYMBOL(application, mmio_end) },\
100 { __APPL_SYMBOL(application, mmio_2_start), __APPL_SYMBOL(application, mmio_2_end) },\
101 { &__APPL_SYMBOL(application, shared_start), &__APPL_SYMBOL(application, shared_end) }\
102 },\
103 { &CMRX_VTABLE_SECTION_START(application), &CMRX_VTABLE_SECTION_STOP(application) }\
104};\
105__attribute__((constructor)) void __APPL_SYMBOL(application, inst_construct)(void)\
106{\
107 cmrx_posix_register_application(&__APPL_SYMBOL(application, instance));\
108}
109
119#define CMRX_THREAD_AUTOCREATE_CONSTRUCTOR(application, entrypoint, data, priority, core) \
120const struct OS_thread_create_t __APPL_SYMBOL(application, thread_create_ ## entrypoint) = {\
121 &__APPL_SYMBOL(application, instance),\
122 entrypoint,\
123 data,\
124 priority,\
125 core\
126}; \
127__attribute__((constructor)) void __APPL_SYMBOL(application, thread_create_ ## entrypoint ## _construct)(void)\
128{\
129 cmrx_posix_register_thread(&__APPL_SYMBOL(application, thread_create_ ## entrypoint));\
130}
131
void cmrx_posix_register_thread(const struct OS_thread_create_t *thread)
Internal routine to register thread with kernel.
Definition static.c:34
void cmrx_posix_register_application(const struct OS_process_definition_t *process)
Internal routine to register application with kernel.
Definition static.c:23
#define CMRX_VTABLE_SECTION_START(application_name)
Definition application.h:58
#define CMRX_VTABLE_SECTION_STOP(application_name)
Definition application.h:61
Static definition of process in firmware image.
Definition runtime.h:31
Structure describing auto-spawned thread.
Definition runtime.h:46