A method and system for implementing device runtime recording
By connecting the EEPROM to the CPU via the I2C bus, and combining the VxWorks system and time recording logic program, the problem of RTC chip occupying I/O interfaces and space is solved, achieving accurate time recording and data security, and avoiding high-frequency interference and data loss.
Patent Information
- Application Number
- CN202310236560.6
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2023-03-08
- Publication Date
- 2026-08-25
- Estimated Expiration
- 2043-03-08
AI Technical Summary
Products that require timing functions on embedded platforms need to be equipped with an RTC chip, which occupies the processor's I/O interface and space. At the same time, the RTC's battery may cause high-frequency interference.
The device records operating time by connecting the EEPROM to the CPU via the I2C bus and using the VxWorks system and time recording logic program. This includes BIOS initialization, VxWorks system startup, software driver initialization, time recording logic program initialization, and auxiliary clock activation. The device records time data using a uniform cyclic writing method.
It achieves accurate time recording, avoids RTC occupying IO interface and space, reduces high-frequency interference, and only causes an error of 1 second in the event of abnormal power failure, without data loss.
Smart Images

Figure CN116361129B_ABST
Abstract
Description
Technical Field
[0001] This invention relates to the field of real-time embedded software technology, and in particular discloses a method and system for recording device runtime via EEPROM under VxWorks. Background Technology
[0002] VxWorks is a real-time operating system developed by Wind River Systems, Inc. It is widely used in high-precision technology fields with extremely high real-time requirements due to its good reliability and excellent real-time performance. It is powerful and complex, and is often used in embedded platforms. EEPROM (Electrically Erasable Programmable Read-Only Memory) is a type of memory chip that retains data even after power loss, and typically uses I / O... 2 The C bus is connected to the CPU. An EEPROM can be frequently and repeatedly programmed when the computer is in use. Therefore, the lifespan of the EEPROM is a very important design consideration.
[0003] In most current small embedded platforms, there are increasingly higher requirements for embedded products, such as small size, low power consumption, and anti-interference. Currently, products with timing functions on embedded platforms need to be equipped with an RTC chip to obtain accurate time values. However, the RTC (Real-Time Clock) chip occupies part of the processor's I / O interface, and the RTC battery also takes up some space. In use, it may also cause high-frequency interference to other circuits in the system.
[0004] Therefore, products with timing requirements on embedded platforms need to be equipped with an RTC chip to obtain accurate time values. However, the RTC occupies part of the processor's I / O interface, and the RTC battery also occupies part of the volume space. In use, it may also cause high-frequency interference to other circuits in the system, which is a technical problem that urgently needs to be solved. Summary of the Invention
[0005] This invention provides a method and system for recording device running time, aiming to solve the technical problem that products with timing requirements on embedded platforms need to be equipped with an RTC chip to obtain accurate time values. However, the RTC occupies part of the processor's I / O interface, and the RTC battery also occupies part of the volume space. In use, there may also be high-frequency interference coupled to other circuits in the system.
[0006] One aspect of the present invention relates to a method for recording device runtime, applied in a runtime recording device, the runtime recording device including a CPU hardware platform and an EEPROM storage chip, the EEPROM storage chip via I... 2The C bus connects to the CPU hardware platform. The VxWorks system runs on the CPU hardware platform, and the time recording logic program runs on the VxWorks system. The time recording logic program communicates with the CPU via I / O. 2 The C protocol reads and writes data to the EEPROM storage chip, and the method of recording device running time by writing or reading time data cyclically through the EEPROM includes the following steps: BIOS initialization: Initializes the CPU platform hardware and peripherals, enabling the runtime recording device to complete basic power-on configuration; VxWorks system startup: After BIOS initialization is complete, the system boots and then enters the VxWorks system; Software driver initialization: Initialize the software driver under the VxWorks system and complete the basic configuration and initialization functions under the system; Initialize the time recording logic program: Initialize the time recording logic program, prepare for timing, and complete the initialization of function parameter variables. Maximum time value readback: According to the application layer design, the time recording logic program reads the maximum time value stored in the EEPROM storage chip. This maximum time value is the cumulative running time when the power was cut off last time, and is used as the timing reference value after the current startup. Auxiliary clock enabled: Powers on the auxiliary clock, invokes the system clock for timing, and configures the interrupt trigger time and interrupt handling function content; Time recording logic program execution: Enable the time recording function to allow the time recording logic program to run in a loop.
[0007] Furthermore, the steps for reading back the maximum time value include: Read the time base value after the program is powered on and running; Configure an auxiliary clock to generate timing operations; once configured, data processing can be performed within the interrupt handler. Once the time writing function is complete, the subsequent program execution polls the configured auxiliary clock logic.
[0008] Furthermore, the steps for reading the time base value after the program is powered on and running include: Read the first time data; Assign the first time data read to the current maximum time value; Determine if the read time data is the last data; If it is not the last data point, then read the next time data. Determine if the next time data read is the current maximum value; If the next time data read is the current maximum value, then the current maximum time value will be assigned to it.
[0009] Furthermore, configuring an auxiliary clock to generate timing operations, and then performing data processing within the interrupt after configuration, includes the following steps: Output the maximum time value and the storage address where the maximum time value is located; Disable auxiliary clock interrupts; Configure auxiliary clock frequency; Obtain the auxiliary clock frequency; Connect the auxiliary clock interrupt service routine; Enable auxiliary clock interrupt.
[0010] Furthermore, after completing the time writing function, the subsequent steps of the program's operation, which polls the configured auxiliary clock logic, include: Enable the auxiliary clock and configure the clock interrupt to one second; Enter the interrupt handler function; If the maximum time value plus one second is detected, the storage location is shifted backward by four bytes. Determine if the address has reached the last digit; If the address has not reached the last digit, then the time value is written to the specified storage location.
[0011] Another aspect of the present invention relates to a system for recording device runtime, applied in a runtime recording device. The runtime recording device includes a CPU hardware platform and an EEPROM storage chip. The EEPROM storage chip is connected to the CPU hardware platform via an I2C bus. A VxWorks system runs on the CPU hardware platform, and a time recording logic program runs on the VxWorks system. The time recording logic program reads and writes data to the EEPROM storage chip via the I2C protocol, writing or reading time data cyclically and evenly through the EEPROM. The system for recording device runtime includes: The BIOS initialization module is used for BIOS initialization: initializing the hardware and peripherals of the CPU platform, enabling the runtime recording device to complete basic power-on configuration; The system boot module is used to boot into the VxWorks system after BIOS initialization is complete; The software initialization module is used for software driver initialization: it performs software driver initialization operations under the VxWorks system and completes the basic configuration and initialization functions under the system. The program initialization module is used to initialize the time recording logic program: it initializes the time recording logic program, prepares for timing, and completes the assignment of variable initialization values for function parameters. The time value readback module is used to read back the maximum time value: According to the application layer design, the time recording logic program reads the maximum time value stored in the EEPROM storage chip. This maximum time value is the cumulative running time when the power was cut off last time, and is used as the timing reference value after this startup. The auxiliary clock enable module is used to enable the auxiliary clock: power on the auxiliary clock, call the system clock to keep time, and configure the interrupt trigger time and interrupt handling function content; The time recording module is used to run the time recording logic program: enabling the time recording function allows the time recording logic program to run in a loop.
[0012] Furthermore, the readback time value module includes: The readout unit is used to read the time base value after the program is powered on and running; The configuration unit is used to configure the auxiliary clock and generate timing operations. After the configuration is completed, data processing can be performed inside the interrupt. The write unit is used to complete the time writing function. The subsequent operation of the program polls the configured auxiliary clock logic.
[0013] Furthermore, the readout unit includes: The first readout subunit is used to read the first time data. The first assignment sub-unit is used to assign the first read time data to the current maximum time value; The first judgment subunit is used to determine whether the read time data is the last data; The second readout subunit is used to read the next time data if it is not the last data. The second judgment subunit is used to determine whether the next time data read is the current maximum value; The second assignment sub-unit is used to assign the current maximum time value if the next time data read is the current maximum value.
[0014] Furthermore, the configuration unit includes: The output sub-unit is used to output the maximum time value and the storage address where the maximum time value is located. The disable subunit is used to disable auxiliary clock interrupts. Configuration subunit, used to configure the auxiliary clock frequency; The acquisition sub-unit is used to acquire the auxiliary clock frequency; The connection subunit is used to connect to the auxiliary clock interrupt service routine; The enable subunit is used to enable the auxiliary clock interrupt.
[0015] Furthermore, the write unit includes: Enable sub-unit to enable the auxiliary clock and configure the clock interrupt to one second; Entering the sub-unit is used to enter the interrupt handling function; The control subunit is used to control the storage location to be offset backward by four bytes if the maximum time value plus one second is detected. The judgment sub-unit is used to determine whether the address has reached the last bit; Write subcell, used to write the time value at the specified storage location if the address has not reached the last bit.
[0016] The beneficial effects achieved by this invention are as follows: This invention provides a method and system for recording device runtime. The method includes: BIOS initialization: initializing the CPU platform hardware and peripherals to complete basic power-on configuration of the runtime recording device; VxWorks system startup: after BIOS initialization, the device boots into the VxWorks system; software driver initialization: initializing the software driver under the VxWorks system and completing basic system configuration and initialization functions; time recording logic program initialization: initializing the time recording logic program to prepare for timing and assigning initial values to function parameters; reading back the maximum time value: according to the application layer design, the time recording logic program reads the maximum time value stored in the EEPROM memory chip, which is the accumulated runtime at the time of the last power failure and used as the timing reference value after the current startup; auxiliary clock activation: powering on the auxiliary clock, calling the system clock for timing, configuring the interrupt trigger time and interrupt handling function content; and time recording logic program execution: enabling the time recording function and allowing the time recording logic program to run cyclically. The method and system for recording device running time provided by this invention have a simple overall hardware platform structure, high reliability, and low cost; at the software level, the logical structure is simple and clear, and the portability is strong; in terms of functionality, the timing accuracy is high, the usable time is long, and in the event of abnormal power failure, it will only cause an error of up to 1 second, without causing data corruption or loss. Attached Figure Description
[0017] Figure 1 A flowchart illustrating an embodiment of the method for recording device running time provided by the present invention; Figure 2 A schematic diagram of the hardware structure of an embodiment of the runtime recording device provided by the present invention; Figure 3 A schematic diagram of the software module structure of an embodiment of the runtime recording device provided by the present invention; Figure 4 A schematic diagram of software data storage processing of an embodiment of the runtime recording device provided by the present invention; Figure 5 for Figure 1 A detailed flowchart of the first embodiment of the step of reading back the maximum time value is shown; Figure 6 for Figure 5 A detailed flowchart illustrating an embodiment of the step of reading the time reference value after the program is powered on and running. Figure 7 for Figure 5 The diagram shows a detailed flowchart of an embodiment of the steps for configuring an auxiliary clock to generate timing operations, and then performing data processing within the interrupt after the configuration is complete. Figure 8 for Figure 5 The flowchart shown is a detailed representation of an embodiment of the completion time writing function and the subsequent steps of the program to poll on the configured auxiliary clock logic. Figure 9 for Figure 1 A detailed flowchart of the second embodiment of the step of reading back the maximum time value is shown; Figure 10 This is a functional block diagram of an embodiment of a system for recording device running time provided by the present invention; Figure 11 for Figure 10 A schematic diagram of the functional modules of an embodiment of the program initialization module shown in the figure; Figure 12 for Figure 11 A schematic diagram of the functional modules of one embodiment of the readout unit shown; Figure 13 for Figure 11 A schematic diagram of the functional modules of one embodiment of the configuration unit shown in the figure; Figure 14 for Figure 11 The diagram shows a functional module schematic of one embodiment of the writing unit.
[0018] Explanation of icon numbers: 10. BIOS Initialization Module; 20. System Startup Module; 30. Software Initialization Module; 40. Program Initialization Module; 50. Time Value Recall Module; 60. Auxiliary Clock Enable Module; 70. Program Execution Recording Module; 51. Read Unit; 52. Configuration Unit; 53. Write Unit; 511. First Read Subunit; 512. First Assignment Subunit; 513. First Judgment Subunit; 514. Second Read Subunit; 515. Second Judgment Subunit; 516. Second Assignment Subunit; 521. Output Subunit; 522. Disable Subunit; 523. Configuration Subunit; 524. Get Subunit; 525. Connect Subunit; 526. Enable Subunit; 531. Open Subunit; 532. Enter Subunit; 533. Control Subunit; 534. Judgment Subunit; 535. Write Subunit. Detailed Implementation
[0019] To better understand the above technical solutions, the following will provide a detailed explanation of the technical solutions in conjunction with the accompanying drawings and specific implementation methods.
[0020] like Figures 1 to 4 As shown, the first embodiment of the present invention proposes a method for recording device runtime, applied in a runtime recording device. The runtime recording device includes a CPU hardware platform and an EEPROM storage chip. The EEPROM storage chip uses I... 2 The C bus connects to the CPU hardware platform. The VxWorks system runs on the CPU hardware platform, and the time recording logic program runs on the VxWorks system. The time recording logic program communicates with the CPU via I / O. 2 The C protocol reads and writes data to the EEPROM storage chip, writing or reading time data cyclically and evenly through the EEPROM. The time recording logic program uses I... 2 The EEPROM chip connected to the C bus records, reads, saves, and retrieves platform runtime data.
[0021] The hardware platform on which the software in this embodiment relies needs to have a Flash chip. The structure shown in the diagram here uses an I... 2 The EEPROM storage chip uses the C protocol for communication and is used to store time data. Software requirements include the ability to run an operating system or a bare program, and it must have I... 2 The diagram shows a C communication driver and a clock timer function. The system used here is VxWorks, which has a fast system response speed, strong development and portability, and high accuracy of its auxiliary clock, which can meet timing requirements.
[0022] like Figure 2 As shown, the system architecture of the software module includes a device driver layer, a VxWorks driver layer, and a VxWorks application layer.
[0023] The device driver layer is based on hardware circuitry. It meets the design requirements of the chip during the design phase and connects to the corresponding interface of the CPU in hardware to ensure the normal operation of the chip. Only when the device driver layer is designed correctly can the CPU recognize the device, ensuring that the device can be operated normally during software programming and achieve its intended functions.
[0024] The VxWorks driver layer primarily handles the initialization and function calls for both CPU internal resources and peripheral resources, ensuring that the underlying hardware can be controlled by the upper-layer software. It provides corresponding function interfaces to the upper-layer software to enable various functions that peripherals can perform. In this application, after completing the basic CPU initialization, the driver layer calls the CPU's I2C interface according to software requirements to perform data read and write operations on the EEPROM peripheral. The driver program controls the read / write timing according to the I2C protocol, reading and writing data from the specified register address in the EEPROM to ensure accurate data transmission. The driver layer's software design is contained within the corresponding CPU's BSP (Board Support Package), and its standard interfaces can be directly called from the application layer.
[0025] The VxWorks application layer is primarily designed based on the software interface of the driver layer, adding necessary logic programs to ensure the device operates normally as designed. The software in this invention is developed based on the application layer; it handles the software logic of the time recording program, calling the auxiliary clock and I / O pins under the driver. 2 It incorporates C drivers, timers, and other resources, and adds logic program control to enable operations such as reading, storing, retrieving, and processing time data.
[0026] The overall calling hierarchy is as follows: the VxWorks application layer calls the VxWorks driver layer API interface through the time recording logic program, and then performs read and write operations on the underlying EEPROM through the I2C protocol driver to complete the overall logic control function.
[0027] The equipment runtime recording software primarily handles the programming of the VxWorks application layer and the VxWorks driver interface layer. 2 Both the C driver and the underlying EEPROM hardware driver are standard operation interfaces that can be directly called. The VxWorks driver interface layer primarily handles I... 2The C driver encapsulates the upper-level interface for easy access by upper-level software, and its main interface functions are data reading and writing. The VxWorks application layer's time recording logic program mainly completes the initialization of the time recording software program, reads back the time value after power-on, controls the auxiliary clock, and performs time recording and reading / writing operations.
[0028] From the moment the device platform is powered on until the software is running normally, the main process is as follows: Figure 3 As shown in the figure, the BIOS initialization, VxWorks system startup, and software driver initialization are the normal software boot programs after the device starts, which are the basic conditions for the normal use of the device. The method for recording device runtime provided in this embodiment includes the following steps: Step S100: BIOS initialization: Initialize the hardware and peripherals of the CPU platform, and enable the runtime recording device to complete the basic power-on configuration.
[0029] After the device platform is powered on, it first performs BIOS initialization, which is mainly used to initialize the hardware and peripherals of the CPU platform to complete the basic power-on configuration.
[0030] Step S200, VxWorks system startup: After BIOS initialization is completed, the system will boot into the VxWorks system.
[0031] After the BIOS initialization is complete, the system will boot into the VxWorks system.
[0032] Step S300: Software driver initialization: Initialize the software driver in the VxWorks system and complete the basic configuration and initialization functions of the system.
[0033] The software driver was initialized under the VxWorks system, and the basic configuration and initialization functions of the system were completed.
[0034] Step S400: Initialize the time recording logic program: Initialize the time recording logic program, prepare for timing, and complete the initialization of function parameter variables.
[0035] After completing the basic initialization, the logic within the function is executed according to the location of the main function. First, the time recording software is initialized to prepare for timing, completing operations such as assigning initial values to some function parameters and variables.
[0036] Step S500: Read back the maximum time value: According to the application layer design, the time recording logic program reads the maximum time value stored in the EEPROM storage chip. This maximum time value is the cumulative running time when the power was cut off last time, and is used as the timing reference value after this startup.
[0037] Based on the application layer design, the maximum time value stored in the EEPROM is read. This value is the cumulative running time when the power was cut off last time, and it is used as the timing reference value after this startup.
[0038] Step S600, Auxiliary clock enabled: Power on the auxiliary clock, call the system clock to keep track of time, and configure the interrupt trigger time and interrupt handling function.
[0039] Power on the auxiliary clock, call the system clock to keep track of time, configure the interrupt trigger time and interrupt handling function, etc.
[0040] Step S700: Time recording logic program execution: Enable the time recording function and let the time recording logic program run in a loop.
[0041] Enable the time recording function to allow the time recording logic program to run in a loop.
[0042] This embodiment provides a method for recording device runtime, utilizing the existing system clock to record runtime through software, thus fully leveraging platform hardware resources and software scheduling. Using an auxiliary clock and EEPROM chip under VxWorks, accurate time recording and storage can be achieved, and the EEPROM data is not lost after a power outage. However, EEPROM read / write operations have a limited lifespan. If the program continuously accesses single bytes of the EEPROM, it will fail after its lifespan expires and will no longer be able to record values. The program cannot recognize or judge this and cannot automatically switch to the next byte area. Furthermore, in practical applications, there is a high possibility of abnormal power outages. If time data is being written during such an event, it will corrupt the data, resulting in the loss of accumulated runtime data. In the current embedded platform environment, to meet increasingly diverse functional requirements, the uniform cyclic writing method for recording time values is very suitable for such application scenarios. It achieves accurate time recording and storage while avoiding the impact of data corruption caused by abnormal power outages. The method for recording device runtime provided in this embodiment ensures the correct assignment of various baseline values after system startup through this initialization process. The time recording logic program is started only after the baseline values are configured, thus writing data from the recording position onwards without overwriting previous data, guaranteeing the overall accuracy and security of the data. The auxiliary clock, serving as the clock count source for the software, must be enabled only after all initialization work is completed; otherwise, counting chaos and writing failures will occur. The time recording logic program runs cyclically, promptly writing updated data to the storage space.
[0043] Further, please see Figure 5 , Figure 5 for Figure 1 The diagram shows a detailed flow chart of one embodiment of step S500. In this embodiment, step S500 includes: Step S510: Read the time base value after the program is powered on and running.
[0044] Reading the time base value is the first step after the program is powered on and running.
[0045] Step S520: Configure the auxiliary clock to generate timing operations. After the configuration is completed, data processing can be performed inside the interrupt.
[0046] Configure an auxiliary clock to generate timing operations. Once configured, data processing can be performed within the interrupt handler.
[0047] Step S530: Complete the time writing function. The subsequent operation of the program will poll the configured auxiliary clock logic.
[0048] The time value is written into the EEPROM using the "WriteTmrToEEProm" function.
[0049] The method for recording device running time provided in this embodiment completes the time writing function, and subsequent program execution polls based on this logic. Following the flowchart, the software program can complete data searching, comparison, and judgment in the simplest and fastest way, saving time. Furthermore, the interrupt handling after the auxiliary clock interrupt is generated runs automatically, without consuming excessive CPU resources, ensuring processing speed.
[0050] Further, see Figure 6 , Figure 6 for Figure 5 The diagram shows a detailed flow chart of an embodiment of step S510. In this embodiment, step S510 includes: Step S511: Read the first time data.
[0051] The "ReadTmrFromEEProm" function is used to read time data from the EEPROM, and the first time data is read.
[0052] Step S512: Assign the first read time data to the current maximum time value.
[0053] Read the time data stored in the EEPROM. If the read time data is the first time data, then assign the read first time data to the current maximum time value.
[0054] Step S513: Determine whether the read time data is the last data.
[0055] Determine whether the time data read from the EEPROM is the last data.
[0056] Step S514: If it is not the last data, then read the next time data.
[0057] If the time data stored in the EEPROM is not the last data, then the next time data is read.
[0058] Step S515: Determine whether the next time data read is the current maximum value.
[0059] Determine whether the next time data stored in the read EEPROM is the current maximum value.
[0060] Step S516: If the next time data read is the current maximum value, then assign it to the current maximum time value.
[0061] If the next time data stored in the read EEPROM is determined to be the current maximum value, then the next time data stored in the EEPROM will be assigned the current maximum time value.
[0062] The method for recording device running time provided in this embodiment requires the running time recording device to determine the total running time value by reading back the time data stored in the EEPROM after each power outage and restart. By reading back and comparing all the data in the storage area, the largest time value is found and used as the total running time value. This value is then used as the time base value for the current running time of the device. The storage location of this maximum value is recorded so that after updating the latest value, the device can continuously record by shifting backward from this storage location.
[0063] Preferably, see Figure 7 , Figure 7 for Figure 5 The diagram shows a detailed flow chart of an embodiment of step S520. In this embodiment, step S520 includes: Step S521: Output the maximum time value and the storage address where the maximum time value is located.
[0064] The "FindMaxTmrFromEEProm" function is used to find the maximum time value in the EEPROM, and then the maximum time value and its storage address are read back.
[0065] Step S522: Disable auxiliary clock interrupt.
[0066] Use the "sysAuxClkDisable" function to disable the auxiliary clock.
[0067] Step S523: Configure the auxiliary clock frequency.
[0068] The auxiliary clock interrupt frequency is set using the "sysAuxClkRateSet" function.
[0069] Step S524: Obtain the auxiliary clock frequency.
[0070] Obtain the frequency of the auxiliary clock interrupt.
[0071] Step S525: Connect the auxiliary clock interrupt service routine.
[0072] Connect the auxiliary clock interrupt service routine.
[0073] Step S526: Enable auxiliary clock interrupt.
[0074] The auxiliary clock is enabled using the "TmrRecFun" function. The auxiliary clock interrupt callback function is also used with the "TmrRecFun" function.
[0075] The method for recording device running time provided in this embodiment requires the software to read back the time data stored in the EEPROM to determine the total running time value. By reading back and comparing all the data in the storage area, the largest time value is found and used as the total running time value. This value is then used as the time base value for the current device operation. The storage location of this maximum value is recorded so that after updating the latest value, the data can be continuously recorded by shifting backward from this storage location.
[0076] Further, see Figure 8 , Figure 8 for Figure 5 The detailed flowchart of step S530 shown in this embodiment is illustrated in this embodiment. Step S530 includes: Step S531: Enable the auxiliary clock and configure the clock interrupt to one second.
[0077] After reading back the maximum time value and storage address, the auxiliary clock is turned on and the clock interrupt is configured to be one second.
[0078] Step S532: Enter the interrupt handling function.
[0079] Specify the corresponding interrupt callback function. After the timer value is reached, the corresponding function is executed by calling the callback function. Inside the interrupt callback function, the main operations are to increment the current running value and write the incremented value to the EEPROM.
[0080] Step S533: If the maximum time value plus one second is detected, then the storage location is shifted backward by four bytes.
[0081] The process of writing values into EEPROM mainly involves splitting the time data into 4 bytes, shifting the storage location 4 bytes backward, and then writing the split 4 bytes of time data into the corresponding storage area. If a boundary is encountered during writing, the writing will start again from the initial position, and so on.
[0082] Step S534: Determine if the address has reached the last bit.
[0083] Determine if the address of the maximum time value is at the last bit.
[0084] Step S535: If the address has not reached the last digit, then write the time value to the specified storage location.
[0085] If the maximum time value is not detected to be the last digit, then the time value is written to the specified storage location.
[0086] The method for recording device running time provided in this embodiment stores the time data in the EEPROM in the following format: Figure 4 As shown, every four bytes from low address to high address represent a time data unit. During data writing and reading, the actual time value is calculated by shifting the time data. As the address increases, the stored value becomes larger. The difference between any two adjacent time data units is one second. This storage method ensures minimal error in the event of a power outage or a failed data write, and allows for the recovery of relatively accurate time data, thus responding to numerous unexpected situations and guaranteeing data accuracy.
[0087] like Figure 10 As shown, Figure 10This is a functional block diagram of an embodiment of a system for recording device runtime provided by the present invention. In this embodiment, the system for recording device runtime is applied to a runtime recording device, which includes a CPU hardware platform and an EEPROM storage chip. The EEPROM storage chip is connected to the CPU hardware platform via an I2C bus. A VxWorks system runs on the CPU hardware platform, and the time recording logic program runs on the VxWorks system. The time recording logic program reads and writes data to the EEPROM storage chip via the I2C protocol, writing or reading time data cyclically through the EEPROM. The system for recording device runtime includes a BIOS initialization module 10, a system startup module 20, a software initialization module 30, a program initialization module 40, a time value readback module 50, an auxiliary clock enabling module 60, and a recording program running module 70. The BIOS initialization module 10 is used for BIOS initialization: initializing the hardware and peripherals of the CPU platform, enabling the runtime recording device to complete basic power-on configuration; system startup... The system comprises the following modules: Module 20, for booting into the VxWorks system after BIOS initialization; Module 30, for software driver initialization: performing initialization operations on the software driver under the VxWorks system and completing basic system configuration and initialization functions; Module 40, for initializing the time recording logic program: initializing the time recording logic program, preparing for timing, and assigning initial values to function parameters; Module 50, for reading back the maximum time value: according to the application layer design, the time recording logic program reads the maximum time value stored in the EEPROM storage chip, which is the accumulated running time at the time of the last power failure, and is used as the timing reference value after this startup; Module 60, for enabling the auxiliary clock: powering on the auxiliary clock, calling the system clock for timing, and configuring the interrupt trigger time and interrupt handling function content; and Module 70, for running the time recording logic program: enabling the time recording function and allowing the time recording logic program to run cyclically.
[0088] The BIOS initialization module 10 initializes the BIOS, mainly to initialize the hardware and peripherals of the CPU platform, so that it can complete the basic power-on configuration.
[0089] After the BIOS initialization is complete, the system boot module 20 boots into the VxWorks system.
[0090] The software initialization module 30 initializes the software driver under the VxWorks system and completes the basic configuration and initialization functions under the system.
[0091] After completing basic initialization, the program initialization module 40 executes the logic functions within the main function based on its location. First, it initializes the time recording software, preparing for timing and performing operations such as assigning initial values to function parameters and variables.
[0092] According to the application layer design, the readback time value module 50 reads the maximum time value stored in the EEPROM. This value is the cumulative running time when the power was cut off last time, and is used as the timing reference value after the current startup.
[0093] The auxiliary clock startup module 60 powers on the auxiliary clock, calls the system clock for timing, and configures the interrupt trigger time and interrupt handling function, among other things.
[0094] The recording program module 70 enables the time recording function, allowing the time recording logic program to run in a loop.
[0095] The system for recording device runtime provided in this embodiment, compared with the prior art, employs a BIOS initialization module 10, a system startup module 20, a software initialization module 30, a program initialization module 40, a time value readback module 50, an auxiliary clock activation module 60, and a program execution recording module 70. It utilizes the existing system clock to record time runtime via software, fully leveraging platform hardware resources and software scheduling. Using an auxiliary clock and EEPROM chip under VxWorks, accurate time recording and storage can be achieved, and the EEPROM data will not be lost after system power failure. However, EEPROM read / write operations have a limited lifespan. If the program continuously accesses single bytes of the EEPROM, it will fail after its lifespan expires and will be unable to record values. The program cannot recognize or judge this and cannot automatically switch to the next byte area. Furthermore, in practical applications, there may be abnormal power outages. If time data is being written during such an event, data corruption will occur, leading to the loss of accumulated runtime data. In the current embedded platform environment, to meet increasingly diverse functional requirements, the uniform cyclic writing method for recording time values is very suitable for the above-mentioned usage scenarios. It achieves both time recording accuracy and data preservation while avoiding data corruption caused by abnormal power outages. The method for recording device runtime provided in this embodiment ensures the correct assignment of various reference values after system startup through this initialization process. The time recording logic program is started only after the reference values are configured, thus writing data from the recording position onwards without overwriting previous data, ensuring overall data accuracy and security. The auxiliary clock, as the clock counting value source for the software in this invention, must be enabled only after all initialization work is completed; otherwise, it will cause counting chaos and write failures. The time recording logic program runs cyclically, writing updated data to the storage space in a timely manner.
[0096] Further, please see Figure 11 , Figure 11 for Figure 10 The schematic diagram of a functional module of an embodiment of the program initialization module shown in the figure is as follows: In this embodiment, the read-back time value module 50 includes a read unit 51, a configuration unit 52, and a write unit 53. The read unit 51 is used to read the time base value after the program is powered on and running; the configuration unit 52 is used to configure the auxiliary clock and generate timing operations. After the configuration is completed, data processing can be performed inside the interrupt; the write unit 53 is used to complete the time writing function. The subsequent running of the program polls on the configured auxiliary clock logic.
[0097] The reading unit 51 reads the time reference value, which is completed first after the program is powered on and running.
[0098] Configuration unit 52 configures the auxiliary clock to generate timing operations. Once the configuration is complete, data processing can be performed within the interrupt.
[0099] The writing unit 53 uses the "WriteTmrToEEProm" function to write the time value into the EEPROM.
[0100] The system for recording device running time provided in this embodiment, compared with the prior art, uses a time value reading module 50 with a reading unit 51, a configuration unit 52, and a writing unit 53 to complete the time writing function. Subsequent program execution polls based on this logic. Following the flowchart, the software program can complete data searching, comparison, and judgment in the simplest and fastest way, saving time. Furthermore, the interrupt handling after the auxiliary clock interrupt is generated runs automatically, without occupying excessive CPU resources, ensuring processing speed.
[0101] Preferably, please see Figure 12 , Figure 12 for Figure 11 The diagram illustrates the functional modules of an embodiment of the readout unit. In this embodiment, the readout unit 51 includes a first readout subunit 511, a first assignment subunit 512, a first judgment subunit 513, a second readout subunit 514, a second judgment subunit 515, and a second assignment subunit 516. The first readout subunit 511 is used to read out the first time data; the first assignment subunit 512 is used to assign the read out first time data to the current maximum time value; the first judgment subunit 513 is used to determine whether the read out time data is the last data; the second readout subunit 514 is used to read out the next time data if it is not the last data; the second judgment subunit 515 is used to determine whether the read out next time data is the current maximum value; and the second assignment subunit 516 is used to assign the read out next time data to the current maximum time value if it is.
[0102] The first readout subunit 511 uses the "ReadTmrFromEEProm" function to read time data from the EEPROM and reads the first time data.
[0103] The first assignment subunit 512 reads the time data stored in the EEPROM. If the read time data is the first time data, then the read first time data is assigned the current maximum time value.
[0104] The first judgment subunit 513 determines whether the time data read from the EEPROM is the last data.
[0105] If the second read subunit 514 detects that the time data stored in the EEPROM is not the last data, it will read the next time data.
[0106] The second judgment subunit 515 determines whether the next time data stored in the read EEPROM is the current maximum value.
[0107] If the second assignment subunit 516 determines that the next time data stored in the read EEPROM is the current maximum value, then it assigns the next time data stored in the EEPROM to the current maximum time value.
[0108] Compared with the prior art, the system for recording device running time provided in this embodiment uses a first reading subunit 511, a first assignment subunit 512, a first judgment subunit 513, a second reading subunit 514, a second judgment subunit 515, and a second assignment subunit 516 in the reading unit 51. After each power failure and restart, the running time recording device needs to read back the time data stored in the EEPROM to determine the total running time value. By reading back and comparing all the data in the storage area, the largest time value is found to be the total running time value and is used as the time base value for the current running of the device. The storage location of this maximum value is recorded so that after updating the latest value, the device can continuously record by shifting backward from this storage location.
[0109] Further, please see Figure 13 , Figure 13 for Figure 11 The schematic diagram of the functional modules of one embodiment of the configuration unit shown is illustrated. In this embodiment, the configuration unit 52 includes an output subunit 521, a disable subunit 522, a configuration subunit 523, an acquisition subunit 524, a connection subunit 525, and an enable subunit 526. The output subunit 521 is used to output the maximum time value and the storage address where the maximum time value is located; the disable subunit 522 is used to disable the auxiliary clock interrupt; the configuration subunit 523 is used to configure the auxiliary clock frequency; the acquisition subunit 524 is used to acquire the auxiliary clock frequency; the connection subunit 525 is used to connect to the auxiliary clock interrupt service routine; and the enable subunit 526 is used to enable the auxiliary clock interrupt.
[0110] The output subunit 521 uses the "FindMaxTmrFromEEProm" function to find the maximum time value in the EEPROM, and then reads back the maximum time value and the storage address where the maximum time value is located.
[0111] The auxiliary clock is disabled by using the "sysAuxClkDisable" function in subunit 522.
[0112] Configuration subunit 523 uses the "sysAuxClkRateSet" function to set the auxiliary clock interrupt time frequency.
[0113] Obtain the auxiliary clock interrupt time frequency from subunit 524.
[0114] Connect subunit 525 to the auxiliary clock interrupt service routine.
[0115] Enable subunit 526 uses the "TmrRecFun" function to set the auxiliary clock enable. The "TmrRecFun" function is also used as the auxiliary clock interrupt callback function.
[0116] Compared with the prior art, the system for recording device running time provided in this embodiment requires the software to read back the time data stored in the EEPROM to determine the total running time value. By reading back and comparing all the data in the storage area, the largest time value is found to be the total running time value and is used as the time base value for the current device operation. The storage location of this maximum value is recorded so that after updating the latest value, the storage location can be shifted backward to continuously record.
[0117] Preferably, see Figure 14 , Figure 14 for Figure 11 The diagram illustrates the functional modules of an embodiment of the write unit. In this embodiment, the write unit 53 includes an open subunit 531, an enter subunit 532, a control subunit 533, a judgment subunit 534, and a write subunit 535. The open subunit 531 is used to open the auxiliary clock and configure the clock interrupt to one second. The enter subunit 532 is used to enter the interrupt handling function. The control subunit 533 is used to control the storage location to be offset backward by four bytes if the maximum time value plus one second is detected. The judgment subunit 534 is used to determine whether the address has reached the last bit. The write subunit 535 is used to write the time value at the specified storage location if the address has not reached the last bit.
[0118] After reading back the maximum time value and storage address, subunit 531 starts the auxiliary clock and configures the clock interrupt to one second.
[0119] Entering subunit 532, the corresponding interrupt callback function is specified. After the timer value is full, the corresponding function is completed by calling the callback function. Inside the interrupt callback function, the main operations are to increment the current running value and write the incremented value to the EEPROM.
[0120] In the process of writing values into the EEPROM, the control subunit 533 mainly splits the time data into 4 bytes, moves the storage location back by 4 bytes, and then writes the split 4 bytes of time data into the corresponding storage area. If a boundary is encountered during writing, it will start writing again from the initial position, and so on in a loop.
[0121] Determine if subunit 534 determines whether the address of the maximum time value has reached the last bit.
[0122] If the write sub-unit 535 detects that the maximum time value has not reached the last digit, it writes the time value to the specified storage location.
[0123] The system for recording device running time provided in this embodiment, compared with the prior art, uses an open subunit 531, an entry subunit 532, a control subunit 533, a judgment subunit 534, and a write subunit 535 for the writing unit 533. The storage format of the time data in the EEPROM is as follows: Figure 4 As shown, every four bytes from low address to high address represent a time data unit. During data writing and reading, the actual time value is calculated by shifting the time data. As the address increases, the stored value becomes larger. The difference between any two adjacent time data units is one second. This storage method ensures minimal error in the event of a power outage or a failed data write, and allows for the recovery of relatively accurate time data, thus responding to numerous unexpected situations and guaranteeing data accuracy.
[0124] Although preferred embodiments of the invention have been described, those skilled in the art, upon learning the basic inventive concept, can make other changes and modifications to these embodiments. Therefore, the appended claims are intended to be interpreted as including both the preferred embodiments and all changes and modifications falling within the scope of the invention. Clearly, those skilled in the art can make various alterations and modifications to the invention without departing from its spirit and scope. Thus, if these modifications and modifications of the invention fall within the scope of the claims and their equivalents, the invention is also intended to include these modifications and modifications.
Claims
1. A method for recording device runtime, applied in a runtime recording device, the runtime recording device comprising a CPU hardware platform and an EEPROM storage chip, the EEPROM storage chip being implemented via I... 2 The C bus is connected to the CPU hardware platform. The VxWorks system runs on the CPU hardware platform, and the time recording logic program runs on the VxWorks system. The time recording logic program is connected via I... 2 The C protocol performs data reading and writing on the EEPROM storage chip, and writes or reads time data cyclically and evenly through the EEPROM storage chip. Its characteristic is that... The method for recording device operating time includes the following steps: BIOS initialization: Initializes the CPU platform hardware and peripherals, enabling the runtime recording device to complete basic power-on configuration; VxWorks system startup: After BIOS initialization is complete, the system boots and then enters the VxWorks system; Software driver initialization: Initialize the software driver under the VxWorks system and complete the basic configuration and initialization functions under the system; Initialize the time recording logic program: Initialize the time recording logic program, prepare for timing, and complete the initialization of function parameter variables. Maximum time value readback: According to the application layer design, the time recording logic program reads the maximum time value stored in the EEPROM storage chip. This maximum time value is the cumulative running time when the power was cut off last time, and is used as the timing reference value after this startup. Auxiliary clock enabled: Powers on the auxiliary clock, invokes the system clock for timing, and configures the interrupt trigger time and interrupt handling function content; Time recording logic program execution: Enable the time recording function to allow the time recording logic program to run in a loop.
2. The method for recording equipment running time as described in claim 1, characterized in that, The steps for determining the maximum readback time value include: Read the time base value after the program is powered on and running; Configure an auxiliary clock to generate timing operations; once configured, data processing can be performed within the interrupt handler. Once the time writing function is complete, the subsequent program execution polls the configured auxiliary clock logic.
3. The method for recording equipment running time as described in claim 2, characterized in that, The step of reading the time reference value after the program is powered on and running includes: Read the first time data; Assign the first time data read to the current maximum time value; Determine if the read time data is the last data; If it is not the last data point, then read the next time data. Determine if the next time data read is the current maximum value; If the next time data read is the current maximum value, then the current maximum time value will be assigned to it.
4. The method for recording equipment running time as described in claim 3, characterized in that, The steps for configuring an auxiliary clock to generate timing operations, and then performing data processing within the interrupt after configuration, include: Output the maximum time value and the storage address where the maximum time value is located; Disable auxiliary clock interrupts; Configure auxiliary clock frequency; Obtain the auxiliary clock frequency; Connect the auxiliary clock interrupt service routine; Enable auxiliary clock interrupt.
5. The method for recording equipment running time as described in claim 4, characterized in that, The completion time writing function, and the subsequent steps of the program's polling operation on the configured auxiliary clock logic, include: Enable the auxiliary clock and configure the clock interrupt to one second; Enter the interrupt handler function; If the maximum time value plus one second is detected, the storage location is shifted backward by four bytes. Determine if the address has reached the last digit; If the address has not reached the last digit, then the time value is written to the specified storage location.
6. A system for recording device runtime, applied in a runtime recording device, the runtime recording device comprising a CPU hardware platform and an EEPROM storage chip, the EEPROM storage chip being connected to the CPU hardware platform via an I2C bus, a VxWorks system running on the CPU hardware platform, a time recording logic program running on the VxWorks system, the time recording logic program performing data read and write operations on the EEPROM storage chip via the I2C protocol, and cyclically writing or reading time data through the EEPROM, characterized in that... The system for recording device operating time includes: BIOS initialization module (10) is used for BIOS initialization: initializing the hardware and peripherals of the CPU platform, enabling the runtime recording device to complete basic power-on configuration; The system startup module (20) is used to boot into the VxWorks system after BIOS initialization is completed; The software initialization module (30) is used for software driver initialization: it performs initialization operations on the software driver under the VxWorks system and completes the basic configuration and initialization functions under the system. The program initialization module (40) is used to initialize the time recording logic program: initialize the time recording logic program, prepare for timing, and complete the variable initialization value assignment operation of the function parameters; The time value readback module (50) is used to read back the maximum time value: According to the application layer design, the time recording logic program reads the maximum time value stored in the EEPROM storage chip. This maximum time value is the cumulative running time when the power was cut off last time, and is used as the timing reference value after this startup. Auxiliary clock enable module (60) is used to enable the auxiliary clock: power on the auxiliary clock, call the clock in the system to keep time, and configure the interrupt trigger time and interrupt handling function content; The recording program execution module (70) is used for the execution of the time recording logic program: enabling the time recording function allows the time recording logic program to run in a loop.
7. The system for recording equipment operating time as described in claim 6, characterized in that, The readback time value module (50) includes: The readout unit (51) is used to read the time base value after the program is powered on and running; Configuration unit (52) is used to configure the auxiliary clock and generate timing operations. After the configuration is completed, data processing can be performed inside the interrupt. The write unit (53) is used to complete the time writing function. The subsequent operation of the program polls on the configured auxiliary clock logic.
8. The system for recording equipment running time as described in claim 7, characterized in that, The readout unit (51) includes: The first readout subunit (511) is used to read out the first time data; The first assignment subunit (512) is used to assign the first time data read out to the current maximum time value; The first judgment subunit (513) is used to determine whether the read time data is the last data; The second readout subunit (514) is used to read the next time data if it is not the last data. The second judgment subunit (515) is used to determine whether the next time data read out is the current maximum value; The second assignment subunit (516) is used to assign the current maximum time value if the next time data read is the current maximum value.
9. The system for recording equipment operating time as described in claim 8, characterized in that, The configuration unit (52) includes: The output subunit (521) is used to output the maximum time value and the storage address where the maximum time value is located. The disable subunit (522) is used to disable auxiliary clock interrupts; Configuration subunit (523) is used to configure the auxiliary clock frequency; Acquisition subunit (524) is used to acquire the auxiliary clock frequency; The connection subunit (525) is used to connect the auxiliary clock interrupt service routine; The enable subunit (526) is used to enable the auxiliary clock interrupt.
10. The system for recording equipment operating time as described in claim 9, characterized in that, The writing unit (53) includes: Enable subunit (531) to enable the auxiliary clock and configure the clock interrupt to one second; Enter subunit (532) to enter the interrupt handling function; The control subunit (533) is used to control the storage location to be offset backward by four bytes if the maximum time value plus one second is detected; The judgment subunit (534) is used to determine whether the address has reached the last bit; Write subcell (535) is used to write the time value at the specified storage location if the address has not reached the last bit.
Citation Information
Patent Citations
An embedded device restart state recording method based on Linux system
CN108984347A
Method for recording power-on accumulated time of task machine by utilizing EEPROM (Electrically Erasable Programmable Read-Only Memory) without battery
CN111797031A