CN106897236A - Method, device and SD card model with SD card console controller information exchange - Google Patents
- ️Tue Jun 27 2017
Detailed Description
In order to make the objects, technical solutions and advantages of the embodiments of the present invention clearer, the technical solutions in the embodiments of the present invention will be clearly and completely described below with reference to the drawings in the embodiments of the present invention, and it is obvious that the described embodiments are some, but not all, embodiments of the present invention. All other embodiments, which can be derived by a person skilled in the art from the embodiments given herein without making any creative effort, shall fall within the protection scope of the present invention.
Fig. 1 is a flowchart of a first embodiment of a method for information interaction with a host controller of an SD card, where the method of this embodiment is applied to an SD card model, and the SD card model has a memory (memory) function and an IO function, as shown in fig. 1, the method of this embodiment may include:
s101, receiving a control command sent by an SD card host controller, wherein the control command comprises a storage control command or an IO control command.
And S102, generating a message packet corresponding to the control command according to the control command.
And S103, sending the message packet to the SD card host controller.
In an alternative implementation manner, before executing S101, it may be further determined that a control command line between the SD card model and the SD card host controller is in an active state, and that a control command enable signal currently indicates that the SD card model is in an input state. In this embodiment, a clock sdclk, a control command line, a control command enable signal, a data line, and a data enable signal exist between the SD card model and the SD card host controller; for example: when the control command enable signal is 0, the SD card model is in an output state, and when the control command enable signal is 1, the SD card model is in an input state; when the data enable signal is 0, the SD card model is in an output state, and when the data enable signal is 1, the SD card model is in an output state. After the SD card model of this embodiment is powered on, the SD card model waits for a control command sent by the SD card host controller, and during this period, the state of the control command line between the SD card model and the SD card host controller is constantly monitored, and when it is determined that the control command line is in an operating state (for example, the level of the control command line is 0) and it is determined that the control command enable signal currently indicates that the SD card model is in an input state (for example, the control command enable signal is 1), the SD card model starts to receive the control command.
In this embodiment, by receiving a control command sent by the SD card host controller, where the control command may be a storage control command or an IO control command, and then generating a message packet corresponding to the control command according to the received control command, and sending the generated message packet to the SD card host controller, information interaction between the SD card model having a storage function and an IO function and the SD card host controller is achieved.
Fig. 2 is a flowchart of a second embodiment of a method for information interaction with a host controller of an SD card, where the method of this embodiment is applied to an SD card model, and the SD card model has a memory (memory) function and an IO function, as shown in fig. 2, the method of this embodiment may include:
s201, when the first bit of a control command sent by the SD card host controller is received, counting is started and is 0, the first bit of the control command is stored to the N-1 th bit of the N-bit register until the count is N-1, the control command is determined to be received completely, and the count is cleared.
In this embodiment, the control command sent by the SD card host controller is an N-bit command, and in this embodiment, the control command sent by the SD card host controller is received and stored in an N-bit register, the received control command is stored in the high order of the N-bit register, specifically, the control command starts to count and counts to 0 when the first bit of the control command is received (for example, the control command is counted by an adder counter, at this time, the count of the adder counter is 0), and the first bit is stored in the N-1 th bit of the N-bit register, then the control command starts to count to 1 when the second bit of the control command is received, and the second bit is stored in the N-2 th bit of the N-bit register, and so on, the control command is counted to N-1 when the N-th bit of the control command is received, and the N-th bit is stored in the 0 th bit of the N. When the count is N-1, the control command reception is completed, and then the count is cleared.
S202, according to the data information in the control command, calculating a Cyclic Redundancy Check (CRC) corresponding to the data information.
In this embodiment, the CRC corresponding to the preset bit may be calculated according to the preset bit in the N bits of the control command. Taking N as an example of 48, the present embodiment can calculate CRC of 47 th bit to 40 th bit (eight bits in total) in the 48-bit register for storing the 48-bit control command.
S203, generating a check result of the control command according to whether the CRC obtained by detection and calculation is the same as the CRC carried by the control command and the value of the end bit of the control command is detected.
The control command in this embodiment carries a CRC, and after the CRC is calculated in S202, it is detected whether the calculated CRC is the same as the CRC carried in the control command, and a value of an end bit of the control command is detected, where the end bit of the control command is a 0 th bit in an N-bit memory storing the control command, and then a check result of the control command is generated, where the check result includes: the calculated CRC is the same as the CRC carried in the control command, and the value of the ending bit of the control command is 1; or the calculated CRC is the same as the CRC carried in the control command, and the value of the ending bit of the control command is not 1; the calculated CRC is different from the CRC carried in the control command, and the value of the ending bit of the control command is 1; or the calculated CRC is different from the CRC carried in the control command, and the value of the ending bit of the control command is not 1.
Taking N as 48 as an example, the CRC carried by the control command may be the seventh bit to the first bit (seven bits in total) in a 48-bit memory storing the control command.
And S204, sending a message packet corresponding to the control command to the SD card host controller, wherein the message packet carries the verification result.
In this embodiment, after the verification result of the control command is obtained, the message packet carrying the verification result corresponding to the control command is sent to the SD card host controller.
Optionally, an optional implementation manner of S203 is: and generating reply command information according to whether the CRC obtained by detection and calculation is the same as the CRC carried by the control command and the value of the end bit of the control command, wherein the reply command information comprises a length value representing the length of the reply command and a content value of the reply command corresponding to the check result. Accordingly, an optional implementation manner of S204 is: and circulating the length value of the reply command length for a clock period, and driving the content value to a command line between the SD card host controller and the SD card host controller so that the SD card host controller obtains the content value on the command line.
The content value of the reply command is used for indicating the verification result of the control command sent by the SD card host controller. The length value of the reply command length (response _ s) may be 0, 48, 136; the values of 135 th and 134 th of the content value (response _ cmd) of the reply command are always 0, the 88 th bit of the content value of the reply command is always 1 when the length value of the reply command length is 48, and the 0 th bit of the content value of the reply command is always 1 when the length value of the reply command length is 136.
After the reply command information is generated, a length value (e.g., 48 or 136) of the command length is replied cyclically according to the reply command information, and the content value of the reply command is driven to a command line between the SD card model and the SD card host controller, and meanwhile, a control command enable signal between the SD card model and the SD card host controller can be set to indicate that the SD card model is in an output state (e.g., when the control command enable signal is set to 0), so that the SD card host controller can obtain the content value of the reply command on the command line in the output state of the SD card model, and further obtain a verification result of the control command.
Optionally, when the control command is a storage stop command, such as CMD12, the reply command information further includes a storage stop instruction (sd _ auto _ stop) for instructing to stop sending data related to the storage function. When the control command is an IO stop command, for example, CMD 52abort, the reply command information further includes an IO stop indication (IO _ auto _ stop) for instructing to stop sending data related to the IO function. Optionally, the reply command information is in the form of a mailbox with a depth of 1. The specific form of the reply command message may be as follows:
logic[135:0]response_cmd;
logic[7:0]response_s;
logic sd_auto_stop;
logic io_auto_stop;
fig. 3 is a flowchart of a third embodiment of a method for information interaction with an SD card host controller according to the present invention, where the method of this embodiment is applied to an SD card model, and the SD card model has a memory (memory) function and an IO function, as shown in fig. 3, on the basis of the foregoing embodiments of the present invention, after receiving a control command sent by the SD card host controller, the method of this embodiment may further include:
s301, generating data control information according to the control command; when the control command is a storage control command, the data control information is storage control data; and when the control command is an IO control command, the data control information is IO control data.
S302, receiving data sent by the SD card host controller corresponding to the data control information according to the data control information, or sending data corresponding to the data control information to the SD card host controller.
By the embodiment, data interaction between the SD card model and the SD card host controller can be realized.
Fig. 4 is a flowchart of a fourth embodiment of a method for information interaction with an SD card host controller according to the present invention, where the method of this embodiment is applied to an SD card model, and the SD card model has a storage (memory) function and an IO function, as shown in fig. 4, and on the basis of the embodiment shown in fig. 3, when the data control information is control information of data sent by the SD card host controller, the step S302 may include:
s401, setting the state of the SD card model as the state of receiving data according to the data control information.
S402, monitoring the level of a 0 th bit data line between the SD card host controller and the data enable signal of the 0 th bit data line, and when the level of the 0 th bit data line is determined to be 0 and the data enable signal indicates that the SD card model is in an input state, starting to receive data sent by the SD card host controller.
S403, after a first preset period, starting to receive the CRC of the data, and calculating the CRC of the data according to the data.
S404, comparing the received CRC with the CRC obtained by calculation after a second preset period, and determining a value of a reply CRC state sent to the SD card host controller according to the comparison result.
S405, after a third preset period, starting to send the value of the reply CRC state to the SD card host controller; setting the level of the 0 th bit data line to be 0 after a fourth preset period; and setting the level of the 0 th bit data line to be 1 after a fifth preset period.
And S406, monitoring the level of the 0 th bit data line and the data enable signal of the 0 th bit data line after a sixth preset period.
In this embodiment, the state of the SD card model is set to the state of receiving data according to the data control information, for example, the state value of the SD card model may be set to 6, and the SD card model is in a data IDLE (IDLE) state at this time, and the level of the 0 th bit data line between the SD card model and the SD card host controller and the data enable signal of the 0 th bit data line are monitored; if the level of the 0 th bit DATA line is 0 and the DATA enable signal indicates that the SD card model is in an input state (e.g., the DATA enable signal is 1), the SD card model enters a receive DATA (RX _ DATA) state, i.e., starts receiving DATA sent by the SD card host controller, and then enters a CRC reception (RX _ CRC) state from the DATA reception state after a first preset period, i.e., starts receiving CRC of the DATA after the first preset period. It should be noted that, if the data corresponding to the data control information is transmitted in a single-line mode, the first preset period is a time period of a length value of 8 × a unit data block length; if the data corresponding to the data control information is transmitted in a four-wire mode, the first preset period is a time period of length value of 2 × unit data block length. In this embodiment, the CRC of the data may be calculated according to the received data, and the data enters an END of reception (RX _ END) state after a second preset period (for example, 16 periods) of starting to receive the CRC of the data, and the received CRC is compared with the calculated CRC, and a value of a reply CRC state sent to the SD card host controller is determined according to the comparison result; in this embodiment, the receiving end state is unconditionally jumped to a receiving WAIT (RX _ WAIT) state, and after a third preset period (e.g., 2 periods), the SD card host controller enters a CRC (CRC _ RESP) state unconditionally, that is, the SD card host controller starts to send a value of the CRC state, after a fourth preset period (e.g., 5 periods), the SD card host controller enters a Program (PRG) state, that is, the level of the 0 th bit data line is set to 0 (the level is pulled down), then after a fifth preset period, the SD card host controller sets the level of the 0 th bit data line to 1 (the level is pulled up), and after a sixth preset period, the SD card host controller enters a data idle state, that is, the level of the 0 th bit data line and the data enable signal of the 0 th bit data line are continuously monitored. It should be noted that, if the data control information is used to indicate that the data corresponding to the data control information is single block data, in this embodiment, before monitoring the level of the 0 th bit data line and the data enable signal of the 0 th bit data line after the sixth preset period, the state of the SD card model is set to a data sending and receiving state, for example, the state value of the SD card model is set to 4.
In summary, the scheme of this embodiment can implement receiving data sent by the SD card host controller.
Fig. 5 is a flowchart of a fifth embodiment of the method for information interaction with a host controller of an SD card, where the method of this embodiment is applied to an SD card model, and the SD card model has a memory (memory) function and an IO function, as shown in fig. 5, and on the basis of the embodiment shown in fig. 3, when the data control information is control information of data sent by the SD card model, S302 may include:
s501, detecting the state of the SD card model, and setting the state of the SD card model as the state of sending data according to the data control information.
And S502, starting to send data to the SD card host controller after a seventh preset period.
And S503, sending the CRC of the data to the SD card host controller after an eighth preset period.
And S504, detecting the state of the SD card model after a ninth preset period.
In this embodiment, the state of the SD card model is set to a data sending state according to the data control information, for example, the state value of the SD card model is set to 5, and at this time, the SD card model is in a data IDLE (IDLE) state, and the state value of the SD card model is detected; entering a sending waiting (TX _ WAIT) state when the state value of the SD card model is detected to be 5, then entering a sending header (TX _ HEAT) state after a plurality of preset periods, and entering a DATA sending (TX _ DATA) state in the next period of the sending header state, namely starting sending DATA to the SD card host controller after detecting a seventh preset period when the state value of the SD card model is detected to be 5. Then, after an eighth preset period, entering a transmit CRC (TX _ CRC) state from a data transmitting state, that is, starting to transmit the data CRC to the SD card host controller, wherein if data corresponding to the data control information is transmitted in a single-line mode, the eighth preset period is a length value time period of 8 × a unit data block length; if the data corresponding to the data control information is transmitted in a four-wire mode, the eighth preset period is a time period of a length value of 2 × a unit data block length. And then entering a transmission END (TX _ END) state after a ninth preset period, and then entering a data idle state, namely continuously detecting the state of the SD card model. It should be noted that the data control information is used to indicate that the data corresponding to the data control information is single block data, and in this embodiment, after sending the CRC of the data to the SD card host controller, the state of the SD card model is set to a state of sending and receiving data, for example, the state value of the SD card model is set to 4.
If the reply command information includes a storage stop instruction, the embodiment stops sending data in the process of sending storage-related data and returns to the data idle state; if the reply command information includes an IO stop instruction, the embodiment stops sending data in the process of sending IO-related data.
On the basis of the foregoing embodiments of the present invention, in an optional implementation manner, when the data control information is storage control data, the data control information includes: the data bus comprises a data byte number, a data bus width, a data read-write start address and a first identifier, wherein the first identifier is used for identifying data to be read in a single block or write in a single block or read in multiple blocks or write in multiple blocks. The present embodiment can determine whether to transmit data or receive data based on the first identifier, and can determine whether the data is single block data or multi-block data. The data control information may be in the form of a mailbox with a depth of 1, and the specific form of the data control information may be as follows:
logic [31:0] sd _ blocklen; // number of bytes of data Block
logic [1:0] sd _ width; // data bus width
logic [31:0] sd _ addr; // data read-write start address
logic sd _ single _ read; // Single Block read
logic sd _ single _ write; // Single Block write
logic sd _ multi _ read; // Multi Block read
logic sd _ multi _ write; // Multi-Block write
In an optional implementation manner, when the data control information is IO control data, the data control information includes: the data bus comprises a data byte number, a data bus width, a transmitted data block number, a data read-write initial address, a function number and a second identification, wherein the first identification is used for identifying data to be single block read or single block write or multi-block read or multi-block write. The present embodiment can determine whether to transmit data or receive data based on the second identifier, and can determine whether the data is single block data or multi-block data. The data control information may be in the form of a mailbox with a depth of 1, and the specific form of the data control information may be as follows:
logic [15:0] io _ blocklen; // number of bytes of data Block
logic [1:0] io _ width; // data bus width
logic [8:0] block _ cnt; // number of data blocks transmitted
logic [16:0] io _ addr; // data read-write start address
logic [2:0] func _ num; // function number
logic io _ single _ read; // Single Block read flag
logic io _ single _ write; // Single Block write Mark
logic io _ multi _ read; // Multi Block read flag
logic io _ multi _ write; // Multi-Block write Mark
Fig. 6 is a schematic structural diagram of a first embodiment of an apparatus for information interaction with a host controller of an SD card, as shown in fig. 6, the apparatus of this embodiment is applied to an SD card model, where the SD card model has a storage function and an input/output IO function, and the apparatus of this embodiment may include: a receiving module 11, a processing module 12 and a sending module 13;
the receiving module 11 is configured to receive a control command sent by the SD card host controller, where the control command includes a storage control command or an IO control command;
the processing module 12 is configured to generate a message packet corresponding to the control command according to the control command;
and a sending module 13, configured to send the message packet to the SD card host controller.
The apparatus of this embodiment may be configured to implement the technical solution of the method embodiment of the present invention, and the implementation principle and the technical effect are similar, which are not described herein again.
Fig. 7 is a schematic structural diagram of a second embodiment of the apparatus for information interaction with a host controller of an SD card according to the present invention, as shown in fig. 7, the apparatus of this embodiment may further include, based on the apparatus structure shown in fig. 6: a determination module 14;
the determining module 14 is configured to determine that a control command line between the SD card model and the SD card host controller is in a working state before the receiving module 11 receives a control command sent by the SD card host controller; and determining that the control command enable signal currently indicates that the SD card model is in an input state.
Optionally, the control command is an N-bit command;
the receiving module 11 is specifically configured to: starting to count and counting to 0 when receiving the first bit of the control command, storing the first bit of the control command to the N-1 th bit of an N-bit register until the count is N-1, determining that the control command is received and resetting the count;
the processing module 12 is specifically configured to: calculating CRC corresponding to the data information according to the data information in the control command; and generating a check result of the control command according to whether the CRC obtained by detection and calculation is the same as the CRC carried by the control command and the value of the end bit of the control command, wherein the message packet carries the check result.
Optionally, when the processing module 12 generates the check result of the control command according to whether the CRC obtained through the detection calculation is the same as the CRC carried by the control command and the value of the end bit of the control command is detected, the processing module is specifically configured to: generating reply command information according to whether the CRC obtained through detection and calculation is the same as the CRC carried by the control command and the value of the end bit of the control command, wherein the reply command information comprises a length value representing the length of the reply command and a content value of the reply command corresponding to the check result;
the sending module 13 is specifically configured to: and circulating the length value of the reply command length for a clock period, and driving the content value to a command line between the SD card host controller and the SD card host controller so that the SD card host controller obtains the content value on the command line.
Optionally, the apparatus of this embodiment may further include: a setting module 15; the setting module 15 is configured to set a control command enable signal between the SD card host controller and the SD card host controller to indicate an SD card model output state after the sending module 13 drives the content value to a command line between the SD card host controller and the SD card host controller, so that the SD card host controller obtains the content value on the command line in the SD card model output state.
Optionally, when the control command is a storage stop command, the reply command information further includes a storage stop instruction, where the storage stop instruction is used to instruct to stop sending data related to the storage function;
when the control command is an IO stop command, the reply command information further includes an IO stop instruction, and the IO stop instruction is used to instruct to stop sending data related to the IO function.
Optionally, the apparatus of this embodiment may further include: a generation module 16; the generating module 16 is configured to generate data control information according to a control command sent by the SD card host controller after the receiving module 11 receives the control command; when the control command is a storage control command, the data control information is storage control data; when the control command is an IO control command, the data control information is IO control data;
the receiving module 11 is further configured to receive, according to the data control information, data sent by the SD card host controller corresponding to the data control information; or,
the sending module 13 is further configured to send data corresponding to the data control information to the SD card host controller.
Optionally, when the data control information is control information of data sent by the SD card host controller, the receiving module 11 is specifically configured to, when receiving, according to the data control information, data sent by the SD card host controller and corresponding to the data control information: setting the state of the SD card model as the state of receiving data according to the data control information; monitoring the level of a 0 th bit data line between the SD card host controller and the data enable signal of the 0 th bit data line, and starting to receive data sent by the SD card host controller when the level of the 0 th bit data line is determined to be 0 and the data enable signal indicates that the SD card model is in an input state; starting to receive the CRC of the data after a first preset period, and calculating the CRC of the data according to the data; comparing the received CRC with the CRC obtained by calculation after a second preset period, and determining a value of a reply CRC state sent to the SD card host controller according to the comparison result; starting to send the value of the reply CRC state to the SD card host controller after a third preset period; setting the level of the 0 th bit data line to be 0 after a fourth preset period; setting the level of the 0 th bit data line to be 1 after a fifth preset period; monitoring a level of the 0 th bit data line and a data enable signal of the 0 th bit data line after a sixth preset period.
Optionally, if data corresponding to the data control information is transmitted in a single-line mode, the first preset period is a time period of a length value of 8 × a unit data block length; the receiving module 11 is further configured to set the state of the SD card model to a state of sending and receiving data before monitoring the level of the 0 th bit data line and the data enable signal after a sixth preset period;
if the data corresponding to the data control information is transmitted in a four-wire mode, the first preset period is a time period of a length value of 2 × a unit data block length.
Optionally, when the data control information is control information of data sent by the SD card model, the sending module 13 is specifically configured to, when sending the data corresponding to the data control information to the SD card host controller: detecting the state of the SD card model, and setting the state of the SD card model as the state of sending data according to the data control information; starting to send data to the SD card host controller after a seventh preset period; sending CRC of the data to the SD card host controller after an eighth preset period; and detecting the state of the SD card model after a ninth preset period.
Optionally, if data corresponding to the data control information is transmitted in a single-line mode, the eighth preset period is a time period of a length value of 8 × a unit data block length; the sending module 13 is further configured to set the state of the SD card model as a state of sending and receiving data after sending the CRC of the data to the SD card host controller;
if the data corresponding to the data control information is transmitted in a four-wire mode, the eighth preset period is a time period of a length value of 2 × a unit data block length.
Optionally, when the data control information is storage control data, the data control information includes: the data bus comprises a data byte number, a data bus width, a data read-write initial address and a first identifier, wherein the first identifier is used for identifying data to be single-block read or single-block write or multi-block read or multi-block write;
when the data control information is IO control data, the data control information includes: the data bus comprises a data byte number, a data bus width, a transmitted data block number, a data read-write initial address, a function number and a second identification, wherein the first identification is used for identifying data to be single block read or single block write or multi-block read or multi-block write.
The apparatus of this embodiment may be configured to implement the technical solution of the method embodiment of the present invention, and the implementation principle and the technical effect are similar, which are not described herein again.
Fig. 8 is a schematic structural diagram of an SD card model according to an embodiment of the present invention, and as shown in fig. 8, the SD card model of this embodiment includes: the apparatus 10 for information interaction with the SD card host controller is configured to perform information interaction with the SD card host controller, where the apparatus 10 for information interaction with the SD card host controller may adopt a structure of an embodiment of the apparatus shown in fig. 6 or fig. 7, and correspondingly, the technical solution of the method embodiment of the present invention may be implemented, and the implementation principle and the technical effect thereof are similar, and are not described herein again.
Finally, it should be noted that: the above embodiments are only used to illustrate the technical solution of the present invention, and not to limit the same; while the invention has been described in detail and with reference to the foregoing embodiments, it will be understood by those skilled in the art that: the technical solutions described in the foregoing embodiments may still be modified, or some or all of the technical features may be equivalently replaced; and the modifications or the substitutions do not make the essence of the corresponding technical solutions depart from the scope of the technical solutions of the embodiments of the present invention.