diff --git a/rt-thread/README.md b/rt-thread/README.md
index 60cebfe..d0ca35c 100644
--- a/rt-thread/README.md
+++ b/rt-thread/README.md
@@ -1,8 +1,6 @@
-
-
-
+# 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 architectures and chips.
+- 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).
-
diff --git a/rt-thread/README_zh.md b/rt-thread/README_zh.md
index da67724..9cdfa30 100644
--- a/rt-thread/README_zh.md
+++ b/rt-thread/README_zh.md
@@ -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 RAM,3KB 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)
# 贡献代码
diff --git a/rt-thread/components/Kconfig b/rt-thread/components/Kconfig
index f99ede2..9a9efa8 100644
--- a/rt-thread/components/Kconfig
+++ b/rt-thread/components/Kconfig
@@ -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"
diff --git a/rt-thread/components/cplusplus/Kconfig b/rt-thread/components/cplusplus/Kconfig
index 0877ff9..dfab433 100644
--- a/rt-thread/components/cplusplus/Kconfig
+++ b/rt-thread/components/cplusplus/Kconfig
@@ -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
diff --git a/rt-thread/components/cplusplus/README.md b/rt-thread/components/cplusplus/README.md
index 46c8c78..d02048d 100644
--- a/rt-thread/components/cplusplus/README.md
+++ b/rt-thread/components/cplusplus/README.md
@@ -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:
diff --git a/rt-thread/components/cplusplus/cpp11/armclang/thread.cpp b/rt-thread/components/cplusplus/cpp11/armclang/thread.cpp
index e10ffb9..46306ec 100644
--- a/rt-thread/components/cplusplus/cpp11/armclang/thread.cpp
+++ b/rt-thread/components/cplusplus/cpp11/armclang/thread.cpp
@@ -13,18 +13,19 @@
#include
#include
-#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;
diff --git a/rt-thread/components/cplusplus/cpp11/gcc/mutex b/rt-thread/components/cplusplus/cpp11/gcc/mutex
index 3fdf866..cc593cc 100644
--- a/rt-thread/components/cplusplus/cpp11/gcc/mutex
+++ b/rt-thread/components/cplusplus/cpp11/gcc/mutex
@@ -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
@@ -509,4 +509,4 @@ namespace std
}
}
-//#endif //(RT_USING_PTHREADS)
\ No newline at end of file
+//#endif // (RT_USING_LIBC) && (RT_USING_PTHREADS)
\ No newline at end of file
diff --git a/rt-thread/components/cplusplus/cpp11/gcc/mutex.cpp b/rt-thread/components/cplusplus/cpp11/gcc/mutex.cpp
index e11f6d8..014460f 100644
--- a/rt-thread/components/cplusplus/cpp11/gcc/mutex.cpp
+++ b/rt-thread/components/cplusplus/cpp11/gcc/mutex.cpp
@@ -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 once_call = std::move(once_functor);
// no need to hold the lock anymore
- unique_lock* lock_ptr = get_once_functor_lock_ptr();
+ unique_lock* lock_ptr = get_once_functor_lock_ptr();
get_once_functor_lock_ptr() = nullptr;
lock_ptr->unlock();
diff --git a/rt-thread/components/cplusplus/cpp11/gcc/thread b/rt-thread/components/cplusplus/cpp11/gcc/thread
index 60e3ec9..5b64dec 100644
--- a/rt-thread/components/cplusplus/cpp11/gcc/thread
+++ b/rt-thread/components/cplusplus/cpp11/gcc/thread
@@ -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
#include
diff --git a/rt-thread/components/cplusplus/cpp11/gcc/thread.cpp b/rt-thread/components/cplusplus/cpp11/gcc/thread.cpp
index 3979da0..947170d 100644
--- a/rt-thread/components/cplusplus/cpp11/gcc/thread.cpp
+++ b/rt-thread/components/cplusplus/cpp11/gcc/thread.cpp
@@ -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;
diff --git a/rt-thread/components/cplusplus/cxx_Mutex.cpp b/rt-thread/components/cplusplus/cxx_Mutex.cpp
index da6f809..97d8fa8 100644
--- a/rt-thread/components/cplusplus/cxx_Mutex.cpp
+++ b/rt-thread/components/cplusplus/cxx_Mutex.cpp
@@ -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)
diff --git a/rt-thread/components/cplusplus/cxx_crt_init.c b/rt-thread/components/cplusplus/cxx_crt_init.c
index 4694608..977dee6 100644
--- a/rt-thread/components/cplusplus/cxx_crt_init.c
+++ b/rt-thread/components/cplusplus/cxx_crt_init.c
@@ -13,7 +13,7 @@
#include
-#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.
diff --git a/rt-thread/components/dfs/Kconfig b/rt-thread/components/dfs/Kconfig
index b93c655..7a4fbb6 100644
--- a/rt-thread/components/dfs/Kconfig
+++ b/rt-thread/components/dfs/Kconfig
@@ -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"
diff --git a/rt-thread/components/dfs/SConscript b/rt-thread/components/dfs/SConscript
index 18b4721..e449c84 100644
--- a/rt-thread/components/dfs/SConscript
+++ b/rt-thread/components/dfs/SConscript
@@ -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)
diff --git a/rt-thread/components/dfs/filesystems/.ignore_format.yml b/rt-thread/components/dfs/filesystems/.ignore_format.yml
new file mode 100644
index 0000000..e72719d
--- /dev/null
+++ b/rt-thread/components/dfs/filesystems/.ignore_format.yml
@@ -0,0 +1,4 @@
+# files format check exclude path, please follow the instructions below to modify;
+
+dir_path:
+- elmfat
diff --git a/rt-thread/components/dfs/filesystems/devfs/devfs.c b/rt-thread/components/dfs/filesystems/devfs/devfs.c
index d60f7dd..d615482 100644
--- a/rt-thread/components/dfs/filesystems/devfs/devfs.c
+++ b/rt-thread/components/dfs/filesystems/devfs/devfs.c
@@ -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)
diff --git a/rt-thread/components/dfs/filesystems/elmfat/00history.txt b/rt-thread/components/dfs/filesystems/elmfat/00history.txt
index 8a0169b..cb8753b 100644
--- a/rt-thread/components/dfs/filesystems/elmfat/00history.txt
+++ b/rt-thread/components/dfs/filesystems/elmfat/00history.txt
@@ -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 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.
-
-
diff --git a/rt-thread/components/dfs/filesystems/elmfat/00readme.txt b/rt-thread/components/dfs/filesystems/elmfat/00readme.txt
index 4960997..234c675 100644
--- a/rt-thread/components/dfs/filesystems/elmfat/00readme.txt
+++ b/rt-thread/components/dfs/filesystems/elmfat/00readme.txt
@@ -1,4 +1,4 @@
-FatFs Module Source Files R0.14b
+FatFs Module Source Files R0.14
FILES
diff --git a/rt-thread/components/dfs/filesystems/elmfat/dfs_elm.c b/rt-thread/components/dfs/filesystems/elmfat/dfs_elm.c
index b7cdaf8..01d303f 100644
--- a/rt-thread/components/dfs/filesystems/elmfat/dfs_elm.c
+++ b/rt-thread/components/dfs/filesystems/elmfat/dfs_elm.c
@@ -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;
diff --git a/rt-thread/components/dfs/filesystems/elmfat/diskio.h b/rt-thread/components/dfs/filesystems/elmfat/diskio.h
index e4ead78..511269c 100644
--- a/rt-thread/components/dfs/filesystems/elmfat/diskio.h
+++ b/rt-thread/components/dfs/filesystems/elmfat/diskio.h
@@ -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
}
diff --git a/rt-thread/components/dfs/filesystems/elmfat/ff.c b/rt-thread/components/dfs/filesystems/elmfat/ff.c
index 815c3d2..39307f2 100644
--- a/rt-thread/components/dfs/filesystems/elmfat/ff.c
+++ b/rt-thread/components/dfs/filesystems/elmfat/ff.c
@@ -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
@@ -19,7 +19,6 @@
/----------------------------------------------------------------------------*/
-#include
#include "ff.h" /* Declarations of FatFs API */
#include "diskio.h" /* Declarations of device I/O functions */
@@ -30,7 +29,7 @@
---------------------------------------------------------------------------*/
-#if FF_DEFINED != 86631 /* Revision ID */
+#if FF_DEFINED != 86606 /* Revision ID */
#error Wrong include file (ff.h).
#endif
@@ -48,8 +47,6 @@
#define IsUpper(c) ((c) >= 'A' && (c) <= 'Z')
#define IsLower(c) ((c) >= 'a' && (c) <= 'z')
#define IsDigit(c) ((c) >= '0' && (c) <= '9')
-#define IsSeparator(c) ((c) == '/' || (c) == '\\')
-#define IsTerminator(c) ((UINT)(c) < (FF_USE_LFN ? ' ' : '!'))
#define IsSurrogate(c) ((c) >= 0xD800 && (c) <= 0xDFFF)
#define IsSurrogateH(c) ((c) >= 0xD800 && (c) <= 0xDBFF)
#define IsSurrogateL(c) ((c) >= 0xDC00 && (c) <= 0xDFFF)
@@ -64,8 +61,7 @@
/* Additional file attribute bits for internal use */
#define AM_VOL 0x08 /* Volume label */
#define AM_LFN 0x0F /* LFN entry */
-#define AM_MASK 0x3F /* Mask of defined bits in FAT */
-#define AM_MASKX 0x37 /* Mask of defined bits in exFAT */
+#define AM_MASK 0x3F /* Mask of defined bits */
/* Name status flags in fn[11] */
@@ -237,7 +233,7 @@
/* Re-entrancy related */
#if FF_FS_REENTRANT
#if FF_USE_LFN == 1
-#error Static LFN work area cannot be used in thread-safe configuration
+#error Static LFN work area cannot be used at thread-safe configuration
#endif
#define LEAVE_FF(fs, res) { unlock_fs(fs, res); return res; }
#else
@@ -248,10 +244,10 @@
/* Definitions of logical drive - physical location conversion */
#if FF_MULTI_PARTITION
#define LD2PD(vol) VolToPart[vol].pd /* Get physical drive number */
-#define LD2PT(vol) VolToPart[vol].pt /* Get partition number (0:auto search, 1..:forced partition number) */
+#define LD2PT(vol) VolToPart[vol].pt /* Get partition index */
#else
#define LD2PD(vol) (BYTE)(vol) /* Each logical drive is associated with the same physical drive number */
-#define LD2PT(vol) 0 /* Auto partition search */
+#define LD2PT(vol) 0 /* Find first valid partition or in SFD */
#endif
@@ -560,7 +556,7 @@ static WCHAR LfnBuf[FF_MAX_LFN + 1]; /* LFN working buffer */
/* Code conversion tables */
/*--------------------------------*/
-#if FF_CODE_PAGE == 0 /* Run-time code page configuration */
+#if FF_CODE_PAGE == 0 /* Run-time code page configuration */
#define CODEPAGE CodePage
static WORD CodePage; /* Current code page */
static const BYTE *ExCvt, *DbcTbl; /* Pointer to current SBCS up-case table and DBCS code range table below */
@@ -684,6 +680,53 @@ static void st_qword (BYTE* ptr, QWORD val) /* Store an 8-byte word in little-en
/* String functions */
/*-----------------------------------------------------------------------*/
+/* Copy memory to memory */
+static void mem_cpy (void* dst, const void* src, UINT cnt)
+{
+ BYTE *d = (BYTE*)dst;
+ const BYTE *s = (const BYTE*)src;
+
+ if (cnt != 0) {
+ do {
+ *d++ = *s++;
+ } while (--cnt);
+ }
+}
+
+
+/* Fill memory block */
+static void mem_set (void* dst, int val, UINT cnt)
+{
+ BYTE *d = (BYTE*)dst;
+
+ do {
+ *d++ = (BYTE)val;
+ } while (--cnt);
+}
+
+
+/* Compare memory block */
+static int mem_cmp (const void* dst, const void* src, UINT cnt) /* ZR:same, NZ:different */
+{
+ const BYTE *d = (const BYTE *)dst, *s = (const BYTE *)src;
+ int r = 0;
+
+ do {
+ r = *d++ - *s++;
+ } while (--cnt && r == 0);
+
+ return r;
+}
+
+
+/* Check if chr is contained in the string */
+static int chk_chr (const char* str, int chr) /* NZ:contained, ZR:not contained */
+{
+ while (*str && *str != chr) str++;
+ return *str;
+}
+
+
/* Test if the byte is DBC 1st byte */
static int dbc_1st (BYTE c)
{
@@ -752,14 +795,18 @@ static DWORD tchar2uni ( /* Returns a character in UTF-16 encoding (>=0x10000 on
uc = (BYTE)*p++; /* Get an encoding unit */
if (uc & 0x80) { /* Multiple byte code? */
- if ((uc & 0xE0) == 0xC0) { /* 2-byte sequence? */
+ if ((uc & 0xE0) == 0xC0) { /* 2-byte sequence? */
uc &= 0x1F; nf = 1;
- } else if ((uc & 0xF0) == 0xE0) { /* 3-byte sequence? */
- uc &= 0x0F; nf = 2;
- } else if ((uc & 0xF8) == 0xF0) { /* 4-byte sequence? */
- uc &= 0x07; nf = 3;
- } else { /* Wrong sequence */
- return 0xFFFFFFFF;
+ } else {
+ if ((uc & 0xF0) == 0xE0) { /* 3-byte sequence? */
+ uc &= 0x0F; nf = 2;
+ } else {
+ if ((uc & 0xF8) == 0xF0) { /* 4-byte sequence? */
+ uc &= 0x07; nf = 3;
+ } else { /* Wrong sequence */
+ return 0xFFFFFFFF;
+ }
+ }
}
do { /* Get trailing bytes */
b = (BYTE)*p++;
@@ -797,8 +844,8 @@ static DWORD tchar2uni ( /* Returns a character in UTF-16 encoding (>=0x10000 on
}
-/* Store a Unicode char in defined API encoding */
-static UINT put_utf ( /* Returns number of encoding units written (0:buffer overflow or wrong encoding) */
+/* Output a TCHAR string in defined API encoding */
+static BYTE put_utf ( /* Returns number of encoding units written (0:buffer overflow or wrong encoding) */
DWORD chr, /* UTF-16 encoded character (Surrogate pair if >=0x10000) */
TCHAR* buf, /* Output buffer */
UINT szb /* Size of the buffer */
@@ -964,7 +1011,7 @@ static UINT inc_lock ( /* Increment object open counter and returns its index (0
&& Files[i].ofs == dp->dptr) break;
}
- if (i == FF_FS_LOCK) { /* Not opened. Register it as new. */
+ if (i == FF_FS_LOCK) { /* Not opened. Register it as new. */
for (i = 0; i < FF_FS_LOCK && Files[i].fs; i++) ;
if (i == FF_FS_LOCK) return 0; /* No free entry to register (int err) */
Files[i].fs = dp->obj.fs;
@@ -991,13 +1038,13 @@ static FRESULT dec_lock ( /* Decrement object open counter */
if (--i < FF_FS_LOCK) { /* Index number origin from 0 */
n = Files[i].ctr;
- if (n == 0x100) n = 0; /* If write mode open, delete the entry */
- if (n > 0) n--; /* Decrement read mode open count */
+ if (n == 0x100) n = 0; /* If write mode open, delete the entry */
+ if (n > 0) n--; /* Decrement read mode open count */
Files[i].ctr = n;
if (n == 0) Files[i].fs = 0; /* Delete the entry if open count gets zero */
res = FR_OK;
} else {
- res = FR_INT_ERR; /* Invalid index nunber */
+ res = FR_INT_ERR; /* Invalid index nunber */
}
return res;
}
@@ -1086,13 +1133,14 @@ static FRESULT sync_fs ( /* Returns FR_OK or FR_DISK_ERR */
if (res == FR_OK) {
if (fs->fs_type == FS_FAT32 && fs->fsi_flag == 1) { /* FAT32: Update FSInfo sector if needed */
/* Create FSInfo structure */
- memset(fs->win, 0, sizeof fs->win);
- st_word(fs->win + BS_55AA, 0xAA55); /* Boot signature */
- st_dword(fs->win + FSI_LeadSig, 0x41615252); /* Leading signature */
- st_dword(fs->win + FSI_StrucSig, 0x61417272); /* Structure signature */
- st_dword(fs->win + FSI_Free_Count, fs->free_clst); /* Number of free clusters */
- st_dword(fs->win + FSI_Nxt_Free, fs->last_clst); /* Last allocated culuster */
- fs->winsect = fs->volbase + 1; /* Write it into the FSInfo sector (Next to VBR) */
+ mem_set(fs->win, 0, sizeof fs->win);
+ st_word(fs->win + BS_55AA, 0xAA55);
+ st_dword(fs->win + FSI_LeadSig, 0x41615252);
+ st_dword(fs->win + FSI_StrucSig, 0x61417272);
+ st_dword(fs->win + FSI_Free_Count, fs->free_clst);
+ st_dword(fs->win + FSI_Nxt_Free, fs->last_clst);
+ /* Write it into the FSInfo sector */
+ fs->winsect = fs->volbase + 1;
disk_write(fs->pdrv, fs->win, fs->winsect, 1);
fs->fsi_flag = 0;
}
@@ -1125,7 +1173,7 @@ static LBA_t clst2sect ( /* !=0:Sector number, 0:Failed (invalid cluster#) */
/*-----------------------------------------------------------------------*/
-/* FAT access - Read value of an FAT entry */
+/* FAT access - Read value of a FAT entry */
/*-----------------------------------------------------------------------*/
static DWORD get_fat ( /* 0xFFFFFFFF:Disk error, 1:Internal error, 2..0x7FFFFFFF:Cluster status */
@@ -1187,8 +1235,7 @@ static DWORD get_fat ( /* 0xFFFFFFFF:Disk error, 1:Internal error, 2..0x7FFFFFF
break;
}
}
- val = 1; /* Internal error */
- break;
+ /* go to default */
#endif
default:
val = 1; /* Internal error */
@@ -1203,7 +1250,7 @@ static DWORD get_fat ( /* 0xFFFFFFFF:Disk error, 1:Internal error, 2..0x7FFFFFF
#if !FF_FS_READONLY
/*-----------------------------------------------------------------------*/
-/* FAT access - Change value of an FAT entry */
+/* FAT access - Change value of a FAT entry */
/*-----------------------------------------------------------------------*/
static FRESULT put_fat ( /* FR_OK(0):succeeded, !=0:error */
@@ -1219,12 +1266,12 @@ static FRESULT put_fat ( /* FR_OK(0):succeeded, !=0:error */
if (clst >= 2 && clst < fs->n_fatent) { /* Check if in valid range */
switch (fs->fs_type) {
- case FS_FAT12:
+ case FS_FAT12 :
bc = (UINT)clst; bc += bc / 2; /* bc: byte offset of the entry */
res = move_window(fs, fs->fatbase + (bc / SS(fs)));
if (res != FR_OK) break;
p = fs->win + bc++ % SS(fs);
- *p = (clst & 1) ? ((*p & 0x0F) | ((BYTE)val << 4)) : (BYTE)val; /* Update 1st byte */
+ *p = (clst & 1) ? ((*p & 0x0F) | ((BYTE)val << 4)) : (BYTE)val; /* Update 1st byte */
fs->wflag = 1;
res = move_window(fs, fs->fatbase + (bc / SS(fs)));
if (res != FR_OK) break;
@@ -1233,16 +1280,16 @@ static FRESULT put_fat ( /* FR_OK(0):succeeded, !=0:error */
fs->wflag = 1;
break;
- case FS_FAT16:
+ case FS_FAT16 :
res = move_window(fs, fs->fatbase + (clst / (SS(fs) / 2)));
if (res != FR_OK) break;
st_word(fs->win + clst * 2 % SS(fs), (WORD)val); /* Simple WORD array */
fs->wflag = 1;
break;
- case FS_FAT32:
+ case FS_FAT32 :
#if FF_FS_EXFAT
- case FS_EXFAT:
+ case FS_EXFAT :
#endif
res = move_window(fs, fs->fatbase + (clst / (SS(fs) / 4)));
if (res != FR_OK) break;
@@ -1637,12 +1684,12 @@ static FRESULT dir_clear ( /* Returns FR_OK or FR_DISK_ERR */
if (sync_window(fs) != FR_OK) return FR_DISK_ERR; /* Flush disk access window */
sect = clst2sect(fs, clst); /* Top of the cluster */
fs->winsect = sect; /* Set window to top of the cluster */
- memset(fs->win, 0, sizeof fs->win); /* Clear window buffer */
+ mem_set(fs->win, 0, sizeof fs->win); /* Clear window buffer */
#if FF_USE_LFN == 3 /* Quick table clear by using multi-secter write */
/* Allocate a temporary buffer */
for (szb = ((DWORD)fs->csize * SS(fs) >= MAX_MALLOC) ? MAX_MALLOC : fs->csize * SS(fs), ibuf = 0; szb > SS(fs) && (ibuf = ff_memalloc(szb)) == 0; szb /= 2) ;
if (szb > SS(fs)) { /* Buffer allocated? */
- memset(ibuf, 0, szb);
+ mem_set(ibuf, 0, szb);
szb /= SS(fs); /* Bytes -> Sectors */
for (n = 0; n < fs->csize && disk_write(fs->pdrv, ibuf, sect + n, szb) == RES_OK; n += szb) ; /* Fill the cluster with 0 */
ff_memfree(ibuf);
@@ -1774,7 +1821,7 @@ static FRESULT dir_next ( /* FR_OK(0):succeeded, FR_NO_FILE:End of table, FR_DEN
static FRESULT dir_alloc ( /* FR_OK(0):succeeded, !=0:error */
DIR* dp, /* Pointer to the directory object */
- UINT n_ent /* Number of contiguous entries to allocate */
+ UINT nent /* Number of contiguous entries to allocate */
)
{
FRESULT res;
@@ -1789,16 +1836,16 @@ static FRESULT dir_alloc ( /* FR_OK(0):succeeded, !=0:error */
res = move_window(fs, dp->sect);
if (res != FR_OK) break;
#if FF_FS_EXFAT
- if ((fs->fs_type == FS_EXFAT) ? (int)((dp->dir[XDIR_Type] & 0x80) == 0) : (int)(dp->dir[DIR_Name] == DDEM || dp->dir[DIR_Name] == 0)) { /* Is the entry free? */
+ if ((fs->fs_type == FS_EXFAT) ? (int)((dp->dir[XDIR_Type] & 0x80) == 0) : (int)(dp->dir[DIR_Name] == DDEM || dp->dir[DIR_Name] == 0)) {
#else
- if (dp->dir[DIR_Name] == DDEM || dp->dir[DIR_Name] == 0) { /* Is the entry free? */
+ if (dp->dir[DIR_Name] == DDEM || dp->dir[DIR_Name] == 0) {
#endif
- if (++n == n_ent) break; /* Is a block of contiguous free entries found? */
+ if (++n == nent) break; /* A block of contiguous free entries is found */
} else {
- n = 0; /* Not a free entry, restart to search */
+ n = 0; /* Not a blank entry. Restart to search */
}
- res = dir_next(dp, 1); /* Next entry with table stretch enabled */
- } while (res == FR_OK);
+ res = dir_next(dp, 1);
+ } while (res == FR_OK); /* Next entry with table stretch enabled */
}
if (res == FR_NO_FILE) res = FR_DENIED; /* No directory entry to allocate */
@@ -1946,7 +1993,7 @@ static void put_lfn (
do {
if (wc != 0xFFFF) wc = lfn[i++]; /* Get an effective character */
st_word(dir + LfnOfs[s], wc); /* Put it */
- if (wc == 0) wc = 0xFFFF; /* Padding characters for following items */
+ if (wc == 0) wc = 0xFFFF; /* Padding characters for following items */
} while (++s < 13);
if (wc == 0xFFFF || !lfn[i]) ord |= LLEF; /* Last LFN part is the start of LFN sequence */
dir[LDIR_Ord] = ord; /* Set the LFN order */
@@ -1964,7 +2011,7 @@ static void put_lfn (
static void gen_numname (
BYTE* dst, /* Pointer to the buffer to store numbered SFN */
- const BYTE* src, /* Pointer to SFN in directory form */
+ const BYTE* src, /* Pointer to SFN */
const WCHAR* lfn, /* Pointer to LFN */
UINT seq /* Sequence number */
)
@@ -1975,7 +2022,7 @@ static void gen_numname (
DWORD sreg;
- memcpy(dst, src, 11); /* Prepare the SFN to be modified */
+ mem_cpy(dst, src, 11);
if (seq > 5) { /* In case of many collisions, generate a hash number instead of sequential number */
sreg = seq;
@@ -1990,23 +2037,24 @@ static void gen_numname (
seq = (UINT)sreg;
}
- /* Make suffix (~ + hexdecimal) */
+ /* itoa (hexdecimal) */
i = 7;
do {
- c = (BYTE)((seq % 16) + '0'); seq /= 16;
+ c = (BYTE)((seq % 16) + '0');
if (c > '9') c += 7;
ns[i--] = c;
- } while (i && seq);
+ seq /= 16;
+ } while (seq);
ns[i] = '~';
- /* Append the suffix to the SFN body */
- for (j = 0; j < i && dst[j] != ' '; j++) { /* Find the offset to append */
- if (dbc_1st(dst[j])) { /* To avoid DBC break up */
+ /* Append the number to the SFN body */
+ for (j = 0; j < i && dst[j] != ' '; j++) {
+ if (dbc_1st(dst[j])) {
if (j == i - 1) break;
j++;
}
}
- do { /* Append the suffix */
+ do {
dst[j++] = (i < 8) ? ns[i++] : ' ';
} while (j < 8);
}
@@ -2091,6 +2139,47 @@ static DWORD xsum32 ( /* Returns 32-bit checksum */
#endif
+#if FF_FS_MINIMIZE <= 1 || FF_FS_RPATH >= 2
+/*------------------------------------------------------*/
+/* exFAT: Get object information from a directory block */
+/*------------------------------------------------------*/
+
+static void get_xfileinfo (
+ BYTE* dirb, /* Pointer to the direcotry entry block 85+C0+C1s */
+ FILINFO* fno /* Buffer to store the extracted file information */
+)
+{
+ WCHAR wc, hs;
+ UINT di, si, nc;
+
+ /* Get file name from the entry block */
+ si = SZDIRE * 2; /* 1st C1 entry */
+ nc = 0; hs = 0; di = 0;
+ while (nc < dirb[XDIR_NumName]) {
+ if (si >= MAXDIRB(FF_MAX_LFN)) { di = 0; break; } /* Truncated directory block? */
+ if ((si % SZDIRE) == 0) si += 2; /* Skip entry type field */
+ wc = ld_word(dirb + si); si += 2; nc++; /* Get a character */
+ if (hs == 0 && IsSurrogate(wc)) { /* Is it a surrogate? */
+ hs = wc; continue; /* Get low surrogate */
+ }
+ wc = put_utf((DWORD)hs << 16 | wc, &fno->fname[di], FF_LFN_BUF - di); /* Store it in API encoding */
+ if (wc == 0) { di = 0; break; } /* Buffer overflow or wrong encoding? */
+ di += wc;
+ hs = 0;
+ }
+ if (hs != 0) di = 0; /* Broken surrogate pair? */
+ if (di == 0) fno->fname[di++] = '?'; /* Inaccessible object name? */
+ fno->fname[di] = 0; /* Terminate the name */
+ fno->altname[0] = 0; /* exFAT does not support SFN */
+
+ fno->fattrib = dirb[XDIR_Attr]; /* Attribute */
+ fno->fsize = (fno->fattrib & AM_DIR) ? 0 : ld_qword(dirb + XDIR_FileSize); /* Size */
+ fno->ftime = ld_word(dirb + XDIR_ModTime + 0); /* Time */
+ fno->fdate = ld_word(dirb + XDIR_ModTime + 2); /* Date */
+}
+
+#endif /* FF_FS_MINIMIZE <= 1 || FF_FS_RPATH >= 2 */
+
/*-----------------------------------*/
/* exFAT: Get a directry entry block */
@@ -2102,28 +2191,28 @@ static FRESULT load_xdir ( /* FR_INT_ERR: invalid entry block */
{
FRESULT res;
UINT i, sz_ent;
- BYTE *dirb = dp->obj.fs->dirbuf; /* Pointer to the on-memory direcotry entry block 85+C0+C1s */
+ BYTE* dirb = dp->obj.fs->dirbuf; /* Pointer to the on-memory direcotry entry block 85+C0+C1s */
- /* Load file directory entry */
+ /* Load file-directory entry */
res = move_window(dp->obj.fs, dp->sect);
if (res != FR_OK) return res;
if (dp->dir[XDIR_Type] != ET_FILEDIR) return FR_INT_ERR; /* Invalid order */
- memcpy(dirb + 0 * SZDIRE, dp->dir, SZDIRE);
+ mem_cpy(dirb + 0 * SZDIRE, dp->dir, SZDIRE);
sz_ent = (dirb[XDIR_NumSec] + 1) * SZDIRE;
if (sz_ent < 3 * SZDIRE || sz_ent > 19 * SZDIRE) return FR_INT_ERR;
- /* Load stream extension entry */
+ /* Load stream-extension entry */
res = dir_next(dp, 0);
if (res == FR_NO_FILE) res = FR_INT_ERR; /* It cannot be */
if (res != FR_OK) return res;
res = move_window(dp->obj.fs, dp->sect);
if (res != FR_OK) return res;
if (dp->dir[XDIR_Type] != ET_STREAM) return FR_INT_ERR; /* Invalid order */
- memcpy(dirb + 1 * SZDIRE, dp->dir, SZDIRE);
+ mem_cpy(dirb + 1 * SZDIRE, dp->dir, SZDIRE);
if (MAXDIRB(dirb[XDIR_NumName]) > sz_ent) return FR_INT_ERR;
- /* Load file name entries */
+ /* Load file-name entries */
i = 2 * SZDIRE; /* Name offset to load */
do {
res = dir_next(dp, 0);
@@ -2132,7 +2221,7 @@ static FRESULT load_xdir ( /* FR_INT_ERR: invalid entry block */
res = move_window(dp->obj.fs, dp->sect);
if (res != FR_OK) return res;
if (dp->dir[XDIR_Type] != ET_FILENAME) return FR_INT_ERR; /* Invalid order */
- if (i < MAXDIRB(FF_MAX_LFN)) memcpy(dirb + i, dp->dir, SZDIRE);
+ if (i < MAXDIRB(FF_MAX_LFN)) mem_cpy(dirb + i, dp->dir, SZDIRE);
} while ((i += SZDIRE) < sz_ent);
/* Sanity check (do it for only accessible object) */
@@ -2200,7 +2289,7 @@ static FRESULT store_xdir (
{
FRESULT res;
UINT nent;
- BYTE *dirb = dp->obj.fs->dirbuf; /* Pointer to the direcotry entry block 85+C0+C1s */
+ BYTE* dirb = dp->obj.fs->dirbuf; /* Pointer to the direcotry entry block 85+C0+C1s */
/* Create set sum */
st_word(dirb + XDIR_SetSum, xdir_sum(dirb));
@@ -2211,7 +2300,7 @@ static FRESULT store_xdir (
while (res == FR_OK) {
res = move_window(dp->obj.fs, dp->sect);
if (res != FR_OK) break;
- memcpy(dp->dir, dirb, SZDIRE);
+ mem_cpy(dp->dir, dirb, SZDIRE);
dp->obj.fs->wflag = 1;
if (--nent == 0) break;
dirb += SZDIRE;
@@ -2237,7 +2326,7 @@ static void create_xdir (
/* Create file-directory and stream-extension entry */
- memset(dirb, 0, 2 * SZDIRE);
+ mem_set(dirb, 0, 2 * SZDIRE);
dirb[0 * SZDIRE + XDIR_Type] = ET_FILEDIR;
dirb[1 * SZDIRE + XDIR_Type] = ET_STREAM;
@@ -2248,7 +2337,7 @@ static void create_xdir (
dirb[i++] = ET_FILENAME; dirb[i++] = 0;
do { /* Fill name field */
if (wc != 0 && (wc = lfn[nlen]) != 0) nlen++; /* Get a character if exist */
- st_word(dirb + i, wc); /* Store it */
+ st_word(dirb + i, wc); /* Store it */
i += 2;
} while (i % SZDIRE != 0);
nc1++;
@@ -2313,17 +2402,17 @@ static FRESULT dir_read (
if (b == DDEM || b == '.' || (int)((attr & ~AM_ARC) == AM_VOL) != vol) { /* An entry without valid data */
ord = 0xFF;
} else {
- if (attr == AM_LFN) { /* An LFN entry is found */
- if (b & LLEF) { /* Is it start of an LFN sequence? */
+ if (attr == AM_LFN) { /* An LFN entry is found */
+ if (b & LLEF) { /* Is it start of an LFN sequence? */
sum = dp->dir[LDIR_Chksum];
b &= (BYTE)~LLEF; ord = b;
dp->blk_ofs = dp->dptr;
}
/* Check LFN validity and capture it */
ord = (b == ord && sum == dp->dir[LDIR_Chksum] && pick_lfn(fs->lfnbuf, dp->dir)) ? ord - 1 : 0xFF;
- } else { /* An SFN entry is found */
+ } else { /* An SFN entry is found */
if (ord != 0 || sum != sum_sfn(dp->dir)) { /* Is there a valid LFN? */
- dp->blk_ofs = 0xFFFFFFFF; /* It has no LFN. */
+ dp->blk_ofs = 0xFFFFFFFF; /* It has no LFN. */
}
break;
}
@@ -2371,7 +2460,7 @@ static FRESULT dir_find ( /* FR_OK(0):succeeded, !=0:error */
while ((res = DIR_READ_FILE(dp)) == FR_OK) { /* Read an item */
#if FF_MAX_LFN < 255
- if (fs->dirbuf[XDIR_NumName] > FF_MAX_LFN) continue; /* Skip comparison if inaccessible object name */
+ if (fs->dirbuf[XDIR_NumName] > FF_MAX_LFN) continue; /* Skip comparison if inaccessible object name */
#endif
if (ld_word(fs->dirbuf + XDIR_NameHash) != hash) continue; /* Skip comparison if hash mismatched */
for (nc = fs->dirbuf[XDIR_NumName], di = SZDIRE * 2, ni = 0; nc; nc--, di += 2, ni++) { /* Compare the name */
@@ -2409,13 +2498,13 @@ static FRESULT dir_find ( /* FR_OK(0):succeeded, !=0:error */
}
} else { /* An SFN entry is found */
if (ord == 0 && sum == sum_sfn(dp->dir)) break; /* LFN matched? */
- if (!(dp->fn[NSFLAG] & NS_LOSS) && !memcmp(dp->dir, dp->fn, 11)) break; /* SFN matched? */
+ if (!(dp->fn[NSFLAG] & NS_LOSS) && !mem_cmp(dp->dir, dp->fn, 11)) break; /* SFN matched? */
ord = 0xFF; dp->blk_ofs = 0xFFFFFFFF; /* Reset LFN sequence */
}
}
#else /* Non LFN configuration */
dp->obj.attr = dp->dir[DIR_Attr] & AM_MASK;
- if (!(dp->dir[DIR_Attr] & AM_VOL) && !memcmp(dp->dir, dp->fn, 11)) break; /* Is it a valid entry? */
+ if (!(dp->dir[DIR_Attr] & AM_VOL) && !mem_cmp(dp->dir, dp->fn, 11)) break; /* Is it a valid entry? */
#endif
res = dir_next(dp, 0); /* Next entry */
} while (res == FR_OK);
@@ -2438,19 +2527,19 @@ static FRESULT dir_register ( /* FR_OK:succeeded, FR_DENIED:no free entry or too
FRESULT res;
FATFS *fs = dp->obj.fs;
#if FF_USE_LFN /* LFN configuration */
- UINT n, len, n_ent;
+ UINT n, nlen, nent;
BYTE sn[12], sum;
if (dp->fn[NSFLAG] & (NS_DOT | NS_NONAME)) return FR_INVALID_NAME; /* Check name validity */
- for (len = 0; fs->lfnbuf[len]; len++) ; /* Get lfn length */
+ for (nlen = 0; fs->lfnbuf[nlen]; nlen++) ; /* Get lfn length */
#if FF_FS_EXFAT
if (fs->fs_type == FS_EXFAT) { /* On the exFAT volume */
- n_ent = (len + 14) / 15 + 2; /* Number of entries to allocate (85+C0+C1s) */
- res = dir_alloc(dp, n_ent); /* Allocate directory entries */
+ nent = (nlen + 14) / 15 + 2; /* Number of entries to allocate (85+C0+C1s) */
+ res = dir_alloc(dp, nent); /* Allocate directory entries */
if (res != FR_OK) return res;
- dp->blk_ofs = dp->dptr - SZDIRE * (n_ent - 1); /* Set the allocated entry block offset */
+ dp->blk_ofs = dp->dptr - SZDIRE * (nent - 1); /* Set the allocated entry block offset */
if (dp->obj.stat & 4) { /* Has the directory been stretched by new allocation? */
dp->obj.stat &= ~4;
@@ -2463,10 +2552,10 @@ static FRESULT dir_register ( /* FR_OK:succeeded, FR_DENIED:no free entry or too
res = load_obj_xdir(&dj, &dp->obj); /* Load the object status */
if (res != FR_OK) return res;
- dp->obj.objsize += (DWORD)fs->csize * SS(fs); /* Increase the directory size by cluster size */
+ dp->obj.objsize += (DWORD)fs->csize * SS(fs); /* Increase the directory size by cluster size */
st_qword(fs->dirbuf + XDIR_FileSize, dp->obj.objsize);
st_qword(fs->dirbuf + XDIR_ValidFileSize, dp->obj.objsize);
- fs->dirbuf[XDIR_GenFlags] = dp->obj.stat | 1; /* Update the allocation status */
+ fs->dirbuf[XDIR_GenFlags] = dp->obj.stat | 1; /* Update the allocation status */
res = store_xdir(&dj); /* Store the object status */
if (res != FR_OK) return res;
}
@@ -2477,7 +2566,7 @@ static FRESULT dir_register ( /* FR_OK:succeeded, FR_DENIED:no free entry or too
}
#endif
/* On the FAT/FAT32 volume */
- memcpy(sn, dp->fn, 12);
+ mem_cpy(sn, dp->fn, 12);
if (sn[NSFLAG] & NS_LOSS) { /* When LFN is out of 8.3 format, generate a numbered name */
dp->fn[NSFLAG] = NS_NOLFN; /* Find only SFN */
for (n = 1; n < 100; n++) {
@@ -2491,19 +2580,19 @@ static FRESULT dir_register ( /* FR_OK:succeeded, FR_DENIED:no free entry or too
}
/* Create an SFN with/without LFNs. */
- n_ent = (sn[NSFLAG] & NS_LFN) ? (len + 12) / 13 + 1 : 1; /* Number of entries to allocate */
- res = dir_alloc(dp, n_ent); /* Allocate entries */
- if (res == FR_OK && --n_ent) { /* Set LFN entry if needed */
- res = dir_sdi(dp, dp->dptr - n_ent * SZDIRE);
+ nent = (sn[NSFLAG] & NS_LFN) ? (nlen + 12) / 13 + 1 : 1; /* Number of entries to allocate */
+ res = dir_alloc(dp, nent); /* Allocate entries */
+ if (res == FR_OK && --nent) { /* Set LFN entry if needed */
+ res = dir_sdi(dp, dp->dptr - nent * SZDIRE);
if (res == FR_OK) {
sum = sum_sfn(dp->fn); /* Checksum value of the SFN tied to the LFN */
do { /* Store LFN entries in bottom first */
res = move_window(fs, dp->sect);
if (res != FR_OK) break;
- put_lfn(fs->lfnbuf, dp->dir, (BYTE)n_ent, sum);
+ put_lfn(fs->lfnbuf, dp->dir, (BYTE)nent, sum);
fs->wflag = 1;
res = dir_next(dp, 0); /* Next entry */
- } while (res == FR_OK && --n_ent);
+ } while (res == FR_OK && --nent);
}
}
@@ -2516,8 +2605,8 @@ static FRESULT dir_register ( /* FR_OK:succeeded, FR_DENIED:no free entry or too
if (res == FR_OK) {
res = move_window(fs, dp->sect);
if (res == FR_OK) {
- memset(dp->dir, 0, SZDIRE); /* Clean the entry */
- memcpy(dp->dir + DIR_Name, dp->fn, 11); /* Put SFN */
+ mem_set(dp->dir, 0, SZDIRE); /* Clean the entry */
+ mem_cpy(dp->dir + DIR_Name, dp->fn, 11); /* Put SFN */
#if FF_USE_LFN
dp->dir[DIR_NTres] = dp->fn[NSFLAG] & (NS_BODY | NS_EXT); /* Put NT flag */
#endif
@@ -2553,7 +2642,7 @@ static FRESULT dir_remove ( /* FR_OK:Succeeded, FR_DISK_ERR:A disk error */
if (res != FR_OK) break;
if (FF_FS_EXFAT && fs->fs_type == FS_EXFAT) { /* On the exFAT volume */
dp->dir[XDIR_Type] &= 0x7F; /* Clear the entry InUse flag. */
- } else { /* On the FAT/FAT32 volume */
+ } else { /* On the FAT/FAT32 volume */
dp->dir[DIR_Name] = DDEM; /* Mark the entry 'deleted'. */
}
fs->wflag = 1;
@@ -2593,7 +2682,6 @@ static void get_fileinfo (
BYTE lcf;
WCHAR wc, hs;
FATFS *fs = dp->obj.fs;
- UINT nw;
#else
TCHAR c;
#endif
@@ -2604,47 +2692,22 @@ static void get_fileinfo (
#if FF_USE_LFN /* LFN configuration */
#if FF_FS_EXFAT
- if (fs->fs_type == FS_EXFAT) { /* exFAT volume */
- UINT nc = 0;
-
- si = SZDIRE * 2; di = 0; /* 1st C1 entry in the entry block */
- hs = 0;
- while (nc < fs->dirbuf[XDIR_NumName]) {
- if (si >= MAXDIRB(FF_MAX_LFN)) { di = 0; break; } /* Truncated directory block? */
- if ((si % SZDIRE) == 0) si += 2; /* Skip entry type field */
- wc = ld_word(fs->dirbuf + si); si += 2; nc++; /* Get a character */
- if (hs == 0 && IsSurrogate(wc)) { /* Is it a surrogate? */
- hs = wc; continue; /* Get low surrogate */
- }
- nw = put_utf((DWORD)hs << 16 | wc, &fno->fname[di], FF_LFN_BUF - di); /* Store it in API encoding */
- if (nw == 0) { di = 0; break; } /* Buffer overflow or wrong char? */
- di += nw;
- hs = 0;
- }
- if (hs != 0) di = 0; /* Broken surrogate pair? */
- if (di == 0) fno->fname[di++] = '?'; /* Inaccessible object name? */
- fno->fname[di] = 0; /* Terminate the name */
- fno->altname[0] = 0; /* exFAT does not support SFN */
-
- fno->fattrib = fs->dirbuf[XDIR_Attr] & AM_MASKX; /* Attribute */
- fno->fsize = (fno->fattrib & AM_DIR) ? 0 : ld_qword(fs->dirbuf + XDIR_FileSize); /* Size */
- fno->ftime = ld_word(fs->dirbuf + XDIR_ModTime + 0); /* Time */
- fno->fdate = ld_word(fs->dirbuf + XDIR_ModTime + 2); /* Date */
+ if (fs->fs_type == FS_EXFAT) { /* On the exFAT volume */
+ get_xfileinfo(fs->dirbuf, fno);
return;
} else
#endif
- { /* FAT/FAT32 volume */
+ { /* On the FAT/FAT32 volume */
if (dp->blk_ofs != 0xFFFFFFFF) { /* Get LFN if available */
- si = di = 0;
- hs = 0;
+ si = di = hs = 0;
while (fs->lfnbuf[si] != 0) {
wc = fs->lfnbuf[si++]; /* Get an LFN character (UTF-16) */
if (hs == 0 && IsSurrogate(wc)) { /* Is it a surrogate? */
hs = wc; continue; /* Get low surrogate */
}
- nw = put_utf((DWORD)hs << 16 | wc, &fno->fname[di], FF_LFN_BUF - di); /* Store it in API encoding */
- if (nw == 0) { di = 0; break; } /* Buffer overflow or wrong char? */
- di += nw;
+ wc = put_utf((DWORD)hs << 16 | wc, &fno->fname[di], FF_LFN_BUF - di); /* Store it in UTF-16 or UTF-8 encoding */
+ if (wc == 0) { di = 0; break; } /* Invalid char or buffer overflow? */
+ di += wc;
hs = 0;
}
if (hs != 0) di = 0; /* Broken surrogate pair? */
@@ -2664,9 +2727,9 @@ static void get_fileinfo (
}
wc = ff_oem2uni(wc, CODEPAGE); /* ANSI/OEM -> Unicode */
if (wc == 0) { di = 0; break; } /* Wrong char in the current code page? */
- nw = put_utf(wc, &fno->altname[di], FF_SFN_BUF - di); /* Store it in API encoding */
- if (nw == 0) { di = 0; break; } /* Buffer overflow? */
- di += nw;
+ wc = put_utf(wc, &fno->altname[di], FF_SFN_BUF - di); /* Store it in Unicode */
+ if (wc == 0) { di = 0; break; } /* Buffer overflow? */
+ di += wc;
#else /* ANSI/OEM output */
fno->altname[di++] = (TCHAR)wc; /* Store it without any conversion */
#endif
@@ -2697,10 +2760,10 @@ static void get_fileinfo (
if (si == 9) fno->fname[di++] = '.';/* Insert a . if extension is exist */
fno->fname[di++] = c;
}
- fno->fname[di] = 0; /* Terminate the SFN */
+ fno->fname[di] = 0;
#endif
- fno->fattrib = dp->dir[DIR_Attr] & AM_MASK; /* Attribute */
+ fno->fattrib = dp->dir[DIR_Attr]; /* Attribute */
fno->fsize = ld_dword(dp->dir + DIR_FileSize); /* Size */
fno->ftime = ld_word(dp->dir + DIR_ModTime + 0); /* Time */
fno->fdate = ld_word(dp->dir + DIR_ModTime + 2); /* Date */
@@ -2715,10 +2778,7 @@ static void get_fileinfo (
/* Pattern matching */
/*-----------------------------------------------------------------------*/
-#define FIND_RECURS 4 /* Maximum number of wildcard terms in the pattern to limit recursion */
-
-
-static DWORD get_achar ( /* Get a character and advance ptr */
+static DWORD get_achar ( /* Get a character and advances ptr */
const TCHAR** ptr /* Pointer to pointer to the ANSI/OEM or Unicode string */
)
{
@@ -2749,43 +2809,41 @@ static DWORD get_achar ( /* Get a character and advance ptr */
}
-static int pattern_match ( /* 0:mismatched, 1:matched */
+static int pattern_matching ( /* 0:not matched, 1:matched */
const TCHAR* pat, /* Matching pattern */
const TCHAR* nam, /* String to be tested */
- UINT skip, /* Number of pre-skip chars (number of ?s, b8:infinite (* specified)) */
- UINT recur /* Recursion count */
+ int skip, /* Number of pre-skip chars (number of ?s) */
+ int inf /* Infinite search (* specified) */
)
{
- const TCHAR *pptr, *nptr;
- DWORD pchr, nchr;
- UINT sk;
+ const TCHAR *pp, *np;
+ DWORD pc, nc;
+ int nm, nx;
- while ((skip & 0xFF) != 0) { /* Pre-skip name chars */
+ while (skip--) { /* Pre-skip name chars */
if (!get_achar(&nam)) return 0; /* Branch mismatched if less name chars */
- skip--;
}
- if (*pat == 0 && skip) return 1; /* Matched? (short circuit) */
+ if (*pat == 0 && inf) return 1; /* (short circuit) */
do {
- pptr = pat; nptr = nam; /* Top of pattern and name to match */
+ pp = pat; np = nam; /* Top of pattern and name to match */
for (;;) {
- if (*pptr == '?' || *pptr == '*') { /* Wildcard term? */
- if (recur == 0) return 0; /* Too many wildcard terms? */
- sk = 0;
- do { /* Analyze the wildcard term */
- if (*pptr++ == '?') sk++; else sk |= 0x100;
- } while (*pptr == '?' || *pptr == '*');
- if (pattern_match(pptr, nptr, sk, recur - 1)) return 1; /* Test new branch (recursive call) */
- nchr = *nptr; break; /* Branch mismatched */
+ if (*pp == '?' || *pp == '*') { /* Wildcard? */
+ nm = nx = 0;
+ do { /* Analyze the wildcard block */
+ if (*pp++ == '?') nm++; else nx = 1;
+ } while (*pp == '?' || *pp == '*');
+ if (pattern_matching(pp, np, nm, nx)) return 1; /* Test new branch (recurs upto number of wildcard blocks in the pattern) */
+ nc = *np; break; /* Branch mismatched */
}
- pchr = get_achar(&pptr); /* Get a pattern char */
- nchr = get_achar(&nptr); /* Get a name char */
- if (pchr != nchr) break; /* Branch mismatched? */
- if (pchr == 0) return 1; /* Branch matched? (matched at end of both strings) */
+ pc = get_achar(&pp); /* Get a pattern char */
+ nc = get_achar(&np); /* Get a name char */
+ if (pc != nc) break; /* Branch mismatched? */
+ if (pc == 0) return 1; /* Branch matched? (matched at end of both strings) */
}
get_achar(&nam); /* nam++ */
- } while (skip && nchr); /* Retry until end of name if infinite search is specified */
+ } while (inf && nc); /* Retry until end of name if infinite search is specified */
return 0;
}
@@ -2818,17 +2876,16 @@ static FRESULT create_name ( /* FR_OK: successful, FR_INVALID_NAME: could not cr
if (uc == 0xFFFFFFFF) return FR_INVALID_NAME; /* Invalid code or UTF decode error */
if (uc >= 0x10000) lfn[di++] = (WCHAR)(uc >> 16); /* Store high surrogate if needed */
wc = (WCHAR)uc;
- if (wc < ' ' || IsSeparator(wc)) break; /* Break if end of the path or a separator is found */
- if (wc < 0x80 && strchr("*:<>|\"\?\x7F", (int)wc)) return FR_INVALID_NAME; /* Reject illegal characters for LFN */
+ if (wc < ' ' || wc == '/' || wc == '\\') break; /* Break if end of the path or a separator is found */
+ if (wc < 0x80 && chk_chr("\"*:<>\?|\x7F", wc)) return FR_INVALID_NAME; /* Reject illegal characters for LFN */
if (di >= FF_MAX_LFN) return FR_INVALID_NAME; /* Reject too long name */
- lfn[di++] = wc; /* Store the Unicode character */
+ lfn[di++] = wc; /* Store the Unicode character */
}
- if (wc < ' ') { /* Stopped at end of the path? */
- cf = NS_LAST; /* Last segment */
- } else { /* Stopped at a separator */
- while (IsSeparator(*p)) p++; /* Skip duplicated separators if exist */
- cf = 0; /* Next segment may follow */
- if (IsTerminator(*p)) cf = NS_LAST; /* Ignore terminating separator */
+ if (wc < ' ') { /* End of path? */
+ cf = NS_LAST; /* Set last segment flag */
+ } else {
+ cf = 0; /* Next segment follows */
+ while (*p == '/' || *p == '\\') p++; /* Skip duplicated separators if exist */
}
*path = p; /* Return pointer to the next segment */
@@ -2836,14 +2893,14 @@ static FRESULT create_name ( /* FR_OK: successful, FR_INVALID_NAME: could not cr
if ((di == 1 && lfn[di - 1] == '.') ||
(di == 2 && lfn[di - 1] == '.' && lfn[di - 2] == '.')) { /* Is this segment a dot name? */
lfn[di] = 0;
- for (i = 0; i < 11; i++) { /* Create dot name for SFN entry */
+ for (i = 0; i < 11; i++) { /* Create dot name for SFN entry */
dp->fn[i] = (i < di) ? '.' : ' ';
}
- dp->fn[i] = cf | NS_DOT; /* This is a dot entry */
+ dp->fn[i] = cf | NS_DOT; /* This is a dot entry */
return FR_OK;
}
#endif
- while (di) { /* Snip off trailing spaces and dots if exist */
+ while (di) { /* Snip off trailing spaces and dots if exist */
wc = lfn[di - 1];
if (wc != ' ' && wc != '.') break;
di--;
@@ -2856,7 +2913,7 @@ static FRESULT create_name ( /* FR_OK: successful, FR_INVALID_NAME: could not cr
if (si > 0 || lfn[si] == '.') cf |= NS_LOSS | NS_LFN; /* Is there any leading space or dot? */
while (di > 0 && lfn[di - 1] != '.') di--; /* Find last dot (di<=si: no extension) */
- memset(dp->fn, ' ', 11);
+ mem_set(dp->fn, ' ', 11);
i = b = 0; ni = 8;
for (;;) {
wc = lfn[si++]; /* Get an LFN character */
@@ -2877,20 +2934,20 @@ static FRESULT create_name ( /* FR_OK: successful, FR_INVALID_NAME: could not cr
continue;
}
- if (wc >= 0x80) { /* Is this an extended character? */
+ if (wc >= 0x80) { /* Is this a non-ASCII character? */
cf |= NS_LFN; /* LFN entry needs to be created */
#if FF_CODE_PAGE == 0
- if (ExCvt) { /* In SBCS cfg */
+ if (ExCvt) { /* At SBCS */
wc = ff_uni2oem(wc, CODEPAGE); /* Unicode ==> ANSI/OEM code */
if (wc & 0x80) wc = ExCvt[wc & 0x7F]; /* Convert extended character to upper (SBCS) */
- } else { /* In DBCS cfg */
- wc = ff_uni2oem(ff_wtoupper(wc), CODEPAGE); /* Unicode ==> Up-convert ==> ANSI/OEM code */
+ } else { /* At DBCS */
+ wc = ff_uni2oem(ff_wtoupper(wc), CODEPAGE); /* Unicode ==> Upper convert ==> ANSI/OEM code */
}
-#elif FF_CODE_PAGE < 900 /* In SBCS cfg */
+#elif FF_CODE_PAGE < 900 /* SBCS cfg */
wc = ff_uni2oem(wc, CODEPAGE); /* Unicode ==> ANSI/OEM code */
if (wc & 0x80) wc = ExCvt[wc & 0x7F]; /* Convert extended character to upper (SBCS) */
-#else /* In DBCS cfg */
- wc = ff_uni2oem(ff_wtoupper(wc), CODEPAGE); /* Unicode ==> Up-convert ==> ANSI/OEM code */
+#else /* DBCS cfg */
+ wc = ff_uni2oem(ff_wtoupper(wc), CODEPAGE); /* Unicode ==> Upper convert ==> ANSI/OEM code */
#endif
}
@@ -2901,7 +2958,7 @@ static FRESULT create_name ( /* FR_OK: successful, FR_INVALID_NAME: could not cr
}
dp->fn[i++] = (BYTE)(wc >> 8); /* Put 1st byte */
} else { /* SBC */
- if (wc == 0 || strchr("+,;=[]", (int)wc)) { /* Replace illegal characters for SFN */
+ if (wc == 0 || chk_chr("+,;=[]", wc)) { /* Replace illegal characters for SFN if needed */
wc = '_'; cf |= NS_LOSS | NS_LFN;/* Lossy conversion */
} else {
if (IsUpper(wc)) { /* ASCII upper case? */
@@ -2936,7 +2993,7 @@ static FRESULT create_name ( /* FR_OK: successful, FR_INVALID_NAME: could not cr
/* Create file name in directory form */
p = *path; sfn = dp->fn;
- memset(sfn, ' ', 11);
+ mem_set(sfn, ' ', 11);
si = i = 0; ni = 8;
#if FF_FS_RPATH != 0
if (p[si] == '.') { /* Is this a dot entry? */
@@ -2945,8 +3002,8 @@ static FRESULT create_name ( /* FR_OK: successful, FR_INVALID_NAME: could not cr
if (c != '.' || si >= 3) break;
sfn[i++] = c;
}
- if (!IsSeparator(c) && c > ' ') return FR_INVALID_NAME;
- *path = p + si; /* Return pointer to the next segment */
+ if (c != '/' && c != '\\' && c > ' ') return FR_INVALID_NAME;
+ *path = p + si; /* Return pointer to the next segment */
sfn[NSFLAG] = (c <= ' ') ? NS_LAST | NS_DOT : NS_DOT; /* Set last segment flag if end of the path */
return FR_OK;
}
@@ -2954,8 +3011,8 @@ static FRESULT create_name ( /* FR_OK: successful, FR_INVALID_NAME: could not cr
for (;;) {
c = (BYTE)p[si++]; /* Get a byte */
if (c <= ' ') break; /* Break if end of the path name */
- if (IsSeparator(c)) { /* Break if a separator is found */
- while (IsSeparator(p[si])) si++; /* Skip duplicated separator if exist */
+ if (c == '/' || c == '\\') { /* Break if a separator is found */
+ while (p[si] == '/' || p[si] == '\\') si++; /* Skip duplicated separator if exist */
break;
}
if (c == '.' || i >= ni) { /* End of body or field overflow? */
@@ -2978,16 +3035,16 @@ static FRESULT create_name ( /* FR_OK: successful, FR_INVALID_NAME: could not cr
sfn[i++] = c;
sfn[i++] = d;
} else { /* SBC */
- if (strchr("*+,:;<=>[]|\"\?\x7F", (int)c)) return FR_INVALID_NAME; /* Reject illegal chrs for SFN */
+ if (chk_chr("\"*+,:;<=>\?[]|\x7F", c)) return FR_INVALID_NAME; /* Reject illegal chrs for SFN */
if (IsLower(c)) c -= 0x20; /* To upper */
sfn[i++] = c;
}
}
- *path = &p[si]; /* Return pointer to the next segment */
+ *path = p + si; /* Return pointer to the next segment */
if (i == 0) return FR_INVALID_NAME; /* Reject nul string */
if (sfn[0] == DDEM) sfn[0] = RDDEM; /* If the first character collides with DDEM, replace it with RDDEM */
- sfn[NSFLAG] = (c <= ' ' || p[si] <= ' ') ? NS_LAST : 0; /* Set last segment flag if end of the path */
+ sfn[NSFLAG] = (c <= ' ') ? NS_LAST : 0; /* Set last segment flag if end of the path */
return FR_OK;
#endif /* FF_USE_LFN */
@@ -3011,13 +3068,13 @@ static FRESULT follow_path ( /* FR_OK(0): successful, !=0: error code */
#if FF_FS_RPATH != 0
- if (!IsSeparator(*path) && (FF_STR_VOLUME_ID != 2 || !IsTerminator(*path))) { /* Without heading separator */
- dp->obj.sclust = fs->cdir; /* Start at the current directory */
+ if (*path != '/' && *path != '\\') { /* Without heading separator */
+ dp->obj.sclust = fs->cdir; /* Start from current directory */
} else
#endif
{ /* With heading separator */
- while (IsSeparator(*path)) path++; /* Strip separators */
- dp->obj.sclust = 0; /* Start from the root directory */
+ while (*path == '/' || *path == '\\') path++; /* Strip heading separator */
+ dp->obj.sclust = 0; /* Start from root directory */
}
#if FF_FS_EXFAT
dp->obj.n_frag = 0; /* Invalidate last fragment counter of the object */
@@ -3058,13 +3115,13 @@ static FRESULT follow_path ( /* FR_OK(0): successful, !=0: error code */
}
break;
}
- if (ns & NS_LAST) break; /* Last segment matched. Function completed. */
+ if (ns & NS_LAST) break; /* Last segment matched. Function completed. */
/* Get into the sub-directory */
- if (!(dp->obj.attr & AM_DIR)) { /* It is not a sub-directory and cannot follow */
+ if (!(dp->obj.attr & AM_DIR)) { /* It is not a sub-directory and cannot follow */
res = FR_NO_PATH; break;
}
#if FF_FS_EXFAT
- if (fs->fs_type == FS_EXFAT) { /* Save containing directory information for next dir */
+ if (fs->fs_type == FS_EXFAT) { /* Save containing directory information for next dir */
dp->obj.c_scl = dp->obj.sclust;
dp->obj.c_size = ((DWORD)dp->obj.objsize & 0xFFFFFF00) | dp->obj.stat;
dp->obj.c_ofs = dp->blk_ofs;
@@ -3093,8 +3150,7 @@ static int get_ldnumber ( /* Returns logical drive number (-1:invalid drive numb
{
const TCHAR *tp, *tt;
TCHAR tc;
- int i;
- int vol = -1;
+ int i, vol = -1;
#if FF_STR_VOLUME_ID /* Find string volume ID */
const char *sp;
char c;
@@ -3102,7 +3158,7 @@ static int get_ldnumber ( /* Returns logical drive number (-1:invalid drive numb
tt = tp = *path;
if (!tp) return vol; /* Invalid path name? */
- do tc = *tt++; while (!IsTerminator(tc) && tc != ':'); /* Find a colon in the path */
+ do tc = *tt++; while ((UINT)tc >= (FF_USE_LFN ? ' ' : '!') && tc != ':'); /* Find a colon in the path */
if (tc == ':') { /* DOS/Windows style volume ID? */
i = FF_VOLUMES;
@@ -3129,22 +3185,21 @@ static int get_ldnumber ( /* Returns logical drive number (-1:invalid drive numb
return vol;
}
#if FF_STR_VOLUME_ID == 2 /* Unix style volume ID is enabled */
- if (*tp == '/') { /* Is there a volume ID? */
- while (*(tp + 1) == '/') tp++; /* Skip duplicated separator */
+ if (*tp == '/') {
i = 0;
do {
- tt = tp; sp = VolumeStr[i]; /* Path name and this string volume ID */
+ sp = VolumeStr[i]; tp = *path; /* This string volume ID and path name */
do { /* Compare the volume ID with path name */
- c = *sp++; tc = *(++tt);
+ c = *sp++; tc = *(++tp);
if (IsLower(c)) c -= 0x20;
if (IsLower(tc)) tc -= 0x20;
} while (c && (TCHAR)c == tc);
- } while ((c || (tc != '/' && !IsTerminator(tc))) && ++i < FF_VOLUMES); /* Repeat for each ID until pattern match */
+ } while ((c || (tc != '/' && (UINT)tc >= (FF_USE_LFN ? ' ' : '!'))) && ++i < FF_VOLUMES); /* Repeat for each ID until pattern match */
if (i < FF_VOLUMES) { /* If a volume ID is found, get the drive number and strip it */
vol = i; /* Drive number */
- *path = tt; /* Snip the drive prefix off */
+ *path = tp; /* Snip the drive prefix off */
+ return vol;
}
- return vol;
}
#endif
/* No drive prefix is found */
@@ -3193,7 +3248,7 @@ static int test_gpt_header ( /* 0:Invalid, 1:Valid */
DWORD bcc;
- if (memcmp(gpth + GPTH_Sign, "EFI PART" "\0\0\1\0" "\x5C\0\0", 16)) return 0; /* Check sign, version (1.0) and length (92) */
+ if (mem_cmp(gpth + GPTH_Sign, "EFI PART" "\0\0\1\0" "\x5C\0\0", 16)) return 0; /* Check sign, version (1.0) and length (92) */
for (i = 0, bcc = 0xFFFFFFFF; i < 92; i++) { /* Check header BCC */
bcc = crc32(bcc, i - GPTH_Bcc < 4 ? 0 : gpth[i]);
}
@@ -3235,7 +3290,7 @@ static DWORD make_rand (
/* Check what the sector is */
-static UINT check_fs ( /* 0:FAT/FAT32 VBR, 1:exFAT VBR, 2:Not FAT and valid BS, 3:Not FAT and invalid BS, 4:Disk error */
+static UINT check_fs ( /* 0:FAT VBR, 1:exFAT VBR, 2:Not FAT and valid BS, 3:Not FAT and invalid BS, 4:Disk error */
FATFS* fs, /* Filesystem object */
LBA_t sect /* Sector to load and check if it is an FAT-VBR or not */
)
@@ -3248,24 +3303,21 @@ static UINT check_fs ( /* 0:FAT/FAT32 VBR, 1:exFAT VBR, 2:Not FAT and valid BS,
if (move_window(fs, sect) != FR_OK) return 4; /* Load the boot sector */
sign = ld_word(fs->win + BS_55AA);
#if FF_FS_EXFAT
- if (sign == 0xAA55 && !memcmp(fs->win + BS_JmpBoot, "\xEB\x76\x90" "EXFAT ", 11)) return 1; /* It is an exFAT VBR */
+ if (sign == 0xAA55 && !mem_cmp(fs->win + BS_JmpBoot, "\xEB\x76\x90" "EXFAT ", 11)) return 1; /* It is an exFAT VBR */
#endif
b = fs->win[BS_JmpBoot];
if (b == 0xEB || b == 0xE9 || b == 0xE8) { /* Valid JumpBoot code? (short jump, near jump or near call) */
- if (sign == 0xAA55 && !memcmp(fs->win + BS_FilSysType32, "FAT32 ", 8)) {
- return 0; /* It is an FAT32 VBR */
- }
- /* FAT volumes formatted with early MS-DOS lack BS_55AA and BS_FilSysType, so FAT VBR needs to be identified without them. */
+ if (sign == 0xAA55 && !mem_cmp(fs->win + BS_FilSysType32, "FAT32 ", 8)) return 0; /* It is an FAT32 VBR */
+ /* FAT volumes formatted with early MS-DOS lack boot signature and FAT string, so that we need to identify the FAT VBR without them. */
w = ld_word(fs->win + BPB_BytsPerSec);
- b = fs->win[BPB_SecPerClus];
- if ((w & (w - 1)) == 0 && w >= FF_MIN_SS && w <= FF_MAX_SS /* Properness of sector size (512-4096 and 2^n) */
- && b != 0 && (b & (b - 1)) == 0 /* Properness of cluster size (2^n) */
- && ld_word(fs->win + BPB_RsvdSecCnt) != 0 /* Properness of reserved sectors (MNBZ) */
- && (UINT)fs->win[BPB_NumFATs] - 1 <= 1 /* Properness of FATs (1 or 2) */
- && ld_word(fs->win + BPB_RootEntCnt) != 0 /* Properness of root dir entries (MNBZ) */
- && (ld_word(fs->win + BPB_TotSec16) >= 128 || ld_dword(fs->win + BPB_TotSec32) >= 0x10000) /* Properness of volume sectors (>=128) */
- && ld_word(fs->win + BPB_FATSz16) != 0) { /* Properness of FAT size (MNBZ) */
- return 0; /* It can be presumed an FAT VBR */
+ if ((w & (w - 1)) == 0 && w >= FF_MIN_SS && w <= FF_MAX_SS) { /* Properness of sector size */
+ b = fs->win[BPB_SecPerClus];
+ if (b != 0 && (b & (b - 1)) == 0 /* Properness of cluster size */
+ && (fs->win[BPB_NumFATs] == 1 || fs->win[BPB_NumFATs] == 2) /* Properness of number of FATs */
+ && ld_word(fs->win + BPB_RootEntCnt) != 0 /* Properness of root entry count */
+ && ld_word(fs->win + BPB_FATSz16) != 0) { /* Properness of FAT size */
+ return 0; /* Sector can be presumed an FAT VBR */
+ }
}
}
return sign == 0xAA55 ? 2 : 3; /* Not an FAT VBR (valid or invalid BS) */
@@ -3284,8 +3336,8 @@ static UINT find_volume ( /* Returns BS status found in the hosting drive */
DWORD mbr_pt[4];
- fmt = check_fs(fs, 0); /* Load sector 0 and check if it is an FAT VBR as SFD format */
- if (fmt != 2 && (fmt >= 3 || part == 0)) return fmt; /* Returns if it is an FAT VBR as auto scan, not a BS or disk error */
+ fmt = check_fs(fs, 0); /* Load sector 0 and check if it is an FAT VBR as SFD */
+ if (fmt != 2 && (fmt >= 3 || part == 0)) return fmt; /* Returns if it is a FAT VBR as auto scan, not a BS or disk error */
/* Sector 0 is not an FAT VBR or forced partition number wants a partition */
@@ -3301,7 +3353,7 @@ static UINT find_volume ( /* Returns BS status found in the hosting drive */
for (v_ent = i = 0; i < n_ent; i++) { /* Find FAT partition */
if (move_window(fs, pt_lba + i * SZ_GPTE / SS(fs)) != FR_OK) return 4; /* PT sector */
ofs = i * SZ_GPTE % SS(fs); /* Offset in the sector */
- if (!memcmp(fs->win + ofs + GPTE_PtGuid, GUID_MS_Basic, 16)) { /* MS basic data partition? */
+ if (!mem_cmp(fs->win + ofs + GPTE_PtGuid, GUID_MS_Basic, 16)) { /* MS basic data partition? */
v_ent++;
fmt = check_fs(fs, ld_qword(fs->win + ofs + GPTE_FstLba)); /* Load VBR and check status */
if (part == 0 && fmt <= 1) return fmt; /* Auto search (valid FAT volume found first) */
@@ -3369,7 +3421,7 @@ static FRESULT mount_volume ( /* FR_OK(0): successful, !=0: an error occurred */
}
/* The filesystem object is not valid. */
- /* Following code attempts to mount the volume. (find an FAT volume, analyze the BPB and initialize the filesystem object) */
+ /* Following code attempts to mount the volume. (find a FAT volume, analyze the BPB and initialize the filesystem object) */
fs->fs_type = 0; /* Clear the filesystem object */
fs->pdrv = LD2PD(vol); /* Volume hosting physical drive */
@@ -3389,7 +3441,7 @@ static FRESULT mount_volume ( /* FR_OK(0): successful, !=0: an error occurred */
fmt = find_volume(fs, LD2PT(vol));
if (fmt == 4) return FR_DISK_ERR; /* An error occured in the disk I/O layer */
if (fmt >= 2) return FR_NO_FILESYSTEM; /* No FAT volume is found */
- bsect = fs->winsect; /* Volume offset */
+ bsect = fs->winsect; /* Volume location */
/* An FAT volume is found (bsect). Following code initializes the filesystem object */
@@ -3407,8 +3459,8 @@ static FRESULT mount_volume ( /* FR_OK(0): successful, !=0: an error occurred */
return FR_NO_FILESYSTEM;
}
- maxlba = ld_qword(fs->win + BPB_TotSecEx) + bsect; /* Last LBA of the volume + 1 */
- if (!FF_LBA64 && maxlba >= 0x100000000) return FR_NO_FILESYSTEM; /* (It cannot be accessed in 32-bit LBA) */
+ maxlba = ld_qword(fs->win + BPB_TotSecEx) + bsect; /* Last LBA + 1 of the volume */
+ if (!FF_LBA64 && maxlba >= 0x100000000) return FR_NO_FILESYSTEM; /* (It cannot be handled in 32-bit LBA) */
fs->fsize = ld_dword(fs->win + BPB_FatSzEx); /* Number of sectors per FAT */
@@ -3416,7 +3468,7 @@ static FRESULT mount_volume ( /* FR_OK(0): successful, !=0: an error occurred */
if (fs->n_fats != 1) return FR_NO_FILESYSTEM; /* (Supports only 1 FAT) */
fs->csize = 1 << fs->win[BPB_SecPerClusEx]; /* Cluster size */
- if (fs->csize == 0) return FR_NO_FILESYSTEM; /* (Must be 1..32768 sectors) */
+ if (fs->csize == 0) return FR_NO_FILESYSTEM; /* (Must be 1..32768) */
nclst = ld_dword(fs->win + BPB_NumClusEx); /* Number of clusters */
if (nclst > MAX_EXFAT) return FR_NO_FILESYSTEM; /* (Too many clusters) */
@@ -3437,11 +3489,11 @@ static FRESULT mount_volume ( /* FR_OK(0): successful, !=0: an error occurred */
if (move_window(fs, clst2sect(fs, (DWORD)fs->dirbase) + so) != FR_OK) return FR_DISK_ERR;
so++;
}
- if (fs->win[i] == ET_BITMAP) break; /* Is it a bitmap entry? */
+ if (fs->win[i] == ET_BITMAP) break; /* Is it a bitmap entry? */
i = (i + SZDIRE) % SS(fs); /* Next entry */
}
- bcl = ld_dword(fs->win + i + 20); /* Bitmap cluster */
- if (bcl < 2 || bcl >= fs->n_fatent) return FR_NO_FILESYSTEM; /* (Wrong cluster#) */
+ bcl = ld_dword(fs->win + i + 20); /* Bitmap cluster */
+ if (bcl < 2 || bcl >= fs->n_fatent) return FR_NO_FILESYSTEM;
fs->bitbase = fs->database + fs->csize * (bcl - 2); /* Bitmap sector */
for (;;) { /* Check if bitmap is contiguous */
if (move_window(fs, fs->fatbase + bcl / (SS(fs) / 4)) != FR_OK) return FR_DISK_ERR;
@@ -3603,9 +3655,9 @@ static FRESULT validate ( /* Returns FR_OK or FR_INVALID_OBJECT */
/*-----------------------------------------------------------------------*/
FRESULT f_mount (
- FATFS* fs, /* Pointer to the filesystem object to be registered (NULL:unmount)*/
+ FATFS* fs, /* Pointer to the filesystem object (NULL:unmount)*/
const TCHAR* path, /* Logical drive number to be mounted/unmounted */
- BYTE opt /* Mount option: 0=Do not mount (delayed mount), 1=Mount immediately */
+ BYTE opt /* Mode option 0:Do not mount (delayed mount), 1:Mount immediately */
)
{
FATFS *cfs;
@@ -3653,14 +3705,14 @@ FRESULT f_mount (
FRESULT f_open (
FIL* fp, /* Pointer to the blank file object */
const TCHAR* path, /* Pointer to the file name */
- BYTE mode /* Access mode and open mode flags */
+ BYTE mode /* Access mode and file open mode flags */
)
{
FRESULT res;
DIR dj;
FATFS *fs;
#if !FF_FS_READONLY
- DWORD cl, bcs, clst, tm;
+ DWORD cl, bcs, clst;
LBA_t sc;
FSIZE_t ofs;
#endif
@@ -3713,8 +3765,8 @@ FRESULT f_open (
fp->obj.fs = fs;
init_alloc_info(fs, &fp->obj);
/* Set directory entry block initial state */
- memset(fs->dirbuf + 2, 0, 30); /* Clear 85 entry except for NumSec */
- memset(fs->dirbuf + 38, 0, 26); /* Clear C0 entry except for NumName and NameHash */
+ mem_set(fs->dirbuf + 2, 0, 30); /* Clear 85 entry except for NumSec */
+ mem_set(fs->dirbuf + 38, 0, 26); /* Clear C0 entry except for NumName and NameHash */
fs->dirbuf[XDIR_Attr] = AM_ARC;
st_dword(fs->dirbuf + XDIR_CrtTime, GET_FATTIME());
fs->dirbuf[XDIR_GenFlags] = 1;
@@ -3727,10 +3779,8 @@ FRESULT f_open (
#endif
{
/* Set directory entry initial state */
- tm = GET_FATTIME(); /* Set created time */
- st_dword(dj.dir + DIR_CrtTime, tm);
- st_dword(dj.dir + DIR_ModTime, tm);
cl = ld_clust(fs, dj.dir); /* Get current cluster chain */
+ st_dword(dj.dir + DIR_CrtTime, GET_FATTIME()); /* Set created time */
dj.dir[DIR_Attr] = AM_ARC; /* Reset attribute */
st_clust(fs, dj.dir, 0); /* Reset file allocation info */
st_dword(dj.dir + DIR_FileSize, 0);
@@ -3792,17 +3842,17 @@ FRESULT f_open (
fp->obj.objsize = ld_dword(dj.dir + DIR_FileSize);
}
#if FF_USE_FASTSEEK
- fp->cltbl = 0; /* Disable fast seek mode */
+ fp->cltbl = 0; /* Disable fast seek mode */
#endif
- fp->obj.fs = fs; /* Validate the file object */
+ fp->obj.fs = fs; /* Validate the file object */
fp->obj.id = fs->id;
- fp->flag = mode; /* Set file access mode */
- fp->err = 0; /* Clear error flag */
- fp->sect = 0; /* Invalidate current data sector */
- fp->fptr = 0; /* Set file pointer top of the file */
+ fp->flag = mode; /* Set file access mode */
+ fp->err = 0; /* Clear error flag */
+ fp->sect = 0; /* Invalidate current data sector */
+ fp->fptr = 0; /* Set file pointer top of the file */
#if !FF_FS_READONLY
#if !FF_FS_TINY
- memset(fp->buf, 0, sizeof fp->buf); /* Clear sector buffer */
+ mem_set(fp->buf, 0, sizeof fp->buf); /* Clear sector buffer */
#endif
if ((mode & FA_SEEKEND) && fp->obj.objsize > 0) { /* Seek to end of file if FA_OPEN_APPEND is specified */
fp->fptr = fp->obj.objsize; /* Offset to seek */
@@ -3825,9 +3875,6 @@ FRESULT f_open (
#endif
}
}
-#if FF_FS_LOCK != 0
- if (res != FR_OK) dec_lock(fp->obj.lockid); /* Decrement file open counter if seek failed */
-#endif
}
#endif
}
@@ -3848,10 +3895,10 @@ FRESULT f_open (
/*-----------------------------------------------------------------------*/
FRESULT f_read (
- FIL* fp, /* Open file to be read */
- void* buff, /* Data buffer to store the read data */
+ FIL* fp, /* Pointer to the file object */
+ void* buff, /* Pointer to data buffer */
UINT btr, /* Number of bytes to read */
- UINT* br /* Number of bytes read */
+ UINT* br /* Pointer to number of bytes read */
)
{
FRESULT res;
@@ -3870,7 +3917,8 @@ FRESULT f_read (
remain = fp->obj.objsize - fp->fptr;
if (btr > remain) btr = (UINT)remain; /* Truncate btr by remaining bytes */
- for ( ; btr > 0; btr -= rcnt, *br += rcnt, rbuff += rcnt, fp->fptr += rcnt) { /* Repeat until btr bytes read */
+ for ( ; btr; /* Repeat until btr bytes read */
+ btr -= rcnt, *br += rcnt, rbuff += rcnt, fp->fptr += rcnt) {
if (fp->fptr % SS(fs) == 0) { /* On the sector boundary? */
csect = (UINT)(fp->fptr / SS(fs) & (fs->csize - 1)); /* Sector offset in the cluster */
if (csect == 0) { /* On the cluster boundary? */
@@ -3902,11 +3950,11 @@ FRESULT f_read (
#if !FF_FS_READONLY && FF_FS_MINIMIZE <= 2 /* Replace one of the read sectors with cached data if it contains a dirty sector */
#if FF_FS_TINY
if (fs->wflag && fs->winsect - sect < cc) {
- memcpy(rbuff + ((fs->winsect - sect) * SS(fs)), fs->win, SS(fs));
+ mem_cpy(rbuff + ((fs->winsect - sect) * SS(fs)), fs->win, SS(fs));
}
#else
if ((fp->flag & FA_DIRTY) && fp->sect - sect < cc) {
- memcpy(rbuff + ((fp->sect - sect) * SS(fs)), fp->buf, SS(fs));
+ mem_cpy(rbuff + ((fp->sect - sect) * SS(fs)), fp->buf, SS(fs));
}
#endif
#endif
@@ -3930,9 +3978,9 @@ FRESULT f_read (
if (rcnt > btr) rcnt = btr; /* Clip it by btr if needed */
#if FF_FS_TINY
if (move_window(fs, fp->sect) != FR_OK) ABORT(fs, FR_DISK_ERR); /* Move sector window */
- memcpy(rbuff, fs->win + fp->fptr % SS(fs), rcnt); /* Extract partial sector */
+ mem_cpy(rbuff, fs->win + fp->fptr % SS(fs), rcnt); /* Extract partial sector */
#else
- memcpy(rbuff, fp->buf + fp->fptr % SS(fs), rcnt); /* Extract partial sector */
+ mem_cpy(rbuff, fp->buf + fp->fptr % SS(fs), rcnt); /* Extract partial sector */
#endif
}
@@ -3948,10 +3996,10 @@ FRESULT f_read (
/*-----------------------------------------------------------------------*/
FRESULT f_write (
- FIL* fp, /* Open file to be written */
- const void* buff, /* Data to be written */
+ FIL* fp, /* Pointer to the file object */
+ const void* buff, /* Pointer to the data to be written */
UINT btw, /* Number of bytes to write */
- UINT* bw /* Number of bytes written */
+ UINT* bw /* Pointer to number of bytes written */
)
{
FRESULT res;
@@ -3972,7 +4020,8 @@ FRESULT f_write (
btw = (UINT)(0xFFFFFFFF - (DWORD)fp->fptr);
}
- for ( ; btw > 0; btw -= wcnt, *bw += wcnt, wbuff += wcnt, fp->fptr += wcnt, fp->obj.objsize = (fp->fptr > fp->obj.objsize) ? fp->fptr : fp->obj.objsize) { /* Repeat until all data written */
+ for ( ; btw; /* Repeat until all data written */
+ btw -= wcnt, *bw += wcnt, wbuff += wcnt, fp->fptr += wcnt, fp->obj.objsize = (fp->fptr > fp->obj.objsize) ? fp->fptr : fp->obj.objsize) {
if (fp->fptr % SS(fs) == 0) { /* On the sector boundary? */
csect = (UINT)(fp->fptr / SS(fs)) & (fs->csize - 1); /* Sector offset in the cluster */
if (csect == 0) { /* On the cluster boundary? */
@@ -4017,12 +4066,12 @@ FRESULT f_write (
#if FF_FS_MINIMIZE <= 2
#if FF_FS_TINY
if (fs->winsect - sect < cc) { /* Refill sector cache if it gets invalidated by the direct write */
- memcpy(fs->win, wbuff + ((fs->winsect - sect) * SS(fs)), SS(fs));
+ mem_cpy(fs->win, wbuff + ((fs->winsect - sect) * SS(fs)), SS(fs));
fs->wflag = 0;
}
#else
if (fp->sect - sect < cc) { /* Refill sector cache if it gets invalidated by the direct write */
- memcpy(fp->buf, wbuff + ((fp->sect - sect) * SS(fs)), SS(fs));
+ mem_cpy(fp->buf, wbuff + ((fp->sect - sect) * SS(fs)), SS(fs));
fp->flag &= (BYTE)~FA_DIRTY;
}
#endif
@@ -4048,10 +4097,10 @@ FRESULT f_write (
if (wcnt > btw) wcnt = btw; /* Clip it by btw if needed */
#if FF_FS_TINY
if (move_window(fs, fp->sect) != FR_OK) ABORT(fs, FR_DISK_ERR); /* Move sector window */
- memcpy(fs->win + fp->fptr % SS(fs), wbuff, wcnt); /* Fit data to the sector */
+ mem_cpy(fs->win + fp->fptr % SS(fs), wbuff, wcnt); /* Fit data to the sector */
fs->wflag = 1;
#else
- memcpy(fp->buf + fp->fptr % SS(fs), wbuff, wcnt); /* Fit data to the sector */
+ mem_cpy(fp->buf + fp->fptr % SS(fs), wbuff, wcnt); /* Fit data to the sector */
fp->flag |= FA_DIRTY;
#endif
}
@@ -4069,7 +4118,7 @@ FRESULT f_write (
/*-----------------------------------------------------------------------*/
FRESULT f_sync (
- FIL* fp /* Open file to be synced */
+ FIL* fp /* Pointer to the file object */
)
{
FRESULT res;
@@ -4150,7 +4199,7 @@ FRESULT f_sync (
/*-----------------------------------------------------------------------*/
FRESULT f_close (
- FIL* fp /* Open file to be closed */
+ FIL* fp /* Pointer to the file object to be closed */
)
{
FRESULT res;
@@ -4251,7 +4300,7 @@ FRESULT f_chdir (
}
FREE_NAMBUF();
if (res == FR_NO_FILE) res = FR_NO_PATH;
-#if FF_STR_VOLUME_ID == 2 /* Also current drive is changed if in Unix style volume ID */
+#if FF_STR_VOLUME_ID == 2 /* Also current drive is changed at Unix style volume ID */
if (res == FR_OK) {
for (i = FF_VOLUMES - 1; i && fs != FatFs[i]; i--) ; /* Set current drive */
CurrVol = (BYTE)i;
@@ -4375,8 +4424,7 @@ FRESULT f_lseek (
LBA_t nsect;
FSIZE_t ifptr;
#if FF_USE_FASTSEEK
- DWORD cl, pcl, ncl, tcl, tlen, ulen;
- DWORD *tbl;
+ DWORD cl, pcl, ncl, tcl, tlen, ulen, *tbl;
LBA_t dsc;
#endif
@@ -4688,9 +4736,9 @@ FRESULT f_findnext (
for (;;) {
res = f_readdir(dp, fno); /* Get a directory item */
if (res != FR_OK || !fno || !fno->fname[0]) break; /* Terminate if any error or end of directory */
- if (pattern_match(dp->pat, fno->fname, 0, FIND_RECURS)) break; /* Test for the file name */
+ if (pattern_matching(dp->pat, fno->fname, 0, 0)) break; /* Test for the file name */
#if FF_USE_LFN && FF_USE_FIND == 2
- if (pattern_match(dp->pat, fno->altname, 0, FIND_RECURS)) break; /* Test for alternative name if exist */
+ if (pattern_matching(dp->pat, fno->altname, 0, 0)) break; /* Test for alternative name if exist */
#endif
}
return res;
@@ -4838,11 +4886,9 @@ FRESULT f_getfree (
} while (--clst);
}
}
- if (res == FR_OK) { /* Update parameters if succeeded */
- *nclst = nfree; /* Return the free clusters */
- fs->free_clst = nfree; /* Now free_clst is valid */
- fs->fsi_flag |= 1; /* FAT32: FSInfo is to be updated */
- }
+ *nclst = nfree; /* Return the free clusters */
+ fs->free_clst = nfree; /* Now free_clst is valid */
+ fs->fsi_flag |= 1; /* FAT32: FSInfo is to be updated */
}
}
@@ -4953,12 +4999,12 @@ FRESULT f_unlink (
}
if (dj.obj.attr & AM_DIR) { /* Is it a sub-directory? */
#if FF_FS_RPATH != 0
- if (dclst == fs->cdir) { /* Is it the current directory? */
+ if (dclst == fs->cdir) { /* Is it the current directory? */
res = FR_DENIED;
} else
#endif
{
- sdj.obj.fs = fs; /* Open the sub-directory */
+ sdj.obj.fs = fs; /* Open the sub-directory */
sdj.obj.sclust = dclst;
#if FF_FS_EXFAT
if (fs->fs_type == FS_EXFAT) {
@@ -5033,12 +5079,12 @@ FRESULT f_mkdir (
res = dir_clear(fs, dcl); /* Clean up the new table */
if (res == FR_OK) {
if (!FF_FS_EXFAT || fs->fs_type != FS_EXFAT) { /* Create dot entries (FAT only) */
- memset(fs->win + DIR_Name, ' ', 11); /* Create "." entry */
+ mem_set(fs->win + DIR_Name, ' ', 11); /* Create "." entry */
fs->win[DIR_Name] = '.';
fs->win[DIR_Attr] = AM_DIR;
st_dword(fs->win + DIR_ModTime, tm);
st_clust(fs, fs->win, dcl);
- memcpy(fs->win + SZDIRE, fs->win, SZDIRE); /* Create ".." entry */
+ mem_cpy(fs->win + SZDIRE, fs->win, SZDIRE); /* Create ".." entry */
fs->win[SZDIRE + 1] = '.'; pcl = dj.obj.sclust;
st_clust(fs, fs->win + SZDIRE, pcl);
fs->wflag = 1;
@@ -5102,21 +5148,21 @@ FRESULT f_rename (
if (res == FR_OK) {
djo.obj.fs = fs;
INIT_NAMBUF(fs);
- res = follow_path(&djo, path_old); /* Check old object */
+ res = follow_path(&djo, path_old); /* Check old object */
if (res == FR_OK && (djo.fn[NSFLAG] & (NS_DOT | NS_NONAME))) res = FR_INVALID_NAME; /* Check validity of name */
#if FF_FS_LOCK != 0
if (res == FR_OK) {
res = chk_lock(&djo, 2);
}
#endif
- if (res == FR_OK) { /* Object to be renamed is found */
+ if (res == FR_OK) { /* Object to be renamed is found */
#if FF_FS_EXFAT
if (fs->fs_type == FS_EXFAT) { /* At exFAT volume */
BYTE nf, nn;
WORD nh;
- memcpy(buf, fs->dirbuf, SZDIRE * 2); /* Save 85+C0 entry of old object */
- memcpy(&djn, &djo, sizeof djo);
+ mem_cpy(buf, fs->dirbuf, SZDIRE * 2); /* Save 85+C0 entry of old object */
+ mem_cpy(&djn, &djo, sizeof djo);
res = follow_path(&djn, path_new); /* Make sure if new object name is not in use */
if (res == FR_OK) { /* Is new name already in use by any other object? */
res = (djn.obj.sclust == djo.obj.sclust && djn.dptr == djo.dptr) ? FR_NO_FILE : FR_EXIST;
@@ -5126,7 +5172,7 @@ FRESULT f_rename (
if (res == FR_OK) {
nf = fs->dirbuf[XDIR_NumSec]; nn = fs->dirbuf[XDIR_NumName];
nh = ld_word(fs->dirbuf + XDIR_NameHash);
- memcpy(fs->dirbuf, buf, SZDIRE * 2); /* Restore 85+C0 entry */
+ mem_cpy(fs->dirbuf, buf, SZDIRE * 2); /* Restore 85+C0 entry */
fs->dirbuf[XDIR_NumSec] = nf; fs->dirbuf[XDIR_NumName] = nn;
st_word(fs->dirbuf + XDIR_NameHash, nh);
if (!(fs->dirbuf[XDIR_Attr] & AM_DIR)) fs->dirbuf[XDIR_Attr] |= AM_ARC; /* Set archive attribute if it is a file */
@@ -5137,8 +5183,8 @@ FRESULT f_rename (
} else
#endif
{ /* At FAT/FAT32 volume */
- memcpy(buf, djo.dir, SZDIRE); /* Save directory entry of the object */
- memcpy(&djn, &djo, sizeof (DIR)); /* Duplicate the directory object */
+ mem_cpy(buf, djo.dir, SZDIRE); /* Save directory entry of the object */
+ mem_cpy(&djn, &djo, sizeof (DIR)); /* Duplicate the directory object */
res = follow_path(&djn, path_new); /* Make sure if new object name is not in use */
if (res == FR_OK) { /* Is new name already in use by any other object? */
res = (djn.obj.sclust == djo.obj.sclust && djn.dptr == djo.dptr) ? FR_NO_FILE : FR_EXIST;
@@ -5147,7 +5193,7 @@ FRESULT f_rename (
res = dir_register(&djn); /* Register the new entry */
if (res == FR_OK) {
dir = djn.dir; /* Copy directory entry of the object except name */
- memcpy(dir + 13, buf + 13, SZDIRE - 13);
+ mem_cpy(dir + 13, buf + 13, SZDIRE - 13);
dir[DIR_Attr] = buf[DIR_Attr];
if (!(dir[DIR_Attr] & AM_DIR)) dir[DIR_Attr] |= AM_ARC; /* Set archive attribute if it is a file */
fs->wflag = 1;
@@ -5313,16 +5359,15 @@ FRESULT f_getlabel (
#if FF_FS_EXFAT
if (fs->fs_type == FS_EXFAT) {
WCHAR hs;
- UINT nw;
for (si = di = hs = 0; si < dj.dir[XDIR_NumLabel]; si++) { /* Extract volume label from 83 entry */
wc = ld_word(dj.dir + XDIR_Label + si * 2);
if (hs == 0 && IsSurrogate(wc)) { /* Is the code a surrogate? */
hs = wc; continue;
}
- nw = put_utf((DWORD)hs << 16 | wc, &label[di], 4); /* Store it in API encoding */
- if (nw == 0) { di = 0; break; } /* Encode error? */
- di += nw;
+ wc = put_utf((DWORD)hs << 16 | wc, &label[di], 4);
+ if (wc == 0) { di = 0; break; }
+ di += wc;
hs = 0;
}
if (hs != 0) di = 0; /* Broken surrogate pair? */
@@ -5335,9 +5380,10 @@ FRESULT f_getlabel (
wc = dj.dir[si++];
#if FF_USE_LFN && FF_LFN_UNICODE >= 1 /* Unicode output */
if (dbc_1st((BYTE)wc) && si < 11) wc = wc << 8 | dj.dir[si++]; /* Is it a DBC? */
- wc = ff_oem2uni(wc, CODEPAGE); /* Convert it into Unicode */
- if (wc == 0) { di = 0; break; } /* Invalid char in current code page? */
- di += put_utf(wc, &label[di], 4); /* Store it in Unicode */
+ wc = ff_oem2uni(wc, CODEPAGE); /* Convert it into Unicode */
+ if (wc != 0) wc = put_utf(wc, &label[di], 4); /* Put it in Unicode */
+ if (wc == 0) { di = 0; break; }
+ di += wc;
#else /* ANSI/OEM output */
label[di++] = (TCHAR)wc;
#endif
@@ -5361,12 +5407,10 @@ FRESULT f_getlabel (
if (res == FR_OK) {
switch (fs->fs_type) {
case FS_EXFAT:
- di = BPB_VolIDEx;
- break;
+ di = BPB_VolIDEx; break;
case FS_FAT32:
- di = BS_VolID32;
- break;
+ di = BS_VolID32; break;
default:
di = BS_VolID;
@@ -5395,7 +5439,7 @@ FRESULT f_setlabel (
BYTE dirvn[22];
UINT di;
WCHAR wc;
- static const char badchr[18] = "+.,;=[]" "/*:<>|\\\"\?\x7F"; /* [0..16] for FAT, [7..16] for exFAT */
+ static const char badchr[] = "+.,;=[]/\\\"*:<>\?|\x7F"; /* [0..] for FAT, [7..] for exFAT */
#if FF_USE_LFN
DWORD dc;
#endif
@@ -5406,7 +5450,7 @@ FRESULT f_setlabel (
#if FF_FS_EXFAT
if (fs->fs_type == FS_EXFAT) { /* On the exFAT volume */
- memset(dirvn, 0, 22);
+ mem_set(dirvn, 0, 22);
di = 0;
while ((UINT)*label >= ' ') { /* Create volume label */
dc = tchar2uni(&label); /* Get a Unicode character */
@@ -5417,7 +5461,7 @@ FRESULT f_setlabel (
st_word(dirvn + di * 2, (WCHAR)(dc >> 16)); di++;
}
}
- if (dc == 0 || strchr(&badchr[7], (int)dc) || di >= 11) { /* Check validity of the volume label */
+ if (dc == 0 || chk_chr(badchr + 7, (int)dc) || di >= 11) { /* Check validity of the volume label */
LEAVE_FF(fs, FR_INVALID_NAME);
}
st_word(dirvn + di * 2, (WCHAR)dc); di++;
@@ -5425,7 +5469,7 @@ FRESULT f_setlabel (
} else
#endif
{ /* On the FAT/FAT32 volume */
- memset(dirvn, ' ', 11);
+ mem_set(dirvn, ' ', 11);
di = 0;
while ((UINT)*label >= ' ') { /* Create volume label */
#if FF_USE_LFN
@@ -5441,7 +5485,7 @@ FRESULT f_setlabel (
if (wc >= 0x80) wc = ExCvt[wc - 0x80]; /* To upper extended characters (SBCS cfg) */
#endif
#endif
- if (wc == 0 || strchr(&badchr[0], (int)wc) || di >= (UINT)((wc >= 0x100) ? 10 : 11)) { /* Reject invalid characters for volume label */
+ if (wc == 0 || chk_chr(badchr + 0, (int)wc) || di >= (UINT)((wc >= 0x100) ? 10 : 11)) { /* Reject invalid characters for volume label */
LEAVE_FF(fs, FR_INVALID_NAME);
}
if (wc >= 0x100) dirvn[di++] = (BYTE)(wc >> 8);
@@ -5459,10 +5503,10 @@ FRESULT f_setlabel (
if (res == FR_OK) {
if (FF_FS_EXFAT && fs->fs_type == FS_EXFAT) {
dj.dir[XDIR_NumLabel] = (BYTE)di; /* Change the volume label */
- memcpy(dj.dir + XDIR_Label, dirvn, 22);
+ mem_cpy(dj.dir + XDIR_Label, dirvn, 22);
} else {
if (di != 0) {
- memcpy(dj.dir, dirvn, 11); /* Change the volume label */
+ mem_cpy(dj.dir, dirvn, 11); /* Change the volume label */
} else {
dj.dir[DIR_Name] = DDEM; /* Remove the volume label */
}
@@ -5475,14 +5519,14 @@ FRESULT f_setlabel (
if (di != 0) { /* Create a volume label entry */
res = dir_alloc(&dj, 1); /* Allocate an entry */
if (res == FR_OK) {
- memset(dj.dir, 0, SZDIRE); /* Clean the entry */
+ mem_set(dj.dir, 0, SZDIRE); /* Clean the entry */
if (FF_FS_EXFAT && fs->fs_type == FS_EXFAT) {
dj.dir[XDIR_Type] = ET_VLABEL; /* Create volume label entry */
dj.dir[XDIR_NumLabel] = (BYTE)di;
- memcpy(dj.dir + XDIR_Label, dirvn, 22);
+ mem_cpy(dj.dir + XDIR_Label, dirvn, 22);
} else {
dj.dir[DIR_Attr] = AM_VOL; /* Create volume label entry */
- memcpy(dj.dir, dirvn, 11);
+ mem_cpy(dj.dir, dirvn, 11);
}
fs->wflag = 1;
res = sync_fs(fs);
@@ -5619,7 +5663,8 @@ FRESULT f_forward (
remain = fp->obj.objsize - fp->fptr;
if (btf > remain) btf = (UINT)remain; /* Truncate btf by remaining bytes */
- for ( ; btf > 0 && (*func)(0, 0); fp->fptr += rcnt, *bf += rcnt, btf -= rcnt) { /* Repeat until all data transferred or stream goes busy */
+ for ( ; btf && (*func)(0, 0); /* Repeat until all data transferred or stream goes busy */
+ fp->fptr += rcnt, *bf += rcnt, btf -= rcnt) {
csect = (UINT)(fp->fptr / SS(fs) & (fs->csize - 1)); /* Sector offset in the cluster */
if (fp->fptr % SS(fs) == 0) { /* On the sector boundary? */
if (csect == 0) { /* On the cluster boundary? */
@@ -5663,7 +5708,7 @@ FRESULT f_forward (
#if !FF_FS_READONLY && FF_USE_MKFS
/*-----------------------------------------------------------------------*/
-/* Create FAT/exFAT volume (with sub-functions) */
+/* Create an FAT/exFAT volume */
/*-----------------------------------------------------------------------*/
#define N_SEC_TRACK 63 /* Sectors per track for determination of drive CHS */
@@ -5671,30 +5716,29 @@ FRESULT f_forward (
#define GPT_ITEMS 128 /* Number of GPT table size (>=128, sector aligned) */
-/* Create partitions on the physical drive in format of MBR or GPT */
+/* Create partitions on the physical drive */
static FRESULT create_partition (
BYTE drv, /* Physical drive number */
const LBA_t plst[], /* Partition list */
- BYTE sys, /* System ID (for only MBR, temp setting) */
+ UINT sys, /* System ID (for only MBR, temp setting) and bit8:GPT */
BYTE* buf /* Working buffer for a sector */
)
{
UINT i, cy;
LBA_t sz_drv;
- DWORD sz_drv32, nxt_alloc32, sz_part32;
- BYTE *pte;
- BYTE hd, n_hd, sc, n_sc;
+ DWORD sz_drv32, s_lba32, n_lba32;
+ BYTE *pte, hd, n_hd, sc, n_sc;
- /* Get physical drive size */
+ /* Get drive size */
if (disk_ioctl(drv, GET_SECTOR_COUNT, &sz_drv) != RES_OK) return FR_DISK_ERR;
#if FF_LBA64
- if (sz_drv >= FF_MIN_GPT) { /* Create partitions in GPT format */
+ if (sz_drv >= FF_MIN_GPT) { /* Create partitions in GPT */
WORD ss;
- UINT sz_ptbl, pi, si, ofs;
+ UINT sz_pt, pi, si, ofs;
DWORD bcc, rnd, align;
- QWORD nxt_alloc, sz_part, sz_pool, top_bpt;
+ QWORD s_lba64, n_lba64, sz_pool, s_bpt;
static const BYTE gpt_mbr[16] = {0x00, 0x00, 0x02, 0x00, 0xEE, 0xFE, 0xFF, 0x00, 0x01, 0x00, 0x00, 0x00, 0xFF, 0xFF, 0xFF, 0xFF};
#if FF_MAX_SS != FF_MIN_SS
@@ -5703,103 +5747,103 @@ static FRESULT create_partition (
#else
ss = FF_MAX_SS;
#endif
- rnd = (DWORD)sz_drv + GET_FATTIME(); /* Random seed */
- align = GPT_ALIGN / ss; /* Partition alignment for GPT [sector] */
- sz_ptbl = GPT_ITEMS * SZ_GPTE / ss; /* Size of partition table [sector] */
- top_bpt = sz_drv - sz_ptbl - 1; /* Backup partiiton table start sector */
- nxt_alloc = 2 + sz_ptbl; /* First allocatable sector */
- sz_pool = top_bpt - nxt_alloc; /* Size of allocatable area */
- bcc = 0xFFFFFFFF; sz_part = 1;
+ rnd = GET_FATTIME(); /* Random seed */
+ align = GPT_ALIGN / ss; /* Partition alignment [sector] */
+ sz_pt = GPT_ITEMS * SZ_GPTE / ss; /* Size of PT [sector] */
+ s_bpt = sz_drv - sz_pt - 1; /* Backup PT start sector */
+ s_lba64 = 2 + sz_pt; /* First allocatable sector */
+ sz_pool = s_bpt - s_lba64; /* Size of allocatable area */
+ bcc = 0xFFFFFFFF; n_lba64 = 1;
pi = si = 0; /* partition table index, size table index */
do {
- if (pi * SZ_GPTE % ss == 0) memset(buf, 0, ss); /* Clean the buffer if needed */
- if (sz_part != 0) { /* Is the size table not termintated? */
- nxt_alloc = (nxt_alloc + align - 1) & ((QWORD)0 - align); /* Align partition start */
- sz_part = plst[si++]; /* Get a partition size */
- if (sz_part <= 100) { /* Is the size in percentage? */
- sz_part = sz_pool * sz_part / 100;
- sz_part = (sz_part + align - 1) & ((QWORD)0 - align); /* Align partition end (only if in percentage) */
+ if (pi * SZ_GPTE % ss == 0) mem_set(buf, 0, ss); /* Clean the buffer if needed */
+ if (n_lba64 != 0) { /* Is the size table not termintated? */
+ s_lba64 = (s_lba64 + align - 1) & ((QWORD)0 - align); /* Align partition start */
+ n_lba64 = plst[si++]; /* Get a partition size */
+ if (n_lba64 <= 100) { /* Is the size in percentage? */
+ n_lba64 = sz_pool * n_lba64 / 100;
+ n_lba64 = (n_lba64 + align - 1) & ((QWORD)0 - align); /* Align partition end (only if in percentage) */
}
- if (nxt_alloc + sz_part > top_bpt) { /* Clip the size at end of the pool */
- sz_part = (nxt_alloc < top_bpt) ? top_bpt - nxt_alloc : 0;
+ if (s_lba64 + n_lba64 > s_bpt) { /* Clip at end of the pool */
+ n_lba64 = (s_lba64 < s_bpt) ? s_bpt - s_lba64 : 0;
}
}
- if (sz_part != 0) { /* Add a partition? */
+ if (n_lba64 != 0) { /* Add a partition? */
ofs = pi * SZ_GPTE % ss;
- memcpy(buf + ofs + GPTE_PtGuid, GUID_MS_Basic, 16); /* Set partition GUID (Microsoft Basic Data) */
- rnd = make_rand(rnd, buf + ofs + GPTE_UpGuid, 16); /* Set unique partition GUID */
- st_qword(buf + ofs + GPTE_FstLba, nxt_alloc); /* Set partition start sector */
- st_qword(buf + ofs + GPTE_LstLba, nxt_alloc + sz_part - 1); /* Set partition end sector */
- nxt_alloc += sz_part; /* Next allocatable sector */
+ mem_cpy(buf + ofs + GPTE_PtGuid, GUID_MS_Basic, 16); /* Partition GUID (Microsoft Basic Data) */
+ rnd = make_rand(rnd, buf + ofs + GPTE_UpGuid, 16); /* Unique partition GUID */
+ st_qword(buf + ofs + GPTE_FstLba, s_lba64); /* Partition start LBA */
+ st_qword(buf + ofs + GPTE_LstLba, s_lba64 + n_lba64 - 1); /* Partition end LBA */
+ s_lba64 += n_lba64; /* Next partition LBA */
}
if ((pi + 1) * SZ_GPTE % ss == 0) { /* Write the buffer if it is filled up */
for (i = 0; i < ss; bcc = crc32(bcc, buf[i++])) ; /* Calculate table check sum */
- if (disk_write(drv, buf, 2 + pi * SZ_GPTE / ss, 1) != RES_OK) return FR_DISK_ERR; /* Write to primary table */
- if (disk_write(drv, buf, top_bpt + pi * SZ_GPTE / ss, 1) != RES_OK) return FR_DISK_ERR; /* Write to secondary table */
+ if (disk_write(drv, buf, 2 + pi * SZ_GPTE / ss, 1) != RES_OK) return FR_DISK_ERR; /* Primary table */
+ if (disk_write(drv, buf, s_bpt + pi * SZ_GPTE / ss, 1) != RES_OK) return FR_DISK_ERR; /* Secondary table */
}
} while (++pi < GPT_ITEMS);
/* Create primary GPT header */
- memset(buf, 0, ss);
- memcpy(buf + GPTH_Sign, "EFI PART" "\0\0\1\0" "\x5C\0\0", 16); /* Signature, version (1.0) and size (92) */
- st_dword(buf + GPTH_PtBcc, ~bcc); /* Table check sum */
- st_qword(buf + GPTH_CurLba, 1); /* LBA of this header */
- st_qword(buf + GPTH_BakLba, sz_drv - 1); /* LBA of secondary header */
- st_qword(buf + GPTH_FstLba, 2 + sz_ptbl); /* LBA of first allocatable sector */
- st_qword(buf + GPTH_LstLba, top_bpt - 1); /* LBA of last allocatable sector */
- st_dword(buf + GPTH_PteSize, SZ_GPTE); /* Size of a table entry */
- st_dword(buf + GPTH_PtNum, GPT_ITEMS); /* Number of table entries */
- st_dword(buf + GPTH_PtOfs, 2); /* LBA of this table */
+ mem_set(buf, 0, ss);
+ mem_cpy(buf + GPTH_Sign, "EFI PART" "\0\0\1\0" "\x5C\0\0", 16); /* Signature, version (1.0) and size (92) */
+ st_dword(buf + GPTH_PtBcc, ~bcc); /* Table check sum */
+ st_qword(buf + GPTH_CurLba, 1); /* LBA of this header */
+ st_qword(buf + GPTH_BakLba, sz_drv - 1); /* LBA of another header */
+ st_qword(buf + GPTH_FstLba, 2 + sz_pt); /* LBA of first allocatable sector */
+ st_qword(buf + GPTH_LstLba, s_bpt - 1); /* LBA of last allocatable sector */
+ st_dword(buf + GPTH_PteSize, SZ_GPTE); /* Size of a table entry */
+ st_dword(buf + GPTH_PtNum, GPT_ITEMS); /* Number of table entries */
+ st_dword(buf + GPTH_PtOfs, 2); /* LBA of this table */
rnd = make_rand(rnd, buf + GPTH_DskGuid, 16); /* Disk GUID */
for (i = 0, bcc= 0xFFFFFFFF; i < 92; bcc = crc32(bcc, buf[i++])) ; /* Calculate header check sum */
- st_dword(buf + GPTH_Bcc, ~bcc); /* Header check sum */
+ st_dword(buf + GPTH_Bcc, ~bcc); /* Header check sum */
if (disk_write(drv, buf, 1, 1) != RES_OK) return FR_DISK_ERR;
/* Create secondary GPT header */
- st_qword(buf + GPTH_CurLba, sz_drv - 1); /* LBA of this header */
- st_qword(buf + GPTH_BakLba, 1); /* LBA of primary header */
- st_qword(buf + GPTH_PtOfs, top_bpt); /* LBA of this table */
+ st_qword(buf + GPTH_CurLba, sz_drv - 1); /* LBA of this header */
+ st_qword(buf + GPTH_BakLba, 1); /* LBA of another header */
+ st_qword(buf + GPTH_PtOfs, s_bpt); /* LBA of this table */
st_dword(buf + GPTH_Bcc, 0);
for (i = 0, bcc= 0xFFFFFFFF; i < 92; bcc = crc32(bcc, buf[i++])) ; /* Calculate header check sum */
- st_dword(buf + GPTH_Bcc, ~bcc); /* Header check sum */
+ st_dword(buf + GPTH_Bcc, ~bcc); /* Header check sum */
if (disk_write(drv, buf, sz_drv - 1, 1) != RES_OK) return FR_DISK_ERR;
/* Create protective MBR */
- memset(buf, 0, ss);
- memcpy(buf + MBR_Table, gpt_mbr, 16); /* Create a GPT partition */
+ mem_set(buf, 0, ss);
+ mem_cpy(buf + MBR_Table, gpt_mbr, 16); /* Create a GPT partition */
st_word(buf + BS_55AA, 0xAA55);
if (disk_write(drv, buf, 0, 1) != RES_OK) return FR_DISK_ERR;
} else
#endif
- { /* Create partitions in MBR format */
+ { /* Create partitions in MBR */
sz_drv32 = (DWORD)sz_drv;
- n_sc = N_SEC_TRACK; /* Determine drive CHS without any consideration of the drive geometry */
+ n_sc = N_SEC_TRACK; /* Determine drive CHS without any consideration of the drive geometry */
for (n_hd = 8; n_hd != 0 && sz_drv32 / n_hd / n_sc > 1024; n_hd *= 2) ;
- if (n_hd == 0) n_hd = 255; /* Number of heads needs to be <256 */
+ if (n_hd == 0) n_hd = 255; /* Number of heads needs to be <256 */
- memset(buf, 0, FF_MAX_SS); /* Clear MBR */
+ mem_set(buf, 0, FF_MAX_SS); /* Clear MBR */
pte = buf + MBR_Table; /* Partition table in the MBR */
- for (i = 0, nxt_alloc32 = n_sc; i < 4 && nxt_alloc32 != 0 && nxt_alloc32 < sz_drv32; i++, nxt_alloc32 += sz_part32) {
- sz_part32 = (DWORD)plst[i]; /* Get partition size */
- if (sz_part32 <= 100) sz_part32 = (sz_part32 == 100) ? sz_drv32 : sz_drv32 / 100 * sz_part32; /* Size in percentage? */
- if (nxt_alloc32 + sz_part32 > sz_drv32 || nxt_alloc32 + sz_part32 < nxt_alloc32) sz_part32 = sz_drv32 - nxt_alloc32; /* Clip at drive size */
- if (sz_part32 == 0) break; /* End of table or no sector to allocate? */
+ for (i = 0, s_lba32 = n_sc; i < 4 && s_lba32 != 0 && s_lba32 < sz_drv32; i++, s_lba32 += n_lba32) {
+ n_lba32 = (DWORD)plst[i]; /* Get partition size */
+ if (n_lba32 <= 100) n_lba32 = (n_lba32 == 100) ? sz_drv32 : sz_drv32 / 100 * n_lba32; /* Size in percentage? */
+ if (s_lba32 + n_lba32 > sz_drv32 || s_lba32 + n_lba32 < s_lba32) n_lba32 = sz_drv32 - s_lba32; /* Clip at drive size */
+ if (n_lba32 == 0) break; /* End of table or no sector to allocate? */
- st_dword(pte + PTE_StLba, nxt_alloc32); /* Start LBA */
- st_dword(pte + PTE_SizLba, sz_part32); /* Number of sectors */
- pte[PTE_System] = sys; /* System type */
+ st_dword(pte + PTE_StLba, s_lba32); /* Start LBA */
+ st_dword(pte + PTE_SizLba, n_lba32); /* Number of sectors */
+ pte[PTE_System] = (BYTE)sys; /* System type */
- cy = (UINT)(nxt_alloc32 / n_sc / n_hd); /* Start cylinder */
- hd = (BYTE)(nxt_alloc32 / n_sc % n_hd); /* Start head */
- sc = (BYTE)(nxt_alloc32 % n_sc + 1); /* Start sector */
+ cy = (UINT)(s_lba32 / n_sc / n_hd); /* Start cylinder */
+ hd = (BYTE)(s_lba32 / n_sc % n_hd); /* Start head */
+ sc = (BYTE)(s_lba32 % n_sc + 1); /* Start sector */
pte[PTE_StHead] = hd;
pte[PTE_StSec] = (BYTE)((cy >> 2 & 0xC0) | sc);
pte[PTE_StCyl] = (BYTE)cy;
- cy = (UINT)((nxt_alloc32 + sz_part32 - 1) / n_sc / n_hd); /* End cylinder */
- hd = (BYTE)((nxt_alloc32 + sz_part32 - 1) / n_sc % n_hd); /* End head */
- sc = (BYTE)((nxt_alloc32 + sz_part32 - 1) % n_sc + 1); /* End sector */
+ cy = (UINT)((s_lba32 + n_lba32 - 1) / n_sc / n_hd); /* End cylinder */
+ hd = (BYTE)((s_lba32 + n_lba32 - 1) / n_sc % n_hd); /* End head */
+ sc = (BYTE)((s_lba32 + n_lba32 - 1) % n_sc + 1); /* End sector */
pte[PTE_EdHead] = hd;
pte[PTE_EdSec] = (BYTE)((cy >> 2 & 0xC0) | sc);
pte[PTE_EdCyl] = (BYTE)cy;
@@ -5828,7 +5872,7 @@ FRESULT f_mkfs (
static const MKFS_PARM defopt = {FM_ANY, 0, 0, 0, 0}; /* Default parameter */
BYTE fsopt, fsty, sys, *buf, *pte, pdrv, ipart;
WORD ss; /* Sector size */
- DWORD sz_buf, sz_blk, n_clst, pau, nsect, n, vsn;
+ DWORD sz_buf, sz_blk, n_clst, pau, nsect, n;
LBA_t sz_vol, b_vol, b_fat, b_data; /* Size of volume, Base LBA of volume, fat, data */
LBA_t sect, lba[2];
DWORD sz_rsv, sz_fat, sz_dir, sz_au; /* Size of reserved, fat, dir, data, cluster */
@@ -5894,7 +5938,7 @@ FRESULT f_mkfs (
ofs = i = 0;
while (n_ent) { /* Find MS Basic partition with order of ipart */
if (ofs == 0 && disk_read(pdrv, buf, pt_lba++, 1) != RES_OK) LEAVE_MKFS(FR_DISK_ERR); /* Get PT sector */
- if (!memcmp(buf + ofs + GPTE_PtGuid, GUID_MS_Basic, 16) && ++i == ipart) { /* MS basic data partition? */
+ if (!mem_cmp(buf + ofs + GPTE_PtGuid, GUID_MS_Basic, 16) && ++i == ipart) { /* MS basic data partition? */
b_vol = ld_qword(buf + ofs + GPTE_FstLba);
sz_vol = ld_qword(buf + ofs + GPTE_LstLba) - b_vol + 1;
break;
@@ -5930,7 +5974,7 @@ FRESULT f_mkfs (
}
if (sz_vol < 128) LEAVE_MKFS(FR_MKFS_ABORTED); /* Check if volume size is >=128s */
- /* Now start to create an FAT volume at b_vol and sz_vol */
+ /* Now start to create a FAT volume at b_vol and sz_vol */
do { /* Pre-determine the FAT type */
if (FF_FS_EXFAT && (fsopt & FM_EXFAT)) { /* exFAT possible? */
@@ -5951,13 +5995,12 @@ FRESULT f_mkfs (
fsty = FS_FAT16;
} while (0);
- vsn = (DWORD)sz_vol + GET_FATTIME(); /* VSN generated from current time and partitiion size */
-
#if FF_FS_EXFAT
if (fsty == FS_EXFAT) { /* Create an exFAT volume */
- DWORD szb_bit, szb_case, sum, nbit, clu, clen[3];
+ DWORD szb_bit, szb_case, sum, nb, cl, tbl[3];
WCHAR ch, si;
UINT j, st;
+ BYTE b;
if (sz_vol < 0x1000) LEAVE_MKFS(FR_MKFS_ABORTED); /* Too small volume for exFAT? */
#if FF_USE_TRIM
@@ -5978,12 +6021,12 @@ FRESULT f_mkfs (
if (n_clst <16) LEAVE_MKFS(FR_MKFS_ABORTED); /* Too few clusters? */
if (n_clst > MAX_EXFAT) LEAVE_MKFS(FR_MKFS_ABORTED); /* Too many clusters? */
- szb_bit = (n_clst + 7) / 8; /* Size of allocation bitmap */
- clen[0] = (szb_bit + sz_au * ss - 1) / (sz_au * ss); /* Number of allocation bitmap clusters */
+ szb_bit = (n_clst + 7) / 8; /* Size of allocation bitmap */
+ tbl[0] = (szb_bit + sz_au * ss - 1) / (sz_au * ss); /* Number of allocation bitmap clusters */
/* Create a compressed up-case table */
- sect = b_data + sz_au * clen[0]; /* Table start sector */
- sum = 0; /* Table checksum to be stored in the 82 entry */
+ sect = b_data + sz_au * tbl[0]; /* Table start sector */
+ sum = 0; /* Table checksum to be stored in the 82 entry */
st = 0; si = 0; i = 0; j = 0; szb_case = 0;
do {
switch (st) {
@@ -5994,10 +6037,10 @@ FRESULT f_mkfs (
}
for (j = 1; (WCHAR)(si + j) && (WCHAR)(si + j) == ff_wtoupper((WCHAR)(si + j)); j++) ; /* Get run length of no-case block */
if (j >= 128) {
- ch = 0xFFFF; st = 2; break; /* Compress the no-case block if run is >= 128 chars */
+ ch = 0xFFFF; st = 2; break; /* Compress the no-case block if run is >= 128 */
}
st = 1; /* Do not compress short run */
- /* FALLTHROUGH */
+ /* go to next case */
case 1:
ch = si++; /* Fill the short run */
if (--j == 0) st = 0;
@@ -6007,7 +6050,7 @@ FRESULT f_mkfs (
ch = (WCHAR)j; si += (WCHAR)j; /* Number of chars to skip */
st = 0;
}
- sum = xsum32(buf[i + 0] = (BYTE)ch, sum); /* Put it into the write buffer */
+ sum = xsum32(buf[i + 0] = (BYTE)ch, sum); /* Put it into the write buffer */
sum = xsum32(buf[i + 1] = (BYTE)(ch >> 8), sum);
i += 2; szb_case += 2;
if (si == 0 || i == sz_buf * ss) { /* Write buffered data when buffer full or end of process */
@@ -6016,15 +6059,16 @@ FRESULT f_mkfs (
sect += n; i = 0;
}
} while (si);
- clen[1] = (szb_case + sz_au * ss - 1) / (sz_au * ss); /* Number of up-case table clusters */
- clen[2] = 1; /* Number of root dir clusters */
+ tbl[1] = (szb_case + sz_au * ss - 1) / (sz_au * ss); /* Number of up-case table clusters */
+ tbl[2] = 1; /* Number of root dir clusters */
/* Initialize the allocation bitmap */
- sect = b_data; nsect = (szb_bit + ss - 1) / ss; /* Start of bitmap and number of bitmap sectors */
- nbit = clen[0] + clen[1] + clen[2]; /* Number of clusters in-use by system (bitmap, up-case and root-dir) */
+ sect = b_data; nsect = (szb_bit + ss - 1) / ss; /* Start of bitmap and number of sectors */
+ nb = tbl[0] + tbl[1] + tbl[2]; /* Number of clusters in-use by system */
do {
- memset(buf, 0, sz_buf * ss); /* Initialize bitmap buffer */
- for (i = 0; nbit != 0 && i / 8 < sz_buf * ss; buf[i / 8] |= 1 << (i % 8), i++, nbit--) ; /* Mark used clusters */
+ mem_set(buf, 0, sz_buf * ss);
+ for (i = 0; nb >= 8 && i < sz_buf * ss; buf[i++] = 0xFF, nb -= 8) ;
+ for (b = 1; nb != 0 && i < sz_buf * ss; buf[i] |= b, b <<= 1, nb--) ;
n = (nsect > sz_buf) ? sz_buf : nsect; /* Write the buffered data */
if (disk_write(pdrv, buf, sect, n) != RES_OK) LEAVE_MKFS(FR_DISK_ERR);
sect += n; nsect -= n;
@@ -6032,40 +6076,40 @@ FRESULT f_mkfs (
/* Initialize the FAT */
sect = b_fat; nsect = sz_fat; /* Start of FAT and number of FAT sectors */
- j = nbit = clu = 0;
+ j = nb = cl = 0;
do {
- memset(buf, 0, sz_buf * ss); i = 0; /* Clear work area and reset write offset */
- if (clu == 0) { /* Initialize FAT [0] and FAT[1] */
- st_dword(buf + i, 0xFFFFFFF8); i += 4; clu++;
- st_dword(buf + i, 0xFFFFFFFF); i += 4; clu++;
+ mem_set(buf, 0, sz_buf * ss); i = 0; /* Clear work area and reset write index */
+ if (cl == 0) { /* Set FAT [0] and FAT[1] */
+ st_dword(buf + i, 0xFFFFFFF8); i += 4; cl++;
+ st_dword(buf + i, 0xFFFFFFFF); i += 4; cl++;
}
do { /* Create chains of bitmap, up-case and root dir */
- while (nbit != 0 && i < sz_buf * ss) { /* Create a chain */
- st_dword(buf + i, (nbit > 1) ? clu + 1 : 0xFFFFFFFF);
- i += 4; clu++; nbit--;
+ while (nb != 0 && i < sz_buf * ss) { /* Create a chain */
+ st_dword(buf + i, (nb > 1) ? cl + 1 : 0xFFFFFFFF);
+ i += 4; cl++; nb--;
}
- if (nbit == 0 && j < 3) nbit = clen[j++]; /* Get next chain length */
- } while (nbit != 0 && i < sz_buf * ss);
+ if (nb == 0 && j < 3) nb = tbl[j++]; /* Next chain */
+ } while (nb != 0 && i < sz_buf * ss);
n = (nsect > sz_buf) ? sz_buf : nsect; /* Write the buffered data */
if (disk_write(pdrv, buf, sect, n) != RES_OK) LEAVE_MKFS(FR_DISK_ERR);
sect += n; nsect -= n;
} while (nsect);
/* Initialize the root directory */
- memset(buf, 0, sz_buf * ss);
- buf[SZDIRE * 0 + 0] = ET_VLABEL; /* Volume label entry (no label) */
- buf[SZDIRE * 1 + 0] = ET_BITMAP; /* Bitmap entry */
- st_dword(buf + SZDIRE * 1 + 20, 2); /* cluster */
- st_dword(buf + SZDIRE * 1 + 24, szb_bit); /* size */
- buf[SZDIRE * 2 + 0] = ET_UPCASE; /* Up-case table entry */
- st_dword(buf + SZDIRE * 2 + 4, sum); /* sum */
- st_dword(buf + SZDIRE * 2 + 20, 2 + clen[0]); /* cluster */
- st_dword(buf + SZDIRE * 2 + 24, szb_case); /* size */
- sect = b_data + sz_au * (clen[0] + clen[1]); nsect = sz_au; /* Start of the root directory and number of sectors */
+ mem_set(buf, 0, sz_buf * ss);
+ buf[SZDIRE * 0 + 0] = ET_VLABEL; /* Volume label entry (no label) */
+ buf[SZDIRE * 1 + 0] = ET_BITMAP; /* Bitmap entry */
+ st_dword(buf + SZDIRE * 1 + 20, 2); /* cluster */
+ st_dword(buf + SZDIRE * 1 + 24, szb_bit); /* size */
+ buf[SZDIRE * 2 + 0] = ET_UPCASE; /* Up-case table entry */
+ st_dword(buf + SZDIRE * 2 + 4, sum); /* sum */
+ st_dword(buf + SZDIRE * 2 + 20, 2 + tbl[0]); /* cluster */
+ st_dword(buf + SZDIRE * 2 + 24, szb_case); /* size */
+ sect = b_data + sz_au * (tbl[0] + tbl[1]); nsect = sz_au; /* Start of the root directory and number of sectors */
do { /* Fill root directory sectors */
n = (nsect > sz_buf) ? sz_buf : nsect;
if (disk_write(pdrv, buf, sect, n) != RES_OK) LEAVE_MKFS(FR_DISK_ERR);
- memset(buf, 0, ss); /* Rest of entries are filled with zero */
+ mem_set(buf, 0, ss);
sect += n; nsect -= n;
} while (nsect);
@@ -6073,16 +6117,16 @@ FRESULT f_mkfs (
sect = b_vol;
for (n = 0; n < 2; n++) {
/* Main record (+0) */
- memset(buf, 0, ss);
- memcpy(buf + BS_JmpBoot, "\xEB\x76\x90" "EXFAT ", 11); /* Boot jump code (x86), OEM name */
+ mem_set(buf, 0, ss);
+ mem_cpy(buf + BS_JmpBoot, "\xEB\x76\x90" "EXFAT ", 11); /* Boot jump code (x86), OEM name */
st_qword(buf + BPB_VolOfsEx, b_vol); /* Volume offset in the physical drive [sector] */
st_qword(buf + BPB_TotSecEx, sz_vol); /* Volume size [sector] */
st_dword(buf + BPB_FatOfsEx, (DWORD)(b_fat - b_vol)); /* FAT offset [sector] */
st_dword(buf + BPB_FatSzEx, sz_fat); /* FAT size [sector] */
st_dword(buf + BPB_DataOfsEx, (DWORD)(b_data - b_vol)); /* Data offset [sector] */
st_dword(buf + BPB_NumClusEx, n_clst); /* Number of clusters */
- st_dword(buf + BPB_RootClusEx, 2 + clen[0] + clen[1]); /* Root dir cluster # */
- st_dword(buf + BPB_VolIDEx, vsn); /* VSN */
+ st_dword(buf + BPB_RootClusEx, 2 + tbl[0] + tbl[1]); /* Root dir cluster # */
+ st_dword(buf + BPB_VolIDEx, GET_FATTIME()); /* VSN */
st_word(buf + BPB_FSVerEx, 0x100); /* Filesystem version (1.00) */
for (buf[BPB_BytsPerSecEx] = 0, i = ss; i >>= 1; buf[BPB_BytsPerSecEx]++) ; /* Log2 of sector size [byte] */
for (buf[BPB_SecPerClusEx] = 0, i = sz_au; i >>= 1; buf[BPB_SecPerClusEx]++) ; /* Log2 of cluster size [sector] */
@@ -6095,14 +6139,14 @@ FRESULT f_mkfs (
}
if (disk_write(pdrv, buf, sect++, 1) != RES_OK) LEAVE_MKFS(FR_DISK_ERR);
/* Extended bootstrap record (+1..+8) */
- memset(buf, 0, ss);
+ mem_set(buf, 0, ss);
st_word(buf + ss - 2, 0xAA55); /* Signature (placed at end of sector) */
for (j = 1; j < 9; j++) {
for (i = 0; i < ss; sum = xsum32(buf[i++], sum)) ; /* VBR checksum */
if (disk_write(pdrv, buf, sect++, 1) != RES_OK) LEAVE_MKFS(FR_DISK_ERR);
}
/* OEM/Reserved record (+9..+10) */
- memset(buf, 0, ss);
+ mem_set(buf, 0, ss);
for ( ; j < 11; j++) {
for (i = 0; i < ss; sum = xsum32(buf[i++], sum)) ; /* VBR checksum */
if (disk_write(pdrv, buf, sect++, 1) != RES_OK) LEAVE_MKFS(FR_DISK_ERR);
@@ -6170,7 +6214,7 @@ FRESULT f_mkfs (
if (fsty == FS_FAT16) {
if (n_clst > MAX_FAT16) { /* Too many clusters for FAT16 */
if (sz_au == 0 && (pau * 2) <= 64) {
- sz_au = pau * 2; continue; /* Adjust cluster size and retry */
+ sz_au = pau * 2; continue; /* Adjust cluster size and retry */
}
if ((fsopt & FM_FAT32)) {
fsty = FS_FAT32; continue; /* Switch type to FAT32 and retry */
@@ -6194,8 +6238,8 @@ FRESULT f_mkfs (
disk_ioctl(pdrv, CTRL_TRIM, lba);
#endif
/* Create FAT VBR */
- memset(buf, 0, ss);
- memcpy(buf + BS_JmpBoot, "\xEB\xFE\x90" "MSDOS5.0", 11); /* Boot jump code (x86), OEM name */
+ mem_set(buf, 0, ss);
+ mem_cpy(buf + BS_JmpBoot, "\xEB\xFE\x90" "MSDOS5.0", 11);/* Boot jump code (x86), OEM name */
st_word(buf + BPB_BytsPerSec, ss); /* Sector size [byte] */
buf[BPB_SecPerClus] = (BYTE)pau; /* Cluster size [sector] */
st_word(buf + BPB_RsvdSecCnt, (WORD)sz_rsv); /* Size of reserved area */
@@ -6211,20 +6255,20 @@ FRESULT f_mkfs (
st_word(buf + BPB_NumHeads, 255); /* Number of heads (for int13) */
st_dword(buf + BPB_HiddSec, (DWORD)b_vol); /* Volume offset in the physical drive [sector] */
if (fsty == FS_FAT32) {
- st_dword(buf + BS_VolID32, vsn); /* VSN */
+ st_dword(buf + BS_VolID32, GET_FATTIME()); /* VSN */
st_dword(buf + BPB_FATSz32, sz_fat); /* FAT size [sector] */
st_dword(buf + BPB_RootClus32, 2); /* Root directory cluster # (2) */
st_word(buf + BPB_FSInfo32, 1); /* Offset of FSINFO sector (VBR + 1) */
st_word(buf + BPB_BkBootSec32, 6); /* Offset of backup VBR (VBR + 6) */
buf[BS_DrvNum32] = 0x80; /* Drive number (for int13) */
buf[BS_BootSig32] = 0x29; /* Extended boot signature */
- memcpy(buf + BS_VolLab32, "NO NAME " "FAT32 ", 19); /* Volume label, FAT signature */
+ mem_cpy(buf + BS_VolLab32, "NO NAME " "FAT32 ", 19); /* Volume label, FAT signature */
} else {
- st_dword(buf + BS_VolID, vsn); /* VSN */
+ st_dword(buf + BS_VolID, GET_FATTIME()); /* VSN */
st_word(buf + BPB_FATSz16, (WORD)sz_fat); /* FAT size [sector] */
buf[BS_DrvNum] = 0x80; /* Drive number (for int13) */
buf[BS_BootSig] = 0x29; /* Extended boot signature */
- memcpy(buf + BS_VolLab, "NO NAME " "FAT ", 19); /* Volume label, FAT signature */
+ mem_cpy(buf + BS_VolLab, "NO NAME " "FAT ", 19); /* Volume label, FAT signature */
}
st_word(buf + BS_55AA, 0xAA55); /* Signature (offset is fixed here regardless of sector size) */
if (disk_write(pdrv, buf, b_vol, 1) != RES_OK) LEAVE_MKFS(FR_DISK_ERR); /* Write it to the VBR sector */
@@ -6232,7 +6276,7 @@ FRESULT f_mkfs (
/* Create FSINFO record if needed */
if (fsty == FS_FAT32) {
disk_write(pdrv, buf, b_vol + 6, 1); /* Write backup VBR (VBR + 6) */
- memset(buf, 0, ss);
+ mem_set(buf, 0, ss);
st_dword(buf + FSI_LeadSig, 0x41615252);
st_dword(buf + FSI_StrucSig, 0x61417272);
st_dword(buf + FSI_Free_Count, n_clst - 1); /* Number of free clusters */
@@ -6243,7 +6287,7 @@ FRESULT f_mkfs (
}
/* Initialize FAT area */
- memset(buf, 0, sz_buf * ss);
+ mem_set(buf, 0, sz_buf * ss);
sect = b_fat; /* FAT start sector */
for (i = 0; i < n_fat; i++) { /* Initialize FATs each */
if (fsty == FS_FAT32) {
@@ -6257,7 +6301,7 @@ FRESULT f_mkfs (
do { /* Fill FAT sectors */
n = (nsect > sz_buf) ? sz_buf : nsect;
if (disk_write(pdrv, buf, sect, (UINT)n) != RES_OK) LEAVE_MKFS(FR_DISK_ERR);
- memset(buf, 0, ss); /* Rest of FAT all are cleared */
+ mem_set(buf, 0, ss); /* Rest of FAT all are cleared */
sect += n; nsect -= n;
} while (nsect);
}
@@ -6297,8 +6341,8 @@ FRESULT f_mkfs (
if (disk_write(pdrv, buf, 0, 1) != RES_OK) LEAVE_MKFS(FR_DISK_ERR); /* Write it back to the MBR */
}
} else { /* Volume as a new single partition */
- if (!(fsopt & FM_SFD)) { /* Create partition table if not in SFD */
- lba[0] = sz_vol; lba[1] = 0;
+ if (!(fsopt & FM_SFD)) { /* Create partition table if not in SFD */
+ lba[0] = sz_vol, lba[1] = 0;
fr = create_partition(pdrv, lba, sys, buf);
if (fr != FR_OK) LEAVE_MKFS(fr);
}
@@ -6381,12 +6425,12 @@ TCHAR* f_gets (
if (rc != 1) break; /* EOF? */
wc = s[0];
if (dbc_1st((BYTE)wc)) { /* DBC 1st byte? */
- f_read(fp, s, 1, &rc); /* Get 2nd byte */
+ f_read(fp, s, 1, &rc); /* Get DBC 2nd byte */
if (rc != 1 || !dbc_2nd(s[0])) continue; /* Wrong code? */
wc = wc << 8 | s[0];
}
- dc = ff_oem2uni(wc, CODEPAGE); /* Convert ANSI/OEM into Unicode */
- if (dc == 0) continue; /* Conversion error? */
+ dc = ff_oem2uni(wc, CODEPAGE); /* OEM --> */
+ if (dc == 0) continue;
#elif FF_STRF_ENCODE == 1 || FF_STRF_ENCODE == 2 /* Read a character in UTF-16LE/BE */
f_read(fp, s, 2, &rc); /* Get a code unit */
if (rc != 2) break; /* EOF? */
@@ -6409,7 +6453,7 @@ TCHAR* f_gets (
if ((dc & 0xF0) == 0xE0) { dc &= 0x0F; ct = 2; } /* 3-byte sequence? */
if ((dc & 0xF8) == 0xF0) { dc &= 0x07; ct = 3; } /* 4-byte sequence? */
if (ct == 0) continue;
- f_read(fp, s, ct, &rc); /* Get trailing bytes */
+ f_read(fp, s, ct, &rc); /* Get trailing bytes */
if (rc != ct) break;
rc = 0;
do { /* Merge the byte sequence */
@@ -6478,14 +6522,11 @@ TCHAR* f_gets (
#if !FF_FS_READONLY
#include
-#define SZ_PUTC_BUF 64
-#define SZ_NUM_BUF 32
-
/*-----------------------------------------------------------------------*/
-/* Put a Character to the File (with sub-functions) */
+/* Put a Character to the File (sub-functions) */
/*-----------------------------------------------------------------------*/
-/* Output buffer and work area */
+/* Putchar output buffer and work area */
typedef struct {
FIL *fp; /* Ptr to the writing file */
@@ -6496,11 +6537,11 @@ typedef struct {
BYTE bs[4];
UINT wi, ct;
#endif
- BYTE buf[SZ_PUTC_BUF]; /* Write buffer */
+ BYTE buf[64]; /* Write buffer */
} putbuff;
-/* Buffered file write with code conversion */
+/* Buffered write with code conversion */
static void putc_bfd (putbuff* pb, TCHAR c)
{
@@ -6510,7 +6551,7 @@ static void putc_bfd (putbuff* pb, TCHAR c)
WCHAR hs, wc;
#if FF_LFN_UNICODE == 2
DWORD dc;
- const TCHAR *tp;
+ TCHAR *tp;
#endif
#endif
@@ -6519,7 +6560,7 @@ static void putc_bfd (putbuff* pb, TCHAR c)
}
i = pb->idx; /* Write index of pb->buf[] */
- if (i < 0) return; /* In write error? */
+ if (i < 0) return;
nc = pb->nchr; /* Write unit counter */
#if FF_USE_LFN && FF_LFN_UNICODE
@@ -6552,7 +6593,7 @@ static void putc_bfd (putbuff* pb, TCHAR c)
return;
}
}
- tp = (const TCHAR*)pb->bs;
+ tp = (TCHAR*)pb->bs;
dc = tchar2uni(&tp); /* UTF-8 ==> UTF-16 */
if (dc == 0xFFFFFFFF) return; /* Wrong code? */
wc = (WCHAR)dc;
@@ -6618,7 +6659,7 @@ static void putc_bfd (putbuff* pb, TCHAR c)
pb->buf[i++] = (BYTE)wc;
#endif
-#else /* ANSI/OEM input (without re-encoding) */
+#else /* ANSI/OEM input (without re-encoding) */
pb->buf[i++] = (BYTE)c;
#endif
@@ -6640,7 +6681,7 @@ static int putc_flush (putbuff* pb)
if ( pb->idx >= 0 /* Flush buffered characters to the file */
&& f_write(pb->fp, pb->buf, (UINT)pb->idx, &nw) == FR_OK
&& (UINT)pb->idx == nw) return pb->nchr;
- return -1;
+ return EOF;
}
@@ -6648,7 +6689,7 @@ static int putc_flush (putbuff* pb)
static void putc_init (putbuff* pb, FIL* fp)
{
- memset(pb, 0, sizeof (putbuff));
+ mem_set(pb, 0, sizeof (putbuff));
pb->fp = fp;
}
@@ -6691,129 +6732,8 @@ int f_puts (
/*-----------------------------------------------------------------------*/
-/* Put a Formatted String to the File (with sub-functions) */
+/* Put a Formatted String to the File */
/*-----------------------------------------------------------------------*/
-#if FF_PRINT_FLOAT && FF_INTDEF == 2
-#include
-
-static int ilog10 (double n) /* Calculate log10(n) in integer output */
-{
- int rv = 0;
-
- while (n >= 10) { /* Decimate digit in right shift */
- if (n >= 100000) {
- n /= 100000; rv += 5;
- } else {
- n /= 10; rv++;
- }
- }
- while (n < 1) { /* Decimate digit in left shift */
- if (n < 0.00001) {
- n *= 100000; rv -= 5;
- } else {
- n *= 10; rv--;
- }
- }
- return rv;
-}
-
-
-static double i10x (int n) /* Calculate 10^n in integer input */
-{
- double rv = 1;
-
- while (n > 0) { /* Left shift */
- if (n >= 5) {
- rv *= 100000; n -= 5;
- } else {
- rv *= 10; n--;
- }
- }
- while (n < 0) { /* Right shift */
- if (n <= -5) {
- rv /= 100000; n += 5;
- } else {
- rv /= 10; n++;
- }
- }
- return rv;
-}
-
-
-static void ftoa (
- char* buf, /* Buffer to output the floating point string */
- double val, /* Value to output */
- int prec, /* Number of fractional digits */
- TCHAR fmt /* Notation */
-)
-{
- int d;
- int e = 0, m = 0;
- char sign = 0;
- double w;
- const char *er = 0;
- const char ds = FF_PRINT_FLOAT == 2 ? ',' : '.';
-
-
- if (isnan(val)) { /* Not a number? */
- er = "NaN";
- } else {
- if (prec < 0) prec = 6; /* Default precision? (6 fractional digits) */
- if (val < 0) { /* Nagative? */
- val = 0 - val; sign = '-';
- } else {
- sign = '+';
- }
- if (isinf(val)) { /* Infinite? */
- er = "INF";
- } else {
- if (fmt == 'f') { /* Decimal notation? */
- val += i10x(0 - prec) / 2; /* Round (nearest) */
- m = ilog10(val);
- if (m < 0) m = 0;
- if (m + prec + 3 >= SZ_NUM_BUF) er = "OV"; /* Buffer overflow? */
- } else { /* E notation */
- if (val != 0) { /* Not a true zero? */
- val += i10x(ilog10(val) - prec) / 2; /* Round (nearest) */
- e = ilog10(val);
- if (e > 99 || prec + 7 >= SZ_NUM_BUF) { /* Buffer overflow or E > +99? */
- er = "OV";
- } else {
- if (e < -99) e = -99;
- val /= i10x(e); /* Normalize */
- }
- }
- }
- }
- if (!er) { /* Not error condition */
- if (sign == '-') *buf++ = sign; /* Add a - if negative value */
- do { /* Put decimal number */
- if (m == -1) *buf++ = ds; /* Insert a decimal separator when get into fractional part */
- w = i10x(m); /* Snip the highest digit d */
- d = (int)(val / w); val -= d * w;
- *buf++ = (char)('0' + d); /* Put the digit */
- } while (--m >= -prec); /* Output all digits specified by prec */
- if (fmt != 'f') { /* Put exponent if needed */
- *buf++ = (char)fmt;
- if (e < 0) {
- e = 0 - e; *buf++ = '-';
- } else {
- *buf++ = '+';
- }
- *buf++ = (char)('0' + e / 10);
- *buf++ = (char)('0' + e % 10);
- }
- }
- }
- if (er) { /* Error condition */
- if (sign) *buf++ = sign; /* Add sign if needed */
- do *buf++ = *er++; while (*er); /* Put error symbol */
- }
- *buf = 0; /* Term */
-}
-#endif /* FF_PRINT_FLOAT && FF_INTDEF == 2 */
-
-
int f_printf (
FIL* fp, /* Pointer to the file object */
@@ -6823,16 +6743,10 @@ int f_printf (
{
va_list arp;
putbuff pb;
- UINT i, j, w, f, r;
- int prec;
-#if FF_PRINT_LLI && FF_INTDEF == 2
- QWORD v;
-#else
+ BYTE f, r;
+ UINT i, j, w;
DWORD v;
-#endif
- TCHAR tc, pad, *tp;
- TCHAR nul = 0;
- char d, str[SZ_NUM_BUF];
+ TCHAR c, d, str[32], *p;
putc_init(&pb, fp);
@@ -6840,122 +6754,88 @@ int f_printf (
va_start(arp, fmt);
for (;;) {
- tc = *fmt++;
- if (tc == 0) break; /* End of format string */
- if (tc != '%') { /* Not an escape character (pass-through) */
- putc_bfd(&pb, tc);
+ c = *fmt++;
+ if (c == 0) break; /* End of string */
+ if (c != '%') { /* Non escape character */
+ putc_bfd(&pb, c);
continue;
}
- f = w = 0; pad = ' '; prec = -1; /* Initialize parms */
- tc = *fmt++;
- if (tc == '0') { /* Flag: '0' padded */
- pad = '0'; tc = *fmt++;
- } else if (tc == '-') { /* Flag: Left aligned */
- f = 2; tc = *fmt++;
- }
- if (tc == '*') { /* Minimum width from an argument */
- w = va_arg(arp, int);
- tc = *fmt++;
+ w = f = 0;
+ c = *fmt++;
+ if (c == '0') { /* Flag: '0' padding */
+ f = 1; c = *fmt++;
} else {
- while (IsDigit(tc)) { /* Minimum width */
- w = w * 10 + tc - '0';
- tc = *fmt++;
+ if (c == '-') { /* Flag: left justified */
+ f = 2; c = *fmt++;
}
}
- if (tc == '.') { /* Precision */
- tc = *fmt++;
- if (tc == '*') { /* Precision from an argument */
- prec = va_arg(arp, int);
- tc = *fmt++;
- } else {
- prec = 0;
- while (IsDigit(tc)) { /* Precision */
- prec = prec * 10 + tc - '0';
- tc = *fmt++;
- }
+ if (c == '*') { /* Minimum width by argument */
+ w = va_arg(arp, int);
+ c = *fmt++;
+ } else {
+ while (IsDigit(c)) { /* Minimum width */
+ w = w * 10 + c - '0';
+ c = *fmt++;
}
}
- if (tc == 'l') { /* Size: long int */
- f |= 4; tc = *fmt++;
-#if FF_PRINT_LLI && FF_INTDEF == 2
- if (tc == 'l') { /* Size: long long int */
- f |= 8; tc = *fmt++;
- }
-#endif
+ if (c == 'l' || c == 'L') { /* Type prefix: Size is long int */
+ f |= 4; c = *fmt++;
}
- if (tc == 0) break; /* End of format string */
- switch (tc) { /* Atgument type is... */
- case 'b': /* Unsigned binary */
+ if (c == 0) break;
+ d = c;
+ if (IsLower(d)) d -= 0x20;
+ switch (d) { /* Atgument type is... */
+ case 'S' : /* String */
+ p = va_arg(arp, TCHAR*);
+ for (j = 0; p[j]; j++) ;
+ if (!(f & 2)) { /* Right padded */
+ while (j++ < w) putc_bfd(&pb, ' ') ;
+ }
+ while (*p) putc_bfd(&pb, *p++) ; /* String body */
+ while (j++ < w) putc_bfd(&pb, ' ') ; /* Left padded */
+ continue;
+
+ case 'C' : /* Character */
+ putc_bfd(&pb, (TCHAR)va_arg(arp, int)); continue;
+
+ case 'B' : /* Unsigned binary */
r = 2; break;
- case 'o': /* Unsigned octal */
+
+ case 'O' : /* Unsigned octal */
r = 8; break;
- case 'd': /* Signed decimal */
- case 'u': /* Unsigned decimal */
+
+ case 'D' : /* Signed decimal */
+ case 'U' : /* Unsigned decimal */
r = 10; break;
- case 'x': /* Unsigned hexdecimal (lower case) */
- case 'X': /* Unsigned hexdecimal (upper case) */
+
+ case 'X' : /* Unsigned hexdecimal */
r = 16; break;
- case 'c': /* Character */
- putc_bfd(&pb, (TCHAR)va_arg(arp, int));
- continue;
- case 's': /* String */
- tp = va_arg(arp, TCHAR*); /* Get a pointer argument */
- if (!tp) tp = &nul; /* Null ptr generates a null string */
- for (j = 0; tp[j]; j++) ; /* j = tcslen(tp) */
- if (prec >= 0 && j > (UINT)prec) j = prec; /* Limited length of string body */
- for ( ; !(f & 2) && j < w; j++) putc_bfd(&pb, pad); /* Left pads */
- while (*tp && prec--) putc_bfd(&pb, *tp++); /* Body */
- while (j++ < w) putc_bfd(&pb, ' '); /* Right pads */
- continue;
-#if FF_PRINT_FLOAT && FF_INTDEF == 2
- case 'f': /* Floating point (decimal) */
- case 'e': /* Floating point (e) */
- case 'E': /* Floating point (E) */
- ftoa(str, va_arg(arp, double), prec, tc); /* Make a flaoting point string */
- for (j = strlen(str); !(f & 2) && j < w; j++) putc_bfd(&pb, pad); /* Left pads */
- for (i = 0; str[i]; putc_bfd(&pb, str[i++])) ; /* Body */
- while (j++ < w) putc_bfd(&pb, ' '); /* Right pads */
- continue;
-#endif
+
default: /* Unknown type (pass-through) */
- putc_bfd(&pb, tc); continue;
+ putc_bfd(&pb, c); continue;
}
- /* Get an integer argument and put it in numeral */
-#if FF_PRINT_LLI && FF_INTDEF == 2
- if (f & 8) { /* long long argument? */
- v = (QWORD)va_arg(arp, LONGLONG);
- } else {
- if (f & 4) { /* long argument? */
- v = (tc == 'd') ? (QWORD)(LONGLONG)va_arg(arp, long) : (QWORD)va_arg(arp, unsigned long);
- } else { /* int/short/char argument */
- v = (tc == 'd') ? (QWORD)(LONGLONG)va_arg(arp, int) : (QWORD)va_arg(arp, unsigned int);
- }
+ /* Get an argument and put it in numeral */
+ v = (f & 4) ? (DWORD)va_arg(arp, long) : ((d == 'D') ? (DWORD)(long)va_arg(arp, int) : (DWORD)va_arg(arp, unsigned int));
+ if (d == 'D' && (v & 0x80000000)) {
+ v = 0 - v;
+ f |= 8;
}
- if (tc == 'd' && (v & 0x8000000000000000)) { /* Negative value? */
- v = 0 - v; f |= 1;
- }
-#else
- if (f & 4) { /* long argument? */
- v = (DWORD)va_arg(arp, long);
- } else { /* int/short/char argument */
- v = (tc == 'd') ? (DWORD)(long)va_arg(arp, int) : (DWORD)va_arg(arp, unsigned int);
- }
- if (tc == 'd' && (v & 0x80000000)) { /* Negative value? */
- v = 0 - v; f |= 1;
- }
-#endif
i = 0;
- do { /* Make an integer number string */
- d = (char)(v % r); v /= r;
- if (d > 9) d += (tc == 'x') ? 0x27 : 0x07;
+ do {
+ d = (TCHAR)(v % r); v /= r;
+ if (d > 9) d += (c == 'x') ? 0x27 : 0x07;
str[i++] = d + '0';
- } while (v && i < SZ_NUM_BUF);
- if (f & 1) str[i++] = '-'; /* Sign */
- /* Write it */
- for (j = i; !(f & 2) && j < w; j++) putc_bfd(&pb, pad); /* Left pads */
- do putc_bfd(&pb, (TCHAR)str[--i]); while (i); /* Body */
- while (j++ < w) putc_bfd(&pb, ' '); /* Right pads */
+ } while (v && i < sizeof str / sizeof *str);
+ if (f & 8) str[i++] = '-';
+ j = i; d = (f & 1) ? '0' : ' ';
+ if (!(f & 2)) {
+ while (j++ < w) putc_bfd(&pb, d); /* Right pad */
+ }
+ do {
+ putc_bfd(&pb, str[--i]); /* Number body */
+ } while (i);
+ while (j++ < w) putc_bfd(&pb, d); /* Left pad */
}
va_end(arp);
@@ -6977,8 +6857,8 @@ FRESULT f_setcp (
WORD cp /* Value to be set as active code page */
)
{
- static const WORD validcp[22] = { 437, 720, 737, 771, 775, 850, 852, 855, 857, 860, 861, 862, 863, 864, 865, 866, 869, 932, 936, 949, 950, 0};
- static const BYTE* const tables[22] = {Ct437, Ct720, Ct737, Ct771, Ct775, Ct850, Ct852, Ct855, Ct857, Ct860, Ct861, Ct862, Ct863, Ct864, Ct865, Ct866, Ct869, Dc932, Dc936, Dc949, Dc950, 0};
+ static const WORD validcp[] = { 437, 720, 737, 771, 775, 850, 852, 857, 860, 861, 862, 863, 864, 865, 866, 869, 932, 936, 949, 950, 0};
+ static const BYTE* const tables[] = {Ct437, Ct720, Ct737, Ct771, Ct775, Ct850, Ct852, Ct857, Ct860, Ct861, Ct862, Ct863, Ct864, Ct865, Ct866, Ct869, Dc932, Dc936, Dc949, Dc950, 0};
UINT i;
diff --git a/rt-thread/components/dfs/filesystems/elmfat/ff.h b/rt-thread/components/dfs/filesystems/elmfat/ff.h
index 7db1c4d..3b80846 100644
--- a/rt-thread/components/dfs/filesystems/elmfat/ff.h
+++ b/rt-thread/components/dfs/filesystems/elmfat/ff.h
@@ -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
typedef unsigned __int64 QWORD;
-#include
-#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
@@ -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
+
diff --git a/rt-thread/components/dfs/filesystems/elmfat/ffconf.h b/rt-thread/components/dfs/filesystems/elmfat/ffconf.h
index be6cf44..a6dcebe 100644
--- a/rt-thread/components/dfs/filesystems/elmfat/ffconf.h
+++ b/rt-thread/components/dfs/filesystems/elmfat/ffconf.h
@@ -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 // O/S definitions */
#include
#ifdef RT_DFS_ELM_REENTRANT
diff --git a/rt-thread/components/dfs/include/dfs.h b/rt-thread/components/dfs/include/dfs.h
index 678ff0e..38f19aa 100644
--- a/rt-thread/components/dfs/include/dfs.h
+++ b/rt-thread/components/dfs/include/dfs.h
@@ -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
}
diff --git a/rt-thread/components/dfs/include/dfs_fs.h b/rt-thread/components/dfs/include/dfs_fs.h
index 0a13040..3d19451 100644
--- a/rt-thread/components/dfs/include/dfs_fs.h
+++ b/rt-thread/components/dfs/include/dfs_fs.h
@@ -12,9 +12,10 @@
#define __DFS_FS_H__
#include
+#ifdef RT_USING_LIBC
#include
+#endif
#include
-
#ifdef __cplusplus
extern "C" {
#endif
diff --git a/rt-thread/components/legacy/dfs/dfs_poll.h b/rt-thread/components/dfs/include/dfs_poll.h
similarity index 83%
rename from rt-thread/components/legacy/dfs/dfs_poll.h
rename to rt-thread/components/dfs/include/dfs_poll.h
index a59e7e2..11d17cc 100644
--- a/rt-thread/components/legacy/dfs/dfs_poll.h
+++ b/rt-thread/components/dfs/include/dfs_poll.h
@@ -5,7 +5,6 @@
*
* Change Logs:
* Date Author Notes
- * 2021-11-14 Meco Man the first version
*/
#ifndef DFS_POLL_H__
diff --git a/rt-thread/components/legacy/dfs/dfs_select.h b/rt-thread/components/dfs/include/dfs_select.h
similarity index 75%
rename from rt-thread/components/legacy/dfs/dfs_select.h
rename to rt-thread/components/dfs/include/dfs_select.h
index e7cf190..17291a6 100644
--- a/rt-thread/components/legacy/dfs/dfs_select.h
+++ b/rt-thread/components/dfs/include/dfs_select.h
@@ -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
-#endif /* DFS_SELECT_H__ */
+#endif
diff --git a/rt-thread/components/dfs/src/dfs.c b/rt-thread/components/dfs/src/dfs.c
index d3a859e..8155b08 100644
--- a/rt-thread/components/dfs/src/dfs.c
+++ b/rt-thread/components/dfs/src/dfs.c
@@ -18,9 +18,9 @@
#include
#endif
-#ifdef RT_USING_POSIX_STDIO
+#if defined(RT_USING_DFS_DEVFS) && defined(RT_USING_POSIX)
#include
-#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
*
diff --git a/rt-thread/components/dfs/src/dfs_file.c b/rt-thread/components/dfs/src/dfs_file.c
index 711a461..fa0f600 100644
--- a/rt-thread/components/dfs/src/dfs_file.c
+++ b/rt-thread/components/dfs/src/dfs_file.c
@@ -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
/* @} */
diff --git a/rt-thread/components/libc/posix/io/poll/poll.c b/rt-thread/components/dfs/src/dfs_poll.c
similarity index 97%
rename from rt-thread/components/libc/posix/io/poll/poll.c
rename to rt-thread/components/dfs/src/dfs_poll.c
index a1500ba..607b348 100644
--- a/rt-thread/components/libc/posix/io/poll/poll.c
+++ b/rt-thread/components/dfs/src/dfs_poll.c
@@ -9,10 +9,17 @@
* 2018-03-09 Bernard Add protection for pt->triggered.
*/
#include
+
#include
+#include
#include
+
+#include
#include
-#include "poll.h"
+#include
+#include
+
+#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
diff --git a/rt-thread/components/dfs/src/dfs_posix.c b/rt-thread/components/dfs/src/dfs_posix.c
index e6336c2..acc05fc 100644
--- a/rt-thread/components/dfs/src/dfs_posix.c
+++ b/rt-thread/components/dfs/src/dfs_posix.c
@@ -9,9 +9,15 @@
* 2018-02-07 Bernard Change the 3rd parameter of open/fcntl/ioctl to '...'
*/
-#include
-#include
-#include
+#include
+#include
+#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_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);
+
+/* @} */
diff --git a/rt-thread/components/libc/posix/io/select.c b/rt-thread/components/dfs/src/dfs_select.c
similarity index 97%
rename from rt-thread/components/libc/posix/io/select.c
rename to rt-thread/components/dfs/src/dfs_select.c
index 55d320e..795b816 100644
--- a/rt-thread/components/libc/posix/io/select.c
+++ b/rt-thread/components/dfs/src/dfs_select.c
@@ -7,10 +7,15 @@
* Date Author Notes
* 2016-12-28 Bernard first version
*/
-#include
+#include
+#include
+#include
+
#include
#include
+#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
diff --git a/rt-thread/components/drivers/Kconfig b/rt-thread/components/drivers/Kconfig
index d197bd2..d3fd14b 100755
--- a/rt-thread/components/drivers/Kconfig
+++ b/rt-thread/components/drivers/Kconfig
@@ -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"
diff --git a/rt-thread/components/drivers/cputime/cputime.c b/rt-thread/components/drivers/cputime/cputime.c
index 490f572..750733f 100644
--- a/rt-thread/components/drivers/cputime/cputime.c
+++ b/rt-thread/components/drivers/cputime/cputime.c
@@ -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();
diff --git a/rt-thread/components/drivers/cputime/cputime_cortexm.c b/rt-thread/components/drivers/cputime/cputime_cortexm.c
index 48ccfdb..071acfe 100644
--- a/rt-thread/components/drivers/cputime/cputime_cortexm.c
+++ b/rt-thread/components/drivers/cputime/cputime_cortexm.c
@@ -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;
}
diff --git a/rt-thread/components/drivers/i2c/i2c_core.c b/rt-thread/components/drivers/i2c/i2c_core.c
index c629765..47ba76d 100644
--- a/rt-thread/components/drivers/i2c/i2c_core.c
+++ b/rt-thread/components/drivers/i2c/i2c_core.c
@@ -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;
diff --git a/rt-thread/components/drivers/i2c/i2c_dev.c b/rt-thread/components/drivers/i2c/i2c_dev.c
index 4e2ca89..c30bb62 100644
--- a/rt-thread/components/drivers/i2c/i2c_dev.c
+++ b/rt-thread/components/drivers/i2c/i2c_dev.c
@@ -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;
diff --git a/rt-thread/components/drivers/include/drivers/alarm.h b/rt-thread/components/drivers/include/drivers/alarm.h
index 56822b7..11637df 100644
--- a/rt-thread/components/drivers/include/drivers/alarm.h
+++ b/rt-thread/components/drivers/include/drivers/alarm.h
@@ -13,8 +13,7 @@
#ifndef __ALARM_H__
#define __ALARM_H__
-#include
-#include
+#include
#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 */
diff --git a/rt-thread/components/drivers/include/drivers/cputime.h b/rt-thread/components/drivers/include/drivers/cputime.h
index ec98f31..26a1e40 100644
--- a/rt-thread/components/drivers/include/drivers/cputime.h
+++ b/rt-thread/components/drivers/include/drivers/cputime.h
@@ -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);
diff --git a/rt-thread/components/drivers/include/drivers/i2c.h b/rt-thread/components/drivers/include/drivers/i2c.h
index 308c344..7bf99d2 100644
--- a/rt-thread/components/drivers/include/drivers/i2c.h
+++ b/rt-thread/components/drivers/include/drivers/i2c.h
@@ -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;
};
diff --git a/rt-thread/components/drivers/include/drivers/i2c_dev.h b/rt-thread/components/drivers/include/drivers/i2c_dev.h
index 268f52b..080ff26 100644
--- a/rt-thread/components/drivers/include/drivers/i2c_dev.h
+++ b/rt-thread/components/drivers/include/drivers/i2c_dev.h
@@ -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
diff --git a/rt-thread/components/drivers/include/drivers/lptimer.h b/rt-thread/components/drivers/include/drivers/lptimer.h
deleted file mode 100644
index e59ce61..0000000
--- a/rt-thread/components/drivers/include/drivers/lptimer.h
+++ /dev/null
@@ -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
-
-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
diff --git a/rt-thread/components/drivers/include/drivers/mmcsd_card.h b/rt-thread/components/drivers/include/drivers/mmcsd_card.h
index 8a49978..511cc11 100644
--- a/rt-thread/components/drivers/include/drivers/mmcsd_card.h
+++ b/rt-thread/components/drivers/include/drivers/mmcsd_card.h
@@ -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
diff --git a/rt-thread/components/drivers/include/drivers/mmcsd_host.h b/rt-thread/components/drivers/include/drivers/mmcsd_host.h
index 68e38c3..c7f673a 100644
--- a/rt-thread/components/drivers/include/drivers/mmcsd_host.h
+++ b/rt-thread/components/drivers/include/drivers/mmcsd_host.h
@@ -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;
diff --git a/rt-thread/components/drivers/include/drivers/pm.h b/rt-thread/components/drivers/include/drivers/pm.h
index 2deee83..d38c0a4 100644
--- a/rt-thread/components/drivers/include/drivers/pm.h
+++ b/rt-thread/components/drivers/include/drivers/pm.h
@@ -17,7 +17,8 @@
#include
#include
-#include
+
+#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
-#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__ */
diff --git a/rt-thread/components/drivers/include/drivers/sensor.h b/rt-thread/components/drivers/include/drivers/sensor.h
index ac57a68..ede8d11 100644
--- a/rt-thread/components/drivers/include/drivers/sensor.h
+++ b/rt-thread/components/drivers/include/drivers/sensor.h
@@ -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;
};
diff --git a/rt-thread/components/drivers/include/drivers/serial_v2.h b/rt-thread/components/drivers/include/drivers/serial_v2.h
index e85bdec..3ba46bd 100644
--- a/rt-thread/components/drivers/include/drivers/serial_v2.h
+++ b/rt-thread/components/drivers/include/drivers/serial_v2.h
@@ -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
*
diff --git a/rt-thread/components/drivers/include/ipc/pipe.h b/rt-thread/components/drivers/include/ipc/pipe.h
index 7d271c3..a45e8ae 100644
--- a/rt-thread/components/drivers/include/ipc/pipe.h
+++ b/rt-thread/components/drivers/include/ipc/pipe.h
@@ -15,6 +15,12 @@
#include
#include
+#ifndef RT_PIPE_BUFSZ
+#define PIPE_BUFSZ 512
+#else
+#define PIPE_BUFSZ RT_PIPE_BUFSZ
+#endif
+
struct rt_pipe_device
{
struct rt_device parent;
diff --git a/rt-thread/components/drivers/include/ipc/ringblk_buf.h b/rt-thread/components/drivers/include/ipc/ringblk_buf.h
index 7a3c930..df05659 100644
--- a/rt-thread/components/drivers/include/ipc/ringblk_buf.h
+++ b/rt-thread/components/drivers/include/ipc/ringblk_buf.h
@@ -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;
diff --git a/rt-thread/components/drivers/include/ipc/workqueue.h b/rt-thread/components/drivers/include/ipc/workqueue.h
index edefb09..776709a 100644
--- a/rt-thread/components/drivers/include/ipc/workqueue.h
+++ b/rt-thread/components/drivers/include/ipc/workqueue.h
@@ -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);
diff --git a/rt-thread/components/drivers/mtd/SConscript b/rt-thread/components/drivers/mtd/SConscript
index 5fffdc6..6f86656 100644
--- a/rt-thread/components/drivers/mtd/SConscript
+++ b/rt-thread/components/drivers/mtd/SConscript
@@ -2,7 +2,7 @@ from building import *
cwd = GetCurrentDir()
src = []
-depend = ['']
+depend = []
CPPPATH = [cwd + '/../include']
group = []
diff --git a/rt-thread/components/drivers/mtd/mtd_nand.c b/rt-thread/components/drivers/mtd/mtd_nand.c
index 4a1e74b..f516f9b 100644
--- a/rt-thread/components/drivers/mtd/mtd_nand.c
+++ b/rt-thread/components/drivers/mtd/mtd_nand.c
@@ -295,11 +295,11 @@ help:
rt_kprintf(" eraseall Erase all block on device \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]);
}
diff --git a/rt-thread/components/drivers/pm/SConscript b/rt-thread/components/drivers/pm/SConscript
index fd23e82..a94fc11 100644
--- a/rt-thread/components/drivers/pm/SConscript
+++ b/rt-thread/components/drivers/pm/SConscript
@@ -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)
diff --git a/rt-thread/components/drivers/pm/lptimer.c b/rt-thread/components/drivers/pm/lptimer.c
deleted file mode 100644
index 144270c..0000000
--- a/rt-thread/components/drivers/pm/lptimer.c
+++ /dev/null
@@ -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
-#include
-#include
-
-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);
diff --git a/rt-thread/components/drivers/pm/pm.c b/rt-thread/components/drivers/pm/pm.c
index b3ebbeb..cf488a9 100644
--- a/rt-thread/components/drivers/pm/pm.c
+++ b/rt-thread/components/drivers/pm/pm.c
@@ -15,44 +15,9 @@
#include
#include
#include
-#include
#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;
diff --git a/rt-thread/components/drivers/rtc/alarm.c b/rt-thread/components/drivers/rtc/alarm.c
index 973e643..2bcc51f 100644
--- a/rt-thread/components/drivers/rtc/alarm.c
+++ b/rt-thread/components/drivers/rtc/alarm.c
@@ -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,
diff --git a/rt-thread/components/drivers/rtc/rtc.c b/rt-thread/components/drivers/rtc/rtc.c
index 39f8249..0658d2a 100644
--- a/rt-thread/components/drivers/rtc/rtc.c
+++ b/rt-thread/components/drivers/rtc/rtc.c
@@ -14,7 +14,7 @@
* 2021-07-30 Meco Man move rtc_core.c to rtc.c
*/
-#include
+#include
#include
#include
#include
diff --git a/rt-thread/components/drivers/sdio/block_dev.c b/rt-thread/components/drivers/sdio/block_dev.c
index 4067566..2acbc44 100644
--- a/rt-thread/components/drivers/sdio/block_dev.c
+++ b/rt-thread/components/drivers/sdio/block_dev.c
@@ -21,6 +21,7 @@
#endif /* RT_SDIO_DEBUG */
#include
+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)
diff --git a/rt-thread/components/drivers/sdio/mmc.c b/rt-thread/components/drivers/sdio/mmc.c
index ac01726..bebfa39 100644
--- a/rt-thread/components/drivers/sdio/mmc.c
+++ b/rt-thread/components/drivers/sdio/mmc.c
@@ -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
diff --git a/rt-thread/components/drivers/sdio/mmcsd_core.c b/rt-thread/components/drivers/sdio/mmcsd_core.c
index b4e08e5..e3bf970 100644
--- a/rt-thread/components/drivers/sdio/mmcsd_core.c
+++ b/rt-thread/components/drivers/sdio/mmcsd_core.c
@@ -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;
diff --git a/rt-thread/components/drivers/sensors/sensor.c b/rt-thread/components/drivers/sensors/sensor.c
index fb75ce3..8d43a7a 100644
--- a/rt-thread/components/drivers/sensors/sensor.c
+++ b/rt-thread/components/drivers/sensors/sensor.c
@@ -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;
}
diff --git a/rt-thread/components/drivers/sensors/sensor_cmd.c b/rt-thread/components/drivers/sensors/sensor_cmd.c
index 83ccde3..14e53b1 100755
--- a/rt-thread/components/drivers/sensors/sensor_cmd.c
+++ b/rt-thread/components/drivers/sensors/sensor_cmd.c
@@ -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
diff --git a/rt-thread/components/drivers/serial/serial.c b/rt-thread/components/drivers/serial/serial.c
index da330b5..289d523 100644
--- a/rt-thread/components/drivers/serial/serial.c
+++ b/rt-thread/components/drivers/serial/serial.c
@@ -36,13 +36,13 @@
#define DBG_LVL DBG_INFO
#include
-#ifdef RT_USING_POSIX_STDIO
+#ifdef RT_USING_POSIX
#include
#include
#include
#ifdef RT_USING_POSIX_TERMIOS
-#include
+#include
#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
#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
diff --git a/rt-thread/components/drivers/serial/serial_v2.c b/rt-thread/components/drivers/serial/serial_v2.c
index 16d376e..390dd31 100644
--- a/rt-thread/components/drivers/serial/serial_v2.c
+++ b/rt-thread/components/drivers/serial/serial_v2.c
@@ -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
-#ifdef RT_USING_POSIX_STDIO
+#ifdef RT_USING_POSIX
#include
#include
#include
@@ -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
diff --git a/rt-thread/components/drivers/spi/enc28j60.c b/rt-thread/components/drivers/spi/enc28j60.c
index f8e5582..f997192 100644
--- a/rt-thread/components/drivers/spi/enc28j60.c
+++ b/rt-thread/components/drivers/spi/enc28j60.c
@@ -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");
diff --git a/rt-thread/components/drivers/spi/sfud/inc/sfud_cfg.h b/rt-thread/components/drivers/spi/sfud/inc/sfud_cfg.h
index 5985914..0125577 100644
--- a/rt-thread/components/drivers/spi/sfud/inc/sfud_cfg.h
+++ b/rt-thread/components/drivers/spi/sfud/inc/sfud_cfg.h
@@ -29,7 +29,7 @@
#ifndef _SFUD_CFG_H_
#define _SFUD_CFG_H_
-#include
+#include
/**
* It will print more information on debug mode.
@@ -47,6 +47,7 @@
#define DBG_TAG "SFUD"
#include
+extern void rt_kprintf(const char *fmt, ...);
#define SFUD_INFO(...) LOG_I(__VA_ARGS__)
/**
diff --git a/rt-thread/components/drivers/spi/spi_core.c b/rt-thread/components/drivers/spi/spi_core.c
index cc48f78..7b6b7a0 100644
--- a/rt-thread/components/drivers/spi/spi_core.c
+++ b/rt-thread/components/drivers/spi/spi_core.c
@@ -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 */
diff --git a/rt-thread/components/drivers/spi/spi_flash_sfud.c b/rt-thread/components/drivers/spi/spi_flash_sfud.c
index 30bc77a..bcc49e8 100644
--- a/rt-thread/components/drivers/spi/spi_flash_sfud.c
+++ b/rt-thread/components/drivers/spi/spi_flash_sfud.c
@@ -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) {
diff --git a/rt-thread/components/drivers/src/dataqueue.c b/rt-thread/components/drivers/src/dataqueue.c
index 4e52662..f32efa1 100644
--- a/rt-thread/components/drivers/src/dataqueue.c
+++ b/rt-thread/components/drivers/src/dataqueue.c
@@ -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;
diff --git a/rt-thread/components/drivers/src/pipe.c b/rt-thread/components/drivers/src/pipe.c
index 7e1f569..af90f13 100644
--- a/rt-thread/components/drivers/src/pipe.c
+++ b/rt-thread/components/drivers/src/pipe.c
@@ -13,22 +13,12 @@
#include
#include
-#if defined(RT_USING_POSIX_DEVIO) && defined(RT_USING_POSIX_PIPE)
+#ifdef RT_USING_POSIX
#include
#include
#include
#include
-/**
- * @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
diff --git a/rt-thread/components/drivers/src/ringblk_buf.c b/rt-thread/components/drivers/src/ringblk_buf.c
index 5b7a5f9..b966da3 100644
--- a/rt-thread/components/drivers/src/ringblk_buf.c
+++ b/rt-thread/components/drivers/src/ringblk_buf.c
@@ -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);
diff --git a/rt-thread/components/drivers/src/waitqueue.c b/rt-thread/components/drivers/src/waitqueue.c
index 4c6bb7e..7fe75a5 100644
--- a/rt-thread/components/drivers/src/waitqueue.c
+++ b/rt-thread/components/drivers/src/waitqueue.c
@@ -15,13 +15,6 @@
#include
#include
-/**
- * @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;
diff --git a/rt-thread/components/drivers/src/workqueue.c b/rt-thread/components/drivers/src/workqueue.c
index 6dbb0da..b5d8034 100644
--- a/rt-thread/components/drivers/src/workqueue.c
+++ b/rt-thread/components/drivers/src/workqueue.c
@@ -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);
diff --git a/rt-thread/components/drivers/usb/usbdevice/class/cdc_vcom.c b/rt-thread/components/drivers/usb/usbdevice/class/cdc_vcom.c
index 61ab0ee..1a24b79 100644
--- a/rt-thread/components/drivers/usb/usbdevice/class/cdc_vcom.c
+++ b/rt-thread/components/drivers/usb/usbdevice/class/cdc_vcom.c
@@ -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;
diff --git a/rt-thread/components/drivers/usb/usbdevice/class/hid.c b/rt-thread/components/drivers/usb/usbdevice/class/hid.c
index aa8877e..ddd4cb9 100644
--- a/rt-thread/components/drivers/usb/usbdevice/class/hid.c
+++ b/rt-thread/components/drivers/usb/usbdevice/class/hid.c
@@ -323,7 +323,7 @@ const static struct uhid_comm_descriptor _hid_comm_desc =
#else
0,
#endif
- },
+ },
/* HID Descriptor */
{
diff --git a/rt-thread/components/drivers/wlan/wlan_cfg.c b/rt-thread/components/drivers/wlan/wlan_cfg.c
index 24a37e0..0befe6e 100644
--- a/rt-thread/components/drivers/wlan/wlan_cfg.c
+++ b/rt-thread/components/drivers/wlan/wlan_cfg.c
@@ -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);
}
}
diff --git a/rt-thread/components/drivers/wlan/wlan_dev.c b/rt-thread/components/drivers/wlan/wlan_dev.c
index 49c39f1..4db8d5e 100644
--- a/rt-thread/components/drivers/wlan/wlan_dev.c
+++ b/rt-thread/components/drivers/wlan/wlan_dev.c
@@ -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);
diff --git a/rt-thread/components/drivers/wlan/wlan_mgnt.c b/rt-thread/components/drivers/wlan/wlan_mgnt.c
index fd16469..6abac56 100644
--- a/rt-thread/components/drivers/wlan/wlan_mgnt.c
+++ b/rt-thread/components/drivers/wlan/wlan_mgnt.c
@@ -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),
diff --git a/rt-thread/components/finsh/SConscript b/rt-thread/components/finsh/SConscript
index 9b2faa2..28fe02b 100644
--- a/rt-thread/components/finsh/SConscript
+++ b/rt-thread/components/finsh/SConscript
@@ -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]
diff --git a/rt-thread/components/finsh/cmd.c b/rt-thread/components/finsh/cmd.c
index 215300f..ee8d4c7 100644
--- a/rt-thread/components/finsh/cmd.c
+++ b/rt-thread/components/finsh/cmd.c
@@ -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");
}
}
diff --git a/rt-thread/components/finsh/finsh.h b/rt-thread/components/finsh/finsh.h
index 05399e1..98048eb 100644
--- a/rt-thread/components/finsh/finsh.h
+++ b/rt-thread/components/finsh/finsh.h
@@ -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
diff --git a/rt-thread/components/finsh/msh.c b/rt-thread/components/finsh/msh.c
index 47ee1ef..18182ca 100644
--- a/rt-thread/components/finsh/msh.c
+++ b/rt-thread/components/finsh/msh.c
@@ -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
-#endif /* DFS_USING_POSIX */
+
+#ifdef RT_USING_DFS
+ #include
+#endif
+
#ifdef RT_USING_MODULE
-#include
-#endif /* RT_USING_MODULE */
+ #include
+#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 */
{
diff --git a/rt-thread/components/finsh/msh_file.c b/rt-thread/components/finsh/msh_file.c
index 2b359fb..8f067ef 100644
--- a/rt-thread/components/finsh/msh_file.c
+++ b/rt-thread/components/finsh/msh_file.c
@@ -11,7 +11,7 @@
#include
-#if defined(RT_USING_FINSH) && defined(DFS_USING_POSIX)
+#if defined(RT_USING_FINSH) && defined(RT_USING_DFS)
#include
#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) */
+
diff --git a/rt-thread/components/finsh/shell.c b/rt-thread/components/finsh/shell.c
index 5b96d0d..20f1bde 100644
--- a/rt-thread/components/finsh/shell.c
+++ b/rt-thread/components/finsh/shell.c
@@ -27,9 +27,9 @@
#include "shell.h"
#include "msh.h"
-#ifdef DFS_USING_POSIX
-#include
-#endif /* DFS_USING_POSIX */
+#if defined(RT_USING_DFS)
+ #include
+#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 */
diff --git a/rt-thread/components/finsh/shell.h b/rt-thread/components/finsh/shell.h
index a74f4da..985d3b3 100644
--- a/rt-thread/components/finsh/shell.h
+++ b/rt-thread/components/finsh/shell.h
@@ -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);
diff --git a/rt-thread/components/legacy/README.md b/rt-thread/components/legacy/README.md
deleted file mode 100644
index 7b1eae9..0000000
--- a/rt-thread/components/legacy/README.md
+++ /dev/null
@@ -1,2 +0,0 @@
-# RT-Thread Legacy
-
diff --git a/rt-thread/components/legacy/SConscript b/rt-thread/components/legacy/SConscript
deleted file mode 100644
index d3821af..0000000
--- a/rt-thread/components/legacy/SConscript
+++ /dev/null
@@ -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')
diff --git a/rt-thread/components/legacy/ipc/workqueue_legacy.c b/rt-thread/components/legacy/ipc/workqueue_legacy.c
deleted file mode 100644
index e79c1ca..0000000
--- a/rt-thread/components/legacy/ipc/workqueue_legacy.c
+++ /dev/null
@@ -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);
-}
diff --git a/rt-thread/components/legacy/ipc/workqueue_legacy.h b/rt-thread/components/legacy/ipc/workqueue_legacy.h
deleted file mode 100644
index a39cc86..0000000
--- a/rt-thread/components/legacy/ipc/workqueue_legacy.h
+++ /dev/null
@@ -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
-
-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
diff --git a/rt-thread/components/legacy/rtlegacy.h b/rt-thread/components/legacy/rtlegacy.h
deleted file mode 100644
index df8463c..0000000
--- a/rt-thread/components/legacy/rtlegacy.h
+++ /dev/null
@@ -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
-
-/* rtlibc */
-#include
-#include
-
-/* IPC */
-#ifdef RT_USING_DEVICE_IPC
-#include "ipc/workqueue_legacy.h"
-#endif /* RT_USING_DEVICE_IPC */
-
-/* FinSH */
-
-#endif /* __RT_LEGACY_H__ */
diff --git a/rt-thread/components/libc/Kconfig b/rt-thread/components/libc/Kconfig
index 0556cf6..b9600ef 100644
--- a/rt-thread/components/libc/Kconfig
+++ b/rt-thread/components/libc/Kconfig
@@ -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
diff --git a/rt-thread/components/libc/aio/SConscript b/rt-thread/components/libc/aio/SConscript
new file mode 100644
index 0000000..f10462e
--- /dev/null
+++ b/rt-thread/components/libc/aio/SConscript
@@ -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')
diff --git a/rt-thread/components/libc/posix/io/aio/aio.c b/rt-thread/components/libc/aio/posix_aio.c
similarity index 99%
rename from rt-thread/components/libc/posix/io/aio/aio.c
rename to rt-thread/components/libc/aio/posix_aio.c
index 08ef4c6..66cced8 100644
--- a/rt-thread/components/libc/posix/io/aio/aio.c
+++ b/rt-thread/components/libc/aio/posix_aio.c
@@ -11,7 +11,7 @@
#include
#include
#include
-#include "aio.h"
+#include "posix_aio.h"
struct rt_workqueue* aio_queue = NULL;
diff --git a/rt-thread/components/libc/posix/io/aio/aio.h b/rt-thread/components/libc/aio/posix_aio.h
similarity index 96%
rename from rt-thread/components/libc/posix/io/aio/aio.h
rename to rt-thread/components/libc/aio/posix_aio.h
index 35a5c19..4e25e1d 100644
--- a/rt-thread/components/libc/posix/io/aio/aio.h
+++ b/rt-thread/components/libc/aio/posix_aio.h
@@ -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
#include
diff --git a/rt-thread/components/libc/compilers/armlibc/README.md b/rt-thread/components/libc/compilers/armlibc/README.md
index fc0d750..4d2a73b 100644
--- a/rt-thread/components/libc/compilers/armlibc/README.md
+++ b/rt-thread/components/libc/compilers/armlibc/README.md
@@ -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/
\ No newline at end of file
diff --git a/rt-thread/components/libc/compilers/armlibc/SConscript b/rt-thread/components/libc/compilers/armlibc/SConscript
index bd3ac8d..52f7a6d 100644
--- a/rt-thread/components/libc/compilers/armlibc/SConscript
+++ b/rt-thread/components/libc/compilers/armlibc/SConscript
@@ -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')
diff --git a/rt-thread/components/libc/compilers/armlibc/libc.c b/rt-thread/components/libc/compilers/armlibc/libc.c
new file mode 100644
index 0000000..889c687
--- /dev/null
+++ b/rt-thread/components/libc/compilers/armlibc/libc.c
@@ -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
+#include
+#include "libc.h"
+
+#ifdef RT_USING_PTHREADS
+#include
+#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);
diff --git a/rt-thread/components/libc/compilers/armlibc/libc.h b/rt-thread/components/libc/compilers/armlibc/libc.h
new file mode 100644
index 0000000..5c16137
--- /dev/null
+++ b/rt-thread/components/libc/compilers/armlibc/libc.h
@@ -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
diff --git a/rt-thread/components/libc/compilers/armlibc/mem_std.c b/rt-thread/components/libc/compilers/armlibc/mem_std.c
new file mode 100644
index 0000000..fbfd17e
--- /dev/null
+++ b/rt-thread/components/libc/compilers/armlibc/mem_std.c
@@ -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
+#include
+
+#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
diff --git a/rt-thread/components/libc/compilers/armlibc/stdio.c b/rt-thread/components/libc/compilers/armlibc/stdio.c
new file mode 100644
index 0000000..7dd9dbf
--- /dev/null
+++ b/rt-thread/components/libc/compilers/armlibc/stdio.c
@@ -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
+#include
+#include
+
+#include
+#include "libc.h"
+
+#if defined(RT_USING_DFS) && defined(RT_USING_DFS_DEVFS)
+#include
+
+#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
diff --git a/rt-thread/components/libc/compilers/armlibc/syscall_mem.c b/rt-thread/components/libc/compilers/armlibc/syscall_mem.c
deleted file mode 100644
index b5403df..0000000
--- a/rt-thread/components/libc/compilers/armlibc/syscall_mem.c
+++ /dev/null
@@ -1,71 +0,0 @@
-/*
- * Copyright (c) 2006-2021, RT-Thread Development Team
- *
- * SPDX-License-Identifier: Apache-2.0
- *
- * Change Logs:
- * Date Author Notes
- * 2014-08-03 bernard Add file header
- * 2021-11-13 Meco Man implement no-heap warning
- */
-
-#include
-#include
-
-#ifndef RT_USING_HEAP
-#define DBG_TAG "armlibc.syscall.mem"
-#define DBG_LVL DBG_INFO
-#include
-
-#define _NO_HEAP_ERROR() do{LOG_E("Please enable RT_USING_HEAP");\
- RT_ASSERT(0);\
- }while(0)
-#endif /* RT_USING_HEAP */
-
-#ifdef __CC_ARM
-/* avoid the heap and heap-using library functions supplied by arm */
-#pragma import(__use_no_heap)
-#endif /* __CC_ARM */
-
-void *malloc(size_t n)
-{
-#ifdef RT_USING_HEAP
- return rt_malloc(n);
-#else
- _NO_HEAP_ERROR();
- return RT_NULL;
-#endif
-}
-RTM_EXPORT(malloc);
-
-void *realloc(void *rmem, size_t newsize)
-{
-#ifdef RT_USING_HEAP
- return rt_realloc(rmem, newsize);
-#else
- _NO_HEAP_ERROR();
- return RT_NULL;
-#endif
-}
-RTM_EXPORT(realloc);
-
-void *calloc(size_t nelem, size_t elsize)
-{
-#ifdef RT_USING_HEAP
- return rt_calloc(nelem, elsize);
-#else
- _NO_HEAP_ERROR();
- return RT_NULL;
-#endif
-}
-RTM_EXPORT(calloc);
-
-void free(void *rmem)
-{
-#ifdef RT_USING_HEAP
- rt_free(rmem);
-#else
- _NO_HEAP_ERROR();
-#endif
-}
-RTM_EXPORT(free);
diff --git a/rt-thread/components/libc/compilers/armlibc/syscalls.c b/rt-thread/components/libc/compilers/armlibc/syscalls.c
index f4ced9d..ccdcfc8 100644
--- a/rt-thread/components/libc/compilers/armlibc/syscalls.c
+++ b/rt-thread/components/libc/compilers/armlibc/syscalls.c
@@ -15,22 +15,21 @@
* 2020-02-14 Meco Man implement _sys_tmpnam()
*/
-#include
-#include
#include
-#include
-#include
-#include
-#include
-#ifdef RT_USING_POSIX_STDIO
+#include
+
+#include
#include "libc.h"
-#endif /* RT_USING_POSIX_STDIO */
+
+#ifdef RT_USING_DFS
+#include
+#endif
#define DBG_TAG "armlibc.syscalls"
#define DBG_LVL DBG_INFO
#include
-#ifdef __clang__
+#ifdef __CLANG_ARM
__asm(".global __use_no_semihosting\n\t");
#else
#pragma import(__use_no_semihosting_swi)
@@ -56,10 +55,10 @@ const char __stderr_name[] = "STDERR";
*/
FILEHANDLE _sys_open(const char *name, int openmode)
{
-#ifdef DFS_USING_POSIX
+#ifdef RT_USING_DFS
int fd;
int mode = O_RDONLY;
-#endif /* DFS_USING_POSIX */
+#endif
/* Register standard Input Output devices. */
if (strcmp(name, __stdin_name) == 0)
@@ -69,9 +68,8 @@ FILEHANDLE _sys_open(const char *name, int openmode)
if (strcmp(name, __stderr_name) == 0)
return (STDERR);
-#ifndef DFS_USING_POSIX
- LOG_W("%s: %s", __func__, _WARNING_WITHOUT_FS);
- return 0; /* error */
+#ifndef RT_USING_DFS
+ return -1;
#else
/* Correct openmode from fopen to open */
if (openmode & OPEN_PLUS)
@@ -101,23 +99,21 @@ FILEHANDLE _sys_open(const char *name, int openmode)
fd = open(name, mode, 0);
if (fd < 0)
- return 0; /* error */
+ return -1;
else
return fd;
-#endif /* DFS_USING_POSIX */
+#endif
}
int _sys_close(FILEHANDLE fh)
{
-#ifdef DFS_USING_POSIX
- if (fh <= STDERR)
- return 0; /* error */
+#ifndef RT_USING_DFS
+ return 0;
+#else
+ if (fh <= STDERR) return 0;
return close(fh);
-#else
- LOG_W("%s: %s", __func__, _WARNING_WITHOUT_FS);
- return 0;
-#endif /* DFS_USING_POSIX */
+#endif
}
/*
@@ -147,96 +143,90 @@ int _sys_close(FILEHANDLE fh)
*/
int _sys_read(FILEHANDLE fh, unsigned char *buf, unsigned len, int mode)
{
-#ifdef DFS_USING_POSIX
+#ifdef RT_USING_DFS
int size;
+#endif
if (fh == STDIN)
{
-#ifdef RT_USING_POSIX_STDIO
+#ifdef RT_USING_POSIX
if (libc_stdio_get_console() < 0)
{
- LOG_W("Do not invoke standard output before initializing Compiler");
- return 0; /* error, but keep going */
+ LOG_W("Do not invoke standard output before initializing libc");
+ return 0;
}
size = read(STDIN_FILENO, buf, len);
- return len - size; /* success */
+ return len - size;
#else
- LOG_W("%s: %s", __func__, _WARNING_WITHOUT_STDIO);
- return 0; /* error */
-#endif /* RT_USING_POSIX_STDIO */
+ /* no stdin */
+ return -1;
+#endif
}
- else if (fh == STDOUT || fh == STDERR)
+ else if ((fh == STDOUT) || (fh == STDERR))
{
- return -1; /* 100% error */
+ return -1;
}
+
+#ifndef RT_USING_DFS
+ return 0;
+#else
+ size = read(fh, buf, len);
+ if (size >= 0)
+ return len - size;
else
- {
- size = read(fh, buf, len);
- if (size >= 0)
- {
- return len - size; /* success */
- }
- else
- {
- return 0; /* error */
- }
- }
-#else
- LOG_W("%s: %s", __func__, _WARNING_WITHOUT_FS);
- return 0; /* error */
-#endif /* DFS_USING_POSIX */
+ return -1;
+#endif
}
/*
* Write to a file. Returns 0 on success, negative on error, and
* the number of characters _not_ written on partial success.
* `mode' exists for historical reasons and must be ignored.
- * The return value is either:
- * A positive number representing the number of characters not written
- * (so any nonzero return value denotes a failure of some sort).
- * A negative number indicating an error.
*/
int _sys_write(FILEHANDLE fh, const unsigned char *buf, unsigned len, int mode)
{
-#ifdef DFS_USING_POSIX
+#ifdef RT_USING_DFS
int size;
-#endif /* DFS_USING_POSIX */
+#endif
- if (fh == STDOUT || fh == STDERR)
+ if ((fh == STDOUT) || (fh == STDERR))
{
-#ifdef RT_USING_CONSOLE
- rt_device_t console;
- console = rt_console_get_device();
- if (console)
- {
- rt_device_write(console, -1, buf, len);
- }
- return 0; /* success */
+#if !defined(RT_USING_CONSOLE) || !defined(RT_USING_DEVICE)
+ return 0;
#else
- return 0; /* error */
-#endif /* RT_USING_CONSOLE */
+#ifdef RT_USING_POSIX
+ if (libc_stdio_get_console() < 0)
+ {
+ LOG_W("Do not invoke standard input before initializing libc");
+ return 0;
+ }
+ size = write(STDOUT_FILENO, buf, len);
+ return len - size;
+#else
+ if (rt_console_get_device())
+ {
+ rt_device_write(rt_console_get_device(), -1, buf, len);
+ return 0;
+ }
+
+ return -1;
+#endif
+#endif
}
else if (fh == STDIN)
{
- return -1; /* 100% error */
+ return -1;
}
- else
- {
-#ifdef DFS_USING_POSIX
- size = write(fh, buf, len);
- if (size >= 0)
- {
- return len - size; /* success */
- }
- else
- {
- return 0; /* error */
- }
+
+#ifndef RT_USING_DFS
+ return 0;
#else
- LOG_W("%s: %s", __func__, _WARNING_WITHOUT_FS);
- return 0; /* error */
-#endif /* DFS_USING_POSIX */
- }
+ size = write(fh, buf, len);
+ if (size >= 0)
+ return len - size;
+ else
+ return -1;
+#endif
}
/*
@@ -245,16 +235,16 @@ int _sys_write(FILEHANDLE fh, const unsigned char *buf, unsigned len, int mode)
*/
int _sys_seek(FILEHANDLE fh, long pos)
{
-#ifdef DFS_USING_POSIX
if (fh < STDERR)
- return 0; /* error */
+ return -1;
+
+#ifndef RT_USING_DFS
+ return -1;
+#else
/* position is relative to the start of file fh */
return lseek(fh, pos, 0);
-#else
- LOG_W("%s: %s", __func__, _WARNING_WITHOUT_FS);
- return 0; /* error */
-#endif /* DFS_USING_POSIX */
+#endif
}
/**
@@ -276,8 +266,11 @@ char *_sys_command_string(char *cmd, int len)
void _ttywrch(int ch)
{
#ifdef RT_USING_CONSOLE
- rt_kprintf("%c", (char)ch);
-#endif /* RT_USING_CONSOLE */
+ char c;
+
+ c = (char)ch;
+ rt_kprintf(&c);
+#endif
}
/* for exit() and abort() */
@@ -296,18 +289,17 @@ RT_WEAK void _sys_exit(int return_code)
*/
long _sys_flen(FILEHANDLE fh)
{
-#ifdef DFS_USING_POSIX
+#ifdef RT_USING_DFS
struct stat stat;
if (fh < STDERR)
- return 0; /* error */
+ return -1;
fstat(fh, &stat);
return stat.st_size;
#else
- LOG_W("%s: %s", __func__, _WARNING_WITHOUT_FS);
- return 0;
-#endif /* DFS_USING_POSIX */
+ return -1;
+#endif
}
int _sys_istty(FILEHANDLE fh)
@@ -320,12 +312,11 @@ int _sys_istty(FILEHANDLE fh)
int remove(const char *filename)
{
-#ifdef DFS_USING_POSIX
- return unlink(filename);
+#ifndef RT_USING_DFS
+ return -1;
#else
- LOG_W("%s: %s", __func__, _WARNING_WITHOUT_FS);
- return 0; /* error */
-#endif /* DFS_USING_POSIX */
+ return unlink(filename);
+#endif
}
#ifdef __MICROLIB
@@ -333,30 +324,28 @@ int remove(const char *filename)
int fputc(int c, FILE *f)
{
-#ifdef RT_USING_CONSOLE
- rt_kprintf("%c", (char)c);
+ char ch[2] = {0};
+
+ ch[0] = c;
+ rt_kprintf(&ch[0]);
return 1;
-#else
- return 0; /* error */
-#endif /* RT_USING_CONSOLE */
}
int fgetc(FILE *f)
{
-#ifdef RT_USING_POSIX_STDIO
+#ifdef RT_USING_POSIX
char ch;
if (libc_stdio_get_console() < 0)
{
- LOG_W("Do not invoke standard output before initializing Compiler");
- return 0;
+ LOG_W("Do not invoke standard output before initializing libc");
+ return -1;
}
if(read(STDIN_FILENO, &ch, 1) == 1)
return ch;
-#endif /* RT_USING_POSIX_STDIO */
- LOG_W("%s: %s", __func__, _WARNING_WITHOUT_STDIO);
- return 0; /* error */
-}
+#endif
-#endif /* __MICROLIB */
+ return -1;
+}
+#endif
diff --git a/rt-thread/components/libc/compilers/common/SConscript b/rt-thread/components/libc/compilers/common/SConscript
index 8db8f2c..b1982aa 100644
--- a/rt-thread/components/libc/compilers/common/SConscript
+++ b/rt-thread/components/libc/compilers/common/SConscript
@@ -1,22 +1,30 @@
from building import *
+
Import('rtconfig')
src = []
cwd = GetCurrentDir()
group = []
CPPPATH = [cwd]
-CPPDEFINES = []
+
+if GetDepend('RT_USING_LIBC'):
+ src += Glob('*.c')
+ if GetDepend('RT_USING_POSIX') == False:
+ SrcRemove(src, ['unistd.c', 'delay.c'])
+elif GetDepend('RT_LIBC_USING_TIME'):
+ src += ['time.c']
if rtconfig.CROSS_TOOL == 'keil':
- CPPDEFINES += ['__CLK_TCK=RT_TICK_PER_SECOND']
+ CPPDEFINES = ['__CLK_TCK=RT_TICK_PER_SECOND']
+else:
+ CPPDEFINES = []
-src += Glob('*.c')
-
-group = DefineGroup('Compiler', src, depend = [''], CPPPATH = CPPPATH, CPPDEFINES = CPPDEFINES)
+group = DefineGroup('libc', src, depend = [], CPPPATH = CPPPATH, CPPDEFINES = CPPDEFINES)
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'))
+for d in list:
+ path = os.path.join(cwd, d)
+ if os.path.isfile(os.path.join(path, 'SConscript')):
+ group = group + SConscript(os.path.join(d, 'SConscript'))
Return('group')
diff --git a/rt-thread/components/libc/compilers/common/compiler_private.h b/rt-thread/components/libc/compilers/common/compiler_private.h
deleted file mode 100644
index 96a49ef..0000000
--- a/rt-thread/components/libc/compilers/common/compiler_private.h
+++ /dev/null
@@ -1,16 +0,0 @@
-/*
- * Copyright (c) 2006-2021, RT-Thread Development Team
- *
- * SPDX-License-Identifier: Apache-2.0
- *
- * Change Logs:
- * Date Author Notes
- * 2021-12-26 Meco Man First Version
- */
-#ifndef __COMPILER_PRIVATE_H__
-#define __COMPILER_PRIVATE_H__
-
-#define _WARNING_WITHOUT_FS "Please enable RT_USING_POSIX_FS"
-#define _WARNING_WITHOUT_STDIO "Please enable RT_USING_POSIX_FS and RT_USING_POSIX_STDIO"
-
-#endif /* __COMPILER_PRIVATE_H__ */
diff --git a/rt-thread/components/libc/compilers/common/delay.c b/rt-thread/components/libc/compilers/common/delay.c
new file mode 100644
index 0000000..4666258
--- /dev/null
+++ b/rt-thread/components/libc/compilers/common/delay.c
@@ -0,0 +1,41 @@
+/*
+ * Copyright (c) 2006-2021, RT-Thread Development Team
+ *
+ * SPDX-License-Identifier: Apache-2.0
+ *
+ * Change Logs:
+ * Date Author Notes
+ * 2021-05-07 Meco Man first Version
+ */
+#include
+#include
+
+void msleep(unsigned int msecs)
+{
+ rt_thread_mdelay(msecs);
+}
+RTM_EXPORT(msleep);
+
+void ssleep(unsigned int seconds)
+{
+ msleep(seconds * 1000);
+}
+RTM_EXPORT(ssleep);
+
+void mdelay(unsigned long msecs)
+{
+ rt_hw_us_delay(msecs * 1000);
+}
+RTM_EXPORT(mdelay);
+
+void udelay(unsigned long usecs)
+{
+ rt_hw_us_delay(usecs);
+}
+RTM_EXPORT(udelay);
+
+void ndelay(unsigned long nsecs)
+{
+ rt_hw_us_delay(1);
+}
+RTM_EXPORT(ndelay);
diff --git a/rt-thread/components/libc/posix/delay/delay.h b/rt-thread/components/libc/compilers/common/delay.h
similarity index 100%
rename from rt-thread/components/libc/posix/delay/delay.h
rename to rt-thread/components/libc/compilers/common/delay.h
diff --git a/rt-thread/components/libc/compilers/common/nogcc/SConscript b/rt-thread/components/libc/compilers/common/nogcc/SConscript
index dbc26ac..c766c8f 100644
--- a/rt-thread/components/libc/compilers/common/nogcc/SConscript
+++ b/rt-thread/components/libc/compilers/common/nogcc/SConscript
@@ -7,8 +7,9 @@ cwd = GetCurrentDir()
CPPPATH = [cwd]
group = []
-src += Glob('*.c')
+if GetDepend('RT_USING_LIBC'):
+ src += Glob('*.c')
if rtconfig.PLATFORM != 'gcc' or rtconfig.ARCH == 'sim':
- group = DefineGroup('Compiler', src, depend = [''], CPPPATH = CPPPATH)
+ group = DefineGroup('libc', src, depend = [], CPPPATH = CPPPATH)
Return('group')
diff --git a/rt-thread/components/libc/compilers/common/nogcc/sys/errno.h b/rt-thread/components/libc/compilers/common/nogcc/sys/errno.h
index 1c6cd6d..ff1abca 100644
--- a/rt-thread/components/libc/compilers/common/nogcc/sys/errno.h
+++ b/rt-thread/components/libc/compilers/common/nogcc/sys/errno.h
@@ -39,134 +39,46 @@ defined in armcc/errno.h
#if defined(__ARMCC_VERSION) || defined(__IAR_SYSTEMS_ICC__)
#include
-
-#ifndef EPERM
#define EPERM (ERROR_BASE_NO + 1)
-#endif
-
-#ifndef ENOENT
#define ENOENT (ERROR_BASE_NO + 2)
-#endif
-
-#ifndef ESRCH
#define ESRCH (ERROR_BASE_NO + 3)
-#endif
-
-#ifndef EINTR
#define EINTR (ERROR_BASE_NO + 4)
-#endif
-
-#ifndef EIO
#define EIO (ERROR_BASE_NO + 5)
-#endif
-
-#ifndef ENXIO
#define ENXIO (ERROR_BASE_NO + 6)
-#endif
-
-#ifndef E2BIG
#define E2BIG (ERROR_BASE_NO + 7)
-#endif
-
-#ifndef ENOEXEC
#define ENOEXEC (ERROR_BASE_NO + 8)
-#endif
-
-#ifndef EBADF
#define EBADF (ERROR_BASE_NO + 9)
-#endif
-
-#ifndef ECHILD
#define ECHILD (ERROR_BASE_NO + 10)
-#endif
-
-#ifndef EAGAIN
#define EAGAIN (ERROR_BASE_NO + 11)
-#endif
#ifndef ENOMEM
#define ENOMEM (ERROR_BASE_NO + 12)
#endif
-#ifndef EACCES
#define EACCES (ERROR_BASE_NO + 13)
-#endif
-
-#ifndef EFAULT
#define EFAULT (ERROR_BASE_NO + 14)
-#endif
-
-#ifndef ENOTBLK
#define ENOTBLK (ERROR_BASE_NO + 15)
-#endif
-
-#ifndef EBUSY
#define EBUSY (ERROR_BASE_NO + 16)
-#endif
-
-#ifndef EEXIST
#define EEXIST (ERROR_BASE_NO + 17)
-#endif
-
-#ifndef EXDEV
#define EXDEV (ERROR_BASE_NO + 18)
-#endif
-
-#ifndef ENODEV
#define ENODEV (ERROR_BASE_NO + 19)
-#endif
-
-#ifndef ENOTDIR
#define ENOTDIR (ERROR_BASE_NO + 20)
-#endif
-
-#ifndef EISDIR
#define EISDIR (ERROR_BASE_NO + 21)
-#endif
#ifndef EINVAL
#define EINVAL (ERROR_BASE_NO + 22)
#endif
-#ifndef ENFILE
#define ENFILE (ERROR_BASE_NO + 23)
-#endif
-
-#ifndef EMFILE
#define EMFILE (ERROR_BASE_NO + 24)
-#endif
-
-#ifndef ENOTTY
#define ENOTTY (ERROR_BASE_NO + 25)
-#endif
-
-#ifndef ETXTBSY
#define ETXTBSY (ERROR_BASE_NO + 26)
-#endif
-
-#ifndef EFBIG
#define EFBIG (ERROR_BASE_NO + 27)
-#endif
-
-#ifndef ENOSPC
#define ENOSPC (ERROR_BASE_NO + 28)
-#endif
-
-#ifndef ESPIPE
#define ESPIPE (ERROR_BASE_NO + 29)
-#endif
-
-#ifndef EROFS
#define EROFS (ERROR_BASE_NO + 30)
-#endif
-
-#ifndef EMLINK
#define EMLINK (ERROR_BASE_NO + 31)
-#endif
-
-#ifndef EPIPE
#define EPIPE (ERROR_BASE_NO + 32)
-#endif
#ifndef EDOM
#define EDOM (ERROR_BASE_NO + 33)
@@ -176,409 +88,110 @@ defined in armcc/errno.h
#define ERANGE (ERROR_BASE_NO + 34)
#endif
-#ifndef EDEADLK
#define EDEADLK (ERROR_BASE_NO + 35)
-#endif
-
-#ifndef ENAMETOOLONG
#define ENAMETOOLONG (ERROR_BASE_NO + 36)
-#endif
-
-#ifndef ENOLCK
#define ENOLCK (ERROR_BASE_NO + 37)
-#endif
-
-#ifndef ENOSYS
#define ENOSYS (ERROR_BASE_NO + 38)
-#endif
-
-#ifndef ENOTEMPTY
#define ENOTEMPTY (ERROR_BASE_NO + 39)
-#endif
-
-#ifndef ELOOP
#define ELOOP (ERROR_BASE_NO + 40)
-#endif
-
-#ifndef EWOULDBLOCK
#define EWOULDBLOCK EAGAIN
-#endif
-
-#ifndef ENOMSG
#define ENOMSG (ERROR_BASE_NO + 42)
-#endif
-
-#ifndef EIDRM
#define EIDRM (ERROR_BASE_NO + 43)
-#endif
-
-#ifndef ECHRNG
#define ECHRNG (ERROR_BASE_NO + 44)
-#endif
-
-#ifndef EL2NSYNC
#define EL2NSYNC (ERROR_BASE_NO + 45)
-#endif
-
-#ifndef EL3HLT
#define EL3HLT (ERROR_BASE_NO + 46)
-#endif
-
-#ifndef EL3RST
#define EL3RST (ERROR_BASE_NO + 47)
-#endif
-
-#ifndef ELNRNG
#define ELNRNG (ERROR_BASE_NO + 48)
-#endif
-
-#ifndef EUNATCH
#define EUNATCH (ERROR_BASE_NO + 49)
-#endif
-
-#ifndef ENOCSI
#define ENOCSI (ERROR_BASE_NO + 50)
-#endif
-
-#ifndef EL2HLT
#define EL2HLT (ERROR_BASE_NO + 51)
-#endif
-
-#ifndef EBADE
#define EBADE (ERROR_BASE_NO + 52)
-#endif
-
-#ifndef EBADR
#define EBADR (ERROR_BASE_NO + 53)
-#endif
-
-#ifndef EXFULL
#define EXFULL (ERROR_BASE_NO + 54)
-#endif
-
-#ifndef ENOANO
#define ENOANO (ERROR_BASE_NO + 55)
-#endif
-
-#ifndef EBADRQC
#define EBADRQC (ERROR_BASE_NO + 56)
-#endif
-
-#ifndef EBADSLT
#define EBADSLT (ERROR_BASE_NO + 57)
-#endif
-
-#ifndef EDEADLOCK
#define EDEADLOCK EDEADLK
-#endif
-
-#ifndef EBFONT
#define EBFONT (ERROR_BASE_NO + 59)
-#endif
-
-#ifndef ENOSTR
#define ENOSTR (ERROR_BASE_NO + 60)
-#endif
-
-#ifndef ENODATA
#define ENODATA (ERROR_BASE_NO + 61)
-#endif
-
-#ifndef ETIME
#define ETIME (ERROR_BASE_NO + 62)
-#endif
-
-#ifndef ENOSR
#define ENOSR (ERROR_BASE_NO + 63)
-#endif
-
-#ifndef ENONET
#define ENONET (ERROR_BASE_NO + 64)
-#endif
-
-#ifndef ENOPKG
#define ENOPKG (ERROR_BASE_NO + 65)
-#endif
-
-#ifndef EREMOTE
#define EREMOTE (ERROR_BASE_NO + 66)
-#endif
-
-#ifndef ENOLINK
#define ENOLINK (ERROR_BASE_NO + 67)
-#endif
-
-#ifndef EADV
#define EADV (ERROR_BASE_NO + 68)
-#endif
-
-#ifndef ESRMNT
#define ESRMNT (ERROR_BASE_NO + 69)
-#endif
-
-#ifndef ECOMM
#define ECOMM (ERROR_BASE_NO + 70)
-#endif
-
-#ifndef EPROTO
#define EPROTO (ERROR_BASE_NO + 71)
-#endif
-
-#ifndef EMULTIHOP
#define EMULTIHOP (ERROR_BASE_NO + 72)
-#endif
-
-#ifndef EDOTDOT
#define EDOTDOT (ERROR_BASE_NO + 73)
-#endif
-
-#ifndef EBADMSG
#define EBADMSG (ERROR_BASE_NO + 74)
-#endif
-
-#ifndef EOVERFLOW
#define EOVERFLOW (ERROR_BASE_NO + 75)
-#endif
-
-#ifndef ENOTUNIQ
#define ENOTUNIQ (ERROR_BASE_NO + 76)
-#endif
-
-#ifndef EBADFD
#define EBADFD (ERROR_BASE_NO + 77)
-#endif
-
-#ifndef EREMCHG
#define EREMCHG (ERROR_BASE_NO + 78)
-#endif
-
-#ifndef ELIBACC
#define ELIBACC (ERROR_BASE_NO + 79)
-#endif
-
-#ifndef ELIBBAD
#define ELIBBAD (ERROR_BASE_NO + 80)
-#endif
-
-#ifndef ELIBSCN
#define ELIBSCN (ERROR_BASE_NO + 81)
-#endif
-
-#ifndef ELIBMAX
#define ELIBMAX (ERROR_BASE_NO + 82)
-#endif
-
-#ifndef ELIBEXEC
#define ELIBEXEC (ERROR_BASE_NO + 83)
-#endif
#ifndef EILSEQ
#define EILSEQ (ERROR_BASE_NO + 84)
#endif
-#ifndef ERESTART
#define ERESTART (ERROR_BASE_NO + 85)
-#endif
-
-#ifndef ESTRPIPE
#define ESTRPIPE (ERROR_BASE_NO + 86)
-#endif
-
-#ifndef EUSERS
#define EUSERS (ERROR_BASE_NO + 87)
-#endif
-
-#ifndef ENOTSOCK
#define ENOTSOCK (ERROR_BASE_NO + 88)
-#endif
-
-#ifndef EDESTADDRREQ
#define EDESTADDRREQ (ERROR_BASE_NO + 89)
-#endif
-
-#ifndef EMSGSIZE
#define EMSGSIZE (ERROR_BASE_NO + 90)
-#endif
-
-#ifndef EPROTOTYPE
#define EPROTOTYPE (ERROR_BASE_NO + 91)
-#endif
-
-#ifndef ENOPROTOOPT
#define ENOPROTOOPT (ERROR_BASE_NO + 92)
-#endif
-
-#ifndef EPROTONOSUPPORT
#define EPROTONOSUPPORT (ERROR_BASE_NO + 93)
-#endif
-
-#ifndef ESOCKTNOSUPPORT
#define ESOCKTNOSUPPORT (ERROR_BASE_NO + 94)
-#endif
-
-#ifndef EOPNOTSUPP
#define EOPNOTSUPP (ERROR_BASE_NO + 95)
-#endif
-
-#ifndef ENOTSUP
#define ENOTSUP EOPNOTSUPP
-#endif
-
-#ifndef EPFNOSUPPORT
#define EPFNOSUPPORT (ERROR_BASE_NO + 96)
-#endif
-
-#ifndef EAFNOSUPPORT
#define EAFNOSUPPORT (ERROR_BASE_NO + 97)
-#endif
-
-#ifndef EADDRINUSE
#define EADDRINUSE (ERROR_BASE_NO + 98)
-#endif
-
-#ifndef EADDRNOTAVAIL
#define EADDRNOTAVAIL (ERROR_BASE_NO + 99)
-#endif
-
-#ifndef ENETDOWN
#define ENETDOWN (ERROR_BASE_NO + 100)
-#endif
-
-#ifndef ENETUNREACH
#define ENETUNREACH (ERROR_BASE_NO + 101)
-#endif
-
-#ifndef ENETRESET
#define ENETRESET (ERROR_BASE_NO + 102)
-#endif
-
-#ifndef ECONNABORTED
#define ECONNABORTED (ERROR_BASE_NO + 103)
-#endif
-
-#ifndef ECONNRESET
#define ECONNRESET (ERROR_BASE_NO + 104)
-#endif
-
-#ifndef ENOBUFS
#define ENOBUFS (ERROR_BASE_NO + 105)
-#endif
-
-#ifndef EISCONN
#define EISCONN (ERROR_BASE_NO + 106)
-#endif
-
-#ifndef ENOTCONN
#define ENOTCONN (ERROR_BASE_NO + 107)
-#endif
-
-#ifndef ESHUTDOWN
#define ESHUTDOWN (ERROR_BASE_NO + 108)
-#endif
-
-#ifndef ETOOMANYREFS
#define ETOOMANYREFS (ERROR_BASE_NO + 109)
-#endif
-
-#ifndef ETIMEDOUT
#define ETIMEDOUT (ERROR_BASE_NO + 110)
-#endif
-
-#ifndef ECONNREFUSED
#define ECONNREFUSED (ERROR_BASE_NO + 111)
-#endif
-
-#ifndef EHOSTDOWN
#define EHOSTDOWN (ERROR_BASE_NO + 112)
-#endif
-
-#ifndef EHOSTUNREACH
#define EHOSTUNREACH (ERROR_BASE_NO + 113)
-#endif
-
-#ifndef EALREADY
#define EALREADY (ERROR_BASE_NO + 114)
-#endif
-
-#ifndef EINPROGRESS
#define EINPROGRESS (ERROR_BASE_NO + 115)
-#endif
-
-#ifndef ESTALE
#define ESTALE (ERROR_BASE_NO + 116)
-#endif
-
-#ifndef EUCLEAN
#define EUCLEAN (ERROR_BASE_NO + 117)
-#endif
-
-#ifndef ENOTNAM
#define ENOTNAM (ERROR_BASE_NO + 118)
-#endif
-
-#ifndef ENAVAIL
#define ENAVAIL (ERROR_BASE_NO + 119)
-#endif
-
-#ifndef EISNAM
#define EISNAM (ERROR_BASE_NO + 120)
-#endif
-
-#ifndef EREMOTEIO
#define EREMOTEIO (ERROR_BASE_NO + 121)
-#endif
-
-#ifndef EDQUOT
#define EDQUOT (ERROR_BASE_NO + 122)
-#endif
-
-#ifndef ENOMEDIUM
#define ENOMEDIUM (ERROR_BASE_NO + 123)
-#endif
-
-#ifndef EMEDIUMTYPE
#define EMEDIUMTYPE (ERROR_BASE_NO + 124)
-#endif
-
-#ifndef ECANCELED
#define ECANCELED (ERROR_BASE_NO + 125)
-#endif
-
-#ifndef ENOKEY
#define ENOKEY (ERROR_BASE_NO + 126)
-#endif
-
-#ifndef EKEYEXPIRED
#define EKEYEXPIRED (ERROR_BASE_NO + 127)
-#endif
-
-#ifndef EKEYREVOKED
#define EKEYREVOKED (ERROR_BASE_NO + 128)
-#endif
-
-#ifndef EKEYREJECTED
#define EKEYREJECTED (ERROR_BASE_NO + 129)
-#endif
-
-#ifndef EOWNERDEAD
#define EOWNERDEAD (ERROR_BASE_NO + 130)
-#endif
-
-#ifndef ENOTRECOVERABLE
#define ENOTRECOVERABLE (ERROR_BASE_NO + 131)
-#endif
-
-#ifndef ERFKILL
#define ERFKILL (ERROR_BASE_NO + 132)
-#endif
-
-#ifndef EHWPOISON
#define EHWPOISON (ERROR_BASE_NO + 133)
#endif
-#elif defined(_WIN32)
-#include
-
-#endif /* defined(__ARMCC_VERSION) || defined(__IAR_SYSTEMS_ICC__) */
-
-#endif /* __SYS_ERRNO_H__ */
+#endif
diff --git a/rt-thread/components/libc/compilers/common/nogcc/sys/select.h b/rt-thread/components/libc/compilers/common/nogcc/sys/select.h
index 44f9b4e..02fb77d 100644
--- a/rt-thread/components/libc/compilers/common/nogcc/sys/select.h
+++ b/rt-thread/components/libc/compilers/common/nogcc/sys/select.h
@@ -6,7 +6,6 @@
* Change Logs:
* Date Author Notes
* 2021-07-21 Meco Man The first version
- * 2021-12-25 Meco Man Handle newlib 2.2.0 or lower version
*/
#ifndef __SYS_SELECT_H__
@@ -34,12 +33,13 @@
typedef long fd_mask;
#ifndef _WIN32
-#ifndef _SYS_TYPES_FD_SET /* Newlib 2.2.0 or lower version */
+#ifndef _SYS_TYPES_FD_SET /* MIPS */
+
#define NBBY 8 /* number of bits in a byte */
#define NFDBITS (sizeof (fd_mask) * NBBY) /* bits per mask */
#ifndef howmany
#define howmany(x,y) (((x)+((y)-1))/(y))
-#endif /* howmany */
+#endif
typedef struct _types_fd_set {
fd_mask fds_bits[howmany(FD_SETSIZE, NFDBITS)];
diff --git a/rt-thread/components/libc/compilers/common/nogcc/unistd.h b/rt-thread/components/libc/compilers/common/nogcc/unistd.h
index 9b96d45..cd77a12 100644
--- a/rt-thread/components/libc/compilers/common/nogcc/unistd.h
+++ b/rt-thread/components/libc/compilers/common/nogcc/unistd.h
@@ -7,3 +7,4 @@
* Date Author Notes
*/
#include "sys/unistd.h"
+
diff --git a/rt-thread/components/libc/posix/io/poll/poll.h b/rt-thread/components/libc/compilers/common/poll.h
similarity index 100%
rename from rt-thread/components/libc/posix/io/poll/poll.h
rename to rt-thread/components/libc/compilers/common/poll.h
diff --git a/rt-thread/components/libc/compilers/common/readme.md b/rt-thread/components/libc/compilers/common/readme.md
index 82e23f8..856ddeb 100644
--- a/rt-thread/components/libc/compilers/common/readme.md
+++ b/rt-thread/components/libc/compilers/common/readme.md
@@ -1 +1,10 @@
-This folder is "common" for all toolchains.
\ No newline at end of file
+## Attentions
+
+1. This folder is "common" for all toolchains.
+
+2. If you want to add new `.c` files, please do not forget to fix SConscript file too. eg:
+
+```python
+if GetDepend('RT_USING_POSIX') == False:
+ SrcRemove(src, ['unistd.c'])
+```
\ No newline at end of file
diff --git a/rt-thread/components/libc/compilers/common/sys/ioctl.h b/rt-thread/components/libc/compilers/common/sys/ioctl.h
index a164219..04f7383 100644
--- a/rt-thread/components/libc/compilers/common/sys/ioctl.h
+++ b/rt-thread/components/libc/compilers/common/sys/ioctl.h
@@ -7,11 +7,13 @@
* Date Author Notes
* 2020-09-01 Meco Man First Version
*/
-#ifndef __SYS_IOCTL_H__
-#define __SYS_IOCTL_H__
+#ifndef _SYS_IOCTL_H
+#define _SYS_IOCTL_H
#include
+#ifdef RT_USING_POSIX
#include
+#endif
#ifdef _WIN32
#include
diff --git a/rt-thread/components/libc/posix/io/mman/sys/mman.h b/rt-thread/components/libc/compilers/common/sys/mman.h
similarity index 96%
rename from rt-thread/components/libc/posix/io/mman/sys/mman.h
rename to rt-thread/components/libc/compilers/common/sys/mman.h
index a730f33..2da2ddf 100644
--- a/rt-thread/components/libc/posix/io/mman/sys/mman.h
+++ b/rt-thread/components/libc/compilers/common/sys/mman.h
@@ -8,8 +8,8 @@
* 2017/11/30 Bernard The first version.
*/
-#ifndef __SYS_MMAN_H__
-#define __SYS_MMAN_H__
+#ifndef _SYS_MMAN_H
+#define _SYS_MMAN_H
#ifdef __cplusplus
extern "C" {
diff --git a/rt-thread/components/libc/posix/ipc/system-v/sys/sem.h b/rt-thread/components/libc/compilers/common/sys/termios.h
similarity index 62%
rename from rt-thread/components/libc/posix/ipc/system-v/sys/sem.h
rename to rt-thread/components/libc/compilers/common/sys/termios.h
index fdb7049..c4b4208 100644
--- a/rt-thread/components/libc/posix/ipc/system-v/sys/sem.h
+++ b/rt-thread/components/libc/compilers/common/sys/termios.h
@@ -5,9 +5,4 @@
*
* Change Logs:
* Date Author Notes
- * 2021-12-07 Meco Man First version
*/
-#ifndef __SYS_SEM_H__
-#define __SYS_SEM_H__
-
-#endif
diff --git a/rt-thread/components/libc/compilers/common/sys/time.h b/rt-thread/components/libc/compilers/common/sys/time.h
index 55c60d7..d14905e 100644
--- a/rt-thread/components/libc/compilers/common/sys/time.h
+++ b/rt-thread/components/libc/compilers/common/sys/time.h
@@ -15,9 +15,6 @@
#include
#include
#include
-#ifdef _WIN32
-#include /* for struct timeval */
-#endif
#ifdef __cplusplus
extern "C" {
@@ -75,7 +72,7 @@ int settimeofday(const struct timeval *tv, const struct timezone *tz);
struct tm *gmtime_r(const time_t *timep, struct tm *r);
#endif
-#ifdef RT_USING_POSIX_CLOCK
+#ifdef RT_USING_POSIX
/* POSIX clock and timer */
#define MILLISECOND_PER_SECOND 1000UL
#define MICROSECOND_PER_SECOND 1000000UL
@@ -105,12 +102,9 @@ struct tm *gmtime_r(const time_t *timep, struct tm *r);
int clock_getres (clockid_t clockid, struct timespec *res);
int clock_gettime (clockid_t clockid, struct timespec *tp);
int clock_settime (clockid_t clockid, const struct timespec *tp);
-int clock_nanosleep(clockid_t clockid, int flags, const struct timespec *rqtp, struct timespec *rmtp);
-int nanosleep(const struct timespec *rqtp, struct timespec *rmtp);
int rt_timespec_to_tick(const struct timespec *time);
-#endif /* RT_USING_POSIX_CLOCK */
+#endif /* RT_USING_POSIX */
-/* timezone */
void tz_set(int8_t tz);
int8_t tz_get(void);
int8_t tz_is_dst(void);
diff --git a/rt-thread/components/libc/posix/ipc/system-v/sys/ipc.h b/rt-thread/components/libc/compilers/common/termios.h
similarity index 52%
rename from rt-thread/components/libc/posix/ipc/system-v/sys/ipc.h
rename to rt-thread/components/libc/compilers/common/termios.h
index 03b5458..2960d52 100644
--- a/rt-thread/components/libc/posix/ipc/system-v/sys/ipc.h
+++ b/rt-thread/components/libc/compilers/common/termios.h
@@ -5,11 +5,15 @@
*
* Change Logs:
* Date Author Notes
- * 2021-12-07 Meco Man First version
*/
-#ifndef __SYS_IPC_H__
-#define __SYS_IPC_H__
+#ifndef _TERMIOS_H__
+#define _TERMIOS_H__
+#include
+#ifdef RT_USING_POSIX_TERMIOS
+#include
+#include
+#endif
#endif
diff --git a/rt-thread/components/libc/compilers/common/time.c b/rt-thread/components/libc/compilers/common/time.c
index 256268a..5bfff15 100644
--- a/rt-thread/components/libc/compilers/common/time.c
+++ b/rt-thread/components/libc/compilers/common/time.c
@@ -25,7 +25,7 @@
#include
#include
#include
-#ifdef RT_USING_RTC
+#ifdef RT_USING_DEVICE
#include
#endif
@@ -33,8 +33,6 @@
#define DBG_LVL DBG_INFO
#include
-#define _WARNING_NO_RTC "Cannot find a RTC device!"
-
/* seconds per day */
#define SPD 24*60*60
@@ -56,8 +54,8 @@ static const short __spm[13] =
(31 + 28 + 31 + 30 + 31 + 30 + 31 + 31 + 30 + 31 + 30 + 31),
};
-ALIGN(4) static const char *days = "Sun Mon Tue Wed Thu Fri Sat ";
-ALIGN(4) static const char *months = "Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec ";
+ALIGN(4) static const char days[] = "Sun Mon Tue Wed Thu Fri Sat ";
+ALIGN(4) static const char months[] = "Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec ";
static int __isleap(int year)
{
@@ -110,7 +108,7 @@ static rt_err_t get_timeval(struct timeval *tv)
else
{
/* LOG_W will cause a recursive printing if ulog timestamp function is enabled */
- rt_kprintf(_WARNING_NO_RTC);
+ rt_kprintf("Cannot find a RTC device to provide time!\r\n");
return -RT_ENOSYS;
}
@@ -118,7 +116,7 @@ static rt_err_t get_timeval(struct timeval *tv)
#else
/* LOG_W will cause a recursive printing if ulog timestamp function is enabled */
- rt_kprintf(_WARNING_NO_RTC);
+ rt_kprintf("Cannot find a RTC device to provide time!\r\n");
return -RT_ENOSYS;
#endif /* RT_USING_RTC */
}
@@ -155,14 +153,14 @@ static int set_timeval(struct timeval *tv)
}
else
{
- LOG_W(_WARNING_NO_RTC);
+ LOG_W("Cannot find a RTC device to provide time!");
return -RT_ENOSYS;
}
return rst;
#else
- LOG_W(_WARNING_NO_RTC);
+ LOG_W("Cannot find a RTC device to provide time!");
return -RT_ENOSYS;
#endif /* RT_USING_RTC */
}
@@ -488,8 +486,8 @@ RTM_EXPORT(settimeofday);
RTM_EXPORT(difftime);
RTM_EXPORT(strftime);
-#ifdef RT_USING_POSIX_CLOCK
-#include
+#ifdef RT_USING_POSIX
+
#ifdef RT_USING_RTC
static volatile struct timeval _timevalue;
static int _rt_clock_time_system_init()
@@ -527,7 +525,7 @@ INIT_COMPONENT_EXPORT(_rt_clock_time_system_init);
int clock_getres(clockid_t clockid, struct timespec *res)
{
#ifndef RT_USING_RTC
- LOG_W(_WARNING_NO_RTC);
+ LOG_W("Cannot find a RTC device to save time!");
return -1;
#else
int ret = 0;
@@ -566,7 +564,7 @@ RTM_EXPORT(clock_getres);
int clock_gettime(clockid_t clockid, struct timespec *tp)
{
#ifndef RT_USING_RTC
- LOG_W(_WARNING_NO_RTC);
+ LOG_W("Cannot find a RTC device to save time!");
return -1;
#else
int ret = 0;
@@ -616,21 +614,10 @@ int clock_gettime(clockid_t clockid, struct timespec *tp)
}
RTM_EXPORT(clock_gettime);
-int clock_nanosleep(clockid_t clockid, int flags, const struct timespec *rqtp, struct timespec *rmtp)
-{
- if ((clockid != CLOCK_REALTIME) || (rqtp == RT_NULL))
- {
- rt_set_errno(EINVAL);
- return -1;
- }
-
- return nanosleep(rqtp, rmtp);
-}
-
int clock_settime(clockid_t clockid, const struct timespec *tp)
{
#ifndef RT_USING_RTC
- LOG_W(_WARNING_NO_RTC);
+ LOG_W("Cannot find a RTC device to save time!");
return -1;
#else
register rt_base_t level;
@@ -670,33 +657,6 @@ int clock_settime(clockid_t clockid, const struct timespec *tp)
}
RTM_EXPORT(clock_settime);
-int nanosleep(const struct timespec *rqtp, struct timespec *rmtp)
-{
- uint32_t time_ms = rqtp->tv_sec * 1000;
- uint32_t time_us = rqtp->tv_nsec / 1000;
-
- time_ms += time_us / 1000 ;
- time_us = time_us % 1000;
-
- if (rt_thread_self() != RT_NULL)
- {
- rt_thread_mdelay(time_ms);
- }
- else /* scheduler has not run yet */
- {
- while(time_ms > 0)
- {
- udelay(1000u);
- time_ms -= 1;
- }
- }
-
- udelay(time_us);
-
- return 0;
-}
-RTM_EXPORT(nanosleep);
-
int rt_timespec_to_tick(const struct timespec *time)
{
int tick;
@@ -730,7 +690,8 @@ int rt_timespec_to_tick(const struct timespec *time)
}
RTM_EXPORT(rt_timespec_to_tick);
-#endif /* RT_USING_POSIX_CLOCK */
+#endif /* RT_USING_POSIX */
+
/* timezone */
#ifndef RT_LIBC_DEFAULT_TIMEZONE
diff --git a/rt-thread/components/libc/compilers/common/unistd.c b/rt-thread/components/libc/compilers/common/unistd.c
new file mode 100644
index 0000000..9a457c4
--- /dev/null
+++ b/rt-thread/components/libc/compilers/common/unistd.c
@@ -0,0 +1,119 @@
+/*
+ * Copyright (c) 2006-2021, RT-Thread Development Team
+ *
+ * SPDX-License-Identifier: Apache-2.0
+ *
+ * Change Logs:
+ * Date Author Notes
+ * 2020-09-01 Meco Man first Version
+ * 2021-02-12 Meco Man move all functions located in to this file
+ */
+
+#include
+#include
+#include
+
+#ifdef RT_USING_POSIX_TERMIOS
+#include "termios.h"
+int isatty(int fd)
+{
+ struct termios ts;
+ return(tcgetattr(fd, &ts) != -1); /*true if no error (is a tty)*/
+}
+#else
+int isatty(int fd)
+{
+ if (fd >=0 && fd < 3)
+ {
+ return 1;
+ }
+ else
+ {
+ return 0;
+ }
+}
+#endif
+RTM_EXPORT(isatty);
+
+char *ttyname(int fd)
+{
+ return "/dev/tty"; /* TODO: need to add more specific */
+}
+RTM_EXPORT(ttyname);
+
+unsigned int sleep(unsigned int seconds)
+{
+ if (rt_thread_self() != RT_NULL)
+ {
+ rt_thread_delay(seconds * RT_TICK_PER_SECOND);
+ }
+ else /* scheduler has not run yet */
+ {
+ while(seconds > 0)
+ {
+ rt_hw_us_delay(1000000u);
+ seconds --;
+ }
+ }
+
+ return 0;
+}
+RTM_EXPORT(sleep);
+
+int usleep(useconds_t usec)
+{
+ if (rt_thread_self() != RT_NULL)
+ {
+ rt_thread_mdelay(usec / 1000u);
+ }
+ else /* scheduler has not run yet */
+ {
+ rt_hw_us_delay(usec / 1000u);
+ }
+ rt_hw_us_delay(usec % 1000u);
+
+ return 0;
+}
+RTM_EXPORT(usleep);
+
+pid_t gettid(void)
+{
+ /*TODO*/
+ return 0;
+}
+
+pid_t getpid(void)
+{
+ return gettid();
+}
+RTM_EXPORT(getpid);
+
+pid_t getppid(void)
+{
+ return 0;
+}
+RTM_EXPORT(getppid);
+
+uid_t getuid(void)
+{
+ return 0; /*ROOT*/
+}
+RTM_EXPORT(getuid);
+
+uid_t geteuid(void)
+{
+ return 0; /*ROOT*/
+}
+RTM_EXPORT(geteuid);
+
+gid_t getgid(void)
+{
+ return 0; /*ROOT*/
+}
+RTM_EXPORT(getgid);
+
+gid_t getegid(void)
+{
+ return 0; /*ROOT*/
+}
+RTM_EXPORT(getegid);
diff --git a/rt-thread/components/libc/compilers/dlib/README.md b/rt-thread/components/libc/compilers/dlib/README.md
index e4d70e8..acd08f9 100644
--- a/rt-thread/components/libc/compilers/dlib/README.md
+++ b/rt-thread/components/libc/compilers/dlib/README.md
@@ -1,3 +1,9 @@
# DLIB (IAR) porting for RT-Thread
+Please define RT_USING_LIBC and compile RT-Thread with IAR compiler.
+
+
+
+## More Information
+
http://www.iarsys.co.jp/download/LMS2/arm/7502/ewarm7502doc/arm/doc/EWARM_DevelopmentGuide.ENU.pdf P.130
\ No newline at end of file
diff --git a/rt-thread/components/libc/compilers/dlib/SConscript b/rt-thread/components/libc/compilers/dlib/SConscript
index e11ea65..75a5812 100644
--- a/rt-thread/components/libc/compilers/dlib/SConscript
+++ b/rt-thread/components/libc/compilers/dlib/SConscript
@@ -1,20 +1,26 @@
from building import *
+
Import('rtconfig')
src = Glob('*.c')
+cwd = GetCurrentDir()
group = []
+CPPPATH = [cwd]
CPPDEFINES = ['RT_USING_DLIBC']
if rtconfig.PLATFORM == 'iar':
- if GetDepend('DFS_USING_POSIX'):
+
+ if GetDepend('RT_USING_DFS'):
from distutils.version import LooseVersion
from iar import IARVersion
CPPDEFINES = CPPDEFINES + ['_DLIB_FILE_DESCRIPTOR']
+
if LooseVersion(IARVersion()) < LooseVersion("8.20.1"):
CPPDEFINES = CPPDEFINES + ['_DLIB_THREAD_SUPPORT']
- group = DefineGroup('Compiler', src, depend = [''], CPPDEFINES = CPPDEFINES)
+ group = DefineGroup('libc', src, depend = ['RT_USING_LIBC'],
+ CPPPATH = CPPPATH, CPPDEFINES = CPPDEFINES)
Return('group')
diff --git a/rt-thread/components/libc/compilers/dlib/libc.c b/rt-thread/components/libc/compilers/dlib/libc.c
new file mode 100644
index 0000000..f540ac9
--- /dev/null
+++ b/rt-thread/components/libc/compilers/dlib/libc.c
@@ -0,0 +1,41 @@
+/*
+ * 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
+#include
+#include "libc.h"
+
+#ifdef RT_USING_PTHREADS
+#include
+#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);
+
diff --git a/rt-thread/components/libc/posix/io/libc.h b/rt-thread/components/libc/compilers/dlib/libc.h
similarity index 84%
rename from rt-thread/components/libc/posix/io/libc.h
rename to rt-thread/components/libc/compilers/dlib/libc.h
index 983a927..9643c11 100644
--- a/rt-thread/components/libc/posix/io/libc.h
+++ b/rt-thread/components/libc/compilers/dlib/libc.h
@@ -7,20 +7,17 @@
* Date Author Notes
* 2017/10/15 bernard the first version
*/
+
#ifndef __RTT_LIBC_H__
#define __RTT_LIBC_H__
-#include
-
#ifdef __cplusplus
extern "C" {
#endif
int libc_system_init(void);
-#ifdef RT_USING_POSIX_STDIO
int libc_stdio_get_console(void);
int libc_stdio_set_console(const char* device_name, int mode);
-#endif /* RT_USING_POSIX_STDIO */
#ifdef __cplusplus
}
diff --git a/rt-thread/components/libc/compilers/dlib/stdio.c b/rt-thread/components/libc/compilers/dlib/stdio.c
new file mode 100644
index 0000000..ed3f5df
--- /dev/null
+++ b/rt-thread/components/libc/compilers/dlib/stdio.c
@@ -0,0 +1,49 @@
+/*
+ * 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 IAR dlib.
+ */
+
+#include
+#include
+#include
+
+#include
+#include "libc.h"
+
+#if defined(RT_USING_DFS) && defined(RT_USING_DFS_DEVFS)
+#include
+
+#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
diff --git a/rt-thread/components/libc/compilers/dlib/syscall_close.c b/rt-thread/components/libc/compilers/dlib/syscall_close.c
index 294c81f..7ed1cc2 100644
--- a/rt-thread/components/libc/compilers/dlib/syscall_close.c
+++ b/rt-thread/components/libc/compilers/dlib/syscall_close.c
@@ -8,30 +8,22 @@
* 2015-01-28 Bernard first version
*/
#include
-#include
-#include
-#include
-#define DBG_TAG "dlib.syscall.close"
-#define DBG_LVL DBG_INFO
-#include
-
-/*
- * The "__close" function should close the file corresponding to
- * "handle". It should return 0 on success and nonzero on failure.
- */
+#ifdef RT_USING_DFS
+#include
+#endif
+#include
#pragma module_name = "?__close"
-
int __close(int handle)
{
if (handle == _LLIO_STDOUT ||
handle == _LLIO_STDERR ||
handle == _LLIO_STDIN)
return _LLIO_ERROR;
-#ifdef DFS_USING_POSIX
+
+#ifdef RT_USING_DFS
return close(handle);
#else
- LOG_W(_WARNING_WITHOUT_FS);
- return _LLIO_ERROR;
-#endif /* DFS_USING_POSIX */
+ return 0;
+#endif
}
diff --git a/rt-thread/components/libc/compilers/dlib/syscall_lseek.c b/rt-thread/components/libc/compilers/dlib/syscall_lseek.c
index 3bfec38..47a069b 100644
--- a/rt-thread/components/libc/compilers/dlib/syscall_lseek.c
+++ b/rt-thread/components/libc/compilers/dlib/syscall_lseek.c
@@ -8,39 +8,22 @@
* 2015-01-28 Bernard first version
*/
#include
-#include
-#include
-#include
-#define DBG_TAG "dlib.syscall.lseek"
-#define DBG_LVL DBG_INFO
-#include
-
-/*
- * The "__lseek" function makes the next file operation (__read or
- * __write) act on a new location. The parameter "whence" specifies
- * how the "offset" parameter should be interpreted according to the
- * following table:
- *
- * 0 (=SEEK_SET) - Goto location "offset".
- * 1 (=SEEK_CUR) - Go "offset" bytes from the current location.
- * 2 (=SEEK_END) - Go to "offset" bytes from the end.
- *
- * This function should return the current file position, or -1 on
- * failure.
- */
+#ifdef RT_USING_DFS
+#include
+#endif
+#include
#pragma module_name = "?__lseek"
-
long __lseek(int handle, long offset, int whence)
{
if (handle == _LLIO_STDOUT ||
handle == _LLIO_STDERR ||
handle == _LLIO_STDIN)
return _LLIO_ERROR;
-#ifdef DFS_USING_POSIX
+
+#ifdef RT_USING_DFS
return lseek(handle, offset, whence);
#else
- LOG_W(_WARNING_WITHOUT_FS);
return _LLIO_ERROR;
-#endif /* DFS_USING_POSIX */
+#endif
}
diff --git a/rt-thread/components/libc/compilers/dlib/syscall_mem.c b/rt-thread/components/libc/compilers/dlib/syscall_mem.c
index 57060da..9c6de64 100644
--- a/rt-thread/components/libc/compilers/dlib/syscall_mem.c
+++ b/rt-thread/components/libc/compilers/dlib/syscall_mem.c
@@ -6,55 +6,27 @@
* Change Logs:
* Date Author Notes
* 2015-01-28 Bernard first version
- * 2021-11-13 Meco Man implement no-heap warning
*/
#include
-#include
-#ifndef RT_USING_HEAP
-#define DBG_TAG "dlib.syscall.mem"
-#define DBG_LVL DBG_INFO
-#include
-#define _NO_HEAP_ERROR() do{LOG_E("Please enable RT_USING_HEAP");\
- RT_ASSERT(0);\
- }while(0)
-#endif /* RT_USING_HEAP */
-
-void *malloc(size_t n)
-{
#ifdef RT_USING_HEAP
+void *malloc(rt_size_t n)
+{
return rt_malloc(n);
-#else
- _NO_HEAP_ERROR();
- return RT_NULL;
-#endif
}
-void *realloc(void *rmem, size_t newsize)
+void *realloc(void *rmem, rt_size_t newsize)
{
-#ifdef RT_USING_HEAP
return rt_realloc(rmem, newsize);
-#else
- _NO_HEAP_ERROR();
- return RT_NULL;
-#endif
}
-void *calloc(size_t nelem, size_t elsize)
+void *calloc(rt_size_t nelem, rt_size_t elsize)
{
-#ifdef RT_USING_HEAP
return rt_calloc(nelem, elsize);
-#else
- _NO_HEAP_ERROR();
- return RT_NULL;
-#endif
}
void free(void *rmem)
{
-#ifdef RT_USING_HEAP
rt_free(rmem);
-#else
- _NO_HEAP_ERROR();
-#endif
}
+#endif
diff --git a/rt-thread/components/libc/compilers/dlib/syscall_open.c b/rt-thread/components/libc/compilers/dlib/syscall_open.c
index 4d557db..37bfcec 100644
--- a/rt-thread/components/libc/compilers/dlib/syscall_open.c
+++ b/rt-thread/components/libc/compilers/dlib/syscall_open.c
@@ -9,75 +9,66 @@
*/
#include
-#include
-#include
-#include
-#define DBG_TAG "dlib.syscall.open"
-#define DBG_LVL DBG_INFO
-#include
-
-/*
- * The "__open" function opens the file named "filename" as specified
- * by "mode".
- */
+#include
+#ifdef RT_USING_DFS
+#include
+#endif
#pragma module_name = "?__open"
int __open(const char *filename, int mode)
{
-#ifdef DFS_USING_POSIX
- int handle;
- int open_mode = O_RDONLY;
-
- if (mode & _LLIO_CREAT)
- {
- open_mode |= O_CREAT;
-
- /* Check what we should do with it if it exists. */
- if (mode & _LLIO_APPEND)
- {
- /* Append to the existing file. */
- open_mode |= O_APPEND;
- }
-
- if (mode & _LLIO_TRUNC)
- {
- /* Truncate the existsing file. */
- open_mode |= O_TRUNC;
- }
- }
-
- if (mode & _LLIO_TEXT)
- {
- /* we didn't support text mode */
- }
-
- switch (mode & _LLIO_RDWRMASK)
- {
- case _LLIO_RDONLY:
- break;
-
- case _LLIO_WRONLY:
- open_mode |= O_WRONLY;
- break;
-
- case _LLIO_RDWR:
- /* The file should be opened for both reads and writes. */
- open_mode |= O_RDWR;
- break;
-
- default:
- return _LLIO_ERROR;
- }
-
- handle = open(filename, open_mode, 0);
- if (handle < 0)
- {
- return _LLIO_ERROR;
- }
- return handle;
+#ifndef RT_USING_DFS
+ return _LLIO_ERROR;
#else
- LOG_W(_WARNING_WITHOUT_FS);
+ int handle;
+ int open_mode = O_RDONLY;
+
+ if (mode & _LLIO_CREAT)
+ {
+ open_mode |= O_CREAT;
+
+ /* Check what we should do with it if it exists. */
+ if (mode & _LLIO_APPEND)
+ {
+ /* Append to the existing file. */
+ open_mode |= O_APPEND;
+ }
+
+ if (mode & _LLIO_TRUNC)
+ {
+ /* Truncate the existsing file. */
+ open_mode |= O_TRUNC;
+ }
+ }
+
+ if (mode & _LLIO_TEXT)
+ {
+ /* we didn't support text mode */
+ }
+
+ switch (mode & _LLIO_RDWRMASK)
+ {
+ case _LLIO_RDONLY:
+ break;
+
+ case _LLIO_WRONLY:
+ open_mode |= O_WRONLY;
+ break;
+
+ case _LLIO_RDWR:
+ /* The file should be opened for both reads and writes. */
+ open_mode |= O_RDWR;
+ break;
+
+ default:
return _LLIO_ERROR;
-#endif /* DFS_USING_POSIX */
+ }
+
+ handle = open(filename, open_mode, 0);
+ if (handle < 0)
+ return _LLIO_ERROR;
+
+ return handle;
+#endif
}
diff --git a/rt-thread/components/libc/compilers/dlib/syscall_read.c b/rt-thread/components/libc/compilers/dlib/syscall_read.c
index a276a3e..ae980be 100644
--- a/rt-thread/components/libc/compilers/dlib/syscall_read.c
+++ b/rt-thread/components/libc/compilers/dlib/syscall_read.c
@@ -9,57 +9,45 @@
*/
#include
-#include
-#include
-#ifdef RT_USING_POSIX_STDIO
+#ifdef RT_USING_DFS
+#include
+#endif
+#include
#include "libc.h"
-#endif /* RT_USING_POSIX_STDIO */
-#include
-#define DBG_TAG "dlib.syscall.read"
+
+#define DBG_TAG "dlib.syscall_read"
#define DBG_LVL DBG_INFO
#include
-/*
- * The "__read" function reads a number of bytes, at most "size" into
- * the memory area pointed to by "buffer". It returns the number of
- * bytes read, 0 at the end of the file, or _LLIO_ERROR if failure
- * occurs.
- *
- * The template implementation below assumes that the application
- * provides the function "MyLowLevelGetchar". It should return a
- * character value, or -1 on failure.
- */
-
#pragma module_name = "?__read"
-
size_t __read(int handle, unsigned char *buf, size_t len)
{
-#ifdef DFS_USING_POSIX
+#ifdef RT_USING_DFS
int size;
+#endif
if (handle == _LLIO_STDIN)
{
-#ifdef RT_USING_POSIX_STDIO
+#ifdef RT_USING_POSIX
if (libc_stdio_get_console() < 0)
{
- LOG_W("Do not invoke standard input before initializing Compiler");
- return 0; /* error, but keep going */
+ LOG_W("Do not invoke standard input before initializing libc");
+ return 0;
}
- return read(STDIN_FILENO, buf, len); /* return the length of the data read */
+ return read(STDIN_FILENO, buf, len);
#else
- LOG_W(_WARNING_WITHOUT_STDIO);
return _LLIO_ERROR;
-#endif /* RT_USING_POSIX_STDIO */
+#endif
}
else if ((handle == _LLIO_STDOUT) || (handle == _LLIO_STDERR))
{
return _LLIO_ERROR;
}
- size = read(handle, buf, len);
- return size; /* return the length of the data read */
-#else
- LOG_W(_WARNING_WITHOUT_FS);
+#ifndef RT_USING_DFS
return _LLIO_ERROR;
-#endif /* DFS_USING_POSIX */
+#else
+ size = read(handle, buf, len);
+ return size;
+#endif
}
diff --git a/rt-thread/components/libc/compilers/dlib/syscall_remove.c b/rt-thread/components/libc/compilers/dlib/syscall_remove.c
index 40c5116..7d74236 100644
--- a/rt-thread/components/libc/compilers/dlib/syscall_remove.c
+++ b/rt-thread/components/libc/compilers/dlib/syscall_remove.c
@@ -8,26 +8,17 @@
* 2015-01-28 Bernard first version
*/
#include
-#include
-#include
-#include
-#define DBG_TAG "dlib.syscall.remove"
-#define DBG_LVL DBG_INFO
-#include
-
-/*
- * The "remove" function should remove the file named "filename". It
- * should return 0 on success and nonzero on failure.
- */
+#ifdef RT_USING_DFS
+#include
+#endif
+#include
#pragma module_name = "?remove"
-
-int remove(const char *filename)
+int remove(const char *val)
{
-#ifdef DFS_USING_POSIX
- return unlink(filename);
+#ifndef RT_USING_DFS
+ return -1;
#else
- LOG_W(_WARNING_WITHOUT_FS);
- return _LLIO_ERROR;
-#endif /* DFS_USING_POSIX */
+ return unlink(val);
+#endif
}
diff --git a/rt-thread/components/libc/compilers/dlib/syscall_write.c b/rt-thread/components/libc/compilers/dlib/syscall_write.c
index 3af08da..ffee518 100644
--- a/rt-thread/components/libc/compilers/dlib/syscall_write.c
+++ b/rt-thread/components/libc/compilers/dlib/syscall_write.c
@@ -9,63 +9,60 @@
*/
#include
-#include
-#include
-#include
-#define DBG_TAG "dlib.syscall.write"
+#ifdef RT_USING_DFS
+#include
+#endif
+#include
+#include "libc.h"
+
+#define DBG_TAG "dlib.syscall_write"
#define DBG_LVL DBG_INFO
#include
-/*
- * The "__write" function should output "size" number of bytes from
- * "buffer" in some application-specific way. It should return the
- * number of characters written, or _LLIO_ERROR on failure.
- *
- * If "buffer" is zero then __write should perform flushing of
- * internal buffers, if any. In this case "handle" can be -1 to
- * indicate that all handles should be flushed.
- *
- * The template implementation below assumes that the application
- * provides the function "MyLowLevelPutchar". It should return the
- * character written, or -1 on failure.
- */
-
#pragma module_name = "?__write"
size_t __write(int handle, const unsigned char *buf, size_t len)
{
-#ifdef DFS_USING_POSIX
+#ifdef RT_USING_DFS
int size;
-#endif /* DFS_USING_POSIX */
+#endif
if ((handle == _LLIO_STDOUT) || (handle == _LLIO_STDERR))
{
-#ifdef RT_USING_CONSOLE
+#ifndef RT_USING_CONSOLE
+ return _LLIO_ERROR;
+#else
+
+#ifdef RT_USING_POSIX
+ if (libc_stdio_get_console() < 0)
+ {
+ LOG_W("Do not invoke standard output before initializing libc");
+ return 0;
+ }
+ return write(STDOUT_FILENO, (void*)buf, len);
+#else
rt_device_t console_device;
console_device = rt_console_get_device();
- if (console_device)
+ if (console_device != 0)
{
rt_device_write(console_device, 0, buf, len);
}
- return len; /* return the length of the data written */
-#else
- return _LLIO_ERROR;
-#endif /* RT_USING_CONSOLE */
+ return len;
+#endif
+#endif
}
else if (handle == _LLIO_STDIN)
{
return _LLIO_ERROR;
}
- else
- {
-#ifdef DFS_USING_POSIX
- size = write(handle, buf, len);
- return size; /* return the length of the data written */
+
+#ifndef RT_USING_DFS
+ return _LLIO_ERROR;
#else
- LOG_W(_WARNING_WITHOUT_FS);
- return _LLIO_ERROR;
-#endif /* DFS_USING_POSIX */
- }
+ size = write(handle, buf, len);
+ return size;
+#endif
}
+
diff --git a/rt-thread/components/libc/compilers/gcc/newlib/README.md b/rt-thread/components/libc/compilers/gcc/newlib/README.md
index 4614375..62172e6 100644
--- a/rt-thread/components/libc/compilers/gcc/newlib/README.md
+++ b/rt-thread/components/libc/compilers/gcc/newlib/README.md
@@ -1,4 +1,10 @@
# NEWLIB (GCC) porting for RT-Thread
+Please define RT_USING_LIBC and compile RT-Thread with GCC compiler.
+
+
+
+## More Information
+
https://sourceware.org/newlib/libc.html#Reentrancy
diff --git a/rt-thread/components/libc/compilers/gcc/newlib/SConscript b/rt-thread/components/libc/compilers/gcc/newlib/SConscript
index 8076a73..e0ee482 100644
--- a/rt-thread/components/libc/compilers/gcc/newlib/SConscript
+++ b/rt-thread/components/libc/compilers/gcc/newlib/SConscript
@@ -1,31 +1,27 @@
-import os
from building import *
-from gcc import *
Import('rtconfig')
src = []
cwd = GetCurrentDir()
group = []
-LIBS = ['m'] # link libm
+LIBS = ['m']
+CPPDEFINES = ['RT_USING_NEWLIB']
CPPPATH = [cwd]
if rtconfig.PLATFORM == 'gcc':
- LIBS += ['c'] # link libc
- src += Glob('*.c')
+ if GetDepend('RT_USING_LIBC'):
+ # link with libc and libm:
+ # libm is a frequently used lib. Newlib is compiled with -ffunction-sections in
+ # recent GCC tool chains. The linker would just link in the functions that have
+ # been referenced. So setting this won't result in bigger text size.
+ LIBS += ['c']
- #report newlib version
- print('Newlib version:' + GetNewLibVersion(rtconfig))
+ src += Glob('*.c')
+ if GetDepend('RT_USING_MODULE') == False:
+ SrcRemove(src, ['libc_syms.c'])
+ else:
+ src += ['syscalls.c']
- # identify this is Newlib, and only enable POSIX.1-1990
- CPPDEFINES = ['RT_USING_NEWLIB', '_POSIX_C_SOURCE=1']
-
- group = DefineGroup('Compiler', src, depend = [''], CPPPATH = CPPPATH, CPPDEFINES = CPPDEFINES, LIBS = LIBS)
-
-
-list = os.listdir(cwd)
-for d in list:
- path = os.path.join(cwd, d)
- if os.path.isfile(os.path.join(path, 'SConscript')):
- group = group + SConscript(os.path.join(d, 'SConscript'))
+ group = DefineGroup('libc', src, depend = [], CPPPATH = CPPPATH, CPPDEFINES = CPPDEFINES, LIBS = LIBS)
Return('group')
diff --git a/rt-thread/components/libc/compilers/gcc/newlib/legacy/_select/SConscript b/rt-thread/components/libc/compilers/gcc/newlib/legacy/_select/SConscript
deleted file mode 100644
index b7bd86a..0000000
--- a/rt-thread/components/libc/compilers/gcc/newlib/legacy/_select/SConscript
+++ /dev/null
@@ -1,20 +0,0 @@
-from shutil import copy
-from building import *
-from gcc import *
-Import('rtconfig')
-
-src = []
-cwd = GetCurrentDir()
-CPPPATH = [cwd]
-group = []
-
-# sys/select.h does not exist in newlib 2.1.0 or lower version
-if rtconfig.PLATFORM == 'gcc' and (CheckHeader(rtconfig, 'sys/select.h') == False):
- try:
- copy("../../../../common/nogcc/sys/select.h", "./sys/select.h") # copy from 'nogcc/sys/select.h'
- except:
- pass
-
- group = DefineGroup('Compiler', src, depend = [''], CPPPATH = CPPPATH)
-
-Return('group')
diff --git a/rt-thread/components/libc/compilers/gcc/newlib/legacy/_select/readme.md b/rt-thread/components/libc/compilers/gcc/newlib/legacy/_select/readme.md
deleted file mode 100644
index 4ad9f21..0000000
--- a/rt-thread/components/libc/compilers/gcc/newlib/legacy/_select/readme.md
+++ /dev/null
@@ -1,2 +0,0 @@
-Newlib 2.2.0 or lower version does not provide `sys/select.h`, and `fd_set` is defined in `sys/types.h`. It will be generated by scons automatically, and **DO NOT** change it.
-
diff --git a/rt-thread/components/libc/compilers/gcc/newlib/libc.c b/rt-thread/components/libc/compilers/gcc/newlib/libc.c
new file mode 100644
index 0000000..9834a9a
--- /dev/null
+++ b/rt-thread/components/libc/compilers/gcc/newlib/libc.c
@@ -0,0 +1,50 @@
+/*
+ * 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
+#include
+#include
+#include
+#include
+
+#include "libc.h"
+
+#ifdef RT_USING_PTHREADS
+#include
+#endif
+
+int _EXFUN(putenv,(char *__string));
+
+int libc_system_init(void)
+{
+#if defined(RT_USING_DFS) & defined(RT_USING_DFS_DEVFS) & defined(RT_USING_CONSOLE)
+ 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
+ }
+
+ /* set PATH and HOME */
+ putenv("PATH=/bin");
+ putenv("HOME=/home");
+#endif
+
+#if defined RT_USING_PTHREADS && !defined RT_USING_COMPONENTS_INIT
+ pthread_system_init();
+#endif
+
+ return 0;
+}
+INIT_COMPONENT_EXPORT(libc_system_init);
diff --git a/rt-thread/components/libc/compilers/gcc/newlib/libc.h b/rt-thread/components/libc/compilers/gcc/newlib/libc.h
new file mode 100644
index 0000000..c470698
--- /dev/null
+++ b/rt-thread/components/libc/compilers/gcc/newlib/libc.h
@@ -0,0 +1,28 @@
+/*
+ * 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__
+
+#ifndef _EXFUN
+#define _EXFUN(name, proto) name proto
+#endif
+
+#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
diff --git a/rt-thread/components/libc/compilers/gcc/newlib/machine/time.h b/rt-thread/components/libc/compilers/gcc/newlib/machine/time.h
index 9ef838f..ff754d2 100644
--- a/rt-thread/components/libc/compilers/gcc/newlib/machine/time.h
+++ b/rt-thread/components/libc/compilers/gcc/newlib/machine/time.h
@@ -4,4 +4,9 @@
#include
#define _CLOCKS_PER_SEC_ RT_TICK_PER_SECOND
+#ifdef __SPU__
+#include
+int nanosleep (const struct timespec *, struct timespec *);
+#endif
+
#endif /* _MACHTIME_H_ */
diff --git a/rt-thread/components/libc/posix/io/libc.c b/rt-thread/components/libc/compilers/gcc/newlib/stdio.c
similarity index 53%
rename from rt-thread/components/libc/posix/io/libc.c
rename to rt-thread/components/libc/compilers/gcc/newlib/stdio.c
index d8780b1..1875d50 100644
--- a/rt-thread/components/libc/posix/io/libc.c
+++ b/rt-thread/components/libc/compilers/gcc/newlib/stdio.c
@@ -7,35 +7,18 @@
* Date Author Notes
* 2017/10/15 bernard the first version
*/
-#include
#include
#include
-#include
-#include
#include
-#include
+#include
#include "libc.h"
-#include
-#include
-int libc_system_init(void)
-{
-#ifdef RT_USING_POSIX_STDIO
- rt_device_t dev_console;
-
- dev_console = rt_console_get_device();
- if (dev_console)
- {
- libc_stdio_set_console(dev_console->parent.name, O_RDWR);
- }
-#endif /* RT_USING_POSIX_STDIO */
- return 0;
-}
-INIT_COMPONENT_EXPORT(libc_system_init);
-
-#if defined(RT_USING_POSIX_STDIO) && defined(RT_USING_NEWLIB)
#define STDIO_DEVICE_NAME_MAX 32
+
+int _EXFUN(fileno, (FILE *));
+
static FILE* std_console = NULL;
+
int libc_stdio_set_console(const char* device_name, int mode)
{
FILE *fp;
@@ -45,18 +28,9 @@ int libc_stdio_set_console(const char* device_name, int mode)
snprintf(name, sizeof(name) - 1, "/dev/%s", device_name);
name[STDIO_DEVICE_NAME_MAX - 1] = '\0';
- if (mode == O_RDWR)
- {
- file_mode = "r+";
- }
- else if (mode == O_WRONLY)
- {
- file_mode = "wb";
- }
- else
- {
- file_mode = "rb";
- }
+ if (mode == O_RDWR) file_mode = "r+";
+ else if (mode == O_WRONLY) file_mode = "wb";
+ else file_mode = "rb";
fp = fopen(name, file_mode);
if (fp)
@@ -93,8 +67,7 @@ int libc_stdio_set_console(const char* device_name, int mode)
_GLOBAL_REENT->__sdidinit = 1;
}
- if (std_console)
- return fileno(std_console);
+ if (std_console) return fileno(std_console);
return -1;
}
@@ -106,32 +79,3 @@ int libc_stdio_get_console(void)
else
return -1;
}
-
-#else
-#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 /* defined(RT_USING_POSIX_STDIO) && defined(RT_USING_NEWLIB) */
diff --git a/rt-thread/components/libc/compilers/gcc/newlib/syscalls.c b/rt-thread/components/libc/compilers/gcc/newlib/syscalls.c
index d8a8ba6..f5a2c16 100644
--- a/rt-thread/components/libc/compilers/gcc/newlib/syscalls.c
+++ b/rt-thread/components/libc/compilers/gcc/newlib/syscalls.c
@@ -13,20 +13,10 @@
#include
#include
-#include
-#include
#include
-#include
#include
#include
-#include
-#ifdef RT_USING_POSIX_STDIO
-#include "libc.h"
-#endif /* RT_USING_POSIX_STDIO */
-#ifdef RT_USING_MODULE
-#include
-#endif /* RT_USING_MODULE */
-#include
+
#define DBG_TAG "newlib.syscalls"
#define DBG_LVL DBG_INFO
#include
@@ -80,7 +70,7 @@ void _free_r (struct _reent *ptr, void *addr)
void *
_sbrk_r(struct _reent *ptr, ptrdiff_t incr)
{
- LOG_E("Please enable RT_USING_HEAP");
+ LOG_E("Please enable RT_USING_HEAP or RT_USING_LIBC");
RT_ASSERT(0);
return RT_NULL;
}
@@ -92,7 +82,19 @@ void __libc_init_array(void)
/* __libc_init_array is ARM code, not Thumb; it will cause a hardfault. */
}
+#ifdef RT_USING_LIBC
+#include
+#include
+#include "libc.h"
+#ifdef RT_USING_DFS
+#include
+#endif
+#ifdef RT_USING_MODULE
+#include
+#endif
+
/* Reentrant versions of system calls. */
+
#ifndef _REENT_ONLY
int *__errno ()
{
@@ -107,35 +109,39 @@ int _getpid_r(struct _reent *ptr)
int _close_r(struct _reent *ptr, int fd)
{
-#ifdef DFS_USING_POSIX
- return close(fd);
-#else
- LOG_W("%s: %s", __func__, _WARNING_WITHOUT_FS);
+#ifndef RT_USING_DFS
+ /* return "not supported" */
ptr->_errno = ENOTSUP;
return -1;
-#endif /* DFS_USING_POSIX */
+#else
+ return close(fd);
+#endif
}
int _execve_r(struct _reent *ptr, const char * name, char *const *argv, char *const *env)
{
+ /* return "not supported" */
ptr->_errno = ENOTSUP;
return -1;
}
int _fcntl_r(struct _reent *ptr, int fd, int cmd, int arg)
{
+ /* return "not supported" */
ptr->_errno = ENOTSUP;
return -1;
}
int _fork_r(struct _reent *ptr)
{
+ /* return "not supported" */
ptr->_errno = ENOTSUP;
return -1;
}
int _fstat_r(struct _reent *ptr, int fd, struct stat *pstat)
{
+ /* return "not supported" */
ptr->_errno = ENOTSUP;
return -1;
}
@@ -154,20 +160,160 @@ int _isatty_r(struct _reent *ptr, int fd)
int _kill_r(struct _reent *ptr, int pid, int sig)
{
+ /* return "not supported" */
ptr->_errno = ENOTSUP;
return -1;
}
int _link_r(struct _reent *ptr, const char *old, const char *new)
{
+ /* return "not supported" */
ptr->_errno = ENOTSUP;
return -1;
}
-int _wait_r(struct _reent *ptr, int *status)
+_off_t _lseek_r(struct _reent *ptr, int fd, _off_t pos, int whence)
{
+#ifndef RT_USING_DFS
+ /* return "not supported" */
ptr->_errno = ENOTSUP;
return -1;
+#else
+ _off_t rc;
+
+ rc = lseek(fd, pos, whence);
+ return rc;
+#endif
+}
+
+int _mkdir_r(struct _reent *ptr, const char *name, int mode)
+{
+#ifndef RT_USING_DFS
+ /* return "not supported" */
+ ptr->_errno = ENOTSUP;
+ return -1;
+#else
+ int rc;
+
+ rc = mkdir(name, mode);
+ return rc;
+#endif
+}
+
+int _open_r(struct _reent *ptr, const char *file, int flags, int mode)
+{
+#ifndef RT_USING_DFS
+ /* return "not supported" */
+ ptr->_errno = ENOTSUP;
+ return -1;
+#else
+ int rc;
+
+ rc = open(file, flags, mode);
+ return rc;
+#endif
+}
+
+_ssize_t _read_r(struct _reent *ptr, int fd, void *buf, size_t nbytes)
+{
+#ifndef RT_USING_DFS
+ /* return "not supported" */
+ ptr->_errno = ENOTSUP;
+ return -1;
+#else
+ _ssize_t rc;
+ if (libc_stdio_get_console() < 0 && fd == STDIN_FILENO)
+ {
+ LOG_W("Do not invoke standard input before initializing libc");
+ return 0;
+ }
+ rc = read(fd, buf, nbytes);
+ return rc;
+#endif
+}
+
+int _rename_r(struct _reent *ptr, const char *old, const char *new)
+{
+#ifndef RT_USING_DFS
+ /* return "not supported" */
+ ptr->_errno = ENOTSUP;
+ return -1;
+#else
+ int rc;
+
+ rc = rename(old, new);
+ return rc;
+#endif
+}
+
+int _stat_r(struct _reent *ptr, const char *file, struct stat *pstat)
+{
+#ifndef RT_USING_DFS
+ /* return "not supported" */
+ ptr->_errno = ENOTSUP;
+ return -1;
+#else
+ int rc;
+
+ rc = stat(file, pstat);
+ return rc;
+#endif
+}
+
+int _unlink_r(struct _reent *ptr, const char *file)
+{
+#ifndef RT_USING_DFS
+ /* return "not supported" */
+ ptr->_errno = ENOTSUP;
+ return -1;
+#else
+ return unlink(file);
+#endif
+}
+
+int _wait_r(struct _reent *ptr, int *status)
+{
+ /* return "not supported" */
+ ptr->_errno = ENOTSUP;
+ return -1;
+}
+
+_ssize_t _write_r(struct _reent *ptr, int fd, const void *buf, size_t nbytes)
+{
+#ifndef RT_USING_DFS
+#if defined(RT_USING_CONSOLE) && defined(RT_USING_DEVICE)
+ if (STDOUT_FILENO == fd)
+ {
+ rt_device_t console;
+
+ console = rt_console_get_device();
+ if (console) return rt_device_write(console, -1, buf, nbytes);
+ }
+
+ return 0;
+#else
+ /* return "not supported" */
+ ptr->_errno = ENOTSUP;
+ return -1;
+#endif /*RT_USING_DEVICE*/
+#else
+ _ssize_t rc;
+ if (libc_stdio_get_console() < 0 && fd == STDOUT_FILENO)
+ {
+ LOG_W("Do not invoke standard output before initializing libc");
+ return 0;
+ }
+ rc = write(fd, buf, nbytes);
+ return rc;
+#endif
+}
+
+/* for exit() and abort() */
+__attribute__ ((noreturn)) void _exit (int status)
+{
+ extern void __rt_libc_exit(int status);
+ __rt_libc_exit(status);
+ while(1);
}
mode_t umask(mode_t mask)
@@ -180,160 +326,10 @@ int flock(int fd, int operation)
return 0;
}
-_off_t _lseek_r(struct _reent *ptr, int fd, _off_t pos, int whence)
-{
-#ifdef DFS_USING_POSIX
- _off_t rc;
- rc = lseek(fd, pos, whence);
- return rc;
-#else
- LOG_W("%s: %s", __func__, _WARNING_WITHOUT_FS);
- ptr->_errno = ENOTSUP;
- return -1;
-#endif /* DFS_USING_POSIX */
-}
-
-int _mkdir_r(struct _reent *ptr, const char *name, int mode)
-{
-#ifdef DFS_USING_POSIX
- int rc;
- rc = mkdir(name, mode);
- return rc;
-#else
- LOG_W("%s: %s", __func__, _WARNING_WITHOUT_FS);
- ptr->_errno = ENOTSUP;
- return -1;
-#endif /* DFS_USING_POSIX */
-}
-
-int _open_r(struct _reent *ptr, const char *file, int flags, int mode)
-{
-#ifdef DFS_USING_POSIX
- int rc;
- rc = open(file, flags, mode);
- return rc;
-#else
- LOG_W("%s: %s", __func__, _WARNING_WITHOUT_FS);
- ptr->_errno = ENOTSUP;
- return -1;
-#endif /* DFS_USING_POSIX */
-}
-
-_ssize_t _read_r(struct _reent *ptr, int fd, void *buf, size_t nbytes)
-{
-#ifdef DFS_USING_POSIX
- _ssize_t rc;
- if (fd == STDIN_FILENO)
- {
-#ifdef RT_USING_POSIX_STDIO
- if (libc_stdio_get_console() < 0)
- {
- LOG_W("Do not invoke standard input before initializing Compiler");
- return 0;
- }
-#else
- LOG_W("%s: %s", __func__, _WARNING_WITHOUT_STDIO);
- ptr->_errno = ENOTSUP;
- return -1;
-#endif /* RT_USING_POSIX_STDIO */
- }
- else if (fd == STDOUT_FILENO || fd == STDERR_FILENO)
- {
- ptr->_errno = ENOTSUP;
- return -1;
- }
-
- rc = read(fd, buf, nbytes);
- return rc;
-#else
- LOG_W("%s: %s", __func__, _WARNING_WITHOUT_FS);
- ptr->_errno = ENOTSUP;
- return -1;
-#endif /* DFS_USING_POSIX */
-}
-
-int _rename_r(struct _reent *ptr, const char *old, const char *new)
-{
-#ifdef DFS_USING_POSIX
- int rc;
- rc = rename(old, new);
- return rc;
-#else
- LOG_W("%s: %s", __func__, _WARNING_WITHOUT_FS);
- ptr->_errno = ENOTSUP;
- return -1;
-#endif /* DFS_USING_POSIX */
-}
-
-int _stat_r(struct _reent *ptr, const char *file, struct stat *pstat)
-{
-#ifdef DFS_USING_POSIX
- int rc;
- rc = stat(file, pstat);
- return rc;
-#else
- LOG_W("%s: %s", __func__, _WARNING_WITHOUT_FS);
- ptr->_errno = ENOTSUP;
- return -1;
-#endif /* DFS_USING_POSIX */
-}
-
-int _unlink_r(struct _reent *ptr, const char *file)
-{
-#ifdef DFS_USING_POSIX
- return unlink(file);
-#else
- LOG_W("%s: %s", __func__, _WARNING_WITHOUT_FS);
- ptr->_errno = ENOTSUP;
- return -1;
-#endif /* DFS_USING_POSIX */
-}
-
-_ssize_t _write_r(struct _reent *ptr, int fd, const void *buf, size_t nbytes)
-{
-#ifdef DFS_USING_POSIX
- _ssize_t rc;
-#endif /* DFS_USING_POSIX */
-
- if (fd == STDOUT_FILENO || fd == STDERR_FILENO)
- {
-#ifdef RT_USING_CONSOLE
- rt_device_t console;
-
- console = rt_console_get_device();
- if (console)
- return rt_device_write(console, -1, buf, nbytes);
-#else
- ptr->_errno = ENOTSUP;
- return -1;
-#endif /* RT_USING_CONSOLE */
- }
- else if (fd == STDIN_FILENO)
- {
- ptr->_errno = ENOTSUP;
- return -1;
- }
-
-#ifdef DFS_USING_POSIX
- rc = write(fd, buf, nbytes);
- return rc;
-#else
- LOG_W("%s: %s", __func__, _WARNING_WITHOUT_FS);
- ptr->_errno = ENOTSUP;
- return -1;
-#endif /* DFS_USING_POSIX */
-}
-
-/* for exit() and abort() */
-__attribute__ ((noreturn)) void _exit (int status)
-{
- extern void __rt_libc_exit(int status);
- __rt_libc_exit(status);
- while(1);
-}
-
/*
These functions are implemented and replaced by the 'common/time.c' file
int _gettimeofday_r(struct _reent *ptr, struct timeval *__tp, void *__tzp);
_CLOCK_T_ _times_r(struct _reent *ptr, struct tms *ptms);
*/
+
+#endif /* RT_USING_LIBC */
diff --git a/rt-thread/components/libc/compilers/gcc/newlib/legacy/SConscript b/rt-thread/components/libc/compilers/gcc/partial/SConscript
similarity index 100%
rename from rt-thread/components/libc/compilers/gcc/newlib/legacy/SConscript
rename to rt-thread/components/libc/compilers/gcc/partial/SConscript
diff --git a/rt-thread/components/libc/compilers/gcc/partial/mips/SConscript b/rt-thread/components/libc/compilers/gcc/partial/mips/SConscript
new file mode 100644
index 0000000..7651233
--- /dev/null
+++ b/rt-thread/components/libc/compilers/gcc/partial/mips/SConscript
@@ -0,0 +1,20 @@
+from shutil import copy
+from building import *
+
+Import('rtconfig')
+
+src = []
+cwd = GetCurrentDir()
+CPPPATH = [cwd]
+group = []
+
+if rtconfig.PLATFORM == 'gcc' and ('mips' in rtconfig.PREFIX): # identify mips gcc tool chain
+ try:
+ # There is no 'sys/select.h' in tthe mips gcc toolchain; it will be copied from 'nogcc/sys/select.h'
+ copy("../../../common/nogcc/sys/select.h", "./sys/select.h")
+ except:
+ pass
+
+ group = DefineGroup('libc', src, depend = [], CPPPATH = CPPPATH)
+
+Return('group')
diff --git a/rt-thread/components/libc/compilers/gcc/partial/mips/readme.md b/rt-thread/components/libc/compilers/gcc/partial/mips/readme.md
new file mode 100644
index 0000000..a3eeb06
--- /dev/null
+++ b/rt-thread/components/libc/compilers/gcc/partial/mips/readme.md
@@ -0,0 +1,4 @@
+These files don't exist in the mips gcc toolchain. They will be generated by scons automatically , and **DO NOT** change them:
+
+- sys/select.h
+
diff --git a/rt-thread/components/libc/compilers/gcc/newlib/legacy/_select/sys/select.h b/rt-thread/components/libc/compilers/gcc/partial/mips/sys/select.h
similarity index 85%
rename from rt-thread/components/libc/compilers/gcc/newlib/legacy/_select/sys/select.h
rename to rt-thread/components/libc/compilers/gcc/partial/mips/sys/select.h
index 44f9b4e..575ad3a 100644
--- a/rt-thread/components/libc/compilers/gcc/newlib/legacy/_select/sys/select.h
+++ b/rt-thread/components/libc/compilers/gcc/partial/mips/sys/select.h
@@ -6,7 +6,6 @@
* Change Logs:
* Date Author Notes
* 2021-07-21 Meco Man The first version
- * 2021-12-25 Meco Man Handle newlib 2.2.0 or lower version
*/
#ifndef __SYS_SELECT_H__
@@ -16,10 +15,6 @@
#include
#include
-#ifdef _WIN32
-#include
-#endif
-
#ifndef FD_SETSIZE
#define FD_SETSIZE 32
#endif
@@ -31,16 +26,16 @@
#define FD_SETSIZE DFS_FD_MAX
#endif /* SAL_USING_POSIX */
+#define NBBY 8 /* number of bits in a byte */
+
typedef long fd_mask;
-#ifndef _WIN32
-#ifndef _SYS_TYPES_FD_SET /* Newlib 2.2.0 or lower version */
-#define NBBY 8 /* number of bits in a byte */
#define NFDBITS (sizeof (fd_mask) * NBBY) /* bits per mask */
#ifndef howmany
#define howmany(x,y) (((x)+((y)-1))/(y))
-#endif /* howmany */
+#endif
+#ifndef _SYS_TYPES_FD_SET /* MIPS */
typedef struct _types_fd_set {
fd_mask fds_bits[howmany(FD_SETSIZE, NFDBITS)];
} _types_fd_set;
@@ -53,6 +48,5 @@ typedef struct _types_fd_set {
#endif /* _SYS_TYPES_FD_SET */
int select(int nfds, fd_set *readfds, fd_set *writefds, fd_set *exceptfds, struct timeval *timeout);
-#endif /* _WIN32 */
#endif /* __SYS_SELECT_H__ */
diff --git a/rt-thread/components/libc/compilers/gcc/partial/readme.md b/rt-thread/components/libc/compilers/gcc/partial/readme.md
new file mode 100644
index 0000000..959fc29
--- /dev/null
+++ b/rt-thread/components/libc/compilers/gcc/partial/readme.md
@@ -0,0 +1,2 @@
+This folder is for some particular targets.
+
diff --git a/rt-thread/components/libc/compilers/readme.md b/rt-thread/components/libc/compilers/readme.md
deleted file mode 100644
index e376cc7..0000000
--- a/rt-thread/components/libc/compilers/readme.md
+++ /dev/null
@@ -1 +0,0 @@
-This folder provides uniformed header files crossing different compiler platforms, and supports basic standard C library functions, such as memory management and time management, etc.
\ No newline at end of file
diff --git a/rt-thread/components/libc/getline/README.md b/rt-thread/components/libc/getline/README.md
new file mode 100644
index 0000000..ef3c19d
--- /dev/null
+++ b/rt-thread/components/libc/getline/README.md
@@ -0,0 +1,20 @@
+# getline/getdelim for RT-Thread POSIX(IEEE Std 1003.1-2008)
+
+[![Build Status](https://travis-ci.org/ivanrad/getline.svg?branch=master)](https://travis-ci.org/ivanrad/getline)
+
+https://github.com/ivanrad/getline
+
+Read a delimited record from stream.
+
+Yet another (hopefully portable C) implementation of getline/getdelim.
+These are ersatz functions, a drop-in replacement, to be used on those occasions when your C library does not already support them.
+
+For more details, see [Open Group Base Specification for getdelim/getline][opengroup-spec].
+
+
+
+## License
+
+This code is unlicensed -- free and released into the public domain. See `UNLICENSE` file for more information.
+
+[opengroup-spec]: http://pubs.opengroup.org/onlinepubs/9699919799/functions/getline.html
diff --git a/rt-thread/components/libc/getline/SConscript b/rt-thread/components/libc/getline/SConscript
new file mode 100644
index 0000000..fa4c861
--- /dev/null
+++ b/rt-thread/components/libc/getline/SConscript
@@ -0,0 +1,13 @@
+# 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_LIBC', 'RT_USING_POSIX','RT_USING_POSIX_GETLINE'],
+ CPPPATH = CPPPATH)
+
+Return('group')
diff --git a/rt-thread/components/libc/getline/UNLICENSE b/rt-thread/components/libc/getline/UNLICENSE
new file mode 100644
index 0000000..68a49da
--- /dev/null
+++ b/rt-thread/components/libc/getline/UNLICENSE
@@ -0,0 +1,24 @@
+This is free and unencumbered software released into the public domain.
+
+Anyone is free to copy, modify, publish, use, compile, sell, or
+distribute this software, either in source code form or as a compiled
+binary, for any purpose, commercial or non-commercial, and by any
+means.
+
+In jurisdictions that recognize copyright laws, the author or authors
+of this software dedicate any and all copyright interest in the
+software to the public domain. We make this dedication for the benefit
+of the public at large and to the detriment of our heirs and
+successors. We intend this dedication to be an overt act of
+relinquishment in perpetuity of all present and future rights to this
+software under copyright law.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
+IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR
+OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
+ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
+OTHER DEALINGS IN THE SOFTWARE.
+
+For more information, please refer to
diff --git a/rt-thread/components/libc/getline/posix_getline.c b/rt-thread/components/libc/getline/posix_getline.c
new file mode 100644
index 0000000..da80242
--- /dev/null
+++ b/rt-thread/components/libc/getline/posix_getline.c
@@ -0,0 +1,78 @@
+/* posix_getline.c
+ * RT-Thread POSIX
+ * getdelim(), getline() - read a delimited record from stream, ersatz implementation
+ * This code is unlicensed -- free and released into the public domain.
+ * https://man7.org/linux/man-pages/man3/getline.3.html
+ * Authors:
+ * https://github.com/ivanrad/getline
+ *
+ * Meco Man 2020-09-03 porting to RT-Thread
+ */
+
+#include "posix_getline.h"
+#include
+#include
+#include
+
+ssize_t getdelim(char **lineptr, size_t *n, int delim, FILE *stream) {
+ char *cur_pos, *new_lineptr;
+ size_t new_lineptr_len;
+ int c;
+
+ if (lineptr == NULL || n == NULL || stream == NULL) {
+ errno = EINVAL;
+ return -1;
+ }
+
+ if (*lineptr == NULL) {
+ *n = 128; /* init len */
+ if ((*lineptr = (char *)malloc(*n)) == NULL) {
+ errno = ENOMEM;
+ return -1;
+ }
+ }
+
+ cur_pos = *lineptr;
+ for (;;) {
+ c = getc(stream);
+
+ if (ferror(stream) || (c == EOF && cur_pos == *lineptr))
+ return -1;
+
+ if (c == EOF)
+ break;
+
+ if ((*lineptr + *n - cur_pos) < 2) {
+ if (LONG_MAX / 2 < *n) {
+#ifdef EOVERFLOW
+ errno = EOVERFLOW;
+#else
+ errno = ERANGE; /* no EOVERFLOW defined */
+#endif
+ return -1;
+ }
+ new_lineptr_len = *n * 2;
+
+ if ((new_lineptr = (char *)realloc(*lineptr, new_lineptr_len)) == NULL) {
+ errno = ENOMEM;
+ return -1;
+ }
+ cur_pos = new_lineptr + (cur_pos - *lineptr);
+ *lineptr = new_lineptr;
+ *n = new_lineptr_len;
+ }
+
+ *cur_pos++ = (char)c;
+
+ if (c == delim)
+ break;
+ }
+
+ *cur_pos = '\0';
+ return (ssize_t)(cur_pos - *lineptr);
+}
+
+ssize_t getline(char **lineptr, size_t *n, FILE *stream) {
+ return getdelim(lineptr, n, '\n', stream);
+}
+
diff --git a/rt-thread/components/libc/getline/posix_getline.h b/rt-thread/components/libc/getline/posix_getline.h
new file mode 100644
index 0000000..13a4487
--- /dev/null
+++ b/rt-thread/components/libc/getline/posix_getline.h
@@ -0,0 +1,23 @@
+/* posix_getline.h
+ * RT-Thread POSIX
+ * getdelim(), getline() - read a delimited record from stream, ersatz implementation
+ * This code is unlicensed -- free and released into the public domain.
+ * https://man7.org/linux/man-pages/man3/getline.3.html
+ * Authors:
+ * https://github.com/ivanrad/getline
+ *
+ * Meco Man 2020-09-03 porting to RT-Thread
+ */
+
+
+#ifndef POSIX_GETLINE_H
+#define POSIX_GETLINE_H
+
+#include
+#include
+
+ssize_t getdelim(char **lineptr, size_t *n, int delim, FILE *stream);
+ssize_t getline(char **lineptr, size_t *n, FILE *stream);
+
+#endif /* POSIX_GETLINE_H */
+
diff --git a/rt-thread/components/libc/libdl/arch/riscv.c b/rt-thread/components/libc/libdl/arch/riscv.c
index c7c454e..33cae28 100644
--- a/rt-thread/components/libc/libdl/arch/riscv.c
+++ b/rt-thread/components/libc/libdl/arch/riscv.c
@@ -1,12 +1,12 @@
/*
- * Copyright (c) 2006-2021, RT-Thread Development Team
+ * Copyright (c) 2006-2018, RT-Thread Development Team
*
* SPDX-License-Identifier: Apache-2.0
- *
+ *
* Change Logs:
* Date Author Notes
* 2021/04/23 chunyexixiaoyu first version
-
+
*/
#include "../dlmodule.h"
@@ -31,7 +31,7 @@ int dlmodule_relocate(struct rt_dlmodule *module, Elf_Rel *rel, Elf_Addr sym_val
Elf64_Addr *where, tmp;
Elf64_Sword addend, offset;
rt_uint64_t upper, lower, sign, j1, j2;
-
+
where = (Elf64_Addr *)((rt_uint8_t *)module->mem_space
+ rel->r_offset
- module->vstart_addr);
@@ -50,7 +50,7 @@ int dlmodule_relocate(struct rt_dlmodule *module, Elf_Rel *rel, Elf_Addr sym_val
case R_RISCV_JUMP_SLOT:
*where = (Elf64_Addr)sym_val;
RT_DEBUG_LOG(RT_DEBUG_MODULE, ("R_RISCV_JUMP_SLOT: %x -> %x\n",where, *where));
- break;
+ break;
default:
RT_DEBUG_LOG(RT_DEBUG_MODULE, ("__riscv__ELF: invalid relocate TYPE %d\n", ELF64_R_TYPE(rel->r_info)));
return -1;
diff --git a/rt-thread/components/libc/posix/signal/SConscript b/rt-thread/components/libc/mmap/SConscript
similarity index 66%
rename from rt-thread/components/libc/posix/signal/SConscript
rename to rt-thread/components/libc/mmap/SConscript
index 9c712fa..1a36a15 100644
--- a/rt-thread/components/libc/posix/signal/SConscript
+++ b/rt-thread/components/libc/mmap/SConscript
@@ -6,8 +6,8 @@ cwd = GetCurrentDir()
src = Glob('*.c') + Glob('*.cpp')
CPPPATH = [cwd]
-group = DefineGroup('POSIX', src,
- depend = ['RT_USING_SIGNALS', 'RT_USING_PTHREADS'],
+group = DefineGroup('libc', src,
+ depend = ['RT_USING_DFS', 'RT_USING_POSIX_MMAP'],
CPPPATH = CPPPATH)
Return('group')
diff --git a/rt-thread/components/libc/posix/io/mman/mman.c b/rt-thread/components/libc/mmap/posix_mmap.c
similarity index 98%
rename from rt-thread/components/libc/posix/io/mman/mman.c
rename to rt-thread/components/libc/mmap/posix_mmap.c
index 827f2cb..e68b82e 100644
--- a/rt-thread/components/libc/posix/io/mman/mman.c
+++ b/rt-thread/components/libc/mmap/posix_mmap.c
@@ -14,7 +14,7 @@
#include
#include