Merge pull request #4559 from enkiller/0220-1044
[bsp][simulator] 支持自动初始化及用户 main 入口
This commit is contained in:
commit
a98d81ab9f
|
@ -72,8 +72,10 @@ CONFIG_RT_VER_NUM=0x40003
|
||||||
#
|
#
|
||||||
# RT-Thread Components
|
# RT-Thread Components
|
||||||
#
|
#
|
||||||
# CONFIG_RT_USING_COMPONENTS_INIT is not set
|
CONFIG_RT_USING_COMPONENTS_INIT=y
|
||||||
# CONFIG_RT_USING_USER_MAIN is not set
|
CONFIG_RT_USING_USER_MAIN=y
|
||||||
|
CONFIG_RT_MAIN_THREAD_STACK_SIZE=2048
|
||||||
|
CONFIG_RT_MAIN_THREAD_PRIORITY=10
|
||||||
|
|
||||||
#
|
#
|
||||||
# C++ features
|
# C++ features
|
||||||
|
@ -133,8 +135,6 @@ CONFIG_RT_DFS_ELM_REENTRANT=y
|
||||||
CONFIG_RT_USING_DFS_DEVFS=y
|
CONFIG_RT_USING_DFS_DEVFS=y
|
||||||
# CONFIG_RT_USING_DFS_ROMFS is not set
|
# CONFIG_RT_USING_DFS_ROMFS is not set
|
||||||
# CONFIG_RT_USING_DFS_RAMFS is not set
|
# CONFIG_RT_USING_DFS_RAMFS is not set
|
||||||
# CONFIG_RT_USING_DFS_UFFS is not set
|
|
||||||
# CONFIG_RT_USING_DFS_JFFS2 is not set
|
|
||||||
|
|
||||||
#
|
#
|
||||||
# Device Drivers
|
# Device Drivers
|
||||||
|
@ -285,8 +285,6 @@ CONFIG_RT_LIBC_USING_TIME=y
|
||||||
# CONFIG_PKG_USING_LIBRWS is not set
|
# CONFIG_PKG_USING_LIBRWS is not set
|
||||||
# CONFIG_PKG_USING_TCPSERVER is not set
|
# CONFIG_PKG_USING_TCPSERVER is not set
|
||||||
# CONFIG_PKG_USING_PROTOBUF_C is not set
|
# CONFIG_PKG_USING_PROTOBUF_C is not set
|
||||||
# CONFIG_PKG_USING_ONNX_PARSER is not set
|
|
||||||
# CONFIG_PKG_USING_ONNX_BACKEND is not set
|
|
||||||
# CONFIG_PKG_USING_DLT645 is not set
|
# CONFIG_PKG_USING_DLT645 is not set
|
||||||
# CONFIG_PKG_USING_QXWZ is not set
|
# CONFIG_PKG_USING_QXWZ is not set
|
||||||
# CONFIG_PKG_USING_SMTP_CLIENT is not set
|
# CONFIG_PKG_USING_SMTP_CLIENT is not set
|
||||||
|
@ -301,6 +299,10 @@ CONFIG_RT_LIBC_USING_TIME=y
|
||||||
# CONFIG_PKG_USING_BTSTACK is not set
|
# CONFIG_PKG_USING_BTSTACK is not set
|
||||||
# CONFIG_PKG_USING_LORAWAN_ED_STACK is not set
|
# CONFIG_PKG_USING_LORAWAN_ED_STACK is not set
|
||||||
# CONFIG_PKG_USING_WAYZ_IOTKIT is not set
|
# CONFIG_PKG_USING_WAYZ_IOTKIT is not set
|
||||||
|
# CONFIG_PKG_USING_MAVLINK is not set
|
||||||
|
# CONFIG_PKG_USING_RAPIDJSON is not set
|
||||||
|
# CONFIG_PKG_USING_BSAL is not set
|
||||||
|
# CONFIG_PKG_USING_AGILE_MODBUS is not set
|
||||||
|
|
||||||
#
|
#
|
||||||
# security packages
|
# security packages
|
||||||
|
@ -382,6 +384,8 @@ CONFIG_RT_LIBC_USING_TIME=y
|
||||||
# CONFIG_PKG_USING_CMSIS is not set
|
# CONFIG_PKG_USING_CMSIS is not set
|
||||||
# CONFIG_PKG_USING_DFS_YAFFS is not set
|
# CONFIG_PKG_USING_DFS_YAFFS is not set
|
||||||
# CONFIG_PKG_USING_LITTLEFS is not set
|
# CONFIG_PKG_USING_LITTLEFS is not set
|
||||||
|
# CONFIG_PKG_USING_DFS_JFFS2 is not set
|
||||||
|
# CONFIG_PKG_USING_DFS_UFFS is not set
|
||||||
# CONFIG_PKG_USING_THREAD_POOL is not set
|
# CONFIG_PKG_USING_THREAD_POOL is not set
|
||||||
# CONFIG_PKG_USING_ROBOTS is not set
|
# CONFIG_PKG_USING_ROBOTS is not set
|
||||||
# CONFIG_PKG_USING_EV is not set
|
# CONFIG_PKG_USING_EV is not set
|
||||||
|
@ -409,6 +413,7 @@ CONFIG_RT_LIBC_USING_TIME=y
|
||||||
# CONFIG_PKG_USING_QFPLIB_M0_TINY is not set
|
# CONFIG_PKG_USING_QFPLIB_M0_TINY is not set
|
||||||
# CONFIG_PKG_USING_QFPLIB_M3 is not set
|
# CONFIG_PKG_USING_QFPLIB_M3 is not set
|
||||||
# CONFIG_PKG_USING_LPM is not set
|
# CONFIG_PKG_USING_LPM is not set
|
||||||
|
# CONFIG_PKG_USING_TLSF is not set
|
||||||
|
|
||||||
#
|
#
|
||||||
# peripheral libraries and drivers
|
# peripheral libraries and drivers
|
||||||
|
@ -471,6 +476,23 @@ CONFIG_RT_LIBC_USING_TIME=y
|
||||||
# CONFIG_PKG_USING_VIRTUAL_SENSOR is not set
|
# CONFIG_PKG_USING_VIRTUAL_SENSOR is not set
|
||||||
# CONFIG_PKG_USING_VDEVICE is not set
|
# CONFIG_PKG_USING_VDEVICE is not set
|
||||||
# CONFIG_PKG_USING_SGM706 is not set
|
# CONFIG_PKG_USING_SGM706 is not set
|
||||||
|
# CONFIG_PKG_USING_STM32WB55_SDK is not set
|
||||||
|
# CONFIG_PKG_USING_RDA58XX is not set
|
||||||
|
# CONFIG_PKG_USING_LIBNFC is not set
|
||||||
|
# CONFIG_PKG_USING_MFOC is not set
|
||||||
|
# CONFIG_PKG_USING_TMC51XX is not set
|
||||||
|
|
||||||
|
#
|
||||||
|
# AI packages
|
||||||
|
#
|
||||||
|
# CONFIG_PKG_USING_LIBANN is not set
|
||||||
|
# CONFIG_PKG_USING_NNOM is not set
|
||||||
|
# CONFIG_PKG_USING_ONNX_BACKEND is not set
|
||||||
|
# CONFIG_PKG_USING_ONNX_PARSER is not set
|
||||||
|
# CONFIG_PKG_USING_TENSORFLOWLITEMICRO is not set
|
||||||
|
# CONFIG_PKG_USING_ELAPACK is not set
|
||||||
|
# CONFIG_PKG_USING_ULAPACK is not set
|
||||||
|
# CONFIG_PKG_USING_QUEST is not set
|
||||||
|
|
||||||
#
|
#
|
||||||
# miscellaneous packages
|
# miscellaneous packages
|
||||||
|
@ -502,25 +524,23 @@ CONFIG_RT_LIBC_USING_TIME=y
|
||||||
# CONFIG_PKG_USING_HELLO is not set
|
# CONFIG_PKG_USING_HELLO is not set
|
||||||
# CONFIG_PKG_USING_VI is not set
|
# CONFIG_PKG_USING_VI is not set
|
||||||
# CONFIG_PKG_USING_KI is not set
|
# CONFIG_PKG_USING_KI is not set
|
||||||
# CONFIG_PKG_USING_NNOM is not set
|
|
||||||
# CONFIG_PKG_USING_LIBANN is not set
|
|
||||||
# CONFIG_PKG_USING_ELAPACK is not set
|
|
||||||
# CONFIG_PKG_USING_ARMv7M_DWT is not set
|
# CONFIG_PKG_USING_ARMv7M_DWT is not set
|
||||||
# CONFIG_PKG_USING_VT100 is not set
|
# CONFIG_PKG_USING_VT100 is not set
|
||||||
# CONFIG_PKG_USING_ULAPACK is not set
|
|
||||||
# CONFIG_PKG_USING_UKAL is not set
|
# CONFIG_PKG_USING_UKAL is not set
|
||||||
# CONFIG_PKG_USING_CRCLIB is not set
|
# CONFIG_PKG_USING_CRCLIB is not set
|
||||||
|
|
||||||
#
|
#
|
||||||
# games: games run on RT-Thread console
|
# entertainment: terminal games and other interesting software packages
|
||||||
#
|
#
|
||||||
# CONFIG_PKG_USING_THREES is not set
|
# CONFIG_PKG_USING_THREES is not set
|
||||||
# CONFIG_PKG_USING_2048 is not set
|
# CONFIG_PKG_USING_2048 is not set
|
||||||
# CONFIG_PKG_USING_SNAKE is not set
|
# CONFIG_PKG_USING_SNAKE is not set
|
||||||
# CONFIG_PKG_USING_TETRIS is not set
|
# CONFIG_PKG_USING_TETRIS is not set
|
||||||
|
# CONFIG_PKG_USING_DONUT is not set
|
||||||
|
# CONFIG_PKG_USING_ACLOCK is not set
|
||||||
# CONFIG_PKG_USING_LWGPS is not set
|
# CONFIG_PKG_USING_LWGPS is not set
|
||||||
# CONFIG_PKG_USING_TENSORFLOWLITEMICRO is not set
|
|
||||||
# CONFIG_PKG_USING_STATE_MACHINE is not set
|
# CONFIG_PKG_USING_STATE_MACHINE is not set
|
||||||
# CONFIG_PKG_USING_MCURSES is not set
|
# CONFIG_PKG_USING_MCURSES is not set
|
||||||
# CONFIG_PKG_USING_COWSAY is not set
|
# CONFIG_PKG_USING_COWSAY is not set
|
||||||
|
CONFIG_SOC_SIMULATOR=y
|
||||||
CONFIG_RT_USING_DFS_WINSHAREDIR=y
|
CONFIG_RT_USING_DFS_WINSHAREDIR=y
|
||||||
|
|
|
@ -18,8 +18,16 @@ config PKGS_DIR
|
||||||
source "$RTT_DIR/Kconfig"
|
source "$RTT_DIR/Kconfig"
|
||||||
source "$PKGS_DIR/Kconfig"
|
source "$PKGS_DIR/Kconfig"
|
||||||
|
|
||||||
|
config SOC_SIMULATOR
|
||||||
|
bool
|
||||||
|
select RT_USING_COMPONENTS_INIT
|
||||||
|
select RT_USING_USER_MAIN
|
||||||
|
default y
|
||||||
|
|
||||||
if RT_USING_DFS
|
if RT_USING_DFS
|
||||||
config RT_USING_DFS_WINSHAREDIR
|
config RT_USING_DFS_WINSHAREDIR
|
||||||
bool "Enable shared file system between windows"
|
bool "Enable shared file system between windows"
|
||||||
default n
|
default n
|
||||||
endif
|
endif
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -86,6 +86,19 @@ def ObjRemove(objs, remove):
|
||||||
objs.remove(item)
|
objs.remove(item)
|
||||||
return
|
return
|
||||||
|
|
||||||
|
def ProjectRemove(group, remove):
|
||||||
|
global Projects
|
||||||
|
for item in Projects:
|
||||||
|
if item['name'] == group:
|
||||||
|
for src in item['src']:
|
||||||
|
if os.path.basename(str(src)) in remove:
|
||||||
|
# print(type(src), os.path.basename(str(src)) )
|
||||||
|
item['src'].remove(src)
|
||||||
|
return
|
||||||
|
|
||||||
|
ObjRemove(objs, ['components.obj', 'components.o', 'components.c'])
|
||||||
|
ProjectRemove('Kernel', ['components.obj', 'components.o', 'components.c'])
|
||||||
|
|
||||||
# build program -shared
|
# build program -shared
|
||||||
if GetDepend('RT_USING_MODULE'):
|
if GetDepend('RT_USING_MODULE'):
|
||||||
# Remove module.c in $RTT_ROOT/src
|
# Remove module.c in $RTT_ROOT/src
|
||||||
|
|
|
@ -11,37 +11,8 @@
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <board.h>
|
#include <board.h>
|
||||||
|
|
||||||
extern int platform_init(void);
|
int main(void)
|
||||||
extern int platform_post_init(void);
|
|
||||||
extern int mnt_init(void);
|
|
||||||
|
|
||||||
void rt_init_thread_entry(void *parameter)
|
|
||||||
{
|
{
|
||||||
rt_kprintf("Hello RT-Thread!\n");
|
rt_kprintf("Hello RT-Thread!\n");
|
||||||
|
|
||||||
platform_init();
|
|
||||||
mnt_init();
|
|
||||||
|
|
||||||
platform_post_init();
|
|
||||||
|
|
||||||
#if defined(PKG_USING_GUIENGINE) && defined(GUIENGINE_USING_DEMO)
|
|
||||||
{
|
|
||||||
extern int rt_gui_demo_init(void);
|
|
||||||
rt_gui_demo_init();
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
}
|
|
||||||
|
|
||||||
int rt_application_init()
|
|
||||||
{
|
|
||||||
rt_thread_t tid;
|
|
||||||
|
|
||||||
tid = rt_thread_create("init",
|
|
||||||
rt_init_thread_entry, RT_NULL,
|
|
||||||
2048, RT_THREAD_PRIORITY_MAX / 3, 20);
|
|
||||||
|
|
||||||
if (tid != RT_NULL)
|
|
||||||
rt_thread_startup(tid);
|
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
|
@ -15,8 +15,6 @@
|
||||||
|
|
||||||
int mnt_init(void)
|
int mnt_init(void)
|
||||||
{
|
{
|
||||||
dfs_init();
|
|
||||||
|
|
||||||
#ifdef RT_USING_DFS_WINSHAREDIR
|
#ifdef RT_USING_DFS_WINSHAREDIR
|
||||||
extern int dfs_win32_init(void);
|
extern int dfs_win32_init(void);
|
||||||
extern rt_err_t rt_win_sharedir_init(const char *name);
|
extern rt_err_t rt_win_sharedir_init(const char *name);
|
||||||
|
@ -54,5 +52,5 @@ int mnt_init(void)
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
INIT_COMPONENT_EXPORT(mnt_init);
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -13,8 +13,6 @@
|
||||||
|
|
||||||
int platform_init(void)
|
int platform_init(void)
|
||||||
{
|
{
|
||||||
finsh_system_init();
|
|
||||||
|
|
||||||
#ifdef RT_USING_LWIP
|
#ifdef RT_USING_LWIP
|
||||||
#ifdef RT_USING_TAPNETIF
|
#ifdef RT_USING_TAPNETIF
|
||||||
tap_netif_hw_init();
|
tap_netif_hw_init();
|
||||||
|
@ -39,6 +37,7 @@ int platform_init(void)
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
INIT_COMPONENT_EXPORT(platform_init);
|
||||||
|
|
||||||
int platform_post_init(void)
|
int platform_post_init(void)
|
||||||
{
|
{
|
||||||
|
@ -51,6 +50,6 @@ int platform_post_init(void)
|
||||||
rt_hw_sdl_start();
|
rt_hw_sdl_start();
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
INIT_COMPONENT_EXPORT(platform_post_init);
|
||||||
|
|
|
@ -1,73 +0,0 @@
|
||||||
/*
|
|
||||||
* Copyright (c) 2006-2021, RT-Thread Development Team
|
|
||||||
*
|
|
||||||
* SPDX-License-Identifier: Apache-2.0
|
|
||||||
*
|
|
||||||
* Change Logs:
|
|
||||||
* Date Author Notes
|
|
||||||
* 2012-09-03 prife first implementation
|
|
||||||
*/
|
|
||||||
#include <rthw.h>
|
|
||||||
#include <rtthread.h>
|
|
||||||
|
|
||||||
#include "board.h"
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @addtogroup win32
|
|
||||||
*/
|
|
||||||
|
|
||||||
/*@{*/
|
|
||||||
|
|
||||||
extern int rt_application_init(void);
|
|
||||||
extern rt_uint8_t *heap;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* This function will startup RT-Thread RTOS.
|
|
||||||
*/
|
|
||||||
void rtthread_startup(void)
|
|
||||||
{
|
|
||||||
/* init board */
|
|
||||||
rt_hw_board_init();
|
|
||||||
|
|
||||||
/* show version */
|
|
||||||
rt_show_version();
|
|
||||||
|
|
||||||
/* init timer system */
|
|
||||||
rt_system_timer_init();
|
|
||||||
|
|
||||||
#ifdef RT_USING_HEAP
|
|
||||||
/* init memory system */
|
|
||||||
rt_system_heap_init((void *)heap, (void *)&heap[RT_HEAP_SIZE - 1]);
|
|
||||||
#endif
|
|
||||||
|
|
||||||
/* init scheduler system */
|
|
||||||
rt_system_scheduler_init();
|
|
||||||
|
|
||||||
/* init application */
|
|
||||||
rt_application_init();
|
|
||||||
|
|
||||||
/* init timer thread */
|
|
||||||
rt_system_timer_thread_init();
|
|
||||||
|
|
||||||
/* init idle thread */
|
|
||||||
rt_thread_idle_init();
|
|
||||||
|
|
||||||
/* start scheduler */
|
|
||||||
rt_system_scheduler_start();
|
|
||||||
|
|
||||||
/* never reach here */
|
|
||||||
return ;
|
|
||||||
}
|
|
||||||
|
|
||||||
int main(void)
|
|
||||||
{
|
|
||||||
/* disable interrupt first */
|
|
||||||
rt_hw_interrupt_disable();
|
|
||||||
|
|
||||||
/* startup RT-Thread RTOS */
|
|
||||||
rtthread_startup();
|
|
||||||
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
/*@}*/
|
|
|
@ -18,7 +18,6 @@
|
||||||
/**
|
/**
|
||||||
* @addtogroup simulator on win32
|
* @addtogroup simulator on win32
|
||||||
*/
|
*/
|
||||||
rt_uint8_t *heap;
|
|
||||||
|
|
||||||
rt_uint8_t *rt_hw_sram_init(void)
|
rt_uint8_t *rt_hw_sram_init(void)
|
||||||
{
|
{
|
||||||
|
@ -33,6 +32,10 @@ rt_uint8_t *rt_hw_sram_init(void)
|
||||||
exit(1);
|
exit(1);
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
#ifdef RT_USING_HEAP
|
||||||
|
/* init memory system */
|
||||||
|
rt_system_heap_init((void*)heap, (void*)&heap[RT_HEAP_SIZE - 1]);
|
||||||
|
#endif
|
||||||
return heap;
|
return heap;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -87,10 +90,10 @@ FINSH_FUNCTION_EXPORT_ALIAS(rt_hw_exit, __cmd_quit, exit rt-thread);
|
||||||
/**
|
/**
|
||||||
* This function will initial win32
|
* This function will initial win32
|
||||||
*/
|
*/
|
||||||
void rt_hw_board_init()
|
int rt_hw_board_init(void)
|
||||||
{
|
{
|
||||||
/* init system memory */
|
/* init system memory */
|
||||||
heap = rt_hw_sram_init();
|
rt_hw_sram_init();
|
||||||
|
|
||||||
uart_console_init();
|
uart_console_init();
|
||||||
|
|
||||||
|
@ -101,5 +104,10 @@ void rt_hw_board_init()
|
||||||
#if defined(RT_USING_CONSOLE)
|
#if defined(RT_USING_CONSOLE)
|
||||||
rt_console_set_device(RT_CONSOLE_DEVICE_NAME);
|
rt_console_set_device(RT_CONSOLE_DEVICE_NAME);
|
||||||
#endif
|
#endif
|
||||||
|
/* init board */
|
||||||
|
#ifdef RT_USING_COMPONENTS_INIT
|
||||||
|
rt_components_board_init();
|
||||||
|
#endif
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
/*@}*/
|
/*@}*/
|
||||||
|
|
|
@ -9,7 +9,7 @@
|
||||||
*/
|
*/
|
||||||
#ifndef __BOARD_H__
|
#ifndef __BOARD_H__
|
||||||
#define __BOARD_H__
|
#define __BOARD_H__
|
||||||
void rt_hw_board_init(void);
|
int rt_hw_board_init(void);
|
||||||
rt_uint8_t *rt_hw_sram_init(void);
|
rt_uint8_t *rt_hw_sram_init(void);
|
||||||
|
|
||||||
/* SD Card init function */
|
/* SD Card init function */
|
||||||
|
|
|
@ -43,6 +43,10 @@
|
||||||
|
|
||||||
/* RT-Thread Components */
|
/* RT-Thread Components */
|
||||||
|
|
||||||
|
#define RT_USING_COMPONENTS_INIT
|
||||||
|
#define RT_USING_USER_MAIN
|
||||||
|
#define RT_MAIN_THREAD_STACK_SIZE 2048
|
||||||
|
#define RT_MAIN_THREAD_PRIORITY 10
|
||||||
|
|
||||||
/* C++ features */
|
/* C++ features */
|
||||||
|
|
||||||
|
@ -157,14 +161,18 @@
|
||||||
/* peripheral libraries and drivers */
|
/* peripheral libraries and drivers */
|
||||||
|
|
||||||
|
|
||||||
|
/* AI packages */
|
||||||
|
|
||||||
|
|
||||||
/* miscellaneous packages */
|
/* miscellaneous packages */
|
||||||
|
|
||||||
|
|
||||||
/* samples: kernel and components samples */
|
/* samples: kernel and components samples */
|
||||||
|
|
||||||
|
|
||||||
/* games: games run on RT-Thread console */
|
/* entertainment: terminal games and other interesting software packages */
|
||||||
|
|
||||||
|
#define SOC_SIMULATOR
|
||||||
#define RT_USING_DFS_WINSHAREDIR
|
#define RT_USING_DFS_WINSHAREDIR
|
||||||
#include "rtconfig_project.h"
|
#include "rtconfig_project.h"
|
||||||
|
|
||||||
|
|
|
@ -210,7 +210,32 @@ typedef rt_base_t rt_off_t; /**< Type for offset */
|
||||||
#ifdef RT_USING_COMPONENTS_INIT
|
#ifdef RT_USING_COMPONENTS_INIT
|
||||||
typedef int (*init_fn_t)(void);
|
typedef int (*init_fn_t)(void);
|
||||||
#ifdef _MSC_VER /* we do not support MS VC++ compiler */
|
#ifdef _MSC_VER /* we do not support MS VC++ compiler */
|
||||||
#define INIT_EXPORT(fn, level)
|
#pragma section("rti_fn$f",read)
|
||||||
|
#if RT_DEBUG_INIT
|
||||||
|
struct rt_init_desc
|
||||||
|
{
|
||||||
|
const char* level;
|
||||||
|
const init_fn_t fn;
|
||||||
|
const char* fn_name;
|
||||||
|
};
|
||||||
|
#define INIT_EXPORT(fn, level) \
|
||||||
|
const char __rti_level_##fn[] = level"__rt_init_"#fn; \
|
||||||
|
const char __rti_##fn##_name[] = #fn; \
|
||||||
|
__declspec(allocate("rti_fn$f")) \
|
||||||
|
RT_USED const struct rt_init_desc __rt_init_msc_##fn = \
|
||||||
|
{__rti_level_##fn, fn, __rti_##fn##_name};
|
||||||
|
#else
|
||||||
|
struct rt_init_desc
|
||||||
|
{
|
||||||
|
const char* level;
|
||||||
|
const init_fn_t fn;
|
||||||
|
};
|
||||||
|
#define INIT_EXPORT(fn, level) \
|
||||||
|
const char __rti_level_##fn[] = level"__rt_init_"#fn; \
|
||||||
|
__declspec(allocate("rti_fn$f")) \
|
||||||
|
RT_USED const struct rt_init_desc __rt_init_msc_##fn = \
|
||||||
|
{__rti_level_##fn, fn };
|
||||||
|
#endif
|
||||||
#else
|
#else
|
||||||
#if RT_DEBUG_INIT
|
#if RT_DEBUG_INIT
|
||||||
struct rt_init_desc
|
struct rt_init_desc
|
||||||
|
|
|
@ -699,3 +699,14 @@ rt_uint32_t YieldInterruptHandle(void)
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
} /*** YieldInterruptHandle ***/
|
} /*** YieldInterruptHandle ***/
|
||||||
|
|
||||||
|
/* system entry */
|
||||||
|
extern int rtthread_startup(void);
|
||||||
|
int wmain(int argc, char* argv[])
|
||||||
|
{
|
||||||
|
/* disable interrupt first */
|
||||||
|
rt_hw_interrupt_disable();
|
||||||
|
/* startup RT-Thread RTOS */
|
||||||
|
rtthread_startup();
|
||||||
|
}
|
||||||
|
#pragma comment(linker, "/subsystem:console /entry:wmainCRTStartup")
|
||||||
|
|
|
@ -0,0 +1,326 @@
|
||||||
|
/*
|
||||||
|
* SPDX-License-Identifier: Apache-2.0
|
||||||
|
*
|
||||||
|
* Change Logs:
|
||||||
|
* Date Author Notes
|
||||||
|
* 2020-12-04 tyx first implementation
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <rthw.h>
|
||||||
|
#include <rtthread.h>
|
||||||
|
|
||||||
|
#ifdef RT_USING_USER_MAIN
|
||||||
|
#ifndef RT_MAIN_THREAD_STACK_SIZE
|
||||||
|
#define RT_MAIN_THREAD_STACK_SIZE 2048
|
||||||
|
#endif
|
||||||
|
#ifndef RT_MAIN_THREAD_PRIORITY
|
||||||
|
#define RT_MAIN_THREAD_PRIORITY (RT_THREAD_PRIORITY_MAX / 3)
|
||||||
|
#endif
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#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 initialization, the driver or component initial function must
|
||||||
|
* be defined with:
|
||||||
|
* INIT_BOARD_EXPORT(fn);
|
||||||
|
* INIT_DEVICE_EXPORT(fn);
|
||||||
|
* ...
|
||||||
|
* INIT_APP_EXPORT(fn);
|
||||||
|
* etc.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#pragma section("rti_fn$a", read)
|
||||||
|
const char __rti_fn_begin_name[] = "__rti_fn_start";
|
||||||
|
__declspec(allocate("rti_fn$a")) const struct rt_init_desc __rti_fn_begin =
|
||||||
|
{
|
||||||
|
__rti_fn_begin_name,
|
||||||
|
NULL
|
||||||
|
};
|
||||||
|
|
||||||
|
#pragma section("rti_fn$z", read)
|
||||||
|
const char __rti_fn_end_name[] = "__rti_fn_end";
|
||||||
|
__declspec(allocate("rti_fn$z")) const struct rt_init_desc __rti_fn_end =
|
||||||
|
{
|
||||||
|
__rti_fn_end_name,
|
||||||
|
NULL
|
||||||
|
};
|
||||||
|
|
||||||
|
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");
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Find next init function
|
||||||
|
*/
|
||||||
|
static const struct rt_init_desc* rt_init_find_next(const char* lv,
|
||||||
|
unsigned int* begin, unsigned int* end)
|
||||||
|
{
|
||||||
|
const struct rt_init_desc* ptr;
|
||||||
|
const struct rt_init_desc* ret_ptr = RT_NULL;
|
||||||
|
|
||||||
|
while (begin < end)
|
||||||
|
{
|
||||||
|
if (*begin != 0)
|
||||||
|
{
|
||||||
|
ptr = (const struct rt_init_desc*)begin;
|
||||||
|
if (ret_ptr != RT_NULL)
|
||||||
|
{
|
||||||
|
if (rt_strcmp(lv, ptr->level) < 0 &&
|
||||||
|
rt_strcmp(ret_ptr->level, ptr->level) > 0)
|
||||||
|
{
|
||||||
|
ret_ptr = ptr;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
if (rt_strcmp(lv, ptr->level) < 0)
|
||||||
|
{
|
||||||
|
ret_ptr = ptr;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
begin += (sizeof(struct rt_init_desc) / sizeof(unsigned int));
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
begin++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return ret_ptr;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* RT-Thread Components Initialization for board
|
||||||
|
*/
|
||||||
|
void rt_components_board_init(void)
|
||||||
|
{
|
||||||
|
const struct rt_init_desc* ptr;
|
||||||
|
const char* lv_start = "0__rt_init_rti_start";
|
||||||
|
const char* lv_end = "1_end__rt_init_rti_board_end";
|
||||||
|
unsigned int* ptr_begin = (unsigned int*)&__rti_fn_begin;
|
||||||
|
unsigned int* ptr_end = (unsigned int*)&__rti_fn_end;
|
||||||
|
int result;
|
||||||
|
|
||||||
|
ptr_begin += (sizeof(struct rt_init_desc) / sizeof(unsigned int));
|
||||||
|
while (*ptr_begin == 0) ptr_begin++;
|
||||||
|
do ptr_end--; while (*ptr_end == 0);
|
||||||
|
|
||||||
|
while (1)
|
||||||
|
{
|
||||||
|
ptr = rt_init_find_next(lv_start, ptr_begin, ptr_end);
|
||||||
|
if (ptr == RT_NULL ||
|
||||||
|
rt_strcmp(ptr->level, lv_end) >= 0)
|
||||||
|
{
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
if (ptr->fn)
|
||||||
|
{
|
||||||
|
#if RT_DEBUG_INIT
|
||||||
|
rt_kprintf("initialize %s", ptr->fn_name);
|
||||||
|
result = ptr->fn();
|
||||||
|
rt_kprintf(":%d done\n", result);
|
||||||
|
#else
|
||||||
|
result = ptr->fn();
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
lv_start = ptr->level;
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* RT-Thread Components Initialization
|
||||||
|
*/
|
||||||
|
void rt_components_init(void)
|
||||||
|
{
|
||||||
|
const struct rt_init_desc* ptr;
|
||||||
|
const char* lv_start = "1_end__rt_init_rti_board_end";
|
||||||
|
const char* lv_end = "6_end__rt_init_rti_end";
|
||||||
|
unsigned int* ptr_begin = (unsigned int*)&__rti_fn_begin;
|
||||||
|
unsigned int* ptr_end = (unsigned int*)&__rti_fn_end;
|
||||||
|
int result;
|
||||||
|
|
||||||
|
ptr_begin += (sizeof(struct rt_init_desc) / sizeof(unsigned int));
|
||||||
|
while (*ptr_begin == 0) ptr_begin++;
|
||||||
|
do ptr_end--; while (*ptr_end == 0);
|
||||||
|
|
||||||
|
while (1)
|
||||||
|
{
|
||||||
|
ptr = rt_init_find_next(lv_start, ptr_begin, ptr_end);
|
||||||
|
if (ptr == RT_NULL ||
|
||||||
|
rt_strcmp(ptr->level, lv_end) >= 0)
|
||||||
|
{
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
if (ptr->fn)
|
||||||
|
{
|
||||||
|
#if RT_DEBUG_INIT
|
||||||
|
rt_kprintf("initialize %s", ptr->fn_name);
|
||||||
|
result = ptr->fn();
|
||||||
|
rt_kprintf(":%d done\n", result);
|
||||||
|
#else
|
||||||
|
result = ptr->fn();
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
lv_start = ptr->level;
|
||||||
|
};
|
||||||
|
}
|
||||||
|
#endif /* RT_USING_COMPONENTS_INIT */
|
||||||
|
|
||||||
|
#ifdef RT_USING_USER_MAIN
|
||||||
|
|
||||||
|
void rt_application_init(void);
|
||||||
|
void rt_hw_board_init(void);
|
||||||
|
int rtthread_startup(void);
|
||||||
|
|
||||||
|
#if defined(__CC_ARM) || defined(__CLANG_ARM)
|
||||||
|
extern int $Super$$main(void);
|
||||||
|
/* re-define main function */
|
||||||
|
int $Sub$$main(void)
|
||||||
|
{
|
||||||
|
rtthread_startup();
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
#elif defined(__ICCARM__)
|
||||||
|
extern int main(void);
|
||||||
|
/* __low_level_init will auto called by IAR cstartup */
|
||||||
|
extern void __iar_data_init3(void);
|
||||||
|
int __low_level_init(void)
|
||||||
|
{
|
||||||
|
// call IAR table copy function.
|
||||||
|
__iar_data_init3();
|
||||||
|
rtthread_startup();
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
#elif defined(__GNUC__)
|
||||||
|
/* Add -eentry to arm-none-eabi-gcc argument */
|
||||||
|
int entry(void)
|
||||||
|
{
|
||||||
|
rtthread_startup();
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifndef RT_USING_HEAP
|
||||||
|
/* if there is not enable heap, we should use static thread and stack. */
|
||||||
|
ALIGN(8)
|
||||||
|
static rt_uint8_t main_stack[RT_MAIN_THREAD_STACK_SIZE];
|
||||||
|
struct rt_thread main_thread;
|
||||||
|
#endif
|
||||||
|
|
||||||
|
/* the system main thread */
|
||||||
|
void main_thread_entry(void *parameter)
|
||||||
|
{
|
||||||
|
extern int main(void);
|
||||||
|
|
||||||
|
#ifdef RT_USING_COMPONENTS_INIT
|
||||||
|
/* RT-Thread components initialization */
|
||||||
|
rt_components_init();
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifdef RT_USING_SMP
|
||||||
|
rt_hw_secondary_cpu_up();
|
||||||
|
#endif
|
||||||
|
/* invoke system main function */
|
||||||
|
#if defined(__CC_ARM) || defined(__CLANG_ARM)
|
||||||
|
{
|
||||||
|
extern int $Super$$main(void);
|
||||||
|
$Super$$main(); /* for ARMCC. */
|
||||||
|
}
|
||||||
|
#elif defined(__ICCARM__) || defined(__GNUC__) || defined(__TASKING__) || defined(_MSC_VER)
|
||||||
|
main();
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
|
void rt_application_init(void)
|
||||||
|
{
|
||||||
|
rt_thread_t tid;
|
||||||
|
|
||||||
|
#ifdef RT_USING_HEAP
|
||||||
|
tid = rt_thread_create("main", main_thread_entry, RT_NULL,
|
||||||
|
RT_MAIN_THREAD_STACK_SIZE, RT_MAIN_THREAD_PRIORITY, 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,
|
||||||
|
main_stack, sizeof(main_stack), RT_MAIN_THREAD_PRIORITY, 20);
|
||||||
|
RT_ASSERT(result == RT_EOK);
|
||||||
|
|
||||||
|
/* if not define RT_USING_HEAP, using to eliminate the warning */
|
||||||
|
(void)result;
|
||||||
|
#endif
|
||||||
|
|
||||||
|
rt_thread_startup(tid);
|
||||||
|
}
|
||||||
|
|
||||||
|
int rtthread_startup(void)
|
||||||
|
{
|
||||||
|
rt_hw_interrupt_disable();
|
||||||
|
|
||||||
|
/* board level initialization
|
||||||
|
* 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();
|
||||||
|
|
||||||
|
#ifdef RT_USING_SIGNALS
|
||||||
|
/* signal system initialization */
|
||||||
|
rt_system_signal_init();
|
||||||
|
#endif
|
||||||
|
|
||||||
|
/* create init_thread */
|
||||||
|
rt_application_init();
|
||||||
|
|
||||||
|
/* timer thread initialization */
|
||||||
|
rt_system_timer_thread_init();
|
||||||
|
|
||||||
|
/* idle thread initialization */
|
||||||
|
rt_thread_idle_init();
|
||||||
|
|
||||||
|
#ifdef RT_USING_SMP
|
||||||
|
rt_hw_spin_lock(&_cpus_lock);
|
||||||
|
#endif /*RT_USING_SMP*/
|
||||||
|
|
||||||
|
/* start scheduler */
|
||||||
|
rt_system_scheduler_start();
|
||||||
|
|
||||||
|
/* never reach here */
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
#endif
|
Loading…
Reference in New Issue