[go: up one dir, main page]

CN102436428A - SD card file management controller based on FPGA - Google Patents

SD card file management controller based on FPGA Download PDF

Info

Publication number
CN102436428A
CN102436428A CN2011103579366A CN201110357936A CN102436428A CN 102436428 A CN102436428 A CN 102436428A CN 2011103579366 A CN2011103579366 A CN 2011103579366A CN 201110357936 A CN201110357936 A CN 201110357936A CN 102436428 A CN102436428 A CN 102436428A
Authority
CN
China
Prior art keywords
card
command
file
data
register
Prior art date
Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
Pending
Application number
CN2011103579366A
Other languages
Chinese (zh)
Inventor
贺前华
何健伦
宋利伟
黄鹏飞
Current Assignee (The listed assignees may be inaccurate. Google has not performed a legal analysis and makes no representation or warranty as to the accuracy of the list.)
South China University of Technology SCUT
Original Assignee
South China University of Technology SCUT
Priority date (The priority date is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the date listed.)
Filing date
Publication date
Application filed by South China University of Technology SCUT filed Critical South China University of Technology SCUT
Priority to CN2011103579366A priority Critical patent/CN102436428A/en
Publication of CN102436428A publication Critical patent/CN102436428A/en
Pending legal-status Critical Current

Links

Images

Landscapes

  • Information Retrieval, Db Structures And Fs Structures Therefor (AREA)

Abstract

本发明公开了一种基于FPGA的SD卡文件管理控制器,包括FPGA芯片、串行配置芯片、SDRAM存储器、主控器接口、SD卡插座、FAT32文件管理单元、SD卡接口单元;FAT32文件管理单元为主控器提供主控器接口、操作文件系统的用户命令,主控器通过该接口在SD卡文件管理控制器的寄存器中写入用户命令;SD卡接口单元在FAT32文件管理单元的控制下,负责SD卡命令的产生和应答接收,以及SD卡中数据的读写;该发明能解决SD卡接口控制装置接口通用性差、移植困难,操作接口复杂、使用不方便,读写SD卡的速度慢等问题,提供了一种通用性强、操作接口方便、能高速读写SD卡的文件管理控制器。

Figure 201110357936

The invention discloses an SD card file management controller based on FPGA, comprising an FPGA chip, a serial configuration chip, an SDRAM memory, a main controller interface, an SD card socket, a FAT32 file management unit and an SD card interface unit; the FAT32 file management unit provides a main controller interface and user commands for operating a file system for the main controller, and the main controller writes the user commands into a register of the SD card file management controller through the interface; the SD card interface unit is responsible for the generation and response reception of SD card commands, as well as the reading and writing of data in the SD card under the control of the FAT32 file management unit; the invention can solve the problems of poor interface versatility and transplantation difficulty of an SD card interface control device, complex operation interface and inconvenience in use, and slow speed of reading and writing SD cards, and provides a file management controller with strong versatility, convenient operation interface and high-speed reading and writing of SD cards.

Figure 201110357936

Description

基于FPGA的SD卡文件管理控制器SD card file management controller based on FPGA

技术领域 technical field

本发明涉及一种对SD接口卡进行控制的装置,具体涉及一种基于FPGA的SD卡文件管理控制器。 The invention relates to a device for controlling an SD interface card, in particular to an FPGA-based SD card file management controller.

背景技术 Background technique

SD卡(Secure Digital Memory Card)是一种基于半导体闪存工艺的存储卡,1999年,由日本松下、东芝及美国SanDisk公司共同研制完成。当前,人们对大数据量的高速存储需求越来越高。SD卡作为新一代数据存储设备,具有体积小、容量高、数据传输速率快、移动灵活性好以及安全性高等特点,很好地满足了市场的具体需求,被广泛用于便携式消费类电子设备和工业控制领域中。 SD card (Secure Digital Memory Card) is a memory card based on semiconductor flash memory technology. It was jointly developed by Panasonic, Toshiba and SanDisk in 1999. At present, people's demand for high-speed storage of large amounts of data is getting higher and higher. As a new generation of data storage device, SD card has the characteristics of small size, high capacity, fast data transmission rate, good mobile flexibility and high security, which well meets the specific needs of the market and is widely used in portable consumer electronics devices and in the field of industrial control.

SD卡中的数据是以块为单位进行存储的,但是为了更有效地组织和管理SD卡中的数据,必须采用文件的格式组织数据。目前,SD卡一般采用FAT32文件系统。 The data in the SD card is stored in blocks, but in order to organize and manage the data in the SD card more effectively, the data must be organized in a file format. Currently, SD cards generally use the FAT32 file system.

面对人们对大数据量的高速存储需求,目前市场上的SD卡接口控制装置存在着明显的缺陷:1.读写SD卡的速度慢。目前的SD卡接口控制器大多采用了SD卡的SPI模式或者1位的SD模式读写SD卡,而很少采用4位数据线的SD模式,即使采用了4位的SD模式,由于控制装置内的缓冲区小、很多处理模块非硬件实现等原因导致读写的速度不高。2.提供的操作接口复杂,使用不方便。目前的SD卡接口控制装置没有提供便捷的SD卡文件管理的功能,用户需要对SD卡底层的物理规范协议很熟悉才能通过控制装置完成对SD卡的操作。3.提供的接口不通用,移植性差。目前的SD卡接口控制装置提供给用户的接口很少采用标准的总线,大多是针对特定的应用而开发的,因而导致了移植困难,通用性差。 In the face of people's demand for high-speed storage of large amounts of data, there are obvious defects in the SD card interface control devices currently on the market: 1. The speed of reading and writing SD cards is slow. Most of the current SD card interface controllers use the SPI mode of the SD card or the 1-bit SD mode to read and write the SD card, but rarely use the SD mode of the 4-bit data line. Even if the 4-bit SD mode is used, due to the control device The internal buffer is small, and many processing modules are not implemented by hardware, which leads to the low read and write speed. 2. The operation interface provided is complex and inconvenient to use. The current SD card interface control device does not provide a convenient SD card file management function. Users need to be familiar with the physical specification protocol at the bottom of the SD card to complete the operation of the SD card through the control device. 3. The interface provided is not universal and has poor portability. The interface provided by the current SD card interface control device to users rarely adopts a standard bus, and most of them are developed for specific applications, which leads to difficulties in transplantation and poor versatility.

发明内容 Contents of the invention

本发明的目的是克服现有技术中的不足之处,提供一种基于FPGA的SD卡文件管理控制器。 The purpose of the invention is to overcome the deficiencies in the prior art and provide a FPGA-based SD card file management controller.

本发明是通过下述技术方案实现的。 The present invention is achieved through the following technical solutions.

基于FPGA的SD卡文件管理控制器,包括FPGA芯片、串行配置芯片、SDRAM存储器、主控器接口、SD卡插座,其中在FPGA内部实现FAT32文件管理单元和SD卡接口单元; FPGA-based SD card file management controller, including FPGA chip, serial configuration chip, SDRAM memory, main controller interface, SD card socket, among which the FAT32 file management unit and SD card interface unit are implemented inside the FPGA;

FAT32文件管理单元为主控器提供主控器接口、操作文件系统的用户命令,主控器通过该接口在SD卡文件管理控制器的寄存器中写入用户命令即可完成对SD卡中FAT32文件系统的管理; The FAT32 file management unit provides the main controller interface and user commands for operating the file system. The main controller can write user commands in the register of the SD card file management controller through this interface to complete the FAT32 file in the SD card. system management;

SD卡接口单元在FAT32文件管理单元的控制下,负责SD卡命令的产生和应答接收,以及SD卡中数据的读写; Under the control of the FAT32 file management unit, the SD card interface unit is responsible for generating SD card commands and receiving responses, as well as reading and writing data in the SD card;

在读写SD卡中的数据时,采用了4位数据线宽的SD模式; When reading and writing data in the SD card, the SD mode with a 4-bit data line width is adopted;

所述的FAT32文件管理单元包括:NIOS II处理器、EPCS控制模块、SDRAM控制模块、主控器接口模块、Avalon总线、Avalon接口模块; Described FAT32 file management unit comprises: NIOS II processor, EPCS control module, SDRAM control module, master controller interface module, Avalon bus, Avalon interface module;

所述NIOS II处理器通过主控器接口模块获取主控器输入的用户命令与数据,并反馈信息给主控器; The NIOS II processor obtains user commands and data input by the main controller through the main controller interface module, and feeds back information to the main controller;

所述NIOS II处理器通过Avalon接口模块与SD卡接口单元进行通信。 The NIOS II processor communicates with the SD card interface unit through the Avalon interface module.

所述的FAT32文件管理单元上面移植了FATFS文件系统模块。 The FATFS file system module is transplanted above the FAT32 file management unit.

所述的SD卡接口单元包括:读写缓冲FIFO模块、 SD卡数据控制模块、SD卡命令控制模块和SD卡时钟控制模块; Described SD card interface unit comprises: read-write buffer FIFO module, SD card data control module, SD card command control module and SD card clock control module;

所述读写缓冲FIFO模块负责缓存读写SD卡时的数据; The read-write buffer FIFO module is responsible for buffering the data when reading and writing the SD card;

所述SD卡数据控制模块负责DAT线上数据的接收和发送以及数据的校验; The SD card data control module is responsible for the receiving and sending of data on the DAT line and the verification of data;

所述SD卡命令控制模块负责控制CMD线上命令发送和回复接收; The SD card command control module is responsible for controlling CMD online command sending and reply receiving;

所述SD卡时钟控制模块负责控制CLK时钟线的频率,以控制读写SD卡的数据速率。 The SD card clock control module is responsible for controlling the frequency of the CLK clock line to control the data rate of reading and writing the SD card.

所述的SD卡接口单元由FPGA内部逻辑资源组成,用硬件电路的方式来实现数据高速接收与发送。 The SD card interface unit is composed of FPGA internal logic resources, and uses hardware circuits to realize high-speed data receiving and sending.

所述的主控器接口为8位地址线、8位数据线、读使能、写使能、中断信号、时钟信号、复位信号和片选信号。 The master controller interface includes 8-bit address lines, 8-bit data lines, read enable, write enable, interrupt signal, clock signal, reset signal and chip select signal.

所述操作文件系统的用户命令包括新建、打开、读写、关闭文件,新建、打开、关闭目录,磁盘容量查询、空闲扇区查询、以扇区或字节为单位对文件进行读写。 The user commands for operating the file system include creating, opening, reading and writing, and closing files, creating, opening, and closing directories, querying disk capacity, querying free sectors, and reading and writing files in units of sectors or bytes.

本发明具有的有益效果是: The beneficial effects that the present invention has are:

1、本发明提供8位地址线ADDR0~ADDR7、8位数据线DATA0~DATA7、读使能RD、写使能WR、中断信号INT、时钟信号CLK、复位信号RESERT和片选信号CS的主控器接口,主控器通过此接口往SD卡文件管理控制器的寄存器中写入特定的用户命令来完成对SD卡中FAT32文件系统的管理。主控器可以很容易和本发明进行连接,操作本发明就像访问同步SRAM存储器一样。解决了传统SD卡接口控制器装置接口不通用,移植性差的缺陷; 1. The present invention provides the main control of 8-bit address lines ADDR0~ADDR7, 8-bit data lines DATA0~DATA7, read enable RD, write enable WR, interrupt signal INT, clock signal CLK, reset signal RESERT and chip select signal CS Through this interface, the main controller writes specific user commands into the registers of the SD card file management controller to complete the management of the FAT32 file system in the SD card. The master controller can be easily connected with the present invention, and the operation of the present invention is like accessing a synchronous SRAM memory. Solve the defects of the traditional SD card interface controller device interface is not universal, poor portability;

2、本发明提供了新建、打开、读写、关闭文件;新建、打开、关闭目录;磁盘容量查询、空闲扇区查询,以扇区或字节为单位对文件进行读写等常用的操作文件系统的用户命令,屏蔽了SD卡中FAT32文件系统的组织形式。用户只需往本发明对应的寄存器中写入既定的用户命令,即可实现上述所有的操作。上述机制使得本发明操作简单,易于使用; 2. The present invention provides common operating files such as creating, opening, reading and writing, and closing files; creating, opening, and closing directories; querying disk capacity, querying free sectors, and reading and writing files in units of sectors or bytes The user command of the system shields the organizational form of the FAT32 file system in the SD card. The user only needs to write a predetermined user command into the corresponding register of the present invention to realize all the above operations. The above mechanism makes the present invention simple to operate and easy to use;

3、本发明为用户屏蔽了SD卡底层的物理规范协议,即使用户完全不熟悉SD卡底层的物理规范协议也能够使用本发明完成对SD卡中数据的读写。在读写SD卡中的数据时,采用了4位数据线宽的SD模式以及大容量的读写FIFO,实现了对SD卡中文件的快速读写。 3. The present invention shields the physical specification protocol at the bottom of the SD card for the user. Even if the user is completely unfamiliar with the physical specification protocol at the bottom of the SD card, the present invention can be used to complete the reading and writing of data in the SD card. When reading and writing data in the SD card, the SD mode with 4-bit data line width and large-capacity read and write FIFO are adopted to realize the fast reading and writing of files in the SD card.

附图说明 Description of drawings

图1是基于FPGA的SD卡文件管理控制器的框图, Fig. 1 is the block diagram of SD card file management controller based on FPGA,

图2是FPGA里的FAT32文件管理单元电路结构图, Figure 2 is a circuit structure diagram of the FAT32 file management unit in the FPGA,

图3是FPGA里的SD卡接口单元电路结构图, Figure 3 is a circuit structure diagram of the SD card interface unit in the FPGA,

图4是运行在软核处理器上的程序流程图。 Figure 4 is a flow chart of the program running on the soft-core processor.

图中示出: The figure shows:

1--FPGA芯片,2--FAT32文件管理单元,3--SD卡接口单元,4--串行配置芯片,5-- SDRAM存储器,6--主控器接口,7--NIOS II处理器,8-- EPCS控制模块,9-- SDRAM控制模块,10--主控器接口模块,11-- Avalon总线,12-- Avalon接口模块,13--读写缓冲FIFO模块,14-- SD卡数据控制模块,15-- SD卡插座,16-- SD卡命令控制模块,17--SD卡时钟控制模块。 1--FPGA chip, 2--FAT32 file management unit, 3--SD card interface unit, 4--serial configuration chip, 5--SDRAM memory, 6--main controller interface, 7--NIOS II processing 8-- EPCS control module, 9-- SDRAM control module, 10-- main controller interface module, 11-- Avalon bus, 12-- Avalon interface module, 13-- read and write buffer FIFO module, 14-- SD card data control module, 15--SD card socket, 16--SD card command control module, 17--SD card clock control module.

具体实施方式 Detailed ways

下面结合实施例,对本发明进行详细说明。 The present invention will be described in detail below in conjunction with the embodiments.

如图1所示,本发明包括FPGA芯片1、串行配置芯片4、SDRAM存储器5、主控器接口6、SD卡插座15,其中在FPGA1内部实现FAT32文件管理单元2和SD卡接口单元3所述的FAT32文件管理单元2包括NIOS II处理器7、EPCS控制模块8、SDRAM控制模块9和主控器接口模块10、Avalon总线11、Avalon接口模块12; As shown in Figure 1, the present invention comprises FPGA chip 1, serial configuration chip 4, SDRAM memory 5, master controller interface 6, SD card socket 15, wherein realize FAT32 file management unit 2 and SD card interface unit 3 in FPGA1 inside Described FAT32 file management unit 2 comprises NIOS II processor 7, EPCS control module 8, SDRAM control module 9 and master controller interface module 10, Avalon bus 11, Avalon interface module 12;

所述的SD卡接口单元3包括读写缓冲FIFO模块13、 SD卡数据控制模块14、SD卡命令控制模块16和SD卡时钟控制模块17。 Described SD card interface unit 3 comprises read-write buffer FIFO module 13, SD card data control module 14, SD card command control module 16 and SD card clock control module 17.

如图2所示的是所述FPGA里的FAT32文件管理单元电路结构图。FAT32文件管理单元由NIOS II处理器7、EPCS控制模块8、SDRAM控制模块9、主控器接口模块10、Avalon总线11和Avalon接口模块12组成。图中,EPCS控制模块8通过FPGA芯片1的特定引脚与串行配置芯片4采用的EPCS16芯片进行连接;引脚addr_sdram[12..0]、ba_sdram[1..0]、cas_n_sdram、cke_sdram、cs_n_sdram、dq_sdram[15..0]、dqm_sdram[1..0]、ras_n_sdram、we_n_sdram为SDRAM控制模块9的引出端口,并且与SDRAM存储器5所采用的HY57V561620T芯片的A12~A0、BA1~BA0、CAS、CKE、CS、DQ15~DQ0、DQM1~DQM0、RAS、WE端口对应连接;引脚mcu_rst、mcu_clk、mcu_wren、mcu_rden、mcu_int、mcu_address[7..0]、mcu_data[7..0]为主控器接口模块10的引出端口;sd_interface_clk、sd_interface_reset、sd_cmd_ctrl[15..0]、sd_cmd_status[3..0]、divider[7..0]、sd_data_ctrl[15..0]、sd_data_status[3..0]、nios_data[7..0]、nios_wrreq、nios_rdreq、nios_fifo_clk为Avalon接口模块12的引出端口。 As shown in Figure 2 is the circuit structure diagram of the FAT32 file management unit in the FPGA. The FAT32 file management unit is made up of NIOS II processor 7, EPCS control module 8, SDRAM control module 9, master controller interface module 10, Avalon bus 11 and Avalon interface module 12. In the figure, the EPCS control module 8 is connected with the EPCS16 chip adopted by the serial configuration chip 4 through the specific pin of the FPGA chip 1; cs_n_sdram, dq_sdram[15..0], dqm_sdram[1..0], ras_n_sdram, we_n_sdram are the outlet ports of SDRAM control module 9, and are connected with A12~A0, BA1~BA0, CAS of HY57V561620T chip used in SDRAM memory 5 , CKE, CS, DQ15~DQ0, DQM1~DQM0, RAS, and WE ports are connected correspondingly; pins mcu_rst, mcu_clk, mcu_wren, mcu_rden, mcu_int, mcu_address[7..0], mcu_data[7..0] are master controllers sd_interface_clk, sd_interface_reset, sd_cmd_ctrl[15..0], sd_cmd_status[3..0], divider[7..0], sd_data_ctrl[15..0], sd_data_status[3..0] ], nios_data[7..0], nios_wrreq, nios_rdreq, and nios_fifo_clk are the outgoing ports of the Avalon interface module 12.

NIOS II处理器7通过EPCS控制模块8和SDRAM控制模块9来控制FPGA外部的串行配置芯片4和SDRAM存储器5;NIOS II处理器7通过主控器接口模块10来获取来自主控器的用户命令与数据,并反馈信息给主控器。NIOS II处理器7通过Avalon接口模块12与SD卡接口单元进行通信,以实现快速读写SD卡。 NIOS II processor 7 controls the serial configuration chip 4 and SDRAM memory 5 outside FPGA by EPCS control module 8 and SDRAM control module 9; command and data, and feedback information to the main controller. The NIOS II processor 7 communicates with the SD card interface unit through the Avalon interface module 12 to realize fast reading and writing of the SD card.

如图3所示为SD卡接口单元电路结构图。SD卡接口单元3由读写缓冲FIFO模块13、SD卡数据控制模块14、SD卡命令控制模块16和SD卡时钟控制模块17组成。图中,读写缓冲FIFO模块13负责SD卡数据的缓冲,其端口nios_data[7..0]、nios_wrreq、nios_rdreq、nios_fifo_clk与Avalon接口模块12的nios_data[7..0]、nios_wrreq、nios_rdreq、nios_fifo_clk相连,host_data[7..0]、host_wrreq、host_rdreq、host_fifo_clk与SD卡数据控制模块14的host_data[7..0]、host_wrreq、host_rdreq、host_fifo_clk相连;SD卡数据控制模块14负责DAT线上数据的接收和发送以及数据的检验,其端口reset_n、sd_cmd_ctrl[15..0]、sd_cmd_status[3..0]与Avalon接口模块12的sd_interface_reset、sd_cmd_ctrl[15..0]、sd_cmd_status[3..0]相连,sd_data[3..0]与SD卡插座15的DAT[3..0]相连;SD卡命令控制模块16主要负责控制CMD线上命令发送和回复接收,其端口reset_n、sd_data_ctrl[15..0]、sd_data_status[3..0]与Avalon接口模块12的sd_interface_reset、sd_data_ctrl[15..0]、sd_data_status[3..0]相连,sd_cmd与SD卡插座15的CMD相连;SD卡时钟控制模块17负责控制CLK时钟线的频率,以控制读写SD卡的数据速率,其端口clk、reset_n、divider[7..0]与Avalon接口模块12的sd_interface_clk、sd_interface_reset、divider[7..0]相连,sd_clk与SD卡数据控制模块14的clk、SD卡命令控制模块16的clk以及SD卡插座15的CLK相连。 Figure 3 shows the circuit structure diagram of the SD card interface unit. The SD card interface unit 3 is composed of a read-write buffer FIFO module 13 , an SD card data control module 14 , an SD card command control module 16 and an SD card clock control module 17 . In the figure, the read-write buffer FIFO module 13 is responsible for buffering SD card data, and its ports nios_data[7..0], nios_wrreq, nios_rdreq, nios_fifo_clk and Avalon interface module 12's nios_data[7..0], nios_wrreq, nios_rdreq, nios_fifo_clk Connected, host_data[7..0], host_wrreq, host_rdreq, host_fifo_clk are connected with host_data[7..0], host_wrreq, host_rdreq, host_fifo_clk of SD card data control module 14; SD card data control module 14 is responsible for data on the DAT line Receiving and sending and data inspection, its ports reset_n, sd_cmd_ctrl[15..0], sd_cmd_status[3..0] and sd_interface_reset, sd_cmd_ctrl[15..0], sd_cmd_status[3..0] of Avalon interface module 12 Connected, sd_data[3..0] is connected with DAT[3..0] of SD card socket 15; SD card command control module 16 is mainly responsible for controlling CMD online command sending and reply receiving, and its ports reset_n, sd_data_ctrl[15. .0], sd_data_status[3..0] are connected with sd_interface_reset, sd_data_ctrl[15..0], sd_data_status[3..0] of Avalon interface module 12, sd_cmd is connected with CMD of SD card socket 15; SD card clock control Module 17 is responsible for controlling the frequency of the CLK clock line to control the data rate of reading and writing SD cards. Its ports clk, reset_n, divider[7..0] and sd_interface_clk, sd_interface_reset, divider[7..0] of Avalon interface module 12 sd_clk is connected to the clk of the SD card data control module 14, the clk of the SD card command control module 16 and the CLK of the SD card socket 15.

如附图4所示为在软核处理器上的程序流程图。程序包括以下步骤: Shown in accompanying drawing 4 is the program flowchart on the soft-core processor. The procedure consists of the following steps:

(1)系统初始化;  (1) System initialization;

(2)主控器是否往SD卡文件管理控制器中写入用户命令,是则进入步骤(3),否则返回步骤(2); (2) Whether the main controller writes user commands into the SD card file management controller, if yes, enter step (3), otherwise return to step (2);

(3)读命令寄存器,获取主控器写入的用户命令号; (3) Read the command register to obtain the user command number written by the master controller;

(4)根据用户命令号调用FATFS文件系统模块对应的接口函数; (4) Call the interface function corresponding to the FATFS file system module according to the user command number;

(5) FATFS文件系统模块调用底层磁盘IO模块操作Avalon总线接口模块; (5) The FATFS file system module calls the underlying disk IO module to operate the Avalon bus interface module;

(6)通过Avalon总线往SD卡接口单元写入SD卡物理层命令的命令号和命令参数。 (6) Write the command number and command parameters of the SD card physical layer command to the SD card interface unit through the Avalon bus.

(7) SD卡接口单元根据写入的SD卡命令号和命令参数产生并发送相应的命令到SD卡中。 (7) The SD card interface unit generates and sends corresponding commands to the SD card according to the written SD card command number and command parameters.

(8)命令执行完毕进入步骤(9)否则返回步骤(8)继续等待 (8) After the command is executed, go to step (9) otherwise return to step (8) and continue to wait

(9)返回命令响应和命令的执行状态,产生中断并返回步骤(2) (9) Return the command response and the execution status of the command, generate an interrupt and return to step (2)

本发明提供8位地址线,8位地址线可以寻址256个单元,这256个单元对应着主控器接口模块中的256个寄存器。主控器接口模块中寄存器空间的分配方式如表1所示。 The invention provides 8-bit address lines, which can address 256 units, and these 256 units correspond to 256 registers in the main controller interface module. Table 1 shows the distribution of register space in the interface module of the main controller.

如软件流程图中所述,主控器通过主控器接口模块往本发明的寄存器中写入特定的用户命令即可完成磁盘管理和文件管理操作。各种用户命令的代码、功能、名称、输入、输出数据如表2所示(表中后缀H表是十六进制数)。各种命令的详细介绍如下: As described in the software flow chart, the main controller can complete disk management and file management operations by writing specific user commands into the registers of the present invention through the main controller interface module. The codes, functions, names, input and output data of various user commands are shown in Table 2 (the suffix H in the table is a hexadecimal number). The details of the various commands are as follows:

CMD_DISK_MOUNT: CMD_DISK_MOUNT:

该命令用来完成SD卡的初始化工作。主控器先往命令寄存器中写入命令CMD_DISK_MOUNT的代码00H,然后往执行命令寄存器中写入01H,即可操作本发明完成SD卡的挂载和初始化工作。本发明将命令的响应反馈在状态寄存器中,主控器通过读取状态寄存器获取SD卡的状态。所有命令返回值的定义如表3所示。本发明提供查询和中断两种方式通知主控器所发出的命令已经执行结束。CMD_DISK_MOUNT命令的返回状态为FR_OK、FR_NOT_READY。操作成功则返回FR_OK,操作失败返回FR_NOT_READY。只有SD卡初始化成功了才能进行其他的磁盘或者文件操作。 This command is used to complete the initialization of the SD card. The main controller first writes the code 00H of the command CMD_DISK_MOUNT into the command register, and then writes 01H into the execution command register, so that the present invention can be operated to complete the mounting and initialization of the SD card. The invention feeds back the response of the command in the state register, and the main controller acquires the state of the SD card by reading the state register. The definitions of all command return values are shown in Table 3. The present invention provides two ways of inquiring and interrupting to notify the main controller that the command sent has been executed. The return status of the CMD_DISK_MOUNT command is FR_OK, FR_NOT_READY. Returns FR_OK if the operation succeeds, and returns FR_NOT_READY if the operation fails. Only when the SD card is initialized successfully can other disk or file operations be performed.

CMD_CREATE_DIR: CMD_CREATE_DIR:

该命令用于新建子目录,特指文件夹。在根目录下建立子目录时,先按照表2所示分配的寄存器中依次填入目录名(本发明只支持短文件名,所以目录名不能超过8个字节)、属性字段、创建时间。属性字段描述了文件或者目录的属性,大小为1个字节。其值为00H表示读写、01H时表示只读、02H表示隐藏、04表示系统文件H、08H表示卷标、0FH表示该目录项为长文件名目录项在本发明中没有任何意义。10H表示目录、20H表示存档。所以在新建目录时在此字段中填入10H即可。若主控器有实时时钟RTC则往创建时间寄存器中写入实时时间,若主控器没有实时时钟,则系统默认时间为2011年10月01日11点10时01分。填写完目录信息后,往命令寄存器中写入命令CMD_CREATE_DIR的代码01H,往执行命令寄存器中写入01H即可完成目录的创建工作。命令执行完成后将会产生中断。主控器可以读取状态寄存器来查询CMD_CREATE_DIR命令的执行状态。CMD_CREATE_DIR可能的状态为FR_OK, FR_DISK_ERR, FR_INT_ERR, FR_NOT_READY, FR_NO_PATH, FR_INVALID_NAME, FR_DENIED, FR_EXIST, FR_WRITE_PROTECTED FR_NO_FILESYSTEM。各种返回状态的意义请见表3。 当创建多级目录时,需要先使用打开目录命令CMD_OPEN_DIR打开各级父目录,然后按照上面的操作方式使用新建目录命令即可。 This command is used to create a new subdirectory, specifically a folder. When establishing a subdirectory under the root directory, first fill in the directory name (the present invention only supports short file names, so the directory name cannot exceed 8 bytes), attribute fields, and creation time in the registers allocated as shown in Table 2. The attribute field describes the attributes of the file or directory, and its size is 1 byte. Its value 00H represents read-write, 01H represents read-only, 02H represents concealment, 04 represents system file H, 08H represents volume label, 0FH represents that this directory entry is long file name directory entry and has no meaning in the present invention. 10H means directory, 20H means archive. So when creating a new directory, fill in 10H in this field. If the main controller has a real-time clock RTC, write the real time into the creation time register; if the main controller does not have a real-time clock, the system default time is 11:10:01 on October 1, 2011. After filling in the directory information, write the code 01H of the command CMD_CREATE_DIR into the command register, and write 01H into the execution command register to complete the creation of the directory. An interrupt will be generated when the command execution is complete. The main controller can read the status register to query the execution status of the CMD_CREATE_DIR command. The possible states of CMD_CREATE_DIR are FR_OK, FR_DISK_ERR, FR_INT_ERR, FR_NOT_READY, FR_NO_PATH, FR_INVALID_NAME, FR_DENIED, FR_EXIST, FR_WRITE_PROTECTED FR_NO_FILESYSTEM. See Table 3 for the meanings of various return states. When creating a multi-level directory, you need to use the open directory command CMD_OPEN_DIR to open the parent directories of all levels, and then use the new directory command according to the above operation method.

CMD_OPEN_DIR: CMD_OPEN_DIR:

该命令用于打开已存在的目录。当打开根目录下的一级子目录时,首先往文件名寄存器中写入需要打开的目录名称且不超过8个字节,在命令寄存器中写入CMD_OPEN_DIR的命令代码02H,往执行命令寄存器中写入01H即可执行命令。命令执行完毕后将会产生中断。主控器通过查询状态寄存器来获取CMD_OPEN_DIR命令的操作状态。CMD_OPEN_DIR命令的可能返回状态为FR_OK, FR_DISK_ERR, FR_INT_ERR, FR_NOT_READY, FR_NO_PATH, FR_INVALID_NAME, FR_NO_FILESYSTEM。当打开多级目录时,需要重复使用CMD_OPEN_DIR命令一级一级的打开。每一级目录的打开方式如同根目录下打开一级子目录的方式。 This command is used to open an existing directory. When opening a first-level subdirectory under the root directory, first write the name of the directory to be opened in the file name register and not exceed 8 bytes, write the command code 02H of CMD_OPEN_DIR in the command register, and write it to the execution command register Write 01H to execute the command. An interrupt will be generated after the command has been executed. The master controller obtains the operation status of the CMD_OPEN_DIR command by querying the status register. The possible return statuses of the CMD_OPEN_DIR command are FR_OK, FR_DISK_ERR, FR_INT_ERR, FR_NOT_READY, FR_NO_PATH, FR_INVALID_NAME, FR_NO_FILESYSTEM. When opening a multi-level directory, you need to repeatedly use the CMD_OPEN_DIR command to open level by level. The opening method of each level of directory is the same as the way of opening a level of subdirectory under the root directory.

CMD_READ_DIR_STAT: CMD_READ_DIR_STAT:

该命令用于获取目录的信息。如果目录为多级目录时,需要使用“打开目录”命令依次打开目录。然后往文件名寄存器中写入需要查询的目录名,往命令寄存器中写入CMD_READ_DIR_STAT命令的代码03H,往执行命令寄存器中写入01H即可执行CMD_READ_DIR_STAT命令。命令执行完成后将会产生中断。在状态寄存器中保存了命令的执行结果,在寄存器03H~22H 32个字节的空间中保存了目录的信息。CMD_READ_DIR_STAT命令的可能返回值为FR_OK, FR_DISK_ERR, FR_INT_ERR, FR_NOT_READY, FR_NO_FILE, FR_NO_PATH, FR_INVALID_NAME, FR_NO_FILESYSTEM。当返回为FR_OK时表示读取目录信息成功,主控器可以从寄存器中读取相关信息。 This command is used to get information about a directory. If the directory is a multi-level directory, you need to use the "Open Directory" command to open the directories one by one. Then write the directory name to be queried into the file name register, write the code 03H of the CMD_READ_DIR_STAT command into the command register, and write 01H into the execution command register to execute the CMD_READ_DIR_STAT command. An interrupt will be generated when the command execution is complete. The execution result of the command is saved in the status register, and the information of the directory is saved in the 32-byte space of the register 03H~22H. The possible return values of the CMD_READ_DIR_STAT command are FR_OK, FR_DISK_ERR, FR_INT_ERR, FR_NOT_READY, FR_NO_FILE, FR_NO_PATH, FR_INVALID_NAME, FR_NO_FILESYSTEM. When the return is FR_OK, it means that the directory information is read successfully, and the main controller can read the relevant information from the register.

CMD_READ_DIR_ITEM: CMD_READ_DIR_ITEM:

该命令用于获取目录的目录项。每一个目录项包含了该目录下文件的文件名、扩展名、属性字节、文件的最近修改时间、最近访问时间、文件的创建日期、文件的首簇号、文件的长度等信息。往文件名寄存器中写入目录名,往命令寄存器中写入CMD_READ_DIR_ITEM命令的代码04H、执行命令寄存器中写入01H即可执行命令。命令执行完毕后会产生中断。主控器需要先查询状态寄存器获取命令的执行情况,当返回值为FR_OK时,才能读取寄存器03H~22H获取目录项的信息。当返回其它值时,表明命令执行失败。读完一条目录项后,主控器可以往命令寄存器中写入CMD_READ_CONTINUE命令、执行命令寄存器中写入01H来继续读取下一条目录项。当所有的目录项读取完毕后,状态寄存器中的返回值为FR_READ_ALL。 This command is used to get the directory entries of a directory. Each directory entry contains information such as the file name, extension, attribute byte, last modification time of the file, latest access time, creation date of the file, first cluster number of the file, and length of the file in the directory. Write the directory name into the file name register, write the code 04H of the CMD_READ_DIR_ITEM command into the command register, and write 01H into the execution command register to execute the command. An interrupt will be generated after the command has been executed. The main controller needs to first query the status register to obtain the execution status of the command. When the return value is FR_OK, the register 03H~22H can be read to obtain the information of the directory item. When other values are returned, it indicates that the command execution failed. After reading a directory entry, the master controller can write the CMD_READ_CONTINUE command into the command register and write 01H into the execution command register to continue reading the next directory entry. When all directory entries are read, the return value in the status register is FR_READ_ALL.

CMD_CHANGE_DIR_STAT: CMD_CHANGE_DIR_STAT:

该命令用于修改目录的属性包括属性字段、目录名、创建时间。如果目录为多级目录时,需要使用打开目录命令依次打开各级目录。往属性字段寄存器、文件名寄存器、创建时间寄存器中填入数据,在文件信息修改标志位寄存器中指定需要修改的属性。01H表示修改目录名、02H表示修改属性字段、04H表示修改创建时间。主控器可以选择性的修改这3个属性。往命令寄存器中写入CMD_CHANGE_DIR_STAT的命令代码05H,往执行命令寄存器中写入01H即可执行命令。命令执行完成后将会产生中断。主控器可以查询状态寄存器来获取命令的执行状况。命令CMD_CHANGE_DIR_STAT可能的返回值为FR_OK, FR_DISK_ERR, FR_INT_ERR, FR_NOT_READY, FR_NO_FILE, FR_NO_PATH, FR_INVALID_NAME, FR_NO_FILESYSTEM, FR_WRITE_PROTECTED, FR_EXIST。当返回值为FR_OK时表明属性修改成功。 This command is used to modify the attributes of the directory, including the attribute field, directory name, and creation time. If the directory is a multi-level directory, you need to use the open directory command to open the directories at all levels in sequence. Fill data into the attribute field register, file name register, and creation time register, and specify the attribute to be modified in the file information modification flag bit register. 01H means to modify the directory name, 02H means to modify the attribute field, and 04H means to modify the creation time. The main controller can selectively modify these 3 attributes. Write the command code 05H of CMD_CHANGE_DIR_STAT into the command register, and write 01H into the execution command register to execute the command. An interrupt will be generated when the command execution is complete. The master controller can query the status register to obtain the execution status of the command. The possible return values of the command CMD_CHANGE_DIR_STAT are FR_OK, FR_DISK_ERR, FR_INT_ERR, FR_NOT_READY, FR_NO_FILE, FR_NO_PATH, FR_INVALID_NAME, FR_NO_FILESYSTEM, FR_WRITE_PROTECTED, FR_EXIST. When the return value is FR_OK, it indicates that the attribute modification is successful.

CMD_GET_CURRENT_DIR: CMD_GET_CURRENT_DIR:

该命令用于获取当前目录的路径名。往命令寄存器中写入命令CMD_GET_CURRENT_DIR     的代码06H、往执行命令寄存器中写入01H即可执行此命令。当命令执行完毕后会产生中断。若命令执行成功,状态寄存器中的值为FR_OK,数据寄存器80H~FFH中为目录的绝对路径名。本发明不支持超过128个字节的路径名。路径名的末尾以“\0”结束。此命令的可能返回值为FR_OK, FR_DISK_ERR, FR_INT_ERR, FR_NOT_READY, FR_NO_FILESYSTEM。 This command is used to get the pathname of the current directory. Write the code 06H of the command CMD_GET_CURRENT_DIR into the command register, and write 01H into the execution command register to execute this command. An interrupt will be generated when the command execution is complete. If the command is executed successfully, the value in the status register is FR_OK, and the absolute path name of the directory is in the data register 80H~FFH. The present invention does not support pathnames longer than 128 bytes. The end of the path name is terminated with "\0". The possible return values of this command are FR_OK, FR_DISK_ERR, FR_INT_ERR, FR_NOT_READY, FR_NO_FILESYSTEM.

CMD_CHANGE_DIR: CMD_CHANGE_DIR:

该命令用于切换目录。往数据寄存器80H~FFH中写入需要切换的目录名包括目录的绝对路径,且路径名需小于128个字节、往命令寄存器中写入命令CMD_CHANGE_DIR的代码07H、往执行命令寄存器中写入01H即可执行命令。目录的绝对路径以“/”开始。“/”表示根目录。“/Test”表示根目录下的“Test”子目录。“/file.txt”表示根目录下的文件“file.txt”。“/Test/file.txt”表示根目录下的一级子目录“Test”中的文件“file.txt”。“.”表示当前目录,“. .”表示当前目录的父目录。命令行完毕后会产生中断。若命令执行成功,则状态寄存器中的值为FR_OK。此命令的可能返回值为FR_OK, FR_DISK_ERR, FR_INT_ERR, FR_NOT_READY, FR_NO_FILESYSTEM, FR_INVALID_NAME, FR_NO_PATH。 This command is used to switch directories. Write the directory name to be switched to the data register 80H~FFH, including the absolute path of the directory, and the path name must be less than 128 bytes, write the code 07H of the command CMD_CHANGE_DIR to the command register, and write 01H to the execution command register The command can be executed. The absolute path of the directory starts with "/". "/" indicates the root directory. "/Test" means the "Test" subdirectory under the root directory. "/file.txt" means the file "file.txt" in the root directory. "/Test/file.txt" means the file "file.txt" in the first-level subdirectory "Test" under the root directory. "." indicates the current directory, and ". ." indicates the parent directory of the current directory. An interrupt is generated when the command line completes. If the command is executed successfully, the value in the status register is FR_OK. The possible return values of this command are FR_OK, FR_DISK_ERR, FR_INT_ERR, FR_NOT_READY, FR_NO_FILESYSTEM, FR_INVALID_NAME, FR_NO_PATH.

CMD_DELETE_DIR: CMD_DELETE_DIR:

该命令用于删除目录。往数据寄存器80H~FFH中写入需要删除的目录名包括目录的绝对路径,且路径名需小于128个字节、往命令寄存器中写入CMD_DELETE_DIR的代码08H、往执行命令寄存器中写入01H即可执行命令。命令执行完毕后会产生中断。若状态寄存器中的值为FR_OK,则命令执行成功。此命只能用于删除空的文件夹,若文件夹非空则操作失败。 This command is used to delete a directory. Write the directory name to be deleted into the data register 80H~FFH, including the absolute path of the directory, and the path name must be less than 128 bytes, write the code 08H of CMD_DELETE_DIR into the command register, and write 01H into the execution command register. Executable commands. An interrupt will be generated after the command has been executed. If the value in the status register is FR_OK, the command is executed successfully. This command can only be used to delete empty folders, if the folder is not empty, the operation will fail.

CMD_CREATE_FILE: CMD_CREATE_FILE:

该命令用于创建文件。此命令可以参考CMD_CREATE_DIR命令的相关细节。在寄存器03H~22H中依次填入新创建文件的文件名、扩展名、属性字节、创建时间、在命令寄存器中写入命令CMD_CREATE_FILE的代码09H、在执行命令寄存器中写入01H即可执行此命令。命令执行完毕后会产生中断。若状态寄存器中的返回值为FR_OK,表明文件创建成功。此命令的可能返回值为FR_OK, FR_DISK_ERR, FR_INT_ERR, FR_NOT_READY, FR_NO_PATH, FR_INVALID_NAME, FR_DENIED, FR_EXIST, FR_WRITE_PROTECTED FR_NO_FILESYSTEM。 This command is used to create a file. This command can refer to the relevant details of the CMD_CREATE_DIR command. Fill in the file name, extension, attribute byte, and creation time of the newly created file in sequence in registers 03H~22H, write the code 09H of the command CMD_CREATE_FILE in the command register, and write 01H in the execution command register to execute this Order. An interrupt will be generated after the command has been executed. If the return value in the status register is FR_OK, it means the file is created successfully. The possible return values of this command are FR_OK, FR_DISK_ERR, FR_INT_ERR, FR_NOT_READY, FR_NO_PATH, FR_INVALID_NAME, FR_DENIED, FR_EXIST, FR_WRITE_PROTECTED FR_NO_FILESYSTEM.

CMD_OPEN_FILE: CMD_OPEN_FILE:

此命令用于打开已存在的文件。在文件名寄存器中写入需要打开的文件名、在命令寄存器中写入命令CMD_OPEN_FILE的代码0AH,在执行命令寄存器中写入01H即可执行此命令。命令执行完毕后会产生中断。若状态寄存器中的值为FR_OK表示打开文件成功。在进行文件的读写、文件指针的移动之前必须先成功打开文件。此命令的可能返回值为FR_OK, FR_DISK_ERR, FR_INT_ERR, FR_NOT_READY, FR_NO_PATH, FR_INVALID_NAME, FR_DENIED, FR_EXIST, FR_WRITE_PROTECTED FR_NO_FILESYSTEM。 This command is used to open an existing file. Write the file name to be opened in the file name register, write the code 0AH of the command CMD_OPEN_FILE in the command register, and write 01H in the execution command register to execute this command. An interrupt will be generated after the command has been executed. If the value in the status register is FR_OK, it means that the file is opened successfully. The file must be successfully opened before reading and writing the file and moving the file pointer. The possible return values of this command are FR_OK, FR_DISK_ERR, FR_INT_ERR, FR_NOT_READY, FR_NO_PATH, FR_INVALID_NAME, FR_DENIED, FR_EXIST, FR_WRITE_PROTECTED FR_NO_FILESYSTEM.

CMD_BYTE_READ: CMD_BYTE_READ:

该命令用于以字节为单位读取指定字节数的数据。往文件名寄存器中写入文件名,往数据大小寄存器23H~26H中写入读取的字节数,字节数的低位放在低地址寄存器中,高位放在高地址寄存器中。往命令寄存器中写入命令CMD_BYTE_READ的代码0BH、往执行命令寄存器中写入01H即可执行命令。命令执行完毕后会产生中断。若命令执行成功,则状态寄存器中的返回值为FR_OK,“可读写字节数”寄存器中为数据寄存器80H~FFH中有效的字节数。主控器根据“可读写字节数”寄存器中的值来从数据寄存器80H单元开始读取数据。数据寄存器80H~FFH中最多只能保存128字节的数据,当主控器读取的字节数大于128个字节时,需要分多次读取。主控器从数据寄存器80H~FFH单元读完128个字节的数据后,往命令寄存器中写入命令CMD_READ_CONTINUE,往执行命令寄存器中写入01H即可读取下128个字节的数据。当读取到文件的末尾或读取的字节数完毕后,状态寄存器中的值为FR_READ_ALL。此命令可能返回值为FR_OK、FR_DISK_ERR、FR_INT_ERR、FR_NOT_READY、FR_READ_ALL。 This command is used to read the specified number of bytes of data in bytes. Write the file name into the file name register, and write the number of bytes read into the data size register 23H~26H. The low bit of the byte number is placed in the low address register, and the high bit is placed in the high address register. Write the code 0BH of the command CMD_BYTE_READ into the command register, and write 01H into the execution command register to execute the command. An interrupt will be generated after the command has been executed. If the command is executed successfully, the return value in the status register is FR_OK, and the "number of readable and writable bytes" register is the effective number of bytes in the data register 80H~FFH. The master controller starts to read data from the data register 80H unit according to the value in the "number of readable and writable bytes" register. Data registers 80H~FFH can only store up to 128 bytes of data. When the number of bytes read by the master controller is greater than 128 bytes, it needs to be read in multiple times. After the main controller reads 128 bytes of data from the data register 80H~FFH, write the command CMD_READ_CONTINUE to the command register, and write 01H to the execution command register to read the next 128 bytes of data. When the end of the file is read or the number of bytes read is complete, the value in the status register is FR_READ_ALL. The possible return values of this command are FR_OK, FR_DISK_ERR, FR_INT_ERR, FR_NOT_READY, FR_READ_ALL.

CMD_SECTOR_READ: CMD_SECTOR_READ:

该命令用于以扇区为单位读取文件。此命令的用法可以参考CMD_BYTE_READ。往文件名寄存器中写入文件名,往数据大小寄存器23H~26H中写入读取的扇区数,扇区数的低位放在低地址寄存器中,高位放在高地址寄存器中。往命令寄存器中写入命令CMD_SECTOR_READ的代码0CH、往执行命令寄存器中写入01H即可执行命令。命令执行完毕后会产生中断。若命令执行成功,则状态寄存器中的返回值为FR_OK,“可读写字节数”寄存器中为数据寄存器80H~FFH中有效的字节数。主控器根据“可读写字节数”寄存器中的值来从数据寄存器80H单元开始读取数据。数据寄存器80H~FFH中最多只能保存128字节的数据,每个扇区的大小是128字节的整数倍。所以以扇区为单位读时,需要主控器反复的读取128字节的数据。主控器从数据寄存器80H~FFH单元读完128个字节的数据后,往命令寄存器中写入命令CMD_READ_CONTINUE,往执行命令寄存器中写入01H即可读取下128个字节的数据。当读取到文件的末尾或读取的书扇区数完毕后,状态寄存器中的值为FR_READ_ALL。此命令可能返回值为FR_OK、FR_DISK_ERR、FR_INT_ERR、FR_NOT_READY、FR_READ_ALL。 This command is used to read files in units of sectors. The usage of this command can refer to CMD_BYTE_READ. Write the file name into the file name register, and write the read sector number into the data size register 23H~26H. The low bit of the sector number is placed in the low address register, and the high bit is placed in the high address register. Write the code 0CH of the command CMD_SECTOR_READ into the command register, and write 01H into the execution command register to execute the command. An interrupt will be generated after the command has been executed. If the command is executed successfully, the return value in the status register is FR_OK, and the "number of readable and writable bytes" register is the effective number of bytes in the data register 80H~FFH. The master controller starts to read data from the data register 80H unit according to the value in the "number of readable and writable bytes" register. Data registers 80H~FFH can only store up to 128 bytes of data, and the size of each sector is an integer multiple of 128 bytes. Therefore, when reading in units of sectors, the master controller needs to repeatedly read 128 bytes of data. After the main controller reads 128 bytes of data from the data register 80H~FFH, write the command CMD_READ_CONTINUE to the command register, and write 01H to the execution command register to read the next 128 bytes of data. When the end of the file is read or the number of read book sectors is completed, the value in the status register is FR_READ_ALL. The possible return values of this command are FR_OK, FR_DISK_ERR, FR_INT_ERR, FR_NOT_READY, FR_READ_ALL.

CMD_BYTE_WRITE: CMD_BYTE_WRITE:

该命令用于以字节为单位往文件中写入数据。此命令的用法可以参考命令CMD_BYTE_READ。往文件名寄存器中写入文件名,往数据寄存器80H~FFH中写入数据,往“可读写字节数”寄存器中写入本次数据寄存器中有效的字节数,往命令寄存器中写入命令CMD_BYTE_WRITE的代码0DH、往执行命令寄存器中写入01H即可执行命令。命令执行完毕后会产生中断。若命令执行成功,则状态寄存器中的返回值为FR_OK,“可读写字节数”寄存器中为实际写入文件中的字节数。若操作失败主控器可根据“可读写字节数”寄存器中的值来确定已经写入了多少数据。数据寄存器80H~FFH中最多只能保存128字节的数据,当主控器写入的字节数大于128个字节时,需要分多次写。当主控器写完128个字节的数据后,往数据寄存器80H~FFH中再次写入数据,往“可读写字节数”寄存器中写入本次操作的字节数、往命令寄存器中写入命令CMD_WRITE_CONTINUE,往执行命令寄存器中写入01H即可连续的往文件中写入数据。此命令可能返回值为FR_OK、FR_DISK_ERR、FR_INT_ERR、FR_NOT_READY。 This command is used to write data to the file in bytes. The usage of this command can refer to the command CMD_BYTE_READ. Write the file name to the file name register, write data to the data register 80H~FFH, write the effective number of bytes in the data register to the "readable and writable bytes" register, and write to the command register Enter the code 0DH of the command CMD_BYTE_WRITE, and write 01H into the execution command register to execute the command. An interrupt will be generated after the command has been executed. If the command is executed successfully, the return value in the status register is FR_OK, and the "number of readable and writable bytes" register is the number of bytes actually written into the file. If the operation fails, the master controller can determine how much data has been written according to the value in the "number of readable and writable bytes" register. Data registers 80H~FFH can only store up to 128 bytes of data. When the number of bytes written by the master controller is greater than 128 bytes, it needs to be written multiple times. After the main controller finishes writing 128 bytes of data, write data again into the data register 80H~FFH, write the number of bytes of this operation into the "number of readable and writable bytes" register, and write to the command register Write the command CMD_WRITE_CONTINUE, and write 01H to the execution command register to continuously write data to the file. The possible return values of this command are FR_OK, FR_DISK_ERR, FR_INT_ERR, FR_NOT_READY.

CMD_SECTOR_WRITE: CMD_SECTOR_WRITE:

该命令用于以扇区为单位往文件中写入数据。此命令的用法可以参考命令CMD_BYTE_WRITE。往文件名寄存器中写入文件名,往数据寄存器80H~FFH中写入数据,往“可读写字节数”寄存器中写入本次数据寄存器中有效的字节数,往命令寄存器中写入命令CMD_SECTOR_WRITE的代码0EH、往执行命令寄存器中写入01H即可执行命令。命令执行完毕后会产生中断。若命令执行成功,则状态寄存器中的返回值为FR_OK,“可读写字节数”寄存器中为实际写入文件中的字节数。若操作失败主控器可根据“可读写字节数”寄存器中的值来确定已经写入了多少数据。数据寄存器80H~FFH中最多只能保存128字节的数据,而FAT32文件系统的扇区大小都是128字节的整数倍。主控器需要分多次才能写完一个扇区。当主控器写完128个字节的数据后,往数据寄存器80H~FFH中再次写入128字节数据,往“可读写字节数”寄存器中写入128、往命令寄存器中写入命令CMD_WRITE_CONTINUE,往执行命令寄存器中写入01H即可连续的往文件中写入数据。此命令可能返回值为FR_OK、FR_DISK_ERR、FR_INT_ERR、FR_NOT_READY。 This command is used to write data to the file in units of sectors. The usage of this command can refer to the command CMD_BYTE_WRITE. Write the file name to the file name register, write data to the data register 80H~FFH, write the effective number of bytes in the data register to the "readable and writable bytes" register, and write to the command register Enter the code 0EH of the command CMD_SECTOR_WRITE, and write 01H into the execution command register to execute the command. An interrupt will be generated after the command has been executed. If the command is executed successfully, the return value in the status register is FR_OK, and the "number of readable and writable bytes" register is the number of bytes actually written into the file. If the operation fails, the master controller can determine how much data has been written according to the value in the "number of readable and writable bytes" register. Data registers 80H~FFH can only store up to 128 bytes of data, and the sector size of the FAT32 file system is an integer multiple of 128 bytes. The master controller needs to write a sector several times. After the master controller finishes writing 128 bytes of data, write 128 bytes of data into the data register 80H~FFH again, write 128 into the "readable and writable bytes" register, and write Command CMD_WRITE_CONTINUE, write 01H into the execution command register to continuously write data into the file. The possible return values of this command are FR_OK, FR_DISK_ERR, FR_INT_ERR, FR_NOT_READY.

CMD_GET_POINTER: CMD_GET_POINTER:

该命令用于读写文件时获取当前文件的指针。往命令寄存器中写入命令CMD_GET_POINTER代码0FH、往执行命令寄存器中写入01H即可执行此命令。命令执行完毕后会产生中断。若命令执行成功,则状态寄存器中的返回值为FR_OK,数据大小寄存器23H~26H中为文件指针到文件开头的偏移量。偏移量的低位存放在低地址,高位存放在高地址。 This command is used to obtain the pointer of the current file when reading and writing files. Write the command CMD_GET_POINTER code 0FH into the command register, and write 01H into the execution command register to execute this command. An interrupt will be generated after the command has been executed. If the command is executed successfully, the return value in the status register is FR_OK, and the data size register 23H~26H is the offset from the file pointer to the beginning of the file. The low bit of the offset is stored at the low address, and the high bit is stored at the high address.

CMD_MOVE_POINTER: CMD_MOVE_POINTER:

该命令用于读写文件时移动文件的指针。往数据大小寄存器23H~26H中写入移动的偏移量,偏移量为4个字。往命令寄存器中写入CMD_MOVE_POINTER命令的代码10H、往执行命令寄存器中写入01H即可执行命令。命令执行完毕后会产生中断。若命令执行成功,状态寄存器中的返回值为FR_OK。此命令可能的返回值为FR_OK、FR_DISK_ERR、FR_INT_ERR、FR_NOT_READY。 This command is used to move the pointer of the file when reading and writing the file. Write the moving offset into the data size register 23H~26H, and the offset is 4 words. Write the code 10H of the CMD_MOVE_POINTER command into the command register, and write 01H into the execution command register to execute the command. An interrupt will be generated after the command has been executed. If the command is executed successfully, the return value in the status register is FR_OK. The possible return values of this command are FR_OK, FR_DISK_ERR, FR_INT_ERR, FR_NOT_READY.

CMD_GET_FILE_STAT: CMD_GET_FILE_STAT:

该命令用于获取文件的读写属性、创建时间、文件大小、文件首簇号、文件最后的访问时间、文件最后修改的时间。当文件位于根目录下时,往文件名寄存器中写入文件名、往命令寄存器中写入命令CDM_GET_FILE_STAT的代码11H、往执行命令寄存器中写入01H即可执行命令。命令执行完毕后会产生中断。若命令执行成功,则状态寄存器中的返回值为FR_OK,寄存器03H~22H为文件的信息。每一项信息在寄存器中的位置详见表1。当文件位于多级目录下时,需要使用打开目录命令打开多级目录,然后获取文件的信息。此命令的可能返回值为FR_OK、FR_DISK_ERR、 FR_INT_ERR、 FR_NOT_READY、FR_NO_FILE, FR_INVALID_NAME, FR_DENIED, FR_EXIST, FR_NO_FILESYSTEM。 This command is used to obtain the read and write attributes of the file, creation time, file size, file first cluster number, last access time of the file, and last modification time of the file. When the file is in the root directory, write the file name into the file name register, write the code 11H of the command CDM_GET_FILE_STAT into the command register, and write 01H into the execution command register to execute the command. An interrupt will be generated after the command has been executed. If the command is executed successfully, the return value in the status register is FR_OK, and the registers 03H~22H are the file information. See Table 1 for the location of each item of information in the register. When the file is located in a multi-level directory, you need to use the open directory command to open the multi-level directory, and then obtain the file information. The possible return values of this command are FR_OK, FR_DISK_ERR, FR_INT_ERR, FR_NOT_READY, FR_NO_FILE, FR_INVALID_NAME, FR_DENIED, FR_EXIST, FR_NO_FILESYSTEM.

CMD_END_OF_FILE: CMD_END_OF_FILE:

该命令用于测试文件指针是否到达了文件的末尾。往命令寄存器中写入命令CMD_END_OF_FILE代码12H、往执行命令寄存器中写入01H即可执行命令。命令执行完毕后会产生中断。若命令执行成功且文件指针到达文件的末尾处,状态寄存器中的返回值为FR_END_OF_FILE,没有到达文件的末尾处则返回FR_OK。 This command is used to test whether the file pointer has reached the end of the file. Write the command CMD_END_OF_FILE code 12H into the command register, and write 01H into the execution command register to execute the command. An interrupt will be generated after the command has been executed. If the command is executed successfully and the file pointer reaches the end of the file, the return value in the status register is FR_END_OF_FILE; if the end of the file is not reached, FR_OK is returned.

CDM_TEST_FILE_ERROR: CDM_TEST_FILE_ERROR:

该命令用于测试文件是否发生了错误。往命令寄存器中写入命令CMD_TEST_FIL_ERROR代码13H、往执行命令寄存器中写入01H即可执行命令。命令执行完毕后会产生中断。若命令执行成功且文件没有错误则状态寄存器中的返回值为FR_OK。 This command is used to test the file for errors. Write the command CMD_TEST_FIL_ERROR code 13H into the command register, and write 01H into the execution command register to execute the command. An interrupt will be generated after the command has been executed. If the command is executed successfully and the file has no errors, the return value in the status register is FR_OK.

CMD_CHANGE_FILE_STAT: CMD_CHANGE_FILE_STAT:

该命令用于修改文件的属性包括属性字段、文件名、创建时间。当文件位于根目录下时,往属性字段寄存器、文件名寄存器、创建时间寄存器中填入修改的数据,在文件信息修改标志位寄存器中指定需要修改的属性。01H表示修改文件名、02H表示修改属性字段、04H表示修改创建时间。主控器可以选择性的修改这3个属性。往命令寄存器中写入CMD_CHANGE_FILE_STAT的命令代码14H,往执行命令寄存器中写入01H即可执行命令。命令执行完成后将会产生中断。主控器可以查询状态寄存器来获取命令的执行状况。命令CMD_CHANGE_FILE_STAT可能的返回值为FR_OK, FR_DISK_ERR, FR_NO_PATH,FR_NOT_READY,FR_WRITE_PROTECTED,FR_INT_ERR,FR_NO_FILE,FR_INVALID_NAME, FR_EXIST FR_NO_FILESYSTEM。当返回值为FR_OK时表明属性修改成功。 This command is used to modify the attributes of the file, including the attribute field, file name, and creation time. When the file is located in the root directory, fill in the modified data in the attribute field register, file name register, and creation time register, and specify the attribute to be modified in the file information modification flag bit register. 01H means to modify the file name, 02H means to modify the attribute field, and 04H means to modify the creation time. The main controller can selectively modify these 3 attributes. Write the command code 14H of CMD_CHANGE_FILE_STAT into the command register, and write 01H into the execution command register to execute the command. An interrupt will be generated when the command execution is complete. The master controller can query the status register to obtain the execution status of the command. The possible return values of the command CMD_CHANGE_FILE_STAT are FR_OK, FR_DISK_ERR, FR_NO_PATH, FR_NOT_READY, FR_WRITE_PROTECTED, FR_INT_ERR, FR_NO_FILE, FR_INVALID_NAME, FR_EXIST FR_NO_FILESYSTEM. When the return value is FR_OK, it indicates that the attribute modification is successful.

CDM_READ_CONTINUE: CDM_READ_CONTINUE:

该命令用于以字节或扇区为单位连续的读同一个文件。 This command is used to continuously read the same file in units of bytes or sectors.

CMD_WRITE_CONTINUE: CMD_WRITE_CONTINUE:

该命令用于以字节或扇区为单位连续的写同一个文件。 This command is used to continuously write the same file in units of bytes or sectors.

CMD_GET_FREE_SECTOR: CMD_GET_FREE_SECTOR:

该命令用于获取SD卡中空闲的扇区号。往命令寄存器中写入命令CMD_GET_FREE_SECTOR代码17H、往执行命令寄存器中写入01H即可执行命令。若命令执行成功,状态寄存器中的返回值为FR_OK,数据大小寄存器23H~26H中为空闲的扇区号。 This command is used to obtain the free sector number in the SD card. Write the command CMD_GET_FREE_SECTOR code 17H into the command register, and write 01H into the execution command register to execute the command. If the command is executed successfully, the return value in the status register is FR_OK, and the data size register 23H~26H is the idle sector number.

CMD_GET_DISK_CAPACITY: CMD_GET_DISK_CAPACITY:

该命令用于获取磁盘的容量。往命令寄存器中写入命令CMD_GET_DISK_CAPACITY代码18H、往执行命令寄存器中写入01H即可执行命令。若命令执行成功,状态寄存器中的返回值为FR_OK,数据大小寄存器23H~26H中为磁盘中所有的扇区数。 This command is used to get the capacity of the disk. Write the command CMD_GET_DISK_CAPACITY code 18H into the command register, and write 01H into the execution command register to execute the command. If the command is executed successfully, the return value in the status register is FR_OK, and the data size register 23H~26H is the number of all sectors in the disk.

表3定义了所有的命令返回值。 Table 3 defines all command return values.

表1 Table 1

寄存器地址register address 字节数Bytes 寄存器定义register definition 宏定义macro definition 00H00H 11 状态寄存器status register OPERATION_STATUSOPERATION_STATUS 01H01H 11 执行命令寄存器execute command register EXECUTE_CMDEXECUTE_CMD 02H02H 11 命令寄存器command register CMD_REGISTERCMD_REGISTER 03~0AH03~0AH 88 文件名寄存器filename register FILE_NAMEFILE_NAME 0BH~0DH0BH~0DH 33 扩展名寄存器extension register EXTENSION_NAMEEXTENSION_NAME 0EH0EH 11 属性字节寄存器Attribute Byte Register FILE_ATTRIBUTEFILE_ATTRIBUTE 0FH0FH 11 文件信息修改标志位File information modification flag FILE_MODIFYFILE_MODIFY 10H10H 11 创建时间10毫秒位Creation time 10 milliseconds bit FILE_CRTTIMETENTHFILE_CRTTIMETENTH 11H~12H11H~12H 22 文件创建时间file creation time FILE_CRTTIMEFILE_CRTTIME 13H~14H13H~14H 22 文件创建日期file creation date FILE_CRTDATEFILE_CRTDATE 15H~16H15H~16H 22 文件最后访问日期File Last Access Date FILE_LASTACCDATEFILE_LASTACCDATE 17H~18H17H~18H 22 文件起始簇号高16位The high 16 bits of the file start cluster number FILE_FSTCLUSHIFILE_FSTCLUSHI 19H~1AH19H~1AH 22 文件最近的修改时间file last modification time FILE_WRITETIMEFILE_WRITETIME 1BH~1CH1BH~1CH 22 文件最近的修改时间file last modification time FILE_WRITEDAYEFILE_WRITED DAYE 1DH~1EH1DH~1EH 22 文件起始簇号低16The starting cluster number of the file is lower than 16 FILE_FSTCLUSLOFILE_FSTCLUSLO 1FH~22H1FH~22H 44 文件的长度file length FILE_SIZEFILE_SIZE 23H~26H23H~26H 44 数据大小寄存器Data Size Register OPERATION_SIZEOPERATION_SIZE 27H27H 11 可读写字节数寄存器Readable and writable byte count register AVAILABLE_COUNTAVAILABLE_COUNT 80H~FFH80H~FFH  the 数据寄存器data register DATA_REG_BASEDATA_REG_BASE

  表2 Table 2

代码the code 功能Function 命令名称command name 输入数据Input data 输出数据Output Data 是否产生中断Whether to generate interrupt 00H00H SD卡初始化SD card initialization CMD_DISK_MOUNTCMD_DISK_MOUNT  the 操作状态operating state yes 01H01H 新建目录new directory CMD_CREATE_DIRCMD_CREATE_DIR FAT32短目录项FAT32 short directory entry 操作状态operating state yes 02H02H 打开目录open Directory CMD_OPEN_DIRCMD_OPEN_DIR 目录名directory name 操作状态operating state yes 03H03H 读取目录信息read directory information CMD_READ_DIR_STATCMD_READ_DIR_STAT 目录名directory name 目录信息和操作状态Directory Information and Operational Status yes 04H04H 读取目录项read directory entry CMD_READ_DIR_ITEMCMD_READ_DIR_ITEM 目录名directory name FAT32短目录项和操作状态FAT32 short directory entry and operating status yes 05H05H 修改目录属性Modify directory properties CMD_CHANGE_DIR_STATCMD_CHANGE_DIR_STAT 目录名和需修改的属性Directory name and attributes to be modified 操作状态operating state  the 06H06H 获取当前目录get the current directory CMD_GET_CURRENT_DIRCMD_GET_CURRENT_DIR  the 当前目录路径名和操作状态Current directory pathname and operation status yes 07H07H 切换目录switch directory CMD_CHANGE_DIRCMD_CHANGE_DIR 目录名(包括路径名)directory name (including pathname) 操作状态operating state yes 08H08H 删除目录delete directory CMD_DELETE_DIRCMD_DELETE_DIR 目录名(包括路径名)directory name (including pathname) 操作状态operating state yes 09H09H 新建文件create a new file CMD_CREATE_FILECMD_CREATE_FILE FAT32短目录项FAT32 short directory entry 操作状态operating state yes 0AH0AH 打开文件open a file CMD_OPEN_FILECMD_OPEN_FILE 文件名file name 操作状态operating state yes 0BH0BH 以字节为单位读文件read file in bytes CMD_BYTE_READCMD_BYTE_READ 文件名和读取的字节数filename and number of bytes read 数据寄存器中有效字节数和数据Valid byte count and data in the data register yes 0CH0CH 以扇区为单位读文件read file by sector CMD_SECTOR_READCMD_SECTOR_READ 文件名和读取的扇区数filename and number of sectors read 数据寄存器中有效字节数和数据Valid byte count and data in the data register yes 0DH0DH 以字节为单位写文件write file in bytes CMD_BYTE_WRITECMD_BYTE_WRITE 文件名、写入的字节数、写入数据和数据寄存器中有效字节数File name, number of bytes written, data written, and number of valid bytes in the data register 本次操作实际写入的字节数和操作状态The number of bytes actually written in this operation and the operation status yes 0EH0EH 以扇区为单位写文件Write files in units of sectors CMD_SECTOR_WRITECMD_SECTOR_WRITE 文件名、写入的扇区数、写入数据和数据寄存器中有效字节数File name, number of sectors written, data written and number of valid bytes in the data register 本次操作实际写入的字节数和操作状态The number of bytes actually written in this operation and the operation status yes 0FH0FH 获取当前文件指针Get the current file pointer CMD_GET_POINTERCMD_GET_POINTER 文件名file name 当前文件指针的偏移量和操作状态The offset and operation status of the current file pointer yes 10H10H 移动当前文件的指针Move the pointer of the current file CMD_MOVE_POINTERCMD_MOVE_POINTER 文件名和偏移的字节数filename and offset in bytes 操作状态operating state yes 11H11H 获取文件的信息Get file information CMD_GET_FILE_STATCMD_GET_FILE_STAT 文件名file name FAT32短目录项操作状态FAT32 short directory entry operation status yes 12H12H 测试是否到达文件的末尾Test whether the end of the file has been reached CMD_END_OF_FILECMD_END_OF_FILE 文件名file name 操作状态operating state yes 13H13H 测试文件是否发生错误Test file for errors CMD_TEST_FILE_ERRORCMD_TEST_FILE_ERROR 文件名file name 操作状态operating state yes 14H14H 修改文件的属性modify file properties CMD_CHANGE_FILE_STATCMD_CHANGE_FILE_STAT 文件名、属性指示位和文件属性File name, attribute indicator bits, and file attributes 操作状态operating state yes 15H15H 继续执行读操作continue reading CMD_READ_CONTINUECMD_READ_CONTINUE  the 操作状态operating state yes 16H16H 继续执行写操作continue writing CMD_WRITE_CONTINUECMD_WRITE_CONTINUE  the 操作状态operating state yes 17H17H 查询空闲扇区号Query free sector number CMD_GET_FREE_SECTORCMD_GET_FREE_SECTOR  the 空闲扇区号和操作状态Free sector number and operating status yes 18H18H 查询磁盘容量Query disk capacity CMD_GET_DISK_CAPACITYCMD_GET_DISK_CAPACITY  the 磁盘的扇区总数和操作状态The total number of sectors and the operating status of the disk yes

表3 table 3

代码the code 状态名称state name 备注Remark 00H00H FR_OKFR_OK 命令操作成功The command operation succeeded 01H01H FR_NOT_READYFR_NOT_READY 挂在SD卡或者初始化文件系统失败Failed to hang on the SD card or initialize the file system 02H02H FR_INT_ERRFR_INT_ERR 要求失败request failed 03H03H FR_DISK_ERRFR_DISK_ERR 不可恢复性错误unrecoverable error 04H04H FR_NO_FILEFR_NO_FILE 找不到指定的文件The specified file could not be found 05H05H FR_NO_PATHFR_NO_PATH 找不到指定的路径The specified path could not be found 06H06H FR_INVALID_NAMEFR_INVALID_NAME 指定的路径名不合法The specified path name is invalid 07H07H FR_DENIEDFR_DENIED 指定的操作被拒绝执行The specified operation is denied 08H08H FR_EXISTFR_EXIST 指定的目录名或者文件名已经存在The specified directory name or file name already exists 09H09H FR_WRITE_PROTECTEDFR_WRITE_PROTECTED 对写保护的磁盘进行写操作Write to a write-protected disk 0AH0AH FR_NO_FILESYSTEMFR_NO_FILESYSTEM SD卡上面没有FAT32文件系统There is no FAT32 file system on the SD card 0BH0BH FR_TOO_MANY_OPEN_FILESFR_TOO_MANY_OPEN_FILES 打开的文件太多超过允许的数目Too many open files than allowed 0CH0CH FR_READ_ALLFR_READ_ALL 所有的读/写操作完毕All read/write operations complete 0DH0DH FR_END_OF_FILEFR_END_OF_FILE 文件指针到达文件末尾The file pointer reaches the end of the file

Claims (6)

1.基于FPGA的SD卡文件管理控制器,其特征在于包括FPGA芯片(1)、串行配置芯片(4)、SDRAM存储器(5)、主控器接口(6)、SD卡插座(15),其中在FPGA(1)内部实现FAT32文件管理单元(2)和SD卡接口单元(3); 1. FPGA-based SD card file management controller, characterized in that it includes FPGA chip (1), serial configuration chip (4), SDRAM memory (5), main controller interface (6), SD card socket (15) , where the FAT32 file management unit (2) and the SD card interface unit (3) are implemented inside the FPGA (1); 所述FAT32文件管理单元(2)为主控器提供主控器接口(6)、操作文件系统的用户命令,主控器通过该接口在SD卡文件管理控制器的寄存器中写入用户命令即可完成对SD卡中FAT32文件系统的管理; The FAT32 file management unit (2) provides the main controller interface (6) and user commands for operating the file system, and the main controller writes the user command in the register of the SD card file management controller through the interface. Can complete the management of the FAT32 file system in the SD card; 所述SD卡接口单元(3)在FAT32文件管理单元(2)的控制下,负责SD卡命令的产生和应答接收,以及SD卡中数据的读写; The SD card interface unit (3) is under the control of the FAT32 file management unit (2), responsible for generating SD card commands and receiving responses, as well as reading and writing data in the SD card; 在读写SD卡中的数据时,采用了4位数据线宽的SD模式。 When reading and writing data in the SD card, the SD mode with a 4-bit data line width is adopted. 2.根据权利要求1所述的一种基于FPGA的SD卡文件管理控制器,其特征在于:所述的FAT32文件管理单元(2)包括NIOS II处理器(7)、EPCS控制模块(8)、SDRAM控制模块(9)、主控器接口模块(10)、Avalon总线(11)、Avalon接口模块(12); 2. a kind of SD card file management controller based on FPGA according to claim 1, is characterized in that: described FAT32 file management unit (2) comprises NIOS II processor (7), EPCS control module (8) , SDRAM control module (9), main controller interface module (10), Avalon bus (11), Avalon interface module (12); 所述NIOS II处理器(7)通过主控器接口模块(10)获取主控器输入的用户命令与数据,并反馈信息给主控器; The NIOS II processor (7) obtains user commands and data input by the main controller through the main controller interface module (10), and feeds back information to the main controller; 所述NIOS II处理器(7)通过Avalon接口模块(12)与SD卡接口单元(3)进行通信; Described NIOS II processor (7) communicates with SD card interface unit (3) by Avalon interface module (12); 所述NIOS II处理器(7)通过EPCS控制模块(8)、SDRAM控制模块(9)分别与FPGA外部的串行配置芯片(4)和SDRAM存储器(5)相连。 The NIOS II processor (7) is connected to the serial configuration chip (4) and the SDRAM memory (5) outside the FPGA respectively through the EPCS control module (8) and the SDRAM control module (9). 3.根据权利要求1所述的一种基于FPGA的SD卡文件管理控制器,其特征在于:所述的FAT32文件管理单元(2)上面移植了FATFS文件系统模块。 3. An FPGA-based SD card file management controller according to claim 1, characterized in that: the FATFS file system module is transplanted on the FAT32 file management unit (2). 4.根据权利要求1所述的一种基于FPGA的SD卡文件管理控制器,其特征在于:所述的SD卡接口单元(3)包括读写缓冲FIFO模块(13)、 SD卡数据控制模块(14)、SD卡命令控制模块(16)和SD卡时钟控制模块(17); 4. a kind of SD card file management controller based on FPGA according to claim 1, is characterized in that: described SD card interface unit (3) comprises read-write buffer FIFO module (13), SD card data control module (14), SD card command control module (16) and SD card clock control module (17); 所述读写缓冲FIFO模块(13)负责缓存读写SD卡时的数据, The read-write buffer FIFO module (13) is responsible for buffering the data when reading and writing the SD card, 所述SD卡数据控制模块(14)负责DAT线上数据的接收和发送以及数据的校验, The SD card data control module (14) is responsible for receiving and sending data on the DAT line and verifying data, 所述SD卡命令控制模块(16)负责控制CMD线上命令发送和回复接收, The SD card command control module (16) is responsible for controlling CMD online command sending and reply receiving, 所述SD卡时钟控制模块(17)负责控制CLK时钟线的频率,以控制读写SD卡的数据速率。 The SD card clock control module (17) is responsible for controlling the frequency of the CLK clock line to control the data rate of reading and writing the SD card. 5.根据权利要求1所述的一种基于FPGA的SD卡文件管理控制器,其特征在所述的主控器接口为8位地址线、8位数据线。 5. a kind of SD card file management controller based on FPGA according to claim 1, it is characterized in that described master controller interface is 8 address lines, 8 data lines. 6.根据权利要求1所述的一种基于FPGA的SD卡文件管理控制器,其特征在于所述操作文件系统的用户命令包括新建、打开、读写、关闭文件,新建、打开、关闭目录,磁盘容量查询、空闲扇区查询、以扇区或字节为单位对文件进行读写。 6. a kind of SD card file management controller based on FPGA according to claim 1, it is characterized in that the user order of described operation file system comprises newly-built, open, read and write, close file, new-build, open, close directory, Disk capacity query, free sector query, read and write files in units of sectors or bytes.
CN2011103579366A 2011-11-11 2011-11-11 SD card file management controller based on FPGA Pending CN102436428A (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN2011103579366A CN102436428A (en) 2011-11-11 2011-11-11 SD card file management controller based on FPGA

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN2011103579366A CN102436428A (en) 2011-11-11 2011-11-11 SD card file management controller based on FPGA

Publications (1)

Publication Number Publication Date
CN102436428A true CN102436428A (en) 2012-05-02

Family

ID=45984499

Family Applications (1)

Application Number Title Priority Date Filing Date
CN2011103579366A Pending CN102436428A (en) 2011-11-11 2011-11-11 SD card file management controller based on FPGA

Country Status (1)

Country Link
CN (1) CN102436428A (en)

Cited By (6)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN102708075A (en) * 2012-05-15 2012-10-03 山东大学 Secure digital (SD) memory card hardware control device and control method
CN103309828A (en) * 2013-05-31 2013-09-18 杭州晟元芯片技术有限公司 SD (secure digital) card subordinate controller and control method thereof
CN105739927A (en) * 2016-01-29 2016-07-06 武汉精测电子技术股份有限公司 Soft-core processor-based mobile memory card read-write method and file upgrading system
CN114578099A (en) * 2022-03-02 2022-06-03 北京百度网讯科技有限公司 Equipment test system
CN114647449A (en) * 2020-12-17 2022-06-21 航天科工惯性技术有限公司 Data processing method, device and system of terminal equipment
CN117991995A (en) * 2024-03-26 2024-05-07 中国人民解放军海军潜艇学院 SD card file continuous reading or writing control method, system and storage device

Citations (1)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN101634071A (en) * 2009-08-13 2010-01-27 浙江理工大学 Electronic jacquard machine control system based on FPGA

Patent Citations (1)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN101634071A (en) * 2009-08-13 2010-01-27 浙江理工大学 Electronic jacquard machine control system based on FPGA

Non-Patent Citations (2)

* Cited by examiner, † Cited by third party
Title
何伟等: "基于FPGA的SD卡控制器设计及应用", 《世界科技研究与发展》 *
杨爽等: "基于NiosⅡ和SD卡的数据采集系统的设计", 《核电子学与探测技术》 *

Cited By (10)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN102708075A (en) * 2012-05-15 2012-10-03 山东大学 Secure digital (SD) memory card hardware control device and control method
CN103309828A (en) * 2013-05-31 2013-09-18 杭州晟元芯片技术有限公司 SD (secure digital) card subordinate controller and control method thereof
CN103309828B (en) * 2013-05-31 2016-03-09 杭州晟元数据安全技术股份有限公司 A kind of SD card is from controller and control method
CN105739927A (en) * 2016-01-29 2016-07-06 武汉精测电子技术股份有限公司 Soft-core processor-based mobile memory card read-write method and file upgrading system
CN105739927B (en) * 2016-01-29 2019-01-04 武汉精测电子集团股份有限公司 A kind of mobile memory card reading/writing method and document upgrading system based on soft-core processor
CN114647449A (en) * 2020-12-17 2022-06-21 航天科工惯性技术有限公司 Data processing method, device and system of terminal equipment
CN114647449B (en) * 2020-12-17 2024-02-20 航天科工惯性技术有限公司 Data processing method, device and system of terminal equipment
CN114578099A (en) * 2022-03-02 2022-06-03 北京百度网讯科技有限公司 Equipment test system
CN117991995A (en) * 2024-03-26 2024-05-07 中国人民解放军海军潜艇学院 SD card file continuous reading or writing control method, system and storage device
CN117991995B (en) * 2024-03-26 2024-06-07 中国人民解放军海军潜艇学院 SD card file continuous reading or writing control method, system and storage device

Similar Documents

Publication Publication Date Title
US6678785B2 (en) Flash management system using only sequential write
US7318117B2 (en) Managing flash memory including recycling obsolete sectors
US10831734B2 (en) Update-insert for key-value storage interface
US5715455A (en) Apparatus and method for storing file allocation table efficiently in memory
CN114840138A (en) File system storage allocation based on regions of memory devices
US11030156B2 (en) Key-value store with partial data access
CN102436428A (en) SD card file management controller based on FPGA
US11816358B2 (en) Preserving application data order in memory devices
WO2008048388A2 (en) Virtual memory card controller
JP2012014706A (en) Selectively utilizing a plurality of disparate solid state storage locations
KR101055324B1 (en) Enhanced Host Interface
WO2020077301A1 (en) Efficient file storage and retrieval system, method and apparatus
US11630595B2 (en) Methods and systems of efficiently storing data
US12045163B2 (en) Storage device for classifying data based on stream class number, storage system, and operating method thereof
US20170153842A1 (en) Data allocation in hard drives
WO2017184477A1 (en) Adapted block translation table (btt)
CN115729461A (en) Dual Mode Storage Device
JP2020502704A (en) System and method for storing large files using a file system based on a file allocation table
CN102375781B (en) Data protection method, memory controller and portable memory storage device
CN202362777U (en) SD (secure digital) card file management controller based on FPGA (field programmable gate array)
CN101089842A (en) Method for duplicating file in embedded equipment
US20140201167A1 (en) Systems and methods for file system management
CN106557275B (en) A kind of method and device of data processing
US20100274828A1 (en) Electronic Device, Storage Area Allocation Method for File System, and Computer Product
CN100444166C (en) Position-based interface access method and device for FAT file system

Legal Events

Date Code Title Description
C06 Publication
PB01 Publication
C10 Entry into substantive examination
SE01 Entry into force of request for substantive examination
C02 Deemed withdrawal of patent application after publication (patent law 2001)
WD01 Invention patent application deemed withdrawn after publication

Application publication date: 20120502