Summary of the invention
Technical matters to be solved by this invention is to solve the embedded system storer can not realize automatic adaptive scaling problem.
In order to solve the problems of the technologies described above, the technical solution adopted in the present invention provides the automatic adaptation method of a kind of embedded system and memory expansion thereof.
Embedded system provided by the invention, comprise CPU and expansion SDRAM storer, some GPIO pins of described CPU are respectively by being communicated with or disconnection pull-up resistor or the different combinations of states of pull down resistor acquisition, and every kind of corresponding respectively a kind of SDRAM storer that is used for system extension of described combinations of states, described CPU obtains the vendor id of described expansion SDRAM storer according to the current state combination of described some GPIO pins, and the initiation parameter that calls corresponding manufacturer carries out initialization to SDRAM, and described expansion SDRAM storer is a kind of of the described SDRAM storer that is used for system extension.
In said system, described some GPIO pins are by the break-make of toggle switch realization with described pull-up resistor or pull down resistor.
In said system, the described SDRAM storer that is used for system extension is the combination of a SDRAM or a plurality of SDRAM storeies.
In said system, the combination that is combined as a plurality of identical or different SDRAM storeies of described a plurality of SDRAM storeies.
In said system, also comprise some spread F lash storeies, the attribute of the Flash that uses according to system, define the structure array of a plurality of Flash memory attributes that are used to represent that system extension is used, this structure array comprises the vendor id of each Flash storer respectively, amount of capacity, sector-size and system are the start address of this Flash memory allocation, described CPU obtains the vendor id of described some spread F lash storeies and the attribute of Flash storer respectively to the read command word that described start address sends different vendor successively, when the Installed System Memory device is expanded, send and read accordingly, the write order word uses corresponding spread F lash storer.
The automatic adaptation method of embedded system memory expansion provided by the invention may further comprise the steps:
Set up the different conditions combination and the one-to-one relationship that is used for the SDRAM storer of system extension of some GPIO pins;
The different conditions of expanding the SDRAM storer and adjusting some GPIO pins according to described corresponding relation is installed;
CPU reads the vendor id of the described expansion of the combinations of states acquisition SDRAM storer of current some GPIO pins;
The initiation parameter that calls corresponding SDRAM memory vendor carries out initialization to described expansion SDRAM storer.
In said method, the described SDRAM storer that is used for system extension is the combination of one or more SDRAM storeies.
In said method, the combination that is combined as a plurality of identical or different SDRAM storeies of described a plurality of SDRAM storeies.
In said method, if use the Flash memory expansion, then:
The attribute of the Flash that uses according to system at first, the structure array of a plurality of Flash memory attributes that definition is used to represent that system extension is used, this structure array comprise vendor id, amount of capacity, sector-size and the system of each the Flash storer start address for this Flash memory allocation respectively;
CPU is that the read command word that the start address of Flash memory allocation sends different vendor obtains the vendor id of corresponding Flash storer to system successively, and then searches described structure array and obtain spread F lash storer device ID and attribute thereof;
Sending corresponding reading order word according to the vendor id of Flash storer and device id reads and writes described spread F lash storer.
In said method, when using the method extension storage capacity of position expansion, select the SDRAM storer of same size; When using the method extension storage capacity of word expansion, select the combination of SDRAM storer or Flash storer or SDRAM storer and Flash storer.
The present invention, the mode of employing software reads the ID of manufacturer and the device id of storer, in order to distinguish dissimilar storeies, and operate accordingly, thereby make a cover BSP can compatible different manufacturers, dissimilar storer, can be to the hardware compatibility of difference configuration, reduced the work that the bottom personnel safeguard the BSP of difference configuration effectively, increase the extensibility of system, reduced the input of engineering maintenance.
Embodiment
Below in conjunction with accompanying drawing the present invention is made detailed explanation.
Fig. 1 is an Embedded System Structure synoptic diagram provided by the invention, and as shown in Figure 1, embedded system comprises CPU, expansion SDRAM storer and spread F lash storer.
Some GPIO pins of CPU obtain different combinations of states (plug-in mounting resistance or extract resistance) by being communicated with or disconnecting pull-up resistor or pull down resistor respectively, preestablish combinations of states and a kind of one-to-one relationship that is used for the SDRAM storer of system extension of each GPIO pin, the SDRAM storer that is used for system extension is the combination of a SDRAM or a plurality of SDRAM storeies, the combination of a plurality of SDRAM storeies can be the combination of a plurality of identical SDRAM storeies, also can be the combination of a plurality of different SDRAM storeies, different SDRAM storeies refer to the storer of different vendor or the storer of same manufacturer different model.In order to adjust the break-make of GPIO pin and pull-up resistor or pull down resistor easily, can realize by the mode that toggle switch is set.When embedded system is carried out memory expansion, make that by adjusting pull-up resistor or pull down resistor the combinations of states of each GPIO pin of CPU is corresponding with the type of the SDRAM storer that will expand, CPU obtains the vendor id of the expansion SDRAM storer of system according to the current state assembled state of each GPIO pin, and the initiation parameter that calls corresponding manufacturer among boot carries out initialization to SDRAM.Same section setup code can compatible same capability multiple SDRAM.In the embedded development, same is selected the SDRAM that can connect the multi-disc same capability on the CS, constitutes a memory headroom.If adopt a plurality of to select CS to connect, then only need be set to a specific value by the GPIO pin, and should value select the GPIO value when being connected SDRAM not overlapping with single.Before these SDRAM of initialization, what adopt according to the value judgement system of GPIO is that a plurality of choosings connect SDRAM, and still single choosing connects SDRAM, adopts corresponding internal memory initialization function then.
If embedded system also adopts some Flash storeies to expand, then at first be these Flash memory allocated space (comprising start address and memory capacity) all, and for the storage space of these Flash distribution not overlapping.When these Flash are carried out read-write operation, thereby then CPU obtains the vendor id of some Flash storeies and the attribute of Flash storer to system respectively for the read command word that the corresponding start address of these Flash memory allocation sends different vendor successively.The attribute of Flash storer is meant amount of capacity, sector-size and the system of the Flash storer start address for this Flash memory allocation.Behind the vendor id of acquisition spread F lash storer and the attribute of Flash storer, when the Installed System Memory device is expanded, send corresponding reading and writing command word and use corresponding spread F lash storer.
The present invention also provides a kind of automatic adaptation method of embedded system memory expansion, as shown in Figure 2, may further comprise the steps:
The attribute of A10, the Flash that at first uses according to system, the structure array of a plurality of Flash memory attributes that definition is used to represent that system extension is used, this structure array comprise vendor id, amount of capacity, sector-size and the system of each the Flash storer start address for this Flash memory allocation respectively;
A20, the different conditions combination and the one-to-one relationship that is used for the SDARM storer of system extension of setting up some GPIO pins, as previously mentioned, the SDRAM storer that is used for system extension is the combination of a SDRAM or a plurality of SDRAM storeies, the combination of a plurality of SDRAM storeies can be the combination of a plurality of identical SDRAM storeies, also can be the combination of a plurality of different SDRAM storeies, different SDRAM storeies refer to the storer of different vendor or the storer of same manufacturer different model.Different conditions combination with the also corresponding different some GPIO pins of the SDRAM storer of same manufacturer of different memory attribute.
A30, installation are expanded the SDRAM storer and are adjusted the different conditions of some GPIO pins according to described corresponding relation;
The combinations of states that A40, CPU read current some GPIO pins obtains the vendor id of the expansion SDRAM storer that current system installs; And the initiation parameter that calls corresponding SDRAM memory vendor carries out initialization to expansion SDRAM storer.
A60, installation spread F lash storer, CPU is that the read command word that the start address of spread F lash memory allocation sends different vendor obtains the vendor id of corresponding Flash storer to system successively, and then searches device id and attribute thereof that described structure array obtains spread F lash storer;
A70, send corresponding reading order word according to the vendor id of Flash storer and device id described spread F lash storer is read and write.
In the automatic adaptation method of embedded system memory expansion provided by the invention, when using the method extension storage capacity of position expansion, select the SDRAM storer of same size.Position expansion is applicable to generally that word (unit) number of storer does not meet the demands and under the not enough situation of figure place, the figure place of each storage unit is expanded.Number of words is constant by increasing word length comes the expansion capacity for this method, needs to select the chip of model size of the same race, and promptly memory attributes such as the manufacturer of SDRAM storer and amount of capacity, sector-size are identical.
When using the method extension storage capacity of word expansion, select dissimilar storeies, the figure place that the word expansion is used for storage chip meets the demands and the not enough situation of number of words, is the expansion to number of memory cells.Figure place is constant by increasing number of words comes the expansion capacity for this method, promptly can select the SDRAM storer, also can select the Flash storer.In practical engineering application, mainly be the expansion capacity because store number of words.
Below by several typical case's application the present invention is further detailed.
Suppose original a slice SDRAM storer A on the embedded system, the combinations of states value of the GPIO pin that it is corresponding is 1, now it is expanded according to the practical application needs, and below be the detailed introduction of multiple extended mode.
(1), the SDRAM storer B of the SDRAM storer A1 of increase a slice and the same manufacturer of SDRAM storer A or different vendor is as extended memory, as shown in Figure 3.
According to pre-defined, with the combinations of states value of the corresponding GPIO pin of SDRAM storer A1 be 2, with the combinations of states value of the corresponding GPIO pin of SDRAM storer B be 3.
When using SDRAM storer A1 to expand, extended memory SDRAM storer A1 at first is installed on embedded system, adjust toggle switch then, some GPIO pins and corresponding pull-up resistor or pull down resistor are connected, thereby change the combinations of states value of GPIO pin, the combinations of states value that makes current GPIO pin is 2, and A1 is corresponding with extended memory SDRAM storer.When system initialization, CPU reads the state SDRAMType of each GPIO pin, judges the type of SDRAMType, thereby obtains the vendor types SDRAM_A of SDRAM storer A1, call the initialize memory parameter of this manufacturer then and carry out initialization, realized the adaptive automatically of extended memory.
When using SDRAM storer B to expand, on embedded system, install in the extended memory SDRAM storer B, adjust toggle switch, the combinations of states value that changes the GPIO pin is 3, B is corresponding with the SDRAM storer, the execution in step of following CPU is identical with above-mentioned execution in step, repeats no more.
When needs increased the multi-disc SDRAM storer different with SDRAM storer A, its method was similar to preceding method, is the different GPIO combinations of states of combination correspondence of multi-disc SDRAM storer.For example, the combinations of states value of GPIO pin is 4 at this moment.
(2), increase a slice SDRAM storer A1 identical with SDRAM storer A.
When increasing the multi-disc SDRAM storer identical with SDRAM storer A, the combinations of states value of GPIO is all inequality.For example, when increasing by two SDRAM storeies identical with SDRAM storer A, the combinations of states value of GPIO pin is 5; When increasing by three SDRAM storeies identical with SDRAM storer A, the combinations of states value of GPIO pin is 6, or the like.
(3), increase multi-disc Flash storer.
Because the initialization of SDRAM and FLASH and the position of operation are different, SDRAM only needs an initialization, carries out in boot; And Flash just has read-write operation in the process that system carries out.Therefore, when expanding, need to adopt different disposal routes with FLASH.Be that example is illustrated with two Flash storer FlashA and FlashB below, as shown in Figure 4:
(1) definition is used to represent the overall array variable of a plurality of Flash:
typedef?struct?flash_dev_s{
UINT32?base;
int vendorID;
int deviceID;
int sectors;
int lgSectorSize;
}flash_dev_t;
In the above-mentioned Flash structure of arrays, it is the start address that a certain Flash distributes that base is used for tag system; VendorID is used for identifying the vendor id of this Flash device, and deviceID is used for identifying the device id of this Flash device, and sectors is used for identifying this Flash number of sectors, and lgSectorSize identifies the size of this Flash sector.
(2) global variable VerdorID of definition, and initialize is 0, and this variable is used for depositing the vendor types of Flash.
(3) the Flash read command word of transmission vendor A is the start address base that Flash distributes to system, and the Verdor ID of Flash is read in the address of depositing vendor id then from Flash.
Whether consistent, if inconsistent, then jump to step (6) if (4) judge obtaining among Verdor ID and the array VendorA_Flash that represents vendor A member variable vendorID.
(5) send the Flash read command word of vendor A, and the Device ID of Flash is read in the address of storage equipment ID from Flash.If the Device ID that obtains is unlikely with the deviceID among the VendorA_Flash, and also inconsistent with the deviceID among the VendorA1_Flash, program execution in step (6); Otherwise, then jump to step (7).
Flash A1 and Flash A mainly are in order to distinguish the Flash chip of same producer different capabilities, and also there be the inconsistent of sector-size in the dissimilar Flash device of same producer, and when defining overall array, sector-size is an important parameters.Flash B then is meant the Flash of other producers, because the read write command word of different manufacturers is different.In addition, SDRAM is an internal memory, is equivalent to the function of the memory bar of computer the inside, and Flash then plays the part of the role of hard disk.If there is not Flash, increase a slice Flash; Perhaps on the basis that Flash is arranged, adopt new chip selection signal CS to increase a slice Flash, can regard the Flash expansion as.Every increase a slice or compatible a slice Flash, all only need to increase the overall array of this Flash, increase the code of surveying this Flash ID according to overall array in producer's message code of surveying Flash, the command word branch that increases this Flash correspondence when read-write is just passable.
(6) send the Flash read command word of the B of manufacturer, and Verdor ID and the Device ID of Flash are read in the address of storage equipment ID from Flash.If Verdor ID that obtains and Device ID are inconsistent with verdorID and deviceID among the array VendorB_Flash that represents vendor A, then program is carried out and is finished.
(7) Verdor ID and the Device ID that obtains combined, assignment is given global variable VerdorID.
(8) select different overall Flash array VendorA_Flash, VendorA1_Flash and VendorB_Flash according to global variable VerdorID, and send different command words, the Flash device is carried out reading and writing and erase operation according to different arrays.
(9) EO.
The present invention is not limited to above-mentioned preferred forms, and anyone should learn the structural change of making under enlightenment of the present invention, and every have identical or close technical scheme with the present invention, all falls within protection scope of the present invention.