Summary of the invention
Technical matters to be solved by this invention is to solve the embedded system storer can not realize the automatic adaptation scaling problem.
In order to solve the problems of the technologies described above, the technical solution adopted in the present invention is to provide 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 respectively corresponding a kind of SDRAM storer 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, described expansion SDRAM storer is a kind of of described SDRAM storer for system extension.
In said system, described some GPIO pins are realized break-make with described pull-up resistor or pull down resistor by toggle switch.
In said system, described SDRAM storer 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 a plurality of structure arrays for representing the Flash memory attribute that system extension is used, this structure array comprises respectively the vendor id of each Flash storer, amount of capacity, sector-size and system are the start address that this Flash storer distributes, described CPU obtains respectively the vendor id of described some spread F lash storeies and the attribute of Flash storer 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 comprises the following steps:
Set up the different conditions combination of some GPIO pins and the one-to-one relationship of the SDRAM storer that is used for system extension;
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, described SDRAM storer 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:
At first the attribute of the Flash that uses according to system, definition is for the structure array that represents a plurality of Flash memory attributes that system extension is used, and this structure array comprises respectively vendor id, amount of capacity, sector-size and the system of each Flash storer and is the start address of this Flash storer distribution;
CPU is that the start address that the Flash storer distributes sends the vendor id of the corresponding Flash storer of read command word acquisition of different vendor to system successively, and then searches described structure array acquisition spread F lash storer device ID and attribute thereof;
According to vendor id and the corresponding reading order word of device id transmission of Flash storer, described spread F lash storer is read and write.
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, adopt the ID of manufacturer and the device id of the mode read memory of software, in order to distinguish dissimilar storer, and operate accordingly, thereby make a cover BSP can compatible different manufacturers, dissimilar storer, can be to the hardware compatibility of difference configuration, effectively reduced the work that the bottom personnel safeguard the BSP of difference configuration, 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 Embedded System Structure schematic 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, preset the combinations of states of each GPIO pin and a kind of one-to-one relationship of the SDRAM storer for system extension, 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, it can be also 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 easily the break-make of GPIO pin and pull-up resistor or pull down resistor, can realize by the mode that toggle switch is set.When embedded system is carried out memory expansion, make the combinations of states of each GPIO pin of CPU corresponding with the type of the SDRAM storer that will expand by adjusting pull-up resistor or pull down resistor, 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 embedded development, same is selected the SDRAM that can connect the multi-disc same capability on CS, consists of a memory headroom.If adopt a plurality of to select CS to connect, only need to be set to a specific value by the GPIO pin, and the GPIO value that should be worth when being connected SDRAM with single choosing is not overlapping.Before these SDRAM of initialization, what adopt according to the value judgement system of GPIO is that a plurality of choosings connect SDRAM, or single choosing connects SDRAM, then adopts corresponding internal memory initialization function.
If embedded system also adopts some Flash storeies to expand, at first be these Flash memory allocated spaces (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 the CPU corresponding start address of distributing for these Flash storeies to the system successively read command word that sends different vendor obtains respectively the vendor id of some Flash storeies and the attribute of Flash storer.The attribute of Flash storer refers to the start address that amount of capacity, sector-size and the system of Flash storer distribute for this Flash storer.After 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, comprises the following steps:
The attribute of A10, the Flash that at first uses according to system, definition is for the structure array that represents a plurality of Flash memory attributes that system extension is used, and this structure array comprises respectively vendor id, amount of capacity, sector-size and the system of each Flash storer and is the start address of this Flash storer distribution;
A20, set up the different conditions combination of some GPIO pins and the one-to-one relationship of the SDARM storer that is used for system extension, 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, can be also 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.The also different conditions combination of corresponding different some GPIO pins of SDRAM storer with 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 start address that spread F lash storer distributes sends the vendor id of the corresponding Flash storer of read command word acquisition of different vendor to system successively, and then searches device id and the 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.Word (unit) number that position expansion generally is applicable to storer does not meet the demands and in the inadequate 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 the method, needs to select the chip of model size of the same race, and namely the 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 storer, the figure place that the word expansion is used for storage chip meets the demands and the inadequate 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 the method, namely can select the SDRAM storer, also can select the Flash storer.In practical engineering application, be mainly the expansion capacity because store number of words.
Use below by several typical cases the present invention is further detailed.
Suppose original a slice SDRAM storer A on embedded system, the combinations of states value of the GPIO pin that it is corresponding is 1, now according to the practical application needs, it is expanded, and be below the detailed introduction of multiple extended mode.
(1), increase the SDRAM storer B of the SDRAM storer A1 of a slice and SDRAM storer A same manufacturer or different vendor as extended memory, as shown in Figure 3.
According to pre-defined, the combinations of states value of the GPIO pin corresponding with SDRAM storer A1 is 2, and the combinations of states value of the GPIO pin corresponding with SDRAM storer B is 3.
When using SDRAM storer A1 to expand, at first extended memory SDRAM storer A1 is installed on embedded system, then adjust toggle switch, 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, the type of judgement SDRAMType, thereby the vendor types SDRAM_A of acquisition SDRAM storer A1, then call the initialize memory parameter of this manufacturer and carry out initialization, realized the automatic adaptation of extended memory.
When using SDRAM storer B to expand, when extended memory SDRAM storer B is installed on embedded system, 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 from 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 not identical.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, etc.
(3), increase multi-disc Flash storer.
Because the position of the initialization of SDRAM and FLASH and operation is 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 with FLASH, need to adopt different disposal routes.The below is illustrated as an example of two Flash storer FlashA and FlashB example, as shown in Figure 4:
(1) definition is used for representing 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 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 then depositing vendor id from Flash.
Whether (4) judgement obtains in Verdor ID and the array VendorA_Flash that represents vendor A member variable vendorID consistent, if inconsistent, jumps to step (6).
(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 in VendorA_Flash, and also inconsistent with the deviceID in VendorA1_Flash, program execution in step (6); Otherwise, jump to step (7).
Flash A1 and Flash A are mainly 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 in the time of the overall array of definition, sector-size is an important parameter.Flash B refers to the Flash of other producers, because the read write command word of different manufacturers is different.In addition, SDRAM is internal memory, is equivalent to the function of the memory bar of computer the inside, and Flash plays the part of the role of hard disk.If there is no Flash, increase a slice Flash; Perhaps adopt new chip selection signal CS to increase a slice Flash on the basis that Flash is arranged, 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 surveying producer's message code of Flash, increase command word branch corresponding to this Flash just passable when read-write.
(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 the Verdor ID that obtains and Device ID are inconsistent with verdorID and deviceID in the array VendorB_Flash that represents vendor A, program is carried out and is finished.
(7) Verdor ID and the Device ID that obtains combined, assignment is to 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 according to different arrays, the Flash device is carried out reading and writing and erase operation.
(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, within all falling into protection scope of the present invention.