### Introduction `romt` is a simple read-only memory (ROM) testing module for the C language. It defines multiple ROM testing modes, related callback function types, and structures representing ROM. Moreover, it provides a series of function interfaces such as initializing the ROM testing structure, starting the test, stopping the test, obtaining the historical test results and the latest test results, and executing the test task. It's convenient for developers to conduct tests on simulated ROM in different modes and for different durations in C language projects and view the corresponding test situations. ### Interfaces #### Functions ##### `romt_init` Function ```c int romt_init(ROMT *romt); ``` **Function Description**: It is mainly used to initialize the `ROMT` structure. It checks the validity of the passed-in `ROMT` structure and its parameters to ensure that key elements in the structure, such as the size of the ROM, pointers to read and write functions, etc., are legal and valid. Meanwhile, it initializes the private data fields in the structure to zero, preparing for subsequent ROM testing-related operations. **Parameter Introduction**: - `romt`: A pointer to the `ROMT` structure. This structure carries key information related to the ROM to be tested, such as the starting address of the ROM (reflected by the `base` member), the size (`size` member), and corresponding pointers to read and write functions. The function uses this pointer to perform initialization-related processing on each member inside the structure. ##### `romt_start` Function ```c int romt_start(ROMT *romt, uint32_t mode, uint32_t duration); ``` **Function Description**: It is responsible for starting the ROM testing operations. It configures and initiates the corresponding test process according to the passed-in specific testing mode and duration. Before starting, it first checks the validity of the input parameters and confirms that the ROM has been correctly initialized to ensure that the test operations can be carried out normally. **Parameter Introduction**: - `romt`: A pointer to the `ROMT` structure, which is used to locate the information related to the ROM to be tested, including its read and write functions, etc., providing a basic basis for conducting tests in accordance with the specified mode and duration later. - `mode`: Represents the operation mode of the ROM test. Its value is taken from predefined testing mode macros (such as `ROMT_MODE_READ`, `ROMT_MODE_WRITE`, etc.). Different macros correspond to different types of testing logic. For example, `ROMT_MODE_READ` represents the test mode of reading data from the ROM, and `ROMT_MODE_WRITE` corresponds to the test mode of writing data to the ROM (it should be noted that the actual ROM is usually read-only, and the write test may be conducted for functional verification in a simulated scenario). - `duration`: Specifies the duration of the ROM test. Based on this parameter, the time range for the test to run is controlled. The specific meaning depends on the actual setting. Different duration settings can meet different testing requirements, such as short-term quick tests or long-term comprehensive tests. ##### `romt_stop` Function ```c int romt_stop(ROMT *romt); ``` **Function Description**: It is used to stop the ongoing ROM testing operation. During the stopping process, relevant configurations such as the test mode and duration will be reset to zero. Meanwhile, it ensures that the ROM has been correctly initialized before to ensure that the entire stopping operation can be completed smoothly, avoiding problems such as abnormal test states remaining and resource occupation. **Parameter Introduction**: - `romt`: A pointer to the `ROMT` structure. Based on the structure pointed to by this pointer, it determines which ROM testing task to stop, and then performs reasonable stop and reset processing on the corresponding test resources, states, etc. ##### `romt_result` Function ```c uint32_t romt_result(ROMT *romt); ``` **Function Description**: It aims to obtain the historical result information of the ROM test. It first checks the validity of the passed-in `ROMT` structure. If the check passes, it extracts and returns the overall test situation accumulated during the previous ROM testing process from the private data of the structure, facilitating developers to comprehensively understand the comprehensive performance of the ROM in past multiple tests. If the check fails, it returns `0xFFFFFFFF` to indicate an error and the inability to obtain valid historical results. **Parameter Introduction**: - `romt`: A pointer to the `ROMT` structure. Based on the structure pointed to by this pointer, it searches for and obtains the corresponding historical test result data. Since different ROM testing tasks have their own independent result record storage locations, this pointer can accurately locate where the corresponding records are. ##### `romt_result_latest` Function ```c uint32_t romt_result_latest(ROMT *romt); ``` **Function Description**: It is used to obtain the latest result of the ROM test, that is, the result information generated by the most recent ROM test closest to the current time. Similarly, it first verifies the validity of the `ROMT` structure. If it is valid, it extracts and returns the latest result from its private data, enabling developers to quickly know the state of the ROM in the most recent test. If the structure validity check fails, it returns `0xFFFFFFFF` to indicate an error in obtaining the result. **Parameter Introduction**: - `romt`: A pointer to the `ROMT` structure. With the help of the structure pointed to by this pointer, it locates and obtains the latest result data of the corresponding ROM test, ensuring that the latest situation of the correct target ROM testing task is returned. ##### `romt_task` Function ```c void romt_task(ROMT *romt); ``` **Function Description**: It executes the operations related to the ROM testing task according to the configured testing mode. First, it checks the current testing mode. Then, within the allowed duration, it performs corresponding tests (such as specific test contents corresponding to different modes like read, write, normal, boundary, random, pattern generation, etc.) on the ROM represented by the `ROMT` structure. During the execution process, it updates the latest result and accumulates the relevant test situations into the historical result (stored in the private data of the structure) for viewing when obtaining results later. **Parameter Introduction**: - `romt`: A pointer to the `ROMT` structure. The function determines which ROM to test and in which mode to execute the testing task through this pointer. It is associated with various key configuration information of the ROM test and is the core basis for executing specific testing operations. Different ROMs correspond to structures containing different configuration situations, and through this pointer, they can be accurately distinguished and targeted tests can be conducted.