更改系统分支为4.0.x分支

master
张程凯 2022-01-10 17:10:14 +08:00
parent 5bf7f6a0a8
commit 752b91920a
264 changed files with 30228 additions and 6088 deletions

View File

@ -1,8 +1,6 @@
<p align="center">
<img src="documentation/figures/logo.png" width="60%" >
</p>
# RT-Thread #
**English** | [中文](README_zh.md) |
[中文页](README_zh.md) |
[![GitHub](https://img.shields.io/github/license/RT-Thread/rt-thread.svg)](https://github.com/RT-Thread/rt-thread/blob/master/LICENSE)
[![GitHub release](https://img.shields.io/github/release/RT-Thread/rt-thread.svg)](https://github.com/RT-Thread/rt-thread/releases)
@ -11,13 +9,13 @@
[![GitHub pull-requests](https://img.shields.io/github/issues-pr/RT-Thread/rt-thread.svg)](https://github.com/RT-Thread/rt-thread/pulls)
[![PRs Welcome](https://img.shields.io/badge/PRs-welcome-brightgreen.svg?style=flat)](https://github.com/RT-Thread/rt-thread/pulls)
# RT-Thread
# Introduction
RT-Thread was born in 2006, it is an open source, neutral, and community-based real-time operating system (RTOS).
RT-Thread was born in 2006, it is an open source, neutral, and community-based real-time operating system (RTOS).
RT-Thread is mainly written in C language, easy to understand and easy to port(can be quickly port to a wide range of mainstream MCUs and module chips). It applies object-oriented programming methods to real-time system design, making the code elegant, structured, modular, and very tailorable.
RT-Thread is mainly written in C language, easy to understand and easy to port(can be quickly port to a wide range of mainstream MCUs and module chips). It applies object-oriented programming methods to real-time system design, making the code elegant, structured, modular, and very tailorable.
RT-Thread has Standard version and Nano version. For resource-constrained microcontroller (MCU) systems, the Nano version that requires only 3KB Flash and 1.2KB RAM memory resources can be tailored with easy-to-use tools. For resource-rich IoT devices, RT-Thread can use the on-line software package management tool, together with system configuration tools, to achieve intuitive and rapid modular cutting, seamlessly import rich software packages; thus, achieving complex functions like Android's graphical interface and touch sliding effects, smart voice interaction effects, and so on.
RT-Thread has Standard version and Nano version. For resource-constrained microcontroller (MCU) systems, the NANO kernel version that requires only 3KB Flash and 1.2KB RAM memory resources can be tailored with easy-to-use tools; And for resource-rich IoT devices, RT-Thread can use the on-line software package management tool, together with system configuration tools, to achieve intuitive and rapid modular cutting, seamlessly import rich software packages, thus achieving complex functions like Android's graphical interface and touch sliding effects, smart voice interaction effects, and so on.
## RT-Thread Architecture
@ -31,20 +29,23 @@ It includes:
- Kernel layer: RT-Thread kernel, the core part of RT-Thread, includes the implementation of objects in the kernel system, such as multi-threading and its scheduling, semaphore, mailbox, message queue, memory management, timer, etc.; libcpu/BSP (Chip Migration Related Files/Board Support Package) is closely related to hardware and consists of peripheral drivers and CPU porting.
- Components and Service Layer: Components are based on upper-level software on top of the RT-Thread kernel, such as virtual file systems, FinSH command-line interfaces, network frameworks, device frameworks, and more. Its modular design allows for high internal cohesion inside the components and low coupling between components.
- [RT-Thread software package](https://packages.rt-thread.org/en/index.html): A general-purpose software component running on the RT-Thread IoT operating system platform for different application areas, consisting of description information, source code or library files. RT-Thread provides an open package platform with officially available or developer-supplied packages that provide developers with a choice of reusable packages that are an important part of the RT-Thread ecosystem. The package ecosystem is critical to the choice of an operating system because these packages are highly reusable and modular, making it easy for application developers to build the system they want in the shortest amount of time. RT-Thread supports more than 370 software packages.
- Components and Service Layer: Components are based on upper-level software on top of the RT-Thread kernel, such as virtual file systems, FinSH command-line interfaces, network frameworks, device frameworks, and more. Its modular design allows for high internal cohesion inside the components and low coupling between components.
- RT-Thread software package: A general-purpose software component running on the RT-Thread IoT operating system platform for different application areas, consisting of description information, source code or library files. RT-Thread provides an open package platform with officially available or developer-supplied packages that provide developers with a choice of reusable packages that are an important part of the RT-Thread ecosystem. The package ecosystem is critical to the choice of an operating system because these packages are highly reusable and modular, making it easy for application developers to build the system they want in the shortest amount of time. RT-Thread supports more than 180 software packages.
## RT-Thread Features
- Designed for resource-constrained devices, the minimum kernel requires only 1.2KB of RAM and 3 KB of Flash.
- A variety of standard interfaces, such as POSIX, CMSIS, C++ application environment.
- Has rich components and a prosperous and fast growing package ecosystem.
- Elegant code style, easy to use, read and master.
- High Scalability. RT-Thread has high-quality scalable software architecture, loose coupling, modularity, is easy to tailor and expand.
- Supports high-performance applications.
- Supports all mainstream compiling tools such as GCC, Keil and IAR.
- Supports a wide range of <a href="https://www.rt-thread.io/board.html">architectures and chips</a>.
- Designed for resource-constrained devices, the minimum kernel requires only 1.2KB of RAM and 3 KB of Flash.
- Has rich components and a prosperous and fast growing package ecosystem.
- Elegant code style, easy to use, read and master.
- High Scalability. RT-Thread has high-quality scalable software architecture, loose coupling, modularity, is easy to tailor and expand.
- Supports high-performance applications.
- Supports cross-platform and a wide range of chips.
## Code Catalogue
@ -61,7 +62,12 @@ It includes:
| src | The source files for the RT-Thread kernel. |
| tools | The script files for the RT-Thread command build tool. |
RT-Thread has now been ported for nearly 200 development boards, most BSPs support MDK, IAR development environment and GCC compiler, and have provided default MDK and IAR project, which allows users to add their own application code directly based on the project. Each BSP has a similar directory structure, and most BSPs provide a README.md file, which is a markdown-format file that contains the basic introduction of BSP, and introduces how to simply start using BSP.
RT-Thread has now been ported for nearly 90 development boards, most BSPs support MDK, IAR development environment and GCC compiler, and have provided default MDK and IAR project, which allows users to add their own application code directly based on the project. Each BSP has a similar directory structure, and most BSPs provide a README.md file, which is a markdown-format file that contains the basic introduction of BSP, and introduces how to simply start using BSP.
Env is a development tool developed by RT-Thread which provides a build environment, text graphical system configuration, and package management capabilities for project based on the RT-Thread operating system. Its built-in `menuconfig` provides an easy-to-use configuration tool. It can tailor the kernels, components and software packages freely, so that the system can be constructed by building blocks.
- [Download Env Tool](https://www.rt-thread.io/download.html?download=Env)
- [User manual of Env](https://github.com/RT-Thread/rtthread-manual-doc/blob/master/env/env.md)
# Resources
@ -74,14 +80,13 @@ RT-Thread supports many architectures, and has covered the major architectures i
- **ARM Cortex-M4**manufacturers like ST、Nuvton、NXP、GigaDevice、Realtek、Ambiq Micro, ect.
- **ARM Cortex-M7**manufacturers like ST、NXP
- **ARM Cortex-M23**manufacturers like GigaDevice
- **ARM Cortex-M33**manufacturers like ST
- **ARM Cortex-R4**
- **ARM Cortex-A8/A9**manufacturers like NXP
- **ARM7**manufacturers like Samsung
- **ARM9**manufacturers like Allwinner、Xilinx 、GOKE
- **ARM11**manufacturers like Fullhan
- **MIPS32**manufacturers like loongson、Ingenic
- **RISC-V**manufacturers like Hifive、Kendryte、Nuclei
- **RISC-V**manufacturers like Hifive、Kendryte、[Nuclei](https://nucleisys.com/)
- **ARC**manufacturers like SYNOPSYS
- **DSP**manufacturers like TI
- **C-Sky**
@ -91,40 +96,35 @@ RT-Thread supports many architectures, and has covered the major architectures i
The main IDE/compilers supported by RT-Thread are:
- RT-Thread Studio IDE
- MDK KEIL
- IAR
- GCC
- RT-Thread Studio
## RT-Thread Studio IDE
Use Python-based [scons](http://www.scons.org/) for command-line builds.
[User Manual](https://www.rt-thread.io/document/site/rtthread-studio/um/studio-user-manual/) | [Tutorial Videos](https://youtu.be/ucq5eJgZIQg)
RT-Thread Studio Demonstration:
RT-Thread Studio IDE (a.k.a. RT-Studio) is a one-stop intergrated development environment built by RT-Thread team. It has a easy-to-use graphical configuration system and a wealth of software packages and components resources. RT-Studio has the features of project creation, configuration and management,as well as code editing, SDK management, build configuration, debugging configuration, program download and debug. We're looking to make the use of RT-Studio as intuitive as possible, reducing the duplication of work and improving the development efficiency.
![studio](./documentation/figures/studio.gif)
![studio](./documentation/figures/studio.gif)
## Env Tool
[User Manual](https://www.rt-thread.io/document/site/programming-manual/env/env/) | [Tutorial Videos](https://www.youtube.com/watch?v=dEK94o_YoSo)
In the early stage, RT-Thread team also created an auxiliary tool called Env. It is an auxiliary tool with a TUI (Text-based user interface). Developers can use Env tool to configure and generate the GCC, Keil MDK, and IAR projects.
![env](./documentation/figures/env.png)
# Getting Started
[RT-Thread Programming Guide](https://www.rt-thread.io/document/site/tutorial/quick-start/introduction/introduction/) | [RT-Thread Studio IDE](https://www.rt-thread.io/studio.html) | [Kernel Sample](https://github.com/RT-Thread-packages/kernel-sample) | [RT-Thread Beginners Guide](https://www.youtube.com/watch?v=ZMi1O-Rr7yc&list=PLXUV89C_M3G5KVw2IerI-pqApdSM_IaZo)
Based on [STM32F103 BluePill](https://github.com/RT-Thread/rt-thread/tree/master/bsp/stm32/stm32f103-blue-pill) | [Raspberry Pi Pico](https://github.com/RT-Thread/rt-thread/tree/master/bsp/raspberry-pico)
## Simulator
## Getting Started
RT-Thread BSP can be compiled directly and downloaded to the corresponding development board for use. In addition, RT-Thread also provides qemu-vexpress-a9 BSP, which can be used without hardware platform. See the getting started guide below for details.
- [Getting Started of QEMU with Env(Windows)](https://github.com/RT-Thread/rtthread-manual-doc/blob/master/documentation/quick_start_qemu/quick_start_qemu.md)
- [Getting Started of QEMU (Windows)](https://github.com/RT-Thread/rtthread-manual-doc/blob/master/documentation/quick_start_qemu/quick_start_qemu.md)
- [Getting Started of QEMU with Env(Ubuntu)](https://github.com/RT-Thread/rtthread-manual-doc/blob/master/documentation/quick_start_qemu/quick_start_qemu_linux.md)
- [Getting Started of QEMU (Ubuntu)](https://github.com/RT-Thread/rtthread-manual-doc/blob/master/documentation/quick_start_qemu/quick_start_qemu_linux.md)
## Documentation
[RT-Thread Programming Guide](https://github.com/RT-Thread/rtthread-manual-doc) | [RT-Thread Supported Chips & Boards](https://www.rt-thread.io/board.html) |
[RT-Thread Software Package](https://github.com/RT-Thread/packages) | [RT-Thread Studio](https://www.rt-thread.io/studio.html)
## Sample
[Kernel Sample](https://github.com/RT-Thread-packages/kernel-sample) | [Device Sample Code](https://github.com/RT-Thread-packages/peripheral-sample) | [File System Sample Code](https://github.com/RT-Thread-packages/filesystem-sample ) | [Network Sample Code](https://github.com/RT-Thread-packages/network-sample ) |
[Based on the STM32L475 IoT Board SDK](https://github.com/RT-Thread/IoT_Board) | [Based on the W601 IoT Board SDK](https://github.com/RT-Thread/W601_IoT_Board)
# License
@ -138,13 +138,14 @@ RT-Thread is an open source software and has been licensed under Apache License
*/
```
To avoid possible future license conflicts, developers need to sign a Contributor License Agreement (CLA) when submitting PR to RT-Thread.
# Community
RT-Thread is very grateful for the support from all community developers, and if you have any ideas, suggestions or questions in the process of using RT-Thread, RT-Thread can be reached by the following means, and we are also updating RT-Thread in real time on these channels. At the same time, any questions can be asked in the [issue section of RT-Thread repository](https://github.com/RT-Thread/rt-thread/issues) or [RT-Thread forum](https://club.rt-thread.io/), and community members will answer them.
RT-Thread is very grateful for the support from all community developers, and if you have any ideas, suggestions or questions in the process of using RT-Thread, RT-Thread can be reached by the following means, and we are also updating RT-Thread in real time on these channels. At the same time, Any questions can be asked in the [issue section of rtthread-manual-doc](https://github.com/RT-Thread/rtthread-manual-doc/issues). By creating a new issue to describe your questions, community members will answer them.
[Website](https://www.rt-thread.io) | [Github](https://github.com/RT-Thread/rt-thread) | [Twitter](https://twitter.com/rt_thread) | [LinkedIn](https://www.linkedin.com/company/rt-thread-iot-os/posts/?feedView=all) | [Youtube](https://www.youtube.com/channel/UCdDHtIfSYPq4002r27ffqPw) | [Facebook](https://www.facebook.com/RT-Thread-IoT-OS-110395723808463/?modal=admin_todo_tour) | [Medium](https://rt-thread.medium.com/)
[Website](https://www.rt-thread.io) | [Twitter](https://twitter.com/rt_thread) | [Youtube]( https://www.youtube.com/channel/UCdDHtIfSYPq4002r27ffqPw?view_as=subscriber) | [Gitter]( https://gitter.im/RT-Thread) | [Facebook](https://www.facebook.com/RT-Thread-IoT-OS-110395723808463/?modal=admin_todo_tour) | [Medium](https://medium.com/@rt_thread)
# Contribution
If you are interested in RT-Thread and want to join in the development of RT-Thread and become a code contributor,please refer to the [Code Contribution Guide](https://github.com/RT-Thread/rtthread-manual-doc/blob/master/documentation/contribution_guide/contribution_guide.md).

View File

@ -9,7 +9,7 @@ RT-Thread有完整版和Nano版对于资源受限的微控制器MCU
RT-Thread是一个集实时操作系统RTOS内核、中间件组件的物联网操作系统架构如下
![architecturezh](./documentation/figures/architecturezh.png)
![architecturezh](./documentation/figures/architecturezh.png)
@ -19,14 +19,14 @@ RT-Thread是一个集实时操作系统RTOS内核、中间件组件的物
- RT-Thread软件包运行于 RT-Thread物联网操作系统平台上面向不同应用领域的通用软件组件由描述信息、源代码或库文件组成。RT-Thread提供了开放的软件包平台这里存放了官方提供或开发者提供的软件包该平台为开发者提供了众多可重用软件包的选择这也是 RT-Thread生态的重要组成部分。软件包生态对于一个操作系统的选择至关重要因为这些软件包具有很强的可重用性模块化程度很高极大的方便应用开发者在最短时间内打造出自己想要的系统。RT-Thread已经支持的软件包数量已经达到 180+。
## RT-Thread的特点
- 资源占用极低超低功耗设计最小内核Nano版本仅需1.2KB RAM3KB Flash。
- 组件丰富,繁荣发展的软件包生态 。
- 组件丰富,繁荣发展的软件包生态 。
- 简单易用 ,优雅的代码风格,易于阅读、掌握。
@ -68,21 +68,35 @@ Env 是RT-Thread推出的开发辅助工具针对基于RT-Thread操作系统
RT-Thread RTOS 支持许多架构,并且已经涵盖了当前应用中的主要架构。涉及的架构和芯片制造商有:
- ARM Cortex-M0/M0+:如芯片制造商 ST
- ARM Cortex-M3如芯片制造商 ST、全志、灵动等.
- ARM Cortex-M4如芯片制造商 ST、Nuvton、NXP、GigaDevice、Realtek、Ambiq Micro等
- ARM Cortex-M7如芯片制造商 ST、NXP
- ARM Cortex-M23如芯片制造商 GigaDevice
- ARM Cortex-M33如芯片制造商 ST
- ARM Cortex-R4
- ARM Cortex-A8/A9如芯片制造商 NXP
- ARM7如芯片制造商Samsung
- ARM9如芯片制造商Allwinner、Xilinx 、GOKE
- ARM11如芯片制造商Fullhan
- MIPS32如芯片制造商loongson、Ingenic
- RISC-V如芯片制造商Hifive、Kendryte、[芯来Nuclei](https://nucleisys.com/)
- ARC如芯片制造商SYNOPSYS
- DSP如芯片制造商 TI
- C-Sky
- x86
@ -103,7 +117,7 @@ RT-Thread主要支持的IDE/编译器包括:
RT-Thread Studio演示
![studiozh](./documentation/figures/studiozh.gif)
![studiozh](./documentation/figures/studiozh.gif)
## **快速上手**
@ -117,15 +131,15 @@ RT-Thread BSP可以直接编译并下载到相应的开发板使用。此外R
## 文档
[文档中心](https://www.rt-thread.org/document/site/ ) | [编程指南](https://www.rt-thread.org/document/site/programming-manual/basic/basic/ )
[文档中心](https://www.rt-thread.org/document/site/ ) | [编程指南](https://www.rt-thread.org/document/site/programming-manual/basic/basic/ )
[应用 RT-Thread 实现蜂鸣器播放器教程](https://www.rt-thread.org/document/site/tutorial/beep-player/) | [分布式温度监控系统教程](https://www.rt-thread.org/document/site/tutorial/temperature-system/ ) | [智能车连载教程](https://www.rt-thread.org/document/site/tutorial/smart-car/ )
[应用 RT-Thread 实现蜂鸣器播放器教程](https://www.rt-thread.org/document/site/tutorial/beep-player/) | [分布式温度监控系统教程](https://www.rt-thread.org/document/site/tutorial/temperature-system/ ) | [智能车连载教程](https://www.rt-thread.org/document/site/tutorial/smart-car/ )
## 例程
[内核示例](https://github.com/RT-Thread-packages/kernel-sample) | [设备示例代码](https://github.com/RT-Thread-packages/peripheral-sample ) | [文件系统示例代码](https://github.com/RT-Thread-packages/filesystem-sample ) | [网络示例代码](https://github.com/RT-Thread-packages/network-sample ) | [RT-Thread API参考手册](https://www.rt-thread.org/document/api/ )
[内核示例](https://github.com/RT-Thread-packages/kernel-sample) | [设备示例代码](https://github.com/RT-Thread-packages/peripheral-sample ) | [文件系统示例代码](https://github.com/RT-Thread-packages/filesystem-sample ) | [网络示例代码](https://github.com/RT-Thread-packages/network-sample ) | [RT-Thread API参考手册](https://www.rt-thread.org/document/api/ )
[基于STM32L475 IoT Board 开发板SDK](https://github.com/RT-Thread/IoT_Board) | [基于W601 IoT Board 开发板SDK](https://github.com/RT-Thread/W601_IoT_Board)
[基于STM32L475 IoT Board 开发板SDK](https://github.com/RT-Thread/IoT_Board) | [基于W601 IoT Board 开发板SDK](https://github.com/RT-Thread/W601_IoT_Board)
## 视频
@ -151,11 +165,11 @@ RT-Thread系统完全开源3.1.0 及以前的版本遵循 GPL V2 + 开源许
RT-Thread非常感谢所有社区小伙伴的支持在使用RT-Thread的过程中若您有任何的想法建议或疑问都可通过以下方式联系到 RT-Thread我们也实时在这些频道更新RT-Thread的最新讯息。同时任何问题都可以在 [issue section](https://github.com/RT-Thread/rtthread-manual-doc/issues) 中提出。通过创建一个issue来描述您的问题社区成员将回答这些问题。
[官网]( https://www.rt-thread.org) | [论坛]( https://www.rt-thread.org/qa/forum.php) | [哔哩哔哩官方账号](https://space.bilibili.com/423462075?spm_id_from=333.788.b_765f7570696e666f.2) | [微博官方账号](https://weibo.com/rtthread?is_hot=1) | [知乎官方账号](https://www.zhihu.com/topic/19964581/hot)
[官网]( https://www.rt-thread.org) | [论坛]( https://www.rt-thread.org/qa/forum.php) | [哔哩哔哩官方账号](https://space.bilibili.com/423462075?spm_id_from=333.788.b_765f7570696e666f.2) | [微博官方账号](https://weibo.com/rtthread?is_hot=1) | [知乎官方账号](https://www.zhihu.com/topic/19964581/hot)
RT-Thread微信公众号
![qrcode](./documentation/figures/qrcode.jpg)
![qrcode](./documentation/figures/qrcode.png)
# 贡献代码

View File

@ -19,10 +19,6 @@ config RT_USING_USER_MAIN
default 85 if RT_THREAD_PRIORITY_256
endif
config RT_USING_LEGACY
bool "Support legacy version for compatibility"
default n
source "$RTT_DIR/components/cplusplus/Kconfig"
source "$RTT_DIR/components/finsh/Kconfig"

View File

@ -9,8 +9,8 @@ if RT_USING_CPLUSPLUS
config RT_USING_CPLUSPLUS11
bool "Enable c++11 threading feature support"
default n
select RT_USING_POSIX_FS
select RT_USING_POSIX_STDIO
select RT_USING_LIBC
select RT_USING_DFS
select RT_USING_PTHREADS
select RT_USING_RTC

View File

@ -11,6 +11,8 @@ Because RT-Thread RTOS is used in embedded system mostly, there are some rules f
4. Static class variables are discouraged. The time and place to call their constructor function could not be precisely controlled and make multi-threaded programming a nightmare.
5. Multiple inheritance is strongly discouraged, as it can cause intolerable confusion.
*NOTE*: The libc (RT_USING_LIBC in rtconfig.h) must be enable.
About GNU GCC compiler
please add following string in your ld link script:

View File

@ -13,18 +13,19 @@
#include <cstdio>
#include <pthread.h>
#define CPP11_DEFAULT_ID_OFFSET 1
extern "C" int __ARM_TPL_thread_create(__ARM_TPL_thread_t *__t,
void *(*__func)(void *),
void *__arg)
{
int ret = 0;
pthread_t pid;
ret = pthread_create(&pid, RT_NULL, __func, __arg);
/* TODO memory leek */
pthread_t *pid = (pthread_t *)rt_malloc(sizeof(pthread_t));
if (pid == nullptr)
return -1;
ret = pthread_create(pid, RT_NULL, __func, __arg);
if (ret == 0)
{
__t->data = (std::uintptr_t)pid + CPP11_DEFAULT_ID_OFFSET;
__t->data = (std::uintptr_t)pid;
return 0;
}
return -1;
@ -49,18 +50,18 @@ extern "C" __ARM_TPL_thread_id __ARM_TPL_thread_get_current_id()
extern "C" __ARM_TPL_thread_id __ARM_TPL_thread_get_id(
const __ARM_TPL_thread_t *__t)
{
return (__ARM_TPL_thread_id)(((pthread_t)__t->data - CPP11_DEFAULT_ID_OFFSET));
return (__ARM_TPL_thread_id)((*(pthread_t *)__t->data));
}
extern "C" int __ARM_TPL_thread_join(__ARM_TPL_thread_t *__t)
{
pthread_join(((pthread_t)__t->data - CPP11_DEFAULT_ID_OFFSET), RT_NULL);
pthread_join((*(pthread_t *)__t->data), RT_NULL);
return 0;
}
extern "C" int __ARM_TPL_thread_detach(__ARM_TPL_thread_t *__t)
{
pthread_detach(((pthread_t)__t->data - CPP11_DEFAULT_ID_OFFSET));
pthread_detach((*(pthread_t *)__t->data));
return 0;
}
@ -95,8 +96,8 @@ extern "C" unsigned __ARM_TPL_thread_hw_concurrency()
extern "C" int __ARM_TPL_tls_create(__ARM_TPL_tls_key *__key,
void (*__at_exit)(void *))
{
pthread_key_t key;
pthread_key_t key;
if (pthread_key_create(&key, __at_exit) == 0)
{
*__key = key;

View File

@ -4,7 +4,7 @@
#error "C++ version lower than C++11"
#endif
//#if defined(RT_USING_PTHREADS)
//#if defined(RT_USING_LIBC) && defined(RT_USING_PTHREADS)
#include <pthread.h>
@ -509,4 +509,4 @@ namespace std
}
}
//#endif //(RT_USING_PTHREADS)
//#endif // (RT_USING_LIBC) && (RT_USING_PTHREADS)

View File

@ -34,7 +34,7 @@ namespace std
get_once_functor_lock_ptr() = m_ptr;
}
extern "C"
extern "C"
{
void once_proxy()
{
@ -42,7 +42,7 @@ namespace std
function<void()> once_call = std::move(once_functor);
// no need to hold the lock anymore
unique_lock<mutex>* lock_ptr = get_once_functor_lock_ptr();
unique_lock<mutex>* lock_ptr = get_once_functor_lock_ptr();
get_once_functor_lock_ptr() = nullptr;
lock_ptr->unlock();

View File

@ -4,7 +4,7 @@
#error "C++ version lower than C++11"
#endif
//#if defined(RT_USING_PTHREADS)
//#if defined(RT_USING_LIBC) && defined(RT_USING_PTHREADS)
#include <unistd.h>
#include <pthread.h>

View File

@ -35,17 +35,17 @@ namespace std
{
auto raw_ptr = b.get();
// transfer the ownership of the invoker to the new thread
raw_ptr->this_ptr = std::move(b);
raw_ptr->this_ptr = std::move(b);
int err = pthread_create(&_m_thr.__cpp_thread_t, NULL,
&execute_native_thread_routine, raw_ptr);
if (err)
if (err)
{
raw_ptr->this_ptr.reset();
throw_system_error(err, "Failed to create a thread");
}
}
}
thread::~thread()
{
@ -59,12 +59,12 @@ namespace std
if (joinable())
err = pthread_join(native_handle(), NULL);
if (err)
if (err)
{
throw_system_error(err, "thread::join failed");
}
_m_thr = id();
}
@ -78,14 +78,14 @@ namespace std
{
throw_system_error(err, "thread::detach failed");
}
_m_thr = id();
}
// TODO: not yet actually implemented.
// The standard states that the returned value should only be considered a hint.
unsigned thread::hardware_concurrency() noexcept
{
unsigned thread::hardware_concurrency() noexcept
{
int __n = _RT_NPROCS;
if (__n < 0)
__n = 0;

View File

@ -13,7 +13,7 @@ using namespace rtthread;
Mutex::Mutex(const char *name)
{
rt_mutex_init(&mID, name, RT_IPC_FLAG_PRIO);
rt_mutex_init(&mID, name, RT_IPC_FLAG_FIFO);
}
bool Mutex::lock(int32_t millisec)

View File

@ -13,7 +13,7 @@
#include <rtthread.h>
#if defined(__ARMCC_VERSION)
#if defined(__CC_ARM) || defined(__CLANG_ARM)
extern void $Super$$__cpp_initialize__aeabi_(void);
/* we need to change the cpp_initialize order */
RT_WEAK void $Sub$$__cpp_initialize__aeabi_(void)
@ -36,7 +36,7 @@ RT_WEAK void *__dso_handle = 0;
RT_WEAK int cplusplus_system_init(void)
{
#if defined(__ARMCC_VERSION)
#if defined(__CC_ARM) || defined(__CLANG_ARM)
/* If there is no SHT$$INIT_ARRAY, calling
* $Super$$__cpp_initialize__aeabi_() will cause fault. At least until Keil5.12
* the problem still exists. So we have to initialize the C++ runtime by ourself.

View File

@ -8,10 +8,6 @@ config RT_USING_DFS
The device file system is a light weight virtual file system.
if RT_USING_DFS
config DFS_USING_POSIX
bool "Using posix-like functions, open/read/write/close"
default y
config DFS_USING_WORKDIR
bool "Using working directory"
default y
@ -137,7 +133,7 @@ if RT_USING_DFS
config RT_USING_DFS_DEVFS
bool "Using devfs for device objects"
default n
default y
config RT_USING_DFS_ROMFS
bool "Enable ReadOnly file system on flash"

View File

@ -1,17 +1,17 @@
from building import *
import os
# The set of source files associated with this SConscript file.
src = Split('''
src/dfs.c
src/dfs_file.c
src/dfs_fs.c
src/dfs_posix.c
''')
cwd = GetCurrentDir()
CPPPATH = [cwd + "/include"]
if GetDepend('DFS_USING_POSIX'):
src += ['src/dfs_posix.c']
if GetDepend('RT_USING_POSIX'):
src += ['src/dfs_poll.c', 'src/dfs_select.c']
group = DefineGroup('Filesystem', src, depend = ['RT_USING_DFS'], CPPPATH = CPPPATH)

View File

@ -0,0 +1,4 @@
# files format check exclude path, please follow the instructions below to modify;
dir_path:
- elmfat

View File

@ -173,7 +173,7 @@ int dfs_device_fs_open(struct dfs_fd *file)
if (device == RT_NULL)
return -ENODEV;
#ifdef RT_USING_POSIX_DEVIO
#ifdef RT_USING_POSIX
if (device->fops)
{
/* use device fops */
@ -192,7 +192,7 @@ int dfs_device_fs_open(struct dfs_fd *file)
}
}
else
#endif /* RT_USING_POSIX_DEVIO */
#endif
{
result = rt_device_open(device, RT_DEVICE_OFLAG_RDWR);
if (result == RT_EOK || result == -RT_ENOSYS)

View File

@ -338,22 +338,3 @@ R0.14 (October 14, 2019)
Fixed f_readdir() function returns file names with wrong case conversion. (appeared at R0.12)
Fixed f_mkfs() function can fail to create exFAT volume in the second partition. (appeared at R0.12)
R0.14a (December 5, 2020)
Limited number of recursive calls in f_findnext().
Fixed old floppy disks formatted with MS-DOS 2.x and 3.x cannot be mounted.
Fixed some compiler warnings.
R0.14b (April 17, 2021)
Made FatFs uses standard library <string.h> for copy, compare and search instead of built-in string functions.
Added support for long long integer and floating point to f_printf(). (FF_STRF_LLI and FF_STRF_FP)
Made path name parser ignore the terminating separator to allow "dir/".
Improved the compatibility in Unix style path name feature.
Fixed the file gets dead-locked when f_open() failed with some conditions. (appeared at R0.12a)
Fixed f_mkfs() can create wrong exFAT volume due to a timing dependent error. (appeared at R0.12)
Fixed code page 855 cannot be set by f_setcp().
Fixed some compiler warnings.

View File

@ -1,4 +1,4 @@
FatFs Module Source Files R0.14b
FatFs Module Source Files R0.14
FILES

View File

@ -945,6 +945,7 @@ DWORD get_fattime(void)
{
DWORD fat_time = 0;
#if defined(RT_LIBC_USING_TIME) || defined(RT_USING_LIBC)
time_t now;
struct tm *p_tm;
struct tm tm_now;
@ -967,6 +968,7 @@ DWORD get_fattime(void)
(DWORD)tm_now.tm_hour << 11 |
(DWORD)tm_now.tm_min << 5 |
(DWORD)tm_now.tm_sec / 2 ;
#endif /* defined(RT_LIBC_USING_TIME) || defined(RT_USING_LIBC) */
return fat_time;
}
@ -978,7 +980,7 @@ int ff_cre_syncobj(BYTE drv, FF_SYNC_t *m)
rt_mutex_t mutex;
rt_snprintf(name, sizeof(name), "fat%d", drv);
mutex = rt_mutex_create(name, RT_IPC_FLAG_PRIO);
mutex = rt_mutex_create(name, RT_IPC_FLAG_FIFO);
if (mutex != RT_NULL)
{
*m = mutex;

View File

@ -10,15 +10,15 @@ extern "C" {
#endif
/* Status of Disk Functions */
typedef BYTE DSTATUS;
typedef BYTE DSTATUS;
/* Results of Disk Functions */
typedef enum {
RES_OK = 0, /* 0: Successful */
RES_ERROR, /* 1: R/W Error */
RES_WRPRT, /* 2: Write Protected */
RES_NOTRDY, /* 3: Not Ready */
RES_PARERR /* 4: Invalid Parameter */
RES_OK = 0, /* 0: Successful */
RES_ERROR, /* 1: R/W Error */
RES_WRPRT, /* 2: Write Protected */
RES_NOTRDY, /* 3: Not Ready */
RES_PARERR /* 4: Invalid Parameter */
} DRESULT;
@ -35,40 +35,40 @@ DRESULT disk_ioctl (BYTE pdrv, BYTE cmd, void* buff);
/* Disk Status Bits (DSTATUS) */
#define STA_NOINIT 0x01 /* Drive not initialized */
#define STA_NODISK 0x02 /* No medium in the drive */
#define STA_PROTECT 0x04 /* Write protected */
#define STA_NOINIT 0x01 /* Drive not initialized */
#define STA_NODISK 0x02 /* No medium in the drive */
#define STA_PROTECT 0x04 /* Write protected */
/* Command code for disk_ioctrl fucntion */
/* Generic command (Used by FatFs) */
#define CTRL_SYNC 0 /* Complete pending write process (needed at FF_FS_READONLY == 0) */
#define GET_SECTOR_COUNT 1 /* Get media size (needed at FF_USE_MKFS == 1) */
#define GET_SECTOR_SIZE 2 /* Get sector size (needed at FF_MAX_SS != FF_MIN_SS) */
#define GET_BLOCK_SIZE 3 /* Get erase block size (needed at FF_USE_MKFS == 1) */
#define CTRL_TRIM 4 /* Inform device that the data on the block of sectors is no longer used (needed at FF_USE_TRIM == 1) */
#define CTRL_SYNC 0 /* Complete pending write process (needed at FF_FS_READONLY == 0) */
#define GET_SECTOR_COUNT 1 /* Get media size (needed at FF_USE_MKFS == 1) */
#define GET_SECTOR_SIZE 2 /* Get sector size (needed at FF_MAX_SS != FF_MIN_SS) */
#define GET_BLOCK_SIZE 3 /* Get erase block size (needed at FF_USE_MKFS == 1) */
#define CTRL_TRIM 4 /* Inform device that the data on the block of sectors is no longer used (needed at FF_USE_TRIM == 1) */
/* Generic command (Not used by FatFs) */
#define CTRL_POWER 5 /* Get/Set power status */
#define CTRL_LOCK 6 /* Lock/Unlock media removal */
#define CTRL_EJECT 7 /* Eject media */
#define CTRL_FORMAT 8 /* Create physical format on the media */
#define CTRL_POWER 5 /* Get/Set power status */
#define CTRL_LOCK 6 /* Lock/Unlock media removal */
#define CTRL_EJECT 7 /* Eject media */
#define CTRL_FORMAT 8 /* Create physical format on the media */
/* MMC/SDC specific ioctl command */
#define MMC_GET_TYPE 10 /* Get card type */
#define MMC_GET_CSD 11 /* Get CSD */
#define MMC_GET_CID 12 /* Get CID */
#define MMC_GET_OCR 13 /* Get OCR */
#define MMC_GET_SDSTAT 14 /* Get SD status */
#define ISDIO_READ 55 /* Read data form SD iSDIO register */
#define ISDIO_WRITE 56 /* Write data to SD iSDIO register */
#define ISDIO_MRITE 57 /* Masked write data to SD iSDIO register */
#define MMC_GET_TYPE 10 /* Get card type */
#define MMC_GET_CSD 11 /* Get CSD */
#define MMC_GET_CID 12 /* Get CID */
#define MMC_GET_OCR 13 /* Get OCR */
#define MMC_GET_SDSTAT 14 /* Get SD status */
#define ISDIO_READ 55 /* Read data form SD iSDIO register */
#define ISDIO_WRITE 56 /* Write data to SD iSDIO register */
#define ISDIO_MRITE 57 /* Masked write data to SD iSDIO register */
/* ATA/CF specific ioctl command */
#define ATA_GET_REV 20 /* Get F/W revision */
#define ATA_GET_MODEL 21 /* Get model name */
#define ATA_GET_SN 22 /* Get serial number */
#define ATA_GET_REV 20 /* Get F/W revision */
#define ATA_GET_MODEL 21 /* Get model name */
#define ATA_GET_SN 22 /* Get serial number */
#ifdef __cplusplus
}

File diff suppressed because it is too large Load Diff

View File

@ -1,8 +1,8 @@
/*----------------------------------------------------------------------------/
/ FatFs - Generic FAT Filesystem module R0.14b /
/ FatFs - Generic FAT Filesystem module R0.14 /
/-----------------------------------------------------------------------------/
/
/ Copyright (C) 2021, ChaN, all right reserved.
/ Copyright (C) 2019, ChaN, all right reserved.
/
/ FatFs module is an open source software. Redistribution and use of FatFs in
/ source and binary forms, with or without modification, are permitted provided
@ -20,7 +20,7 @@
#ifndef FF_DEFINED
#define FF_DEFINED 86631 /* Revision ID */
#define FF_DEFINED 86606 /* Revision ID */
#ifdef __cplusplus
extern "C" {
@ -36,14 +36,10 @@ extern "C" {
/* Integer types used for FatFs API */
#if defined(_WIN32) /* Windows VC++ (for development only) */
#if defined(_WIN32) /* Main development platform */
#define FF_INTDEF 2
#include <windows.h>
typedef unsigned __int64 QWORD;
#include <float.h>
#define isnan(v) _isnan(v)
#define isinf(v) (!_finite(v))
#elif (defined(__STDC_VERSION__) && __STDC_VERSION__ >= 199901L) || defined(__cplusplus) /* C99 or later */
#define FF_INTDEF 2
#include <stdint.h>
@ -53,7 +49,6 @@ typedef uint16_t WORD; /* 16-bit unsigned integer */
typedef uint32_t DWORD; /* 32-bit unsigned integer */
typedef uint64_t QWORD; /* 64-bit unsigned integer */
typedef WORD WCHAR; /* UTF-16 character type */
#else /* Earlier than C99 */
#define FF_INTDEF 1
typedef unsigned int UINT; /* int must be 16-bit or 32-bit */
@ -64,29 +59,28 @@ typedef WORD WCHAR; /* UTF-16 character type */
#endif
/* Type of file size and LBA variables */
/* Definitions of volume management */
#if FF_FS_EXFAT
#if FF_INTDEF != 2
#error exFAT feature wants C99 or later
#if FF_MULTI_PARTITION /* Multiple partition configuration */
typedef struct {
BYTE pd; /* Physical drive number */
BYTE pt; /* Partition: 0:Auto detect, 1-4:Forced partition) */
} PARTITION;
extern PARTITION VolToPart[]; /* Volume - Partition mapping table */
#endif
typedef QWORD FSIZE_t;
#if FF_LBA64
typedef QWORD LBA_t;
#else
typedef DWORD LBA_t;
#if FF_STR_VOLUME_ID
#ifndef FF_VOLUME_STRS
extern const char* VolumeStr[FF_VOLUMES]; /* User defied volume ID */
#endif
#else
#if FF_LBA64
#error exFAT needs to be enabled when enable 64-bit LBA
#endif
typedef DWORD FSIZE_t;
typedef DWORD LBA_t;
#endif
/* Type of path name strings on FatFs API (TCHAR) */
/* Type of path name strings on FatFs API */
#ifndef _INC_TCHAR
#define _INC_TCHAR
#if FF_USE_LFN && FF_LFN_UNICODE == 1 /* Unicode in UTF-16 encoding */
typedef WCHAR TCHAR;
@ -108,22 +102,28 @@ typedef char TCHAR;
#define _TEXT(x) x
#endif
/* Definitions of volume management */
#if FF_MULTI_PARTITION /* Multiple partition configuration */
typedef struct {
BYTE pd; /* Physical drive number */
BYTE pt; /* Partition: 0:Auto detect, 1-4:Forced partition) */
} PARTITION;
extern PARTITION VolToPart[]; /* Volume - Partition mapping table */
#endif
#if FF_STR_VOLUME_ID
#ifndef FF_VOLUME_STRS
extern const char* VolumeStr[FF_VOLUMES]; /* User defied volume ID */
/* Type of file size and LBA variables */
#if FF_FS_EXFAT
#if FF_INTDEF != 2
#error exFAT feature wants C99 or later
#endif
typedef QWORD FSIZE_t;
#if FF_LBA64
typedef QWORD LBA_t;
#else
typedef DWORD LBA_t;
#endif
#else
#if FF_LBA64
#error exFAT needs to be enabled when enable 64-bit LBA
#endif
typedef DWORD FSIZE_t;
typedef DWORD LBA_t;
#endif
@ -347,6 +347,10 @@ TCHAR* f_gets (TCHAR* buff, int len, FIL* fp); /* Get a string from the fil
#define f_rmdir(path) f_unlink(path)
#define f_unmount(path) f_mount(0, path, 0)
#ifndef EOF
#define EOF (-1)
#endif

View File

@ -2,7 +2,7 @@
/ FatFs Functional Configurations
/---------------------------------------------------------------------------*/
#define FFCONF_DEF 86631 /* Revision ID */
#define FFCONF_DEF 86606 /* Revision ID */
/*---------------------------------------------------------------------------/
/ Function Configurations
@ -25,6 +25,14 @@
/ 3: f_lseek() function is removed in addition to 2. */
#define FF_USE_STRFUNC 0
/* This option switches string functions, f_gets(), f_putc(), f_puts() and f_printf().
/
/ 0: Disable string functions.
/ 1: Enable without LF-CRLF conversion.
/ 2: Enable with LF-CRLF conversion. */
#define FF_USE_FIND 0
/* This option switches filtered directory read functions, f_findfirst() and
/ f_findnext(). (0:Disable, 1:Enable 2:Enable with matching altname[] too) */
@ -56,30 +64,6 @@
/* This option switches f_forward() function. (0:Disable or 1:Enable) */
#define FF_USE_STRFUNC 0
#define FF_PRINT_LLI 0
#define FF_PRINT_FLOAT 0
#define FF_STRF_ENCODE 3
/* FF_USE_STRFUNC switches string functions, f_gets(), f_putc(), f_puts() and
/ f_printf().
/
/ 0: Disable. FF_PRINT_LLI, FF_PRINT_FLOAT and FF_STRF_ENCODE have no effect.
/ 1: Enable without LF-CRLF conversion.
/ 2: Enable with LF-CRLF conversion.
/
/ FF_PRINT_LLI = 1 makes f_printf() support long long argument and FF_PRINT_FLOAT = 1/2
makes f_printf() support floating point argument. These features want C99 or later.
/ When FF_LFN_UNICODE >= 1 with LFN enabled, string functions convert the character
/ encoding in it. FF_STRF_ENCODE selects assumption of character encoding ON THE FILE
/ to be read/written via those functions.
/
/ 0: ANSI/OEM in current CP
/ 1: Unicode in UTF-16LE
/ 2: Unicode in UTF-16BE
/ 3: Unicode in UTF-8
*/
/*---------------------------------------------------------------------------/
/ Locale and Namespace Configurations
/---------------------------------------------------------------------------*/
@ -121,8 +105,8 @@
#define FF_USE_LFN RT_DFS_ELM_USE_LFN
#define FF_MAX_LFN RT_DFS_ELM_MAX_LFN
#else
#define FF_USE_LFN 0 /* 0 to 3 */
#define FF_MAX_LFN 255 /* Maximum LFN length to handle (12 to 255) */
#define FF_USE_LFN 0 /* 0 to 3 */
#define FF_MAX_LFN 255 /* Maximum LFN length to handle (12 to 255) */
#endif
/* The FF_USE_LFN switches the support for LFN (long file name).
/
@ -156,16 +140,6 @@
#else
#define FF_LFN_UNICODE 0 /* 0:ANSI/OEM or 1:Unicode */
#endif
/* This option switches the character encoding on the API when LFN is enabled.
/
/ 0: ANSI/OEM in current CP (TCHAR = char)
/ 1: Unicode in UTF-16 (TCHAR = WCHAR)
/ 2: Unicode in UTF-8 (TCHAR = char)
/ 3: Unicode in UTF-32 (TCHAR = DWORD)
/
/ Also behavior of string I/O functions will be affected by this option.
/ When LFN is not enabled, this option has no effect. */
#define FF_LFN_BUF 255
#define FF_SFN_BUF 12
@ -175,6 +149,19 @@
/ on character encoding. When LFN is not enabled, these options have no effect. */
#define FF_STRF_ENCODE 3
/* When FF_LFN_UNICODE >= 1 with LFN enabled, string I/O functions, f_gets(),
/ f_putc(), f_puts and f_printf() convert the character encoding in it.
/ This option selects assumption of character encoding ON THE FILE to be
/ read/written via those functions.
/
/ 0: ANSI/OEM in current CP
/ 1: Unicode in UTF-16LE
/ 2: Unicode in UTF-16BE
/ 3: Unicode in UTF-8
*/
#define FF_FS_RPATH 0
/* This option configures support for relative path.
/
@ -219,7 +206,7 @@
/ funciton will be available. */
#define FF_MIN_SS 512
#define FF_MIN_SS 512
#ifdef RT_DFS_ELM_MAX_SECTOR_SIZE
#define FF_MAX_SS RT_DFS_ELM_MAX_SECTOR_SIZE
#else
@ -227,7 +214,7 @@
#endif
/* This set of options configures the range of sector size to be supported. (512,
/ 1024, 2048 or 4096) Always set both 512 for most systems, generic memory card and
/ harddisk, but a larger value may be required for on-board flash memory and some
/ harddisk. But a larger value may be required for on-board flash memory and some
/ type of optical media. When FF_MAX_SS is larger than FF_MIN_SS, FatFs is configured
/ for variable sector size mode and disk_ioctl() function needs to implement
/ GET_SECTOR_SIZE command. */
@ -238,8 +225,8 @@
/ To enable the 64-bit LBA, also exFAT needs to be enabled. (FF_FS_EXFAT == 1) */
#define FF_MIN_GPT 0x10000000
/* Minimum number of sectors to switch GPT as partitioning format in f_mkfs and
#define FF_MIN_GPT 0x100000000
/* Minimum number of sectors to switch GPT format to create partition in f_mkfs and
/ f_fdisk function. 0x100000000 max. This option has no effect when FF_LBA64 == 0. */
@ -273,7 +260,7 @@
#define FF_FS_NORTC 0
#define FF_NORTC_MON 1
#define FF_NORTC_MDAY 1
#define FF_NORTC_YEAR 2020
#define FF_NORTC_YEAR 2019
/* The option FF_FS_NORTC switches timestamp functiton. If the system does not have
/ any RTC function or valid timestamp is not needed, set FF_FS_NORTC = 1 to disable
/ the timestamp function. Every object modified by FatFs will have a fixed timestamp
@ -307,7 +294,6 @@
/ can be opened simultaneously under file lock control. Note that the file
/ lock control is independent of re-entrancy. */
/* #include <somertos.h> // O/S definitions */
#include <rtdef.h>
#ifdef RT_DFS_ELM_REENTRANT

View File

@ -81,18 +81,16 @@ int dfs_init(void);
char *dfs_normalize_path(const char *directory, const char *filename);
const char *dfs_subdir(const char *directory, const char *filename);
int fd_is_open(const char *pathname);
struct dfs_fdtable *dfs_fdtable_get(void);
void dfs_lock(void);
void dfs_unlock(void);
#ifdef DFS_USING_POSIX
/* FD APIs */
int fd_new(void);
struct dfs_fd *fd_get(int fd);
void fd_put(struct dfs_fd *fd);
#endif /* DFS_USING_POSIX */
int fd_is_open(const char *pathname);
struct dfs_fdtable *dfs_fdtable_get(void);
#ifdef __cplusplus
}

View File

@ -12,9 +12,10 @@
#define __DFS_FS_H__
#include <dfs.h>
#ifdef RT_USING_LIBC
#include <sys/types.h>
#endif
#include <sys/errno.h>
#ifdef __cplusplus
extern "C" {
#endif

View File

@ -5,7 +5,6 @@
*
* Change Logs:
* Date Author Notes
* 2021-11-14 Meco Man the first version
*/
#ifndef DFS_POLL_H__

View File

@ -5,7 +5,6 @@
*
* Change Logs:
* Date Author Notes
* 2021-11-14 Meco Man the first version
*/
#ifndef DFS_SELECT_H__
@ -13,4 +12,4 @@
#include <sys/select.h>
#endif /* DFS_SELECT_H__ */
#endif

View File

@ -18,9 +18,9 @@
#include <lwp.h>
#endif
#ifdef RT_USING_POSIX_STDIO
#if defined(RT_USING_DFS_DEVFS) && defined(RT_USING_POSIX)
#include <libc.h>
#endif /* RT_USING_POSIX_STDIO */
#endif
/* Global variables */
const struct dfs_filesystem_ops *filesystem_operation_table[DFS_FILESYSTEM_TYPES_MAX];
@ -34,6 +34,7 @@ char working_directory[DFS_PATH_MAX] = {"/"};
#endif
static struct dfs_fdtable _fdtab;
static int fd_alloc(struct dfs_fdtable *fdt, int startfd);
/**
* @addtogroup DFS
@ -62,7 +63,7 @@ int dfs_init(void)
memset(&_fdtab, 0, sizeof(_fdtab));
/* create device filesystem lock */
rt_mutex_init(&fslock, "fslock", RT_IPC_FLAG_PRIO);
rt_mutex_init(&fslock, "fslock", RT_IPC_FLAG_FIFO);
#ifdef DFS_USING_WORKDIR
/* set current working directory */
@ -117,7 +118,6 @@ void dfs_unlock(void)
rt_mutex_release(&fslock);
}
#ifdef DFS_USING_POSIX
static int fd_alloc(struct dfs_fdtable *fdt, int startfd)
{
int idx;
@ -216,10 +216,10 @@ struct dfs_fd *fd_get(int fd)
struct dfs_fd *d;
struct dfs_fdtable *fdt;
#ifdef RT_USING_POSIX_STDIO
#if defined(RT_USING_DFS_DEVFS) && defined(RT_USING_POSIX)
if ((0 <= fd) && (fd <= 2))
fd = libc_stdio_get_console();
#endif /* RT_USING_POSIX_STDIO */
#endif
fdt = dfs_fdtable_get();
fd = fd - DFS_FD_OFFSET;
@ -276,8 +276,6 @@ void fd_put(struct dfs_fd *fd)
dfs_unlock();
}
#endif /* DFS_USING_POSIX */
/**
* @ingroup Fd
*

View File

@ -621,7 +621,6 @@ void cat(const char *filename)
}
FINSH_FUNCTION_EXPORT(cat, print file);
#ifdef DFS_USING_POSIX
#define BUF_SZ 4096
static void copyfile(const char *src, const char *dst)
{
@ -750,7 +749,6 @@ static const char *_get_path_lastname(const char *path)
/* skip the '/' then return */
return ++ptr;
}
void copy(const char *src, const char *dst)
{
#define FLAG_SRC_TYPE 0x03
@ -843,8 +841,7 @@ void copy(const char *src, const char *dst)
}
}
FINSH_FUNCTION_EXPORT(copy, copy file or dir)
#endif /* DFS_USING_POSIX */
#endif /* RT_USING_FINSH */
#endif
/* @} */

View File

@ -9,10 +9,17 @@
* 2018-03-09 Bernard Add protection for pt->triggered.
*/
#include <stdint.h>
#include <rthw.h>
#include <rtdevice.h>
#include <rtthread.h>
#include <dfs.h>
#include <dfs_file.h>
#include "poll.h"
#include <dfs_posix.h>
#include <poll.h>
#ifdef RT_USING_POSIX
struct rt_poll_node;
@ -224,3 +231,5 @@ int poll(struct pollfd *fds, nfds_t nfds, int timeout)
return num;
}
#endif

View File

@ -9,9 +9,15 @@
* 2018-02-07 Bernard Change the 3rd parameter of open/fcntl/ioctl to '...'
*/
#include <dfs_file.h>
#include <dfs_private.h>
#include <sys/errno.h>
#include <dfs.h>
#include <dfs_posix.h>
#include "dfs_private.h"
/**
* @addtogroup FsPosixApi
*/
/*@{*/
/**
* this function is a POSIX compliant version, which will open a file and
@ -248,7 +254,7 @@ off_t lseek(int fd, off_t offset, int whence)
}
RTM_EXPORT(lseek);
#ifndef _WIN32
#ifndef _WIN32 /* we can not implement these functions */
/**
* this function is a POSIX compliant version, which will rename old file name
* to new file name.
@ -579,6 +585,11 @@ int mkdir(const char *path, mode_t mode)
}
RTM_EXPORT(mkdir);
#ifdef RT_USING_FINSH
#include <finsh.h>
FINSH_FUNCTION_EXPORT(mkdir, create a directory);
#endif
/**
* this function is a POSIX compliant version, which will remove a directory.
*
@ -935,3 +946,5 @@ char *getcwd(char *buf, size_t size)
return buf;
}
RTM_EXPORT(getcwd);
/* @} */

View File

@ -7,10 +7,15 @@
* Date Author Notes
* 2016-12-28 Bernard first version
*/
#include <rtthread.h>
#include <dfs.h>
#include <dfs_fs.h>
#include <dfs_posix.h>
#include <poll.h>
#include <sys/select.h>
#ifdef RT_USING_POSIX
static void fdszero(fd_set *set, int nfds)
{
fd_mask *m;
@ -174,3 +179,5 @@ int select(int nfds, fd_set *readfds, fd_set *writefds, fd_set *exceptfds, struc
return ret;
}
#endif

View File

@ -5,6 +5,10 @@ config RT_USING_DEVICE_IPC
default y
if RT_USING_DEVICE_IPC
config RT_PIPE_BUFSZ
int "Set pipe buffer size"
default 512
config RT_USING_SYSTEM_WORKQUEUE
bool "Using system default workqueue"
default n
@ -14,7 +18,7 @@ if RT_USING_DEVICE_IPC
int "The stack size for system workqueue thread"
default 2048
config RT_SYSTEM_WORKQUEUE_PRIORITY
config RT_SYSTEM_WORKQUEUE_PRIORITY
int "The priority level of system workqueue thread"
default 23
endif
@ -145,42 +149,6 @@ config RT_USING_PM
bool "Using Power Management device drivers"
default n
if RT_USING_PM
config PM_TICKLESS_THRESHOLD_TIME
int "PM tickless threashold time"
default 2
config PM_USING_CUSTOM_CONFIG
bool "PM using custom pm config"
default n
config PM_ENABLE_DEBUG
bool "PM Enable Debug"
default n
config PM_ENABLE_SUSPEND_SLEEP_MODE
bool "PM Device suspend change sleep mode"
default n
config PM_ENABLE_THRESHOLD_SLEEP_MODE
bool "PM using threshold time change sleep mode"
default n
if PM_ENABLE_THRESHOLD_SLEEP_MODE
config PM_LIGHT_THRESHOLD_TIME
int "PM light mode threashold time"
default 5
config PM_DEEP_THRESHOLD_TIME
int "PM deep mode threashold time"
default 20
config PM_STANDBY_THRESHOLD_TIME
int "PM standby mode threashold time"
default 100
endif
endif
config RT_USING_RTC
bool "Using RTC device drivers"
default n
@ -655,14 +623,9 @@ menuconfig RT_USING_WIFI
endif
menu "Using USB"
config RT_USING_USB
bool
default n
config RT_USING_USB_HOST
bool "Using USB host"
default n
select RT_USING_USB
if RT_USING_USB_HOST
config RT_USBH_MSTORAGE
@ -685,8 +648,6 @@ menu "Using USB"
config RT_USING_USB_DEVICE
bool "Using USB device"
default n
select RT_USING_USB
if RT_USING_USB_DEVICE || RT_USING_USB_HOST
config RT_USBD_THREAD_STACK_SZ
int "usb thread stack size"

View File

@ -34,7 +34,7 @@ float clock_cpu_getres(void)
*
* @return the cpu tick
*/
uint64_t clock_cpu_gettime(void)
uint32_t clock_cpu_gettime(void)
{
if (_cputime_ops)
return _cputime_ops->cputime_gettime();

View File

@ -24,7 +24,7 @@ static float cortexm_cputime_getres(void)
return ret;
}
static uint64_t cortexm_cputime_gettime(void)
static uint32_t cortexm_cputime_gettime(void)
{
return DWT->CYCCNT;
}

View File

@ -24,7 +24,7 @@ rt_err_t rt_i2c_bus_device_register(struct rt_i2c_bus_device *bus,
{
rt_err_t res = RT_EOK;
rt_mutex_init(&bus->lock, "i2c_bus_lock", RT_IPC_FLAG_PRIO);
rt_mutex_init(&bus->lock, "i2c_bus_lock", RT_IPC_FLAG_FIFO);
if (bus->timeout == 0) bus->timeout = RT_TICK_PER_SECOND;

View File

@ -77,6 +77,9 @@ static rt_err_t i2c_bus_device_control(rt_device_t dev,
case RT_I2C_DEV_CTRL_10BIT:
bus->flags |= RT_I2C_ADDR_10BIT;
break;
case RT_I2C_DEV_CTRL_ADDR:
bus->addr = *(rt_uint16_t *)args;
break;
case RT_I2C_DEV_CTRL_TIMEOUT:
bus->timeout = *(rt_uint32_t *)args;
break;

View File

@ -13,8 +13,7 @@
#ifndef __ALARM_H__
#define __ALARM_H__
#include <sys/time.h>
#include <rtdef.h>
#include <time.h>
#define RT_ALARM_TM_NOW -1 /* set the alarm tm_day,tm_mon,tm_sec,etc.
to now.we also call it "don't care" value */

View File

@ -16,11 +16,11 @@
struct rt_clock_cputime_ops
{
float (*cputime_getres) (void);
uint64_t (*cputime_gettime)(void);
uint32_t (*cputime_gettime)(void);
};
float clock_cpu_getres(void);
uint64_t clock_cpu_gettime(void);
uint32_t clock_cpu_gettime(void);
uint32_t clock_cpu_microsecond(uint32_t cpu_tick);
uint32_t clock_cpu_millisecond(uint32_t cpu_tick);

View File

@ -55,6 +55,7 @@ struct rt_i2c_bus_device
struct rt_device parent;
const struct rt_i2c_bus_device_ops *ops;
rt_uint16_t flags;
rt_uint16_t addr;
struct rt_mutex lock;
rt_uint32_t timeout;
rt_uint32_t retries;
@ -63,6 +64,7 @@ struct rt_i2c_bus_device
struct rt_i2c_client
{
struct rt_device parent;
struct rt_i2c_bus_device *bus;
rt_uint16_t client_addr;
};

View File

@ -19,6 +19,7 @@ extern "C" {
#endif
#define RT_I2C_DEV_CTRL_10BIT 0x20
#define RT_I2C_DEV_CTRL_ADDR 0x21
#define RT_I2C_DEV_CTRL_TIMEOUT 0x22
#define RT_I2C_DEV_CTRL_RW 0x23
#define RT_I2C_DEV_CTRL_CLK 0x24

View File

@ -1,38 +0,0 @@
/*
* Copyright (c) 2006-2021, RT-Thread Development Team
*
* SPDX-License-Identifier: Apache-2.0
*
* Change Logs:
* Date Author Notes
* 2021-10-11 zhangsz the first version
*/
#ifndef __LPTIMER_H__
#define __LPTIMER_H__
#include <rtthread.h>
struct rt_lptimer
{
struct rt_timer timer;
rt_list_t list;
};
typedef struct rt_lptimer *rt_lptimer_t;
void rt_lptimer_init(rt_lptimer_t timer,
const char *name,
void (*timeout)(void *parameter),
void *parameter,
rt_tick_t time,
rt_uint8_t flag);
rt_err_t rt_lptimer_detach(rt_lptimer_t timer);
rt_err_t rt_lptimer_start(rt_lptimer_t timer);
rt_err_t rt_lptimer_stop(rt_lptimer_t timer);
rt_err_t rt_lptimer_control(rt_lptimer_t timer, int cmd, void *arg);
rt_tick_t rt_lptimer_next_timeout_tick(void);
#endif

View File

@ -161,7 +161,7 @@ struct rt_mmcsd_card {
struct rt_sdio_cccr cccr; /* common card info */
struct rt_sdio_cis cis; /* common tuple info */
struct rt_sdio_function *sdio_function[SDIO_MAX_FUNCTIONS + 1]; /* SDIO functions (devices) */
rt_list_t blk_devices; /* for block device list */
};
#ifdef __cplusplus

View File

@ -96,8 +96,6 @@ struct rt_mmcsd_host {
rt_uint32_t max_blk_size; /* maximum block size */
rt_uint32_t max_blk_count; /* maximum block count */
rt_uint32_t id; /* Assigned host id */
rt_uint32_t spi_use_crc;
struct rt_mutex bus_lock;
struct rt_semaphore sem_ack;

View File

@ -17,7 +17,8 @@
#include <stdint.h>
#include <rtthread.h>
#include <drivers/lptimer.h>
#ifndef PM_HAS_CUSTOM_CONFIG
/* All modes used for rt_pm_request() and rt_pm_release() */
enum
@ -47,6 +48,10 @@ enum
RT_PM_FREQUENCY_PENDING = 0x01,
};
#define RT_PM_DEFAULT_SLEEP_MODE PM_SLEEP_MODE_NONE
#define RT_PM_DEFAULT_DEEPSLEEP_MODE PM_SLEEP_MODE_DEEP
#define RT_PM_DEFAULT_RUN_MODE PM_RUN_MODE_NORMAL_SPEED
/* The name of all modes used in the msh command "pm_dump" */
#define PM_SLEEP_MODE_NAMES \
{ \
@ -66,7 +71,6 @@ enum
"Low Mode", \
}
#ifndef PM_USING_CUSTOM_CONFIG
/**
* Modules used for
* pm_module_request(PM_BOARD_ID, PM_SLEEP_MODE_IDLE)
@ -94,23 +98,11 @@ enum pm_module_id {
PM_MODULE_MAX_ID, /* enum must! */
};
#else
#else /* PM_HAS_CUSTOM_CONFIG */
#include <pm_cfg.h>
#endif /* PM_USING_CUSTOM_CONFIG */
#ifndef RT_PM_DEFAULT_SLEEP_MODE
#define RT_PM_DEFAULT_SLEEP_MODE PM_SLEEP_MODE_NONE
#endif
#ifndef RT_PM_DEFAULT_DEEPSLEEP_MODE
#define RT_PM_DEFAULT_DEEPSLEEP_MODE PM_SLEEP_MODE_DEEP
#endif
#ifndef RT_PM_DEFAULT_RUN_MODE
#define RT_PM_DEFAULT_RUN_MODE PM_RUN_MODE_NORMAL_SPEED
#endif
#endif /* PM_HAS_CUSTOM_CONFIG */
/**
* device control flag to request or release power
@ -168,9 +160,6 @@ struct rt_pm
/* modules request status*/
struct rt_pm_module module_status[PM_MODULE_MAX_ID];
/* sleep request table */
rt_uint32_t sleep_status[PM_SLEEP_MODE_MAX - 1][(PM_MODULE_MAX_ID + 31) / 32];
/* the list of device, which has PM feature */
rt_uint8_t device_pm_number;
struct rt_device_pm *device_pm;
@ -214,16 +203,5 @@ void rt_pm_module_release_all(uint8_t module_id, rt_uint8_t sleep_mode);
void rt_pm_module_delay_sleep(rt_uint8_t module_id, rt_tick_t timeout);
rt_uint32_t rt_pm_module_get_status(void);
rt_uint8_t rt_pm_get_sleep_mode(void);
struct rt_pm *rt_pm_get_handle(void);
/* sleep : request or release */
void rt_pm_sleep_request(rt_uint16_t module_id, rt_uint8_t mode);
void rt_pm_sleep_release(rt_uint16_t module_id, rt_uint8_t mode);
void rt_pm_sleep_none_request(rt_uint16_t module_id);
void rt_pm_sleep_none_release(rt_uint16_t module_id);
void rt_pm_sleep_idle_request(rt_uint16_t module_id);
void rt_pm_sleep_idle_release(rt_uint16_t module_id);
void rt_pm_sleep_light_request(rt_uint16_t module_id);
void rt_pm_sleep_light_release(rt_uint16_t module_id);
#endif /* __PM_H__ */

View File

@ -50,8 +50,6 @@ extern "C" {
#define RT_SENSOR_CLASS_GNSS (16) /* GPS/GNSS sensor */
#define RT_SENSOR_CLASS_TOF (17) /* TOF sensor */
#define RT_SENSOR_CLASS_SPO2 (18) /* SpO2 sensor */
#define RT_SENSOR_CLASS_IAQ (19) /* IAQ sensor. */
#define RT_SENSOR_CLASS_ETOH (20) /* EtOH sensor. */
/* Sensor vendor types */
@ -92,7 +90,6 @@ extern "C" {
#define RT_SENSOR_UNIT_PPB (15) /* Concentration unit: ppb */
#define RT_SENSOR_UNIT_DMS (16) /* Coordinates unit: DMS */
#define RT_SENSOR_UNIT_DD (17) /* Coordinates unit: DD */
#define RT_SENSOR_UNIT_MGM3 (18) /* Concentration unit: mg/m3 */
/* Sensor communication interface types */
#define RT_SENSOR_INTF_I2C (1 << 0)
@ -221,8 +218,6 @@ struct rt_sensor_data
rt_uint32_t dust; /* Dust sensor. unit: ug/m3 */
rt_uint32_t eco2; /* eCO2 sensor. unit: ppm */
rt_uint32_t spo2; /* SpO2 sensor. unit: permillage */
rt_uint32_t iaq; /* IAQ sensor. unit: 1 */
rt_uint32_t etoh; /* EtOH sensor. unit: ppm */
} data;
};

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2006-2021, RT-Thread Development Team
* Copyright (c) 2006-2018, RT-Thread Development Team
*
* SPDX-License-Identifier: Apache-2.0
*

View File

@ -15,6 +15,12 @@
#include <rtthread.h>
#include <rtdevice.h>
#ifndef RT_PIPE_BUFSZ
#define PIPE_BUFSZ 512
#else
#define PIPE_BUFSZ RT_PIPE_BUFSZ
#endif
struct rt_pipe_device
{
struct rt_device parent;

View File

@ -71,10 +71,6 @@ struct rt_rbb
rt_size_t blk_max_num;
/* saved the initialized and put status blocks */
rt_slist_t blk_list;
/* point to tail node */
rt_slist_t *tail;
/* free node list */
rt_slist_t free_list;
};
typedef struct rt_rbb *rt_rbb_t;

View File

@ -61,7 +61,7 @@ rt_err_t rt_workqueue_submit_work(struct rt_workqueue *queue, struct rt_work *wo
rt_err_t rt_workqueue_cancel_work(struct rt_workqueue *queue, struct rt_work *work);
rt_err_t rt_workqueue_cancel_work_sync(struct rt_workqueue *queue, struct rt_work *work);
rt_err_t rt_workqueue_cancel_all_work(struct rt_workqueue *queue);
rt_err_t rt_workqueue_urgent_work(struct rt_workqueue *queue, struct rt_work *work);
rt_err_t rt_workqueue_critical_work(struct rt_workqueue *queue, struct rt_work *work);
#ifdef RT_USING_SYSTEM_WORKQUEUE
rt_err_t rt_work_submit(struct rt_work *work, rt_tick_t time);

View File

@ -2,7 +2,7 @@ from building import *
cwd = GetCurrentDir()
src = []
depend = ['']
depend = []
CPPPATH = [cwd + '/../include']
group = []

View File

@ -295,11 +295,11 @@ help:
rt_kprintf(" eraseall <name> Erase all block on device <name>\n");
return ;
}
else if (!rt_strcmp(argv[1], "id"))
else if (!strcmp(argv[1], "id"))
{
mtd_nandid(argv[2]);
}
else if (!rt_strcmp(argv[1], "read"))
else if (!strcmp(argv[1], "read"))
{
if (argc < 5)
{
@ -308,7 +308,7 @@ help:
}
mtd_nand_read(argv[2], atoi(argv[3]), atoi(argv[4]));
}
else if (!rt_strcmp(argv[1], "readoob"))
else if (!strcmp(argv[1], "readoob"))
{
if (argc < 5)
{
@ -317,7 +317,7 @@ help:
}
mtd_nand_readoob(argv[2], atoi(argv[3]), atoi(argv[4]));
}
else if (!rt_strcmp(argv[1], "write"))
else if (!strcmp(argv[1], "write"))
{
if (argc < 5)
{
@ -326,7 +326,7 @@ help:
}
mtd_nand_write(argv[2], atoi(argv[3]), atoi(argv[4]));
}
else if (!rt_strcmp(argv[1], "erase"))
else if (!strcmp(argv[1], "erase"))
{
if (argc < 4)
{
@ -335,7 +335,7 @@ help:
}
mtd_nand_erase(argv[2], atoi(argv[3]));
}
else if (!rt_strcmp(argv[1], "eraseall"))
else if (!strcmp(argv[1], "eraseall"))
{
mtd_nand_erase_all(argv[2]);
}

View File

@ -7,7 +7,6 @@ group = []
if GetDepend(['RT_USING_PM']):
src = src + ['pm.c']
src = src + ['lptimer.c']
if len(src):
group = DefineGroup('DeviceDrivers', src, depend = [''], CPPPATH = CPPPATH)

View File

@ -1,176 +0,0 @@
/*
* Copyright (c) 2006-2021, RT-Thread Development Team
*
* SPDX-License-Identifier: Apache-2.0
*
* Change Logs:
* Date Author Notes
* 2021-10-11 zhangsz the first version
*/
#include <rtthread.h>
#include <rthw.h>
#include <drivers/lptimer.h>
static rt_list_t rt_soft_lptimer_list = RT_LIST_OBJECT_INIT(rt_soft_lptimer_list);
/* lptimer init */
void rt_lptimer_init(rt_lptimer_t timer,
const char *name,
void (*timeout)(void *parameter),
void *parameter,
rt_tick_t time,
rt_uint8_t flag)
{
rt_timer_init(&timer->timer, name, timeout, parameter, time, flag);
rt_list_init(&timer->list);
}
/* lptimer detach */
rt_err_t rt_lptimer_detach(rt_lptimer_t timer)
{
rt_base_t level;
rt_err_t ret = RT_EOK;
RT_ASSERT(timer != RT_NULL);
/* disable interrupt */
level = rt_hw_interrupt_disable();
ret = rt_timer_detach(&timer->timer);
rt_list_remove(&timer->list);
/* enable interrupt */
rt_hw_interrupt_enable(level);
return ret;
}
/* lptimer start */
rt_err_t rt_lptimer_start(rt_lptimer_t timer)
{
rt_base_t level;
RT_ASSERT(timer != RT_NULL);
/* disable interrupt */
level = rt_hw_interrupt_disable();
rt_list_remove(&timer->list); /* remove first */
if (rt_timer_start(&timer->timer) == RT_EOK)
{
/* insert to lptimer list */
rt_list_insert_after(&rt_soft_lptimer_list, &(timer->list));
}
else
{
/* enable interrupt */
rt_hw_interrupt_enable(level);
return -RT_ERROR;
}
/* enable interrupt */
rt_hw_interrupt_enable(level);
return RT_EOK;
}
/* lptimer stop */
rt_err_t rt_lptimer_stop(rt_lptimer_t timer)
{
rt_base_t level;
RT_ASSERT(timer != RT_NULL);
/* disable interrupt */
level = rt_hw_interrupt_disable();
rt_list_remove(&timer->list);
if (rt_timer_stop(&timer->timer) == RT_EOK)
{
/* enable interrupt */
rt_hw_interrupt_enable(level);
return RT_EOK;
}
else
{
/* enable interrupt */
rt_hw_interrupt_enable(level);
return -RT_ERROR;
}
}
rt_err_t rt_lptimer_control(rt_lptimer_t timer, int cmd, void *arg)
{
RT_ASSERT(timer != RT_NULL);
return rt_timer_control(&timer->timer, cmd, arg);
}
/* get the next soft lptimer timeout */
rt_tick_t rt_lptimer_next_timeout_tick(void)
{
struct rt_lptimer *timer;
rt_base_t level;
rt_tick_t timeout_tick = RT_TICK_MAX;
struct rt_list_node *node = RT_NULL;
rt_tick_t temp_tick = 0;
rt_tick_t min_tick = RT_TICK_MAX;
rt_tick_t cur_tick = rt_tick_get();
/* disable interrupt */
level = rt_hw_interrupt_disable();
if (!rt_list_isempty(&rt_soft_lptimer_list))
{
/* find the first active timer's timeout */
rt_list_for_each(node, &rt_soft_lptimer_list)
{
timer = rt_list_entry(node, struct rt_lptimer, list);
if (timer->timer.parent.flag & RT_TIMER_FLAG_ACTIVATED)
{
temp_tick = timer->timer.timeout_tick - cur_tick;
/* find the least timeout_tick */
if (min_tick > temp_tick)
{
min_tick = temp_tick;
timeout_tick = timer->timer.timeout_tick;
}
}
}
}
/* enable interrupt */
rt_hw_interrupt_enable(level);
return timeout_tick;
}
void lptimer_dump(void)
{
struct rt_lptimer *timer;
rt_base_t level;
struct rt_list_node *node = RT_NULL;
/* disable interrupt */
level = rt_hw_interrupt_disable();
rt_kprintf("| lptimer | periodic | timeout | flag |\n");
rt_kprintf("+---------------+------------+------------+-------------+\n");
if (!rt_list_isempty(&rt_soft_lptimer_list))
{
rt_list_for_each(node, &rt_soft_lptimer_list)
{
timer = rt_list_entry(node, struct rt_lptimer, list);
rt_kprintf("| %-13s | 0x%08x | 0x%08x |",
timer->timer.parent.name, timer->timer.init_tick,
timer->timer.timeout_tick);
if (timer->timer.parent.flag & RT_TIMER_FLAG_ACTIVATED)
rt_kprintf(" activated |\n");
else
rt_kprintf(" deactivated |\n");
}
}
/* enable interrupt */
rt_hw_interrupt_enable(level);
rt_kprintf("+---------------+------------+------------+-------------+\n");
}
MSH_CMD_EXPORT(lptimer_dump, soft lptimer dump);

View File

@ -15,44 +15,9 @@
#include <rthw.h>
#include <rtthread.h>
#include <drivers/pm.h>
#include <stdlib.h>
#ifdef RT_USING_PM
/* tickless threshold time */
#ifndef PM_TICKLESS_THRESHOLD_TIME
#define PM_TICKLESS_THRESHOLD_TIME 2
#endif
/* tickless threshold : sleep mode */
#ifndef PM_TICKLESS_THRESHOLD_MODE
#define PM_TICKLESS_THRESHOLD_MODE PM_SLEEP_MODE_IDLE
#endif
/* busy : sleep mode */
#ifndef PM_BUSY_SLEEP_MODE
#define PM_BUSY_SLEEP_MODE PM_SLEEP_MODE_IDLE
#endif
/* suspend : suspend sleep mode */
#ifndef PM_SUSPEND_SLEEP_MODE
#define PM_SUSPEND_SLEEP_MODE PM_SLEEP_MODE_IDLE
#endif
#ifdef PM_ENABLE_THRESHOLD_SLEEP_MODE
#ifndef PM_LIGHT_THRESHOLD_TIME
#define PM_LIGHT_THRESHOLD_TIME 5
#endif
#ifndef PM_DEEP_THRESHOLD_TIME
#define PM_DEEP_THRESHOLD_TIME 20
#endif
#ifndef PM_STANDBY_THRESHOLD_TIME
#define PM_STANDBY_THRESHOLD_TIME 100
#endif
#endif
static struct rt_pm _pm;
/* default mode : system power on */
@ -64,6 +29,8 @@ static rt_uint8_t _pm_default_deepsleep = RT_PM_DEFAULT_DEEPSLEEP_MODE;
static struct rt_pm_notify _pm_notify;
static rt_uint8_t _pm_init_flag = 0;
#define RT_PM_TICKLESS_THRESH (2)
RT_WEAK rt_uint32_t rt_pm_enter_critical(rt_uint8_t sleep_mode)
{
return rt_hw_interrupt_disable();
@ -74,48 +41,6 @@ RT_WEAK void rt_pm_exit_critical(rt_uint32_t ctx, rt_uint8_t sleep_mode)
rt_hw_interrupt_enable(ctx);
}
/* lptimer start */
static void pm_lptimer_start(struct rt_pm *pm, uint32_t timeout)
{
if (_pm.ops == RT_NULL)
return;
if (_pm.ops->timer_start != RT_NULL)
_pm.ops->timer_start(pm, timeout);
}
/* lptimer stop */
static void pm_lptimer_stop(struct rt_pm *pm)
{
if (_pm.ops == RT_NULL)
return;
if (_pm.ops->timer_stop != RT_NULL)
_pm.ops->timer_stop(pm);
}
/* lptimer get timeout tick */
static rt_tick_t pm_lptimer_get_timeout(struct rt_pm *pm)
{
if (_pm.ops == RT_NULL)
return RT_TICK_MAX;
if (_pm.ops->timer_get_tick != RT_NULL)
return _pm.ops->timer_get_tick(pm);
return RT_TICK_MAX;
}
/* enter sleep mode */
static void pm_sleep(struct rt_pm *pm, uint8_t sleep_mode)
{
if (_pm.ops == RT_NULL)
return;
if (_pm.ops->sleep != RT_NULL)
_pm.ops->sleep(pm, sleep_mode);
}
/**
* This function will suspend all registered devices
*/
@ -186,30 +111,6 @@ static void _pm_frequency_scaling(struct rt_pm *pm)
}
}
/**
* judge sleep mode from sleep request
*
* @param none
*
* @return sleep mode
*/
static rt_uint8_t _judge_sleep_mode(void)
{
rt_uint16_t index;
rt_uint16_t len;
for (index = 0; index < PM_SLEEP_MODE_MAX -1; index++)
{
for (len = 0; len < ((PM_MODULE_MAX_ID + 31) / 32); len++)
{
if (_pm.sleep_status[index][len] != 0x00)
return index;
}
}
return PM_SLEEP_MODE_MAX; /* default sleep mode */
}
/**
* This function selects the sleep mode according to the rt_pm_request/rt_pm_release count.
*/
@ -219,7 +120,6 @@ static rt_uint8_t _pm_select_sleep_mode(struct rt_pm *pm)
rt_uint8_t mode;
mode = _pm_default_deepsleep;
rt_uint8_t request_mode = _judge_sleep_mode();
for (index = PM_SLEEP_MODE_NONE; index < PM_SLEEP_MODE_MAX; index ++)
{
if (pm->modes[index])
@ -228,10 +128,7 @@ static rt_uint8_t _pm_select_sleep_mode(struct rt_pm *pm)
break;
}
}
/* select the high power mode */
if (request_mode < mode)
mode = request_mode;
pm->sleep_mode = mode;
return mode;
}
@ -288,72 +185,6 @@ static rt_bool_t _pm_device_check_idle(void)
return RT_TRUE;
}
RT_WEAK rt_tick_t pm_timer_next_timeout_tick(rt_uint8_t mode)
{
switch (mode)
{
case PM_SLEEP_MODE_LIGHT:
return rt_timer_next_timeout_tick();
case PM_SLEEP_MODE_DEEP:
case PM_SLEEP_MODE_STANDBY:
return rt_lptimer_next_timeout_tick();
}
return RT_TICK_MAX;
}
/**
* This function will judge sleep mode from threshold timeout.
*
* @param cur_mode the current pm sleep mode
* @param timeout_tick the threshold timeout
*
* @return none
*/
RT_WEAK rt_uint8_t pm_get_sleep_threshold_mode(rt_uint8_t cur_mode, rt_tick_t timeout_tick)
{
rt_uint8_t sleep_mode = cur_mode;
if (_pm_init_flag == 0)
return sleep_mode;
if (cur_mode >= PM_SLEEP_MODE_MAX)
return sleep_mode;
#ifdef PM_ENABLE_THRESHOLD_SLEEP_MODE
switch (cur_mode)
{
case PM_SLEEP_MODE_NONE:
case PM_SLEEP_MODE_IDLE:
break;
case PM_SLEEP_MODE_LIGHT:
if (timeout_tick < PM_LIGHT_THRESHOLD_TIME)
sleep_mode = PM_SLEEP_MODE_IDLE;
break;
case PM_SLEEP_MODE_DEEP:
if (timeout_tick < PM_LIGHT_THRESHOLD_TIME)
sleep_mode = PM_SLEEP_MODE_IDLE;
else if (timeout_tick < PM_DEEP_THRESHOLD_TIME)
sleep_mode = PM_SLEEP_MODE_LIGHT;
break;
case PM_SLEEP_MODE_STANDBY:
if (timeout_tick < PM_LIGHT_THRESHOLD_TIME)
sleep_mode = PM_SLEEP_MODE_IDLE;
else if (timeout_tick < PM_DEEP_THRESHOLD_TIME)
sleep_mode = PM_SLEEP_MODE_LIGHT;
else if (timeout_tick < PM_STANDBY_THRESHOLD_TIME)
sleep_mode = PM_SLEEP_MODE_DEEP;
}
#else
if (timeout_tick < PM_TICKLESS_THRESHOLD_TIME)
{
cur_mode = PM_SLEEP_MODE_IDLE;
}
#endif
return cur_mode;
}
/**
* This function changes the power sleep mode base on the result of selection
*/
@ -361,21 +192,16 @@ static void _pm_change_sleep_mode(struct rt_pm *pm)
{
rt_tick_t timeout_tick, delta_tick;
rt_base_t level;
uint8_t sleep_mode = PM_SLEEP_MODE_DEEP;
int ret = RT_EOK;
level = rt_pm_enter_critical(pm->sleep_mode);
/* judge sleep mode from module request */
pm->sleep_mode = _pm_select_sleep_mode(pm);
/* module busy request check */
/* module busy request */
if (_pm_device_check_idle() == RT_FALSE)
{
sleep_mode = PM_BUSY_SLEEP_MODE;
if (sleep_mode < pm->sleep_mode)
{
pm->sleep_mode = sleep_mode; /* judge the highest sleep mode */
}
pm->ops->sleep(pm, PM_SLEEP_MODE_NONE);
rt_pm_exit_critical(level, pm->sleep_mode);
return;
}
if (_pm.sleep_mode == PM_SLEEP_MODE_NONE)
@ -390,54 +216,50 @@ static void _pm_change_sleep_mode(struct rt_pm *pm)
_pm_notify.notify(RT_PM_ENTER_SLEEP, pm->sleep_mode, _pm_notify.data);
/* Suspend all peripheral device */
#ifdef PM_ENABLE_SUSPEND_SLEEP_MODE
int ret = _pm_device_suspend(pm->sleep_mode);
ret = _pm_device_suspend(pm->sleep_mode);
if (ret != RT_EOK)
{
_pm_device_resume(pm->sleep_mode);
if (_pm_notify.notify)
_pm_notify.notify(RT_PM_EXIT_SLEEP, pm->sleep_mode, _pm_notify.data);
if (pm->sleep_mode > PM_SUSPEND_SLEEP_MODE)
{
pm->sleep_mode = PM_SUSPEND_SLEEP_MODE;
}
pm->ops->sleep(pm, pm->sleep_mode); /* suspend failed */
rt_pm_exit_critical(level, pm->sleep_mode);
return;
}
#else
_pm_device_suspend(pm->sleep_mode);
#endif
/* Tickless*/
if (pm->timer_mask & (0x01 << pm->sleep_mode))
{
timeout_tick = pm_timer_next_timeout_tick(pm->sleep_mode);
timeout_tick = timeout_tick - rt_tick_get();
/* Judge sleep_mode from threshold time */
pm->sleep_mode = pm_get_sleep_threshold_mode(pm->sleep_mode, timeout_tick);
if (pm->timer_mask & (0x01 << pm->sleep_mode))
timeout_tick = rt_timer_next_timeout_tick();
if (timeout_tick == RT_TICK_MAX)
{
if (timeout_tick == RT_TICK_MAX)
if (pm->ops->timer_start)
{
pm_lptimer_start(pm, RT_TICK_MAX);
pm->ops->timer_start(pm, RT_TICK_MAX);
}
}
else
{
timeout_tick = timeout_tick - rt_tick_get();
if (timeout_tick < RT_PM_TICKLESS_THRESH)
{
pm->sleep_mode = PM_SLEEP_MODE_IDLE;
}
else
{
pm_lptimer_start(pm, timeout_tick);
pm->ops->timer_start(pm, timeout_tick);
}
}
}
/* enter lower power state */
pm_sleep(pm, pm->sleep_mode);
pm->ops->sleep(pm, pm->sleep_mode);
/* wake up from lower power state*/
if (pm->timer_mask & (0x01 << pm->sleep_mode))
{
delta_tick = pm_lptimer_get_timeout(pm);
pm_lptimer_stop(pm);
delta_tick = pm->ops->timer_get_tick(pm);
pm->ops->timer_stop(pm);
if (delta_tick)
{
rt_tick_set(rt_tick_get() + delta_tick);
@ -498,6 +320,7 @@ void rt_pm_request(rt_uint8_t mode)
pm = &_pm;
if (pm->modes[mode] < 255)
pm->modes[mode] ++;
_pm_select_sleep_mode(pm);
rt_hw_interrupt_enable(level);
}
@ -523,6 +346,7 @@ void rt_pm_release(rt_uint8_t mode)
pm = &_pm;
if (pm->modes[mode] > 0)
pm->modes[mode] --;
_pm_select_sleep_mode(pm);
rt_hw_interrupt_enable(level);
}
@ -547,6 +371,7 @@ void rt_pm_release_all(rt_uint8_t mode)
level = rt_hw_interrupt_disable();
pm = &_pm;
pm->modes[mode] = 0;
_pm_select_sleep_mode(pm);
rt_hw_interrupt_enable(level);
}
@ -576,6 +401,7 @@ void rt_pm_module_request(uint8_t module_id, rt_uint8_t mode)
pm->module_status[module_id].req_status = 0x01;
if (pm->modes[mode] < 255)
pm->modes[mode] ++;
_pm_select_sleep_mode(pm);
rt_hw_interrupt_enable(level);
}
@ -607,6 +433,7 @@ void rt_pm_module_release(uint8_t module_id, rt_uint8_t mode)
pm->modes[mode] --;
if (pm->modes[mode] == 0)
pm->module_status[module_id].req_status = 0x00;
_pm_select_sleep_mode(pm);
rt_hw_interrupt_enable(level);
}
@ -633,135 +460,10 @@ void rt_pm_module_release_all(uint8_t module_id, rt_uint8_t mode)
pm = &_pm;
pm->modes[mode] = 0;
pm->module_status[module_id].req_status = 0x00;
_pm_select_sleep_mode(pm);
rt_hw_interrupt_enable(level);
}
/**
* This function will let current module work with specified sleep mode.
*
* @param module_id the pm module id
* @param mode the pm sleep mode
*
* @return none
*/
void rt_pm_sleep_request(rt_uint16_t module_id, rt_uint8_t mode)
{
rt_uint32_t level;
if (module_id >= PM_MODULE_MAX_ID)
{
return;
}
if (mode >= (PM_SLEEP_MODE_MAX - 1))
{
return;
}
level = rt_hw_interrupt_disable();
_pm.sleep_status[mode][module_id / 32] |= 1 << (module_id % 32);
rt_hw_interrupt_enable(level);
}
/**
* This function will let current module work with PM_SLEEP_MODE_NONE mode.
*
* @param module_id the pm module id
*
* @return NULL
*/
void rt_pm_sleep_none_request(rt_uint16_t module_id)
{
rt_pm_sleep_request(module_id, PM_SLEEP_MODE_NONE);
}
/**
* This function will let current module work with PM_SLEEP_MODE_IDLE mode.
*
* @param module_id the pm module id
*
* @return NULL
*/
void rt_pm_sleep_idle_request(rt_uint16_t module_id)
{
rt_pm_sleep_request(module_id, PM_SLEEP_MODE_IDLE);
}
/**
* This function will let current module work with PM_SLEEP_MODE_LIGHT mode.
*
* @param module_id the pm module id
*
* @return NULL
*/
void rt_pm_sleep_light_request(rt_uint16_t module_id)
{
rt_pm_sleep_request(module_id, PM_SLEEP_MODE_LIGHT);
}
/**
* When current module don't work, release requested sleep mode.
*
* @param module_id the pm module id
* @param mode the pm sleep mode
*
* @return NULL
*/
void rt_pm_sleep_release(rt_uint16_t module_id, rt_uint8_t mode)
{
rt_uint32_t level;
if (module_id >= PM_MODULE_MAX_ID)
{
return;
}
if (mode >= (PM_SLEEP_MODE_MAX - 1))
{
return;
}
level = rt_hw_interrupt_disable();
_pm.sleep_status[mode][module_id / 32] &= ~(1 << (module_id % 32));
rt_hw_interrupt_enable(level);
}
/**
* The specified module release the requested PM_SLEEP_MODE_NONE mode
*
* @param module_id the pm module id
*
* @return none
*/
void rt_pm_sleep_none_release(rt_uint16_t module_id)
{
rt_pm_sleep_release(module_id, PM_SLEEP_MODE_NONE);
}
/**
* The specified module release the requested PM_SLEEP_MODE_IDLE mode
*
* @param module_id the pm module id
*
* @return none
*/
void rt_pm_sleep_idle_release(rt_uint16_t module_id)
{
rt_pm_sleep_release(module_id, PM_SLEEP_MODE_IDLE);
}
/**
* The specified module release the requested PM_SLEEP_MODE_LIGHT mode
*
* @param module_id the pm module id
*
* @return none
*/
void rt_pm_sleep_light_release(rt_uint16_t module_id)
{
rt_pm_sleep_release(module_id, PM_SLEEP_MODE_LIGHT);
}
/**
* Register a device with PM feature
*
@ -1151,69 +853,6 @@ rt_uint8_t rt_pm_get_sleep_mode(void)
return pm->sleep_mode;
}
/* get pm entity pointer */
struct rt_pm *rt_pm_get_handle(void)
{
return &_pm;
}
#ifdef PM_ENABLE_DEBUG
/**
* print current module sleep request list
*
* @param none
*
* @return none
*/
void pm_sleep_dump(void)
{
uint8_t index;
uint16_t len;
rt_kprintf("+-------------+--------------+\n");
rt_kprintf("| Sleep Mode | Request List |\n");
rt_kprintf("+-------------+--------------+\n");
for (index = 0; index < PM_SLEEP_MODE_MAX -1; index++)
{
for (len = 0; len < ((PM_MODULE_MAX_ID + 31) / 32); len++)
{
rt_kprintf("| Mode[%d] : %d | 0x%08x |\n", index, len,
_pm.sleep_status[index][len]);
}
}
rt_kprintf("+-------------+--------------+\n");
}
MSH_CMD_EXPORT(pm_sleep_dump, dump pm request list);
static void pm_sleep_request(int argc, char **argv)
{
int module = 0;
int mode = 0;
if (argc >= 3)
{
module = atoi(argv[1]);
mode = atoi(argv[2]);
rt_pm_sleep_request(module, mode);
}
}
MSH_CMD_EXPORT(pm_sleep_request, pm_sleep_request module sleep_mode);
static void pm_sleep_release(int argc, char **argv)
{
int module = 0;
int mode = 0;
if (argc >= 3)
{
module = atoi(argv[1]);
mode = atoi(argv[2]);
rt_pm_sleep_release(module, mode);
}
}
MSH_CMD_EXPORT(pm_sleep_release, pm_sleep_release module sleep_mode);
#endif
static void rt_pm_dump_status(void)
{
rt_uint32_t index;

View File

@ -790,7 +790,7 @@ int rt_alarm_system_init(void)
rt_list_init(&_container.head);
rt_event_init(&_container.event, "alarmsvc", RT_IPC_FLAG_FIFO);
rt_mutex_init(&_container.mutex, "alarmsvc", RT_IPC_FLAG_PRIO);
rt_mutex_init(&_container.mutex, "alarmsvc", RT_IPC_FLAG_FIFO);
tid = rt_thread_create("alarmsvc",
rt_alarmsvc_thread_init, RT_NULL,

View File

@ -14,7 +14,7 @@
* 2021-07-30 Meco Man move rtc_core.c to rtc.c
*/
#include <sys/time.h>
#include <time.h>
#include <string.h>
#include <stdlib.h>
#include <rtthread.h>

View File

@ -21,6 +21,7 @@
#endif /* RT_SDIO_DEBUG */
#include <rtdbg.h>
static rt_list_t blk_devices = RT_LIST_OBJECT_INIT(blk_devices);
#define BLK_MIN(a, b) ((a) < (b) ? (a) : (b))
@ -351,81 +352,14 @@ const static struct rt_device_ops mmcsd_blk_ops =
};
#endif
static struct mmcsd_blk_device * rt_mmcsd_create_blkdev(struct rt_mmcsd_card *card, const char* dname, struct dfs_partition* psPart)
{
struct mmcsd_blk_device *blk_dev;
char sname[12];
blk_dev = rt_calloc(1, sizeof(struct mmcsd_blk_device));
if (!blk_dev)
{
LOG_E("mmcsd:malloc memory failed!");
return RT_NULL;
}
if (psPart != RT_NULL)
{
rt_memcpy(&blk_dev->part, psPart, sizeof(struct dfs_partition));
blk_dev->geometry.sector_count = psPart->size;
}
else
{
blk_dev->part.offset = 0;
blk_dev->part.size = 0;
blk_dev->geometry.sector_count = card->card_capacity * (1024 / 512);
}
blk_dev->geometry.bytes_per_sector = 1<<9;
blk_dev->geometry.block_size = card->card_blksize;
rt_snprintf(sname, sizeof(sname), "sem_%s", dname);
blk_dev->part.lock = rt_sem_create(sname, 1, RT_IPC_FLAG_FIFO);
blk_dev->max_req_size = BLK_MIN((card->host->max_dma_segs *
card->host->max_seg_size) >> 9,
(card->host->max_blk_count *
card->host->max_blk_size) >> 9);
/* register mmcsd device */
blk_dev->dev.type = RT_Device_Class_Block;
#ifdef RT_USING_DEVICE_OPS
blk_dev->dev.ops = &mmcsd_blk_ops;
#else
blk_dev->dev.init = rt_mmcsd_init;
blk_dev->dev.open = rt_mmcsd_open;
blk_dev->dev.close = rt_mmcsd_close;
blk_dev->dev.read = rt_mmcsd_read;
blk_dev->dev.write = rt_mmcsd_write;
blk_dev->dev.control = rt_mmcsd_control;
#endif
blk_dev->dev.user_data = blk_dev;
blk_dev->card = card;
rt_device_register(&blk_dev->dev, dname,
RT_DEVICE_FLAG_RDWR | RT_DEVICE_FLAG_REMOVABLE | RT_DEVICE_FLAG_STANDALONE);
/* Insert to list. */
rt_list_insert_after(&card->blk_devices, &blk_dev->list);
#ifdef RT_USING_DFS_MNTTABLE
if ( blk_dev )
{
LOG_I("try to mount file system!");
/* try to mount file system on this block device */
dfs_mount_device(&(blk_dev->dev));
}
#endif
return blk_dev;
}
rt_int32_t rt_mmcsd_blk_probe(struct rt_mmcsd_card *card)
{
rt_int32_t err = 0;
rt_uint8_t status;
rt_uint8_t i, status;
rt_uint8_t *sector;
char dname[4];
char sname[8];
struct mmcsd_blk_device *blk_dev = RT_NULL;
err = mmcsd_set_blksize(card);
if(err)
@ -447,43 +381,102 @@ rt_int32_t rt_mmcsd_blk_probe(struct rt_mmcsd_card *card)
status = rt_mmcsd_req_blk(card, 0, sector, 1, 0);
if (status == RT_EOK)
{
rt_uint8_t i;
char dname[8];
struct dfs_partition part;
struct mmcsd_blk_device *blk_dev = RT_NULL;
rt_int32_t host_id = card->host->id;
/* Initial blk_device link-list. */
rt_list_init(&card->blk_devices);
for (i = 0; i < RT_MMCSD_MAX_PARTITION; i++)
{
/* Get the first partition */
status = dfs_filesystem_get_partition(&part, sector, i);
blk_dev = rt_calloc(1, sizeof(struct mmcsd_blk_device));
if (!blk_dev)
{
LOG_E("mmcsd:malloc memory failed!");
break;
}
blk_dev->max_req_size = BLK_MIN((card->host->max_dma_segs *
card->host->max_seg_size) >> 9,
(card->host->max_blk_count *
card->host->max_blk_size) >> 9);
/* get the first partition */
status = dfs_filesystem_get_partition(&blk_dev->part, sector, i);
if (status == RT_EOK)
{
/* Given name is with allocated host id and its partition index. */
rt_snprintf(dname, sizeof(dname), "sd%dp%d", host_id, i);
blk_dev = rt_mmcsd_create_blkdev(card, (const char*)dname, &part);
if ( blk_dev == RT_NULL )
{
err = -RT_ENOMEM;
goto exit_rt_mmcsd_blk_probe;
}
rt_snprintf(dname, 4, "sd%d", i);
rt_snprintf(sname, 8, "sem_sd%d", i);
blk_dev->part.lock = rt_sem_create(sname, 1, RT_IPC_FLAG_FIFO);
/* register mmcsd device */
blk_dev->dev.type = RT_Device_Class_Block;
#ifdef RT_USING_DEVICE_OPS
blk_dev->dev.ops = &mmcsd_blk_ops;
#else
blk_dev->dev.init = rt_mmcsd_init;
blk_dev->dev.open = rt_mmcsd_open;
blk_dev->dev.close = rt_mmcsd_close;
blk_dev->dev.read = rt_mmcsd_read;
blk_dev->dev.write = rt_mmcsd_write;
blk_dev->dev.control = rt_mmcsd_control;
#endif
blk_dev->dev.user_data = blk_dev;
blk_dev->card = card;
blk_dev->geometry.bytes_per_sector = 1<<9;
blk_dev->geometry.block_size = card->card_blksize;
blk_dev->geometry.sector_count = blk_dev->part.size;
rt_device_register(&blk_dev->dev, dname,
RT_DEVICE_FLAG_RDWR | RT_DEVICE_FLAG_REMOVABLE | RT_DEVICE_FLAG_STANDALONE);
rt_list_insert_after(&blk_devices, &blk_dev->list);
}
else
{
break;
}
}
if (i == 0)
{
/* there is no partition table */
blk_dev->part.offset = 0;
blk_dev->part.size = 0;
blk_dev->part.lock = rt_sem_create("sem_sd0", 1, RT_IPC_FLAG_FIFO);
/* Always create the super node, given name is with allocated host id. */
rt_snprintf(dname, sizeof(dname), "sd%d", host_id);
blk_dev = rt_mmcsd_create_blkdev(card, (const char*)dname, RT_NULL);
if ( blk_dev == RT_NULL )
{
err = -RT_ENOMEM;
goto exit_rt_mmcsd_blk_probe;
/* register mmcsd device */
blk_dev->dev.type = RT_Device_Class_Block;
#ifdef RT_USING_DEVICE_OPS
blk_dev->dev.ops = &mmcsd_blk_ops;
#else
blk_dev->dev.init = rt_mmcsd_init;
blk_dev->dev.open = rt_mmcsd_open;
blk_dev->dev.close = rt_mmcsd_close;
blk_dev->dev.read = rt_mmcsd_read;
blk_dev->dev.write = rt_mmcsd_write;
blk_dev->dev.control = rt_mmcsd_control;
#endif
blk_dev->dev.user_data = blk_dev;
blk_dev->card = card;
blk_dev->geometry.bytes_per_sector = 1<<9;
blk_dev->geometry.block_size = card->card_blksize;
blk_dev->geometry.sector_count =
card->card_capacity * (1024 / 512);
rt_device_register(&blk_dev->dev, "sd0",
RT_DEVICE_FLAG_RDWR | RT_DEVICE_FLAG_REMOVABLE | RT_DEVICE_FLAG_STANDALONE);
rt_list_insert_after(&blk_devices, &blk_dev->list);
}
else
{
rt_free(blk_dev);
blk_dev = RT_NULL;
break;
}
}
#ifdef RT_USING_DFS_MNTTABLE
if (blk_dev)
{
LOG_I("try to mount file system!");
/* try to mount file system on this block device */
dfs_mount_device(&(blk_dev->dev));
}
#endif
}
}
else
@ -492,8 +485,6 @@ rt_int32_t rt_mmcsd_blk_probe(struct rt_mmcsd_card *card)
err = -RT_ERROR;
}
exit_rt_mmcsd_blk_probe:
/* release sector buffer */
rt_free(sector);
@ -505,7 +496,7 @@ void rt_mmcsd_blk_remove(struct rt_mmcsd_card *card)
rt_list_t *l, *n;
struct mmcsd_blk_device *blk_dev;
for (l = (&card->blk_devices)->next, n = l->next; l != &card->blk_devices; l = n, n=n->next)
for (l = (&blk_devices)->next, n = l->next; l != &blk_devices; l = n)
{
blk_dev = (struct mmcsd_blk_device *)rt_list_entry(l, struct mmcsd_blk_device, list);
if (blk_dev->card == card)

View File

@ -294,6 +294,11 @@ static int mmc_select_bus_width(struct rt_mmcsd_card *card, rt_uint8_t *ext_csd)
EXT_CSD_BUS_WIDTH_4,
EXT_CSD_BUS_WIDTH_1
};
rt_uint32_t bus_widths[] = {
MMCSD_BUS_WIDTH_8,
MMCSD_BUS_WIDTH_4,
MMCSD_BUS_WIDTH_1
};
struct rt_mmcsd_host *host = card->host;
unsigned idx, trys, bus_width = 0;
int err = 0;
@ -307,7 +312,7 @@ static int mmc_select_bus_width(struct rt_mmcsd_card *card, rt_uint8_t *ext_csd)
* the supported bus width or compare the ext csd values of current
* bus width and ext csd values of 1 bit mode read earlier.
*/
for (idx = 0; idx < sizeof(ext_csd_bits)/sizeof(rt_uint32_t); idx++) {
for (idx = 0; idx < sizeof(bus_widths)/sizeof(rt_uint32_t); idx++) {
/*
* Host is capable of 8bit transfer, then switch
* the device to work in 8bit transfer mode. If the

View File

@ -40,7 +40,6 @@ static struct rt_mailbox mmcsd_detect_mb;
static rt_uint32_t mmcsd_detect_mb_pool[4];
static struct rt_mailbox mmcsd_hotpluge_mb;
static rt_uint32_t mmcsd_hotpluge_mb_pool[4];
static rt_uint32_t allocated_host_num = 0;
void mmcsd_host_lock(struct rt_mmcsd_host *host)
{
@ -708,10 +707,8 @@ struct rt_mmcsd_host *mmcsd_alloc_host(void)
host->max_dma_segs = 1;
host->max_blk_size = 512;
host->max_blk_count = 4096;
host->id = allocated_host_num;
allocated_host_num++;
rt_mutex_init(&host->bus_lock, "sd_bus_lock", RT_IPC_FLAG_PRIO);
rt_mutex_init(&host->bus_lock, "sd_bus_lock", RT_IPC_FLAG_FIFO);
rt_sem_init(&host->sem_ack, "sd_ack", 0, RT_IPC_FLAG_FIFO);
return host;

View File

@ -37,9 +37,7 @@ static char *const sensor_name_str[] =
"eco2_", /* eCO2 sensor */
"gnss_", /* GPS/GNSS sensor */
"tof_", /* TOF sensor */
"spo2_", /* SpO2 sensor */
"iaq_", /* IAQ sensor */
"etoh_", /* EtOH sensor */
"spo2_" /* SpO2 sensor */
};
/* Sensor interrupt correlation function */
@ -136,8 +134,7 @@ static rt_err_t local_control(struct rt_sensor_device *sensor, int cmd, void *ar
LOG_D("Undefined control");
return RT_ERROR;
}
static struct rt_sensor_ops local_ops =
{
static struct rt_sensor_ops local_ops = {
.fetch_data = local_fetch_data,
.control = local_control
};
@ -148,7 +145,7 @@ static rt_err_t rt_sensor_open(rt_device_t dev, rt_uint16_t oflag)
rt_sensor_t sensor = (rt_sensor_t)dev;
RT_ASSERT(dev != RT_NULL);
rt_err_t res = RT_EOK;
rt_err_t (*local_ctrl)(struct rt_sensor_device * sensor, int cmd, void *arg) = local_control;
rt_err_t (*local_ctrl)(struct rt_sensor_device *sensor, int cmd, void *arg) = local_control;
if (sensor->module)
{
@ -314,7 +311,7 @@ static rt_size_t rt_sensor_read(rt_device_t dev, rt_off_t pos, void *buf, rt_siz
if (sensor->ops->fetch_data != RT_NULL)
{
result = sensor->ops->fetch_data(sensor, buf, len);
}
}
}
if (sensor->module)
@ -362,7 +359,7 @@ static rt_err_t rt_sensor_control(rt_device_t dev, int cmd, void *args)
{
sensor->config.range = (rt_int32_t)args;
LOG_D("set range %d", sensor->config.range);
}
}
break;
case RT_SENSOR_CTRL_SET_ODR:
/* Configuration data output rate */
@ -455,7 +452,7 @@ int rt_hw_sensor_register(rt_sensor_t sensor,
if (sensor->module != RT_NULL && sensor->module->lock == RT_NULL)
{
/* Create a mutex lock for the module */
sensor->module->lock = rt_mutex_create(name, RT_IPC_FLAG_PRIO);
sensor->module->lock = rt_mutex_create(name, RT_IPC_FLAG_FIFO);
if (sensor->module->lock == RT_NULL)
{
rt_free(device_name);
@ -488,7 +485,7 @@ int rt_hw_sensor_register(rt_sensor_t sensor,
return result;
}
LOG_I("rt_sensor[%s] init success", device_name);
rt_free(device_name);
LOG_I("rt_sensor[%s] init success", device_name);
return RT_EOK;
}

View File

@ -74,12 +74,6 @@ static void sensor_show_data(rt_size_t num, rt_sensor_t sensor, struct rt_sensor
case RT_SENSOR_CLASS_ECO2:
LOG_I("num:%3d, eco2:%5d ppm, timestamp:%5d", num, sensor_data->data.eco2, sensor_data->timestamp);
break;
case RT_SENSOR_CLASS_IAQ:
LOG_I("num:%3d, IAQ:%5d.%d , timestamp:%5d", num, sensor_data->data.iaq / 10, sensor_data->data.iaq % 10, sensor_data->timestamp);
break;
case RT_SENSOR_CLASS_ETOH:
LOG_I("num:%3d, EtOH:%5d.%03d ppm, timestamp:%5d", num, sensor_data->data.etoh / 1000, sensor_data->data.etoh % 1000, sensor_data->timestamp);
break;
default:
break;
}
@ -162,7 +156,7 @@ static void sensor_fifo(int argc, char **argv)
rt_device_control(dev, RT_SENSOR_CTRL_SET_ODR, (void *)20);
}
#ifdef RT_USING_FINSH
MSH_CMD_EXPORT(sensor_fifo, Sensor fifo mode test function);
MSH_CMD_EXPORT(sensor_fifo, Sensor fifo mode test function);
#endif
static void sensor_irq_rx_entry(void *parameter)
@ -226,12 +220,12 @@ static void sensor_int(int argc, char **argv)
rt_device_control(dev, RT_SENSOR_CTRL_SET_ODR, (void *)20);
}
#ifdef RT_USING_FINSH
MSH_CMD_EXPORT(sensor_int, Sensor interrupt mode test function);
MSH_CMD_EXPORT(sensor_int, Sensor interrupt mode test function);
#endif
static void sensor_polling(int argc, char **argv)
{
rt_uint16_t num = 10;
uint16_t num = 10;
rt_device_t dev = RT_NULL;
rt_sensor_t sensor;
struct rt_sensor_data data;
@ -275,7 +269,7 @@ static void sensor_polling(int argc, char **argv)
rt_device_close(dev);
}
#ifdef RT_USING_FINSH
MSH_CMD_EXPORT(sensor_polling, Sensor polling mode test function);
MSH_CMD_EXPORT(sensor_polling, Sensor polling mode test function);
#endif
static void sensor(int argc, char **argv)
@ -312,103 +306,103 @@ static void sensor(int argc, char **argv)
rt_device_control(dev, RT_SENSOR_CTRL_GET_INFO, &info);
switch (info.vendor)
{
case RT_SENSOR_VENDOR_UNKNOWN:
rt_kprintf("vendor :unknown vendor\n");
break;
case RT_SENSOR_VENDOR_STM:
rt_kprintf("vendor :STMicroelectronics\n");
break;
case RT_SENSOR_VENDOR_BOSCH:
rt_kprintf("vendor :Bosch\n");
break;
case RT_SENSOR_VENDOR_INVENSENSE:
rt_kprintf("vendor :Invensense\n");
break;
case RT_SENSOR_VENDOR_SEMTECH:
rt_kprintf("vendor :Semtech\n");
break;
case RT_SENSOR_VENDOR_GOERTEK:
rt_kprintf("vendor :Goertek\n");
break;
case RT_SENSOR_VENDOR_MIRAMEMS:
rt_kprintf("vendor :MiraMEMS\n");
break;
case RT_SENSOR_VENDOR_DALLAS:
rt_kprintf("vendor :Dallas\n");
break;
case RT_SENSOR_VENDOR_ASAIR:
rt_kprintf("vendor :Asair\n");
break;
case RT_SENSOR_VENDOR_SHARP:
rt_kprintf("vendor :Sharp\n");
break;
case RT_SENSOR_VENDOR_SENSIRION:
rt_kprintf("vendor :Sensirion\n");
break;
case RT_SENSOR_VENDOR_TI:
rt_kprintf("vendor :Texas Instruments\n");
break;
case RT_SENSOR_VENDOR_PLANTOWER:
rt_kprintf("vendor :Plantower\n");
break;
case RT_SENSOR_VENDOR_AMS:
rt_kprintf("vendor :AMS\n");
break;
case RT_SENSOR_VENDOR_MAXIM:
rt_kprintf("vendor :Maxim Integrated\n");
break;
case RT_SENSOR_VENDOR_UNKNOWN:
rt_kprintf("vendor :unknown vendor\n");
break;
case RT_SENSOR_VENDOR_STM:
rt_kprintf("vendor :STMicroelectronics\n");
break;
case RT_SENSOR_VENDOR_BOSCH:
rt_kprintf("vendor :Bosch\n");
break;
case RT_SENSOR_VENDOR_INVENSENSE:
rt_kprintf("vendor :Invensense\n");
break;
case RT_SENSOR_VENDOR_SEMTECH:
rt_kprintf("vendor :Semtech\n");
break;
case RT_SENSOR_VENDOR_GOERTEK:
rt_kprintf("vendor :Goertek\n");
break;
case RT_SENSOR_VENDOR_MIRAMEMS:
rt_kprintf("vendor :MiraMEMS\n");
break;
case RT_SENSOR_VENDOR_DALLAS:
rt_kprintf("vendor :Dallas\n");
break;
case RT_SENSOR_VENDOR_ASAIR:
rt_kprintf("vendor :Asair\n");
break;
case RT_SENSOR_VENDOR_SHARP:
rt_kprintf("vendor :Sharp\n");
break;
case RT_SENSOR_VENDOR_SENSIRION:
rt_kprintf("vendor :Sensirion\n");
break;
case RT_SENSOR_VENDOR_TI:
rt_kprintf("vendor :Texas Instruments\n");
break;
case RT_SENSOR_VENDOR_PLANTOWER:
rt_kprintf("vendor :Plantower\n");
break;
case RT_SENSOR_VENDOR_AMS:
rt_kprintf("vendor :AMS\n");
break;
case RT_SENSOR_VENDOR_MAXIM:
rt_kprintf("vendor :Maxim Integrated\n");
break;
}
rt_kprintf("model :%s\n", info.model);
switch (info.unit)
{
case RT_SENSOR_UNIT_NONE:
rt_kprintf("unit :none\n");
break;
case RT_SENSOR_UNIT_MG:
rt_kprintf("unit :mG\n");
break;
case RT_SENSOR_UNIT_MDPS:
rt_kprintf("unit :mdps\n");
break;
case RT_SENSOR_UNIT_MGAUSS:
rt_kprintf("unit :mGauss\n");
break;
case RT_SENSOR_UNIT_LUX:
rt_kprintf("unit :lux\n");
break;
case RT_SENSOR_UNIT_CM:
rt_kprintf("unit :cm\n");
break;
case RT_SENSOR_UNIT_PA:
rt_kprintf("unit :pa\n");
break;
case RT_SENSOR_UNIT_PERMILLAGE:
rt_kprintf("unit :permillage\n");
break;
case RT_SENSOR_UNIT_DCELSIUS:
rt_kprintf("unit :Celsius\n");
break;
case RT_SENSOR_UNIT_HZ:
rt_kprintf("unit :HZ\n");
break;
case RT_SENSOR_UNIT_ONE:
rt_kprintf("unit :1\n");
break;
case RT_SENSOR_UNIT_BPM:
rt_kprintf("unit :bpm\n");
break;
case RT_SENSOR_UNIT_MM:
rt_kprintf("unit :mm\n");
break;
case RT_SENSOR_UNIT_MN:
rt_kprintf("unit :mN\n");
break;
case RT_SENSOR_UNIT_PPM:
rt_kprintf("unit :ppm\n");
break;
case RT_SENSOR_UNIT_PPB:
rt_kprintf("unit :ppb\n");
break;
case RT_SENSOR_UNIT_NONE:
rt_kprintf("unit :none\n");
break;
case RT_SENSOR_UNIT_MG:
rt_kprintf("unit :mG\n");
break;
case RT_SENSOR_UNIT_MDPS:
rt_kprintf("unit :mdps\n");
break;
case RT_SENSOR_UNIT_MGAUSS:
rt_kprintf("unit :mGauss\n");
break;
case RT_SENSOR_UNIT_LUX:
rt_kprintf("unit :lux\n");
break;
case RT_SENSOR_UNIT_CM:
rt_kprintf("unit :cm\n");
break;
case RT_SENSOR_UNIT_PA:
rt_kprintf("unit :pa\n");
break;
case RT_SENSOR_UNIT_PERMILLAGE:
rt_kprintf("unit :permillage\n");
break;
case RT_SENSOR_UNIT_DCELSIUS:
rt_kprintf("unit :Celsius\n");
break;
case RT_SENSOR_UNIT_HZ:
rt_kprintf("unit :HZ\n");
break;
case RT_SENSOR_UNIT_ONE:
rt_kprintf("unit :1\n");
break;
case RT_SENSOR_UNIT_BPM:
rt_kprintf("unit :bpm\n");
break;
case RT_SENSOR_UNIT_MM:
rt_kprintf("unit :mm\n");
break;
case RT_SENSOR_UNIT_MN:
rt_kprintf("unit :mN\n");
break;
case RT_SENSOR_UNIT_PPM:
rt_kprintf("unit :ppm\n");
break;
case RT_SENSOR_UNIT_PPB:
rt_kprintf("unit :ppb\n");
break;
}
rt_kprintf("range_max :%d\n", info.range_max);
rt_kprintf("range_min :%d\n", info.range_min);
@ -417,7 +411,7 @@ static void sensor(int argc, char **argv)
}
else if (!strcmp(argv[1], "read"))
{
rt_uint16_t num = 5;
uint16_t num = 5;
if (dev == RT_NULL)
{
@ -503,5 +497,5 @@ static void sensor(int argc, char **argv)
}
}
#ifdef RT_USING_FINSH
MSH_CMD_EXPORT(sensor, sensor test function);
MSH_CMD_EXPORT(sensor, sensor test function);
#endif

View File

@ -36,13 +36,13 @@
#define DBG_LVL DBG_INFO
#include <rtdbg.h>
#ifdef RT_USING_POSIX_STDIO
#ifdef RT_USING_POSIX
#include <dfs_posix.h>
#include <poll.h>
#include <sys/ioctl.h>
#ifdef RT_USING_POSIX_TERMIOS
#include <termios.h>
#include <posix_termios.h>
#endif
/* it's possible the 'getc/putc' is defined by stdio.h in gcc/newlib. */
@ -203,7 +203,7 @@ const static struct dfs_file_ops _serial_fops =
RT_NULL, /* getdents */
serial_fops_poll,
};
#endif /* RT_USING_POSIX_STDIO */
#endif
/*
* Serial poll routines
@ -362,7 +362,7 @@ static void _serial_check_buffer_size(void)
}
}
#if defined(RT_USING_POSIX_STDIO) || defined(RT_SERIAL_USING_DMA)
#if defined(RT_USING_POSIX) || defined(RT_SERIAL_USING_DMA)
static rt_size_t _serial_fifo_calc_recved_len(struct rt_serial_device *serial)
{
struct rt_serial_rx_fifo *rx_fifo = (struct rt_serial_rx_fifo *) serial->serial_rx;
@ -385,7 +385,7 @@ static rt_size_t _serial_fifo_calc_recved_len(struct rt_serial_device *serial)
}
}
}
#endif /* RT_USING_POSIX_STDIO || RT_SERIAL_USING_DMA */
#endif /* RT_USING_POSIX || RT_SERIAL_USING_DMA */
#ifdef RT_SERIAL_USING_DMA
/**
@ -976,7 +976,8 @@ static void _tc_flush(struct rt_serial_device *serial, int queue)
}
}
#endif /* RT_USING_POSIX_TERMIOS */
#endif
static rt_err_t rt_serial_control(struct rt_device *dev,
int cmd,
@ -1019,7 +1020,7 @@ static rt_err_t rt_serial_control(struct rt_device *dev,
}
break;
#ifdef RT_USING_POSIX_STDIO
#ifdef RT_USING_POSIX
#ifdef RT_USING_POSIX_TERMIOS
case TCGETA:
{
@ -1133,7 +1134,6 @@ static rt_err_t rt_serial_control(struct rt_device *dev,
}
else
{
#include <shell.h>
#define _TIO_BUFLEN 20
char _tio_buf[_TIO_BUFLEN];
unsigned char cnt1, cnt2, cnt3, i;
@ -1149,7 +1149,7 @@ static rt_err_t rt_serial_control(struct rt_device *dev,
i = 0;
while(i < _TIO_BUFLEN)
{
_tio_buf[i] = finsh_getchar();
_tio_buf[i] = getchar();
if(_tio_buf[i] != 't')
{
i ++;
@ -1215,7 +1215,7 @@ static rt_err_t rt_serial_control(struct rt_device *dev,
*(rt_size_t *)args = recved;
}
break;
#endif /* RT_USING_POSIX_STDIO */
#endif /*RT_USING_POSIX*/
default :
/* control device */
ret = serial->ops->control(serial, cmd, args);
@ -1270,7 +1270,7 @@ rt_err_t rt_hw_serial_register(struct rt_serial_device *serial,
/* register a character device */
ret = rt_device_register(device, name, flag);
#ifdef RT_USING_POSIX_STDIO
#if defined(RT_USING_POSIX)
/* set fops */
device->fops = &_serial_fops;
#endif

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2006-2021, RT-Thread Development Team
* Copyright (c) 2006-2018, RT-Thread Development Team
*
* SPDX-License-Identifier: Apache-2.0
*
@ -16,7 +16,7 @@
#define DBG_LVL DBG_INFO
#include <rtdbg.h>
#ifdef RT_USING_POSIX_STDIO
#ifdef RT_USING_POSIX
#include <dfs_posix.h>
#include <poll.h>
#include <sys/ioctl.h>
@ -179,7 +179,7 @@ const static struct dfs_file_ops _serial_fops =
RT_NULL, /* getdents */
serial_fops_poll,
};
#endif /* RT_USING_POSIX_STDIO */
#endif
static rt_size_t rt_serial_get_linear_buffer(struct rt_ringbuffer *rb,
rt_uint8_t **ptr)
@ -1135,7 +1135,7 @@ rt_err_t rt_hw_serial_register(struct rt_serial_device *serial,
/* register a character device */
ret = rt_device_register(device, name, flag);
#ifdef RT_USING_POSIX_STDIO
#if defined(RT_USING_POSIX)
/* set fops */
device->fops = &_serial_fops;
#endif

View File

@ -834,7 +834,7 @@ rt_err_t enc28j60_attach(const char *spi_device_name)
enc28j60_dev.parent.eth_rx = enc28j60_rx;
enc28j60_dev.parent.eth_tx = enc28j60_tx;
rt_mutex_init(&enc28j60_dev.lock, "enc28j60", RT_IPC_FLAG_PRIO);
rt_mutex_init(&enc28j60_dev.lock, "enc28j60", RT_IPC_FLAG_FIFO);
eth_device_init(&(enc28j60_dev.parent), "e0");

View File

@ -29,7 +29,7 @@
#ifndef _SFUD_CFG_H_
#define _SFUD_CFG_H_
#include <rtthread.h>
#include <rtconfig.h>
/**
* It will print more information on debug mode.
@ -47,6 +47,7 @@
#define DBG_TAG "SFUD"
#include <rtdbg.h>
extern void rt_kprintf(const char *fmt, ...);
#define SFUD_INFO(...) LOG_I(__VA_ARGS__)
/**

View File

@ -29,7 +29,7 @@ rt_err_t rt_spi_bus_register(struct rt_spi_bus *bus,
return result;
/* initialize mutex lock */
rt_mutex_init(&(bus->lock), name, RT_IPC_FLAG_PRIO);
rt_mutex_init(&(bus->lock), name, RT_IPC_FLAG_FIFO);
/* set ops */
bus->ops = ops;
/* initialize owner */

View File

@ -318,7 +318,7 @@ rt_spi_flash_device_t rt_sfud_flash_probe_ex(const char *spi_flash_dev_name, con
if (rtt_dev) {
rt_memset(rtt_dev, 0, sizeof(struct spi_flash_device));
/* initialize lock */
rt_mutex_init(&(rtt_dev->lock), spi_flash_dev_name, RT_IPC_FLAG_PRIO);
rt_mutex_init(&(rtt_dev->lock), spi_flash_dev_name, RT_IPC_FLAG_FIFO);
}
if (rtt_dev && sfud_dev && spi_flash_dev_name_bak && spi_dev_name_bak) {

View File

@ -21,23 +21,6 @@ struct rt_data_item
rt_size_t data_size;
};
/**
* @brief This function will initialize the data queue. Calling this function will
* initialize the data queue control block and set the notification callback function.
*
* @param queue is a pointer to the data queue object.
*
* @param size is the maximum number of data in the data queue.
*
* @param lwm is low water mark.
* When the number of data in the data queue is less than this value, this function will
* wake up the thread waiting for write data.
*
* @param evt_notify is the notification callback function.
*
* @return Return the operation status. When the return value is RT_EOK, the initialization is successful.
* When the return value is RT_ENOMEM, it means insufficient memory allocation failed.
*/
rt_err_t
rt_data_queue_init(struct rt_data_queue *queue,
rt_uint16_t size,
@ -71,21 +54,6 @@ rt_data_queue_init(struct rt_data_queue *queue,
}
RTM_EXPORT(rt_data_queue_init);
/**
* @brief This function will write data to the data queue. If the data queue is full,
* the thread will suspend for the specified amount of time.
*
* @param queue is a pointer to the data queue object.
* .
* @param data_ptr is the buffer pointer of the data to be written.
*
* @param size is the size in bytes of the data to be written.
*
* @param timeout is the waiting time.
*
* @return Return the operation status. When the return value is RT_EOK, the operation is successful.
* When the return value is RT_ETIMEOUT, it means the specified time out.
*/
rt_err_t rt_data_queue_push(struct rt_data_queue *queue,
const void *data_ptr,
rt_size_t data_size,
@ -185,24 +153,6 @@ __exit:
}
RTM_EXPORT(rt_data_queue_push);
/**
* @brief This function will pop data from the data queue. If the data queue is empty,the thread
* will suspend for the specified amount of time.
*
* @note When the number of data in the data queue is less than lwm(low water mark), will
* wake up the thread waiting for write data.
*
* @param queue is a pointer to the data queue object.
*
* @param data_ptr is the buffer pointer of the data to be fetched.
*
* @param size is the size in bytes of the data to be fetched.
*
* @param timeout is the waiting time.
*
* @return Return the operation status. When the return value is RT_EOK, the operation is successful.
* When the return value is RT_ETIMEOUT, it means the specified time out.
*/
rt_err_t rt_data_queue_pop(struct rt_data_queue *queue,
const void** data_ptr,
rt_size_t *size,
@ -314,18 +264,6 @@ __exit:
}
RTM_EXPORT(rt_data_queue_pop);
/**
* @brief This function will fetch but retaining data in the data queue.
*
* @param queue is a pointer to the data queue object.
*
* @param data_ptr is the buffer pointer of the data to be fetched.
*
* @param size is the size in bytes of the data to be fetched.
*
* @return Return the operation status. When the return value is RT_EOK, the operation is successful.
* When the return value is -RT_EEMPTY, it means the data queue is empty.
*/
rt_err_t rt_data_queue_peek(struct rt_data_queue *queue,
const void** data_ptr,
rt_size_t *size)
@ -351,14 +289,6 @@ rt_err_t rt_data_queue_peek(struct rt_data_queue *queue,
}
RTM_EXPORT(rt_data_queue_peek);
/**
* @brief This function will reset the data queue.
*
* @note Calling this function will wake up all threads on the data queue
* that are hanging and waiting.
*
* @param queue is a pointer to the data queue object.
*/
void rt_data_queue_reset(struct rt_data_queue *queue)
{
rt_ubase_t level;
@ -432,13 +362,6 @@ void rt_data_queue_reset(struct rt_data_queue *queue)
}
RTM_EXPORT(rt_data_queue_reset);
/**
* @brief This function will deinit the data queue.
*
* @param queue is a pointer to the data queue object.
*
* @return Return the operation status. When the return value is RT_EOK, the operation is successful.
*/
rt_err_t rt_data_queue_deinit(struct rt_data_queue *queue)
{
rt_ubase_t level;
@ -459,13 +382,6 @@ rt_err_t rt_data_queue_deinit(struct rt_data_queue *queue)
}
RTM_EXPORT(rt_data_queue_deinit);
/**
* @brief This function will get the number of data in the data queue.
*
* @param queue is a pointer to the data queue object.
*
* @return Return the number of data in the data queue.
*/
rt_uint16_t rt_data_queue_len(struct rt_data_queue *queue)
{
rt_ubase_t level;

View File

@ -13,22 +13,12 @@
#include <stdint.h>
#include <sys/errno.h>
#if defined(RT_USING_POSIX_DEVIO) && defined(RT_USING_POSIX_PIPE)
#ifdef RT_USING_POSIX
#include <dfs_file.h>
#include <dfs_posix.h>
#include <poll.h>
#include <sys/ioctl.h>
/**
* @brief This function will open a pipe.
*
* @param fd is the file descriptor.
*
* @return Return the operation status.
* When the return value is 0, it means the operation is successful.
* When the return value is -1, it means the file descriptor is invalid.
* When the return value is -RT_ENOMEM, it means insufficient memory allocation failed.
*/
static int pipe_fops_open(struct dfs_fd *fd)
{
int rc = 0;
@ -72,15 +62,6 @@ __exit:
return rc;
}
/**
* @brief This function will close a pipe.
*
* @param fd is the file descriptor.
*
* @return Return the operation status.
* When the return value is 0, it means the operation is successful.
* When the return value is -1, it means the file descriptor is invalid.
*/
static int pipe_fops_close(struct dfs_fd *fd)
{
rt_device_t device;
@ -135,23 +116,6 @@ static int pipe_fops_close(struct dfs_fd *fd)
return 0;
}
/**
* @brief This function will get the pipe space size depends on the command.
*
* @param fd is the file descriptor.
*
* @param cmd is the command. It determines what data will get.
*
* FIONREAD The command to get the number of bytes in the pipe.
*
* FIONWRITE The command to get the number of bytes can be written to the pipe.
*
* @param args is the pointer to the data to store the read data.
*
* @return Return the operation status.
* When the return value is 0, it means the operation is successful.
* When the return value is -EINVAL, it means the command is invalid.
*/
static int pipe_fops_ioctl(struct dfs_fd *fd, int cmd, void *args)
{
rt_pipe_t *pipe;
@ -175,19 +139,6 @@ static int pipe_fops_ioctl(struct dfs_fd *fd, int cmd, void *args)
return ret;
}
/**
* @brief This function will read data from pipe.
*
* @param fd is the file descriptor.
*
* @param buf is the buffer to store the read data.
*
* @param count is the length of data to be read.
*
* @return Return the length of data read.
* When the return value is 0, it means O_NONBLOCK is enabled and there is no thread that has the pipe open for writing.
* When the return value is -EAGAIN, it means there are no data to be read.
*/
static int pipe_fops_read(struct dfs_fd *fd, void *buf, size_t count)
{
int len = 0;
@ -237,19 +188,6 @@ out:
return len;
}
/**
* @brief This function will write data to pipe.
*
* @param fd is the file descriptor.
*
* @param buf is a pointer to the data buffer to be written.
*
* @param count is the length of data to be write.
*
* @return Return the length of data written.
* When the return value is -EAGAIN, it means O_NONBLOCK is enabled and there are no space to be written.
* When the return value is -EPIPE, it means there is no thread that has the pipe open for reading.
*/
static int pipe_fops_write(struct dfs_fd *fd, const void *buf, size_t count)
{
int len;
@ -320,19 +258,6 @@ out:
return ret;
}
/**
* @brief This function will get the pipe status.
*
* @param fd is the file descriptor.
*
* @param req is the request type.
*
* @return mask of the pipe status.
* POLLIN means there is data to be read.
* POLLHUP means there is no thread that occupied the pipe to open for writing.
* POLLOUT means there is space to be written.
* POLLERR means there is no thread that occupied the pipe to open for reading.
*/
static int pipe_fops_poll(struct dfs_fd *fd, rt_pollreq_t *req)
{
int mask = 0;
@ -395,21 +320,9 @@ static const struct dfs_file_ops pipe_fops =
RT_NULL,
pipe_fops_poll,
};
#endif /* defined(RT_USING_POSIX_DEVIO) && defined(RT_USING_POSIX_PIPE) */
#endif /* end of RT_USING_POSIX */
/**
* @brief This function will open the pipe and actually creates the pipe buffer.
*
* @param device is a pointer to the pipe device descriptor.
*
* @param oflag is the open method, but it is not used yet.
*
* @return Return the operation status.
* When the return value is RT_EOK, the operation is successful.
* When the return value is -RT_EINVAL, it means the device handle is empty.
* When the return value is -RT_ENOMEM, it means insufficient memory allocation failed.
*/
static rt_err_t rt_pipe_open(rt_device_t device, rt_uint16_t oflag)
rt_err_t rt_pipe_open(rt_device_t device, rt_uint16_t oflag)
{
rt_pipe_t *pipe = (rt_pipe_t *)device;
rt_err_t ret = RT_EOK;
@ -437,16 +350,7 @@ __exit:
return ret;
}
/**
* @brief This function will close the pipe and release the pipe buffer.
*
* @param device is a pointer to the pipe device descriptor.
*
* @return Return the operation status.
* When the return value is RT_EOK, the operation is successful.
* When the return value is -RT_EINVAL, it means the device handle is empty.
*/
static rt_err_t rt_pipe_close(rt_device_t device)
rt_err_t rt_pipe_close(rt_device_t device)
{
rt_pipe_t *pipe = (rt_pipe_t *)device;
@ -464,21 +368,7 @@ static rt_err_t rt_pipe_close(rt_device_t device)
return RT_EOK;
}
/**
* @brief This function will read the specified length of data from the pipe.
*
* @param device is a pointer to the pipe device descriptor.
*
* @param pos is a parameter compatible with POSIX standard interface (currently meaningless, just pass in 0).
*
* @param buffer is a pointer to the buffer to store the read data.
*
* @param count is the length of data to be read.
*
* @return Return the length of data read.
* When the return value is 0, it means the pipe device handle is empty or the count is 0.
*/
static rt_size_t rt_pipe_read(rt_device_t device, rt_off_t pos, void *buffer, rt_size_t count)
rt_size_t rt_pipe_read(rt_device_t device, rt_off_t pos, void *buffer, rt_size_t count)
{
uint8_t *pbuf;
rt_size_t read_bytes = 0;
@ -506,21 +396,7 @@ static rt_size_t rt_pipe_read(rt_device_t device, rt_off_t pos, void *buffer, rt
return read_bytes;
}
/**
* @brief This function will write the specified length of data to the pipe.
*
* @param device is a pointer to the pipe device descriptor.
*
* @param pos is a parameter compatible with POSIX standard interface (currently meaningless, just pass in 0).
*
* @param buffer is a pointer to the data buffer to be written.
*
* @param count is the length of data to be written.
*
* @return Return the length of data written.
* When the return value is 0, it means the pipe device handle is empty or the count is 0.
*/
static rt_size_t rt_pipe_write(rt_device_t device, rt_off_t pos, const void *buffer, rt_size_t count)
rt_size_t rt_pipe_write(rt_device_t device, rt_off_t pos, const void *buffer, rt_size_t count)
{
uint8_t *pbuf;
rt_size_t write_bytes = 0;
@ -548,18 +424,7 @@ static rt_size_t rt_pipe_write(rt_device_t device, rt_off_t pos, const void *buf
return write_bytes;
}
/**
* @brief This function is not used yet.
*
* @param dev is not used yet.
*
* @param cmd is not used yet.
*
* @param args is not used yet.
*
* @return Always return RT_EOK.
*/
static rt_err_t rt_pipe_control(rt_device_t dev, int cmd, void *args)
rt_err_t rt_pipe_control(rt_device_t dev, int cmd, void *args)
{
return RT_EOK;
}
@ -574,20 +439,8 @@ const static struct rt_device_ops pipe_ops =
rt_pipe_write,
rt_pipe_control,
};
#endif /* RT_USING_DEVICE_OPS */
#endif
/**
* @brief This function will initialize a pipe device.
* The system allocates a pipe handle from dynamic heap memory, initializes the pipe handle
* with the specified value, and registers the pipe device with the system.
*
* @param name is the name of pipe device.
*
* @param bufsz is the size of pipe buffer.
*
* @return Return the pointer to the pipe device.
* When the return value is RT_NULL, it means the initialization failed.
*/
rt_pipe_t *rt_pipe_create(const char *name, int bufsz)
{
rt_pipe_t *pipe;
@ -598,7 +451,7 @@ rt_pipe_t *rt_pipe_create(const char *name, int bufsz)
rt_memset(pipe, 0, sizeof(rt_pipe_t));
pipe->is_named = RT_TRUE; /* initialize as a named pipe */
rt_mutex_init(&(pipe->lock), name, RT_IPC_FLAG_PRIO);
rt_mutex_init(&(pipe->lock), name, RT_IPC_FLAG_FIFO);
rt_wqueue_init(&(pipe->reader_queue));
rt_wqueue_init(&(pipe->writer_queue));
@ -626,24 +479,13 @@ rt_pipe_t *rt_pipe_create(const char *name, int bufsz)
rt_free(pipe);
return RT_NULL;
}
#if defined(RT_USING_POSIX_DEVIO) && defined(RT_USING_POSIX_PIPE)
#ifdef RT_USING_POSIX
dev->fops = (void*)&pipe_fops;
#endif
return pipe;
}
/**
* @brief This function will delete a pipe device.
* The system will release the pipe handle and unregister the pipe device from the system.
*
* @param pipe is the pointer to the pipe device.
*
* @return Return the operation status.
* When the return value is 0, it means the operation is successful.
* When the return value is -RT_EINVAL, it means the pipe device is not found or the device isn't a pipe.
* When the return value is -RT_EBUSY, it means the pipe device is busy.
*/
int rt_pipe_delete(const char *name)
{
int result = 0;
@ -687,17 +529,7 @@ int rt_pipe_delete(const char *name)
return result;
}
#if defined(RT_USING_POSIX_DEVIO) && defined(RT_USING_POSIX_PIPE)
/**
* @brief This function will creat a anonymous pipe.
*
* @param fildes[0] is the read handle.
* fildes[1] is the write handle.
*
* @return Return the operation status.
* When the return value is 0, it means the operation is successful.
* When the return value is -1, it means the operation is failed.
*/
#ifdef RT_USING_POSIX
int pipe(int fildes[2])
{
rt_pipe_t *pipe;
@ -707,7 +539,7 @@ int pipe(int fildes[2])
rt_snprintf(dname, sizeof(dname), "pipe%d", pipeno++);
pipe = rt_pipe_create(dname, RT_USING_POSIX_PIPE_SIZE);
pipe = rt_pipe_create(dname, PIPE_BUFSZ);
if (pipe == RT_NULL)
{
return -1;
@ -731,22 +563,11 @@ int pipe(int fildes[2])
return 0;
}
/**
* @brief This function will create a named pipe.
*
* @param path is the name of pipe device.
*
* @param mode is not used yet.
*
* @return Return the operation status.
* When the return value is 0, it means the operation is successful.
* When the return value is -1, it means the operation is failed.
*/
int mkfifo(const char *path, mode_t mode)
{
rt_pipe_t *pipe;
pipe = rt_pipe_create(path, RT_USING_POSIX_PIPE_SIZE);
pipe = rt_pipe_create(path, PIPE_BUFSZ);
if (pipe == RT_NULL)
{
return -1;
@ -754,4 +575,4 @@ int mkfifo(const char *path, mode_t mode)
return 0;
}
#endif /* defined(RT_USING_POSIX_DEVIO) && defined(RT_USING_POSIX_PIPE) */
#endif

View File

@ -35,15 +35,11 @@ void rt_rbb_init(rt_rbb_t rbb, rt_uint8_t *buf, rt_size_t buf_size, rt_rbb_blk_t
rbb->buf_size = buf_size;
rbb->blk_set = block_set;
rbb->blk_max_num = blk_max_num;
rbb->tail = &rbb->blk_list;
rt_slist_init(&rbb->blk_list);
rt_slist_init(&rbb->free_list);
/* initialize block status */
for (i = 0; i < blk_max_num; i++)
{
block_set[i].status = RT_RBB_BLK_UNUSED;
rt_slist_init(&block_set[i].list);
rt_slist_insert(&rbb->free_list, &block_set[i].list);
}
}
RTM_EXPORT(rt_rbb_init);
@ -112,46 +108,19 @@ RTM_EXPORT(rt_rbb_destroy);
static rt_rbb_blk_t find_empty_blk_in_set(rt_rbb_t rbb)
{
struct rt_rbb_blk *blk;
rt_size_t i;
RT_ASSERT(rbb);
if (rt_slist_isempty(&rbb->free_list))
for (i = 0; i < rbb->blk_max_num; i ++)
{
return RT_NULL;
if (rbb->blk_set[i].status == RT_RBB_BLK_UNUSED)
{
return &rbb->blk_set[i];
}
}
blk = rt_slist_first_entry(&rbb->free_list, struct rt_rbb_blk, list);
rt_slist_remove(&rbb->free_list, &blk->list);
RT_ASSERT(blk->status == RT_RBB_BLK_UNUSED);
return blk;
}
rt_inline void list_append(rt_rbb_t rbb, rt_slist_t* n)
{
/* append the node to the tail */
rbb->tail->next = n;
n->next = RT_NULL;
/* save tail node */
rbb->tail = n;
}
rt_inline rt_slist_t *list_remove(rt_rbb_t rbb, rt_slist_t* n)
{
rt_slist_t* l = &rbb->blk_list;
struct rt_slist_node* node = l;
/* remove slist head */
while (node->next && node->next != n) node = node->next;
/* remove node */
if (node->next != (rt_slist_t*)0)
{
node->next = node->next->next;
n->next = RT_NULL;
/* update tail node */
if (rbb->tail == n)
rbb->tail = node;
}
return l;
return RT_NULL;
}
/**
@ -178,13 +147,12 @@ rt_rbb_blk_t rt_rbb_blk_alloc(rt_rbb_t rbb, rt_size_t blk_size)
new_rbb = find_empty_blk_in_set(rbb);
if (new_rbb)
if (rt_slist_len(&rbb->blk_list) < rbb->blk_max_num && new_rbb)
{
if (rt_slist_isempty(&rbb->blk_list) == 0)
if (rt_slist_len(&rbb->blk_list) > 0)
{
head = rt_slist_first_entry(&rbb->blk_list, struct rt_rbb_blk, list);
/* get tail rbb blk object */
tail = rt_slist_entry(rbb->tail, struct rt_rbb_blk, list);
tail = rt_slist_tail_entry(&rbb->blk_list, struct rt_rbb_blk, list);
if (head->buf <= tail->buf)
{
/**
@ -199,14 +167,14 @@ rt_rbb_blk_t rt_rbb_blk_alloc(rt_rbb_t rbb, rt_size_t blk_size)
if (empty1 >= blk_size)
{
list_append(rbb, &new_rbb->list);
rt_slist_append(&rbb->blk_list, &new_rbb->list);
new_rbb->status = RT_RBB_BLK_INITED;
new_rbb->buf = tail->buf + tail->size;
new_rbb->size = blk_size;
}
else if (empty2 >= blk_size)
{
list_append(rbb, &new_rbb->list);
rt_slist_append(&rbb->blk_list, &new_rbb->list);
new_rbb->status = RT_RBB_BLK_INITED;
new_rbb->buf = rbb->buf;
new_rbb->size = blk_size;
@ -230,7 +198,7 @@ rt_rbb_blk_t rt_rbb_blk_alloc(rt_rbb_t rbb, rt_size_t blk_size)
if (empty1 >= blk_size)
{
list_append(rbb, &new_rbb->list);
rt_slist_append(&rbb->blk_list, &new_rbb->list);
new_rbb->status = RT_RBB_BLK_INITED;
new_rbb->buf = tail->buf + tail->size;
new_rbb->size = blk_size;
@ -245,7 +213,7 @@ rt_rbb_blk_t rt_rbb_blk_alloc(rt_rbb_t rbb, rt_size_t blk_size)
else
{
/* the list is empty */
list_append(rbb, &new_rbb->list);
rt_slist_append(&rbb->blk_list, &new_rbb->list);
new_rbb->status = RT_RBB_BLK_INITED;
new_rbb->buf = rbb->buf;
new_rbb->size = blk_size;
@ -362,10 +330,12 @@ void rt_rbb_blk_free(rt_rbb_t rbb, rt_rbb_blk_t block)
RT_ASSERT(block->status != RT_RBB_BLK_UNUSED);
level = rt_hw_interrupt_disable();
/* remove it on rbb block list */
list_remove(rbb, &block->list);
rt_slist_remove(&rbb->blk_list, &block->list);
block->status = RT_RBB_BLK_UNUSED;
rt_slist_insert(&rbb->free_list, &block->list);
rt_hw_interrupt_enable(level);
}
RTM_EXPORT(rt_rbb_blk_free);
@ -397,7 +367,7 @@ rt_size_t rt_rbb_blk_queue_get(rt_rbb_t rbb, rt_size_t queue_data_len, rt_rbb_bl
{
rt_base_t level;
rt_size_t data_total_size = 0;
rt_slist_t *node, *tmp = RT_NULL;
rt_slist_t *node;
rt_rbb_blk_t last_block = RT_NULL, block;
RT_ASSERT(rbb);
@ -408,12 +378,7 @@ rt_size_t rt_rbb_blk_queue_get(rt_rbb_t rbb, rt_size_t queue_data_len, rt_rbb_bl
level = rt_hw_interrupt_disable();
node = rt_slist_first(&rbb->blk_list);
if (node != RT_NULL)
{
tmp = rt_slist_next(node);
}
for (; node; node = tmp, tmp = rt_slist_next(node))
for (node = rt_slist_first(&rbb->blk_list); node; node = rt_slist_next(node))
{
if (!last_block)
{
@ -450,6 +415,7 @@ rt_size_t rt_rbb_blk_queue_get(rt_rbb_t rbb, rt_size_t queue_data_len, rt_rbb_bl
last_block = block;
}
/* remove current block */
rt_slist_remove(&rbb->blk_list, &last_block->list);
data_total_size += last_block->size;
last_block->status = RT_RBB_BLK_GET;
blk_queue->blk_num++;
@ -470,16 +436,15 @@ RTM_EXPORT(rt_rbb_blk_queue_get);
*/
rt_size_t rt_rbb_blk_queue_len(rt_rbb_blk_queue_t blk_queue)
{
rt_size_t i = 0, data_total_size = 0;
rt_rbb_blk_t blk;
rt_size_t i, data_total_size = 0;
RT_ASSERT(blk_queue);
for (blk = blk_queue->blocks; i < blk_queue->blk_num; i++)
for (i = 0; i < blk_queue->blk_num; i++)
{
data_total_size += blk->size;
blk = rt_slist_entry(blk->list.next, struct rt_rbb_blk, list);
data_total_size += blk_queue->blocks[i].size;
}
return data_total_size;
}
RTM_EXPORT(rt_rbb_blk_queue_len);
@ -507,17 +472,14 @@ RTM_EXPORT(rt_rbb_blk_queue_buf);
*/
void rt_rbb_blk_queue_free(rt_rbb_t rbb, rt_rbb_blk_queue_t blk_queue)
{
rt_size_t i = 0;
rt_rbb_blk_t blk, next_blk;
rt_size_t i;
RT_ASSERT(rbb);
RT_ASSERT(blk_queue);
for (blk = blk_queue->blocks; i < blk_queue->blk_num; i++)
for (i = 0; i < blk_queue->blk_num; i++)
{
next_blk = rt_slist_entry(blk->list.next, struct rt_rbb_blk, list);
rt_rbb_blk_free(rbb, blk);
blk = next_blk;
rt_rbb_blk_free(rbb, &blk_queue->blocks[i]);
}
}
RTM_EXPORT(rt_rbb_blk_queue_free);

View File

@ -15,13 +15,6 @@
#include <rtdevice.h>
#include <rtservice.h>
/**
* @brief This function will insert a node to the wait queue.
*
* @param queue is a pointer to the wait queue.
*
* @param node is a pointer to the node to be inserted.
*/
void rt_wqueue_add(rt_wqueue_t *queue, struct rt_wqueue_node *node)
{
rt_base_t level;
@ -31,13 +24,6 @@ void rt_wqueue_add(rt_wqueue_t *queue, struct rt_wqueue_node *node)
rt_hw_interrupt_enable(level);
}
/**
* @brief This function will remove a node from the wait queue.
*
* @param queue is a pointer to the wait queue.
*
* @param node is a pointer to the node to be removed.
*/
void rt_wqueue_remove(struct rt_wqueue_node *node)
{
rt_base_t level;
@ -47,30 +33,11 @@ void rt_wqueue_remove(struct rt_wqueue_node *node)
rt_hw_interrupt_enable(level);
}
/**
* @brief This function is the default wakeup function, but it doesn't do anything in actual.
* It always return 0, user should define their own wakeup function.
*
* @param queue is a pointer to the wait queue.
*
* @param key is the wakeup condition.
*
* @return always return 0.
*/
int __wqueue_default_wake(struct rt_wqueue_node *wait, void *key)
{
return 0;
}
/**
* @brief This function will wake up a pending thread on the specified waiting queue that meets the conditions.
*
* @param queue is a pointer to the wait queue.
*
* @param key is the wakeup conditions, but it is not effective now, because
* default wakeup function always return 0.
* If user wants to use it, user should define their own wakeup function.
*/
void rt_wqueue_wakeup(rt_wqueue_t *queue, void *key)
{
rt_base_t level;
@ -107,18 +74,6 @@ void rt_wqueue_wakeup(rt_wqueue_t *queue, void *key)
rt_schedule();
}
/**
* @brief This function will join a thread to the specified waiting queue, the thread will holds a wait or
* timeout return on the specified wait queue.
*
* @param queue is a pointer to the wait queue.
*
* @param condition is parameters compatible with POSIX standard interface (currently meaningless, just pass in 0).
*
* @param msec is the timeout value, unit is millisecond.
*
* @return Return 0 if the thread is woken up.
*/
int rt_wqueue_wait(rt_wqueue_t *queue, int condition, int msec)
{
int tick;

View File

@ -309,7 +309,7 @@ rt_err_t rt_workqueue_submit_work(struct rt_workqueue *queue, struct rt_work *wo
*
* @return RT_EOK Success.
*/
rt_err_t rt_workqueue_urgent_work(struct rt_workqueue *queue, struct rt_work *work)
rt_err_t rt_workqueue_critical_work(struct rt_workqueue *queue, struct rt_work *work)
{
rt_base_t level;
RT_ASSERT(queue != RT_NULL);

View File

@ -738,7 +738,7 @@ static rt_size_t _vcom_rb_block_put(struct vcom *data, const rt_uint8_t *buf, rt
return size;
}
static rt_size_t _vcom_tx(struct rt_serial_device *serial, rt_uint8_t *buf, rt_size_t size, int direction)
static rt_size_t _vcom_tx(struct rt_serial_device *serial, rt_uint8_t *buf, rt_size_t size,rt_uint32_t direction)
{
struct ufunction *func;
struct vcom *data;

View File

@ -323,7 +323,7 @@ const static struct uhid_comm_descriptor _hid_comm_desc =
#else
0,
#endif
},
},
/* HID Descriptor */
{

View File

@ -84,7 +84,7 @@ void rt_wlan_cfg_init(void)
rt_memset(cfg_cache, 0, sizeof(struct rt_wlan_cfg_des));
}
/* init mutex lock */
rt_mutex_init(&cfg_mutex, "wlan_cfg", RT_IPC_FLAG_PRIO);
rt_mutex_init(&cfg_mutex, "wlan_cfg", RT_IPC_FLAG_FIFO);
}
}

View File

@ -650,7 +650,7 @@ static rt_err_t _rt_wlan_dev_init(rt_device_t dev)
struct rt_wlan_device *wlan = (struct rt_wlan_device *)dev;
rt_err_t result = RT_EOK;
rt_mutex_init(&wlan->lock, "wlan_dev", RT_IPC_FLAG_PRIO);
rt_mutex_init(&wlan->lock, "wlan_dev", RT_IPC_FLAG_FIFO);
if (wlan->ops->wlan_init)
result = wlan->ops->wlan_init(wlan);

View File

@ -2011,10 +2011,10 @@ int rt_wlan_init(void)
rt_memset(&_ap_mgnt, 0, sizeof(struct rt_wlan_mgnt_des));
rt_memset(&scan_result, 0, sizeof(struct rt_wlan_scan_result));
rt_memset(&sta_info, 0, sizeof(struct rt_wlan_sta_des));
rt_mutex_init(&mgnt_mutex, "mgnt", RT_IPC_FLAG_PRIO);
rt_mutex_init(&scan_result_mutex, "scan", RT_IPC_FLAG_PRIO);
rt_mutex_init(&sta_info_mutex, "sta", RT_IPC_FLAG_PRIO);
rt_mutex_init(&complete_mutex, "complete", RT_IPC_FLAG_PRIO);
rt_mutex_init(&mgnt_mutex, "mgnt", RT_IPC_FLAG_FIFO);
rt_mutex_init(&scan_result_mutex, "scan", RT_IPC_FLAG_FIFO);
rt_mutex_init(&sta_info_mutex, "sta", RT_IPC_FLAG_FIFO);
rt_mutex_init(&complete_mutex, "complete", RT_IPC_FLAG_FIFO);
#ifdef RT_WLAN_AUTO_CONNECT_ENABLE
rt_timer_init(&reconnect_time, "wifi_tim", rt_wlan_cyclic_check, RT_NULL,
rt_tick_from_millisecond(AUTO_CONNECTION_PERIOD_MS),

View File

@ -9,7 +9,7 @@ msh.c
if GetDepend('MSH_USING_BUILT_IN_COMMANDS'):
src += ['cmd.c']
if GetDepend('DFS_USING_POSIX'):
if GetDepend('RT_USING_DFS'):
src += ['msh_file.c']
CPPPATH = [cwd]

View File

@ -751,9 +751,9 @@ long list_timer(void)
maxlen = RT_NAME_MAX;
rt_kprintf("%-*.s periodic timeout activated mode\n", maxlen, item_title);
rt_kprintf("%-*.s periodic timeout flag\n", maxlen, item_title);
object_split(maxlen);
rt_kprintf(" ---------- ---------- ----------- ---------\n");
rt_kprintf(" ---------- ---------- -----------\n");
do
{
next = list_get_next(next, &find_arg);
@ -781,13 +781,9 @@ long list_timer(void)
timer->init_tick,
timer->timeout_tick);
if (timer->parent.flag & RT_TIMER_FLAG_ACTIVATED)
rt_kprintf("activated ");
rt_kprintf("activated\n");
else
rt_kprintf("deactivated ");
if (timer->parent.flag & RT_TIMER_FLAG_PERIODIC)
rt_kprintf("periodic\n");
else
rt_kprintf("one shot\n");
rt_kprintf("deactivated\n");
}
}

View File

@ -168,8 +168,8 @@ extern struct finsh_syscall *_syscall_table_begin, *_syscall_table_end;
/* find out system call, which should be implemented in user program */
struct finsh_syscall *finsh_syscall_lookup(const char *name);
#if !defined(RT_USING_POSIX_STDIO) && defined(RT_USING_DEVICE)
void finsh_set_device(const char *device_name);
#ifdef RT_USING_DEVICE
void finsh_set_device(const char *device_name);
#endif
#endif

View File

@ -15,17 +15,19 @@
#ifdef RT_USING_FINSH
#ifndef FINSH_ARG_MAX
#define FINSH_ARG_MAX 8
#endif /* FINSH_ARG_MAX */
#define FINSH_ARG_MAX 8
#endif
#include "msh.h"
#include "shell.h"
#ifdef DFS_USING_POSIX
#include <dfs_posix.h>
#endif /* DFS_USING_POSIX */
#ifdef RT_USING_DFS
#include <dfs_posix.h>
#endif
#ifdef RT_USING_MODULE
#include <dlmodule.h>
#endif /* RT_USING_MODULE */
#include <dlmodule.h>
#endif
typedef int (*cmd_function_t)(int argc, char **argv);
@ -71,12 +73,14 @@ MSH_CMD_EXPORT_ALIAS(cmd_ps, ps, List threads in the system.);
#ifdef RT_USING_HEAP
int cmd_free(int argc, char **argv)
{
rt_uint32_t total = 0, used = 0, max_used = 0;
extern void list_mem(void);
extern void list_memheap(void);
rt_memory_info(&total, &used, &max_used);
rt_kprintf("total : %d\n", total);
rt_kprintf("used : %d\n", used);
rt_kprintf("maximum : %d\n", max_used);
#ifdef RT_USING_MEMHEAP_AS_HEAP
list_memheap();
#else /* RT_USING_MEMHEAP_AS_HEAP */
list_mem();
#endif
return 0;
}
MSH_CMD_EXPORT_ALIAS(cmd_free, free, Show the memory usage in the system.);
@ -182,7 +186,7 @@ static cmd_function_t msh_get_cmd(char *cmd, int size)
return cmd_func;
}
#if defined(RT_USING_MODULE) && defined(DFS_USING_POSIX)
#if defined(RT_USING_MODULE) && defined(RT_USING_DFS)
/* Return 0 on module executed. Other value indicate error.
*/
int msh_exec_module(const char *cmd_line, int size)
@ -253,7 +257,7 @@ int msh_exec_module(const char *cmd_line, int size)
rt_free(pg_name);
return ret;
}
#endif /* defined(RT_USING_MODULE) && defined(DFS_USING_POSIX) */
#endif /* defined(RT_USING_MODULE) && defined(RT_USING_DFS) */
static int _msh_exec_cmd(char *cmd, rt_size_t length, int *retp)
{
@ -286,7 +290,7 @@ static int _msh_exec_cmd(char *cmd, rt_size_t length, int *retp)
return 0;
}
#if defined(RT_USING_LWP) && defined(DFS_USING_POSIX)
#if defined(RT_USING_LWP) && defined(RT_USING_DFS)
static int _msh_exec_lwp(char *cmd, rt_size_t length)
{
int argc;
@ -322,7 +326,7 @@ static int _msh_exec_lwp(char *cmd, rt_size_t length)
return 0;
}
#endif /* defined(RT_USING_LWP) && defined(DFS_USING_POSIX) */
#endif /* defined(RT_USING_LWP) && defined(RT_USING_DFS) */
int msh_exec(char *cmd, rt_size_t length)
{
@ -346,7 +350,7 @@ int msh_exec(char *cmd, rt_size_t length)
{
return cmd_ret;
}
#ifdef DFS_USING_POSIX
#ifdef RT_USING_DFS
#ifdef DFS_USING_WORKDIR
if (msh_exec_script(cmd, length) == 0)
{
@ -367,7 +371,7 @@ int msh_exec(char *cmd, rt_size_t length)
return 0;
}
#endif /* RT_USING_LWP */
#endif /* DFS_USING_POSIX */
#endif /* RT_USING_DFS */
/* truncate the cmd at the first space. */
{
@ -396,7 +400,7 @@ static int str_common(const char *str1, const char *str2)
return (str - str1);
}
#ifdef DFS_USING_POSIX
#ifdef RT_USING_DFS
void msh_auto_complete_path(char *path)
{
DIR *dir = RT_NULL;
@ -517,7 +521,7 @@ void msh_auto_complete_path(char *path)
closedir(dir);
rt_free(full_path);
}
#endif /* DFS_USING_POSIX */
#endif /* RT_USING_DFS */
void msh_auto_complete(char *prefix)
{
@ -534,7 +538,7 @@ void msh_auto_complete(char *prefix)
return;
}
#ifdef DFS_USING_POSIX
#ifdef RT_USING_DFS
/* check whether a spare in the command */
{
char *ptr;
@ -560,7 +564,7 @@ void msh_auto_complete(char *prefix)
}
#endif /* RT_USING_MODULE */
}
#endif /* DFS_USING_POSIX */
#endif /* RT_USING_DFS */
/* checks in internal command */
{

View File

@ -11,7 +11,7 @@
#include <rtthread.h>
#if defined(RT_USING_FINSH) && defined(DFS_USING_POSIX)
#if defined(RT_USING_FINSH) && defined(RT_USING_DFS)
#include <finsh.h>
#include "msh.h"
@ -612,7 +612,7 @@ static int cmd_tail(int argc, char **argv)
rt_uint32_t target_line = 0;
rt_uint32_t current_line = 0;
rt_uint32_t required_lines = 0;
rt_uint32_t start_line = 0;
rt_uint32_t after_xxx_line = 0;
if (argc < 2)
{
@ -632,7 +632,7 @@ static int cmd_tail(int argc, char **argv)
}
else
{
start_line = atoi(&argv[2][1]); /* eg: +100, to get the 100 */
after_xxx_line = atoi(&argv[2][1]); /* eg: +100, to get the 100 */
}
file_name = argv[3];
}
@ -651,10 +651,6 @@ static int cmd_tail(int argc, char **argv)
while ((read(fd, &c, sizeof(char))) > 0)
{
if(total_lines == 0)
{
total_lines++;
}
if (c == '\n')
{
total_lines++;
@ -663,11 +659,11 @@ static int cmd_tail(int argc, char **argv)
rt_kprintf("\nTotal Number of lines:%d\n", total_lines);
if (start_line != 0)
if (after_xxx_line != 0)
{
if (total_lines >= start_line)
if (total_lines > after_xxx_line)
{
required_lines = total_lines - start_line + 1;
required_lines = total_lines - after_xxx_line;
}
else
{
@ -690,14 +686,14 @@ static int cmd_tail(int argc, char **argv)
while ((read(fd, &c, sizeof(char))) > 0)
{
if (current_line >= target_line)
{
rt_kprintf("%c", c);
}
if (c == '\n')
{
current_line++;
}
if (current_line > target_line)
{
rt_kprintf("%c", c);
}
}
rt_kprintf("\n");
@ -706,4 +702,5 @@ static int cmd_tail(int argc, char **argv)
}
MSH_CMD_EXPORT_ALIAS(cmd_tail, tail, print the last N - lines data of the given file);
#endif /* defined(RT_USING_FINSH) && defined(DFS_USING_POSIX) */
#endif /* defined(RT_USING_FINSH) && defined(RT_USING_DFS) */

View File

@ -27,9 +27,9 @@
#include "shell.h"
#include "msh.h"
#ifdef DFS_USING_POSIX
#include <dfs_posix.h>
#endif /* DFS_USING_POSIX */
#if defined(RT_USING_DFS)
#include <dfs_posix.h>
#endif /* RT_USING_DFS */
/* finsh thread */
#ifndef RT_USING_HEAP
@ -104,7 +104,7 @@ const char *finsh_get_prompt(void)
}
strcpy(finsh_prompt, _MSH_PROMPT);
#if defined(DFS_USING_POSIX) && defined(DFS_USING_WORKDIR)
#if defined(RT_USING_DFS) && defined(DFS_USING_WORKDIR)
/* get current working directory */
getcwd(&finsh_prompt[rt_strlen(finsh_prompt)], RT_CONSOLEBUF_SIZE - rt_strlen(finsh_prompt));
#endif
@ -145,17 +145,10 @@ void finsh_set_prompt_mode(rt_uint32_t prompt_mode)
int finsh_getchar(void)
{
#ifdef RT_USING_DEVICE
char ch = 0;
#ifdef RT_USING_POSIX_STDIO
if(read(STDIN_FILENO, &ch, 1) > 0)
{
return ch;
}
else
{
return -1; /* EOF */
}
#ifdef RT_USING_POSIX
return getchar();
#else
char ch = 0;
rt_device_t device;
RT_ASSERT(shell != RT_NULL);
@ -170,14 +163,14 @@ int finsh_getchar(void)
rt_sem_take(&shell->rx_sem, RT_WAITING_FOREVER);
return ch;
#endif /* RT_USING_POSIX_STDIO */
#endif /* RT_USING_POSIX */
#else
extern char rt_hw_console_getchar(void);
return rt_hw_console_getchar();
#endif /* RT_USING_DEVICE */
}
#if !defined(RT_USING_POSIX_STDIO) && defined(RT_USING_DEVICE)
#if !defined(RT_USING_POSIX) && defined(RT_USING_DEVICE)
static rt_err_t finsh_rx_ind(rt_device_t dev, rt_size_t size)
{
RT_ASSERT(shell != RT_NULL);
@ -241,7 +234,7 @@ const char *finsh_get_device()
RT_ASSERT(shell != RT_NULL);
return shell->device->parent.name;
}
#endif /* !defined(RT_USING_POSIX_STDIO) && defined(RT_USING_DEVICE) */
#endif
/**
* @ingroup finsh
@ -443,7 +436,7 @@ void finsh_thread_entry(void *parameter)
shell->echo_mode = 0;
#endif
#if !defined(RT_USING_POSIX_STDIO) && defined(RT_USING_DEVICE)
#if !defined(RT_USING_POSIX) && defined(RT_USING_DEVICE)
/* set console device as shell device */
if (shell->device == RT_NULL)
{
@ -453,7 +446,7 @@ void finsh_thread_entry(void *parameter)
finsh_set_device(console->parent.name);
}
}
#endif /* !defined(RT_USING_POSIX_STDIO) && defined(RT_USING_DEVICE) */
#endif
#ifdef FINSH_USING_AUTH
/* set the default password when the password isn't setting */

View File

@ -78,7 +78,7 @@ struct finsh_shell
rt_uint16_t line_position;
rt_uint16_t line_curpos;
#if !defined(RT_USING_POSIX_STDIO) && defined(RT_USING_DEVICE)
#if !defined(RT_USING_POSIX) && defined(RT_USING_DEVICE)
rt_device_t device;
#endif
@ -91,6 +91,7 @@ void finsh_set_echo(rt_uint32_t echo);
rt_uint32_t finsh_get_echo(void);
int finsh_system_init(void);
void finsh_set_device(const char *device_name);
const char *finsh_get_device(void);
int finsh_getchar(void);

View File

@ -1,2 +0,0 @@
# RT-Thread Legacy

View File

@ -1,22 +0,0 @@
from building import *
import os
src = Split('''
ipc/workqueue_legacy.c
''')
cwd = GetCurrentDir()
CPPPATH = [cwd]
if GetDepend('RT_USING_DFS'):
dfs_cwd = os.path.join(cwd,'dfs')
CPPPATH += [dfs_cwd]
group = DefineGroup('Legacy', src, depend = ['RT_USING_LEGACY'], CPPPATH = CPPPATH)
list = os.listdir(cwd)
for item in list:
if os.path.isfile(os.path.join(cwd, item, 'SConscript')):
group = group + SConscript(os.path.join(item, 'SConscript'))
Return('group')

View File

@ -1,18 +0,0 @@
/*
* Copyright (c) 2006-2021, RT-Thread Development Team
*
* SPDX-License-Identifier: Apache-2.0
*
* Change Logs:
* Date Author Notes
* 2021-11-14 Meco Man the first version
*/
#include "workqueue_legacy.h"
void rt_delayed_work_init(struct rt_delayed_work *work,
void (*work_func)(struct rt_work *work,
void *work_data), void *work_data)
{
rt_work_init(&work->work, work_func, work_data);
}

View File

@ -1,25 +0,0 @@
/*
* Copyright (c) 2006-2021, RT-Thread Development Team
*
* SPDX-License-Identifier: Apache-2.0
*
* Change Logs:
* Date Author Notes
* 2021-11-14 Meco Man the first version
*/
#ifndef __WORKQUEUE_LEGACY_H__
#define __WORKQUEUE_LEGACY_H__
#include <ipc/workqueue.h>
struct rt_delayed_work
{
struct rt_work work;
};
void rt_delayed_work_init(struct rt_delayed_work *work,
void (*work_func)(struct rt_work *work,
void *work_data), void *work_data);
#endif

View File

@ -1,27 +0,0 @@
/*
* Copyright (c) 2006-2021, RT-Thread Development Team
*
* SPDX-License-Identifier: Apache-2.0
*
* Change Logs:
* Date Author Notes
* 2021-11-14 Meco Man the first version
*/
#ifndef __RT_LEGACY_H__
#define __RT_LEGACY_H__
#include <rtconfig.h>
/* rtlibc */
#include <stdint.h>
#include <stddef.h>
/* IPC */
#ifdef RT_USING_DEVICE_IPC
#include "ipc/workqueue_legacy.h"
#endif /* RT_USING_DEVICE_IPC */
/* FinSH */
#endif /* __RT_LEGACY_H__ */

View File

@ -1,20 +1,71 @@
menu "POSIX layer and C standard library"
config RT_USING_MODULE
bool "Enable dynamic module with dlopen/dlsym/dlclose feature"
config RT_USING_LIBC
bool "Enable libc APIs from toolchain"
default y
config RT_USING_PTHREADS
bool "Enable pthreads APIs"
default n
if RT_USING_MODULE
if RT_USING_PTHREADS
config PTHREAD_NUM_MAX
int "Maximum number of pthreads"
default 8
endif
if RT_USING_LIBC && RT_USING_DFS
config RT_USING_POSIX
bool "Enable POSIX layer for compatibility with UNIX APIs, poll/select etc"
select RT_USING_DFS_DEVFS
default y
if RT_USING_POSIX
config RT_USING_POSIX_MMAP
bool "Enable mmap() API"
default n
config RT_USING_POSIX_TERMIOS
bool "Enable termios APIs"
default n
config RT_USING_POSIX_GETLINE
bool "Enable getline()/getdelim() APIs"
default n
config RT_USING_POSIX_AIO
bool "Enable AIO"
default n
endif
endif
if RT_USING_LIBC
config RT_LIBC_USING_TIME
default y
config RT_USING_MODULE
bool "Enable dynamic module with dlopen/dlsym/dlclose feature"
default n
if RT_USING_MODULE
config RT_USING_CUSTOM_DLMODULE
bool "Enable load dynamic module by custom"
default n
endif
endif
if RT_USING_LIBC != y
config RT_LIBC_USING_TIME
bool "Enable time functions without compiler's libc"
default y
endif
config RT_LIBC_DEFAULT_TIMEZONE
depends on (RT_LIBC_USING_TIME || RT_USING_LIBC)
int "Set the default time zone (UTC+)"
range -12 12
default 8
source "$RTT_DIR/components/libc/posix/Kconfig"
endmenu

View File

@ -0,0 +1,11 @@
# RT-Thread building script for component
from building import *
cwd = GetCurrentDir()
src = Glob('*.c') + Glob('*.cpp')
CPPPATH = [cwd]
group = DefineGroup('libc', src, depend = ['RT_USING_POSIX', 'RT_USING_POSIX_AIO'], CPPPATH = CPPPATH)
Return('group')

View File

@ -11,7 +11,7 @@
#include <stdint.h>
#include <rthw.h>
#include <dfs_posix.h>
#include "aio.h"
#include "posix_aio.h"
struct rt_workqueue* aio_queue = NULL;

View File

@ -8,8 +8,8 @@
* 2017/12/30 Bernard The first version.
*/
#ifndef __AIO_H__
#define __AIO_H__
#ifndef POSIX_AIO_H__
#define POSIX_AIO_H__
#include <stdio.h>
#include <sys/signal.h>

View File

@ -1,3 +1,9 @@
# ARMLIB (Keil-MDK) porting for RT-Thread
Please define RT_USING_LIBC and compile RT-Thread with Keil-MDK compiler.
## More Information
https://www.keil.com/support/man/docs/armlib/

View File

@ -1,12 +1,21 @@
from building import *
Import('rtconfig')
src = Glob('*.c')
src = Glob('*.c') + Glob('*.cpp')
cwd = GetCurrentDir()
group = []
CPPPATH = [cwd]
CPPDEFINES = ['RT_USING_ARM_LIBC']
if GetDepend('RT_USING_DFS') == False:
SrcRemove(src, ['stdio.c'])
if GetDepend('RT_USING_MODULE') == False:
SrcRemove(src, ['libc_syms.c'])
if rtconfig.PLATFORM == 'armcc' or rtconfig.PLATFORM == 'armclang':
group = DefineGroup('Compiler', src, depend = [''], CPPDEFINES = CPPDEFINES)
group = DefineGroup('libc', src, depend = ['RT_USING_LIBC'],
CPPPATH = CPPPATH, CPPDEFINES = CPPDEFINES)
Return('group')

View File

@ -0,0 +1,40 @@
/*
* Copyright (c) 2006-2021, RT-Thread Development Team
*
* SPDX-License-Identifier: Apache-2.0
*
* Change Logs:
* Date Author Notes
* 2017/10/15 bernard the first version
*/
#include <fcntl.h>
#include <rtthread.h>
#include "libc.h"
#ifdef RT_USING_PTHREADS
#include <pthread.h>
#endif
int libc_system_init(void)
{
#if defined(RT_USING_DFS) & defined(RT_USING_DFS_DEVFS)
rt_device_t dev_console;
dev_console = rt_console_get_device();
if (dev_console)
{
#if defined(RT_USING_POSIX)
libc_stdio_set_console(dev_console->parent.name, O_RDWR);
#else
libc_stdio_set_console(dev_console->parent.name, O_WRONLY);
#endif
}
#endif
#if defined RT_USING_PTHREADS && !defined RT_USING_COMPONENTS_INIT
pthread_system_init();
#endif
return 0;
}
INIT_COMPONENT_EXPORT(libc_system_init);

View File

@ -0,0 +1,25 @@
/*
* Copyright (c) 2006-2021, RT-Thread Development Team
*
* SPDX-License-Identifier: Apache-2.0
*
* Change Logs:
* Date Author Notes
* 2017/10/15 bernard the first version
*/
#ifndef __RTT_LIBC_H__
#define __RTT_LIBC_H__
#ifdef __cplusplus
extern "C" {
#endif
int libc_system_init(void);
int libc_stdio_get_console(void);
int libc_stdio_set_console(const char* device_name, int mode);
#ifdef __cplusplus
}
#endif
#endif

View File

@ -0,0 +1,43 @@
/*
* Copyright (c) 2006-2021, RT-Thread Development Team
*
* SPDX-License-Identifier: Apache-2.0
*
* Change Logs:
* 2014-08-03 bernard Add file header.
*/
#include <rtthread.h>
#include <stddef.h>
#ifdef RT_USING_HEAP
#ifdef __CC_ARM
/* avoid the heap and heap-using library functions supplied by arm */
#pragma import(__use_no_heap)
#endif
void *malloc(size_t n)
{
return rt_malloc(n);
}
RTM_EXPORT(malloc);
void *realloc(void *rmem, size_t newsize)
{
return rt_realloc(rmem, newsize);
}
RTM_EXPORT(realloc);
void *calloc(size_t nelem, size_t elsize)
{
return rt_calloc(nelem, elsize);
}
RTM_EXPORT(calloc);
void free(void *rmem)
{
rt_free(rmem);
}
RTM_EXPORT(free);
#endif

View File

@ -0,0 +1,51 @@
/*
* Copyright (c) 2006-2021, RT-Thread Development Team
*
* SPDX-License-Identifier: Apache-2.0
*
* Change Logs:
* Date Author Notes
* 2017/10/15 bernard implement stdio for armcc.
*/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <rtthread.h>
#include "libc.h"
#if defined(RT_USING_DFS) && defined(RT_USING_DFS_DEVFS)
#include <dfs_posix.h>
#define STDIO_DEVICE_NAME_MAX 32
static int std_fd = -1;
int libc_stdio_set_console(const char* device_name, int mode)
{
int fd;
char name[STDIO_DEVICE_NAME_MAX];
snprintf(name, sizeof(name) - 1, "/dev/%s", device_name);
name[STDIO_DEVICE_NAME_MAX - 1] = '\0';
fd = open(name, mode, 0);
if (fd >= 0)
{
if (std_fd >= 0)
{
close(std_fd);
}
std_fd = fd;
}
return std_fd;
}
int libc_stdio_get_console(void)
{
return std_fd;
}
#endif

Some files were not shown because too many files have changed in this diff Show More