From 041a351de7c0604961f4041be17f2aaf2cf75a7d Mon Sep 17 00:00:00 2001 From: latercomer Date: Sun, 16 Mar 2025 01:06:58 +0800 Subject: [PATCH 1/7] =?UTF-8?q?=E8=A7=A3=E5=86=B3bps/simulator=E6=97=A0?= =?UTF-8?q?=E6=B3=95=E5=9C=A8vs2019=E7=8E=AF=E5=A2=83=E4=B8=8B=E7=BC=96?= =?UTF-8?q?=E8=AF=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: latercomer --- .gitignore | 1 + bsp/simulator/template_vs2012.vcxproj | 1 + components/finsh/finsh.h | 8 ++++++++ src/scheduler_up.c | 1 + 4 files changed, 11 insertions(+) diff --git a/.gitignore b/.gitignore index 7f7bab74a77..72a8882ed48 100644 --- a/.gitignore +++ b/.gitignore @@ -13,6 +13,7 @@ *.crf build Debug +.vs rtthread settings documentation/html diff --git a/bsp/simulator/template_vs2012.vcxproj b/bsp/simulator/template_vs2012.vcxproj index 0ace6590650..914efbc8093 100644 --- a/bsp/simulator/template_vs2012.vcxproj +++ b/bsp/simulator/template_vs2012.vcxproj @@ -44,6 +44,7 @@ Level3 EditAndContinue /utf-8 %(AdditionalOptions) + stdc11 winmm.lib;Packet.lib;wpcap.lib;%(AdditionalDependencies) diff --git a/components/finsh/finsh.h b/components/finsh/finsh.h index 5c97ccd7315..d9ddec59831 100644 --- a/components/finsh/finsh.h +++ b/components/finsh/finsh.h @@ -212,14 +212,22 @@ typedef struct msh_cmd_opt * * @param[in] command The command associated with these options. */ +#ifdef _MSC_VER +#define CMD_OPTIONS_STATEMENT(command) static struct msh_cmd_opt command##_msh_options[16]; +#else #define CMD_OPTIONS_STATEMENT(command) static struct msh_cmd_opt command##_msh_options[]; +#endif /** * @brief Starts the definition of command options for a specific command. * * @param[in] command The command these options are associated with. */ +#ifdef _MSC_VER +#define CMD_OPTIONS_NODE_START(command) static struct msh_cmd_opt command##_msh_options[16] = { +#else #define CMD_OPTIONS_NODE_START(command) static struct msh_cmd_opt command##_msh_options[] = { +#endif /** * @brief Defines a single command option. diff --git a/src/scheduler_up.c b/src/scheduler_up.c index 693cfcae0ed..95e3cc7fb64 100644 --- a/src/scheduler_up.c +++ b/src/scheduler_up.c @@ -32,6 +32,7 @@ * 2023-10-17 ChuShicheng Modify the timing of clearing RT_THREAD_STAT_YIELD flag bits */ +#define __RT_IPC_SOURCE__ #include #include From 1ed64f16026082afb2ef4220b7d28f6d948129ce Mon Sep 17 00:00:00 2001 From: latercomer Date: Sun, 16 Mar 2025 09:20:31 +0800 Subject: [PATCH 2/7] =?UTF-8?q?=E5=88=A0=E9=99=A4libcpu/sim/simulator?= =?UTF-8?q?=E4=B8=ADmsvc=E7=BC=96=E8=AF=91=E5=99=A8=E5=A4=9A=E4=BD=99?= =?UTF-8?q?=E4=BB=A3=E7=A0=81=EF=BC=8C=E4=B8=BA=E5=90=8E=E7=BB=AD=E6=94=AF?= =?UTF-8?q?=E6=8C=81mingw64=E5=81=9A=E5=87=86=E5=A4=87?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: latercomer --- libcpu/sim/win32/cpu_port.c | 11 ------ .../sim/win32/{startup.c => startup_msvc.c} | 39 ++++--------------- 2 files changed, 8 insertions(+), 42 deletions(-) rename libcpu/sim/win32/{startup.c => startup_msvc.c} (90%) diff --git a/libcpu/sim/win32/cpu_port.c b/libcpu/sim/win32/cpu_port.c index 4f8b32271b6..6b7da50bf4b 100644 --- a/libcpu/sim/win32/cpu_port.c +++ b/libcpu/sim/win32/cpu_port.c @@ -699,14 +699,3 @@ rt_uint32_t YieldInterruptHandle(void) return 0; } /*** 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") diff --git a/libcpu/sim/win32/startup.c b/libcpu/sim/win32/startup_msvc.c similarity index 90% rename from libcpu/sim/win32/startup.c rename to libcpu/sim/win32/startup_msvc.c index f0f2784a7a1..6bf7a575bcd 100644 --- a/libcpu/sim/win32/startup.c +++ b/libcpu/sim/win32/startup_msvc.c @@ -221,33 +221,16 @@ void rt_application_init(void); void rt_hw_board_init(void); int rtthread_startup(void); -#if defined(__ARMCC_VERSION) -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) +/* 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(); - return 0; } -#endif +#pragma comment(linker, "/subsystem:console /entry:wmainCRTStartup") #ifndef RT_USING_HEAP /* if there is not enable heap, we should use static thread and stack. */ @@ -269,15 +252,9 @@ void main_thread_entry(void *parameter) #ifdef RT_USING_SMP rt_hw_secondary_cpu_up(); #endif + /* invoke system main function */ -#if defined(__ARMCC_VERSION) - { - 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) From 9dcfc43359b197cd2aeaba30721a25098e2c5f1e Mon Sep 17 00:00:00 2001 From: latercomer Date: Sun, 16 Mar 2025 16:26:21 +0800 Subject: [PATCH 3/7] =?UTF-8?q?=E8=A7=A3=E5=86=B3rt=5Fhw=5Fcontext=5Fswitc?= =?UTF-8?q?h=5Finterrupt=E5=BD=A2=E5=8F=82=E5=AE=9A=E4=B9=89=E4=B8=8D?= =?UTF-8?q?=E4=B8=80=E8=87=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: latercomer --- bsp/simulator/template_vs2012.vcxproj | 1 + libcpu/sim/win32/cpu_port.c | 12 ++++++------ 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/bsp/simulator/template_vs2012.vcxproj b/bsp/simulator/template_vs2012.vcxproj index 914efbc8093..610a05b4c47 100644 --- a/bsp/simulator/template_vs2012.vcxproj +++ b/bsp/simulator/template_vs2012.vcxproj @@ -45,6 +45,7 @@ EditAndContinue /utf-8 %(AdditionalOptions) stdc11 + 4029 winmm.lib;Packet.lib;wpcap.lib;%(AdditionalDependencies) diff --git a/libcpu/sim/win32/cpu_port.c b/libcpu/sim/win32/cpu_port.c index 6b7da50bf4b..15d0218f038 100644 --- a/libcpu/sim/win32/cpu_port.c +++ b/libcpu/sim/win32/cpu_port.c @@ -97,8 +97,9 @@ static MMRESULT OSTick_TimerID; /* * flag in interrupt handling */ -rt_uint32_t rt_interrupt_from_thread, rt_interrupt_to_thread; -rt_uint32_t rt_thread_switch_interrupt_flag; +volatile rt_ubase_t rt_interrupt_from_thread = 0; +volatile rt_ubase_t rt_interrupt_to_thread = 0; +volatile rt_uint32_t rt_thread_switch_interrupt_flag = 0; /* ********************************************************************************************************* @@ -248,18 +249,17 @@ void rt_hw_interrupt_enable(rt_base_t level) * Note(s) : none ********************************************************************************************************* */ -void rt_hw_context_switch_interrupt(rt_uint32_t from, - rt_uint32_t to) +void rt_hw_context_switch_interrupt(rt_ubase_t from, rt_ubase_t to, rt_thread_t from_thread, rt_thread_t to_thread) { if(rt_thread_switch_interrupt_flag != 1) { rt_thread_switch_interrupt_flag = 1; // set rt_interrupt_from_thread - rt_interrupt_from_thread = *((rt_uint32_t *)(from)); + rt_interrupt_from_thread = from; } - rt_interrupt_to_thread = *((rt_uint32_t *)(to)); + rt_interrupt_to_thread = to; //trigger YIELD exception(cause context switch) TriggerSimulateInterrupt(CPU_INTERRUPT_YIELD); From 3f306044416cbd21794edc6851a4b8235e226e9f Mon Sep 17 00:00:00 2001 From: latercomer Date: Sun, 16 Mar 2025 16:58:33 +0800 Subject: [PATCH 4/7] =?UTF-8?q?=E8=A7=A3=E5=86=B3=5F=5FRT=5FKERNEL=5FSOURC?= =?UTF-8?q?E=5F=5F=E5=AE=8F=E6=B2=A1=E6=9C=89=E5=AE=9A=E4=B9=89?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: latercomer --- src/SConscript | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/src/SConscript b/src/SConscript index 93b8e8e3f3d..7b2dec5e4ce 100644 --- a/src/SConscript +++ b/src/SConscript @@ -50,9 +50,14 @@ if GetDepend('RT_USING_HOOKLIST') == True: elif rtconfig.PLATFORM in ['armcc']: LOCAL_CFLAGS += ' --c99 --gnu' -group = DefineGroup('Kernel', src, depend=[''], CPPPATH=inc, - LINKFLAGS=LINKFLAGS, LOCAL_CFLAGS=LOCAL_CFLAGS, - CPPDEFINES=['__RTTHREAD__'], LOCAL_CPPDEFINES=['__RT_KERNEL_SOURCE__']) +if rtconfig.CROSS_TOOL == 'msvc': + group = DefineGroup('Kernel', src, depend=[''], CPPPATH=inc, + LINKFLAGS=LINKFLAGS, LOCAL_CFLAGS=LOCAL_CFLAGS, + CPPDEFINES=['__RTTHREAD__', '__RT_KERNEL_SOURCE__']) +else: + group = DefineGroup('Kernel', src, depend=[''], CPPPATH=inc, + LINKFLAGS=LINKFLAGS, LOCAL_CFLAGS=LOCAL_CFLAGS, + CPPDEFINES=['__RTTHREAD__'], LOCAL_CPPDEFINES=['__RT_KERNEL_SOURCE__']) list = os.listdir(cwd) for item in list: From 0c6afbe37a2daa22ee7ef58b63675431a41132e6 Mon Sep 17 00:00:00 2001 From: latercomer Date: Sun, 16 Mar 2025 21:05:29 +0800 Subject: [PATCH 5/7] =?UTF-8?q?=E4=BF=AE=E5=A4=8Drt=5Fhw=5Fcontext=5Fswitc?= =?UTF-8?q?h=5Fto=E5=92=8Crt=5Fhw=5Fcontext=5Fswitch=E7=9A=84=E5=BD=A2?= =?UTF-8?q?=E5=8F=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: latercomer --- libcpu/sim/win32/cpu_port.c | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/libcpu/sim/win32/cpu_port.c b/libcpu/sim/win32/cpu_port.c index 15d0218f038..1ac9fc0379e 100644 --- a/libcpu/sim/win32/cpu_port.c +++ b/libcpu/sim/win32/cpu_port.c @@ -267,20 +267,19 @@ void rt_hw_context_switch_interrupt(rt_ubase_t from, rt_ubase_t to, rt_thread_t -void rt_hw_context_switch(rt_uint32_t from, - rt_uint32_t to) +void rt_hw_context_switch(rt_ubase_t from, rt_ubase_t to) { if(rt_thread_switch_interrupt_flag != 1) { rt_thread_switch_interrupt_flag = 1; // set rt_interrupt_from_thread - rt_interrupt_from_thread = *((rt_uint32_t *)(from)); + rt_interrupt_from_thread = from; } // set rt_interrupt_to_thread - rt_interrupt_to_thread = *((rt_uint32_t *)(to)); + rt_interrupt_to_thread = to; //trigger YIELD exception(cause contex switch) TriggerSimulateInterrupt(CPU_INTERRUPT_YIELD); @@ -310,10 +309,10 @@ void rt_hw_context_switch(rt_uint32_t from, * Note(s) : this function is used to perform the first thread switch ********************************************************************************************************* */ -void rt_hw_context_switch_to(rt_uint32_t to) +void rt_hw_context_switch_to(rt_ubase_t to) { //set to thread - rt_interrupt_to_thread = *((rt_uint32_t *)(to)); + rt_interrupt_to_thread = to; //clear from thread rt_interrupt_from_thread = 0; From 052d8eeb4831694c186c58f50cca47bff5f13054 Mon Sep 17 00:00:00 2001 From: latercomer Date: Sun, 16 Mar 2025 23:11:17 +0800 Subject: [PATCH 6/7] =?UTF-8?q?=E8=A7=A3=E5=86=B3rt=5Finterrupt=5Ffrom=5Ft?= =?UTF-8?q?hread=E5=92=8Crt=5Finterrupt=5Fto=5Fthread=E6=8C=87=E9=92=88?= =?UTF-8?q?=E8=B5=8B=E5=80=BC=E9=94=99=E8=AF=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: latercomer --- libcpu/sim/win32/cpu_port.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/libcpu/sim/win32/cpu_port.c b/libcpu/sim/win32/cpu_port.c index 1ac9fc0379e..ad5891c91fa 100644 --- a/libcpu/sim/win32/cpu_port.c +++ b/libcpu/sim/win32/cpu_port.c @@ -256,10 +256,10 @@ void rt_hw_context_switch_interrupt(rt_ubase_t from, rt_ubase_t to, rt_thread_t rt_thread_switch_interrupt_flag = 1; // set rt_interrupt_from_thread - rt_interrupt_from_thread = from; + rt_interrupt_from_thread = *((rt_ubase_t *)(from)); } - rt_interrupt_to_thread = to; + rt_interrupt_to_thread = *((rt_ubase_t *)(to)); //trigger YIELD exception(cause context switch) TriggerSimulateInterrupt(CPU_INTERRUPT_YIELD); @@ -274,12 +274,12 @@ void rt_hw_context_switch(rt_ubase_t from, rt_ubase_t to) rt_thread_switch_interrupt_flag = 1; // set rt_interrupt_from_thread - rt_interrupt_from_thread = from; + rt_interrupt_from_thread = *((rt_ubase_t *)(from)); } // set rt_interrupt_to_thread - rt_interrupt_to_thread = to; + rt_interrupt_to_thread = *((rt_ubase_t *)(to)); //trigger YIELD exception(cause contex switch) TriggerSimulateInterrupt(CPU_INTERRUPT_YIELD); @@ -312,7 +312,7 @@ void rt_hw_context_switch(rt_ubase_t from, rt_ubase_t to) void rt_hw_context_switch_to(rt_ubase_t to) { //set to thread - rt_interrupt_to_thread = to; + rt_interrupt_to_thread = *((rt_ubase_t *)(to)); //clear from thread rt_interrupt_from_thread = 0; From 6e35858624a5488e56c93254da2d42a873ecad6a Mon Sep 17 00:00:00 2001 From: latercomer Date: Sun, 16 Mar 2025 23:30:54 +0800 Subject: [PATCH 7/7] =?UTF-8?q?rttypes.h=E4=B8=AD=E5=A2=9E=E5=8A=A0?= =?UTF-8?q?=E4=BA=86=E5=AF=B9ARCH=5FCPU=5F64BIT=E5=AE=8F=E7=9A=84=E5=88=A4?= =?UTF-8?q?=E6=96=AD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: latercomer --- include/rttypes.h | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/include/rttypes.h b/include/rttypes.h index 75bf58d52f9..aa2d70d7b4a 100644 --- a/include/rttypes.h +++ b/include/rttypes.h @@ -32,6 +32,12 @@ extern "C" { * RT-Thread basic data types definition */ +#if defined(_WIN64) || defined(__x86_64__) +#ifndef ARCH_CPU_64BIT +#define ARCH_CPU_64BIT +#endif // ARCH_CPU_64BIT +#endif // defined(_WIN64) || defined(__x86_64__) + typedef int rt_bool_t; /**< boolean type */ #ifndef RT_USING_ARCH_DATA_TYPE