Background of this article
DFS (Device virtual file system) is an abstract file mechanism. The related operations of the file system in RT-Thread are actually realized by operating DFS, that is to say, DFS is an abstraction of each specific file system. DFS makes other parts do not need to care about the differences between different file systems, so that RTThread can support multiple types of file systems.
1 SD card mount operation code
The source code to mount the filesystem is in qemu-vexpress-a9applicationsmnt.c. In the actual code, the file system in the block device sd0 will be mounted on the root directory /.
#include
#ifdef RT_USING_DFS
#include
int mnt_init(void)
{ rt_thread_delay(RT_TICK_PER_SECOND); if (dfs_mount("sd0", "/", "elm", 0, 0) == 0) { rt_kprintf("file system initialization done! "); } return 0;
}
INIT_ENV_EXPORT(mnt_init);
#endif
2 Common command display
After the file system is mounted successfully, you can use some common commands in msh to experience the file system.
2.1ls: View current directory information
msh />ls # Use the ls command to view file system directory information
Directory /: # You can see that the root directory already exists/
2.2mkdir: create a folder
msh />mkdir rt-thread # Create rt-thread folder
msh />ls # View directory information as follows
Directory /:rt-thread
2.3echo: Output the input string to the specified output location
msh />echo "hello rt-thread!!!" # output the string to stdout hello rt-thread!!!msh />echo "hello rt-thread!!!" hello.txt # output the string to hello.txt file msh />lsDirectory /:rt-thread
hello.txt 18msh />
2.4cat: View file content
msh />cat hello.txt # View the content of the hello.txt file and output
hello rt-thread!!!
2.5rm: delete a folder or file
msh />ls # View current directory information
Directory /:rt-thread
hello.txt 18msh />rm rt-thread # delete rt-thread folder
msh />lsDirectory/:hello.txt 18
msh />rm hello.txt # delete the hello.txt file
msh />lsDirectory /:msh />
3 Run the file system example program
After understanding some common commands of the file system, the following guides you to familiarize yourself with the basic operations of the file system by running some sample programs of the file system. The sample program is implemented by using some DFS API interfaces, and the sample is exported to the msh command. By running the sample program and comparing the source code of the sample program, it is helpful for us to get started operating the file system as soon as possible.
3.1 Get sample code
The sample code of the file system is included in the RT-Thread samples package, and the sample code can be added to the project through the env configuration, and the path is as follows.
RT-Thread online packages ---> miscellaneous packages ---> samples: RT-Thread kernel and components samples ---> [*] a filesystem_samples package for rt-thread --->
Select all the sample codes, then exit to save and update the software package to add the sample codes to the project.
3.2 Run the sample code
Before running the sample code, you need to enter scons to compile the project.
Then enter .qemu.bat to run the project
After RT-Thread is started, press the TAB key to view the msh command. The file system samples command has been exported to msh:
Then you can enter the command to run the corresponding sample code.
For example: the result of executing the command mkdir_sample is
msh />mkdir_samplemkdir ok!msh />lsDirectory /:dir_test
Then we can compare the source code of these sample codes to understand the usage of the file system API in detail.
4QEMU SD card reading and writing
After QEMU is running, it will create a sd.bin file in the bspqemu-vexpress-a9 directory. This is a virtual SD card, and the default file system of RT-Thread is built in this.
4.1 Read the content of QEMU SD card
Because sd.bin is essentially an image file of the FAT file system, we can read the files in sd.bin by using the decompression software 7-Zip that supports extracting FAT format.
4.2 Making QEMU SD card
In the tools/fatdisk directory of the env tool, there is a tool fatdisk.exe for packaging FAT format files. We can use this tool to package the files we want to store in the QEMU SD card into an sd.bin file. Then replace the original sd.bin file in the bspqemu-vexpress-a9 directory with the newly generated sd.bin.
Open the path env/tools/fatdisk and create a new folder sd in this directory
Open the folder we created in the previous step and put the files or folders we need to store in the QEMU SD card
Modify the fatdisk.xml file in the env/tools/fatdisk directory to the following content (the content in the video is wrong)
65536512sdsd.bin0
Right-click in the env/tools/fatdisk directory to open the env tool, enter the command fatdisk to run, and the sd.bin file will be generated in the current directory.
Then replace the original sd.bin file in the bspqemu-vexpress-a9 directory with the newly generated sd.bin
Run qemu and enter ls to see the files and folders we stored in the QEMU SD card.
5 Using RomFS
RomFS is a file system commonly used on embedded devices. It has the advantages of small size, high reliability, and fast reading speed. It is often used as the initial file system of the system. But it also has its limitations, RomFS is a read-only file system.
Different data storage methods have a great impact on the main performance of the file system, such as the space occupied by the file system, read and write efficiency, and search speed. RomFS uses sequential storage, and all data is stored sequentially. Therefore, the data in RomFS cannot be modified once it is determined, which is why RomFS is a read-only file system. Due to this sequential storage strategy, the data of each file in RomFS can be stored continuously, and only one addressing operation is needed during the reading process to read the entire block of data, so the efficiency of reading data in RomFS is very high.
5.1 Configuring and enabling RomFS
Enable RT-Thread support for RomFS, and adjust the maximum number of supported file system types.
Open the menuconfig menu and ensure that “RT-Thread Components†→ “Device virtual file system†→ “Enable ReadOnly file system on flash†is turned on:
Open the submenu "RT-Thread Components" → "Device virtual file system" to adjust the maximum number of supported file system types:
5.2 Generate romfs.c file
Since RomFS is a read-only file system, the files that need to be put into RomFS need to be added before the system runs. We can put the file data to be stored in RomFS in the romfs.c file, RT-Thread provides a Python script file for making romfs.c, and generates the corresponding data structure according to the files and directories added to RomFS according to user needs.
open path
rtthreadcomponentsdfsfilesystems omfs and create a new folder romfs in this directory
Open the folder we created in the previous step and put the files or folders we need to place in RomFS.
go back to the previous directory
rt-threadcomponentsdfsfilesystems omfs, open the env tool in this directory, and run the command
python mkromfs.py romfs romfs.c
You can see that the romfs.c file was successfully generated in the directory:
5.3 Mount RomFS
After the system task scheduling starts, mount RomFS through the dfs_mount() function, and add the header file #include "dfs_romfs.h" to the file where the mount function is added
We replace the content in the qemu-vexpress-a9applicationsmnt.c file with the following code to mount RomFS to the root directory.
#include
#ifdef RT_USING_DFS
#include
#include "dfs_romfs.h"
int mnt_init(void)
{ if (dfs_mount(RT_NULL, "/", "rom", 0, &(romfs_root)) == 0) { rt_kprintf("ROM file system initializated! "); } else { rt_kprintf("ROM file system initializate failed! "); } return 0;
}
INIT_ENV_EXPORT(mnt_init);
#endif
5.4 Expected Results
After compiling and running the project, you can see that the RomFS file system is mounted successfully. You can use the ls command to see the folders and files in the RomFS file system:
6 Using RamFS
As the name suggests, RamFS is a memory file system. It cannot be formatted, and multiple files can be created at the same time. When creating, you can specify the maximum memory size that can be used. The advantage is that the read and write speed is very fast, but there is a risk of power loss and loss. If the performance bottleneck of a process is the reading and writing of the hard disk, then you can consider reading and writing large files on RamFS or tmpfs.
RamFS uses the chain storage method, and the data is stored in the memory space, so RamFS has the characteristics of a readable and writable file system, and also has a faster read and write speed.
6.1 Configuring and enabling RamFS
Open the menuconfig menu and ensure that “RT-Thread Components†→ “Device virtual file system†→ “Enable RAM file system†is turned on:
6.2 Mount RamFS
Since RamFS is dynamically created during system operation, we should create RamFS before mounting. RT-Thread provides an API interface for creating RamFS:
struct dfs_ramfs* dfs_ramfs_create(rt_uint8_t *pool, rt_size_t size)
After the system task scheduling starts, mount RamFS through the dfs_mount() function
We can mount RamFS to the root directory by replacing the content in the qemu-vexpress-a9applicationsmnt.c file with the following code.
#include
#ifdef RT_USING_DFS
#include
int mnt_init(void)
{ if (dfs_mount(RT_NULL, "/", "ram", 0, dfs_ramfs_create(rt_malloc(1024),1024)) == 0) { rt_kprintf("RAM file system initializated! "); } else { rt_kprintf("RAM file system initializate failed! "); } return 0;
}
INIT_ENV_EXPORT(mnt_init);
#endif
6.3 Expected Results
After compiling and running the project, you can see that the RamFS file system is mounted successfully. Then we use the echo command to create a file, and we can see that the creation was successful.
7Citation references (please copy the following link to an external browser to open)
• Filesystem samples
https://github.com/RT-Thread-packages/filesystem-sample
•env manual
https://
BIOTEPT three-phase NEMA frame general purpose AC motors don't require starting capacitors, run capacitors, or centrifugal starting switches that can wear out and fail. Motors operate with a higher torque and greater efficiency than single-phase models of the same HP, rpm, and frame size. They have three-windings that create a naturally rotating magnetic field within the frame of the motor and are suitable for use in nonhazardous applications with pumps, ventilation equipment, machine tools, and other industrial equipment.
Nema Three Phase Motor,3 Phase Ac Motor,Three Phase Ac Motor,Three Phase Induction Motors
Ningbo Biote Mechanical Electrical Co.,Ltd , https://www.biotept.com