Disclosure of Invention
The invention mainly aims to provide a data transmission method and device for a micro control unit and a data transmission system, so as to solve the problem that the efficiency of reading data from an external storage element by an MCU (microprogrammed control unit) in the prior art is low.
To solve the above problems, according to one aspect of the present invention, a data transmission method for a micro control unit is provided.
The data transmission method for the micro control unit of the invention comprises the following steps: reading data from the storage device through a serial port and then storing the data in a cache, converting the read data from serial to parallel during storage, wherein the frequency of a serial clock is higher than that of a parallel clock; and determining the address corresponding to the address appointed by the MCU in the storage device in the cache according to the corresponding relation between the storage address of the cache and the storage address of the storage device, and then sending the data in the corresponding address to the MCU through a parallel port.
Further, before reading data from the memory device through the serial port, the method further comprises: determining a rule followed by the MCU when the address is specified according to the address specified by the MCU in each history; the reading data from the storage device includes reading data from an address within the storage device determined according to the rule.
Further, the rule includes: the MCU acquires data from a section of continuous addresses in the storage device according to the address sequence; or, the law includes: the MCU acquires data from a plurality of address fields in the storage device, and the data is acquired in each address field according to the address sequence.
Further, the reading data from the storage device includes: reading partial data from addresses in the storage device determined according to the rule and recording the addresses of the partial data in the storage device before the MCU specifies the addresses in the storage device; before sending the data in the corresponding address to the MCU through a parallel port, the method further includes: confirming that the specified address is the same address as the address of the recorded part of data in the storage device.
Further, the reading data from the storage device includes: reading partial data from addresses in the storage device determined according to the rule and recording the addresses of the partial data in the storage device before the MCU specifies the addresses in the storage device; before sending the data in the corresponding address to the MCU through a parallel port, the method further includes: confirming that the designated address is different from the recorded address of the partial data in the storage device, then reading all data in the designated address of the MCU in the storage device from the storage device and covering the existing data in the cache with the all data.
To solve the above problem, according to another aspect of the present invention, another data transmission method for a micro control unit is proposed.
The data transmission method for the micro control unit of the invention comprises the following steps: receiving data sent by the MCU through a parallel port, storing the data in a cache, converting the read data from parallel to serial during storage, wherein the frequency of a serial clock is higher than that of a parallel clock, and recording an address in a storage device appointed by the MCU; and determining the address corresponding to the address appointed by the MCU in the storage device in the cache according to the corresponding relation between the storage address of the cache and the storage address of the storage device, and then sending the data in the corresponding address to the storage device through a serial port and storing the data in the address appointed by the MCU in the storage device.
Further, after sending the data in the corresponding address to the storage device through a serial port, the method further includes: and receiving an address in a storage device appointed by the MCU, judging whether the data stored in the storage device by the MCU is stored in the cache according to whether the received address is the same as the recorded address in the storage device, if so, sending the data in the cache to the storage device, otherwise, receiving the data from the MCU and then sending the data to the storage device.
To solve the above problems, according to still another aspect of the present invention, a data transmission apparatus for a micro control unit is provided.
The data transmission device for the micro control unit comprises a pre-fetching control module, a cache module and an address mapping module, wherein: the prefetch control module is used for reading data from the storage device through a serial port and then storing the data in the cache module; and the address mapping module is used for determining the corresponding address of the address specified by the MCU in the storage device in the cache module according to the corresponding relation between the storage address of the cache module and the storage address of the storage device, and then sending the data in the corresponding address to the MCU through a parallel port.
To solve the above problem, according to still another aspect of the present invention, another data transmission apparatus for a micro control unit is provided.
The data transmission device for the micro control unit comprises a receiving module and a sending module, wherein: the receiving module is used for receiving the data sent by the MCU through the parallel port, then storing the data in a cache and recording an address in a storage device appointed by the MCU; and the sending module is used for determining the address corresponding to the address specified by the MCU in the storage device in the cache according to the corresponding relation between the storage address of the cache and the storage address of the storage device, then sending the data in the corresponding address to the storage device through a serial port and storing the data in the address specified by the MCU in the storage device.
To solve the above problems, according to still another aspect of the present invention, a data transmission system for a micro control unit is provided.
The data transmission system for the micro control unit of the present invention includes a Micro Control Unit (MCU); the data transmission device is connected with the MCU; and the storage device is connected with the data transmission device.
According to the technical scheme of the invention, the serial port of the storage device can be matched with the parallel port of the MCU in speed by caching the data read out from the storage device and carrying out clock domain conversion, so that the efficiency of the MCU for reading the data is improved under the condition that the serial clock frequency is higher than the parallel clock frequency. In addition, in the invention, the data is read from the storage device in advance through the data transmission device and stored in the cache, and the data in the cache is directly sent to the MCU when the MCU needs the data, so that the data does not need to be read from the storage device at the moment, and the efficiency of acquiring the data by the MCU is also improved.
Detailed Description
Embodiments of the present invention will be described below with reference to the accompanying drawings.
Fig. 1 is a schematic diagram of a basic structure of a data transmission system according to an embodiment of the present invention.
As shown in fig. 1, the data transmission system according to the embodiment of the present invention mainly includes a Micro Control Unit (MCU), a data transmission device, and a storage device, which are connected in sequence.
The data transmission method for the MCU according to the embodiment of the present invention is mainly performed by a data transmission apparatus, and its main steps are shown in fig. 2, where fig. 2 is a schematic diagram of the data transmission method for the MCU according to the embodiment of the present invention.
Step S21: data is read from the memory device through the serial port.
Step S22: the read data is converted from serial to parallel.
In step S22, the serial clock frequency is higher than the parallel clock frequency.
Step S23: the parallel data is stored in a cache.
Step S24: and determining the address corresponding to the address specified by the MCU in the storage device in the cache according to the corresponding relation between the storage address of the cache and the storage address of the storage device.
When the MCU reads data from the storage device, the MCU sends an address to be accessed to the data transfer device, that is, the MCU specifies an address in the storage device, where the data is to be read by the MCU.
The storage capacity of the cache is usually smaller than that of the storage device, so the correspondence between the storage addresses of the cache and the storage addresses of the storage device may be dynamic, and the correspondence may be realized by recording from which address of the storage device the data stored in the cache comes.
Step S25: and sending the data in the corresponding address in the step S24 to the MCU through the parallel port.
As can be seen from the above steps S21 to S25, by performing clock domain conversion and buffering on the data in the storage device and making the serial clock frequency higher than the parallel clock frequency, the execution efficiency of the serial circuit can be increased, the serial circuit can be matched with the transmission rate of the parallel port, the bandwidth requirement of the parallel port can be met, and the efficiency of the MCU reading data from the storage device can be increased.
In an implementation, the storage device may be a Flash memory (Flash).
In an implementation, the serial clock of the serial port may be set to be 8N times the parallel clock of the parallel port, where N represents a positive integer.
In this embodiment, in addition to improving the efficiency of the MCU reading the memory device by performing the above-mentioned clock domain conversion and buffering on the data, the efficiency of the MCU reading the memory device is also improved in various ways, which will be described below.
According to the application characteristics of the MCU, the MCU is usually used to execute the program, that is, the MCU reads the program command and then executes the command, then reads the next command and then executes it, and so on. That is, the data read by the MCU is an instruction of a program, which is stored in the storage device. Based on the characteristics of the MCU for reading data, the address of the MCU for accessing the storage device also has certain regularity correspondingly, for example, when the MCU accesses the storage device, the MCU jumps among specific address sections, sequentially reads the data of the address after accessing a section of continuous address, and then jumps to the next address section.
Therefore, the data transmission device can determine the law followed by the MCU when the address is designated according to the address designated by the MCU all the time, thereby predetermining the address in the storage device to be accessed by the MCU, and then reading data in advance from the address in the storage device determined according to the law and storing the data in the cache. The pre-reading here mainly refers to reading of the storage device by the data transmission device before receiving an address to be accessed sent by the MCU.
In this way, in step S21, the data read may be data read in advance according to the above rule. That is, before the MCU specifies an address in the storage device, the data transfer device previously finds an address of the storage device that the MCU may access, reads a part of data from the address, and records the address of the part of data in the storage device, according to the above-described rule.
Therefore, when the data in the cache is to be sent to the MCU, whether the part of data is the data required by the MCU is judged, and if the recorded address of the part of data in the storage device is the same as the address specified by the MCU, the part of data is the data required by the MCU. Under the condition, the data in the cache can be directly sent to the MCU, the data do not need to be read from the storage device, and the data acquisition efficiency of the MCU is improved. And at the same time of transmitting, continuously reading other data required by the MCU from the data storage device.
In the above judgment, if the part of data is not the data required by the MCU, all the data in the designated address of the MCU in the storage device is read from the storage device and the data existing in the buffer is overwritten with the all the data.
In the process of transmitting data from the buffer to the MCU, the MCU is also an instruction to execute the received data while receiving the data. A water level pointer may be set in the cache, and when the MCU accesses the water level pointer, the water level pointer indicates that the instruction stored in the cache is about to be executed, and the data transmission apparatus starts to retrieve data from the storage apparatus again.
As for the MCU, a plurality of functions are usually run in sequence, each function includes a plurality of instructions, so when the MCU obtains data from the storage device, it usually accesses a section of address in sequence and then jumps to another address, and then accesses a section of address in sequence from the address, and when accessing, the MCU executes a section of instruction, which corresponds to a function, and the functions usually have a certain logical relationship of running in sequence. The above-described law that the MCU follows when designating an address is easily grasped by providing a module having a learning function in the data transmission device, thereby reading the storage device in advance. The data read in advance can be program segments commonly used by the MCU, so that the MCU can be directly obtained from the cache of the storage device when the program segments are needed, and the data are not required to be read from the storage device through a serial port, and the data acquisition efficiency of the MCU is improved.
The above description describes a method for the MCU to acquire data from the storage device. In addition, data may be written from the MCU to the storage device using the data storage device.
The specific mode can be that data sent by the MCU is received through a parallel port and then stored in a cache, the read data is converted from parallel to serial during storage, wherein the frequency of a serial clock is higher than that of a parallel clock, and an address in a storage device appointed by the MCU is recorded; and determining the address corresponding to the address specified by the MCU in the storage device in the cache according to the corresponding relation between the storage address of the cache and the storage address of the storage device, and then sending the data in the corresponding address to the storage device through the serial port and storing the data in the address specified by the MCU in the storage device.
When data is continuously written into the storage device, the address in the storage device specified by the MCU may be received first, and whether the data to be stored in the storage device by the MCU is stored in the cache is determined according to whether the received address is the same as the recorded address in the storage device, if so, the data in the cache is sent to the storage device, otherwise, the data is received from the MCU and then sent to the storage device. Thus, the data in the buffer memory is directly saved in the storage device without transmitting the data from the MCU again.
According to the above method of the embodiment of the present invention, a data transmission device can be directly obtained by using an appropriate circuit. For example, a current programmable gate array (FPGA) may be used to build a circuit having various functions of the data transmission device in the above method.
An alternative construction of the data transmission device is described below.
Fig. 3 is a schematic diagram of a structure of a data transmission apparatus according to an embodiment of the present invention.
As shown in fig. 3, in one structure of the data transmission apparatus according to the embodiment of the present invention, the data transmission apparatus 30 mainly includes a prefetch control module 31, a cache module 32, and an address mapping module 33.
The prefetch control module 31 is used to read data from the storage device through the serial port and then store the data in the cache module 32.
The address mapping module 33 is configured to determine, according to a correspondence between a storage address of the cache module 32 and a storage address of the storage device, an address in the cache module 32 corresponding to an address specified by the MCU in the storage device, and then send data in the corresponding address to the MCU through the parallel port.
The data transmission device 30 in fig. 3 is mainly used for the MCU to obtain data from the storage device. The basic structure of the data transmission device mainly used for writing data into the memory device by the MCU in this embodiment will be described below with reference to fig. 4.
Fig. 4 is a schematic diagram of the structure of another data transmission apparatus according to an embodiment of the present invention.
The data transmission device 40 shown in fig. 4 includes a receiving module 41 and a sending module 42, where the receiving module 41 is configured to receive data sent by the MCU through the parallel port and then store the data in the buffer memory, and record an address in the storage device specified by the MCU, and the sending module 42 is configured to determine, according to a correspondence between a storage address of the buffer memory and a storage address of the storage device, an address in the buffer memory corresponding to the address specified by the MCU in the storage device, and then send data in the corresponding address to the storage device through the serial port and store the data in the address specified by the MCU in the storage device.
According to the embodiment of the invention, the data read out from the storage device is cached and subjected to clock domain conversion, so that the rate of the serial port of the storage device is matched with that of the parallel port of the MCU, and the efficiency of the MCU for reading the data is improved under the condition that the serial clock frequency is higher than the parallel clock frequency. In addition, in the invention, the data is read from the storage device in advance through the data transmission device and stored in the cache, and the data in the cache is directly sent to the MCU when the MCU needs the data, so that the data does not need to be read from the storage device at the moment, and the efficiency of acquiring the data by the MCU is also improved.
In the related technical field of televisions, the scheme of the embodiment of the invention can remarkably improve the speed of accessing the storage device, particularly the Flash memory, by the MCU, and especially can accelerate the OSD display speed because the speed of acquiring data by the MCU is effectively improved when some programs such as On-screen display (OSD) and the like which need to read a large amount of data from the Flash memory are processed.
It will be apparent to those skilled in the art that the modules or steps of the present invention described above may be implemented by a general purpose computing device, they may be centralized on a single computing device or distributed across a network of multiple computing devices, and alternatively, they may be implemented by program code executable by a computing device, such that they may be stored in a memory device and executed by a computing device, and in some cases, the steps shown or described may be performed in an order different than that described herein, or they may be separately fabricated into individual integrated circuit modules, or multiple ones of them may be fabricated into a single integrated circuit module. Thus, the present invention is not limited to any specific combination of hardware and software.
The above description is only a preferred embodiment of the present invention and is not intended to limit the present invention, and various modifications and changes may be made by those skilled in the art. Any modification, equivalent replacement, or improvement made within the spirit and principle of the present invention should be included in the protection scope of the present invention.