From fbd620a7f4053f68cea82c67a0c7f515f1d02355 Mon Sep 17 00:00:00 2001 From: Bernard Xiong Date: Wed, 25 Feb 2015 10:50:21 +0800 Subject: [Kernel] Move the components initailzation to the kernel --- src/init.c | 199 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 199 insertions(+) create mode 100644 src/init.c (limited to 'src') diff --git a/src/init.c b/src/init.c new file mode 100644 index 0000000000..3b95ea3a57 --- /dev/null +++ b/src/init.c @@ -0,0 +1,199 @@ +/* + * File : init.c + * This file is part of RT-Thread RTOS + * COPYRIGHT (C) 2012 - 2015, RT-Thread Development Team + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License along + * with this program; if not, write to the Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Change Logs: + * Date Author Notes + * 2012-09-20 Bernard Change the name to components.c + * And all components related header files. + * 2012-12-23 Bernard fix the pthread initialization issue. + * 2013-06-23 Bernard Add the init_call for components initialization. + * 2013-07-05 Bernard Remove initialization feature for MS VC++ compiler + * 2015-02-06 Bernard Remove the MS VC++ support and move to the kernel + */ + +#include + +#ifdef RT_USING_COMPONENTS_INIT +/* + * Components Initialization will initialize some driver and components as following + * order: + * rti_start --> 0 + * BOARD_EXPORT --> 1 + * rti_board_end --> 1.end + * + * DEVICE_EXPORT --> 2 + * COMPONENT_EXPORT --> 3 + * FS_EXPORT --> 4 + * ENV_EXPORT --> 5 + * APP_EXPORT --> 6 + * + * rti_end --> 6.end + * + * These automatically initializaiton, the driver or component initial function must + * be defined with: + * INIT_BOARD_EXPORT(fn); + * INIT_DEVICE_EXPORT(fn); + * ... + * INIT_APP_EXPORT(fn); + * etc. + */ +static int rti_start(void) +{ + return 0; +} +INIT_EXPORT(rti_start, "0"); + +static int rti_board_end(void) +{ + return 0; +} +INIT_EXPORT(rti_board_end, "1.end"); + +static int rti_end(void) +{ + return 0; +} +INIT_EXPORT(rti_end, "6.end"); + +/** + * RT-Thread Components Initialization for board + */ +void rt_components_board_init(void) +{ +#if RT_DEBUG_INIT + int result; + const struct rt_init_desc *desc; + for (desc = &__rt_init_desc_rti_start; desc < &__rt_init_desc_rti_board_end; desc ++) + { + rt_kprintf("initialize %s", desc->fn_name); + result = desc->fn(); + rt_kprintf(":%d done\n", result); + } +#else + const init_fn_t *fn_ptr; + + for (fn_ptr = &__rt_init_rti_start; fn_ptr < &__rt_init_rti_board_end; fn_ptr++) + { + (*fn_ptr)(); + } +#endif +} + +/** + * RT-Thread Components Initialization + */ +void rt_components_init(void) +{ +#if RT_DEBUG_INIT + int result; + const struct rt_init_desc *desc; + + rt_kprintf("do components intialization.\n"); + for (desc = &__rt_init_desc_rti_board_end; desc < &__rt_init_desc_rti_end; desc ++) + { + rt_kprintf("initialize %s", desc->fn_name); + result = desc->fn(); + rt_kprintf(":%d done\n", result); + } +#else + const init_fn_t *fn_ptr; + + for (fn_ptr = &__rt_init_rti_board_end; fn_ptr < &__rt_init_rti_end; fn_ptr ++) + { + (*fn_ptr)(); + } +#endif +} + +#ifdef RT_USING_USER_MAIN +void rt_application_init(void); +void rt_hw_board_init(void); + +#ifndef RT_USING_HEAP +/* if there is not enble heap, we should use static thread and stack. */ +ALIGN(8) +static rt_uint8_t main_stack[2048]; +struct rt_thread main_thread; +#endif + +/* the system main thread */ +void main_thread_entry(void *parameter) +{ + extern int main(void); + + /* RT-Thread components initialization */ + rt_components_init(); + + /* invoke system main function */ + main(); +} + +void rt_application_init(void) +{ + rt_thread_t tid; + +#ifdef RT_USING_HEAP + tid = rt_thread_create("main", main_thread_entry, RT_NULL, + 2048, RT_THREAD_PRIORITY_MAX / 3, 20); + RT_ASSERT(tid != RT_NULL); +#else + rt_err_t result; + + tid = &main_thread; + result = rt_thread_init(tid, "main", main_thread_entry, RT_NULL, + 2048, RT_THREAD_PRIORITY_MAX / 3, 20); + RT_ASSERT(result != RT_EOK); +#endif + + rt_thread_startup(tid); +} + +int rtthread_startup(void) +{ + /* board level initalization + * NOTE: please initialize heap inside board initialization. + */ + rt_hw_board_init(); + + /* show RT-Thread version */ + rt_show_version(); + + /* timer system initialization */ + rt_system_timer_init(); + + /* scheduler system initialization */ + rt_system_scheduler_init(); + + /* create init_thread */ + rt_application_init(); + + /* timer thread initialization */ + rt_system_timer_thread_init(); + + /* idle thread initialization */ + rt_thread_idle_init(); + + /* start scheduler */ + rt_system_scheduler_start(); + + /* never reach here */ + return ; +} +#endif +#endif -- cgit v1.3.1 From 62a0172d11e559272128bf52b56ef806ba28ae24 Mon Sep 17 00:00:00 2001 From: "Bernard.Xiong" Date: Sun, 22 Mar 2015 09:06:48 +0800 Subject: [Kernel] Fix the system initialization link issue --- include/components.h | 79 ++++++++++++++++++++++++++++++++++++++++++++++++++++ include/rtthread.h | 13 ++++++--- src/SConscript | 9 ++++-- 3 files changed, 95 insertions(+), 6 deletions(-) create mode 100644 include/components.h (limited to 'src') diff --git a/include/components.h b/include/components.h new file mode 100644 index 0000000000..4113a8691b --- /dev/null +++ b/include/components.h @@ -0,0 +1,79 @@ +/* + * File : components.h + * header for RT-Thread components + * This file is part of RT-Thread RTOS + * COPYRIGHT (C) 2012-2015, RT-Thread Development Team + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License along + * with this program; if not, write to the Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Change Logs: + * Date Author Notes + * 2012-09-20 Bernard Change the name to components.h + * And all components related header files. + * 2015-02-06 Bernard Rename the components.h to rtcom.h + * 2015-03-22 Bernard Keep the compatibility. + */ + +#ifndef COMPONENTS_H__ +#define COMPONENTS_H__ + +#ifdef RT_USING_FINSH +#include +#include +#endif + +#ifdef RT_USING_LWIP +#include +#include +#endif + +#ifdef RT_USING_DFS +#include +#include +#ifdef RT_USING_DFS_ELMFAT +#include +#endif +#if defined(RT_USING_LWIP) && defined(RT_USING_DFS_NFS) +#include +#endif +#ifdef RT_USING_DFS_ROMFS +#include +#endif +#ifdef RT_USING_DFS_DEVFS +#include +#endif +#ifdef RT_USING_DFS_UFFS +#include +#endif +#ifdef RT_USING_DFS_JFFS2 +#include +#endif +#ifdef RT_USING_DFS_YAFFS2 +#include +#endif +#ifdef RT_USING_DFS_ROMFS +#include +#endif +#endif + +#ifdef RT_USING_PTHREADS +#include +#endif + +#ifdef RT_USING_MODULE +#include +#endif + +#endif diff --git a/include/rtthread.h b/include/rtthread.h index edd207bcb7..5309c31d5a 100644 --- a/include/rtthread.h +++ b/include/rtthread.h @@ -437,6 +437,11 @@ void rt_module_unload_sethook(void (*hook)(rt_module_t module)); void rt_module_init_object_container(struct rt_module *module); rt_err_t rt_module_destroy(rt_module_t module); +/* + * application module system initialization + */ +int rt_system_module_init(void); + /*@}*/ #endif @@ -455,10 +460,10 @@ void rt_interrupt_leave(void); */ rt_uint8_t rt_interrupt_get_nest(void); -/** - * application module - */ -int rt_system_module_init(void); +#ifdef RT_USING_COMPONENTS_INIT +void rt_components_init(void); +void rt_components_board_init(void); +#endif /** * @addtogroup KernelService diff --git a/src/SConscript b/src/SConscript index 0eda61b1ef..6d59365195 100644 --- a/src/SConscript +++ b/src/SConscript @@ -5,8 +5,13 @@ from building import * src = Glob('*.c') CPPPATH = [RTT_ROOT + '/include'] -if rtconfig.CROSS_TOOL == 'keil' and GetDepend('RT_USING_MODULE') == True: - LINKFLAGS = ' --keep __rtmsym_* ' +if rtconfig.CROSS_TOOL == 'keil': + # add more link flags for module and components_init. + LINKFLAGS = '' + if GetDepend('RT_USING_MODULE'): + LINKFLAGS = ' --keep __rtmsym_* ' + if GetDepend('RT_USING_COMPONENTS_INIT'): + LINKFLAGS = ' --keep __rt_init* ' else: LINKFLAGS = '' -- cgit v1.3.1 From 655054b1c52c103afb5c815eea408e112da26c7d Mon Sep 17 00:00:00 2001 From: Bernard Xiong Date: Fri, 3 Apr 2015 14:27:56 +0000 Subject: [Kernel] Use main function in the Keil MDK --- src/init.c | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) (limited to 'src') diff --git a/src/init.c b/src/init.c index 3b95ea3a57..56b7e0bf8d 100644 --- a/src/init.c +++ b/src/init.c @@ -122,9 +122,22 @@ void rt_components_init(void) } #ifdef RT_USING_USER_MAIN + void rt_application_init(void); void rt_hw_board_init(void); +#ifdef __CC_ARM +extern int $Super$$main(void); +/* re-define main function */ +int $Sub$$main(void) +{ + rt_hw_interrupt_disable(); + rtthread_startup(); + + return 0; +} +#endif + #ifndef RT_USING_HEAP /* if there is not enble heap, we should use static thread and stack. */ ALIGN(8) @@ -141,7 +154,11 @@ void main_thread_entry(void *parameter) rt_components_init(); /* invoke system main function */ +#ifdef __CC_ARM + $Sub$$main(); +#else main(); +#endif } void rt_application_init(void) -- cgit v1.3.1