Embodiment one
The information storage means of the electronic tag that the embodiment of the present invention one provides, after arranging state of activation byte, electronic tag realizes the flow process of information storage as shown in Figure 2, performs step as follows:
Step S11: electronic tag receives and uses request.
Electronic tag, when not using, is in dormant state, and the use request of wait-receiving mode outside.
Such as: use request can from the composite read-write device of expressway entrance and exit and road side base station etc. on the way.
Step S12: electronic tag searches the sector being in state of activation in each sector of its storage space after receiving and using request.
After receiving use request, electronic tag starts to search which sector in its storage space is in state of activation, general by traveling through the sector of searching in the state of activation byte of setting and comprising and activating mark, realize searching the sector being in state of activation in each sector of storage space.
Such as: when the activation arranged is designated 0xfe, then finding in state of activation byte is that sector of 0xfe, is the sector being in state of activation.
Such as: the specific implementation flow process that traversal is searched as shown in Figure 3, performs step as follows:
Step S120: start.
Step S121: read sector S
istate of activation byte.
From i=0 when generally searching, namely first sector starts to read.
Step S122: judge that this sector is in state of activation?
Activate mark if comprise in the state of activation byte of this sector, then this sector is in state of activation, otherwise is not.
If so, perform step S123, otherwise perform step S124.
Step S123: determine this sector S
ifor being in the sector of state of activation.
Step S124: make i=i++, and judge whether i is more than or equal to sector total quantity N.If so, then step S125 is performed; If not, then return continuation and perform step S121.
Step S125: determine the sector not being in state of activation.
Step S13: according to the Query Result whether inquiring the sector being in state of activation, determines and currently uses sector.Specifically comprise:
(1) sector activating mark is comprised if found in above-mentioned steps S12, and this sector is not when being last sector of storage space, activation mark in this sector is rewritten as and is used to complete mark, and the next sector of this sector is used sector as current.
(2) sector activating mark is comprised if found in above-mentioned steps S12, and this sector is when being last sector of storage space, activation mark in this sector is rewritten as and is used to complete mark, and first of storage space sector is used sector as current.
(3), when comprising the sector activating mark if do not find in above-mentioned steps S12, first of storage space sector is used sector as current.
Continue to use the example of top, if find sector S
istate of activation byte in comprise state of activation mark 0xfe time, then illustrate this sector be last time use sector, by this sector activation mark 0xfe be rewritten as be used to complete mark 0xfc.And determine sector S
(i+1) %Nsector is used as current.Wherein, (i+1) %N represents the remainder of (i+1)/N, thus can be implemented in the sector S comprising state of activation mark 0xfe found
ifor sector S
n-1time, the current sector that uses determined is for sector S
0.
If when finding in state of activation byte the sector comprising and activate mark 0xfe, the current sector that uses determined is for sector S
0.Be now the situation of storage space when being in unused state, all sectors are all original, therefore do not need to rewrite state of activation byte.
Step S14: activate and currently use sector.
Determine current use sector after, wipe the current information being used to complete mark and storing used in sector, to use in the state of activation byte of sector write to activate mark current, currently use sector to activate.
Continue to use the example of top, currently use sector S by what determine
(i+1) %Nor S
0erasing, and write activates mark 0xfe in its state of activation byte.Namely currently sector S is used
(i+1) %Nor S
0be activated.
Step S15: continue to receive the information from outside.
Ask and after performing above-mentioned steps, electronic tag then can keep dormant state and the information of wait-receiving mode outside, the instruction that the information from outside that may receive comprises write request and is used to complete receiving to use.
When receiving write request, perform step S16; When receiving the instruction be used to complete, perform step S17; Otherwise continuation dormancy.
Step S16: write as initial write point the information to be stored received using the current sector that uses, and return step S15 continuation wait-receiving mode information.
After electronic tag receives information to be stored, although information generally to be stored can not more than the size of a sector.But consider and may occur this special circumstances of the size of information to be stored more than the size of the available memory area of a sector.Preferably, need to carry out the need of the judgement across sector storage according to the actual conditions of information to be stored.Different situations for court verdict can be divided into following two kinds of modes to write:
If the size of the storage area needed for i information that () is to be stored is not more than the size of the available memory area of a sector, then directly information to be stored is written to determine current uses in sector.
Continue to use above-mentioned example, the information to be stored received is written to be activated current and uses that sector is current uses sector S
(i+1) %Nor S
0.
(ii) if the size of the storage area needed for information to be stored is greater than the size of the available memory area of a sector, the size of the storage area then needed for information to be stored, is written to information to be stored and uses in the available memory area of at least two continuous print sectors sector from current.
Continue to use above-mentioned example, the information to be stored received is written to from what be activated and currently uses sector S
(i+1) %Nor S
0in at least two the continuous print sectors started.
In (ii) kind situation, in order to use the storage space of sector more fully, it is also conceivable in several sectors of using continuously, the first character joint of other sector except first sector and second byte, also for storage, now then need to do an escape process.Namely, when using first character joint, for not using with above-mentioned setting, the information data if desired write identifies or activates that the identification information such as to identify identical just.When second bytes store information, the information data if desired write for being set using irrecoverable mark maybe can recovering identify identical with above-mentioned, then can adopt two characters replacements of setting just.Such as: when written information data 0xfe, 0xff and 0,x01 two characters are used to replace; When written information data 0xff, 0xff and 0,x00 two characters are used to replace.Other situation then carries out normal write operation.
Step S17: terminate this Stored Procedure.
When electronic tag receives the instruction be used to complete, then terminate this use, electronic tag enters dormant state.
Preferably, for the ease of after judge whether to need the information recovered in sector in abnormal cases, when receiving the instruction be used to complete, writing irrecoverable mark current use in the byte that returns to form of sector, representing that this sector has been used to complete without the need to recovering information again.That is, when not writing this irrecoverable mark, being the recovered Identification obtained behind erasing sector in the byte that returns to form, representing and need recovery information.
Continuing to use above-mentioned example, when being used to complete, writing irrecoverable mark 0xfe current use in the byte that returns to form of sector, before for this mark of write, for recovering mark 0xff in the byte that returns to form.
Embodiment two
The information storage means of the electronic tag that the embodiment of the present invention two provides, after arranging state of activation byte, electronic tag realizes the flow process of information storage as shown in Figure 4, performs step as follows:
Step S21: electronic tag receives and uses request.
With step S11, repeat no more herein.
Step S22: electronic tag searches the sector being in state of activation in each sector of its storage space after receiving and using request.
With step S12, repeat no more herein.
Step S23: according to the Query Result whether inquiring the sector being in state of activation, determines and currently uses sector.Specifically comprise:
(1) sector activating mark is comprised if found in above-mentioned steps S22, and this sector is not when being last sector of storage space, the information of wiping the activation mark in this sector and storing, and the next sector of this sector is used sector as current.
(2) sector activating mark is comprised if found in above-mentioned steps S22, and this sector is when being last sector of storage space, the information of wiping the activation mark in this sector and storing, and first of storage space sector is used sector as current.
(3), when comprising the sector activating mark if do not find in above-mentioned steps S22, first of storage space sector is used sector as current.
Continue to use the example of top, if find sector S
istate of activation byte in comprise state of activation mark 0xfe time, then illustrate this sector be last time use sector, wipe this sector S
iin activation mark and the information that stores, and determine sector S
(i+1) %Nsector is used as current.Wherein, (i+1) %N represents the remainder of (i+1)/N, thus can be implemented in the sector S comprising state of activation mark 0xfe found
ifor sector S
n-1time, the current sector that uses determined is for sector S
0.
If when finding in state of activation byte the sector comprising and activate mark 0xfe, the current sector that uses determined is for sector S
0.Now, be the situation of storage space when being in unused state, all sectors are all original, therefore do not need erasing.
Step S24: activate and currently use sector.
Determine current use sector after, to use in the state of activation byte of sector write to activate mark current, currently use sector to activate.
Continue to use the example of top, currently use sector S what determine
(i+1) %Nor S
0state of activation byte in write activate mark 0xfe.Namely currently sector S is used
(i+1) %Nor S
0be activated.
Step S25: continue to receive the information from outside.
Ask and after performing above-mentioned steps, electronic tag then can keep dormant state and the information of wait-receiving mode outside, the instruction that the information from outside that may receive may comprise write request and be used to complete receiving to use.
When receiving write request, perform step S26; When receiving the instruction be used to complete, perform step S27; Otherwise continuation dormancy.
Step S26: write as initial write point the information to be stored received using the current sector that uses, and return step S25 continuation wait-receiving mode information.
The detailed process that information stores, with step S16, repeats no more herein.
Step S27: terminate this Stored Procedure.Electronic tag enters dormant state.
With step S17, repeat no more herein.
The electronic labeling information of above-described embodiment one stores realization flow, before each write, wipe the sector that will use, and the sector repeating query realizing storage space uses, and ensures that each sector used only is wiped free of once.The electronic labeling information of above-described embodiment two stores realization flow, just used sector was wiped once before each write, when writing then without the need to clashing, the sector repeating query that can realize storage space equally uses again, and ensures that each sector used only is wiped free of once.
After above-mentioned setting returns to form byte, when there is abnormal restarting, such as: when accident power-off, equipment failure etc. cause the situation of abnormal restarting to occur, can recover to be in state of activation and information in the sector used.Its flow process as shown in Figure 5, performs step as follows:
Step S31: electronic tag powers on and restarts.
Such as: electronic tag restarts because of the abnormal conditions such as fault or power-off.
Step S32: find the sector being in state of activation in each sector of its storage space.
The process of searching with step S12, can repeat no more herein.
Step S33: check the byte that returns to form be in the sector of state of activation found.
Check the byte that returns to form be in the sector of state of activation, whether to comprise irrecoverable mark according in the byte that returns to form arranged, determine whether to need to recover the information that this is in the sector of state of activation.
Wherein, above-mentioned irrecoverable be identified at the instruction receiving and be used to complete after write current the returning to form in byte of sector of using.If fruit to be in the sector of state of activation not this irrecoverable mark, then when specification exception starts, this sector just in use, needs to recover.
Such as: the sector being in state of activation found, namely comprising the sector activating mark in state of activation byte is S
i, then sector S is checked
ithe byte that returns to form.
Step S34: comprise irrecoverable mark in the byte that returns to form? if not, step S36 is performed; If so, step S35 is performed.
Continue to use the example of top, if sector S
ithe byte packet that returns to form containing irrecoverable mark 0xfe, then execution step S35, if sector S
ithe byte that returns to form do not comprise irrecoverable mark 0xfe, but comprise can recover identify 0xff, then perform step S36.
Step S35: electronic tag enters dormant state.
Without the need to sector S
iinternal storage information recover.
Step S36: what recovery found is in the information stored in the sector of state of activation.
To sector S
iinternal storage information recover according to message structure.
Step S37: electronic tag enters normal Stored Procedure.
After storage Information recovering completes, this electronic tag being in state of activation enters normal Stored Procedure, uses until complete this.
As long as ensure that in fact it is available by erase operation for not using mark and can recovering mark, and irrecoverable mark and activate mark be can by write mode available, be used to complete mark be can by rewriting mode available.Concrete mark is arranged can be selected flexibly.
According to the information storage means of the above-mentioned electronic tag that the embodiment of the present invention one provides, a kind of information-storing device of electronic tag can be built, its structure as shown in Figure 6, comprising: receiver module 10, enquiry module 20, determination module 30, writing module 40 and execution module 50.
Receiver module 10, for receiving the instruction using request, write request and be used to complete.
Enquiry module 20, for receive use request when receiver module 10 after, searches the sector being in state of activation in each sector of its storage space.
Above-mentioned enquiry module 20, specifically for: after receiver module 10 receives and uses request, by searching the sector comprising in the state of activation byte that arranges in storage space and activate mark, realize looking into the sector being in state of activation in each sector of storage space.
Determination module 30, for whether inquiring the Query Result of the sector being in state of activation according to enquiry module 20, determines and currently use sector, and the sector that change is in state of activation is that determine current uses sector.
Preferably, above-mentioned determination module 30, can comprise further: the first determining unit 301 and first activates unit 302.
First determining unit 301, for find in the state of activation byte that arranges in storage space the sector that comprises and activate mark when enquiry module 20 and this sector is not last sector of storage space time, activation mark in this sector is rewritten as and is used to complete mark, and the next sector of this sector is used sector as current; When enquiry module 20 finds that to comprise the sector activating mark be last sector of storage space, the activation mark in this sector is rewritten as and is used to complete mark, and first of storage space sector is used sector as current; When enquiry module 20 does not find the sector comprising and activate mark, first of storage space sector is used sector as current.
First activates unit 302, for wiping the current information being used to complete mark and storing used in sector that the first determining unit 301 is determined, uses write in the state of activation byte of sector to activate mark current.
Writing module 40, for when receiver module 10 receives write request, writes as initial write point the information to be stored received using the current sector that uses that determination module 30 is determined.
Preferably, above-mentioned writing module 40, can comprise further: judging unit 401 and writing unit 402.
Judging unit 401, for when receiver module 10 receives write request, judges whether the size of the storage area needed for information to be stored is greater than the size of the available memory area of a sector.
Writing unit 402, if the size being not more than the available memory area of a sector for the size of the storage area needed for information to be stored, is then directly written to determine current and uses in sector by information to be stored; If the size of the storage area needed for information to be stored is greater than the size of the available memory area of a sector, the size of the storage area then needed for information to be stored, is written to information to be stored and uses in the available memory area of at least two continuous print sectors sector from current.
Execution module 50, for after receiver module 10 receives the instruction be used to complete, terminates this Stored Procedure.
Preferably, the information-storing device of above-mentioned electronic tag, also comprises: recover module 60.
Above-mentioned execution module 50, also for after receiver module 10 receives the instruction be used to complete, writes irrecoverable mark current use in the byte that returns to form of sector.
Recover module 60, after electronic tag abnormal restarting, find the sector being in state of activation in each sector of its storage space, be in the byte that returns to form arranged in the sector of state of activation whether comprise irrecoverable mark according to this, determine whether to need to recover the information that this is in the sector of state of activation.
According to the information storage means of the above-mentioned electronic tag that the embodiment of the present invention two provides, a kind of information-storing device of electronic tag can be built, its structure as shown in Figure 7, comprising: receiver module 11, enquiry module 21, determination module 31, writing module 41 and execution module 51.
Wherein, receiver module 11, enquiry module 21, writing module 41 and execution module 51 respectively with the receiver module 10 of the information-storing device of the electronic tag shown in above-mentioned Fig. 6, enquiry module 20, writing module 40 and execution module 50.The judging unit 411 comprised in writing module 41 and writing unit 412 are identical with writing unit 402 with the judging unit 401 comprised in writing module 40.
The difference of the device shown in this device and Fig. 6 is: its determination module 31, for whether inquiring the Query Result of the sector being in state of activation according to enquiry module 20, determine and currently use sector, and the sector that change is in state of activation is that determine current uses sector.
Preferably, above-mentioned determination module 31, can comprise further: the first determining unit 311 and first activates unit 312.
Second determining unit 311, for find in the state of activation byte that arranges in storage space the sector that comprises and activate mark when enquiry module 21 and this sector is not last sector of storage space time, the information of wiping the activation mark in this sector and storing, and the next sector of this sector is used sector as current; When enquiry module 21 finds that to comprise the sector activating mark be last sector of storage space, the information of wiping the activation mark in this sector and storing, and uses sector using first of storage space sector as current; When enquiry module 21 does not find the sector comprising and activate mark, first of storage space sector is used sector as current.
Second activates unit 312, writes activation mark for current the use in the state of activation byte of sector determined in the second determining unit 311.
The information storage means of the above-mentioned electronic tag that the embodiment of the present invention provides and device, by when using certain sector, be set to state of activation, search by identifying in state of activation byte to comprise to activate to identify the sector being in state of activation when using next time, and determine that its next sector is current spendable sector, thus the rotation successively realizing sector uses, and improves the resources of chip utilization factor of electronic tag, extends the serviceable life of electronic tag internal storage space.
The electronic tag applied in the path identifying system of intelligent transportation field, in the sheet of its CPU, the storage space such as the outer EEPROM of Flash or sheet is generally used for the store electrons label routing information of process and expressway entrance and exit information on the way.Need the quantity of information stored usually to only have tens bytes, be generally not more than the memory capacity of a minimum sector.And the storage space of electronic tag can provide the space of multiple sector to store for data, the application on electronic labeling information stores of sector rotation mechanism is made to possess precondition.
As can be seen from the flow process that above-mentioned whole information stores, after sector new each time uses request to occur, the sector of use all can automatic alternate, recycles available sector.No matter be that above-described embodiment one wiped the sector that will use before each write, the once just used sector in erasing before each write of above-described embodiment two, when next time writes then without the need to carrying out the mode clashed again, it is once for once erase operation that each sector often uses.For the transition process of embodiment one from state of activation to completion status be by state of activation byte activation mark 0xfe be directly rewritten into be used to complete mark 0xfc; The process becoming unrecoverable state from returning to form to is that the mark the recovered 0xff returned to form byte is directly rewritten into irrecoverable mark 0xfe.
The characteristic of Flash storage space determines write operation and can only realize being write as 0 by 1 of some or several binary digit, and erase operation reverts to 1 by 0 of all binary digits.And above-mentioned state of activation byte and the mark setting returned to form in byte are arranged based on this rule just, never use mark 0xff be rewritten into activate mark 0xfe, from activation mark 0xfe be directly rewritten into be used to complete mark 0xfc and from can recover mark 0xff be directly rewritten into irrecoverable mark 0xfe, be all write as from 10 operation; And from from activation mark 0xfe revert to do not use mark 0xff, from be used to complete mark 0xfc revert to do not use mark 0xff and from can not recover mark 0xfe revert to can recover identify 0xff, be all by erasable from 0 recover 1 operation.Therefore, the setting of state of activation byte and the byte that returns to form does not need additionally to wipe storage space, at utmost reduce the erasing frequency of storage space, ensure that each sector used only is wiped free of once, improve the access times of storage space to greatest extent.Avoid same position at storage space by repeatedly erasable problem, thus improve serviceable life.
Said method activates mark by using the write meeting erasable characteristic in state of activation byte and is used to complete mark, does not use mark, controls the rotation use of sector; And pass through to meet the mark recovered of erasable characteristic and irrecoverable mark equally, realize Information recovering and control.By having taken into full account the erasable characteristic of storage space, ensure that each byte of current use sector only can by once erasable in the process completing primary information storage use.Simultaneously, by arranging the byte that returns to form, when there are abnormal conditions, the system that can also ensure is meeting accident power-off or after restarting, power on restart after correctly can recover power-off before be in the information stored in the sector used of state of activation, improve stability and the reliability of system to a great extent.
The above; be only the present invention's preferably embodiment; but protection scope of the present invention is not limited thereto; anyly be familiar with those skilled in the art in the technical scope that the present invention discloses; the change that can expect easily, replace or be applied to other similar devices, all should be encompassed within protection scope of the present invention.Therefore, protection scope of the present invention should be as the criterion with the protection domain of claims.