更改系统分支为4.0.x分支
parent
5bf7f6a0a8
commit
752b91920a
|
@ -1,8 +1,6 @@
|
||||||
<p align="center">
|
# RT-Thread #
|
||||||
<img src="documentation/figures/logo.png" width="60%" >
|
|
||||||
</p>
|
|
||||||
|
|
||||||
**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](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)
|
[![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)
|
[![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)
|
[![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
|
## RT-Thread Architecture
|
||||||
|
|
||||||
|
@ -33,18 +31,21 @@ It includes:
|
||||||
|
|
||||||
- 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.
|
- 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.
|
- 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
|
## RT-Thread Features
|
||||||
|
|
||||||
- Designed for resource-constrained devices, the minimum kernel requires only 1.2KB of RAM and 3 KB of Flash.
|
- 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.
|
- Has rich components and a prosperous and fast growing package ecosystem.
|
||||||
|
|
||||||
- Elegant code style, easy to use, read and master.
|
- 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.
|
- High Scalability. RT-Thread has high-quality scalable software architecture, loose coupling, modularity, is easy to tailor and expand.
|
||||||
|
|
||||||
- Supports high-performance applications.
|
- Supports high-performance applications.
|
||||||
- Supports all mainstream compiling tools such as GCC, Keil and IAR.
|
|
||||||
- Supports a wide range of <a href="https://www.rt-thread.io/board.html">architectures and chips</a>.
|
- Supports cross-platform and a wide range of chips.
|
||||||
|
|
||||||
## Code Catalogue
|
## Code Catalogue
|
||||||
|
|
||||||
|
@ -61,7 +62,12 @@ It includes:
|
||||||
| src | The source files for the RT-Thread kernel. |
|
| src | The source files for the RT-Thread kernel. |
|
||||||
| tools | The script files for the RT-Thread command build tool. |
|
| 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
|
# 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-M4**:manufacturers like ST、Nuvton、NXP、GigaDevice、Realtek、Ambiq Micro, ect.
|
||||||
- **ARM Cortex-M7**:manufacturers like ST、NXP
|
- **ARM Cortex-M7**:manufacturers like ST、NXP
|
||||||
- **ARM Cortex-M23**:manufacturers like GigaDevice
|
- **ARM Cortex-M23**:manufacturers like GigaDevice
|
||||||
- **ARM Cortex-M33**:manufacturers like ST
|
|
||||||
- **ARM Cortex-R4**
|
- **ARM Cortex-R4**
|
||||||
- **ARM Cortex-A8/A9**:manufacturers like NXP
|
- **ARM Cortex-A8/A9**:manufacturers like NXP
|
||||||
- **ARM7**:manufacturers like Samsung
|
- **ARM7**:manufacturers like Samsung
|
||||||
- **ARM9**:manufacturers like Allwinner、Xilinx 、GOKE
|
- **ARM9**:manufacturers like Allwinner、Xilinx 、GOKE
|
||||||
- **ARM11**:manufacturers like Fullhan
|
- **ARM11**:manufacturers like Fullhan
|
||||||
- **MIPS32**:manufacturers like loongson、Ingenic
|
- **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
|
- **ARC**:manufacturers like SYNOPSYS
|
||||||
- **DSP**:manufacturers like TI
|
- **DSP**:manufacturers like TI
|
||||||
- **C-Sky**
|
- **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:
|
The main IDE/compilers supported by RT-Thread are:
|
||||||
|
|
||||||
- RT-Thread Studio IDE
|
|
||||||
- MDK KEIL
|
- MDK KEIL
|
||||||
- IAR
|
- IAR
|
||||||
- GCC
|
- 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
|
## Getting Started
|
||||||
|
|
||||||
[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
|
|
||||||
|
|
||||||
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.
|
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
|
# 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
|
# 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
|
# 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).
|
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).
|
||||||
|
|
||||||
|
|
|
@ -68,21 +68,35 @@ Env 是RT-Thread推出的开发辅助工具,针对基于RT-Thread操作系统
|
||||||
RT-Thread RTOS 支持许多架构,并且已经涵盖了当前应用中的主要架构。涉及的架构和芯片制造商有:
|
RT-Thread RTOS 支持许多架构,并且已经涵盖了当前应用中的主要架构。涉及的架构和芯片制造商有:
|
||||||
|
|
||||||
- ARM Cortex-M0/M0+:如芯片制造商 ST
|
- ARM Cortex-M0/M0+:如芯片制造商 ST
|
||||||
|
|
||||||
- ARM Cortex-M3:如芯片制造商 ST、全志、灵动等.
|
- ARM Cortex-M3:如芯片制造商 ST、全志、灵动等.
|
||||||
|
|
||||||
- ARM Cortex-M4:如芯片制造商 ST、Nuvton、NXP、GigaDevice、Realtek、Ambiq Micro等
|
- ARM Cortex-M4:如芯片制造商 ST、Nuvton、NXP、GigaDevice、Realtek、Ambiq Micro等
|
||||||
|
|
||||||
- ARM Cortex-M7:如芯片制造商 ST、NXP
|
- ARM Cortex-M7:如芯片制造商 ST、NXP
|
||||||
|
|
||||||
- ARM Cortex-M23:如芯片制造商 GigaDevice
|
- ARM Cortex-M23:如芯片制造商 GigaDevice
|
||||||
- ARM Cortex-M33:如芯片制造商 ST
|
|
||||||
- ARM Cortex-R4
|
- ARM Cortex-R4
|
||||||
|
|
||||||
- ARM Cortex-A8/A9:如芯片制造商 NXP
|
- ARM Cortex-A8/A9:如芯片制造商 NXP
|
||||||
|
|
||||||
- ARM7:如芯片制造商Samsung
|
- ARM7:如芯片制造商Samsung
|
||||||
|
|
||||||
- ARM9:如芯片制造商Allwinner、Xilinx 、GOKE
|
- ARM9:如芯片制造商Allwinner、Xilinx 、GOKE
|
||||||
|
|
||||||
- ARM11:如芯片制造商Fullhan
|
- ARM11:如芯片制造商Fullhan
|
||||||
|
|
||||||
- MIPS32:如芯片制造商loongson、Ingenic
|
- MIPS32:如芯片制造商loongson、Ingenic
|
||||||
|
|
||||||
- RISC-V:如芯片制造商Hifive、Kendryte、[芯来Nuclei](https://nucleisys.com/)
|
- RISC-V:如芯片制造商Hifive、Kendryte、[芯来Nuclei](https://nucleisys.com/)
|
||||||
|
|
||||||
- ARC:如芯片制造商SYNOPSYS
|
- ARC:如芯片制造商SYNOPSYS
|
||||||
|
|
||||||
- DSP:如芯片制造商 TI
|
- DSP:如芯片制造商 TI
|
||||||
|
|
||||||
- C-Sky
|
- C-Sky
|
||||||
|
|
||||||
- x86
|
- x86
|
||||||
|
|
||||||
|
|
||||||
|
@ -155,7 +169,7 @@ RT-Thread非常感谢所有社区小伙伴的支持,在使用RT-Thread的过
|
||||||
|
|
||||||
RT-Thread微信公众号:
|
RT-Thread微信公众号:
|
||||||
|
|
||||||
![qrcode](./documentation/figures/qrcode.jpg)
|
![qrcode](./documentation/figures/qrcode.png)
|
||||||
|
|
||||||
|
|
||||||
# 贡献代码
|
# 贡献代码
|
||||||
|
|
|
@ -19,10 +19,6 @@ config RT_USING_USER_MAIN
|
||||||
default 85 if RT_THREAD_PRIORITY_256
|
default 85 if RT_THREAD_PRIORITY_256
|
||||||
endif
|
endif
|
||||||
|
|
||||||
config RT_USING_LEGACY
|
|
||||||
bool "Support legacy version for compatibility"
|
|
||||||
default n
|
|
||||||
|
|
||||||
source "$RTT_DIR/components/cplusplus/Kconfig"
|
source "$RTT_DIR/components/cplusplus/Kconfig"
|
||||||
|
|
||||||
source "$RTT_DIR/components/finsh/Kconfig"
|
source "$RTT_DIR/components/finsh/Kconfig"
|
||||||
|
|
|
@ -9,8 +9,8 @@ if RT_USING_CPLUSPLUS
|
||||||
config RT_USING_CPLUSPLUS11
|
config RT_USING_CPLUSPLUS11
|
||||||
bool "Enable c++11 threading feature support"
|
bool "Enable c++11 threading feature support"
|
||||||
default n
|
default n
|
||||||
select RT_USING_POSIX_FS
|
select RT_USING_LIBC
|
||||||
select RT_USING_POSIX_STDIO
|
select RT_USING_DFS
|
||||||
select RT_USING_PTHREADS
|
select RT_USING_PTHREADS
|
||||||
select RT_USING_RTC
|
select RT_USING_RTC
|
||||||
|
|
||||||
|
|
|
@ -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.
|
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.
|
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
|
About GNU GCC compiler
|
||||||
|
|
||||||
please add following string in your ld link script:
|
please add following string in your ld link script:
|
||||||
|
|
|
@ -13,18 +13,19 @@
|
||||||
#include <cstdio>
|
#include <cstdio>
|
||||||
#include <pthread.h>
|
#include <pthread.h>
|
||||||
|
|
||||||
#define CPP11_DEFAULT_ID_OFFSET 1
|
|
||||||
|
|
||||||
extern "C" int __ARM_TPL_thread_create(__ARM_TPL_thread_t *__t,
|
extern "C" int __ARM_TPL_thread_create(__ARM_TPL_thread_t *__t,
|
||||||
void *(*__func)(void *),
|
void *(*__func)(void *),
|
||||||
void *__arg)
|
void *__arg)
|
||||||
{
|
{
|
||||||
int ret = 0;
|
int ret = 0;
|
||||||
pthread_t pid;
|
/* TODO memory leek */
|
||||||
ret = pthread_create(&pid, RT_NULL, __func, __arg);
|
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)
|
if (ret == 0)
|
||||||
{
|
{
|
||||||
__t->data = (std::uintptr_t)pid + CPP11_DEFAULT_ID_OFFSET;
|
__t->data = (std::uintptr_t)pid;
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
return -1;
|
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(
|
extern "C" __ARM_TPL_thread_id __ARM_TPL_thread_get_id(
|
||||||
const __ARM_TPL_thread_t *__t)
|
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)
|
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;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
extern "C" int __ARM_TPL_thread_detach(__ARM_TPL_thread_t *__t)
|
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;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -4,7 +4,7 @@
|
||||||
#error "C++ version lower than C++11"
|
#error "C++ version lower than C++11"
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
//#if defined(RT_USING_PTHREADS)
|
//#if defined(RT_USING_LIBC) && defined(RT_USING_PTHREADS)
|
||||||
|
|
||||||
#include <pthread.h>
|
#include <pthread.h>
|
||||||
|
|
||||||
|
@ -509,4 +509,4 @@ namespace std
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
//#endif //(RT_USING_PTHREADS)
|
//#endif // (RT_USING_LIBC) && (RT_USING_PTHREADS)
|
|
@ -4,7 +4,7 @@
|
||||||
#error "C++ version lower than C++11"
|
#error "C++ version lower than C++11"
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
//#if defined(RT_USING_PTHREADS)
|
//#if defined(RT_USING_LIBC) && defined(RT_USING_PTHREADS)
|
||||||
|
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
#include <pthread.h>
|
#include <pthread.h>
|
||||||
|
|
|
@ -13,7 +13,7 @@ using namespace rtthread;
|
||||||
|
|
||||||
Mutex::Mutex(const char *name)
|
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)
|
bool Mutex::lock(int32_t millisec)
|
||||||
|
|
|
@ -13,7 +13,7 @@
|
||||||
|
|
||||||
#include <rtthread.h>
|
#include <rtthread.h>
|
||||||
|
|
||||||
#if defined(__ARMCC_VERSION)
|
#if defined(__CC_ARM) || defined(__CLANG_ARM)
|
||||||
extern void $Super$$__cpp_initialize__aeabi_(void);
|
extern void $Super$$__cpp_initialize__aeabi_(void);
|
||||||
/* we need to change the cpp_initialize order */
|
/* we need to change the cpp_initialize order */
|
||||||
RT_WEAK void $Sub$$__cpp_initialize__aeabi_(void)
|
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)
|
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
|
/* If there is no SHT$$INIT_ARRAY, calling
|
||||||
* $Super$$__cpp_initialize__aeabi_() will cause fault. At least until Keil5.12
|
* $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.
|
* the problem still exists. So we have to initialize the C++ runtime by ourself.
|
||||||
|
|
|
@ -8,10 +8,6 @@ config RT_USING_DFS
|
||||||
The device file system is a light weight virtual file system.
|
The device file system is a light weight virtual file system.
|
||||||
|
|
||||||
if RT_USING_DFS
|
if RT_USING_DFS
|
||||||
config DFS_USING_POSIX
|
|
||||||
bool "Using posix-like functions, open/read/write/close"
|
|
||||||
default y
|
|
||||||
|
|
||||||
config DFS_USING_WORKDIR
|
config DFS_USING_WORKDIR
|
||||||
bool "Using working directory"
|
bool "Using working directory"
|
||||||
default y
|
default y
|
||||||
|
@ -137,7 +133,7 @@ if RT_USING_DFS
|
||||||
|
|
||||||
config RT_USING_DFS_DEVFS
|
config RT_USING_DFS_DEVFS
|
||||||
bool "Using devfs for device objects"
|
bool "Using devfs for device objects"
|
||||||
default n
|
default y
|
||||||
|
|
||||||
config RT_USING_DFS_ROMFS
|
config RT_USING_DFS_ROMFS
|
||||||
bool "Enable ReadOnly file system on flash"
|
bool "Enable ReadOnly file system on flash"
|
||||||
|
|
|
@ -1,17 +1,17 @@
|
||||||
from building import *
|
from building import *
|
||||||
import os
|
|
||||||
|
|
||||||
# The set of source files associated with this SConscript file.
|
# The set of source files associated with this SConscript file.
|
||||||
src = Split('''
|
src = Split('''
|
||||||
src/dfs.c
|
src/dfs.c
|
||||||
src/dfs_file.c
|
src/dfs_file.c
|
||||||
src/dfs_fs.c
|
src/dfs_fs.c
|
||||||
|
src/dfs_posix.c
|
||||||
''')
|
''')
|
||||||
cwd = GetCurrentDir()
|
cwd = GetCurrentDir()
|
||||||
CPPPATH = [cwd + "/include"]
|
CPPPATH = [cwd + "/include"]
|
||||||
|
|
||||||
if GetDepend('DFS_USING_POSIX'):
|
if GetDepend('RT_USING_POSIX'):
|
||||||
src += ['src/dfs_posix.c']
|
src += ['src/dfs_poll.c', 'src/dfs_select.c']
|
||||||
|
|
||||||
group = DefineGroup('Filesystem', src, depend = ['RT_USING_DFS'], CPPPATH = CPPPATH)
|
group = DefineGroup('Filesystem', src, depend = ['RT_USING_DFS'], CPPPATH = CPPPATH)
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,4 @@
|
||||||
|
# files format check exclude path, please follow the instructions below to modify;
|
||||||
|
|
||||||
|
dir_path:
|
||||||
|
- elmfat
|
|
@ -173,7 +173,7 @@ int dfs_device_fs_open(struct dfs_fd *file)
|
||||||
if (device == RT_NULL)
|
if (device == RT_NULL)
|
||||||
return -ENODEV;
|
return -ENODEV;
|
||||||
|
|
||||||
#ifdef RT_USING_POSIX_DEVIO
|
#ifdef RT_USING_POSIX
|
||||||
if (device->fops)
|
if (device->fops)
|
||||||
{
|
{
|
||||||
/* use device fops */
|
/* use device fops */
|
||||||
|
@ -192,7 +192,7 @@ int dfs_device_fs_open(struct dfs_fd *file)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
#endif /* RT_USING_POSIX_DEVIO */
|
#endif
|
||||||
{
|
{
|
||||||
result = rt_device_open(device, RT_DEVICE_OFLAG_RDWR);
|
result = rt_device_open(device, RT_DEVICE_OFLAG_RDWR);
|
||||||
if (result == RT_EOK || result == -RT_ENOSYS)
|
if (result == RT_EOK || result == -RT_ENOSYS)
|
||||||
|
|
|
@ -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_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)
|
Fixed f_mkfs() function can fail to create exFAT volume in the second partition. (appeared at R0.12)
|
||||||
|
|
||||||
|
|
||||||
R0.14a (December 5, 2020)
|
|
||||||
Limited number of recursive calls in f_findnext().
|
|
||||||
Fixed old floppy disks formatted with MS-DOS 2.x and 3.x cannot be mounted.
|
|
||||||
Fixed some compiler warnings.
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
R0.14b (April 17, 2021)
|
|
||||||
Made FatFs uses standard library <string.h> for copy, compare and search instead of built-in string functions.
|
|
||||||
Added support for long long integer and floating point to f_printf(). (FF_STRF_LLI and FF_STRF_FP)
|
|
||||||
Made path name parser ignore the terminating separator to allow "dir/".
|
|
||||||
Improved the compatibility in Unix style path name feature.
|
|
||||||
Fixed the file gets dead-locked when f_open() failed with some conditions. (appeared at R0.12a)
|
|
||||||
Fixed f_mkfs() can create wrong exFAT volume due to a timing dependent error. (appeared at R0.12)
|
|
||||||
Fixed code page 855 cannot be set by f_setcp().
|
|
||||||
Fixed some compiler warnings.
|
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
FatFs Module Source Files R0.14b
|
FatFs Module Source Files R0.14
|
||||||
|
|
||||||
|
|
||||||
FILES
|
FILES
|
||||||
|
|
|
@ -945,6 +945,7 @@ DWORD get_fattime(void)
|
||||||
{
|
{
|
||||||
DWORD fat_time = 0;
|
DWORD fat_time = 0;
|
||||||
|
|
||||||
|
#if defined(RT_LIBC_USING_TIME) || defined(RT_USING_LIBC)
|
||||||
time_t now;
|
time_t now;
|
||||||
struct tm *p_tm;
|
struct tm *p_tm;
|
||||||
struct tm tm_now;
|
struct tm tm_now;
|
||||||
|
@ -967,6 +968,7 @@ DWORD get_fattime(void)
|
||||||
(DWORD)tm_now.tm_hour << 11 |
|
(DWORD)tm_now.tm_hour << 11 |
|
||||||
(DWORD)tm_now.tm_min << 5 |
|
(DWORD)tm_now.tm_min << 5 |
|
||||||
(DWORD)tm_now.tm_sec / 2 ;
|
(DWORD)tm_now.tm_sec / 2 ;
|
||||||
|
#endif /* defined(RT_LIBC_USING_TIME) || defined(RT_USING_LIBC) */
|
||||||
|
|
||||||
return fat_time;
|
return fat_time;
|
||||||
}
|
}
|
||||||
|
@ -978,7 +980,7 @@ int ff_cre_syncobj(BYTE drv, FF_SYNC_t *m)
|
||||||
rt_mutex_t mutex;
|
rt_mutex_t mutex;
|
||||||
|
|
||||||
rt_snprintf(name, sizeof(name), "fat%d", drv);
|
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)
|
if (mutex != RT_NULL)
|
||||||
{
|
{
|
||||||
*m = mutex;
|
*m = mutex;
|
||||||
|
|
File diff suppressed because it is too large
Load Diff
|
@ -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
|
/ FatFs module is an open source software. Redistribution and use of FatFs in
|
||||||
/ source and binary forms, with or without modification, are permitted provided
|
/ source and binary forms, with or without modification, are permitted provided
|
||||||
|
@ -20,7 +20,7 @@
|
||||||
|
|
||||||
|
|
||||||
#ifndef FF_DEFINED
|
#ifndef FF_DEFINED
|
||||||
#define FF_DEFINED 86631 /* Revision ID */
|
#define FF_DEFINED 86606 /* Revision ID */
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
extern "C" {
|
extern "C" {
|
||||||
|
@ -36,14 +36,10 @@ extern "C" {
|
||||||
|
|
||||||
/* Integer types used for FatFs API */
|
/* Integer types used for FatFs API */
|
||||||
|
|
||||||
#if defined(_WIN32) /* Windows VC++ (for development only) */
|
#if defined(_WIN32) /* Main development platform */
|
||||||
#define FF_INTDEF 2
|
#define FF_INTDEF 2
|
||||||
#include <windows.h>
|
#include <windows.h>
|
||||||
typedef unsigned __int64 QWORD;
|
typedef unsigned __int64 QWORD;
|
||||||
#include <float.h>
|
|
||||||
#define isnan(v) _isnan(v)
|
|
||||||
#define isinf(v) (!_finite(v))
|
|
||||||
|
|
||||||
#elif (defined(__STDC_VERSION__) && __STDC_VERSION__ >= 199901L) || defined(__cplusplus) /* C99 or later */
|
#elif (defined(__STDC_VERSION__) && __STDC_VERSION__ >= 199901L) || defined(__cplusplus) /* C99 or later */
|
||||||
#define FF_INTDEF 2
|
#define FF_INTDEF 2
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
|
@ -53,7 +49,6 @@ typedef uint16_t WORD; /* 16-bit unsigned integer */
|
||||||
typedef uint32_t DWORD; /* 32-bit unsigned integer */
|
typedef uint32_t DWORD; /* 32-bit unsigned integer */
|
||||||
typedef uint64_t QWORD; /* 64-bit unsigned integer */
|
typedef uint64_t QWORD; /* 64-bit unsigned integer */
|
||||||
typedef WORD WCHAR; /* UTF-16 character type */
|
typedef WORD WCHAR; /* UTF-16 character type */
|
||||||
|
|
||||||
#else /* Earlier than C99 */
|
#else /* Earlier than C99 */
|
||||||
#define FF_INTDEF 1
|
#define FF_INTDEF 1
|
||||||
typedef unsigned int UINT; /* int must be 16-bit or 32-bit */
|
typedef unsigned int UINT; /* int must be 16-bit or 32-bit */
|
||||||
|
@ -64,29 +59,28 @@ typedef WORD WCHAR; /* UTF-16 character type */
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
||||||
/* Type of file size and LBA variables */
|
/* Definitions of volume management */
|
||||||
|
|
||||||
#if FF_FS_EXFAT
|
#if FF_MULTI_PARTITION /* Multiple partition configuration */
|
||||||
#if FF_INTDEF != 2
|
typedef struct {
|
||||||
#error exFAT feature wants C99 or later
|
BYTE pd; /* Physical drive number */
|
||||||
|
BYTE pt; /* Partition: 0:Auto detect, 1-4:Forced partition) */
|
||||||
|
} PARTITION;
|
||||||
|
extern PARTITION VolToPart[]; /* Volume - Partition mapping table */
|
||||||
#endif
|
#endif
|
||||||
typedef QWORD FSIZE_t;
|
|
||||||
#if FF_LBA64
|
#if FF_STR_VOLUME_ID
|
||||||
typedef QWORD LBA_t;
|
#ifndef FF_VOLUME_STRS
|
||||||
#else
|
extern const char* VolumeStr[FF_VOLUMES]; /* User defied volume ID */
|
||||||
typedef DWORD LBA_t;
|
|
||||||
#endif
|
#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
|
#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 */
|
#if FF_USE_LFN && FF_LFN_UNICODE == 1 /* Unicode in UTF-16 encoding */
|
||||||
typedef WCHAR TCHAR;
|
typedef WCHAR TCHAR;
|
||||||
|
@ -108,22 +102,28 @@ typedef char TCHAR;
|
||||||
#define _TEXT(x) x
|
#define _TEXT(x) x
|
||||||
#endif
|
#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
|
#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
|
#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
|
#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_rmdir(path) f_unlink(path)
|
||||||
#define f_unmount(path) f_mount(0, path, 0)
|
#define f_unmount(path) f_mount(0, path, 0)
|
||||||
|
|
||||||
|
#ifndef EOF
|
||||||
|
#define EOF (-1)
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -2,7 +2,7 @@
|
||||||
/ FatFs Functional Configurations
|
/ FatFs Functional Configurations
|
||||||
/---------------------------------------------------------------------------*/
|
/---------------------------------------------------------------------------*/
|
||||||
|
|
||||||
#define FFCONF_DEF 86631 /* Revision ID */
|
#define FFCONF_DEF 86606 /* Revision ID */
|
||||||
|
|
||||||
/*---------------------------------------------------------------------------/
|
/*---------------------------------------------------------------------------/
|
||||||
/ Function Configurations
|
/ Function Configurations
|
||||||
|
@ -25,6 +25,14 @@
|
||||||
/ 3: f_lseek() function is removed in addition to 2. */
|
/ 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
|
#define FF_USE_FIND 0
|
||||||
/* This option switches filtered directory read functions, f_findfirst() and
|
/* This option switches filtered directory read functions, f_findfirst() and
|
||||||
/ f_findnext(). (0:Disable, 1:Enable 2:Enable with matching altname[] too) */
|
/ 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) */
|
/* 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
|
/ Locale and Namespace Configurations
|
||||||
/---------------------------------------------------------------------------*/
|
/---------------------------------------------------------------------------*/
|
||||||
|
@ -156,16 +140,6 @@
|
||||||
#else
|
#else
|
||||||
#define FF_LFN_UNICODE 0 /* 0:ANSI/OEM or 1:Unicode */
|
#define FF_LFN_UNICODE 0 /* 0:ANSI/OEM or 1:Unicode */
|
||||||
#endif
|
#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_LFN_BUF 255
|
||||||
#define FF_SFN_BUF 12
|
#define FF_SFN_BUF 12
|
||||||
|
@ -175,6 +149,19 @@
|
||||||
/ on character encoding. When LFN is not enabled, these options have no effect. */
|
/ 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
|
#define FF_FS_RPATH 0
|
||||||
/* This option configures support for relative path.
|
/* This option configures support for relative path.
|
||||||
/
|
/
|
||||||
|
@ -227,7 +214,7 @@
|
||||||
#endif
|
#endif
|
||||||
/* This set of options configures the range of sector size to be supported. (512,
|
/* 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
|
/ 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
|
/ 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
|
/ for variable sector size mode and disk_ioctl() function needs to implement
|
||||||
/ GET_SECTOR_SIZE command. */
|
/ GET_SECTOR_SIZE command. */
|
||||||
|
@ -238,8 +225,8 @@
|
||||||
/ To enable the 64-bit LBA, also exFAT needs to be enabled. (FF_FS_EXFAT == 1) */
|
/ To enable the 64-bit LBA, also exFAT needs to be enabled. (FF_FS_EXFAT == 1) */
|
||||||
|
|
||||||
|
|
||||||
#define FF_MIN_GPT 0x10000000
|
#define FF_MIN_GPT 0x100000000
|
||||||
/* Minimum number of sectors to switch GPT as partitioning format in f_mkfs and
|
/* 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. */
|
/ 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_FS_NORTC 0
|
||||||
#define FF_NORTC_MON 1
|
#define FF_NORTC_MON 1
|
||||||
#define FF_NORTC_MDAY 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
|
/* 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
|
/ 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
|
/ 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
|
/ can be opened simultaneously under file lock control. Note that the file
|
||||||
/ lock control is independent of re-entrancy. */
|
/ lock control is independent of re-entrancy. */
|
||||||
|
|
||||||
|
|
||||||
/* #include <somertos.h> // O/S definitions */
|
/* #include <somertos.h> // O/S definitions */
|
||||||
#include <rtdef.h>
|
#include <rtdef.h>
|
||||||
#ifdef RT_DFS_ELM_REENTRANT
|
#ifdef RT_DFS_ELM_REENTRANT
|
||||||
|
|
|
@ -81,18 +81,16 @@ int dfs_init(void);
|
||||||
char *dfs_normalize_path(const char *directory, const char *filename);
|
char *dfs_normalize_path(const char *directory, const char *filename);
|
||||||
const char *dfs_subdir(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_lock(void);
|
||||||
void dfs_unlock(void);
|
void dfs_unlock(void);
|
||||||
|
|
||||||
#ifdef DFS_USING_POSIX
|
|
||||||
/* FD APIs */
|
/* FD APIs */
|
||||||
int fd_new(void);
|
int fd_new(void);
|
||||||
struct dfs_fd *fd_get(int fd);
|
struct dfs_fd *fd_get(int fd);
|
||||||
void fd_put(struct dfs_fd *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
|
#ifdef __cplusplus
|
||||||
}
|
}
|
||||||
|
|
|
@ -12,9 +12,10 @@
|
||||||
#define __DFS_FS_H__
|
#define __DFS_FS_H__
|
||||||
|
|
||||||
#include <dfs.h>
|
#include <dfs.h>
|
||||||
|
#ifdef RT_USING_LIBC
|
||||||
#include <sys/types.h>
|
#include <sys/types.h>
|
||||||
|
#endif
|
||||||
#include <sys/errno.h>
|
#include <sys/errno.h>
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
extern "C" {
|
extern "C" {
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -5,7 +5,6 @@
|
||||||
*
|
*
|
||||||
* Change Logs:
|
* Change Logs:
|
||||||
* Date Author Notes
|
* Date Author Notes
|
||||||
* 2021-11-14 Meco Man the first version
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#ifndef DFS_POLL_H__
|
#ifndef DFS_POLL_H__
|
|
@ -5,7 +5,6 @@
|
||||||
*
|
*
|
||||||
* Change Logs:
|
* Change Logs:
|
||||||
* Date Author Notes
|
* Date Author Notes
|
||||||
* 2021-11-14 Meco Man the first version
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#ifndef DFS_SELECT_H__
|
#ifndef DFS_SELECT_H__
|
||||||
|
@ -13,4 +12,4 @@
|
||||||
|
|
||||||
#include <sys/select.h>
|
#include <sys/select.h>
|
||||||
|
|
||||||
#endif /* DFS_SELECT_H__ */
|
#endif
|
|
@ -18,9 +18,9 @@
|
||||||
#include <lwp.h>
|
#include <lwp.h>
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef RT_USING_POSIX_STDIO
|
#if defined(RT_USING_DFS_DEVFS) && defined(RT_USING_POSIX)
|
||||||
#include <libc.h>
|
#include <libc.h>
|
||||||
#endif /* RT_USING_POSIX_STDIO */
|
#endif
|
||||||
|
|
||||||
/* Global variables */
|
/* Global variables */
|
||||||
const struct dfs_filesystem_ops *filesystem_operation_table[DFS_FILESYSTEM_TYPES_MAX];
|
const struct dfs_filesystem_ops *filesystem_operation_table[DFS_FILESYSTEM_TYPES_MAX];
|
||||||
|
@ -34,6 +34,7 @@ char working_directory[DFS_PATH_MAX] = {"/"};
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
static struct dfs_fdtable _fdtab;
|
static struct dfs_fdtable _fdtab;
|
||||||
|
static int fd_alloc(struct dfs_fdtable *fdt, int startfd);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @addtogroup DFS
|
* @addtogroup DFS
|
||||||
|
@ -62,7 +63,7 @@ int dfs_init(void)
|
||||||
memset(&_fdtab, 0, sizeof(_fdtab));
|
memset(&_fdtab, 0, sizeof(_fdtab));
|
||||||
|
|
||||||
/* create device filesystem lock */
|
/* 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
|
#ifdef DFS_USING_WORKDIR
|
||||||
/* set current working directory */
|
/* set current working directory */
|
||||||
|
@ -117,7 +118,6 @@ void dfs_unlock(void)
|
||||||
rt_mutex_release(&fslock);
|
rt_mutex_release(&fslock);
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef DFS_USING_POSIX
|
|
||||||
static int fd_alloc(struct dfs_fdtable *fdt, int startfd)
|
static int fd_alloc(struct dfs_fdtable *fdt, int startfd)
|
||||||
{
|
{
|
||||||
int idx;
|
int idx;
|
||||||
|
@ -216,10 +216,10 @@ struct dfs_fd *fd_get(int fd)
|
||||||
struct dfs_fd *d;
|
struct dfs_fd *d;
|
||||||
struct dfs_fdtable *fdt;
|
struct dfs_fdtable *fdt;
|
||||||
|
|
||||||
#ifdef RT_USING_POSIX_STDIO
|
#if defined(RT_USING_DFS_DEVFS) && defined(RT_USING_POSIX)
|
||||||
if ((0 <= fd) && (fd <= 2))
|
if ((0 <= fd) && (fd <= 2))
|
||||||
fd = libc_stdio_get_console();
|
fd = libc_stdio_get_console();
|
||||||
#endif /* RT_USING_POSIX_STDIO */
|
#endif
|
||||||
|
|
||||||
fdt = dfs_fdtable_get();
|
fdt = dfs_fdtable_get();
|
||||||
fd = fd - DFS_FD_OFFSET;
|
fd = fd - DFS_FD_OFFSET;
|
||||||
|
@ -276,8 +276,6 @@ void fd_put(struct dfs_fd *fd)
|
||||||
dfs_unlock();
|
dfs_unlock();
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif /* DFS_USING_POSIX */
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @ingroup Fd
|
* @ingroup Fd
|
||||||
*
|
*
|
||||||
|
|
|
@ -621,7 +621,6 @@ void cat(const char *filename)
|
||||||
}
|
}
|
||||||
FINSH_FUNCTION_EXPORT(cat, print file);
|
FINSH_FUNCTION_EXPORT(cat, print file);
|
||||||
|
|
||||||
#ifdef DFS_USING_POSIX
|
|
||||||
#define BUF_SZ 4096
|
#define BUF_SZ 4096
|
||||||
static void copyfile(const char *src, const char *dst)
|
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 */
|
/* skip the '/' then return */
|
||||||
return ++ptr;
|
return ++ptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
void copy(const char *src, const char *dst)
|
void copy(const char *src, const char *dst)
|
||||||
{
|
{
|
||||||
#define FLAG_SRC_TYPE 0x03
|
#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)
|
FINSH_FUNCTION_EXPORT(copy, copy file or dir)
|
||||||
#endif /* DFS_USING_POSIX */
|
|
||||||
|
|
||||||
#endif /* RT_USING_FINSH */
|
#endif
|
||||||
/* @} */
|
/* @} */
|
||||||
|
|
||||||
|
|
|
@ -9,10 +9,17 @@
|
||||||
* 2018-03-09 Bernard Add protection for pt->triggered.
|
* 2018-03-09 Bernard Add protection for pt->triggered.
|
||||||
*/
|
*/
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
|
|
||||||
#include <rthw.h>
|
#include <rthw.h>
|
||||||
|
#include <rtdevice.h>
|
||||||
#include <rtthread.h>
|
#include <rtthread.h>
|
||||||
|
|
||||||
|
#include <dfs.h>
|
||||||
#include <dfs_file.h>
|
#include <dfs_file.h>
|
||||||
#include "poll.h"
|
#include <dfs_posix.h>
|
||||||
|
#include <poll.h>
|
||||||
|
|
||||||
|
#ifdef RT_USING_POSIX
|
||||||
|
|
||||||
struct rt_poll_node;
|
struct rt_poll_node;
|
||||||
|
|
||||||
|
@ -224,3 +231,5 @@ int poll(struct pollfd *fds, nfds_t nfds, int timeout)
|
||||||
|
|
||||||
return num;
|
return num;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#endif
|
|
@ -9,9 +9,15 @@
|
||||||
* 2018-02-07 Bernard Change the 3rd parameter of open/fcntl/ioctl to '...'
|
* 2018-02-07 Bernard Change the 3rd parameter of open/fcntl/ioctl to '...'
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include <dfs_file.h>
|
#include <dfs.h>
|
||||||
#include <dfs_private.h>
|
#include <dfs_posix.h>
|
||||||
#include <sys/errno.h>
|
#include "dfs_private.h"
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @addtogroup FsPosixApi
|
||||||
|
*/
|
||||||
|
|
||||||
|
/*@{*/
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* this function is a POSIX compliant version, which will open a file and
|
* 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);
|
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
|
* this function is a POSIX compliant version, which will rename old file name
|
||||||
* to new file name.
|
* to new file name.
|
||||||
|
@ -579,6 +585,11 @@ int mkdir(const char *path, mode_t mode)
|
||||||
}
|
}
|
||||||
RTM_EXPORT(mkdir);
|
RTM_EXPORT(mkdir);
|
||||||
|
|
||||||
|
#ifdef RT_USING_FINSH
|
||||||
|
#include <finsh.h>
|
||||||
|
FINSH_FUNCTION_EXPORT(mkdir, create a directory);
|
||||||
|
#endif
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* this function is a POSIX compliant version, which will remove a directory.
|
* 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;
|
return buf;
|
||||||
}
|
}
|
||||||
RTM_EXPORT(getcwd);
|
RTM_EXPORT(getcwd);
|
||||||
|
|
||||||
|
/* @} */
|
||||||
|
|
|
@ -7,10 +7,15 @@
|
||||||
* Date Author Notes
|
* Date Author Notes
|
||||||
* 2016-12-28 Bernard first version
|
* 2016-12-28 Bernard first version
|
||||||
*/
|
*/
|
||||||
#include <rtthread.h>
|
#include <dfs.h>
|
||||||
|
#include <dfs_fs.h>
|
||||||
|
#include <dfs_posix.h>
|
||||||
|
|
||||||
#include <poll.h>
|
#include <poll.h>
|
||||||
#include <sys/select.h>
|
#include <sys/select.h>
|
||||||
|
|
||||||
|
#ifdef RT_USING_POSIX
|
||||||
|
|
||||||
static void fdszero(fd_set *set, int nfds)
|
static void fdszero(fd_set *set, int nfds)
|
||||||
{
|
{
|
||||||
fd_mask *m;
|
fd_mask *m;
|
||||||
|
@ -174,3 +179,5 @@ int select(int nfds, fd_set *readfds, fd_set *writefds, fd_set *exceptfds, struc
|
||||||
|
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#endif
|
|
@ -5,6 +5,10 @@ config RT_USING_DEVICE_IPC
|
||||||
default y
|
default y
|
||||||
|
|
||||||
if RT_USING_DEVICE_IPC
|
if RT_USING_DEVICE_IPC
|
||||||
|
config RT_PIPE_BUFSZ
|
||||||
|
int "Set pipe buffer size"
|
||||||
|
default 512
|
||||||
|
|
||||||
config RT_USING_SYSTEM_WORKQUEUE
|
config RT_USING_SYSTEM_WORKQUEUE
|
||||||
bool "Using system default workqueue"
|
bool "Using system default workqueue"
|
||||||
default n
|
default n
|
||||||
|
@ -145,42 +149,6 @@ config RT_USING_PM
|
||||||
bool "Using Power Management device drivers"
|
bool "Using Power Management device drivers"
|
||||||
default n
|
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
|
config RT_USING_RTC
|
||||||
bool "Using RTC device drivers"
|
bool "Using RTC device drivers"
|
||||||
default n
|
default n
|
||||||
|
@ -655,14 +623,9 @@ menuconfig RT_USING_WIFI
|
||||||
endif
|
endif
|
||||||
|
|
||||||
menu "Using USB"
|
menu "Using USB"
|
||||||
config RT_USING_USB
|
|
||||||
bool
|
|
||||||
default n
|
|
||||||
|
|
||||||
config RT_USING_USB_HOST
|
config RT_USING_USB_HOST
|
||||||
bool "Using USB host"
|
bool "Using USB host"
|
||||||
default n
|
default n
|
||||||
select RT_USING_USB
|
|
||||||
|
|
||||||
if RT_USING_USB_HOST
|
if RT_USING_USB_HOST
|
||||||
config RT_USBH_MSTORAGE
|
config RT_USBH_MSTORAGE
|
||||||
|
@ -685,8 +648,6 @@ menu "Using USB"
|
||||||
config RT_USING_USB_DEVICE
|
config RT_USING_USB_DEVICE
|
||||||
bool "Using USB device"
|
bool "Using USB device"
|
||||||
default n
|
default n
|
||||||
select RT_USING_USB
|
|
||||||
|
|
||||||
if RT_USING_USB_DEVICE || RT_USING_USB_HOST
|
if RT_USING_USB_DEVICE || RT_USING_USB_HOST
|
||||||
config RT_USBD_THREAD_STACK_SZ
|
config RT_USBD_THREAD_STACK_SZ
|
||||||
int "usb thread stack size"
|
int "usb thread stack size"
|
||||||
|
|
|
@ -34,7 +34,7 @@ float clock_cpu_getres(void)
|
||||||
*
|
*
|
||||||
* @return the cpu tick
|
* @return the cpu tick
|
||||||
*/
|
*/
|
||||||
uint64_t clock_cpu_gettime(void)
|
uint32_t clock_cpu_gettime(void)
|
||||||
{
|
{
|
||||||
if (_cputime_ops)
|
if (_cputime_ops)
|
||||||
return _cputime_ops->cputime_gettime();
|
return _cputime_ops->cputime_gettime();
|
||||||
|
|
|
@ -24,7 +24,7 @@ static float cortexm_cputime_getres(void)
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
static uint64_t cortexm_cputime_gettime(void)
|
static uint32_t cortexm_cputime_gettime(void)
|
||||||
{
|
{
|
||||||
return DWT->CYCCNT;
|
return DWT->CYCCNT;
|
||||||
}
|
}
|
||||||
|
|
|
@ -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_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;
|
if (bus->timeout == 0) bus->timeout = RT_TICK_PER_SECOND;
|
||||||
|
|
||||||
|
|
|
@ -77,6 +77,9 @@ static rt_err_t i2c_bus_device_control(rt_device_t dev,
|
||||||
case RT_I2C_DEV_CTRL_10BIT:
|
case RT_I2C_DEV_CTRL_10BIT:
|
||||||
bus->flags |= RT_I2C_ADDR_10BIT;
|
bus->flags |= RT_I2C_ADDR_10BIT;
|
||||||
break;
|
break;
|
||||||
|
case RT_I2C_DEV_CTRL_ADDR:
|
||||||
|
bus->addr = *(rt_uint16_t *)args;
|
||||||
|
break;
|
||||||
case RT_I2C_DEV_CTRL_TIMEOUT:
|
case RT_I2C_DEV_CTRL_TIMEOUT:
|
||||||
bus->timeout = *(rt_uint32_t *)args;
|
bus->timeout = *(rt_uint32_t *)args;
|
||||||
break;
|
break;
|
||||||
|
|
|
@ -13,8 +13,7 @@
|
||||||
#ifndef __ALARM_H__
|
#ifndef __ALARM_H__
|
||||||
#define __ALARM_H__
|
#define __ALARM_H__
|
||||||
|
|
||||||
#include <sys/time.h>
|
#include <time.h>
|
||||||
#include <rtdef.h>
|
|
||||||
|
|
||||||
#define RT_ALARM_TM_NOW -1 /* set the alarm tm_day,tm_mon,tm_sec,etc.
|
#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 */
|
to now.we also call it "don't care" value */
|
||||||
|
|
|
@ -16,11 +16,11 @@
|
||||||
struct rt_clock_cputime_ops
|
struct rt_clock_cputime_ops
|
||||||
{
|
{
|
||||||
float (*cputime_getres) (void);
|
float (*cputime_getres) (void);
|
||||||
uint64_t (*cputime_gettime)(void);
|
uint32_t (*cputime_gettime)(void);
|
||||||
};
|
};
|
||||||
|
|
||||||
float clock_cpu_getres(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_microsecond(uint32_t cpu_tick);
|
||||||
uint32_t clock_cpu_millisecond(uint32_t cpu_tick);
|
uint32_t clock_cpu_millisecond(uint32_t cpu_tick);
|
||||||
|
|
|
@ -55,6 +55,7 @@ struct rt_i2c_bus_device
|
||||||
struct rt_device parent;
|
struct rt_device parent;
|
||||||
const struct rt_i2c_bus_device_ops *ops;
|
const struct rt_i2c_bus_device_ops *ops;
|
||||||
rt_uint16_t flags;
|
rt_uint16_t flags;
|
||||||
|
rt_uint16_t addr;
|
||||||
struct rt_mutex lock;
|
struct rt_mutex lock;
|
||||||
rt_uint32_t timeout;
|
rt_uint32_t timeout;
|
||||||
rt_uint32_t retries;
|
rt_uint32_t retries;
|
||||||
|
@ -63,6 +64,7 @@ struct rt_i2c_bus_device
|
||||||
|
|
||||||
struct rt_i2c_client
|
struct rt_i2c_client
|
||||||
{
|
{
|
||||||
|
struct rt_device parent;
|
||||||
struct rt_i2c_bus_device *bus;
|
struct rt_i2c_bus_device *bus;
|
||||||
rt_uint16_t client_addr;
|
rt_uint16_t client_addr;
|
||||||
};
|
};
|
||||||
|
|
|
@ -19,6 +19,7 @@ extern "C" {
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#define RT_I2C_DEV_CTRL_10BIT 0x20
|
#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_TIMEOUT 0x22
|
||||||
#define RT_I2C_DEV_CTRL_RW 0x23
|
#define RT_I2C_DEV_CTRL_RW 0x23
|
||||||
#define RT_I2C_DEV_CTRL_CLK 0x24
|
#define RT_I2C_DEV_CTRL_CLK 0x24
|
||||||
|
|
|
@ -1,38 +0,0 @@
|
||||||
/*
|
|
||||||
* Copyright (c) 2006-2021, RT-Thread Development Team
|
|
||||||
*
|
|
||||||
* SPDX-License-Identifier: Apache-2.0
|
|
||||||
*
|
|
||||||
* Change Logs:
|
|
||||||
* Date Author Notes
|
|
||||||
* 2021-10-11 zhangsz the first version
|
|
||||||
*/
|
|
||||||
|
|
||||||
#ifndef __LPTIMER_H__
|
|
||||||
#define __LPTIMER_H__
|
|
||||||
|
|
||||||
#include <rtthread.h>
|
|
||||||
|
|
||||||
struct rt_lptimer
|
|
||||||
{
|
|
||||||
struct rt_timer timer;
|
|
||||||
rt_list_t list;
|
|
||||||
};
|
|
||||||
typedef struct rt_lptimer *rt_lptimer_t;
|
|
||||||
|
|
||||||
void rt_lptimer_init(rt_lptimer_t timer,
|
|
||||||
const char *name,
|
|
||||||
void (*timeout)(void *parameter),
|
|
||||||
void *parameter,
|
|
||||||
rt_tick_t time,
|
|
||||||
rt_uint8_t flag);
|
|
||||||
|
|
||||||
rt_err_t rt_lptimer_detach(rt_lptimer_t timer);
|
|
||||||
rt_err_t rt_lptimer_start(rt_lptimer_t timer);
|
|
||||||
rt_err_t rt_lptimer_stop(rt_lptimer_t timer);
|
|
||||||
|
|
||||||
rt_err_t rt_lptimer_control(rt_lptimer_t timer, int cmd, void *arg);
|
|
||||||
|
|
||||||
rt_tick_t rt_lptimer_next_timeout_tick(void);
|
|
||||||
|
|
||||||
#endif
|
|
|
@ -161,7 +161,7 @@ struct rt_mmcsd_card {
|
||||||
struct rt_sdio_cccr cccr; /* common card info */
|
struct rt_sdio_cccr cccr; /* common card info */
|
||||||
struct rt_sdio_cis cis; /* common tuple info */
|
struct rt_sdio_cis cis; /* common tuple info */
|
||||||
struct rt_sdio_function *sdio_function[SDIO_MAX_FUNCTIONS + 1]; /* SDIO functions (devices) */
|
struct rt_sdio_function *sdio_function[SDIO_MAX_FUNCTIONS + 1]; /* SDIO functions (devices) */
|
||||||
rt_list_t blk_devices; /* for block device list */
|
|
||||||
};
|
};
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
|
|
|
@ -96,8 +96,6 @@ struct rt_mmcsd_host {
|
||||||
rt_uint32_t max_blk_size; /* maximum block size */
|
rt_uint32_t max_blk_size; /* maximum block size */
|
||||||
rt_uint32_t max_blk_count; /* maximum block count */
|
rt_uint32_t max_blk_count; /* maximum block count */
|
||||||
|
|
||||||
rt_uint32_t id; /* Assigned host id */
|
|
||||||
|
|
||||||
rt_uint32_t spi_use_crc;
|
rt_uint32_t spi_use_crc;
|
||||||
struct rt_mutex bus_lock;
|
struct rt_mutex bus_lock;
|
||||||
struct rt_semaphore sem_ack;
|
struct rt_semaphore sem_ack;
|
||||||
|
|
|
@ -17,7 +17,8 @@
|
||||||
|
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
#include <rtthread.h>
|
#include <rtthread.h>
|
||||||
#include <drivers/lptimer.h>
|
|
||||||
|
#ifndef PM_HAS_CUSTOM_CONFIG
|
||||||
|
|
||||||
/* All modes used for rt_pm_request() and rt_pm_release() */
|
/* All modes used for rt_pm_request() and rt_pm_release() */
|
||||||
enum
|
enum
|
||||||
|
@ -47,6 +48,10 @@ enum
|
||||||
RT_PM_FREQUENCY_PENDING = 0x01,
|
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" */
|
/* The name of all modes used in the msh command "pm_dump" */
|
||||||
#define PM_SLEEP_MODE_NAMES \
|
#define PM_SLEEP_MODE_NAMES \
|
||||||
{ \
|
{ \
|
||||||
|
@ -66,7 +71,6 @@ enum
|
||||||
"Low Mode", \
|
"Low Mode", \
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifndef PM_USING_CUSTOM_CONFIG
|
|
||||||
/**
|
/**
|
||||||
* Modules used for
|
* Modules used for
|
||||||
* pm_module_request(PM_BOARD_ID, PM_SLEEP_MODE_IDLE)
|
* pm_module_request(PM_BOARD_ID, PM_SLEEP_MODE_IDLE)
|
||||||
|
@ -94,23 +98,11 @@ enum pm_module_id {
|
||||||
PM_MODULE_MAX_ID, /* enum must! */
|
PM_MODULE_MAX_ID, /* enum must! */
|
||||||
};
|
};
|
||||||
|
|
||||||
#else
|
#else /* PM_HAS_CUSTOM_CONFIG */
|
||||||
|
|
||||||
#include <pm_cfg.h>
|
#include <pm_cfg.h>
|
||||||
|
|
||||||
#endif /* PM_USING_CUSTOM_CONFIG */
|
#endif /* PM_HAS_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
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* device control flag to request or release power
|
* device control flag to request or release power
|
||||||
|
@ -168,9 +160,6 @@ struct rt_pm
|
||||||
/* modules request status*/
|
/* modules request status*/
|
||||||
struct rt_pm_module module_status[PM_MODULE_MAX_ID];
|
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 */
|
/* the list of device, which has PM feature */
|
||||||
rt_uint8_t device_pm_number;
|
rt_uint8_t device_pm_number;
|
||||||
struct rt_device_pm *device_pm;
|
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);
|
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_uint32_t rt_pm_module_get_status(void);
|
||||||
rt_uint8_t rt_pm_get_sleep_mode(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__ */
|
#endif /* __PM_H__ */
|
||||||
|
|
|
@ -50,8 +50,6 @@ extern "C" {
|
||||||
#define RT_SENSOR_CLASS_GNSS (16) /* GPS/GNSS sensor */
|
#define RT_SENSOR_CLASS_GNSS (16) /* GPS/GNSS sensor */
|
||||||
#define RT_SENSOR_CLASS_TOF (17) /* TOF sensor */
|
#define RT_SENSOR_CLASS_TOF (17) /* TOF sensor */
|
||||||
#define RT_SENSOR_CLASS_SPO2 (18) /* SpO2 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 */
|
/* Sensor vendor types */
|
||||||
|
|
||||||
|
@ -92,7 +90,6 @@ extern "C" {
|
||||||
#define RT_SENSOR_UNIT_PPB (15) /* Concentration unit: ppb */
|
#define RT_SENSOR_UNIT_PPB (15) /* Concentration unit: ppb */
|
||||||
#define RT_SENSOR_UNIT_DMS (16) /* Coordinates unit: DMS */
|
#define RT_SENSOR_UNIT_DMS (16) /* Coordinates unit: DMS */
|
||||||
#define RT_SENSOR_UNIT_DD (17) /* Coordinates unit: DD */
|
#define RT_SENSOR_UNIT_DD (17) /* Coordinates unit: DD */
|
||||||
#define RT_SENSOR_UNIT_MGM3 (18) /* Concentration unit: mg/m3 */
|
|
||||||
/* Sensor communication interface types */
|
/* Sensor communication interface types */
|
||||||
|
|
||||||
#define RT_SENSOR_INTF_I2C (1 << 0)
|
#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 dust; /* Dust sensor. unit: ug/m3 */
|
||||||
rt_uint32_t eco2; /* eCO2 sensor. unit: ppm */
|
rt_uint32_t eco2; /* eCO2 sensor. unit: ppm */
|
||||||
rt_uint32_t spo2; /* SpO2 sensor. unit: permillage */
|
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;
|
} data;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -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
|
* SPDX-License-Identifier: Apache-2.0
|
||||||
*
|
*
|
||||||
|
|
|
@ -15,6 +15,12 @@
|
||||||
#include <rtthread.h>
|
#include <rtthread.h>
|
||||||
#include <rtdevice.h>
|
#include <rtdevice.h>
|
||||||
|
|
||||||
|
#ifndef RT_PIPE_BUFSZ
|
||||||
|
#define PIPE_BUFSZ 512
|
||||||
|
#else
|
||||||
|
#define PIPE_BUFSZ RT_PIPE_BUFSZ
|
||||||
|
#endif
|
||||||
|
|
||||||
struct rt_pipe_device
|
struct rt_pipe_device
|
||||||
{
|
{
|
||||||
struct rt_device parent;
|
struct rt_device parent;
|
||||||
|
|
|
@ -71,10 +71,6 @@ struct rt_rbb
|
||||||
rt_size_t blk_max_num;
|
rt_size_t blk_max_num;
|
||||||
/* saved the initialized and put status blocks */
|
/* saved the initialized and put status blocks */
|
||||||
rt_slist_t blk_list;
|
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;
|
typedef struct rt_rbb *rt_rbb_t;
|
||||||
|
|
||||||
|
|
|
@ -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(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_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_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
|
#ifdef RT_USING_SYSTEM_WORKQUEUE
|
||||||
rt_err_t rt_work_submit(struct rt_work *work, rt_tick_t time);
|
rt_err_t rt_work_submit(struct rt_work *work, rt_tick_t time);
|
||||||
|
|
|
@ -2,7 +2,7 @@ from building import *
|
||||||
|
|
||||||
cwd = GetCurrentDir()
|
cwd = GetCurrentDir()
|
||||||
src = []
|
src = []
|
||||||
depend = ['']
|
depend = []
|
||||||
|
|
||||||
CPPPATH = [cwd + '/../include']
|
CPPPATH = [cwd + '/../include']
|
||||||
group = []
|
group = []
|
||||||
|
|
|
@ -295,11 +295,11 @@ help:
|
||||||
rt_kprintf(" eraseall <name> Erase all block on device <name>\n");
|
rt_kprintf(" eraseall <name> Erase all block on device <name>\n");
|
||||||
return ;
|
return ;
|
||||||
}
|
}
|
||||||
else if (!rt_strcmp(argv[1], "id"))
|
else if (!strcmp(argv[1], "id"))
|
||||||
{
|
{
|
||||||
mtd_nandid(argv[2]);
|
mtd_nandid(argv[2]);
|
||||||
}
|
}
|
||||||
else if (!rt_strcmp(argv[1], "read"))
|
else if (!strcmp(argv[1], "read"))
|
||||||
{
|
{
|
||||||
if (argc < 5)
|
if (argc < 5)
|
||||||
{
|
{
|
||||||
|
@ -308,7 +308,7 @@ help:
|
||||||
}
|
}
|
||||||
mtd_nand_read(argv[2], atoi(argv[3]), atoi(argv[4]));
|
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)
|
if (argc < 5)
|
||||||
{
|
{
|
||||||
|
@ -317,7 +317,7 @@ help:
|
||||||
}
|
}
|
||||||
mtd_nand_readoob(argv[2], atoi(argv[3]), atoi(argv[4]));
|
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)
|
if (argc < 5)
|
||||||
{
|
{
|
||||||
|
@ -326,7 +326,7 @@ help:
|
||||||
}
|
}
|
||||||
mtd_nand_write(argv[2], atoi(argv[3]), atoi(argv[4]));
|
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)
|
if (argc < 4)
|
||||||
{
|
{
|
||||||
|
@ -335,7 +335,7 @@ help:
|
||||||
}
|
}
|
||||||
mtd_nand_erase(argv[2], atoi(argv[3]));
|
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]);
|
mtd_nand_erase_all(argv[2]);
|
||||||
}
|
}
|
||||||
|
|
|
@ -7,7 +7,6 @@ group = []
|
||||||
|
|
||||||
if GetDepend(['RT_USING_PM']):
|
if GetDepend(['RT_USING_PM']):
|
||||||
src = src + ['pm.c']
|
src = src + ['pm.c']
|
||||||
src = src + ['lptimer.c']
|
|
||||||
|
|
||||||
if len(src):
|
if len(src):
|
||||||
group = DefineGroup('DeviceDrivers', src, depend = [''], CPPPATH = CPPPATH)
|
group = DefineGroup('DeviceDrivers', src, depend = [''], CPPPATH = CPPPATH)
|
||||||
|
|
|
@ -1,176 +0,0 @@
|
||||||
/*
|
|
||||||
* Copyright (c) 2006-2021, RT-Thread Development Team
|
|
||||||
*
|
|
||||||
* SPDX-License-Identifier: Apache-2.0
|
|
||||||
*
|
|
||||||
* Change Logs:
|
|
||||||
* Date Author Notes
|
|
||||||
* 2021-10-11 zhangsz the first version
|
|
||||||
*/
|
|
||||||
|
|
||||||
#include <rtthread.h>
|
|
||||||
#include <rthw.h>
|
|
||||||
#include <drivers/lptimer.h>
|
|
||||||
|
|
||||||
static rt_list_t rt_soft_lptimer_list = RT_LIST_OBJECT_INIT(rt_soft_lptimer_list);
|
|
||||||
|
|
||||||
/* lptimer init */
|
|
||||||
void rt_lptimer_init(rt_lptimer_t timer,
|
|
||||||
const char *name,
|
|
||||||
void (*timeout)(void *parameter),
|
|
||||||
void *parameter,
|
|
||||||
rt_tick_t time,
|
|
||||||
rt_uint8_t flag)
|
|
||||||
{
|
|
||||||
rt_timer_init(&timer->timer, name, timeout, parameter, time, flag);
|
|
||||||
rt_list_init(&timer->list);
|
|
||||||
}
|
|
||||||
|
|
||||||
/* lptimer detach */
|
|
||||||
rt_err_t rt_lptimer_detach(rt_lptimer_t timer)
|
|
||||||
{
|
|
||||||
rt_base_t level;
|
|
||||||
rt_err_t ret = RT_EOK;
|
|
||||||
RT_ASSERT(timer != RT_NULL);
|
|
||||||
|
|
||||||
/* disable interrupt */
|
|
||||||
level = rt_hw_interrupt_disable();
|
|
||||||
|
|
||||||
ret = rt_timer_detach(&timer->timer);
|
|
||||||
rt_list_remove(&timer->list);
|
|
||||||
|
|
||||||
/* enable interrupt */
|
|
||||||
rt_hw_interrupt_enable(level);
|
|
||||||
return ret;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* lptimer start */
|
|
||||||
rt_err_t rt_lptimer_start(rt_lptimer_t timer)
|
|
||||||
{
|
|
||||||
rt_base_t level;
|
|
||||||
|
|
||||||
RT_ASSERT(timer != RT_NULL);
|
|
||||||
|
|
||||||
/* disable interrupt */
|
|
||||||
level = rt_hw_interrupt_disable();
|
|
||||||
rt_list_remove(&timer->list); /* remove first */
|
|
||||||
if (rt_timer_start(&timer->timer) == RT_EOK)
|
|
||||||
{
|
|
||||||
/* insert to lptimer list */
|
|
||||||
rt_list_insert_after(&rt_soft_lptimer_list, &(timer->list));
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
/* enable interrupt */
|
|
||||||
rt_hw_interrupt_enable(level);
|
|
||||||
return -RT_ERROR;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* enable interrupt */
|
|
||||||
rt_hw_interrupt_enable(level);
|
|
||||||
return RT_EOK;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* lptimer stop */
|
|
||||||
rt_err_t rt_lptimer_stop(rt_lptimer_t timer)
|
|
||||||
{
|
|
||||||
rt_base_t level;
|
|
||||||
RT_ASSERT(timer != RT_NULL);
|
|
||||||
|
|
||||||
/* disable interrupt */
|
|
||||||
level = rt_hw_interrupt_disable();
|
|
||||||
rt_list_remove(&timer->list);
|
|
||||||
if (rt_timer_stop(&timer->timer) == RT_EOK)
|
|
||||||
{
|
|
||||||
/* enable interrupt */
|
|
||||||
rt_hw_interrupt_enable(level);
|
|
||||||
return RT_EOK;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
/* enable interrupt */
|
|
||||||
rt_hw_interrupt_enable(level);
|
|
||||||
return -RT_ERROR;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
rt_err_t rt_lptimer_control(rt_lptimer_t timer, int cmd, void *arg)
|
|
||||||
{
|
|
||||||
RT_ASSERT(timer != RT_NULL);
|
|
||||||
|
|
||||||
return rt_timer_control(&timer->timer, cmd, arg);
|
|
||||||
}
|
|
||||||
|
|
||||||
/* get the next soft lptimer timeout */
|
|
||||||
rt_tick_t rt_lptimer_next_timeout_tick(void)
|
|
||||||
{
|
|
||||||
struct rt_lptimer *timer;
|
|
||||||
rt_base_t level;
|
|
||||||
rt_tick_t timeout_tick = RT_TICK_MAX;
|
|
||||||
struct rt_list_node *node = RT_NULL;
|
|
||||||
rt_tick_t temp_tick = 0;
|
|
||||||
rt_tick_t min_tick = RT_TICK_MAX;
|
|
||||||
rt_tick_t cur_tick = rt_tick_get();
|
|
||||||
|
|
||||||
/* disable interrupt */
|
|
||||||
level = rt_hw_interrupt_disable();
|
|
||||||
|
|
||||||
if (!rt_list_isempty(&rt_soft_lptimer_list))
|
|
||||||
{
|
|
||||||
/* find the first active timer's timeout */
|
|
||||||
rt_list_for_each(node, &rt_soft_lptimer_list)
|
|
||||||
{
|
|
||||||
timer = rt_list_entry(node, struct rt_lptimer, list);
|
|
||||||
if (timer->timer.parent.flag & RT_TIMER_FLAG_ACTIVATED)
|
|
||||||
{
|
|
||||||
temp_tick = timer->timer.timeout_tick - cur_tick;
|
|
||||||
|
|
||||||
/* find the least timeout_tick */
|
|
||||||
if (min_tick > temp_tick)
|
|
||||||
{
|
|
||||||
min_tick = temp_tick;
|
|
||||||
timeout_tick = timer->timer.timeout_tick;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/* enable interrupt */
|
|
||||||
rt_hw_interrupt_enable(level);
|
|
||||||
|
|
||||||
return timeout_tick;
|
|
||||||
}
|
|
||||||
|
|
||||||
void lptimer_dump(void)
|
|
||||||
{
|
|
||||||
struct rt_lptimer *timer;
|
|
||||||
rt_base_t level;
|
|
||||||
struct rt_list_node *node = RT_NULL;
|
|
||||||
|
|
||||||
/* disable interrupt */
|
|
||||||
level = rt_hw_interrupt_disable();
|
|
||||||
|
|
||||||
rt_kprintf("| lptimer | periodic | timeout | flag |\n");
|
|
||||||
rt_kprintf("+---------------+------------+------------+-------------+\n");
|
|
||||||
|
|
||||||
if (!rt_list_isempty(&rt_soft_lptimer_list))
|
|
||||||
{
|
|
||||||
rt_list_for_each(node, &rt_soft_lptimer_list)
|
|
||||||
{
|
|
||||||
timer = rt_list_entry(node, struct rt_lptimer, list);
|
|
||||||
rt_kprintf("| %-13s | 0x%08x | 0x%08x |",
|
|
||||||
timer->timer.parent.name, timer->timer.init_tick,
|
|
||||||
timer->timer.timeout_tick);
|
|
||||||
if (timer->timer.parent.flag & RT_TIMER_FLAG_ACTIVATED)
|
|
||||||
rt_kprintf(" activated |\n");
|
|
||||||
else
|
|
||||||
rt_kprintf(" deactivated |\n");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/* enable interrupt */
|
|
||||||
rt_hw_interrupt_enable(level);
|
|
||||||
rt_kprintf("+---------------+------------+------------+-------------+\n");
|
|
||||||
}
|
|
||||||
|
|
||||||
MSH_CMD_EXPORT(lptimer_dump, soft lptimer dump);
|
|
|
@ -15,44 +15,9 @@
|
||||||
#include <rthw.h>
|
#include <rthw.h>
|
||||||
#include <rtthread.h>
|
#include <rtthread.h>
|
||||||
#include <drivers/pm.h>
|
#include <drivers/pm.h>
|
||||||
#include <stdlib.h>
|
|
||||||
|
|
||||||
#ifdef RT_USING_PM
|
#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;
|
static struct rt_pm _pm;
|
||||||
|
|
||||||
/* default mode : system power on */
|
/* 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 struct rt_pm_notify _pm_notify;
|
||||||
static rt_uint8_t _pm_init_flag = 0;
|
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)
|
RT_WEAK rt_uint32_t rt_pm_enter_critical(rt_uint8_t sleep_mode)
|
||||||
{
|
{
|
||||||
return rt_hw_interrupt_disable();
|
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);
|
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
|
* 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.
|
* 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;
|
rt_uint8_t mode;
|
||||||
|
|
||||||
mode = _pm_default_deepsleep;
|
mode = _pm_default_deepsleep;
|
||||||
rt_uint8_t request_mode = _judge_sleep_mode();
|
|
||||||
for (index = PM_SLEEP_MODE_NONE; index < PM_SLEEP_MODE_MAX; index ++)
|
for (index = PM_SLEEP_MODE_NONE; index < PM_SLEEP_MODE_MAX; index ++)
|
||||||
{
|
{
|
||||||
if (pm->modes[index])
|
if (pm->modes[index])
|
||||||
|
@ -228,10 +128,7 @@ static rt_uint8_t _pm_select_sleep_mode(struct rt_pm *pm)
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
pm->sleep_mode = mode;
|
||||||
/* select the high power mode */
|
|
||||||
if (request_mode < mode)
|
|
||||||
mode = request_mode;
|
|
||||||
|
|
||||||
return mode;
|
return mode;
|
||||||
}
|
}
|
||||||
|
@ -288,72 +185,6 @@ static rt_bool_t _pm_device_check_idle(void)
|
||||||
return RT_TRUE;
|
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
|
* 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_tick_t timeout_tick, delta_tick;
|
||||||
rt_base_t level;
|
rt_base_t level;
|
||||||
uint8_t sleep_mode = PM_SLEEP_MODE_DEEP;
|
int ret = RT_EOK;
|
||||||
|
|
||||||
level = rt_pm_enter_critical(pm->sleep_mode);
|
level = rt_pm_enter_critical(pm->sleep_mode);
|
||||||
|
|
||||||
/* judge sleep mode from module request */
|
/* module busy request */
|
||||||
pm->sleep_mode = _pm_select_sleep_mode(pm);
|
|
||||||
|
|
||||||
/* module busy request check */
|
|
||||||
if (_pm_device_check_idle() == RT_FALSE)
|
if (_pm_device_check_idle() == RT_FALSE)
|
||||||
{
|
{
|
||||||
sleep_mode = PM_BUSY_SLEEP_MODE;
|
pm->ops->sleep(pm, PM_SLEEP_MODE_NONE);
|
||||||
if (sleep_mode < pm->sleep_mode)
|
rt_pm_exit_critical(level, pm->sleep_mode);
|
||||||
{
|
return;
|
||||||
pm->sleep_mode = sleep_mode; /* judge the highest sleep mode */
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (_pm.sleep_mode == PM_SLEEP_MODE_NONE)
|
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);
|
_pm_notify.notify(RT_PM_ENTER_SLEEP, pm->sleep_mode, _pm_notify.data);
|
||||||
|
|
||||||
/* Suspend all peripheral device */
|
/* Suspend all peripheral device */
|
||||||
#ifdef PM_ENABLE_SUSPEND_SLEEP_MODE
|
ret = _pm_device_suspend(pm->sleep_mode);
|
||||||
int ret = _pm_device_suspend(pm->sleep_mode);
|
|
||||||
if (ret != RT_EOK)
|
if (ret != RT_EOK)
|
||||||
{
|
{
|
||||||
_pm_device_resume(pm->sleep_mode);
|
_pm_device_resume(pm->sleep_mode);
|
||||||
if (_pm_notify.notify)
|
if (_pm_notify.notify)
|
||||||
_pm_notify.notify(RT_PM_EXIT_SLEEP, pm->sleep_mode, _pm_notify.data);
|
_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);
|
rt_pm_exit_critical(level, pm->sleep_mode);
|
||||||
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
#else
|
|
||||||
_pm_device_suspend(pm->sleep_mode);
|
|
||||||
#endif
|
|
||||||
/* Tickless*/
|
/* Tickless*/
|
||||||
if (pm->timer_mask & (0x01 << pm->sleep_mode))
|
if (pm->timer_mask & (0x01 << pm->sleep_mode))
|
||||||
{
|
{
|
||||||
timeout_tick = pm_timer_next_timeout_tick(pm->sleep_mode);
|
timeout_tick = rt_timer_next_timeout_tick();
|
||||||
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))
|
|
||||||
{
|
|
||||||
if (timeout_tick == RT_TICK_MAX)
|
if (timeout_tick == RT_TICK_MAX)
|
||||||
{
|
{
|
||||||
pm_lptimer_start(pm, RT_TICK_MAX);
|
if (pm->ops->timer_start)
|
||||||
|
{
|
||||||
|
pm->ops->timer_start(pm, RT_TICK_MAX);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
pm_lptimer_start(pm, timeout_tick);
|
timeout_tick = timeout_tick - rt_tick_get();
|
||||||
|
if (timeout_tick < RT_PM_TICKLESS_THRESH)
|
||||||
|
{
|
||||||
|
pm->sleep_mode = PM_SLEEP_MODE_IDLE;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
pm->ops->timer_start(pm, timeout_tick);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/* enter lower power state */
|
/* enter lower power state */
|
||||||
pm_sleep(pm, pm->sleep_mode);
|
pm->ops->sleep(pm, pm->sleep_mode);
|
||||||
|
|
||||||
/* wake up from lower power state*/
|
/* wake up from lower power state*/
|
||||||
if (pm->timer_mask & (0x01 << pm->sleep_mode))
|
if (pm->timer_mask & (0x01 << pm->sleep_mode))
|
||||||
{
|
{
|
||||||
delta_tick = pm_lptimer_get_timeout(pm);
|
delta_tick = pm->ops->timer_get_tick(pm);
|
||||||
pm_lptimer_stop(pm);
|
pm->ops->timer_stop(pm);
|
||||||
if (delta_tick)
|
if (delta_tick)
|
||||||
{
|
{
|
||||||
rt_tick_set(rt_tick_get() + delta_tick);
|
rt_tick_set(rt_tick_get() + delta_tick);
|
||||||
|
@ -498,6 +320,7 @@ void rt_pm_request(rt_uint8_t mode)
|
||||||
pm = &_pm;
|
pm = &_pm;
|
||||||
if (pm->modes[mode] < 255)
|
if (pm->modes[mode] < 255)
|
||||||
pm->modes[mode] ++;
|
pm->modes[mode] ++;
|
||||||
|
_pm_select_sleep_mode(pm);
|
||||||
rt_hw_interrupt_enable(level);
|
rt_hw_interrupt_enable(level);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -523,6 +346,7 @@ void rt_pm_release(rt_uint8_t mode)
|
||||||
pm = &_pm;
|
pm = &_pm;
|
||||||
if (pm->modes[mode] > 0)
|
if (pm->modes[mode] > 0)
|
||||||
pm->modes[mode] --;
|
pm->modes[mode] --;
|
||||||
|
_pm_select_sleep_mode(pm);
|
||||||
rt_hw_interrupt_enable(level);
|
rt_hw_interrupt_enable(level);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -547,6 +371,7 @@ void rt_pm_release_all(rt_uint8_t mode)
|
||||||
level = rt_hw_interrupt_disable();
|
level = rt_hw_interrupt_disable();
|
||||||
pm = &_pm;
|
pm = &_pm;
|
||||||
pm->modes[mode] = 0;
|
pm->modes[mode] = 0;
|
||||||
|
_pm_select_sleep_mode(pm);
|
||||||
rt_hw_interrupt_enable(level);
|
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;
|
pm->module_status[module_id].req_status = 0x01;
|
||||||
if (pm->modes[mode] < 255)
|
if (pm->modes[mode] < 255)
|
||||||
pm->modes[mode] ++;
|
pm->modes[mode] ++;
|
||||||
|
_pm_select_sleep_mode(pm);
|
||||||
rt_hw_interrupt_enable(level);
|
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] --;
|
pm->modes[mode] --;
|
||||||
if (pm->modes[mode] == 0)
|
if (pm->modes[mode] == 0)
|
||||||
pm->module_status[module_id].req_status = 0x00;
|
pm->module_status[module_id].req_status = 0x00;
|
||||||
|
_pm_select_sleep_mode(pm);
|
||||||
rt_hw_interrupt_enable(level);
|
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 = &_pm;
|
||||||
pm->modes[mode] = 0;
|
pm->modes[mode] = 0;
|
||||||
pm->module_status[module_id].req_status = 0x00;
|
pm->module_status[module_id].req_status = 0x00;
|
||||||
|
_pm_select_sleep_mode(pm);
|
||||||
rt_hw_interrupt_enable(level);
|
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
|
* Register a device with PM feature
|
||||||
*
|
*
|
||||||
|
@ -1151,69 +853,6 @@ rt_uint8_t rt_pm_get_sleep_mode(void)
|
||||||
return pm->sleep_mode;
|
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)
|
static void rt_pm_dump_status(void)
|
||||||
{
|
{
|
||||||
rt_uint32_t index;
|
rt_uint32_t index;
|
||||||
|
|
|
@ -790,7 +790,7 @@ int rt_alarm_system_init(void)
|
||||||
|
|
||||||
rt_list_init(&_container.head);
|
rt_list_init(&_container.head);
|
||||||
rt_event_init(&_container.event, "alarmsvc", RT_IPC_FLAG_FIFO);
|
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",
|
tid = rt_thread_create("alarmsvc",
|
||||||
rt_alarmsvc_thread_init, RT_NULL,
|
rt_alarmsvc_thread_init, RT_NULL,
|
||||||
|
|
|
@ -14,7 +14,7 @@
|
||||||
* 2021-07-30 Meco Man move rtc_core.c to rtc.c
|
* 2021-07-30 Meco Man move rtc_core.c to rtc.c
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include <sys/time.h>
|
#include <time.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <rtthread.h>
|
#include <rtthread.h>
|
||||||
|
|
|
@ -21,6 +21,7 @@
|
||||||
#endif /* RT_SDIO_DEBUG */
|
#endif /* RT_SDIO_DEBUG */
|
||||||
#include <rtdbg.h>
|
#include <rtdbg.h>
|
||||||
|
|
||||||
|
static rt_list_t blk_devices = RT_LIST_OBJECT_INIT(blk_devices);
|
||||||
|
|
||||||
#define BLK_MIN(a, b) ((a) < (b) ? (a) : (b))
|
#define BLK_MIN(a, b) ((a) < (b) ? (a) : (b))
|
||||||
|
|
||||||
|
@ -351,81 +352,14 @@ const static struct rt_device_ops mmcsd_blk_ops =
|
||||||
};
|
};
|
||||||
#endif
|
#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 rt_mmcsd_blk_probe(struct rt_mmcsd_card *card)
|
||||||
{
|
{
|
||||||
rt_int32_t err = 0;
|
rt_int32_t err = 0;
|
||||||
rt_uint8_t status;
|
rt_uint8_t i, status;
|
||||||
rt_uint8_t *sector;
|
rt_uint8_t *sector;
|
||||||
|
char dname[4];
|
||||||
|
char sname[8];
|
||||||
|
struct mmcsd_blk_device *blk_dev = RT_NULL;
|
||||||
|
|
||||||
err = mmcsd_set_blksize(card);
|
err = mmcsd_set_blksize(card);
|
||||||
if(err)
|
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);
|
status = rt_mmcsd_req_blk(card, 0, sector, 1, 0);
|
||||||
if (status == RT_EOK)
|
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++)
|
for (i = 0; i < RT_MMCSD_MAX_PARTITION; i++)
|
||||||
{
|
{
|
||||||
/* Get the first partition */
|
blk_dev = rt_calloc(1, sizeof(struct mmcsd_blk_device));
|
||||||
status = dfs_filesystem_get_partition(&part, sector, i);
|
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)
|
if (status == RT_EOK)
|
||||||
{
|
{
|
||||||
/* Given name is with allocated host id and its partition index. */
|
rt_snprintf(dname, 4, "sd%d", i);
|
||||||
rt_snprintf(dname, sizeof(dname), "sd%dp%d", host_id, i);
|
rt_snprintf(sname, 8, "sem_sd%d", i);
|
||||||
blk_dev = rt_mmcsd_create_blkdev(card, (const char*)dname, &part);
|
blk_dev->part.lock = rt_sem_create(sname, 1, RT_IPC_FLAG_FIFO);
|
||||||
if ( blk_dev == RT_NULL )
|
|
||||||
{
|
/* register mmcsd device */
|
||||||
err = -RT_ENOMEM;
|
blk_dev->dev.type = RT_Device_Class_Block;
|
||||||
goto exit_rt_mmcsd_blk_probe;
|
#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
|
else
|
||||||
{
|
{
|
||||||
|
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);
|
||||||
|
|
||||||
|
/* 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;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Always create the super node, given name is with allocated host id. */
|
#ifdef RT_USING_DFS_MNTTABLE
|
||||||
rt_snprintf(dname, sizeof(dname), "sd%d", host_id);
|
if (blk_dev)
|
||||||
blk_dev = rt_mmcsd_create_blkdev(card, (const char*)dname, RT_NULL);
|
|
||||||
if ( blk_dev == RT_NULL )
|
|
||||||
{
|
{
|
||||||
err = -RT_ENOMEM;
|
LOG_I("try to mount file system!");
|
||||||
goto exit_rt_mmcsd_blk_probe;
|
/* try to mount file system on this block device */
|
||||||
|
dfs_mount_device(&(blk_dev->dev));
|
||||||
|
}
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
@ -492,8 +485,6 @@ rt_int32_t rt_mmcsd_blk_probe(struct rt_mmcsd_card *card)
|
||||||
err = -RT_ERROR;
|
err = -RT_ERROR;
|
||||||
}
|
}
|
||||||
|
|
||||||
exit_rt_mmcsd_blk_probe:
|
|
||||||
|
|
||||||
/* release sector buffer */
|
/* release sector buffer */
|
||||||
rt_free(sector);
|
rt_free(sector);
|
||||||
|
|
||||||
|
@ -505,7 +496,7 @@ void rt_mmcsd_blk_remove(struct rt_mmcsd_card *card)
|
||||||
rt_list_t *l, *n;
|
rt_list_t *l, *n;
|
||||||
struct mmcsd_blk_device *blk_dev;
|
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);
|
blk_dev = (struct mmcsd_blk_device *)rt_list_entry(l, struct mmcsd_blk_device, list);
|
||||||
if (blk_dev->card == card)
|
if (blk_dev->card == card)
|
||||||
|
|
|
@ -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_4,
|
||||||
EXT_CSD_BUS_WIDTH_1
|
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;
|
struct rt_mmcsd_host *host = card->host;
|
||||||
unsigned idx, trys, bus_width = 0;
|
unsigned idx, trys, bus_width = 0;
|
||||||
int err = 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
|
* the supported bus width or compare the ext csd values of current
|
||||||
* bus width and ext csd values of 1 bit mode read earlier.
|
* 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
|
* Host is capable of 8bit transfer, then switch
|
||||||
* the device to work in 8bit transfer mode. If the
|
* the device to work in 8bit transfer mode. If the
|
||||||
|
|
|
@ -40,7 +40,6 @@ static struct rt_mailbox mmcsd_detect_mb;
|
||||||
static rt_uint32_t mmcsd_detect_mb_pool[4];
|
static rt_uint32_t mmcsd_detect_mb_pool[4];
|
||||||
static struct rt_mailbox mmcsd_hotpluge_mb;
|
static struct rt_mailbox mmcsd_hotpluge_mb;
|
||||||
static rt_uint32_t mmcsd_hotpluge_mb_pool[4];
|
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)
|
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_dma_segs = 1;
|
||||||
host->max_blk_size = 512;
|
host->max_blk_size = 512;
|
||||||
host->max_blk_count = 4096;
|
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);
|
rt_sem_init(&host->sem_ack, "sd_ack", 0, RT_IPC_FLAG_FIFO);
|
||||||
|
|
||||||
return host;
|
return host;
|
||||||
|
|
|
@ -37,9 +37,7 @@ static char *const sensor_name_str[] =
|
||||||
"eco2_", /* eCO2 sensor */
|
"eco2_", /* eCO2 sensor */
|
||||||
"gnss_", /* GPS/GNSS sensor */
|
"gnss_", /* GPS/GNSS sensor */
|
||||||
"tof_", /* TOF sensor */
|
"tof_", /* TOF sensor */
|
||||||
"spo2_", /* SpO2 sensor */
|
"spo2_" /* SpO2 sensor */
|
||||||
"iaq_", /* IAQ sensor */
|
|
||||||
"etoh_", /* EtOH sensor */
|
|
||||||
};
|
};
|
||||||
|
|
||||||
/* Sensor interrupt correlation function */
|
/* 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");
|
LOG_D("Undefined control");
|
||||||
return RT_ERROR;
|
return RT_ERROR;
|
||||||
}
|
}
|
||||||
static struct rt_sensor_ops local_ops =
|
static struct rt_sensor_ops local_ops = {
|
||||||
{
|
|
||||||
.fetch_data = local_fetch_data,
|
.fetch_data = local_fetch_data,
|
||||||
.control = local_control
|
.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_sensor_t sensor = (rt_sensor_t)dev;
|
||||||
RT_ASSERT(dev != RT_NULL);
|
RT_ASSERT(dev != RT_NULL);
|
||||||
rt_err_t res = RT_EOK;
|
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)
|
if (sensor->module)
|
||||||
{
|
{
|
||||||
|
@ -455,7 +452,7 @@ int rt_hw_sensor_register(rt_sensor_t sensor,
|
||||||
if (sensor->module != RT_NULL && sensor->module->lock == RT_NULL)
|
if (sensor->module != RT_NULL && sensor->module->lock == RT_NULL)
|
||||||
{
|
{
|
||||||
/* Create a mutex lock for the module */
|
/* 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)
|
if (sensor->module->lock == RT_NULL)
|
||||||
{
|
{
|
||||||
rt_free(device_name);
|
rt_free(device_name);
|
||||||
|
@ -488,7 +485,7 @@ int rt_hw_sensor_register(rt_sensor_t sensor,
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
LOG_I("rt_sensor[%s] init success", device_name);
|
|
||||||
rt_free(device_name);
|
rt_free(device_name);
|
||||||
|
LOG_I("rt_sensor[%s] init success", device_name);
|
||||||
return RT_EOK;
|
return RT_EOK;
|
||||||
}
|
}
|
||||||
|
|
|
@ -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:
|
case RT_SENSOR_CLASS_ECO2:
|
||||||
LOG_I("num:%3d, eco2:%5d ppm, timestamp:%5d", num, sensor_data->data.eco2, sensor_data->timestamp);
|
LOG_I("num:%3d, eco2:%5d ppm, timestamp:%5d", num, sensor_data->data.eco2, sensor_data->timestamp);
|
||||||
break;
|
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:
|
default:
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -162,7 +156,7 @@ static void sensor_fifo(int argc, char **argv)
|
||||||
rt_device_control(dev, RT_SENSOR_CTRL_SET_ODR, (void *)20);
|
rt_device_control(dev, RT_SENSOR_CTRL_SET_ODR, (void *)20);
|
||||||
}
|
}
|
||||||
#ifdef RT_USING_FINSH
|
#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
|
#endif
|
||||||
|
|
||||||
static void sensor_irq_rx_entry(void *parameter)
|
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);
|
rt_device_control(dev, RT_SENSOR_CTRL_SET_ODR, (void *)20);
|
||||||
}
|
}
|
||||||
#ifdef RT_USING_FINSH
|
#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
|
#endif
|
||||||
|
|
||||||
static void sensor_polling(int argc, char **argv)
|
static void sensor_polling(int argc, char **argv)
|
||||||
{
|
{
|
||||||
rt_uint16_t num = 10;
|
uint16_t num = 10;
|
||||||
rt_device_t dev = RT_NULL;
|
rt_device_t dev = RT_NULL;
|
||||||
rt_sensor_t sensor;
|
rt_sensor_t sensor;
|
||||||
struct rt_sensor_data data;
|
struct rt_sensor_data data;
|
||||||
|
@ -275,7 +269,7 @@ static void sensor_polling(int argc, char **argv)
|
||||||
rt_device_close(dev);
|
rt_device_close(dev);
|
||||||
}
|
}
|
||||||
#ifdef RT_USING_FINSH
|
#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
|
#endif
|
||||||
|
|
||||||
static void sensor(int argc, char **argv)
|
static void sensor(int argc, char **argv)
|
||||||
|
@ -417,7 +411,7 @@ static void sensor(int argc, char **argv)
|
||||||
}
|
}
|
||||||
else if (!strcmp(argv[1], "read"))
|
else if (!strcmp(argv[1], "read"))
|
||||||
{
|
{
|
||||||
rt_uint16_t num = 5;
|
uint16_t num = 5;
|
||||||
|
|
||||||
if (dev == RT_NULL)
|
if (dev == RT_NULL)
|
||||||
{
|
{
|
||||||
|
@ -503,5 +497,5 @@ static void sensor(int argc, char **argv)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
#ifdef RT_USING_FINSH
|
#ifdef RT_USING_FINSH
|
||||||
MSH_CMD_EXPORT(sensor, sensor test function);
|
MSH_CMD_EXPORT(sensor, sensor test function);
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -36,13 +36,13 @@
|
||||||
#define DBG_LVL DBG_INFO
|
#define DBG_LVL DBG_INFO
|
||||||
#include <rtdbg.h>
|
#include <rtdbg.h>
|
||||||
|
|
||||||
#ifdef RT_USING_POSIX_STDIO
|
#ifdef RT_USING_POSIX
|
||||||
#include <dfs_posix.h>
|
#include <dfs_posix.h>
|
||||||
#include <poll.h>
|
#include <poll.h>
|
||||||
#include <sys/ioctl.h>
|
#include <sys/ioctl.h>
|
||||||
|
|
||||||
#ifdef RT_USING_POSIX_TERMIOS
|
#ifdef RT_USING_POSIX_TERMIOS
|
||||||
#include <termios.h>
|
#include <posix_termios.h>
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/* it's possible the 'getc/putc' is defined by stdio.h in gcc/newlib. */
|
/* 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 */
|
RT_NULL, /* getdents */
|
||||||
serial_fops_poll,
|
serial_fops_poll,
|
||||||
};
|
};
|
||||||
#endif /* RT_USING_POSIX_STDIO */
|
#endif
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Serial poll routines
|
* 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)
|
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;
|
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
|
#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,
|
static rt_err_t rt_serial_control(struct rt_device *dev,
|
||||||
int cmd,
|
int cmd,
|
||||||
|
@ -1019,7 +1020,7 @@ static rt_err_t rt_serial_control(struct rt_device *dev,
|
||||||
}
|
}
|
||||||
|
|
||||||
break;
|
break;
|
||||||
#ifdef RT_USING_POSIX_STDIO
|
#ifdef RT_USING_POSIX
|
||||||
#ifdef RT_USING_POSIX_TERMIOS
|
#ifdef RT_USING_POSIX_TERMIOS
|
||||||
case TCGETA:
|
case TCGETA:
|
||||||
{
|
{
|
||||||
|
@ -1133,7 +1134,6 @@ static rt_err_t rt_serial_control(struct rt_device *dev,
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
#include <shell.h>
|
|
||||||
#define _TIO_BUFLEN 20
|
#define _TIO_BUFLEN 20
|
||||||
char _tio_buf[_TIO_BUFLEN];
|
char _tio_buf[_TIO_BUFLEN];
|
||||||
unsigned char cnt1, cnt2, cnt3, i;
|
unsigned char cnt1, cnt2, cnt3, i;
|
||||||
|
@ -1149,7 +1149,7 @@ static rt_err_t rt_serial_control(struct rt_device *dev,
|
||||||
i = 0;
|
i = 0;
|
||||||
while(i < _TIO_BUFLEN)
|
while(i < _TIO_BUFLEN)
|
||||||
{
|
{
|
||||||
_tio_buf[i] = finsh_getchar();
|
_tio_buf[i] = getchar();
|
||||||
if(_tio_buf[i] != 't')
|
if(_tio_buf[i] != 't')
|
||||||
{
|
{
|
||||||
i ++;
|
i ++;
|
||||||
|
@ -1215,7 +1215,7 @@ static rt_err_t rt_serial_control(struct rt_device *dev,
|
||||||
*(rt_size_t *)args = recved;
|
*(rt_size_t *)args = recved;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
#endif /* RT_USING_POSIX_STDIO */
|
#endif /*RT_USING_POSIX*/
|
||||||
default :
|
default :
|
||||||
/* control device */
|
/* control device */
|
||||||
ret = serial->ops->control(serial, cmd, args);
|
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 */
|
/* register a character device */
|
||||||
ret = rt_device_register(device, name, flag);
|
ret = rt_device_register(device, name, flag);
|
||||||
|
|
||||||
#ifdef RT_USING_POSIX_STDIO
|
#if defined(RT_USING_POSIX)
|
||||||
/* set fops */
|
/* set fops */
|
||||||
device->fops = &_serial_fops;
|
device->fops = &_serial_fops;
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -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
|
* SPDX-License-Identifier: Apache-2.0
|
||||||
*
|
*
|
||||||
|
@ -16,7 +16,7 @@
|
||||||
#define DBG_LVL DBG_INFO
|
#define DBG_LVL DBG_INFO
|
||||||
#include <rtdbg.h>
|
#include <rtdbg.h>
|
||||||
|
|
||||||
#ifdef RT_USING_POSIX_STDIO
|
#ifdef RT_USING_POSIX
|
||||||
#include <dfs_posix.h>
|
#include <dfs_posix.h>
|
||||||
#include <poll.h>
|
#include <poll.h>
|
||||||
#include <sys/ioctl.h>
|
#include <sys/ioctl.h>
|
||||||
|
@ -179,7 +179,7 @@ const static struct dfs_file_ops _serial_fops =
|
||||||
RT_NULL, /* getdents */
|
RT_NULL, /* getdents */
|
||||||
serial_fops_poll,
|
serial_fops_poll,
|
||||||
};
|
};
|
||||||
#endif /* RT_USING_POSIX_STDIO */
|
#endif
|
||||||
|
|
||||||
static rt_size_t rt_serial_get_linear_buffer(struct rt_ringbuffer *rb,
|
static rt_size_t rt_serial_get_linear_buffer(struct rt_ringbuffer *rb,
|
||||||
rt_uint8_t **ptr)
|
rt_uint8_t **ptr)
|
||||||
|
@ -1135,7 +1135,7 @@ rt_err_t rt_hw_serial_register(struct rt_serial_device *serial,
|
||||||
/* register a character device */
|
/* register a character device */
|
||||||
ret = rt_device_register(device, name, flag);
|
ret = rt_device_register(device, name, flag);
|
||||||
|
|
||||||
#ifdef RT_USING_POSIX_STDIO
|
#if defined(RT_USING_POSIX)
|
||||||
/* set fops */
|
/* set fops */
|
||||||
device->fops = &_serial_fops;
|
device->fops = &_serial_fops;
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -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_rx = enc28j60_rx;
|
||||||
enc28j60_dev.parent.eth_tx = enc28j60_tx;
|
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");
|
eth_device_init(&(enc28j60_dev.parent), "e0");
|
||||||
|
|
||||||
|
|
|
@ -29,7 +29,7 @@
|
||||||
#ifndef _SFUD_CFG_H_
|
#ifndef _SFUD_CFG_H_
|
||||||
#define _SFUD_CFG_H_
|
#define _SFUD_CFG_H_
|
||||||
|
|
||||||
#include <rtthread.h>
|
#include <rtconfig.h>
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* It will print more information on debug mode.
|
* It will print more information on debug mode.
|
||||||
|
@ -47,6 +47,7 @@
|
||||||
|
|
||||||
#define DBG_TAG "SFUD"
|
#define DBG_TAG "SFUD"
|
||||||
#include <rtdbg.h>
|
#include <rtdbg.h>
|
||||||
|
extern void rt_kprintf(const char *fmt, ...);
|
||||||
#define SFUD_INFO(...) LOG_I(__VA_ARGS__)
|
#define SFUD_INFO(...) LOG_I(__VA_ARGS__)
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -29,7 +29,7 @@ rt_err_t rt_spi_bus_register(struct rt_spi_bus *bus,
|
||||||
return result;
|
return result;
|
||||||
|
|
||||||
/* initialize mutex lock */
|
/* 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 */
|
/* set ops */
|
||||||
bus->ops = ops;
|
bus->ops = ops;
|
||||||
/* initialize owner */
|
/* initialize owner */
|
||||||
|
|
|
@ -318,7 +318,7 @@ rt_spi_flash_device_t rt_sfud_flash_probe_ex(const char *spi_flash_dev_name, con
|
||||||
if (rtt_dev) {
|
if (rtt_dev) {
|
||||||
rt_memset(rtt_dev, 0, sizeof(struct spi_flash_device));
|
rt_memset(rtt_dev, 0, sizeof(struct spi_flash_device));
|
||||||
/* initialize lock */
|
/* 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) {
|
if (rtt_dev && sfud_dev && spi_flash_dev_name_bak && spi_dev_name_bak) {
|
||||||
|
|
|
@ -21,23 +21,6 @@ struct rt_data_item
|
||||||
rt_size_t data_size;
|
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_err_t
|
||||||
rt_data_queue_init(struct rt_data_queue *queue,
|
rt_data_queue_init(struct rt_data_queue *queue,
|
||||||
rt_uint16_t size,
|
rt_uint16_t size,
|
||||||
|
@ -71,21 +54,6 @@ rt_data_queue_init(struct rt_data_queue *queue,
|
||||||
}
|
}
|
||||||
RTM_EXPORT(rt_data_queue_init);
|
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,
|
rt_err_t rt_data_queue_push(struct rt_data_queue *queue,
|
||||||
const void *data_ptr,
|
const void *data_ptr,
|
||||||
rt_size_t data_size,
|
rt_size_t data_size,
|
||||||
|
@ -185,24 +153,6 @@ __exit:
|
||||||
}
|
}
|
||||||
RTM_EXPORT(rt_data_queue_push);
|
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,
|
rt_err_t rt_data_queue_pop(struct rt_data_queue *queue,
|
||||||
const void** data_ptr,
|
const void** data_ptr,
|
||||||
rt_size_t *size,
|
rt_size_t *size,
|
||||||
|
@ -314,18 +264,6 @@ __exit:
|
||||||
}
|
}
|
||||||
RTM_EXPORT(rt_data_queue_pop);
|
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,
|
rt_err_t rt_data_queue_peek(struct rt_data_queue *queue,
|
||||||
const void** data_ptr,
|
const void** data_ptr,
|
||||||
rt_size_t *size)
|
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);
|
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)
|
void rt_data_queue_reset(struct rt_data_queue *queue)
|
||||||
{
|
{
|
||||||
rt_ubase_t level;
|
rt_ubase_t level;
|
||||||
|
@ -432,13 +362,6 @@ void rt_data_queue_reset(struct rt_data_queue *queue)
|
||||||
}
|
}
|
||||||
RTM_EXPORT(rt_data_queue_reset);
|
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_err_t rt_data_queue_deinit(struct rt_data_queue *queue)
|
||||||
{
|
{
|
||||||
rt_ubase_t level;
|
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);
|
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_uint16_t rt_data_queue_len(struct rt_data_queue *queue)
|
||||||
{
|
{
|
||||||
rt_ubase_t level;
|
rt_ubase_t level;
|
||||||
|
|
|
@ -13,22 +13,12 @@
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
#include <sys/errno.h>
|
#include <sys/errno.h>
|
||||||
|
|
||||||
#if defined(RT_USING_POSIX_DEVIO) && defined(RT_USING_POSIX_PIPE)
|
#ifdef RT_USING_POSIX
|
||||||
#include <dfs_file.h>
|
#include <dfs_file.h>
|
||||||
#include <dfs_posix.h>
|
#include <dfs_posix.h>
|
||||||
#include <poll.h>
|
#include <poll.h>
|
||||||
#include <sys/ioctl.h>
|
#include <sys/ioctl.h>
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief This function will open a pipe.
|
|
||||||
*
|
|
||||||
* @param fd is the file descriptor.
|
|
||||||
*
|
|
||||||
* @return Return the operation status.
|
|
||||||
* When the return value is 0, it means the operation is successful.
|
|
||||||
* When the return value is -1, it means the file descriptor is invalid.
|
|
||||||
* When the return value is -RT_ENOMEM, it means insufficient memory allocation failed.
|
|
||||||
*/
|
|
||||||
static int pipe_fops_open(struct dfs_fd *fd)
|
static int pipe_fops_open(struct dfs_fd *fd)
|
||||||
{
|
{
|
||||||
int rc = 0;
|
int rc = 0;
|
||||||
|
@ -72,15 +62,6 @@ __exit:
|
||||||
return rc;
|
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)
|
static int pipe_fops_close(struct dfs_fd *fd)
|
||||||
{
|
{
|
||||||
rt_device_t device;
|
rt_device_t device;
|
||||||
|
@ -135,23 +116,6 @@ static int pipe_fops_close(struct dfs_fd *fd)
|
||||||
return 0;
|
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)
|
static int pipe_fops_ioctl(struct dfs_fd *fd, int cmd, void *args)
|
||||||
{
|
{
|
||||||
rt_pipe_t *pipe;
|
rt_pipe_t *pipe;
|
||||||
|
@ -175,19 +139,6 @@ static int pipe_fops_ioctl(struct dfs_fd *fd, int cmd, void *args)
|
||||||
return ret;
|
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)
|
static int pipe_fops_read(struct dfs_fd *fd, void *buf, size_t count)
|
||||||
{
|
{
|
||||||
int len = 0;
|
int len = 0;
|
||||||
|
@ -237,19 +188,6 @@ out:
|
||||||
return len;
|
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)
|
static int pipe_fops_write(struct dfs_fd *fd, const void *buf, size_t count)
|
||||||
{
|
{
|
||||||
int len;
|
int len;
|
||||||
|
@ -320,19 +258,6 @@ out:
|
||||||
return ret;
|
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)
|
static int pipe_fops_poll(struct dfs_fd *fd, rt_pollreq_t *req)
|
||||||
{
|
{
|
||||||
int mask = 0;
|
int mask = 0;
|
||||||
|
@ -395,21 +320,9 @@ static const struct dfs_file_ops pipe_fops =
|
||||||
RT_NULL,
|
RT_NULL,
|
||||||
pipe_fops_poll,
|
pipe_fops_poll,
|
||||||
};
|
};
|
||||||
#endif /* defined(RT_USING_POSIX_DEVIO) && defined(RT_USING_POSIX_PIPE) */
|
#endif /* end of RT_USING_POSIX */
|
||||||
|
|
||||||
/**
|
rt_err_t rt_pipe_open(rt_device_t device, rt_uint16_t oflag)
|
||||||
* @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_pipe_t *pipe = (rt_pipe_t *)device;
|
rt_pipe_t *pipe = (rt_pipe_t *)device;
|
||||||
rt_err_t ret = RT_EOK;
|
rt_err_t ret = RT_EOK;
|
||||||
|
@ -437,16 +350,7 @@ __exit:
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
rt_err_t rt_pipe_close(rt_device_t device)
|
||||||
* @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_pipe_t *pipe = (rt_pipe_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;
|
return RT_EOK;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
rt_size_t rt_pipe_read(rt_device_t device, rt_off_t pos, void *buffer, rt_size_t count)
|
||||||
* @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)
|
|
||||||
{
|
{
|
||||||
uint8_t *pbuf;
|
uint8_t *pbuf;
|
||||||
rt_size_t read_bytes = 0;
|
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;
|
return read_bytes;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
rt_size_t rt_pipe_write(rt_device_t device, rt_off_t pos, const void *buffer, rt_size_t count)
|
||||||
* @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)
|
|
||||||
{
|
{
|
||||||
uint8_t *pbuf;
|
uint8_t *pbuf;
|
||||||
rt_size_t write_bytes = 0;
|
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;
|
return write_bytes;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
rt_err_t rt_pipe_control(rt_device_t dev, int cmd, void *args)
|
||||||
* @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)
|
|
||||||
{
|
{
|
||||||
return RT_EOK;
|
return RT_EOK;
|
||||||
}
|
}
|
||||||
|
@ -574,20 +439,8 @@ const static struct rt_device_ops pipe_ops =
|
||||||
rt_pipe_write,
|
rt_pipe_write,
|
||||||
rt_pipe_control,
|
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 *rt_pipe_create(const char *name, int bufsz)
|
||||||
{
|
{
|
||||||
rt_pipe_t *pipe;
|
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));
|
rt_memset(pipe, 0, sizeof(rt_pipe_t));
|
||||||
pipe->is_named = RT_TRUE; /* initialize as a named pipe */
|
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->reader_queue));
|
||||||
rt_wqueue_init(&(pipe->writer_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);
|
rt_free(pipe);
|
||||||
return RT_NULL;
|
return RT_NULL;
|
||||||
}
|
}
|
||||||
#if defined(RT_USING_POSIX_DEVIO) && defined(RT_USING_POSIX_PIPE)
|
#ifdef RT_USING_POSIX
|
||||||
dev->fops = (void*)&pipe_fops;
|
dev->fops = (void*)&pipe_fops;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
return pipe;
|
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 rt_pipe_delete(const char *name)
|
||||||
{
|
{
|
||||||
int result = 0;
|
int result = 0;
|
||||||
|
@ -687,17 +529,7 @@ int rt_pipe_delete(const char *name)
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
#if defined(RT_USING_POSIX_DEVIO) && defined(RT_USING_POSIX_PIPE)
|
#ifdef RT_USING_POSIX
|
||||||
/**
|
|
||||||
* @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.
|
|
||||||
*/
|
|
||||||
int pipe(int fildes[2])
|
int pipe(int fildes[2])
|
||||||
{
|
{
|
||||||
rt_pipe_t *pipe;
|
rt_pipe_t *pipe;
|
||||||
|
@ -707,7 +539,7 @@ int pipe(int fildes[2])
|
||||||
|
|
||||||
rt_snprintf(dname, sizeof(dname), "pipe%d", pipeno++);
|
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)
|
if (pipe == RT_NULL)
|
||||||
{
|
{
|
||||||
return -1;
|
return -1;
|
||||||
|
@ -731,22 +563,11 @@ int pipe(int fildes[2])
|
||||||
return 0;
|
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)
|
int mkfifo(const char *path, mode_t mode)
|
||||||
{
|
{
|
||||||
rt_pipe_t *pipe;
|
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)
|
if (pipe == RT_NULL)
|
||||||
{
|
{
|
||||||
return -1;
|
return -1;
|
||||||
|
@ -754,4 +575,4 @@ int mkfifo(const char *path, mode_t mode)
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
#endif /* defined(RT_USING_POSIX_DEVIO) && defined(RT_USING_POSIX_PIPE) */
|
#endif
|
||||||
|
|
|
@ -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->buf_size = buf_size;
|
||||||
rbb->blk_set = block_set;
|
rbb->blk_set = block_set;
|
||||||
rbb->blk_max_num = blk_max_num;
|
rbb->blk_max_num = blk_max_num;
|
||||||
rbb->tail = &rbb->blk_list;
|
|
||||||
rt_slist_init(&rbb->blk_list);
|
rt_slist_init(&rbb->blk_list);
|
||||||
rt_slist_init(&rbb->free_list);
|
|
||||||
/* initialize block status */
|
/* initialize block status */
|
||||||
for (i = 0; i < blk_max_num; i++)
|
for (i = 0; i < blk_max_num; i++)
|
||||||
{
|
{
|
||||||
block_set[i].status = RT_RBB_BLK_UNUSED;
|
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);
|
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)
|
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);
|
RT_ASSERT(rbb);
|
||||||
|
|
||||||
if (rt_slist_isempty(&rbb->free_list))
|
for (i = 0; i < rbb->blk_max_num; i ++)
|
||||||
{
|
{
|
||||||
|
if (rbb->blk_set[i].status == RT_RBB_BLK_UNUSED)
|
||||||
|
{
|
||||||
|
return &rbb->blk_set[i];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return RT_NULL;
|
return RT_NULL;
|
||||||
}
|
|
||||||
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;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -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);
|
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);
|
head = rt_slist_first_entry(&rbb->blk_list, struct rt_rbb_blk, list);
|
||||||
/* get tail rbb blk object */
|
tail = rt_slist_tail_entry(&rbb->blk_list, struct rt_rbb_blk, list);
|
||||||
tail = rt_slist_entry(rbb->tail, struct rt_rbb_blk, list);
|
|
||||||
if (head->buf <= tail->buf)
|
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)
|
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->status = RT_RBB_BLK_INITED;
|
||||||
new_rbb->buf = tail->buf + tail->size;
|
new_rbb->buf = tail->buf + tail->size;
|
||||||
new_rbb->size = blk_size;
|
new_rbb->size = blk_size;
|
||||||
}
|
}
|
||||||
else if (empty2 >= 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->status = RT_RBB_BLK_INITED;
|
||||||
new_rbb->buf = rbb->buf;
|
new_rbb->buf = rbb->buf;
|
||||||
new_rbb->size = blk_size;
|
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)
|
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->status = RT_RBB_BLK_INITED;
|
||||||
new_rbb->buf = tail->buf + tail->size;
|
new_rbb->buf = tail->buf + tail->size;
|
||||||
new_rbb->size = blk_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
|
else
|
||||||
{
|
{
|
||||||
/* the list is empty */
|
/* 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->status = RT_RBB_BLK_INITED;
|
||||||
new_rbb->buf = rbb->buf;
|
new_rbb->buf = rbb->buf;
|
||||||
new_rbb->size = blk_size;
|
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);
|
RT_ASSERT(block->status != RT_RBB_BLK_UNUSED);
|
||||||
|
|
||||||
level = rt_hw_interrupt_disable();
|
level = rt_hw_interrupt_disable();
|
||||||
|
|
||||||
/* remove it on rbb block list */
|
/* 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;
|
block->status = RT_RBB_BLK_UNUSED;
|
||||||
rt_slist_insert(&rbb->free_list, &block->list);
|
|
||||||
rt_hw_interrupt_enable(level);
|
rt_hw_interrupt_enable(level);
|
||||||
}
|
}
|
||||||
RTM_EXPORT(rt_rbb_blk_free);
|
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_base_t level;
|
||||||
rt_size_t data_total_size = 0;
|
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_rbb_blk_t last_block = RT_NULL, block;
|
||||||
|
|
||||||
RT_ASSERT(rbb);
|
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();
|
level = rt_hw_interrupt_disable();
|
||||||
|
|
||||||
node = rt_slist_first(&rbb->blk_list);
|
for (node = rt_slist_first(&rbb->blk_list); node; node = rt_slist_next(node))
|
||||||
if (node != RT_NULL)
|
|
||||||
{
|
|
||||||
tmp = rt_slist_next(node);
|
|
||||||
}
|
|
||||||
for (; node; node = tmp, tmp = rt_slist_next(node))
|
|
||||||
{
|
{
|
||||||
if (!last_block)
|
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;
|
last_block = block;
|
||||||
}
|
}
|
||||||
/* remove current block */
|
/* remove current block */
|
||||||
|
rt_slist_remove(&rbb->blk_list, &last_block->list);
|
||||||
data_total_size += last_block->size;
|
data_total_size += last_block->size;
|
||||||
last_block->status = RT_RBB_BLK_GET;
|
last_block->status = RT_RBB_BLK_GET;
|
||||||
blk_queue->blk_num++;
|
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 rt_rbb_blk_queue_len(rt_rbb_blk_queue_t blk_queue)
|
||||||
{
|
{
|
||||||
rt_size_t i = 0, data_total_size = 0;
|
rt_size_t i, data_total_size = 0;
|
||||||
rt_rbb_blk_t blk;
|
|
||||||
|
|
||||||
RT_ASSERT(blk_queue);
|
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;
|
data_total_size += blk_queue->blocks[i].size;
|
||||||
blk = rt_slist_entry(blk->list.next, struct rt_rbb_blk, list);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return data_total_size;
|
return data_total_size;
|
||||||
}
|
}
|
||||||
RTM_EXPORT(rt_rbb_blk_queue_len);
|
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)
|
void rt_rbb_blk_queue_free(rt_rbb_t rbb, rt_rbb_blk_queue_t blk_queue)
|
||||||
{
|
{
|
||||||
rt_size_t i = 0;
|
rt_size_t i;
|
||||||
rt_rbb_blk_t blk, next_blk;
|
|
||||||
|
|
||||||
RT_ASSERT(rbb);
|
RT_ASSERT(rbb);
|
||||||
RT_ASSERT(blk_queue);
|
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_queue->blocks[i]);
|
||||||
rt_rbb_blk_free(rbb, blk);
|
|
||||||
blk = next_blk;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
RTM_EXPORT(rt_rbb_blk_queue_free);
|
RTM_EXPORT(rt_rbb_blk_queue_free);
|
||||||
|
|
|
@ -15,13 +15,6 @@
|
||||||
#include <rtdevice.h>
|
#include <rtdevice.h>
|
||||||
#include <rtservice.h>
|
#include <rtservice.h>
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief This function will insert a node to the wait queue.
|
|
||||||
*
|
|
||||||
* @param queue is a pointer to the wait queue.
|
|
||||||
*
|
|
||||||
* @param node is a pointer to the node to be inserted.
|
|
||||||
*/
|
|
||||||
void rt_wqueue_add(rt_wqueue_t *queue, struct rt_wqueue_node *node)
|
void rt_wqueue_add(rt_wqueue_t *queue, struct rt_wqueue_node *node)
|
||||||
{
|
{
|
||||||
rt_base_t level;
|
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);
|
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)
|
void rt_wqueue_remove(struct rt_wqueue_node *node)
|
||||||
{
|
{
|
||||||
rt_base_t level;
|
rt_base_t level;
|
||||||
|
@ -47,30 +33,11 @@ void rt_wqueue_remove(struct rt_wqueue_node *node)
|
||||||
rt_hw_interrupt_enable(level);
|
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)
|
int __wqueue_default_wake(struct rt_wqueue_node *wait, void *key)
|
||||||
{
|
{
|
||||||
return 0;
|
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)
|
void rt_wqueue_wakeup(rt_wqueue_t *queue, void *key)
|
||||||
{
|
{
|
||||||
rt_base_t level;
|
rt_base_t level;
|
||||||
|
@ -107,18 +74,6 @@ void rt_wqueue_wakeup(rt_wqueue_t *queue, void *key)
|
||||||
rt_schedule();
|
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 rt_wqueue_wait(rt_wqueue_t *queue, int condition, int msec)
|
||||||
{
|
{
|
||||||
int tick;
|
int tick;
|
||||||
|
|
|
@ -309,7 +309,7 @@ rt_err_t rt_workqueue_submit_work(struct rt_workqueue *queue, struct rt_work *wo
|
||||||
*
|
*
|
||||||
* @return RT_EOK Success.
|
* @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_base_t level;
|
||||||
RT_ASSERT(queue != RT_NULL);
|
RT_ASSERT(queue != RT_NULL);
|
||||||
|
|
|
@ -738,7 +738,7 @@ static rt_size_t _vcom_rb_block_put(struct vcom *data, const rt_uint8_t *buf, rt
|
||||||
return size;
|
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 ufunction *func;
|
||||||
struct vcom *data;
|
struct vcom *data;
|
||||||
|
|
|
@ -84,7 +84,7 @@ void rt_wlan_cfg_init(void)
|
||||||
rt_memset(cfg_cache, 0, sizeof(struct rt_wlan_cfg_des));
|
rt_memset(cfg_cache, 0, sizeof(struct rt_wlan_cfg_des));
|
||||||
}
|
}
|
||||||
/* init mutex lock */
|
/* 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);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -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;
|
struct rt_wlan_device *wlan = (struct rt_wlan_device *)dev;
|
||||||
rt_err_t result = RT_EOK;
|
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)
|
if (wlan->ops->wlan_init)
|
||||||
result = wlan->ops->wlan_init(wlan);
|
result = wlan->ops->wlan_init(wlan);
|
||||||
|
|
|
@ -2011,10 +2011,10 @@ int rt_wlan_init(void)
|
||||||
rt_memset(&_ap_mgnt, 0, sizeof(struct rt_wlan_mgnt_des));
|
rt_memset(&_ap_mgnt, 0, sizeof(struct rt_wlan_mgnt_des));
|
||||||
rt_memset(&scan_result, 0, sizeof(struct rt_wlan_scan_result));
|
rt_memset(&scan_result, 0, sizeof(struct rt_wlan_scan_result));
|
||||||
rt_memset(&sta_info, 0, sizeof(struct rt_wlan_sta_des));
|
rt_memset(&sta_info, 0, sizeof(struct rt_wlan_sta_des));
|
||||||
rt_mutex_init(&mgnt_mutex, "mgnt", RT_IPC_FLAG_PRIO);
|
rt_mutex_init(&mgnt_mutex, "mgnt", RT_IPC_FLAG_FIFO);
|
||||||
rt_mutex_init(&scan_result_mutex, "scan", RT_IPC_FLAG_PRIO);
|
rt_mutex_init(&scan_result_mutex, "scan", RT_IPC_FLAG_FIFO);
|
||||||
rt_mutex_init(&sta_info_mutex, "sta", RT_IPC_FLAG_PRIO);
|
rt_mutex_init(&sta_info_mutex, "sta", RT_IPC_FLAG_FIFO);
|
||||||
rt_mutex_init(&complete_mutex, "complete", RT_IPC_FLAG_PRIO);
|
rt_mutex_init(&complete_mutex, "complete", RT_IPC_FLAG_FIFO);
|
||||||
#ifdef RT_WLAN_AUTO_CONNECT_ENABLE
|
#ifdef RT_WLAN_AUTO_CONNECT_ENABLE
|
||||||
rt_timer_init(&reconnect_time, "wifi_tim", rt_wlan_cyclic_check, RT_NULL,
|
rt_timer_init(&reconnect_time, "wifi_tim", rt_wlan_cyclic_check, RT_NULL,
|
||||||
rt_tick_from_millisecond(AUTO_CONNECTION_PERIOD_MS),
|
rt_tick_from_millisecond(AUTO_CONNECTION_PERIOD_MS),
|
||||||
|
|
|
@ -9,7 +9,7 @@ msh.c
|
||||||
if GetDepend('MSH_USING_BUILT_IN_COMMANDS'):
|
if GetDepend('MSH_USING_BUILT_IN_COMMANDS'):
|
||||||
src += ['cmd.c']
|
src += ['cmd.c']
|
||||||
|
|
||||||
if GetDepend('DFS_USING_POSIX'):
|
if GetDepend('RT_USING_DFS'):
|
||||||
src += ['msh_file.c']
|
src += ['msh_file.c']
|
||||||
|
|
||||||
CPPPATH = [cwd]
|
CPPPATH = [cwd]
|
||||||
|
|
|
@ -751,9 +751,9 @@ long list_timer(void)
|
||||||
|
|
||||||
maxlen = RT_NAME_MAX;
|
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);
|
object_split(maxlen);
|
||||||
rt_kprintf(" ---------- ---------- ----------- ---------\n");
|
rt_kprintf(" ---------- ---------- -----------\n");
|
||||||
do
|
do
|
||||||
{
|
{
|
||||||
next = list_get_next(next, &find_arg);
|
next = list_get_next(next, &find_arg);
|
||||||
|
@ -781,13 +781,9 @@ long list_timer(void)
|
||||||
timer->init_tick,
|
timer->init_tick,
|
||||||
timer->timeout_tick);
|
timer->timeout_tick);
|
||||||
if (timer->parent.flag & RT_TIMER_FLAG_ACTIVATED)
|
if (timer->parent.flag & RT_TIMER_FLAG_ACTIVATED)
|
||||||
rt_kprintf("activated ");
|
rt_kprintf("activated\n");
|
||||||
else
|
else
|
||||||
rt_kprintf("deactivated ");
|
rt_kprintf("deactivated\n");
|
||||||
if (timer->parent.flag & RT_TIMER_FLAG_PERIODIC)
|
|
||||||
rt_kprintf("periodic\n");
|
|
||||||
else
|
|
||||||
rt_kprintf("one shot\n");
|
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -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 */
|
/* find out system call, which should be implemented in user program */
|
||||||
struct finsh_syscall *finsh_syscall_lookup(const char *name);
|
struct finsh_syscall *finsh_syscall_lookup(const char *name);
|
||||||
|
|
||||||
#if !defined(RT_USING_POSIX_STDIO) && defined(RT_USING_DEVICE)
|
#ifdef RT_USING_DEVICE
|
||||||
void finsh_set_device(const char *device_name);
|
void finsh_set_device(const char *device_name);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -15,17 +15,19 @@
|
||||||
#ifdef RT_USING_FINSH
|
#ifdef RT_USING_FINSH
|
||||||
|
|
||||||
#ifndef FINSH_ARG_MAX
|
#ifndef FINSH_ARG_MAX
|
||||||
#define FINSH_ARG_MAX 8
|
#define FINSH_ARG_MAX 8
|
||||||
#endif /* FINSH_ARG_MAX */
|
#endif
|
||||||
|
|
||||||
#include "msh.h"
|
#include "msh.h"
|
||||||
#include "shell.h"
|
#include "shell.h"
|
||||||
#ifdef DFS_USING_POSIX
|
|
||||||
#include <dfs_posix.h>
|
#ifdef RT_USING_DFS
|
||||||
#endif /* DFS_USING_POSIX */
|
#include <dfs_posix.h>
|
||||||
|
#endif
|
||||||
|
|
||||||
#ifdef RT_USING_MODULE
|
#ifdef RT_USING_MODULE
|
||||||
#include <dlmodule.h>
|
#include <dlmodule.h>
|
||||||
#endif /* RT_USING_MODULE */
|
#endif
|
||||||
|
|
||||||
typedef int (*cmd_function_t)(int argc, char **argv);
|
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
|
#ifdef RT_USING_HEAP
|
||||||
int cmd_free(int argc, char **argv)
|
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);
|
#ifdef RT_USING_MEMHEAP_AS_HEAP
|
||||||
rt_kprintf("total : %d\n", total);
|
list_memheap();
|
||||||
rt_kprintf("used : %d\n", used);
|
#else /* RT_USING_MEMHEAP_AS_HEAP */
|
||||||
rt_kprintf("maximum : %d\n", max_used);
|
list_mem();
|
||||||
|
#endif
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
MSH_CMD_EXPORT_ALIAS(cmd_free, free, Show the memory usage in the system.);
|
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;
|
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.
|
/* Return 0 on module executed. Other value indicate error.
|
||||||
*/
|
*/
|
||||||
int msh_exec_module(const char *cmd_line, int size)
|
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);
|
rt_free(pg_name);
|
||||||
return ret;
|
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)
|
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;
|
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)
|
static int _msh_exec_lwp(char *cmd, rt_size_t length)
|
||||||
{
|
{
|
||||||
int argc;
|
int argc;
|
||||||
|
@ -322,7 +326,7 @@ static int _msh_exec_lwp(char *cmd, rt_size_t length)
|
||||||
|
|
||||||
return 0;
|
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)
|
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;
|
return cmd_ret;
|
||||||
}
|
}
|
||||||
#ifdef DFS_USING_POSIX
|
#ifdef RT_USING_DFS
|
||||||
#ifdef DFS_USING_WORKDIR
|
#ifdef DFS_USING_WORKDIR
|
||||||
if (msh_exec_script(cmd, length) == 0)
|
if (msh_exec_script(cmd, length) == 0)
|
||||||
{
|
{
|
||||||
|
@ -367,7 +371,7 @@ int msh_exec(char *cmd, rt_size_t length)
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
#endif /* RT_USING_LWP */
|
#endif /* RT_USING_LWP */
|
||||||
#endif /* DFS_USING_POSIX */
|
#endif /* RT_USING_DFS */
|
||||||
|
|
||||||
/* truncate the cmd at the first space. */
|
/* truncate the cmd at the first space. */
|
||||||
{
|
{
|
||||||
|
@ -396,7 +400,7 @@ static int str_common(const char *str1, const char *str2)
|
||||||
return (str - str1);
|
return (str - str1);
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef DFS_USING_POSIX
|
#ifdef RT_USING_DFS
|
||||||
void msh_auto_complete_path(char *path)
|
void msh_auto_complete_path(char *path)
|
||||||
{
|
{
|
||||||
DIR *dir = RT_NULL;
|
DIR *dir = RT_NULL;
|
||||||
|
@ -517,7 +521,7 @@ void msh_auto_complete_path(char *path)
|
||||||
closedir(dir);
|
closedir(dir);
|
||||||
rt_free(full_path);
|
rt_free(full_path);
|
||||||
}
|
}
|
||||||
#endif /* DFS_USING_POSIX */
|
#endif /* RT_USING_DFS */
|
||||||
|
|
||||||
void msh_auto_complete(char *prefix)
|
void msh_auto_complete(char *prefix)
|
||||||
{
|
{
|
||||||
|
@ -534,7 +538,7 @@ void msh_auto_complete(char *prefix)
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef DFS_USING_POSIX
|
#ifdef RT_USING_DFS
|
||||||
/* check whether a spare in the command */
|
/* check whether a spare in the command */
|
||||||
{
|
{
|
||||||
char *ptr;
|
char *ptr;
|
||||||
|
@ -560,7 +564,7 @@ void msh_auto_complete(char *prefix)
|
||||||
}
|
}
|
||||||
#endif /* RT_USING_MODULE */
|
#endif /* RT_USING_MODULE */
|
||||||
}
|
}
|
||||||
#endif /* DFS_USING_POSIX */
|
#endif /* RT_USING_DFS */
|
||||||
|
|
||||||
/* checks in internal command */
|
/* checks in internal command */
|
||||||
{
|
{
|
||||||
|
|
|
@ -11,7 +11,7 @@
|
||||||
|
|
||||||
#include <rtthread.h>
|
#include <rtthread.h>
|
||||||
|
|
||||||
#if defined(RT_USING_FINSH) && defined(DFS_USING_POSIX)
|
#if defined(RT_USING_FINSH) && defined(RT_USING_DFS)
|
||||||
|
|
||||||
#include <finsh.h>
|
#include <finsh.h>
|
||||||
#include "msh.h"
|
#include "msh.h"
|
||||||
|
@ -612,7 +612,7 @@ static int cmd_tail(int argc, char **argv)
|
||||||
rt_uint32_t target_line = 0;
|
rt_uint32_t target_line = 0;
|
||||||
rt_uint32_t current_line = 0;
|
rt_uint32_t current_line = 0;
|
||||||
rt_uint32_t required_lines = 0;
|
rt_uint32_t required_lines = 0;
|
||||||
rt_uint32_t start_line = 0;
|
rt_uint32_t after_xxx_line = 0;
|
||||||
|
|
||||||
if (argc < 2)
|
if (argc < 2)
|
||||||
{
|
{
|
||||||
|
@ -632,7 +632,7 @@ static int cmd_tail(int argc, char **argv)
|
||||||
}
|
}
|
||||||
else
|
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];
|
file_name = argv[3];
|
||||||
}
|
}
|
||||||
|
@ -651,10 +651,6 @@ static int cmd_tail(int argc, char **argv)
|
||||||
|
|
||||||
while ((read(fd, &c, sizeof(char))) > 0)
|
while ((read(fd, &c, sizeof(char))) > 0)
|
||||||
{
|
{
|
||||||
if(total_lines == 0)
|
|
||||||
{
|
|
||||||
total_lines++;
|
|
||||||
}
|
|
||||||
if (c == '\n')
|
if (c == '\n')
|
||||||
{
|
{
|
||||||
total_lines++;
|
total_lines++;
|
||||||
|
@ -663,11 +659,11 @@ static int cmd_tail(int argc, char **argv)
|
||||||
|
|
||||||
rt_kprintf("\nTotal Number of lines:%d\n", total_lines);
|
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
|
else
|
||||||
{
|
{
|
||||||
|
@ -690,14 +686,14 @@ static int cmd_tail(int argc, char **argv)
|
||||||
|
|
||||||
while ((read(fd, &c, sizeof(char))) > 0)
|
while ((read(fd, &c, sizeof(char))) > 0)
|
||||||
{
|
{
|
||||||
if (current_line >= target_line)
|
|
||||||
{
|
|
||||||
rt_kprintf("%c", c);
|
|
||||||
}
|
|
||||||
if (c == '\n')
|
if (c == '\n')
|
||||||
{
|
{
|
||||||
current_line++;
|
current_line++;
|
||||||
}
|
}
|
||||||
|
if (current_line > target_line)
|
||||||
|
{
|
||||||
|
rt_kprintf("%c", c);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
rt_kprintf("\n");
|
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);
|
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) */
|
||||||
|
|
||||||
|
|
|
@ -27,9 +27,9 @@
|
||||||
#include "shell.h"
|
#include "shell.h"
|
||||||
#include "msh.h"
|
#include "msh.h"
|
||||||
|
|
||||||
#ifdef DFS_USING_POSIX
|
#if defined(RT_USING_DFS)
|
||||||
#include <dfs_posix.h>
|
#include <dfs_posix.h>
|
||||||
#endif /* DFS_USING_POSIX */
|
#endif /* RT_USING_DFS */
|
||||||
|
|
||||||
/* finsh thread */
|
/* finsh thread */
|
||||||
#ifndef RT_USING_HEAP
|
#ifndef RT_USING_HEAP
|
||||||
|
@ -104,7 +104,7 @@ const char *finsh_get_prompt(void)
|
||||||
}
|
}
|
||||||
strcpy(finsh_prompt, _MSH_PROMPT);
|
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 */
|
/* get current working directory */
|
||||||
getcwd(&finsh_prompt[rt_strlen(finsh_prompt)], RT_CONSOLEBUF_SIZE - rt_strlen(finsh_prompt));
|
getcwd(&finsh_prompt[rt_strlen(finsh_prompt)], RT_CONSOLEBUF_SIZE - rt_strlen(finsh_prompt));
|
||||||
#endif
|
#endif
|
||||||
|
@ -145,17 +145,10 @@ void finsh_set_prompt_mode(rt_uint32_t prompt_mode)
|
||||||
int finsh_getchar(void)
|
int finsh_getchar(void)
|
||||||
{
|
{
|
||||||
#ifdef RT_USING_DEVICE
|
#ifdef RT_USING_DEVICE
|
||||||
char ch = 0;
|
#ifdef RT_USING_POSIX
|
||||||
#ifdef RT_USING_POSIX_STDIO
|
return getchar();
|
||||||
if(read(STDIN_FILENO, &ch, 1) > 0)
|
|
||||||
{
|
|
||||||
return ch;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
return -1; /* EOF */
|
|
||||||
}
|
|
||||||
#else
|
#else
|
||||||
|
char ch = 0;
|
||||||
rt_device_t device;
|
rt_device_t device;
|
||||||
|
|
||||||
RT_ASSERT(shell != RT_NULL);
|
RT_ASSERT(shell != RT_NULL);
|
||||||
|
@ -170,14 +163,14 @@ int finsh_getchar(void)
|
||||||
rt_sem_take(&shell->rx_sem, RT_WAITING_FOREVER);
|
rt_sem_take(&shell->rx_sem, RT_WAITING_FOREVER);
|
||||||
|
|
||||||
return ch;
|
return ch;
|
||||||
#endif /* RT_USING_POSIX_STDIO */
|
#endif /* RT_USING_POSIX */
|
||||||
#else
|
#else
|
||||||
extern char rt_hw_console_getchar(void);
|
extern char rt_hw_console_getchar(void);
|
||||||
return rt_hw_console_getchar();
|
return rt_hw_console_getchar();
|
||||||
#endif /* RT_USING_DEVICE */
|
#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)
|
static rt_err_t finsh_rx_ind(rt_device_t dev, rt_size_t size)
|
||||||
{
|
{
|
||||||
RT_ASSERT(shell != RT_NULL);
|
RT_ASSERT(shell != RT_NULL);
|
||||||
|
@ -241,7 +234,7 @@ const char *finsh_get_device()
|
||||||
RT_ASSERT(shell != RT_NULL);
|
RT_ASSERT(shell != RT_NULL);
|
||||||
return shell->device->parent.name;
|
return shell->device->parent.name;
|
||||||
}
|
}
|
||||||
#endif /* !defined(RT_USING_POSIX_STDIO) && defined(RT_USING_DEVICE) */
|
#endif
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @ingroup finsh
|
* @ingroup finsh
|
||||||
|
@ -443,7 +436,7 @@ void finsh_thread_entry(void *parameter)
|
||||||
shell->echo_mode = 0;
|
shell->echo_mode = 0;
|
||||||
#endif
|
#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 */
|
/* set console device as shell device */
|
||||||
if (shell->device == RT_NULL)
|
if (shell->device == RT_NULL)
|
||||||
{
|
{
|
||||||
|
@ -453,7 +446,7 @@ void finsh_thread_entry(void *parameter)
|
||||||
finsh_set_device(console->parent.name);
|
finsh_set_device(console->parent.name);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
#endif /* !defined(RT_USING_POSIX_STDIO) && defined(RT_USING_DEVICE) */
|
#endif
|
||||||
|
|
||||||
#ifdef FINSH_USING_AUTH
|
#ifdef FINSH_USING_AUTH
|
||||||
/* set the default password when the password isn't setting */
|
/* set the default password when the password isn't setting */
|
||||||
|
|
|
@ -78,7 +78,7 @@ struct finsh_shell
|
||||||
rt_uint16_t line_position;
|
rt_uint16_t line_position;
|
||||||
rt_uint16_t line_curpos;
|
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;
|
rt_device_t device;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
@ -91,6 +91,7 @@ void finsh_set_echo(rt_uint32_t echo);
|
||||||
rt_uint32_t finsh_get_echo(void);
|
rt_uint32_t finsh_get_echo(void);
|
||||||
|
|
||||||
int finsh_system_init(void);
|
int finsh_system_init(void);
|
||||||
|
void finsh_set_device(const char *device_name);
|
||||||
const char *finsh_get_device(void);
|
const char *finsh_get_device(void);
|
||||||
int finsh_getchar(void);
|
int finsh_getchar(void);
|
||||||
|
|
||||||
|
|
|
@ -1,2 +0,0 @@
|
||||||
# RT-Thread Legacy
|
|
||||||
|
|
|
@ -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')
|
|
|
@ -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);
|
|
||||||
}
|
|
|
@ -1,25 +0,0 @@
|
||||||
/*
|
|
||||||
* Copyright (c) 2006-2021, RT-Thread Development Team
|
|
||||||
*
|
|
||||||
* SPDX-License-Identifier: Apache-2.0
|
|
||||||
*
|
|
||||||
* Change Logs:
|
|
||||||
* Date Author Notes
|
|
||||||
* 2021-11-14 Meco Man the first version
|
|
||||||
*/
|
|
||||||
|
|
||||||
#ifndef __WORKQUEUE_LEGACY_H__
|
|
||||||
#define __WORKQUEUE_LEGACY_H__
|
|
||||||
|
|
||||||
#include <ipc/workqueue.h>
|
|
||||||
|
|
||||||
struct rt_delayed_work
|
|
||||||
{
|
|
||||||
struct rt_work work;
|
|
||||||
};
|
|
||||||
|
|
||||||
void rt_delayed_work_init(struct rt_delayed_work *work,
|
|
||||||
void (*work_func)(struct rt_work *work,
|
|
||||||
void *work_data), void *work_data);
|
|
||||||
|
|
||||||
#endif
|
|
|
@ -1,27 +0,0 @@
|
||||||
/*
|
|
||||||
* Copyright (c) 2006-2021, RT-Thread Development Team
|
|
||||||
*
|
|
||||||
* SPDX-License-Identifier: Apache-2.0
|
|
||||||
*
|
|
||||||
* Change Logs:
|
|
||||||
* Date Author Notes
|
|
||||||
* 2021-11-14 Meco Man the first version
|
|
||||||
*/
|
|
||||||
|
|
||||||
#ifndef __RT_LEGACY_H__
|
|
||||||
#define __RT_LEGACY_H__
|
|
||||||
|
|
||||||
#include <rtconfig.h>
|
|
||||||
|
|
||||||
/* rtlibc */
|
|
||||||
#include <stdint.h>
|
|
||||||
#include <stddef.h>
|
|
||||||
|
|
||||||
/* IPC */
|
|
||||||
#ifdef RT_USING_DEVICE_IPC
|
|
||||||
#include "ipc/workqueue_legacy.h"
|
|
||||||
#endif /* RT_USING_DEVICE_IPC */
|
|
||||||
|
|
||||||
/* FinSH */
|
|
||||||
|
|
||||||
#endif /* __RT_LEGACY_H__ */
|
|
|
@ -1,20 +1,71 @@
|
||||||
menu "POSIX layer and C standard library"
|
menu "POSIX layer and C standard library"
|
||||||
|
|
||||||
config RT_USING_MODULE
|
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_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"
|
bool "Enable dynamic module with dlopen/dlsym/dlclose feature"
|
||||||
default n
|
default n
|
||||||
|
|
||||||
if RT_USING_MODULE
|
if RT_USING_MODULE
|
||||||
config RT_USING_CUSTOM_DLMODULE
|
config RT_USING_CUSTOM_DLMODULE
|
||||||
bool "Enable load dynamic module by custom"
|
bool "Enable load dynamic module by custom"
|
||||||
default n
|
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
|
endif
|
||||||
|
|
||||||
config RT_LIBC_DEFAULT_TIMEZONE
|
config RT_LIBC_DEFAULT_TIMEZONE
|
||||||
|
depends on (RT_LIBC_USING_TIME || RT_USING_LIBC)
|
||||||
int "Set the default time zone (UTC+)"
|
int "Set the default time zone (UTC+)"
|
||||||
range -12 12
|
range -12 12
|
||||||
default 8
|
default 8
|
||||||
|
|
||||||
source "$RTT_DIR/components/libc/posix/Kconfig"
|
|
||||||
|
|
||||||
endmenu
|
endmenu
|
||||||
|
|
|
@ -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')
|
|
@ -11,7 +11,7 @@
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
#include <rthw.h>
|
#include <rthw.h>
|
||||||
#include <dfs_posix.h>
|
#include <dfs_posix.h>
|
||||||
#include "aio.h"
|
#include "posix_aio.h"
|
||||||
|
|
||||||
struct rt_workqueue* aio_queue = NULL;
|
struct rt_workqueue* aio_queue = NULL;
|
||||||
|
|
|
@ -8,8 +8,8 @@
|
||||||
* 2017/12/30 Bernard The first version.
|
* 2017/12/30 Bernard The first version.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#ifndef __AIO_H__
|
#ifndef POSIX_AIO_H__
|
||||||
#define __AIO_H__
|
#define POSIX_AIO_H__
|
||||||
|
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <sys/signal.h>
|
#include <sys/signal.h>
|
|
@ -1,3 +1,9 @@
|
||||||
# ARMLIB (Keil-MDK) porting for RT-Thread
|
# 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/
|
https://www.keil.com/support/man/docs/armlib/
|
|
@ -1,12 +1,21 @@
|
||||||
from building import *
|
from building import *
|
||||||
Import('rtconfig')
|
Import('rtconfig')
|
||||||
|
|
||||||
src = Glob('*.c')
|
src = Glob('*.c') + Glob('*.cpp')
|
||||||
|
cwd = GetCurrentDir()
|
||||||
group = []
|
group = []
|
||||||
|
|
||||||
|
CPPPATH = [cwd]
|
||||||
CPPDEFINES = ['RT_USING_ARM_LIBC']
|
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':
|
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')
|
Return('group')
|
||||||
|
|
|
@ -0,0 +1,40 @@
|
||||||
|
/*
|
||||||
|
* Copyright (c) 2006-2021, RT-Thread Development Team
|
||||||
|
*
|
||||||
|
* SPDX-License-Identifier: Apache-2.0
|
||||||
|
*
|
||||||
|
* Change Logs:
|
||||||
|
* Date Author Notes
|
||||||
|
* 2017/10/15 bernard the first version
|
||||||
|
*/
|
||||||
|
#include <fcntl.h>
|
||||||
|
#include <rtthread.h>
|
||||||
|
#include "libc.h"
|
||||||
|
|
||||||
|
#ifdef RT_USING_PTHREADS
|
||||||
|
#include <pthread.h>
|
||||||
|
#endif
|
||||||
|
|
||||||
|
int libc_system_init(void)
|
||||||
|
{
|
||||||
|
#if defined(RT_USING_DFS) & defined(RT_USING_DFS_DEVFS)
|
||||||
|
rt_device_t dev_console;
|
||||||
|
|
||||||
|
dev_console = rt_console_get_device();
|
||||||
|
if (dev_console)
|
||||||
|
{
|
||||||
|
#if defined(RT_USING_POSIX)
|
||||||
|
libc_stdio_set_console(dev_console->parent.name, O_RDWR);
|
||||||
|
#else
|
||||||
|
libc_stdio_set_console(dev_console->parent.name, O_WRONLY);
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#if defined RT_USING_PTHREADS && !defined RT_USING_COMPONENTS_INIT
|
||||||
|
pthread_system_init();
|
||||||
|
#endif
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
INIT_COMPONENT_EXPORT(libc_system_init);
|
|
@ -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
|
|
@ -0,0 +1,43 @@
|
||||||
|
/*
|
||||||
|
* Copyright (c) 2006-2021, RT-Thread Development Team
|
||||||
|
*
|
||||||
|
* SPDX-License-Identifier: Apache-2.0
|
||||||
|
*
|
||||||
|
* Change Logs:
|
||||||
|
* 2014-08-03 bernard Add file header.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <rtthread.h>
|
||||||
|
#include <stddef.h>
|
||||||
|
|
||||||
|
#ifdef RT_USING_HEAP
|
||||||
|
|
||||||
|
#ifdef __CC_ARM
|
||||||
|
/* avoid the heap and heap-using library functions supplied by arm */
|
||||||
|
#pragma import(__use_no_heap)
|
||||||
|
#endif
|
||||||
|
|
||||||
|
void *malloc(size_t n)
|
||||||
|
{
|
||||||
|
return rt_malloc(n);
|
||||||
|
}
|
||||||
|
RTM_EXPORT(malloc);
|
||||||
|
|
||||||
|
void *realloc(void *rmem, size_t newsize)
|
||||||
|
{
|
||||||
|
return rt_realloc(rmem, newsize);
|
||||||
|
}
|
||||||
|
RTM_EXPORT(realloc);
|
||||||
|
|
||||||
|
void *calloc(size_t nelem, size_t elsize)
|
||||||
|
{
|
||||||
|
return rt_calloc(nelem, elsize);
|
||||||
|
}
|
||||||
|
RTM_EXPORT(calloc);
|
||||||
|
|
||||||
|
void free(void *rmem)
|
||||||
|
{
|
||||||
|
rt_free(rmem);
|
||||||
|
}
|
||||||
|
RTM_EXPORT(free);
|
||||||
|
#endif
|
|
@ -0,0 +1,51 @@
|
||||||
|
/*
|
||||||
|
* Copyright (c) 2006-2021, RT-Thread Development Team
|
||||||
|
*
|
||||||
|
* SPDX-License-Identifier: Apache-2.0
|
||||||
|
*
|
||||||
|
* Change Logs:
|
||||||
|
* Date Author Notes
|
||||||
|
* 2017/10/15 bernard implement stdio for armcc.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <string.h>
|
||||||
|
|
||||||
|
#include <rtthread.h>
|
||||||
|
#include "libc.h"
|
||||||
|
|
||||||
|
#if defined(RT_USING_DFS) && defined(RT_USING_DFS_DEVFS)
|
||||||
|
#include <dfs_posix.h>
|
||||||
|
|
||||||
|
#define STDIO_DEVICE_NAME_MAX 32
|
||||||
|
|
||||||
|
static int std_fd = -1;
|
||||||
|
|
||||||
|
int libc_stdio_set_console(const char* device_name, int mode)
|
||||||
|
{
|
||||||
|
int fd;
|
||||||
|
char name[STDIO_DEVICE_NAME_MAX];
|
||||||
|
|
||||||
|
snprintf(name, sizeof(name) - 1, "/dev/%s", device_name);
|
||||||
|
name[STDIO_DEVICE_NAME_MAX - 1] = '\0';
|
||||||
|
|
||||||
|
fd = open(name, mode, 0);
|
||||||
|
if (fd >= 0)
|
||||||
|
{
|
||||||
|
if (std_fd >= 0)
|
||||||
|
{
|
||||||
|
close(std_fd);
|
||||||
|
}
|
||||||
|
std_fd = fd;
|
||||||
|
}
|
||||||
|
|
||||||
|
return std_fd;
|
||||||
|
}
|
||||||
|
|
||||||
|
int libc_stdio_get_console(void)
|
||||||
|
{
|
||||||
|
return std_fd;
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif
|
|
@ -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 <rtthread.h>
|
|
||||||
#include <stddef.h>
|
|
||||||
|
|
||||||
#ifndef RT_USING_HEAP
|
|
||||||
#define DBG_TAG "armlibc.syscall.mem"
|
|
||||||
#define DBG_LVL DBG_INFO
|
|
||||||
#include <rtdbg.h>
|
|
||||||
|
|
||||||
#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);
|
|
|
@ -15,22 +15,21 @@
|
||||||
* 2020-02-14 Meco Man implement _sys_tmpnam()
|
* 2020-02-14 Meco Man implement _sys_tmpnam()
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include <rt_sys.h>
|
|
||||||
#include <rtthread.h>
|
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <fcntl.h>
|
#include <rt_sys.h>
|
||||||
#include <unistd.h>
|
|
||||||
#include <sys/stat.h>
|
#include <rtthread.h>
|
||||||
#include <compiler_private.h>
|
|
||||||
#ifdef RT_USING_POSIX_STDIO
|
|
||||||
#include "libc.h"
|
#include "libc.h"
|
||||||
#endif /* RT_USING_POSIX_STDIO */
|
|
||||||
|
#ifdef RT_USING_DFS
|
||||||
|
#include <dfs_posix.h>
|
||||||
|
#endif
|
||||||
|
|
||||||
#define DBG_TAG "armlibc.syscalls"
|
#define DBG_TAG "armlibc.syscalls"
|
||||||
#define DBG_LVL DBG_INFO
|
#define DBG_LVL DBG_INFO
|
||||||
#include <rtdbg.h>
|
#include <rtdbg.h>
|
||||||
|
|
||||||
#ifdef __clang__
|
#ifdef __CLANG_ARM
|
||||||
__asm(".global __use_no_semihosting\n\t");
|
__asm(".global __use_no_semihosting\n\t");
|
||||||
#else
|
#else
|
||||||
#pragma import(__use_no_semihosting_swi)
|
#pragma import(__use_no_semihosting_swi)
|
||||||
|
@ -56,10 +55,10 @@ const char __stderr_name[] = "STDERR";
|
||||||
*/
|
*/
|
||||||
FILEHANDLE _sys_open(const char *name, int openmode)
|
FILEHANDLE _sys_open(const char *name, int openmode)
|
||||||
{
|
{
|
||||||
#ifdef DFS_USING_POSIX
|
#ifdef RT_USING_DFS
|
||||||
int fd;
|
int fd;
|
||||||
int mode = O_RDONLY;
|
int mode = O_RDONLY;
|
||||||
#endif /* DFS_USING_POSIX */
|
#endif
|
||||||
|
|
||||||
/* Register standard Input Output devices. */
|
/* Register standard Input Output devices. */
|
||||||
if (strcmp(name, __stdin_name) == 0)
|
if (strcmp(name, __stdin_name) == 0)
|
||||||
|
@ -69,9 +68,8 @@ FILEHANDLE _sys_open(const char *name, int openmode)
|
||||||
if (strcmp(name, __stderr_name) == 0)
|
if (strcmp(name, __stderr_name) == 0)
|
||||||
return (STDERR);
|
return (STDERR);
|
||||||
|
|
||||||
#ifndef DFS_USING_POSIX
|
#ifndef RT_USING_DFS
|
||||||
LOG_W("%s: %s", __func__, _WARNING_WITHOUT_FS);
|
return -1;
|
||||||
return 0; /* error */
|
|
||||||
#else
|
#else
|
||||||
/* Correct openmode from fopen to open */
|
/* Correct openmode from fopen to open */
|
||||||
if (openmode & OPEN_PLUS)
|
if (openmode & OPEN_PLUS)
|
||||||
|
@ -101,23 +99,21 @@ FILEHANDLE _sys_open(const char *name, int openmode)
|
||||||
|
|
||||||
fd = open(name, mode, 0);
|
fd = open(name, mode, 0);
|
||||||
if (fd < 0)
|
if (fd < 0)
|
||||||
return 0; /* error */
|
return -1;
|
||||||
else
|
else
|
||||||
return fd;
|
return fd;
|
||||||
#endif /* DFS_USING_POSIX */
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
int _sys_close(FILEHANDLE fh)
|
int _sys_close(FILEHANDLE fh)
|
||||||
{
|
{
|
||||||
#ifdef DFS_USING_POSIX
|
#ifndef RT_USING_DFS
|
||||||
if (fh <= STDERR)
|
return 0;
|
||||||
return 0; /* error */
|
#else
|
||||||
|
if (fh <= STDERR) return 0;
|
||||||
|
|
||||||
return close(fh);
|
return close(fh);
|
||||||
#else
|
#endif
|
||||||
LOG_W("%s: %s", __func__, _WARNING_WITHOUT_FS);
|
|
||||||
return 0;
|
|
||||||
#endif /* DFS_USING_POSIX */
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
@ -147,96 +143,90 @@ int _sys_close(FILEHANDLE fh)
|
||||||
*/
|
*/
|
||||||
int _sys_read(FILEHANDLE fh, unsigned char *buf, unsigned len, int mode)
|
int _sys_read(FILEHANDLE fh, unsigned char *buf, unsigned len, int mode)
|
||||||
{
|
{
|
||||||
#ifdef DFS_USING_POSIX
|
#ifdef RT_USING_DFS
|
||||||
int size;
|
int size;
|
||||||
|
#endif
|
||||||
|
|
||||||
if (fh == STDIN)
|
if (fh == STDIN)
|
||||||
{
|
{
|
||||||
#ifdef RT_USING_POSIX_STDIO
|
#ifdef RT_USING_POSIX
|
||||||
if (libc_stdio_get_console() < 0)
|
if (libc_stdio_get_console() < 0)
|
||||||
{
|
{
|
||||||
LOG_W("Do not invoke standard output before initializing Compiler");
|
LOG_W("Do not invoke standard output before initializing libc");
|
||||||
return 0; /* error, but keep going */
|
return 0;
|
||||||
}
|
}
|
||||||
size = read(STDIN_FILENO, buf, len);
|
size = read(STDIN_FILENO, buf, len);
|
||||||
return len - size; /* success */
|
return len - size;
|
||||||
#else
|
#else
|
||||||
LOG_W("%s: %s", __func__, _WARNING_WITHOUT_STDIO);
|
/* no stdin */
|
||||||
return 0; /* error */
|
return -1;
|
||||||
#endif /* RT_USING_POSIX_STDIO */
|
#endif
|
||||||
}
|
}
|
||||||
else if (fh == STDOUT || fh == STDERR)
|
else if ((fh == STDOUT) || (fh == STDERR))
|
||||||
{
|
{
|
||||||
return -1; /* 100% error */
|
return -1;
|
||||||
}
|
}
|
||||||
else
|
|
||||||
{
|
#ifndef RT_USING_DFS
|
||||||
|
return 0;
|
||||||
|
#else
|
||||||
size = read(fh, buf, len);
|
size = read(fh, buf, len);
|
||||||
if (size >= 0)
|
if (size >= 0)
|
||||||
{
|
return len - size;
|
||||||
return len - size; /* success */
|
|
||||||
}
|
|
||||||
else
|
else
|
||||||
{
|
return -1;
|
||||||
return 0; /* error */
|
#endif
|
||||||
}
|
|
||||||
}
|
|
||||||
#else
|
|
||||||
LOG_W("%s: %s", __func__, _WARNING_WITHOUT_FS);
|
|
||||||
return 0; /* error */
|
|
||||||
#endif /* DFS_USING_POSIX */
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Write to a file. Returns 0 on success, negative on error, and
|
* Write to a file. Returns 0 on success, negative on error, and
|
||||||
* the number of characters _not_ written on partial success.
|
* the number of characters _not_ written on partial success.
|
||||||
* `mode' exists for historical reasons and must be ignored.
|
* `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)
|
int _sys_write(FILEHANDLE fh, const unsigned char *buf, unsigned len, int mode)
|
||||||
{
|
{
|
||||||
#ifdef DFS_USING_POSIX
|
#ifdef RT_USING_DFS
|
||||||
int size;
|
int size;
|
||||||
#endif /* DFS_USING_POSIX */
|
#endif
|
||||||
|
|
||||||
if (fh == STDOUT || fh == STDERR)
|
if ((fh == STDOUT) || (fh == STDERR))
|
||||||
{
|
{
|
||||||
#ifdef RT_USING_CONSOLE
|
#if !defined(RT_USING_CONSOLE) || !defined(RT_USING_DEVICE)
|
||||||
rt_device_t console;
|
return 0;
|
||||||
console = rt_console_get_device();
|
|
||||||
if (console)
|
|
||||||
{
|
|
||||||
rt_device_write(console, -1, buf, len);
|
|
||||||
}
|
|
||||||
return 0; /* success */
|
|
||||||
#else
|
#else
|
||||||
return 0; /* error */
|
#ifdef RT_USING_POSIX
|
||||||
#endif /* RT_USING_CONSOLE */
|
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)
|
else if (fh == STDIN)
|
||||||
{
|
{
|
||||||
return -1; /* 100% error */
|
return -1;
|
||||||
}
|
}
|
||||||
else
|
|
||||||
{
|
#ifndef RT_USING_DFS
|
||||||
#ifdef DFS_USING_POSIX
|
return 0;
|
||||||
|
#else
|
||||||
size = write(fh, buf, len);
|
size = write(fh, buf, len);
|
||||||
if (size >= 0)
|
if (size >= 0)
|
||||||
{
|
return len - size;
|
||||||
return len - size; /* success */
|
|
||||||
}
|
|
||||||
else
|
else
|
||||||
{
|
return -1;
|
||||||
return 0; /* error */
|
#endif
|
||||||
}
|
|
||||||
#else
|
|
||||||
LOG_W("%s: %s", __func__, _WARNING_WITHOUT_FS);
|
|
||||||
return 0; /* error */
|
|
||||||
#endif /* DFS_USING_POSIX */
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
@ -245,16 +235,16 @@ int _sys_write(FILEHANDLE fh, const unsigned char *buf, unsigned len, int mode)
|
||||||
*/
|
*/
|
||||||
int _sys_seek(FILEHANDLE fh, long pos)
|
int _sys_seek(FILEHANDLE fh, long pos)
|
||||||
{
|
{
|
||||||
#ifdef DFS_USING_POSIX
|
|
||||||
if (fh < STDERR)
|
if (fh < STDERR)
|
||||||
return 0; /* error */
|
return -1;
|
||||||
|
|
||||||
|
#ifndef RT_USING_DFS
|
||||||
|
return -1;
|
||||||
|
#else
|
||||||
|
|
||||||
/* position is relative to the start of file fh */
|
/* position is relative to the start of file fh */
|
||||||
return lseek(fh, pos, 0);
|
return lseek(fh, pos, 0);
|
||||||
#else
|
#endif
|
||||||
LOG_W("%s: %s", __func__, _WARNING_WITHOUT_FS);
|
|
||||||
return 0; /* error */
|
|
||||||
#endif /* DFS_USING_POSIX */
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -276,8 +266,11 @@ char *_sys_command_string(char *cmd, int len)
|
||||||
void _ttywrch(int ch)
|
void _ttywrch(int ch)
|
||||||
{
|
{
|
||||||
#ifdef RT_USING_CONSOLE
|
#ifdef RT_USING_CONSOLE
|
||||||
rt_kprintf("%c", (char)ch);
|
char c;
|
||||||
#endif /* RT_USING_CONSOLE */
|
|
||||||
|
c = (char)ch;
|
||||||
|
rt_kprintf(&c);
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
/* for exit() and abort() */
|
/* for exit() and abort() */
|
||||||
|
@ -296,18 +289,17 @@ RT_WEAK void _sys_exit(int return_code)
|
||||||
*/
|
*/
|
||||||
long _sys_flen(FILEHANDLE fh)
|
long _sys_flen(FILEHANDLE fh)
|
||||||
{
|
{
|
||||||
#ifdef DFS_USING_POSIX
|
#ifdef RT_USING_DFS
|
||||||
struct stat stat;
|
struct stat stat;
|
||||||
|
|
||||||
if (fh < STDERR)
|
if (fh < STDERR)
|
||||||
return 0; /* error */
|
return -1;
|
||||||
|
|
||||||
fstat(fh, &stat);
|
fstat(fh, &stat);
|
||||||
return stat.st_size;
|
return stat.st_size;
|
||||||
#else
|
#else
|
||||||
LOG_W("%s: %s", __func__, _WARNING_WITHOUT_FS);
|
return -1;
|
||||||
return 0;
|
#endif
|
||||||
#endif /* DFS_USING_POSIX */
|
|
||||||
}
|
}
|
||||||
|
|
||||||
int _sys_istty(FILEHANDLE fh)
|
int _sys_istty(FILEHANDLE fh)
|
||||||
|
@ -320,12 +312,11 @@ int _sys_istty(FILEHANDLE fh)
|
||||||
|
|
||||||
int remove(const char *filename)
|
int remove(const char *filename)
|
||||||
{
|
{
|
||||||
#ifdef DFS_USING_POSIX
|
#ifndef RT_USING_DFS
|
||||||
return unlink(filename);
|
return -1;
|
||||||
#else
|
#else
|
||||||
LOG_W("%s: %s", __func__, _WARNING_WITHOUT_FS);
|
return unlink(filename);
|
||||||
return 0; /* error */
|
#endif
|
||||||
#endif /* DFS_USING_POSIX */
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef __MICROLIB
|
#ifdef __MICROLIB
|
||||||
|
@ -333,30 +324,28 @@ int remove(const char *filename)
|
||||||
|
|
||||||
int fputc(int c, FILE *f)
|
int fputc(int c, FILE *f)
|
||||||
{
|
{
|
||||||
#ifdef RT_USING_CONSOLE
|
char ch[2] = {0};
|
||||||
rt_kprintf("%c", (char)c);
|
|
||||||
|
ch[0] = c;
|
||||||
|
rt_kprintf(&ch[0]);
|
||||||
return 1;
|
return 1;
|
||||||
#else
|
|
||||||
return 0; /* error */
|
|
||||||
#endif /* RT_USING_CONSOLE */
|
|
||||||
}
|
}
|
||||||
|
|
||||||
int fgetc(FILE *f)
|
int fgetc(FILE *f)
|
||||||
{
|
{
|
||||||
#ifdef RT_USING_POSIX_STDIO
|
#ifdef RT_USING_POSIX
|
||||||
char ch;
|
char ch;
|
||||||
|
|
||||||
if (libc_stdio_get_console() < 0)
|
if (libc_stdio_get_console() < 0)
|
||||||
{
|
{
|
||||||
LOG_W("Do not invoke standard output before initializing Compiler");
|
LOG_W("Do not invoke standard output before initializing libc");
|
||||||
return 0;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(read(STDIN_FILENO, &ch, 1) == 1)
|
if(read(STDIN_FILENO, &ch, 1) == 1)
|
||||||
return ch;
|
return ch;
|
||||||
#endif /* RT_USING_POSIX_STDIO */
|
#endif
|
||||||
LOG_W("%s: %s", __func__, _WARNING_WITHOUT_STDIO);
|
|
||||||
return 0; /* error */
|
|
||||||
}
|
|
||||||
|
|
||||||
#endif /* __MICROLIB */
|
return -1;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
|
@ -1,22 +1,30 @@
|
||||||
from building import *
|
from building import *
|
||||||
|
|
||||||
Import('rtconfig')
|
Import('rtconfig')
|
||||||
|
|
||||||
src = []
|
src = []
|
||||||
cwd = GetCurrentDir()
|
cwd = GetCurrentDir()
|
||||||
group = []
|
group = []
|
||||||
CPPPATH = [cwd]
|
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':
|
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('libc', src, depend = [], CPPPATH = CPPPATH, CPPDEFINES = CPPDEFINES)
|
||||||
|
|
||||||
group = DefineGroup('Compiler', src, depend = [''], CPPPATH = CPPPATH, CPPDEFINES = CPPDEFINES)
|
|
||||||
|
|
||||||
list = os.listdir(cwd)
|
list = os.listdir(cwd)
|
||||||
for item in list:
|
for d in list:
|
||||||
if os.path.isfile(os.path.join(cwd, item, 'SConscript')):
|
path = os.path.join(cwd, d)
|
||||||
group = group + SConscript(os.path.join(item, 'SConscript'))
|
if os.path.isfile(os.path.join(path, 'SConscript')):
|
||||||
|
group = group + SConscript(os.path.join(d, 'SConscript'))
|
||||||
|
|
||||||
Return('group')
|
Return('group')
|
||||||
|
|
|
@ -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__ */
|
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue