diff --git a/common/elab_export.c b/common/elab_export.c index 65299f30e8c188479be6faabf125e1a417ed375c..a6fae1c39828b007b4bbc6887bc92bb2f59b299a 100644 --- a/common/elab_export.c +++ b/common/elab_export.c @@ -135,10 +135,10 @@ static void signal_handler(int sig) #endif /** - * @brief eLab startup function. + * @brief module init function. * @retval None */ -void elab_run(void) +void module_init(void) { #if defined(__linux__) || defined(_WIN32) signal(SIGINT, signal_handler); /* Ctrl + C*/ @@ -154,7 +154,6 @@ void elab_run(void) /* Start polling function in metal eLab, or start the RTOS kernel in RTOS eLab. */ _get_init_export_table(); - _get_poll_export_table(); #if (ELAB_RTOS_CMSIS_OS_EN != 0 || ELAB_RTOS_BASIC_OS_EN != 0) osKernelInitialize(); #endif @@ -170,16 +169,10 @@ void elab_run(void) eos_run(); #else /* Initialize all module in eLab. */ - for (uint8_t level = 0; level < export_level_max; level ++) + for (uint8_t level = 0; level <= export_level_max; level ++) { _init_func_execute(level); } - - /* Start polling function in metal eLab. */ - while (1) - { - _poll_func_execute(); - } #endif } diff --git a/common/elab_export.h b/common/elab_export.h index 00485be348613f9109a9bd260b50f780dc0e39be..512694e61cbf3869ceb513dcbc5ea888594574cf 100644 --- a/common/elab_export.h +++ b/common/elab_export.h @@ -25,9 +25,9 @@ enum elab_export_level EXPORT_POLL = -2, EXPORT_UNIT_TEST = -1, EXPORT_LEVEL_BSP = 0, - EXPORT_LEVEL_HW_INDEPNEDENT = 0, - EXPORT_DRVIVER = 1, - EXPORT_MIDWARE = 2, + EXPORT_LEVEL_HW_INDEPENDENT = 0, + EXPORT_DRIVER = 1, + EXPORT_MIDDLEWARE = 2, EXPORT_DEVICE = 3, EXPORT_APP = 4, EXPORT_USER = 5, @@ -59,7 +59,7 @@ typedef struct elab_export /* private function --------------------------------------------------------- */ void elab_unit_test(void); -void elab_run(void); +void module_init(void); /* public export ------------------------------------------------------------ */ /** diff --git a/examples/stm32g070/user/app/eos_led_reactor.c b/examples/stm32g070/user/app/eos_led_reactor.c index 98f8b971818a4708e064951d20ae589c9fb141f0..042a8d77abe9612add3758cbe02bae66cee2358d 100644 --- a/examples/stm32g070/user/app/eos_led_reactor.c +++ b/examples/stm32g070/user/app/eos_led_reactor.c @@ -4,6 +4,7 @@ #include "event_def.h" #include "stm32g0xx_hal.h" #include +#include "elab_export.h" /* data structure ----------------------------------------------------------- */ typedef struct eos_reactor_led_tag { @@ -32,12 +33,14 @@ void eos_reactor_led_init(void) eos_event_pub_period(Event_Time_1000ms, 1000); #endif } +INIT_EXPORT(eos_reactor_led_init, EXPORT_APP); /* static state function ---------------------------------------------------- */ static void led_e_handler(eos_reactor_led_t * const me, eos_event_t const * const e) { if (e->topic == Event_Time_1000ms) { HAL_GPIO_TogglePin(GPIOC, GPIO_PIN_9); + printf("led status: %d\r\n", me->status); me->status = (me->status == 0) ? 1 : 0; } } diff --git a/examples/stm32g070/user/app/eos_led_sm.c b/examples/stm32g070/user/app/eos_led_sm.c index 87f6362103162faf422b752d14a50df33188aef5..683e7346df3cfaa182c17a770064e990ebec897b 100644 --- a/examples/stm32g070/user/app/eos_led_sm.c +++ b/examples/stm32g070/user/app/eos_led_sm.c @@ -4,7 +4,7 @@ #include "event_def.h" #include "stm32g070xx.h" #include "stm32g0xx_hal.h" -#include +#include "elab_export.h" #if (EOS_USE_SM_MODE != 0) /* data structure ----------------------------------------------------------- */ @@ -29,6 +29,7 @@ void eos_sm_led_init(void) sm_led.status = 0; } +INIT_EXPORT(eos_sm_led_init, EXPORT_APP); /* static state function ---------------------------------------------------- */ static eos_ret_t state_init(eos_sm_led_t * const me, eos_event_t const * const e) diff --git a/examples/stm32g070/user/app/main.c b/examples/stm32g070/user/app/main.c index bb699c7a7a5f9784988b9e5801b1ab2346b13688..41f7457111188f8694c9dbcd24877b04abb330f4 100644 --- a/examples/stm32g070/user/app/main.c +++ b/examples/stm32g070/user/app/main.c @@ -1,28 +1,27 @@ /* include ------------------------------------------------------------------ */ #include "eventos.h" // EventOS Nano头文件 #include "event_def.h" // 事件主题的枚举 -#include "eos_led.h" // LED灯闪烁状态机 -#include "bsp.h" +#include "elab_export.h" /* define ------------------------------------------------------------------- */ #if (EOS_USE_PUB_SUB != 0) static eos_u32_t eos_sub_table[Event_Max]; // 订阅表数据空间 #endif -/* main function ------------------------------------------------------------ */ -int main(void) +void eos_module_init(void) { - bsp_init(); - eos_init(); // EventOS初始化 + #if (EOS_USE_PUB_SUB != 0) eos_sub_init(eos_sub_table, Event_Max); // 订阅表初始化 #endif +} +INIT_EXPORT(eos_module_init, EXPORT_MIDDLEWARE); -#if (EOS_USE_SM_MODE != 0) - eos_sm_led_init(); // LED状态机初始化 -#endif - eos_reactor_led_init(); +/* main function ------------------------------------------------------------ */ +int main(void) +{ + module_init(); // 各模块初始化 eos_run(); // EventOS启动 diff --git a/examples/stm32g070/user/bsp/bsp.c b/examples/stm32g070/user/bsp/bsp.c index 1f3083e667215271941e422b4bbffe0330f20c34..e21d8fdbc06c2bfb532cab35b7057fee472f54f9 100644 --- a/examples/stm32g070/user/bsp/bsp.c +++ b/examples/stm32g070/user/bsp/bsp.c @@ -7,6 +7,7 @@ /* includes ----------------------------------------------------------------- */ #include "bsp.h" #include "stm32g0xx_hal.h" +#include "elab_export.h" #ifdef __cplusplus extern "C" { @@ -45,6 +46,8 @@ void bsp_init(void) GPIO_PIN_RESET); } +INIT_EXPORT(bsp_init, EXPORT_LEVEL_BSP); + /* private functions -------------------------------------------------------- */ /** * @brief System Clock Configuration diff --git a/examples/stm32g070/user/bsp/elab_uart_debug.c b/examples/stm32g070/user/bsp/elab_uart_debug.c index d45c6c94577b9eb46d784d9525ba6fecf1b2c3cc..2a182a01e4c09207ce32759ddb98d7da41b26599 100644 --- a/examples/stm32g070/user/bsp/elab_uart_debug.c +++ b/examples/stm32g070/user/bsp/elab_uart_debug.c @@ -4,8 +4,10 @@ */ /* includes ----------------------------------------------------------------- */ +#include #include "elab_common.h" #include "elib_queue.h" +#include "elab_export.h" #include "stm32g0xx_hal.h" /* private config ----------------------------------------------------------- */ @@ -75,6 +77,12 @@ void elab_debug_uart_init(uint32_t baudrate) elib_queue_init(&queue_tx, buffer_tx, ELAB_DEBUG_UART_BUFFER_TX); } +void debug_uart_init(void) +{ + elab_debug_uart_init(115200); +} +INIT_EXPORT(debug_uart_init, EXPORT_DRIVER); + /** * @brief Send data to the debug uart. * @param buffer this pointer