# rtthread-apps **Repository Path**: ltree930/rtthread-apps ## Basic Information - **Project Name**: rtthread-apps - **Description**: RT-Thread独立应用程序 - **Primary Language**: Unknown - **License**: GPL-2.0 - **Default Branch**: master - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 0 - **Forks**: 10 - **Created**: 2024-09-07 - **Last Updated**: 2024-09-07 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README # RT-Thread RTOS 的应用 [English](README.md)| **中文** ## [介绍](https://gitee.com/rtthread/rtthread-apps#introduction) rtthread-apps是 RT-Thread RTOS 的应用层,开发人员可以 在 RT-Thread 实时操作系统环境中开发应用程序。 RT-Thread 应用程序有两种模式, - 独立应用程序 - 共享库 独立应用程序具有 main() 函数作为程序入口,它更像 PC/Linux 中的程序。 共享库由函数组成,并将这些 API 提供给其他程序。 ## [构建应用程序](https://gitee.com/rtthread/rtthread-apps#build-application) 首先,这些程序必须基于 RT-Thread 实时操作系统环境,并在内部运行。 在 RT-Thread 实时操作系统中,必须在 rtconfig.h 文件中启用 module 选项: ``` #define RT_USING_MODULE ``` 并在 rtconfig.py 文件中提供构建应用程序的标志(从 RT-Thread 2.1.x 开始, 这些标志将逐步添加到每个 BSP 中): - M_CFLAGS - User Application C/C++ 编译器标志 - M_LFLAGS - User Application 链接标志 并提供 ENV 变量 `BSP_ROOT` 指向您的板级支持包目录 Windows: ``` set BSP_ROOT=`your_bsp_directory` ``` Linux: ``` export BSP_ROOT=`your_bsp_directory` ``` 要在 BSP 目录下运行命令: ``` scons --target=ua -s ``` 要为 User Application 生成信息,例如头文件搜索路径、 RT-Thread RTOS etc 中定义的宏。 最后,您可以在`rtthread-apps`目录中构建用户应用程序,例如: ``` scons --app=hello ``` 构建程序 `hello` ``` scons --lib=libtar ``` 构建共享库 `libtar` ## [一个简单的应用程序](https://gitee.com/rtthread/rtthread-apps#a-simple-application) 这是一个简单的应用程序:`Hello World` ```Hello #include int main(int argc, char **argv) { printf("Hello World!\n"); return 0; } ``` 它就像 PC/Linux 中的程序一样。除此之外,用户应用程序可以使用 RT-Thread 的大部分 API,例如:`Hello World` ```Hello #include void my_thread_entry(void* parameter) { int index; while (1) { rt_kprintf("index => %d\n", index ++); rt_thread_delay(RT_TICK_PER_SECOND); } } int my_thread_init(void) { rt_thread_t tid; tid = rt_thread_create("tMyTask', my_thread_entry, RT_NULL, 2048, 20, 20); if (tid != RT_NULL) rt_thread_startup(tid); return 0; } ``` 此示例将创建一个名为 'tMyTask' 的子线程。 ## [在主机中构建 POSIX应用程序](https://gitee.com/rtthread/rtthread-apps#build-the-posix-application-in-the-host) 如果您没有设置` RTT_ROOT`或者`BSP_ROOT`,该命令将`scons --app=hello`将在主机环境中构建程序,例如作为一个 Linux 程序来构建。 因此,只有 POSIX 应用程序可以像这样构建。 ## [许可证](https://gitee.com/rtthread/rtthread-apps#license) 所有用户应用程序均为独立程序,如无特别说明, 这些程序的许可证是 [GPLv2](https://gitee.com/rtthread/rtthread-apps/blob/master/LICENSE)。而 RT-Thread RTOS 的许可证是 GPLv2+。