A TIMER timer correction method, system and PSAM card
By starting the timer only once when the system starts, and setting the time slot interval of the timer in subsequent time slots to the second time interval when the first and second time slot intervals are modified, the problem of starting the TIMER timer is solved. And the problem that the execution time of the stop function is difficult to accurately measure is achieved to achieve the accuracy of timing sampling and system stability.
Patent Information
- Application Number
- CN202210486499.6
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2022-05-06
- Publication Date
- 2024-10-29
- Estimated Expiration
- 2042-05-06
Smart Images

Figure CN114816706B_ABST
Abstract
Description
Technical Field
[0001] The invention relates to the technical field of TIMER timers, and in particular to a TIMER timer correction method, system and PSAM card. Background Art
[0002] During system operation, it is often necessary to use the TIMER timer for timing and execute preset actions at the corresponding time points. For example, a timer with a time interval of T is started, and a signal is collected every T period. Generally speaking, given the start time, if the CPU runs fast enough, the time required to start the TIMER timer can be ignored, that is, the time to execute start_timer will not affect the execution of subsequent sampling actions. However, since the MCU main frequency of the system cannot reach the ideal speed during actual operation, calling the start_timer function itself takes up a lot of time from the time the signal is received to start the TIMER, which makes it easy for subsequent sampling actions to be executed at the wrong time slot, which in turn causes operation errors.
[0003] The existing solution is to call stop_timer and start_timer in each time slot when using TIMER, and deduct the execution time of these two functions when calling start_timer to ensure the normal operation of the system. However, this solution needs to ensure that the execution time of stop_timer and start_timer in each time slot can be accurately obtained, but the actual situation is that there is no way to accurately measure these two times. If the time of stop_timer and start_timer functions in each time slot has a deviation of 1, after accumulating n time slots, this deviation is n*1. Unless fewer interruption points are required, the accumulated deviation will still cause the interrupt action to be executed in the wrong time slot.
[0004] Therefore, a TIMER timer correction method is currently needed to avoid the technical problem of interrupt actions being executed in the wrong time slot due to the accumulation of deviations during system operation without changing the hardware basis, and to meet the needs of timed execution of actions in scenarios with high requirements for time accuracy. Summary of the invention
[0005] In order to solve the technical problem that the accumulation of deviations during system operation causes the interrupt action to be executed in the wrong time slot, the present invention provides a TIMER timer correction method, system and PSAM card, and the specific technical solution is as follows:
[0006] The present invention provides a TIMER timer correction method, comprising the steps of:
[0007] When the system is started, the timer is run, and according to the start time of the timer and the interruption period preset in each time slot, the time slot interval of the timer in the first time slot is set to a first time interval, so that the timer performs an interruption in the interruption period in the first time slot according to the first time interval;
[0008] After the first time slot, the time slot intervals of the timer in each subsequent time slot are modified to be the second time interval, so that the timer in each subsequent time slot is interrupted within the interruption period in the current time slot.
[0009] The TIMER timer correction method provided by the present invention starts the timer only once when the system is started, and executes the modification action of the timer time slot interval twice, so as to realize the correction based on the existing TIMER hardware solution by software, so that each time slot meets the timing interruption requirement and avoids interruption in the wrong time slot.
[0010] In some embodiments, the timer is implemented based on the ARM architecture;
[0011] The method of modifying the timer so that the time slot intervals in each subsequent time slot are all before the second time interval after the first time slot has passed, further includes:
[0012] A timer is run when the system starts, and according to the start time of the timer and the interruption period preset in each time slot, the time slot intervals of the timer in the first time slot and the second time slot are set to a third time interval, so that the timer executes an interruption in the interruption period in the first time slot and the interruption period in the second time slot respectively according to the third time interval.
[0013] The TIMER timer correction method provided by the present invention optimizes the solution for the timer in the ARM architecture. When the timer time slot interval is set for the first time, it is considered that when the time slot interval of the timer in the ARM architecture is modified after the first time slot ends, it must wait until the third time slot to officially take effect. Therefore, the interruption period in the first time slot and the second time slot is comprehensively considered, and the third time interval is set to improve the accuracy of the interrupt execution action in each time slot.
[0014] In some embodiments, an interruption moment is preset in each time slot;
[0015] The method of modifying the time slot intervals of the timer in each subsequent time slot to be a second time interval after the first time slot has passed, so that the timer in each subsequent time slot is interrupted within the interruption period in the current time slot, specifically includes:
[0016] After the first time slot, the time slot intervals of the timer in each subsequent time slot are modified to be the second time interval, so that the timer in each subsequent time slot executes an interrupt at the interrupt time in the current time slot.
[0017] The TIMER timer correction method provided by the present invention determines the second time interval of the timer according to the interruption time, so that in the third time slot and subsequent time slots, the timer can execute the interruption at a more accurate interruption time, further improving the accuracy of the execution of the interruption action.
[0018] In some implementations, the interruption period is set according to the interruption time and a duty cycle of the timer.
[0019] In some implementations, the time difference between the interruption moments in any two adjacent time slots is the same;
[0020] The modifying of the timer so that the time slot intervals in each subsequent time slot are all the second time interval specifically includes:
[0021] The time slot intervals of the timer in subsequent time slots are modified to be the time difference.
[0022] In some implementations, modifying the timer so that the time slot intervals in each subsequent time slot are all the second time interval specifically includes:
[0023] By modifying the Auto-reload register in the timer, the time slot intervals in subsequent time slots of the timer are modified to be the second time interval.
[0024] In some implementations, each time the timer is interrupted, data sampling is performed at the current moment.
[0025] The TIMER timer correction method provided by the present invention is suitable for occasions where sampling is required, and the accuracy of timing sampling is improved by executing an interrupt action by the timer.
[0026] In some embodiments, the present invention further provides a TIMER timer correction system, comprising:
[0027] A setting module, configured to run a timer when the system is started, and to set a time slot interval of the timer in a first time slot to a first time interval according to a start time of the timer and an interruption period preset in each time slot, so that the timer performs an interruption in the interruption period in the first time slot according to the first time interval;
[0028] The modification module is used to modify the time slot interval of the timer in each subsequent time slot to be a second time interval after the first time slot, so that the timer in each subsequent time slot executes an interrupt within the interrupt period in the current time slot.
[0029] In some embodiments, the present invention also provides a PSAM card, including a processor, a memory, and a computer program stored in the memory and executable on the processor, wherein the processor is configured to execute the computer program stored in the memory to implement the operations performed by the above-mentioned TIMER timer correction method.
[0030] In some implementations, the present invention further provides a handheld POS terminal, including the above-mentioned PSAM card, or a terminal that implements the above-mentioned TIMER timer correction method.
[0031] The TIMER timer correction method, system and PSAM card provided by the present invention have at least one of the following technical effects:
[0032] (1) By starting the timer only once when the system starts, and performing the modification action of the timer time slot interval twice, the existing TIMER hardware solution is implemented through software modification, so that each time slot meets the timing interruption requirements and avoids interruption in the wrong time slot;
[0033] (2) Optimize the solution for the timer in the ARM architecture. When setting the time slot interval of the timer for the first time, consider that when the time slot interval of the timer in the ARM architecture is modified after the first time slot ends, it will not take effect until the third time slot. Therefore, the interruption period in the first time slot and the second time slot is comprehensively considered, and the third time interval is set to improve the accuracy of the interruption execution action in each time slot;
[0034] (3) determining the second time interval of the timer according to the interruption time, so that in the third time slot and each subsequent time slot, the timer can execute the interruption at a more precise interruption time, further improving the accuracy of the execution of the interruption action;
[0035] (4) Applicable to situations where sampling is required, the accuracy of timed sampling can be improved by executing interrupt actions through the timer. BRIEF DESCRIPTION OF THE DRAWINGS
[0036] In order to more clearly illustrate the technical solutions in the embodiments of the present invention, the drawings required for use in the description of the embodiments will be briefly introduced below. Obviously, the drawings described below are only some embodiments of the present invention. For ordinary technicians in this field, other drawings can be obtained based on these drawings without paying creative labor.
[0037] Figure 1A flowchart of a TIMER timer correction method of the present invention;
[0038] Figure 2 Another flow chart of a TIMER timer correction method of the present invention;
[0039] Figure 3 An exemplary diagram of a TIMER timer correction system of the present invention;
[0040] Figure 4 This is an example diagram of a PSAM card of the present invention.
[0041] Reference numerals in the figure: setting module-10, modification module-20, processor-100, memory-200 and computer program-210. DETAILED DESCRIPTION
[0042] In the following description, specific details such as specific system structures, technologies, etc. are provided for the purpose of illustration rather than limitation, so as to provide a thorough understanding of the embodiments of the present application. However, it should be clear to those skilled in the art that the present application may also be implemented in other embodiments without these specific details. In other cases, detailed descriptions of well-known systems, devices, circuits, and methods are omitted to prevent unnecessary details from obstructing the description of the present application.
[0043] It should be understood that when used in this specification and the appended claims, the term "comprising" indicates the presence of the described features, integers, steps, operations, elements and / or components, but does not exclude the presence or addition of one or more other features, integers, steps, operations, elements, components and / or collections.
[0044] In order to simplify the drawings, only the parts related to the present invention are schematically shown in each figure, and they do not represent the actual structure of the product. In addition, in order to simplify the drawings and facilitate understanding, in some figures, only one of the parts with the same structure or function is schematically drawn or marked. In this article, "one" not only means "only one", but also means "more than one".
[0045] It should be further understood that the term “and / or” used in the specification and appended claims refers to any combination and all possible combinations of one or more of the associated listed items, and includes these combinations.
[0046] In addition, in the description of the present application, the terms "first", "second", etc. are only used to distinguish the description and cannot be understood as indicating or implying relative importance.
[0047] In order to more clearly illustrate the embodiments of the present invention or the technical solutions in the prior art, the specific implementation methods of the present invention will be described below with reference to the accompanying drawings. Obviously, the accompanying drawings described below are only some embodiments of the present invention. For ordinary technicians in this field, other drawings and other implementation methods can be obtained based on these drawings without creative work.
[0048] One embodiment of the present invention, as Figure 1 As shown, the present invention provides a TIMER timer correction method, comprising the steps of:
[0049] S100 runs a timer at system startup.
[0050] Specifically, the timer start_timer is started only once at the beginning of the system operation startup.
[0051] S210 sets the time slot interval of the timer in the first time slot as a first time interval according to the start time of the timer and the interruption period preset in each time slot, so that the timer performs an interruption in the interruption period in the first time slot according to the first time interval.
[0052] Specifically, the initial interval T of the first time slot needs to deduct the time T1 when the timer start_timer starts, that is, T-T1, and add the first time interval X on the basis of T-T1, that is, T-T1+X, and execute the interrupt at T-T1+X. The specific setting of the first time interval X needs to be determined according to the preset interrupt period in each time slot and the start time of the timer.
[0053] For example, assuming that the initial time is t 0 = 0, the sampling center point occurs at a time interval that is an integer multiple of T = 100, that is, 100n (n> = 1), and the allowed deviation is assumed to be +-50. The time interval of the first time slot interruption is set to T-T1+X, and the time when the first interrupt comes is t 0 +T1+T-T1+X=T+X=100+X must fall between 50 and 150, and considering that the interruption time is modified to T after the first time slot interruption, it will actually take effect in the next (third) time slot, and the interruption time of the second time slot is still T-T1+X like the first time slot, so the interruption occurrence time of the second time slot T+X+T-T1+X=2T+2X-T1=2T+2X-T1 needs to fall between 150 and 250, and starting from the third time slot, the interval of each time slot is T, so the interruption occurrence time of the third and subsequent time slots is 2T+2X-T1+(n-2)T, which needs to fall within Tn+-50 (n>=3).
[0054] S300, after the first time slot, modifies the time slot intervals of the timer in each subsequent time slot to be the second time interval, so that the timer in each subsequent time slot is interrupted within the interruption period of the current time slot.
[0055] Specifically, after the first time slot, the time interval of the next time slot interruption is modified to return to normal, so that adjustments are made in the first two controllable time slots so that all time slots can meet the sampling time requirements.
[0056] The TIMER timer correction method provided in this embodiment starts the timer only once when the system starts, and executes the modification action of the timer time slot interval twice, so as to realize the correction based on the existing TIMER hardware solution by software, so that each time slot meets the timing interruption requirement and avoids interruption in the wrong time slot.
[0057] In one embodiment, Figure 2 As shown, when the timer is implemented based on the ARM architecture, after step S100 and before step S300, the following steps are further included:
[0058] S220 sets the time slot intervals of the timer in the first time slot and the second time slot to be the third time interval according to the start time of the timer and the preset interruption period in each time slot, so that the timer executes an interruption in the interruption period in the first time slot and the interruption period in the second time slot according to the third time interval.
[0059] Specifically, when implementing this solution based on the ARM hardware timer, modifying the timer's time slot interval will not take effect until the third time slot, so the actual effect is that the first two time slots are interrupted by the third time interval, and all time slots after the third are interrupted by the second time interval.
[0060] The TIMER timer correction method provided in this embodiment optimizes the solution for the timer in the ARM architecture. When the timer time slot interval is set for the first time, it is considered that when the time slot interval of the timer in the ARM architecture is modified after the end of the first time slot, it must wait until the third time slot to officially take effect. Therefore, the interruption period in the first time slot and the second time slot is comprehensively considered, and the third time interval is set to improve the accuracy of the interrupt execution action in each time slot.
[0061] In one embodiment, after the interruption time is preset in each time slot, step S300 may also include: after the first time slot, modifying the time slot interval of the timer in each subsequent time slot to be a second time interval, so that the timer in each subsequent time slot executes an interruption at the interruption time in the current time slot.
[0062] Specifically, the relationship between the interruption period and the interruption time is that the interruption period is set according to the interruption time and the duty cycle of the timer. For example, if the interruption time of the first time slot is set to 100 and the duty cycle is 0.5, the interruption period is 50-150.
[0063] Furthermore, when the time difference between the interruption moments in any two adjacent time slots is the same, the time slot interval of the timer can be modified to the time difference so that the timer is interrupted at the interruption moment in the current time slot in each subsequent time slot.
[0064] During the execution of step S300, the time slot intervals of the timer in each subsequent time slot may be modified to be the second time interval by modifying the Auto-reload register or related registers in the timer.
[0065] In one embodiment, after the timer is interrupted each time, data sampling is performed at the current moment, which is suitable for occasions where sampling is required. The accuracy of timing sampling is improved by executing the interrupt action by the timer.
[0066] In one embodiment, for the timer in the ARM architecture, assuming that the initial time is t 0 =0, the sampling center point occurs at an integer multiple of the time interval T=100, that is, 100n (n>=1), the allowed deviation is assumed to be +-50, the timer start time needs to be 60, and the first interrupt time is set to 70. Then the first time slot interruption time is 0+60+70=130, and the sampling action is performed after the interruption. The interruption time is still a safe distance from the boundary of the interruption period of 100+-50, and the sampling is acceptable.
[0067] After the first time slot ends, the interruption time interval is modified from 70 to 100. Since this modification will not take effect until the next time slot, the second time slot interruption is actually still executed according to 70, that is, the second time slot interruption at 130+70=200 is exactly located at the center point of the second time slot range 200+-50. All subsequent time slot time intervals are no longer modified, so they are all 100, and they will all fall on the sampling center point. In this embodiment, as long as the sampling of the first two time slots is fine-tuned to fall within the safe range, and the second sampling interruption falls at the center point as much as possible, all subsequent sampling points will fall at the sampling center point, even if the time interval of the first two sampling points actually has some deviations within the acceptable range, such deviations are consistent from the third sampling point onwards and no cumulative error will occur.
[0068] In one embodiment, Figure 3 As shown, the present invention also provides a TIMER timer correction system, including a setting module 10 and a modification module 20.
[0069] The setting module 10 is used to run the timer when the system starts, and set the time slot interval of the timer in the first time slot to the first time interval according to the start time of the timer and the preset interruption period in each time slot, so that the timer executes an interrupt within the interruption period in the first time slot according to the first time interval. The modification module 20 is used to modify the time slot interval of the timer in each subsequent time slot to the second time interval after the first time slot, so that the timer executes an interrupt within the interruption period in the current time slot in each subsequent time slot.
[0070] Specifically, at the beginning of the system operation, only one timer start_timer is started. The initial interval T of the first time slot needs to deduct the time T1 of the timer start itself, and an additional time X is introduced, so that the first time slot interruption time T1+T-T1+X=T+X is within the (first) safe sampling range, and the second time slot interruption T+X+T-T1+X=2T+2X-T1 also occurs within the (second) safe sampling range. The third and subsequent time slot interruptions 2T+2X-T1+(n-2)T all occur within the (nth) safe sampling range.
[0071] The TIMER timer correction system provided in this embodiment starts the timer only once when the system starts, and executes the modification action of the timer time slot interval twice, thereby realizing correction based on the existing TIMER hardware solution through software, so that each time slot meets the timing interruption requirement and avoids interruption in the wrong time slot.
[0072] In one embodiment, Figure 4 As shown, the present invention also provides a PSAM card, including a processor 100, a memory 200, and a computer program 210 stored in the memory 200 and executable on the processor 100, the processor 100 is used to execute the computer program 210 stored in the memory 200, and implement the operations performed in the above-mentioned TIMER timer correction method embodiment.
[0073] The PSAM card structure provided in this embodiment is not limited to being composed of a processor and a memory, but may also be composed of other functional devices and integrated into the PSAM card.
[0074] The PSAM card protected by this solution is only an example. Any device or memory that integrates the terminal security control module PSAM, as long as it serves as the execution medium of the above-mentioned TIMER timer correction method embodiment, belongs to the protection scope of this application.
[0075] In one embodiment, this embodiment also provides a handheld POS machine, including the above-mentioned PSAM card, or a terminal that implements the above-mentioned TIMER timer correction method embodiment. The handheld POS machine controls the PSAM terminal security control module to perform data sampling at regular intervals based on the above-mentioned TIMER timer correction method, thereby achieving the security and stability of the POS machine.
[0076] In the above embodiments, the description of each embodiment has its own emphasis. For parts that are not described or recorded in detail in a certain embodiment, reference can be made to the relevant descriptions of other embodiments.
[0077] Those of ordinary skill in the art will appreciate that the units and steps of each example described in conjunction with the embodiments disclosed herein can be implemented with electronic hardware, or a combination of computer software and electronic hardware. Whether these functions are performed with hardware or software depends on the specific application and design constraints of the technical solution. Professional and technical personnel can use different methods to implement the described functions for each specific application, but such implementation should not be considered to be beyond the scope of this application.
[0078] In the embodiment provided by the present application, it should be understood that a kind of TIMER timer correction method, system and PSAM card disclosed can be realized by other ways.For example, a kind of TIMER timer correction method, system and PSAM card embodiment described above are only schematic, for example, the division of described modules or units is only a kind of logical function division, and other division modes can be arranged during actual implementation, for example, a plurality of units or modules can be combined or can be integrated into another system, or some features can be ignored, or do not execute.Another point, the communication connection between shown or discussed can be through some interfaces, the communication connection or integrated circuit of device or unit, can be electrical, mechanical or other forms.
[0079] The units described as separate components may or may not be physically separated, and the components shown as units may or may not be physical units, that is, they may be located in one place or distributed on multiple network units. Some or all of the units may be selected according to actual needs to achieve the purpose of the solution of this embodiment.
[0080] In addition, each functional unit in each embodiment of the present application may be integrated into one processing unit, or each unit may exist physically separately, or two or more units may be integrated into one unit. The above integrated unit may be implemented in the form of hardware or in the form of software functional units.
[0081] It should be noted that the above is only a preferred embodiment of the present invention. It should be pointed out that for ordinary technicians in this technical field, several improvements and modifications can be made without departing from the principle of the present invention. These improvements and modifications should also be regarded as the scope of protection of the present invention.
Claims
1. A TIMER timer correction method, characterized in that: Includes steps: Run the timer at system startup; According to the start time of the timer and the interruption period preset in each time slot, setting the time slot interval of the timer in the first time slot to a first time interval, so that the timer performs an interruption in the interruption period in the first time slot according to the first time interval; Wherein, the start time of the timer is the time required to start the timer; After the first time slot, modifying the time slot intervals of the timer in each subsequent time slot to be a second time interval, so that the timer in each subsequent time slot is interrupted within the interruption period in the current time slot, includes: After the first time slot, modify the time slot intervals of the timer in each subsequent time slot to be the second time interval, so that the timer in each subsequent time slot is interrupted at the interruption time in the current time slot; The time interval is used to obtain the interruption time interval by subtracting the start time of the timer from the time slot interval and then accumulating the time interval.
2. A TIMER timer correction method according to claim 1, characterized in that: The timer is implemented based on ARM architecture; After the timer is run at system startup, after the first time slot has passed, before the time slot intervals of the timer in each subsequent time slot are modified to be the second time interval, further comprising: According to the start time of the timer and the preset interruption period in each time slot, the time slot intervals of the timer in the first time slot and the second time slot are set to a third time interval, so that the timer executes an interruption in the interruption period in the first time slot and the interruption period in the second time slot respectively according to the third time interval.
3. A TIMER timer correction method according to claim 1, characterized in that: The interruption period is set according to the interruption time and the duty cycle of the timer.
4. A TIMER timer correction method according to claim 1, characterized in that: The time difference between the interruption moments in any two adjacent time slots is the same; The modifying of the timer so that the time slot intervals in each subsequent time slot are all the second time interval specifically includes: The time slot intervals of the timer in subsequent time slots are modified to be the time difference.
5. A TIMER timer correction method according to any one of claims 1 and 4, characterized in that: The modifying of the timer so that the time slot intervals in each subsequent time slot are all the second time interval specifically includes: By modifying the Auto-reload register in the timer, the time slot intervals in subsequent time slots of the timer are modified to be the second time interval.
6. A TIMER timer correction method according to any one of claims 1 to 4, characterized in that: After the timer is interrupted each time, data sampling is performed at the current moment.
7. A TIMER timer correction system, characterized in that: include: A setting module, configured to run the timer when the system is started, and to set the time slot interval of the timer in the first time slot to a first time interval according to the start time of the timer and the interruption period preset in each time slot, so that the timer performs an interruption in the interruption period in the first time slot according to the first time interval; wherein the start time of the timer is the time required to start the timer; A modification module, used for modifying the time slot intervals of the timer in each subsequent time slot to be a second time interval after the first time slot, so that the timer in each subsequent time slot is interrupted within the interruption period in the current time slot, including: After the first time slot, modify the time slot intervals of the timer in each subsequent time slot to be the second time interval, so that the timer in each subsequent time slot is interrupted at the interruption time in the current time slot; The time interval is used to obtain the interruption time interval by subtracting the start time of the timer from the time slot interval and then accumulating the time interval.
8. A PSAM card device, characterized in that: The invention comprises a processor, a memory and a computer program stored in the memory and executable on the processor, wherein the processor is used to execute the computer program stored in the memory to implement the operation performed by the TIMER timer correction method as claimed in any one of claims 1 to 6.
9. A handheld POS device, characterized in that: A PSAM card device comprising the PSAM card device of claim 8, or a terminal implementing the TIMER timer correction method of any one of claims 1 to 6.
Citation Information
Patent Citations
Embedded system timer realizing method
CN103034480A
Data processing system
US20150046742A1
