A memory self-testing method for collaborative protection of stack and data areas

The memory self-testing method that uses stack and data area collaborative protection solves the problem of the contradiction between collaborative protection and efficiency in traditional memory detection, and achieves efficient and reliable memory fault detection, which is suitable for rail transit signal control systems.

CN123114940APending Publication Date: 2026-11-17CRRC QINGDAO SIFANG ROLLING STOCK RESEARCH INSTITUTE CO LTD
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202611313761.1
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2026-08-27
Publication Date
2026-11-17

AI Technical Summary

Technical Problem

In existing technologies, memory detection methods lack a collaborative protection mechanism for the stack and data area, resulting in a prominent contradiction between detection efficiency and real-time performance. The types of faults detected are limited, resource consumption is high, and comprehensive memory verification cannot be completed within a limited time.

Method used

A memory self-testing method that employs collaborative protection of the stack and data area is adopted. Through progressive granularity refinement algorithms in the first and second detection stages, combined with an intelligent scheduling mechanism, it achieves organic collaborative protection of the stack and data area, adapts to different system loads and task priorities, and performs detection in stages.

Benefits of technology

It achieves multi-level memory integrity protection, improves detection efficiency and reliability, meets the response requirements of real-time systems, supports multiple CPU architectures, has higher applicability, and the detection time increases almost linearly with the memory size.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN123114940A_ABST
    Figure CN123114940A_ABST
Patent Text Reader

Abstract

This invention provides a memory self-testing method for collaborative protection of the stack and data areas, comprising: detecting the integrity of the stack memory area; detecting the integrity of the data area memory; wherein, the detection of the integrity of the data area memory includes a first detection stage and a second detection stage, the first detection stage performing detection on the data area memory at a first detection granularity, and the second detection stage performing detection on the data area memory at a second detection granularity, the second detection granularity being smaller than the first detection granularity; coordinating the execution timing of detecting the integrity of the stack memory area and detecting the integrity of the data area memory; the coordination includes: obtaining the current running state parameters of the memory self-testing method; controlling the switching of the data area detection between the first detection stage and the second detection stage according to the running state parameters; and, when the detection result of the stack detection indicates a stack abnormality, immediately terminating the current execution operation of the data area detection.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This application relates to the field of embedded computer system technology, and in particular to a memory self-testing method that coordinates stack and data area protection. Background Technology

[0002] In embedded systems for rail transit, especially safety-critical systems such as railway signaling and high-safety controllers, memory integrity is directly related to the system's reliability and security. Traditional memory detection methods have the following problems: (1) The detection objects are isolated and lack a collaborative protection mechanism. Existing technologies often detect the stack or data area separately. Stack protection and data area detection are independent of each other and are executed separately, which cannot form a unified integrity protection system and is difficult to deal with cross-regional fault propagation.

[0003] (2) The contradiction between detection efficiency and real-time performance is prominent. Comprehensive memory detection takes too long. If all memory verification is completed in a single detection cycle, it will seriously affect the real-time performance of the system. If the detection is distributed across multiple cycles, the timeliness of fault detection will decrease, which will not meet the fault response time requirements of safety-critical systems.

[0004] (3) Limited fault detection types. Existing methods mainly detect single types of faults, which makes it difficult to cover complex memory problems such as fixed faults, coupled faults and state-dependent faults at the same time, resulting in insufficient fault coverage.

[0005] (4) High resource consumption. The detection process consumes a lot of CPU time and system resources. In resource-constrained embedded environments, it may affect the execution of normal functional tasks or even cause task timeouts.

[0006] In summary, existing technologies lack a collaborative protection mechanism for the stack and data area, and cannot complete a comprehensive memory verification that balances efficiency and depth within a limited time. Summary of the Invention

[0007] The purpose of this application is to provide a memory self-testing method that coordinates the protection of the stack and data area to address the deficiencies in the existing technology, thereby solving the problems existing in the prior art.

[0008] To achieve the above objectives, this application provides a memory self-testing method that coordinates stack and data area protection. The integrity of the stack memory region is checked; The integrity of the data area memory is detected; wherein the integrity detection of the data area memory includes a first detection stage and a second detection stage, the first detection stage performs detection on the data area memory at a first detection granularity, and the second detection stage performs detection on the data area memory at a second detection granularity, the second detection granularity being smaller than the first detection granularity; The execution timing of detecting the integrity of the stack memory region and detecting the integrity of the data memory region is coordinated; the coordination includes: obtaining the current running state parameters of the memory self-test method; controlling the data region detection to switch between the first detection stage and the second detection stage according to the running state parameters; and, when the detection result of the stack detection indicates a stack abnormality, immediately terminating the current execution operation of the data region detection.

[0009] In one possible implementation, before the integrity check of the stack memory region, the method further includes: Set the address range of the stack bottom protection region and the stack top protection region, and set the size of the stack bottom protection region and the stack top protection region to a preset byte length; The stack bottom protection area is filled sequentially with mode values ​​that are cyclically incremented from 0x00 to 0xFF; After the data in the bottom protection region of the stack is filled, all the data is completely copied to the top protection region of the stack as mirror data of the top protection region of the stack. Save the inverse code of the stack bottom address, the inverse code of the stack top address, the CRC check value of the stack bottom protection area, and the CRC check value of the stack top protection area.

[0010] In one possible implementation, the detection of the integrity of the stack memory region specifically includes: Calculate the one's complement of the stack bottom address and the one's complement of the stack top address, and compare them with the one's complement of the stack bottom address and the one's complement of the stack top address that are pre-stored locally; if the comparison result of either the one's complement of the stack bottom address or the one's complement of the stack top address is inconsistent, a stack exception is directly determined and no further verification is performed. When both the inverse code of the stack bottom address and the inverse code of the stack top address pass the verification, the CRC check value of the stack bottom protection area and the CRC check value of the stack top protection area are calculated respectively, and compared with the corresponding CRC check values ​​pre-saved locally; if the comparison result of any CRC check value is inconsistent, a stack error is determined.

[0011] In one possible implementation, the first detection phase includes: The Abraham operation table is updated based on the current number of operations. The Abraham operation table records the types of operations that should be performed in each memory region during the current detection period. Based on the updated Abraham operation table, determine the first memory region where write operations are performed and the second and third memory regions where read operations are performed during the current detection period; According to the instructions of the operation table, the data in the first memory region is written from 0 to 1 or from 1 to 0; The second memory region and the third memory region are initialized to 0 or 1 respectively, and their data is read to verify whether the read value is consistent with the initial value; Within one detection cycle, detection operations are performed simultaneously on one write operation unit and two read operation units; Back up the original data of the first memory region, the second memory region, and the third memory region and calculate their CRC check values; After the write operation and the read operation are completed and the data verification is completed, the backed-up original data is restored to the first memory area, the second memory area and the third memory area respectively; Recalculate the CRC checksum for the restored data and compare it with the CRC checksum calculated during backup. If the comparison results are consistent, update the operation counter and perform the test on the next set of test units; If the comparison results are inconsistent, the detection is deemed to have failed and the embedded device where the memory self-test method is located is switched to a safe state.

[0012] In one possible implementation, the second detection phase includes: Set the current granularity level, and determine the number of test units in this detection cycle based on the current granularity level; Divide the data area memory according to the current granularity level, and perform a complete unit test on each test unit in turn; The unit integrity detection includes: Back up the original data of the current test unit and calculate its CRC check value; Execute the complete Abraham algorithm sequence on the current test unit. The Abraham algorithm sequence includes at least 8 operations, including at least 4 write operations and at least 4 read operations. After execution, the backed-up original data is restored to the current test unit, and the CRC checksum of the restored data is verified. After all test units at the current granularity level have completed the full unit test, it is determined whether the granularity needs to be refined. If the current granularity level is greater than the preset minimum granularity, it is determined that the granularity needs to be refined, and the current granularity level is reduced to half of its original value. The data area memory is then re-divided according to the reduced granularity level, and the unit integrity detection is restarted. If the current granularity level is equal to the preset minimum granularity, and the complete unit detection of all test units at this granularity level has been completed, then the second detection stage is determined to be complete.

[0013] In one possible implementation, coordinating the execution timing of integrity checks on the stack memory region and the data memory region also includes switching to different detection modes according to the system operating scenario. The detection modes include a power-on full detection mode, a periodic detection mode, a fast verification mode, a key verification mode, and a deep detection mode. The power-on full detection mode is to perform a complete detection of the stack memory area and data area memory during the power-on phase after system initialization. The periodic detection mode is that after the system enters normal operation, data area detection is performed in stages within a preset scheduling period. The staged gradual execution includes the sequential execution of the first detection stage and the second detection stage. The fast verification mode is to perform fast verification detection on a preset key memory region before the execution of key operations. The detection granularity of the fast verification detection is greater than the first detection granularity, that is, the verification detection is performed with a coarser granularity than the first detection stage. The key verification mode is to re-inspect the memory area related to the fault after the fault is recovered, and only the fault-related area is inspected instead of the entire data area memory. The deep detection mode is to perform the second detection stage of deep detection on the data area memory when the system is idle.

[0014] In one possible implementation, the running status parameters include CPU load rate and / or current task priority; The step of controlling the data area detection to switch between the first detection stage and the second detection stage according to the operating status parameters specifically includes: When the CPU load rate is higher than a preset threshold, the data area detection is controlled to perform the first detection stage; When the CPU load rate is lower than a preset threshold, the data area detection is controlled to perform the second detection stage; And / or, When the priority of the current task is higher than the preset level, the data area detection is controlled to perform the first detection stage; When the priority of the current task is lower than the preset level, the data area detection is controlled to perform the second detection stage.

[0015] In one possible implementation, the coordination of the execution timing of integrity checks on the stack memory region and integrity checks on the data memory region specifically includes: The integrity check of the stack memory region is performed in each detection cycle; In each detection cycle, only a portion of the data area memory is checked for integrity, thus distributing the detection of the complete data area memory across multiple detection cycles.

[0016] In one possible implementation, when the stack detection result indicates a stack exception, the current execution operation of the data area detection is immediately terminated, specifically including: A stack error is determined when any of the following occurs: failure to verify the inverse code of the stack bottom address, failure to verify the inverse code of the stack top address, failure to compare the verification value of the stack bottom protected area, or failure to compare the verification value of the stack top protected area. Based on the stack exception, the currently executing data area detection operation is terminated, and the embedded device where the memory self-test method is located is switched to a safe state.

[0017] In one possible implementation, the method further includes: During the data area detection process, the current detection progress status is saved in the global state structure; When the data area detection is terminated, at the start of the next detection cycle, the current detection progress status is read from the global state structure, and the data area detection is continued from the current detection progress status.

[0018] The memory self-testing method with stack and data area collaborative protection provided in this application has the following technical effects: (1) Collaborative protection architecture breaks through the traditional single detection mode and realizes organic collaborative protection of stack and data area. Traditional methods often detect stack or data area separately. This invention organically combines the two through a unified coordination and control mechanism to form a three-dimensional, multi-level memory integrity protection system.

[0019] (2) Intelligent scheduling mechanism: The system can intelligently adjust the detection strategy according to the real-time status such as CPU load and task priority. When the load is high, stack detection + fast data detection is performed; when the load is low, stack detection + deep data detection is performed; and key areas are quickly verified before critical operations.

[0020] (3) Progressive granularity refinement algorithm breaks through the limitations of traditional fixed granularity detection. It adopts an adaptive granularity evolution strategy, starting from macroscopic large memory blocks, such as 1024 test units, to quickly scan and gradually refine to microscopic single units, such as 1 test unit depth detection, to achieve the best balance between detection efficiency and depth.

[0021] (4) Performance efficiency advantage: It achieves efficient detection of O(n)-O(n log n), which has significant advantages over traditional methods and can meet the response requirements of real-time systems.

[0022] (5) Improved reliability, breaking through the limitations of traditional detection methods, and enabling the detection of various types of memory faults.

[0023] (6) Improved fault recovery efficiency: The detection progress is saved through a global state structure. When the data area detection is terminated due to a stack exception, it can continue to be executed from the breakpoint in the next detection cycle, avoiding starting the detection from the beginning after each interruption.

[0024] (7) It has greater applicability, supports hardware platforms with multiple CPU architectures, and has more flexible parameter configuration. Attached Figure Description

[0025] Figure 1 A flowchart of a memory self-test method for collaborative protection of stack and data area provided in an embodiment of the present invention; Figure 2 This is a flowchart of stack detection initialization provided in an embodiment of the present invention; Figure 3 A flowchart of the stack detection mechanism provided in this embodiment of the invention; Figure 4 A flowchart of the first stage detection provided in this embodiment of the invention; Figure 5 This is a flowchart of the second-stage detection process provided in an embodiment of the present invention; Figure 6 A flowchart of the coordination control mechanism provided in an embodiment of the present invention. Detailed Implementation

[0026] To make the objectives, technical solutions, and advantages of this application clearer, the application will be further described in detail below with reference to the accompanying drawings. Obviously, the described embodiments are only some embodiments of this application, and not all embodiments. Based on the embodiments in this application, all other embodiments obtained by those skilled in the art without creative effort are within the scope of protection of this application.

[0027] The technical solution of this application will be further described in detail below with reference to the accompanying drawings and embodiments.

[0028] Figure 1 The flowchart of the memory self-test method for collaborative protection of stack and data area provided in the embodiments of the present invention is as follows: Figure 1 As shown, the method includes the following steps: Step 110: Check the integrity of the stack memory region.

[0029] Combination Figure 2As shown, before detecting the integrity of the stack memory region, the method further includes: setting the address range of the stack bottom protection region and the stack top protection region, checking the validity of the input parameters, the input parameters including the stack bottom address and the length of the protection region; and setting the size of the stack bottom protection region and the stack top protection region to a preset byte length. Preferably, the preset byte length is 256 bytes. In practical applications, this value can be flexibly configured according to the system stack space size. For example, it can be set to 128 bytes in a resource-constrained embedded system and 512 bytes in a system with ample memory. The stack bottom protection region is filled sequentially using a pattern value that increases cyclically from 0x00 to 0xFF. All data in the filled stack bottom protection region is completely copied to the stack top protection region as mirror data of the stack top protection region. The inverse code of the stack bottom address, the inverse code of the stack top address, the CRC check value of the stack bottom protection region, and the CRC check value of the stack top protection region are saved.

[0030] Combination Figure 3 As shown, the integrity detection of the stack memory region specifically includes: Calculate the inverse complement of the stack bottom address and the stack top address, and compare them with the inverse complements of the stack bottom address and the stack top address pre-stored locally. If either the inverse complement of the stack bottom address or the inverse complement of the stack top address is inconsistent, a stack exception is directly determined, and no further checks are performed. When both the inverse complements of the stack bottom address and the inverse complement of the stack top address pass the checks, calculate the CRC checksums of the stack bottom protection area and the stack top protection area, and compare them with the corresponding CRC checksums pre-stored locally. If either CRC checksum is inconsistent, a stack exception is determined.

[0031] If the stack bottom address inverse code verification, stack top address inverse code verification, stack bottom protected area CRC verification, and stack top protected area CRC verification all pass, then the detection is returned as successful.

[0032] The stack detection mechanism described above can detect various types of stack exceptions. The corresponding relationships are shown in Table 1, which is a table of fault types that can be detected by stack detection.

[0033] Table 1 Preferably, a first CRC polynomial is used to calculate the CRC check value of the bottom protection region, and a second CRC polynomial is used to calculate the CRC check value of the top protection region, wherein the second CRC polynomial is different from the first CRC polynomial.

[0034] Step 120: Integrity detection of the data area memory; wherein, the integrity detection of the data area memory includes a first detection stage and a second detection stage, the first detection stage performs detection on the data area memory at a first detection granularity, and the second detection stage performs detection on the data area memory at a second detection granularity, the second detection granularity being smaller than the first detection granularity.

[0035] Preferably, the first detection stage and the second detection stage are performed based on the improved Abraham algorithm. The Abraham algorithm is a memory testing algorithm that detects memory faults by writing a specific sequence to memory cells and reading back to verify it. It adopts a functional-level fault model and can detect fixed faults, coupled faults, and state-dependent faults.

[0036] Combination Figure 4 As shown, the first detection stage includes: The Abraham operation table is updated based on the current number of operations. This table records the operation types to be performed on each memory region during the current detection cycle. These operation types include read 0, read 1, write high (0-1), and write low (1-0). Based on the updated Abraham operation table, the first memory region to perform write operations, and the second and third memory regions to perform read operations are determined during the current detection cycle. Following the instructions of the operation table, the data in the first memory region is written from 0 to 1 (write high) or from 1 to 0 (write low). The second and third memory regions are initialized to 0 or 1 respectively, and their data is read to verify that the read values ​​match the initial values. During one detection cycle, detection operations are performed simultaneously on one write operation unit and two read operation units; each memory region experiences both write high and write low operations, and each memory region is read while other memory regions are performing write operations, to detect coupling faults between memory units. The original data of the first, second, and third memory regions are backed up, and their CRC checksums are calculated. After completing the write and read operations and verifying the data, the backed-up original data is restored to the first memory region, the second memory region, and the third memory region, respectively. The CRC checksum is recalculated for the restored data and compared with the CRC checksum calculated during backup. If the comparison results match, the operation counter is updated, and the next set of test units is tested. Once the operation counter has accumulated all operations, the system automatically switches to the second testing phase. If the comparison results do not match, the test is deemed a failure, and the embedded device containing the memory self-test method is switched to a safe state.

[0037] Combination Figure 5 As shown, the second detection stage includes: The current granularity level is set, and the number of test units in the current testing cycle is determined based on the current granularity level. Preferably, the initial value of the current granularity level is 1024 test units, and the preset minimum granularity is 1 test unit. The granularity refinement process is: 1024-512-256-128-64-32-16-8-4-2-1, reducing the granularity to half of its original value each time.

[0038] The data area memory is divided according to the current granularity level, and a complete unit test is performed on each test unit in turn.

[0039] The unit integrity detection includes: Back up the original data of the current test unit and calculate its CRC checksum. Initialize the current test unit to all zeros. Execute the complete Abraham algorithm sequence on the current test unit, which includes at least 8 operations, including at least 4 write operations and at least 4 read operations, covering all state combinations. After execution, restore the backed-up original data to the current test unit and verify the CRC checksum of the restored data.

[0040] Preferably, the complete Abraham algorithm sequence includes the following 8 operations: The first operation is to read 0 and write 1 in descending address order, and then read 1 in ascending address order; the second operation is to read 1 and write 0 in descending address order, and then read 0 in ascending address order; the third operation is to read 0 and write 1 in ascending address order, and then read 1 in descending address order; the fourth operation is to read 1 and write 0 in ascending address order, and then read 0 in descending address order; the fifth operation is to read 0, write 1, and write 0 in descending address order, and then read 0 in ascending address order; the sixth operation is to read 0, write 1, and write 0 in ascending address order, and then read 0 in ascending address order; the seventh operation is to read 1, write 0, and write 1 in ascending address order, and then read 1 in ascending address order; the eighth operation is to read 1, write 0, and write 1 in descending address order, and then read 1-3 in ascending address order.

[0041] Through the above 8 operations, each memory unit goes through a complete state transition sequence of reading 0, writing 1, reading 1, writing 0, and reading 0 in sequence, ensuring comprehensive coverage of stuck-at faults, transition faults, coupling faults, and address decoder faults.

[0042] After all test units at the current granularity level have completed the unit complete detection, it is determined whether the granularity needs to be refined. If the current granularity level is greater than the preset minimum granularity, it is determined that the granularity needs to be refined, and the current granularity level is reduced to half of its original value. The data area memory is then re-divided according to the reduced granularity level, and the unit complete detection is restarted. If the current granularity level is equal to the preset minimum granularity, and the unit complete detection of all test units at this granularity level has been completed, the second detection stage is determined to be complete.

[0043] Step 130: Coordinate the execution timing of integrity checks on the stack memory region and integrity checks on the data memory region.

[0044] Combination Figure 6 As shown, the coordination includes: obtaining the current running status parameters of the memory self-test method; controlling the data area detection to switch between the first detection stage and the second detection stage according to the running status parameters; and immediately terminating the current execution operation of the data area detection when the detection result of the stack detection indicates a stack abnormality.

[0045] Specifically, the timing of coordinating the execution of integrity checks on the stack memory region and the data memory region includes: The integrity check of the stack memory region is performed in each detection cycle. However, only a portion of the data memory is checked in each detection cycle, thus distributing the detection of the complete data memory across multiple detection cycles.

[0046] Specifically, when a stack detection result indicates a stack anomaly, the current execution of the data area detection operation is immediately terminated. This includes determining a stack anomaly when any of the following occurs: stack bottom address inverse code verification fails, stack top address inverse code verification fails, stack bottom protection region verification value comparison fails, or stack top protection region verification value comparison fails. Based on the stack anomaly, the currently executing data area detection operation is terminated, and the embedded device where the memory self-test method is located is switched to a safe state.

[0047] Furthermore, in combination Figure 6 As shown, the execution timing of coordinating the integrity detection of the stack memory area and the integrity detection of the data area memory also includes switching to different detection modes according to the system running scenario. The detection modes include power-on full detection mode, periodic detection mode, fast verification mode, key verification mode and deep detection mode. The power-on full detection mode performs a complete detection of the stack memory area and data area memory during the power-on phase after system initialization.

[0048] The periodic detection mode is that after the system enters normal operation, data area detection is performed in stages within a preset scheduling period. The staged progressive detection includes sequentially executing the first detection stage and the second detection stage; wherein, within the normal scheduling period, the detection is performed in a staged progressive detection manner.

[0049] The fast verification mode performs fast verification detection on a preset key memory region before the execution of critical operations. The detection granularity of the fast verification detection is greater than the first detection granularity, that is, the verification detection is performed with a coarser granularity than the first detection stage.

[0050] The key verification mode involves re-testing the memory regions related to the fault after the fault is recovered, but only testing the fault-related regions and not testing the entire data memory area.

[0051] The deep detection mode is to perform the second detection stage of deep detection on the data area memory when the system is idle.

[0052] The operating status parameters include CPU load rate and / or current task priority.

[0053] The step of controlling the data area detection to switch between the first detection stage and the second detection stage based on the operating status parameters specifically includes: when the CPU load rate is higher than a preset threshold, controlling the data area detection to execute the first detection stage; when the CPU load rate is lower than the preset threshold, controlling the data area detection to execute the second detection stage; and / or, when the current task priority is higher than a preset level, controlling the data area detection to execute the first detection stage; when the current task priority is lower than a preset level, controlling the data area detection to execute the second detection stage.

[0054] Preferably, the preset threshold is 70% of the CPU load rate. When the CPU load rate is higher than 70%, the system is in a high-load state and performs the first detection stage, i.e., fast scanning; when the CPU load rate is lower than 70%, the system is in a low-load state and performs the second detection stage, i.e., deep scanning. The preset level can be flexibly set according to the system task priority.

[0055] Preferably, the memory self-testing method provided by this invention can be applied to an embedded safety computer in a rail transit signal control system. In this application scenario, the embedded safety computer runs railway signal interlocking logic or Automatic Train Protection (ATP) algorithm, and its memory integrity is directly related to train operation safety. After the system is powered on, the complete detection process described in steps 110 to 130 is executed: first, the initialization of the stack protection area and stack integrity detection are completed; then, a fast scan of the data area is performed at a first detection granularity, such as 1024 test units, to detect basic memory faults; during daily operation cycles, the system performs stack detection in each control cycle, such as within 50ms, while distributing the detection of the complete data area across multiple cycles. Before critical operations such as when the train approaches the turnout area, the system triggers a fast verification mode, performing focused verification only on key memory areas related to the turnout control logic; during system idle periods such as inter-station operation, the system automatically switches to a deep detection mode, performing a complete Abraham algorithm sequence on the entire data area at a second detection granularity, such as 1 test unit, covering fixed faults, coupled faults, and state-dependent faults. When an anomaly is detected during stack detection, the system immediately terminates data area detection within the current control cycle and redirects the signal control system to a safer approach, such as shutting down signal output or triggering emergency braking, to ensure train safety. Actual measurements show that using this method, a single stack detection takes less than 1ms, and a complete data area detection can be completed within 200ms, meeting the dual requirements of real-time performance and safety for rail transit signal control systems.

[0056] Furthermore, the method also includes: During the data area detection process, the current detection progress status is saved in a global state structure. Preferably, the global state structure is a data structure stored in system memory, used to record the current execution status of the data area detection. The global state structure includes at least the following information: a current detection stage identifier, used to identify whether the current detection stage is the first or second detection stage; the current number of operations, used to record the current index of the Abraham operation table; the currently detected unit number, used to identify the number of test units completed at the current granularity level; and the current granularity level, used to identify the current detection granularity.

[0057] When the data area detection is terminated due to a stack exception, at the start of the next detection cycle, the current detection progress status is read from the global state structure, and the data area detection continues from the current detection progress status. By storing the detection progress status in the global state structure, breakpoint resumption of the detection progress is achieved, avoiding starting from the beginning after each detection interruption, thereby improving detection efficiency.

[0058] Compared to the shortcomings of existing memory detection methods described in the background section, this invention achieves targeted technical improvements through the following means: To address the issues of isolated detection targets and lack of collaborative protection mechanisms, this invention integrates stack detection and data area detection into the same scheduling framework through a unified collaborative control module, achieving organic collaboration between the two. To address the prominent conflict between detection efficiency and real-time performance, this invention divides data area detection into two stages: fast scanning and deep scanning. Combined with an intelligent scheduling mechanism, it dynamically switches detection strategies based on system load, maximizing detection depth while ensuring real-time performance. To address the limitation on fault detection types, this invention achieves coverage of fixed faults and simple coupled faults based on the Abraham algorithm in the first detection stage, and achieves deep detection of complex coupled faults and state-dependent faults through progressive granularity refinement in the second detection stage. To address the issue of high resource overhead, this invention distributes complete data area detection across multiple detection cycles, avoiding the large CPU time consumed by a single detection. Simultaneously, it implements breakpoint resumption detection through a global state structure, avoiding the overhead of repeated detection due to interruptions.

[0059] The memory self-testing method with stack and data area collaborative protection provided in this application has the following technical effects: (1) Collaborative protection architecture breaks through the traditional single detection mode and realizes organic collaborative protection of stack and data area. Traditional methods often detect stack or data area separately. This invention organically combines the two through a unified coordination and control mechanism to form a three-dimensional, multi-level memory integrity protection system.

[0060] (2) Intelligent scheduling mechanism: The system can intelligently adjust the detection strategy according to the real-time status such as CPU load and task priority. When the load is high, stack detection + fast data detection is performed; when the load is low, stack detection + deep data detection is performed; and key areas are quickly verified before critical operations.

[0061] (3) Progressive granularity refinement algorithm breaks through the limitations of traditional fixed granularity detection. It adopts an adaptive granularity evolution strategy, starting from macroscopic large memory blocks, such as 1024 test units, to quickly scan and gradually refine to microscopic single units, such as 1 test unit depth detection, to achieve the best balance between detection efficiency and depth.

[0062] (4) Performance efficiency advantage: Compared with traditional methods, it has a significant advantage in detection efficiency. The detection time is nearly linearly related to the memory size, which can meet the response requirements of real-time systems.

[0063] (5) Improved reliability, breaking through the limitations of traditional detection methods, and enabling the detection of various types of memory faults.

[0064] (6) Improved fault recovery efficiency: The detection progress is saved through a global state structure. When the data area detection is terminated due to a stack exception, it can continue to be executed from the breakpoint in the next detection cycle, avoiding starting the detection from the beginning after each interruption.

[0065] (7) It has greater applicability, supports hardware platforms with multiple CPU architectures, and has more flexible parameter configuration.

[0066] Those skilled in the art will further recognize that the units and algorithm steps of the various examples described in conjunction with the embodiments disclosed herein can be implemented in electronic hardware, computer software, or a combination of both. To clearly illustrate the interchangeability of hardware and software, the components and steps of the various examples have been generally described in terms of functionality in the foregoing description. Whether these functions are implemented in hardware or software depends on the specific application and design constraints of the technical solution. Those skilled in the art can use different methods to implement the described functions for each specific application, but such implementation should not be considered beyond the scope of this application.

[0067] The steps of the methods or algorithms described in conjunction with the embodiments disclosed herein can be implemented in hardware, a software module executed by a processor, or a combination of both. The software module can be located in random access memory (RAM), main memory, read-only memory (ROM), electrically programmable ROM, electrically erasable programmable ROM, registers, hard disk, removable disk, CD-ROM, or any other form of storage medium known in the art.

[0068] The specific embodiments described above further illustrate the purpose, technical solution, and beneficial effects of this application. It should be understood that the above description is only a specific embodiment of this application and is not intended to limit the scope of protection of this application. Any modifications, equivalent substitutions, improvements, etc., made within the spirit and principles of this application should be included within the scope of protection of this application.

Claims

1. A memory self-testing method for collaborative protection of stack and data area, characterized in that, The method includes: The integrity of the stack memory region is checked; The integrity of the data area memory is detected; wherein the integrity detection of the data area memory includes a first detection stage and a second detection stage, the first detection stage performs detection on the data area memory at a first detection granularity, and the second detection stage performs detection on the data area memory at a second detection granularity, the second detection granularity being smaller than the first detection granularity; The execution timing of detecting the integrity of the stack memory region and detecting the integrity of the data memory region is coordinated; the coordination includes: obtaining the current running state parameters of the memory self-test method; controlling the data region detection to switch between the first detection stage and the second detection stage according to the running state parameters; and terminating the current execution operation of the data region detection when the detection result of the stack detection indicates a stack abnormality.

2. The method according to claim 1, characterized in that, Before performing the integrity check on the stack memory region, the method further includes: Set the address range of the stack bottom protection region and the stack top protection region, and set the size of the stack bottom protection region and the stack top protection region to a preset byte length; The stack bottom protection area is filled sequentially with mode values ​​that are cyclically incremented from 0x00 to 0xFF; After the data in the bottom protection region of the stack is filled, all the data is completely copied to the top protection region of the stack as mirror data of the top protection region of the stack. Save the inverse code of the stack bottom address, the inverse code of the stack top address, the CRC check value of the stack bottom protection area, and the CRC check value of the stack top protection area.

3. The method according to claim 1, characterized in that, The integrity detection of the stack memory region specifically includes: Calculate the one's complement of the stack bottom address and the one's complement of the stack top address, and compare them with the one's complement of the stack bottom address and the one's complement of the stack top address that are pre-stored locally; if the comparison result of either the one's complement of the stack bottom address or the one's complement of the stack top address is inconsistent, a stack exception is directly determined and no further verification is performed. When both the inverse code of the stack bottom address and the inverse code of the stack top address pass the verification, the CRC check value of the stack bottom protection area and the CRC check value of the stack top protection area are calculated respectively, and compared with the corresponding CRC check values ​​pre-saved locally; if the comparison result of any CRC check value is inconsistent, a stack error is determined.

4. The method according to claim 1, characterized in that, The first detection stage includes: The Abraham operation table is updated based on the current number of operations. The Abraham operation table records the types of operations that should be performed in each memory region during the current detection period. Based on the updated Abraham operation table, determine the first memory region where write operations are performed and the second and third memory regions where read operations are performed during the current detection period; According to the instructions of the operation table, the data in the first memory region is written from 0 to 1 or from 1 to 0; The second memory region and the third memory region are initialized to 0 or 1 respectively, and their data is read to verify whether the read value is consistent with the initial value; Within one detection cycle, detection operations are performed simultaneously on one write operation unit and two read operation units; Back up the original data of the first memory region, the second memory region, and the third memory region and calculate their CRC check values; After the write operation and the read operation are completed and the data verification is completed, the backed-up original data is restored to the first memory area, the second memory area and the third memory area respectively; Recalculate the CRC checksum for the restored data and compare it with the CRC checksum calculated during backup. If the comparison results are consistent, update the operation counter and perform the test on the next set of test units; If the comparison results are inconsistent, the detection is deemed to have failed and the embedded device where the memory self-test method is located is switched to a safe state.

5. The method according to claim 1, characterized in that, The second detection stage includes: Set the current granularity level, and determine the number of test units in this detection cycle based on the current granularity level; Divide the data area memory according to the current granularity level, and perform a complete unit test on each test unit in turn; The unit integrity detection includes: Back up the original data of the current test unit and calculate its CRC check value; Execute the complete Abraham algorithm sequence on the current test unit. The Abraham algorithm sequence includes at least 8 operations, including at least 4 write operations and at least 4 read operations. After execution, the backed-up original data is restored to the current test unit, and the CRC checksum of the restored data is verified. After all test units at the current granularity level have completed the full unit test, it is determined whether the granularity needs to be refined. If the current granularity level is greater than the preset minimum granularity, it is determined that the granularity needs to be refined, and the current granularity level is reduced to half of its original value. The data area memory is then re-divided according to the reduced granularity level, and the unit integrity detection is restarted. If the current granularity level is equal to the preset minimum granularity, and the complete unit detection of all test units at this granularity level has been completed, then the second detection stage is determined to be complete.

6. The method according to claim 1, characterized in that, The coordination of the execution timing of integrity detection of the stack memory area and integrity detection of the data area memory also includes switching to different detection modes according to the system operation scenario. The detection modes include power-on full detection mode, periodic detection mode, fast verification mode, key verification mode and deep detection mode. The power-on full detection mode is to perform a complete detection of the stack memory area and data area memory during the power-on phase after system initialization. The periodic detection mode is that after the system enters normal operation, data area detection is performed in stages within a preset scheduling period. The staged gradual execution includes the sequential execution of the first detection stage and the second detection stage. The fast verification mode is to perform fast verification detection on a preset key memory region before the execution of key operations. The detection granularity of the fast verification detection is greater than the first detection granularity, that is, the verification detection is performed with a coarser granularity than the first detection stage. The key verification mode is to re-inspect the memory area related to the fault after the fault is recovered, and only the fault-related area is inspected instead of the entire data area memory. The deep detection mode is to perform the second detection stage of deep detection on the data area memory when the system is idle.

7. The method according to claim 1, characterized in that, The operating status parameters include CPU load rate and / or current task priority; The step of controlling the data area detection to switch between the first detection stage and the second detection stage according to the operating status parameters specifically includes: When the CPU load rate is higher than a preset threshold, the data area detection is controlled to perform the first detection stage; When the CPU load rate is lower than a preset threshold, the data area detection is controlled to perform the second detection stage; And / or, When the priority of the current task is higher than the preset level, the data area detection is controlled to perform the first detection stage; When the priority of the current task is lower than the preset level, the data area detection is controlled to perform the second detection stage.

8. The method according to claim 1, characterized in that, The coordination of the execution timing of integrity checks on the stack memory region and the data memory region specifically includes: The integrity check of the stack memory region is performed in each detection cycle; In each detection cycle, only a portion of the data area memory is checked for integrity, thus distributing the detection of the complete data area memory across multiple detection cycles.

9. The method according to claim 1, characterized in that, When the stack detection result indicates a stack anomaly, the current execution operation of the data area detection is immediately terminated, specifically including: A stack error is determined when any of the following occurs: failure to verify the inverse code of the stack bottom address, failure to verify the inverse code of the stack top address, failure to compare the verification value of the stack bottom protected area, or failure to compare the verification value of the stack top protected area. Based on the stack exception, the currently executing data area detection operation is terminated, and the embedded device where the memory self-test method is located is switched to a safe state.

10. The method according to claim 1, characterized in that, The method further includes: During the data area detection process, the current detection progress status is saved in the global state structure; When the data area detection is terminated, at the start of the next detection cycle, the current detection progress status is read from the global state structure, and the data area detection is continued from the current detection progress status.