A design method for write cache of automotive-grade MCU eFlash controller based on cache reuse

By using the free cache lines of read cache or prefetch cache SRAM in the automotive-grade MCU eFlash controller as temporary write caches, the area and power consumption problems caused by read and write cache resource partitioning are solved, and coordinated control of write order and response release is achieved, improving the efficiency of fast writing of the entire line.

CN123114548APending Publication Date: 2026-11-17ZHONGYIN MICROELECTRONICS (CHENGDU) CO LTD
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202611563569.8
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2026-10-10
Publication Date
2026-11-17

Smart Images

  • Figure CN123114548A_ABST
    Figure CN123114548A_ABST
Patent Text Reader

Abstract

This invention discloses a design method for a write cache of an automotive-grade MCU eFlash controller based on cache reuse, relating to the field of automotive MCU eFlash controller storage technology. The method includes the following steps: determining the row start address and intra-row write order based on the entire row fast write request and row boundary offset; selecting an idle cache row in the read cache or prefetch cache SRAM as a temporary write cache row; writing data sequentially and recording the valid status; determining the downstream read position; sending the data to be written and releasing the corresponding position according to the response. In this invention, by reusing existing cache SRAM to carry the entire row fast write, the occupation of a dedicated write cache is reduced, and the idle cache space under read / write load is dynamically converted into write temporary storage resources. The consistency between the write order and the sending order is ensured through the coordinated action of valid status and completion release, reducing control path and arbitration complexity and improving the adaptability of area and timing implementation.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This invention relates to the field of automotive MCU eFlash controller storage technology, and in particular to a design method for a write cache of an automotive-grade MCU eFlash controller based on cache reuse. Background Technology

[0002] The field of automotive MCU eFlash controller storage technology belongs to the field of on-chip embedded flash memory control for automotive-grade microcontrollers. It mainly involves eFlash devices, AHB bus interfaces, read and write commands, fast write timing, cache SRAM, address tags, valid bits, write responses, and read and write arbitration. It is usually used to coordinate the CPU's reading, erasing, and writing of code, data, and upgrade content in eFlash. Among them, the traditional design method of automotive-grade MCU eFlash controller write cache refers to setting up a separate Data Buffer or write FIFO in the Flash controller to temporarily store 32 consecutive 64-bit write data sent by the AHB interface when writing to the entire line of eFlash. The data is written to a dedicated cache according to address offset, write count, and line order. Then, the Flash write control logic sends the data to the downstream interface one by one according to the eFlash device programming timing. The read cache is only used for reading data.

[0003] When existing automotive-grade MCU eFlash controllers are used for fast writing of entire rows, they typically have a separate write buffer to handle continuous write data, a read buffer to serve only read access, and fixed storage resources. When the read and write load changes, it is difficult to convert idle read buffer into write buffer capacity. The chip area and static resource overhead are relatively high. The dedicated write buffer also needs to independently maintain address offset, write count, in-row order and downstream transmission status, which makes the control path complex. There is insufficient reusable space in read and write arbitration. The buffer occupancy time before the entire row is written is long, which reduces the controller's overall adaptability to area, power consumption and timing convergence in automotive-grade scenarios. Summary of the Invention

[0004] The purpose of this invention is to provide a design method for write cache of automotive-grade MCU eFlash controller based on cache reuse. This method enables the automotive-grade MCU eFlash controller to use idle cache lines in the existing read cache or prefetch cache SRAM as temporary write cache lines during the fast writing process of the entire line. It establishes a coordinated control relationship between write order, valid status, transmission progress and response release, thereby realizing the reuse allocation and orderly release of write data temporary storage resources without changing the timing requirements of fast writing of the entire line. To achieve the above objectives, this invention provides a design method for a write cache of an automotive-grade MCU eFlash controller based on cache reuse, comprising the following steps: Obtain the write operation type, starting write address, write data width, and number of consecutive writes from the entire row fast write request. Based on the offset of the starting write address relative to the flash row boundary, and in combination with the write operation type, the write data width, and the number of consecutive writes, determine the row start address and the writing order within the row.

[0005] Based on the row start address, the read access occupancy status and write occupancy status of the candidate cache line are read from the read cache or prefetch cache SRAM of the eFlash controller. The candidate cache line with both states being idle is determined as a temporary write cache line, and the temporary write cache line is switched to write cache use and marked as the write occupancy status.

[0006] Write consecutive data into the corresponding positions of the temporary write cache lines in the order of writing within the lines, and record the validity status of the data at the corresponding positions.

[0007] Based on the in-row writing order, the number of entries written to the cache, and the number of entries sent to the eFlash device, the earliest position that has been written but not yet sent is determined as the downstream position to be read.

[0008] Read the write data to be sent from the downstream read position and send it to the eFlash device. Release the corresponding position according to the write response status and clear the write occupancy status when the condition for the entire line is met, so that the temporary write cache line can re-participate in the read cache or write cache allocation.

[0009] Further, when determining the row start address and the row write order, the starting write address in the whole row fast write request is obtained, and the starting write address is boundary aligned according to the flash row capacity. The row boundary address that is not greater than the starting write address and falls into the same flash row is determined, and the row boundary address is determined as the row start address. The row offset is determined based on the address difference between the starting write address and the row start address. The row offset is converted into the row start position according to the write data width. Multiple row write positions are determined from the row start position according to the number of consecutive writes, and the row write order is generated.

[0010] Optionally, when the write operation type is a non-wrap-around continuous write, the plurality of in-row write positions are determined sequentially from the starting position of the row in the address increment direction, and a sequential write sequence is output before the plurality of in-row write positions reach the end of the flash row; when the write operation type is a wrap-around continuous write, a first position sequence to the end of the flash row is determined in the address increment direction, and a second position sequence is determined from the beginning of the flash row, and the first position sequence and the second position sequence are associated according to the order of arrival of the write request to generate a wrap-around write sequence.

[0011] Further, when determining the temporary write cache line, a cache line index and address tag are generated based on the line start address. The cache line index is used to read the read access occupancy status, write occupancy status, and cache usage identifier of the candidate cache line in the state storage area of ​​the read cache or the prefetch cache SRAM. The address tag is compared with the line address tag of the candidate cache line to obtain the candidate matching status. When the candidate matching status is allowed to reuse, the read access occupancy status is idle, and the write occupancy status is idle, the candidate cache line is determined as the temporary write cache line, and the cache usage identifier is updated to the write cache identifier, and the write occupancy status is updated to the occupancy status.

[0012] Furthermore, when updating the write occupancy status, after reading the read access occupancy status and the write occupancy status, a status lock request for the candidate cache line is generated. When the status lock request receives a response, the read access occupancy status and the write occupancy status are reread. If the reread result is still idle, a write occupancy flag is written and an address association relationship is established between the temporary write cache line and the line start address. If any occupancy status in the reread result is occupied, the status lock request is canceled, and the occupancy status of the next candidate cache line is read according to the preset candidate line order, and the reallocation result is output.

[0013] Further, when writing the continuous write data into the temporary write cache line and recording the data validity status at the corresponding position, the write data sequence number corresponding to the number of continuous writes is obtained, the write data sequence number is sequentially mapped to the in-line write position in the in-line write order, and the byte write enable range corresponding to the temporary write cache line is determined according to the write data width, generating position write control information; the continuous write data is written into the corresponding storage position of the temporary write cache line according to the position write control information, and after each continuous write data is completed, the data validity status of the corresponding storage position is updated to a valid status, generating a cache line valid bitmap.

[0014] Further, when determining the downstream read position, the in-line write order, the number of written buffer entries, the number of entries sent to the eFlash device, and the data validity status corresponding to the temporary write buffer line are obtained. Based on the number of entries sent to the eFlash device, the sending progress position is determined in the in-line write order, and the first in-line write position after the sending progress position and with a valid data validity status is determined as the downstream read position. When the number of written buffer entries is greater than the number of entries sent to the eFlash device and the data validity status corresponding to the downstream read position is valid, a read-allowed flag is output. When the number of written buffer entries is equal to the number of entries sent to the eFlash device, a read-wait flag is output.

[0015] Furthermore, when determining the sending progress position, a sequential mapping relationship between the writing pen number and the writing position in the row is established according to the in-row writing order, and the next writing pen number corresponding to the number of writings sent to the eFlash device is determined as the candidate pen number to be read. The candidate in-row position corresponding to the candidate pen number to be read is read according to the sequential mapping relationship. If the data validity status of the candidate in-row position is valid, the candidate in-row position is determined as the downstream reading position. If the data validity status of the candidate in-row position is invalid, the waiting flag for reading is maintained and the candidate pen number to be read is latched.

[0016] Further, when reading the write data to be sent from the downstream read position and releasing the corresponding position, the data validity status corresponding to the downstream read position and the cached data in the temporary write cache line are read. When the data validity status is valid, a device write address is generated according to the line start address and the downstream read position, and the cached data is associated with the device write address to form the write data to be sent. The write data to be sent is sent to the eFlash device, and when the write response status matching the device write address is received, the data validity status corresponding to the downstream read position is released, and the number of records sent to the eFlash device is updated.

[0017] Furthermore, when receiving the write response status that matches the write address of the device, a response association record is established between the transmission sequence number, the write address of the device, and the downstream read position when sending the write data to be sent, and the response association record is written into the transmission status table; the write response status returned by the eFlash device is obtained, and the transmission status table is queried based on the address return information or sequence number return information carried by the write response status. When the query result is consistent with the response association record, the downstream read position is determined as the response release position.

[0018] The present invention has the following beneficial effects: In this invention, the row starting address and intra-row writing order are determined based on row boundary offset, write operation type, write data width, and number of consecutive writes. Write data is carried in read cache or prefetch cache SRAM where both types of cache rows are idle. This allows the fixed read cache to be converted into write temporary storage resources on demand. Continuous write data is written sequentially and its valid status is recorded. The downstream read position is constrained by both write progress and transmission progress, ensuring that unsent data is pushed to the eFlash device in an orderly manner. After the write response returns, the corresponding position is released. When the entire row is completed, the write occupancy status is cleared, enabling the read and write cache resources to be reused cyclically. This reduces the occupation of dedicated write cache, simplifies state maintenance and arbitration burden, and improves the coordination between area, power consumption, and timing. Attached Figure Description

[0019] Figure 1 This is the main flowchart for writing the cache to the automotive-grade MCU eFlash controller based on cache reuse, as described in this invention. Figure 2 A flowchart is generated to show the row start address and the writing order within the row in this invention; Figure 3 This is a logic diagram of the candidate cache line reuse allocation in this invention; Figure 4 This is a collaborative data flow diagram showing the valid data status and downstream read positions of the present invention. Figure 5 This is a state transition diagram for writing response matching and cache location release in this invention. Detailed Implementation

[0020] The following describes the possible embodiments of the present invention in conjunction with the technical solutions described herein. The embodiments described below are based on the automotive-grade MCU eFlash controller executing a full-line fast write request. Terms such as full-line fast write request, write operation type, starting write address, write data width, number of consecutive writes, row starting address, in-row write order, read access occupancy status, write occupancy status, temporary write buffer line, data valid status, downstream read position, write data to be sent, write response status, and sending status table are all understood in accordance with the technical solutions described in the protection scope text and application documents.

[0021] Among them, write occupancy status refers to the state of whether the cache line is used for write caching, temporary write cache line refers to the cache line selected from the read cache or prefetch cache SRAM and temporarily used to store write data, downstream read position refers to the earliest position that has been written but not yet sent, determined according to the writing order in the line, read allow flag refers to the flag indicating that there is currently a data position available for downstream reading, and read wait flag refers to the flag indicating that there is currently no data position that meets the downstream reading conditions.

[0022] The following implementation methods refer to Figures 1 to 5 All of these are newly added figures, used to illustrate the logical relationships of the main process, address order generation, cache line reuse allocation, effective status and sending progress coordination, and write response release.

[0023] Example 1, please refer to Figures 1 to 5 This embodiment provides a design method for a write cache of an automotive-grade MCU eFlash controller based on cache reuse, with non-wrap-around continuous write as the main focus. This method is executed by the eFlash controller upon receiving a full-line fast write request. In an application scenario where the automotive-grade MCU operates at a frequency of 300MHz and the internal high-speed bus bandwidth is 64 bits (8 bytes), idle candidate cache lines in the read cache or prefetch cache SRAM are switched to temporary write cache lines. This allows continuous write data to first enter the reused cache space, and then be sent to the eFlash device according to the in-line write order and downstream transmission progress. Finally, the positions where transmission has been completed are released based on the write response status.

[0024] S1: Obtain the write operation type, starting write address, write data width, and number of consecutive writes from the entire row fast write request. Assuming the current flash row capacity is 512 bits (64 bytes), the write data width is 64 bits (8 bytes), and the number of consecutive writes is 8, determine the row starting address and the writing order within the row based on the offset of the starting write address relative to the flash row boundary, combined with the write operation type, write data width, and number of consecutive writes.

[0025] Before S1 is executed, the eFlash controller is in a state capable of receiving full-line fast write requests. Upon receiving a full-line fast write request, the eFlash controller extracts the write operation type, starting write address, write data width, and number of consecutive writes from the request. The write operation type distinguishes whether the consecutive write data within the same flash row is directly arranged in an ascending address order; the starting write address determines the starting position of the write within the flash row; the write data width determines the in-row storage range occupied by each consecutive write data; and the number of consecutive writes determines the number of consecutive data frames to be written in this full-line fast write request.

[0026] S111: Obtain the starting write address from the entire fast write request, and perform boundary alignment processing on the starting write address according to the flash row capacity. Determine the row boundary address that is not greater than the starting write address and falls within the same flash row, and determine the row boundary address as the row start address. For example, when the received starting write address is 0x0800_1018, the eFlash controller performs a 64-byte boundary alignment mask operation on it, and the resulting row start address is 0x0800_1000. This processing ensures that the address labels, in-row position mappings, and device write addresses of subsequent candidate cache rows are all based on the same flash row, avoiding the mixing of address states between different flash rows.

[0027] S112, the in-line offset is determined based on the address difference between the starting write address and the row start address, and then converted into the in-line start position according to the write data width. Continuing the previous example, the address difference between the starting write address 0x0800_1018 and the row start address 0x0800_1000 is 0x18 (i.e., 24 bytes in decimal). Converted according to an 8-byte write data width, the in-line start position of the first write is calculated to be the 3rd data clock cycle (24 / 8=3). The in-line offset represents the in-line distance of this write relative to the row start address, and the in-line start position represents the write position corresponding to the first consecutive write data within the temporary write cache line. The write data width participates in the conversion from the in-line offset to the in-line start position, ensuring that the write position aligns with the storage boundary corresponding to the data width.

[0028] S113, when the write operation type is non-wrap-around continuous write, the eFlash controller sequentially determines multiple in-line write positions from the beginning of the row in the address increment direction, and outputs a sequential write sequence before the multiple in-line write positions reach the end of the flash row. This sequential write sequence corresponds to the arrival order of the continuous write data, and each subsequent continuous write data can be mapped to an in-line write position in the sequential write sequence through its write data sequence number.

[0029] S2, based on the row start address, reads the read access occupancy status and write occupancy status of candidate cache lines in the read cache or prefetch cache SRAM of the eFlash controller, determines the candidate cache lines with both states being idle as temporary write cache lines, switches the temporary write cache lines to write cache use and marks them as write occupancy status.

[0030] The input to S2 is the row start address determined by S1. The eFlash controller generates a cache line index and an address tag based on the row start address. The cache line index is used to locate candidate cache lines in the read cache or prefetch cache SRAM, and the address tag is used to compare with the row address tag of the candidate cache line. Assuming the eFlash controller is configured with 4KB of prefetch SRAM (physically containing 64 cache lines of 64 bytes each), candidate cache lines can come from either the read cache SRAM or the prefetch cache SRAM. However, before being identified as a temporary write cache line, both the read access state and the write access state must be idle simultaneously to avoid duplicate occupation of cache lines currently being accessed by the server or used as write cache. To evaluate the degree of interference of this cache reuse strategy on system read performance, an existing shared cache interference miss rate formula (based on the Thiebaut-Stone approximation model) is introduced: ; in, The equivalent miss rate after the reuse mechanism is introduced; This represents the base miss rate under the original read access (typically 0.05 under standard automotive conditions). This is the total number of cache lines in SRAM (64 in this example). This refers to the number of SRAM rows temporarily used for concurrent writes (in extreme write scenarios, the instantaneous peak usage is typically 1 to 2 rows). As the formula shows, due to... much smaller The increase in miss rate brought about by reuse is negligible (less than 0.032), thus verifying the stability guarantee of read performance by the reuse scheme using existing formulas without increasing the dedicated write SRAM hardware area.

[0031] S211: Using the cache line index, read the read access occupancy status, write occupancy status, and cache usage identifier of the candidate cache line in the status storage area of ​​the read cache or prefetch cache SRAM. Compare the address label with the line address label of the candidate cache line to obtain the candidate matching status. The candidate matching status indicates whether the candidate cache line is allowed to be reused by the current full-line fast write request. The read access occupancy status indicates whether the candidate cache line is occupied by read access. The write occupancy status indicates whether the candidate cache line is already being used for write caching. The cache usage identifier is used to distinguish whether the cache line is currently being used as a read cache, prefetch cache, or write cache.

[0032] In step S212, when the candidate matching state is enabled for reuse, the read access occupancy state is idle, and the write occupancy state is idle, the eFlash controller generates a state lock request for the candidate cache line. The state lock request establishes a mutual exclusion boundary for state updates before cache line usage switching, ensuring that the candidate cache line is not occupied by other read accesses or write cache allocation processes between state reads and state writes. At a 300MHz clock frequency, the hardware response time for this state lock is typically strictly controlled within 1 to 2 clock cycles (approximately 3.3ns to 6.6ns).

[0033] S213, upon receiving a response to the status lock request, the eFlash controller rereads the read access occupancy status and write occupancy status. If the reread result is still idle, a write occupancy flag is written, and an address association is established between the temporary write cache line and its starting address. Simultaneously, the cache usage identifier is updated to the write cache identifier. If any occupancy status in the reread result is occupied, the status lock request is canceled, and the occupancy status of the next candidate cache line is read according to the preset candidate line order. The reallocation result is output. The reallocation result indicates that the current candidate cache line was not successfully occupied, and subsequent candidate cache lines continue to participate in the allocation.

[0034] S3 writes consecutive write data to the corresponding positions in the temporary write cache line in the order of in-line writing, and records the validity status of the data at the corresponding positions.

[0035] The inputs to S3 include the in-row write order, write data width, and number of consecutive writes generated by S1, as well as the temporary write buffer line determined by S2. After the temporary write buffer line is in a write-occupied state, the eFlash controller allows consecutive write data to enter the temporary write buffer line in the order the write requests arrive. After each consecutive write data entry, the data validity status of the corresponding position is set to valid. The data validity status is the basis for subsequently determining the downstream read positions. In-row positions that have not been written to remain invalid, and positions that have been sent and received a matching write response are no longer considered read positions after being released.

[0036] S311: Obtain the write data sequence number corresponding to the number of consecutive writes, and map the write data sequence numbers sequentially to the in-line write positions in the in-line write order. The write data sequence number indicates the arrival order of consecutive write data in this whole-line fast write request, and the in-line write position indicates the target position of the consecutive write data within the temporary write buffer line. Through the mapping between the write data sequence number and the in-line write position, the write order and the subsequent sending order can maintain the same order basis.

[0037] S312: Based on the write data width, determine the corresponding byte write enable range within the temporary write buffer line and generate position write control information. The position write control information corresponds to at least one write position within the line, the data sequence number associated with that position, and the byte write enable range matching the write data width. The eFlash controller writes consecutive write data to the corresponding storage location within the temporary write buffer line according to the position write control information, ensuring that consecutive write data does not overwrite data areas within the same buffer line that do not belong to the current write operation.

[0038] S313: After each consecutive write operation is completed, the data validity status of the corresponding storage location is updated to valid, generating a cache line validity bitmap. The cache line validity bitmap uses the in-line write positions within the temporary write cache line as its object, recording whether each position already contains write data that can be read downstream. For example, during the complete reception of 8 write operations, an 8-bit cache line validity bitmap register will be updated sequentially from the initial 0b00000000 to 0b11111111. The observable result upon completion of the write operation is: the corresponding in-line write position stores consecutive write data, and the data validity status at that position is valid.

[0039] S4. Based on the in-line writing order, the number of entries written to the cache, and the number of entries sent to the eFlash device, determine the earliest position that has been written but not yet sent as the downstream position to be read.

[0040] The inputs to S4 include the in-line write order, the number of data entries written to the buffer, the number of data entries sent to the eFlash device, and the buffer line validity bitmap. The number of data entries written to the buffer indicates the number of consecutive write data entries that have entered the temporary write buffer line, and the number of data entries sent to the eFlash device indicates the number of data entries that have been sent from the temporary write buffer line to the eFlash device and entered the transmission progress statistics. The eFlash controller does not determine the downstream read position based solely on address size, but rather uses the in-line write order as the main criterion, combined with the data validity status, to determine whether the position is ready for transmission.

[0041] S411 determines the transmission progress position in the in-line write order based on the number of data sent to the eFlash device, and identifies the first in-line write position after the transmission progress position that is valid as the downstream read position. The transmission progress position is used to define the boundary of the in-line write positions that have entered the downstream transmission path, and the first valid position after the transmission progress position is the earliest position that has been written but not yet transmitted.

[0042] S412: When the number of writes to the buffer is greater than the number of writes sent to the eFlash device and the data validity status of the downstream read position is valid, a read-allowed flag is output. After the read-allowed flag is output, the corresponding buffered data in the temporary write buffer line can be read and form the write data to be sent. When the number of writes to the buffer is equal to the number of writes sent to the eFlash device, a read-wait flag is output, indicating that there is currently no data position that has been written but not sent available for downstream reading. In the asynchronous flow control pipeline formed by high-speed writing on the system bus and relatively slow programming actions of the back-end eFlash, the existing finite-capacity queue blocking probability formula (M / M / 1 / K queuing model) can be introduced to quantify the pipeline pause characteristics here: ; in, This is the theoretical probability that a temporary write cache line will generate a read wait flag (i.e., a pipeline blockage state) due to the exhaustion of all ready data or the cache being full. The ratio of the average arrival rate of continuous data writes to the downstream eFlash device programming rate (in automotive-grade burst writes, the front-end arrival rate can reach several GB / s, while the eFlash device's programming bandwidth is typically in the tens of MB / s range, therefore...). (usually greater than 1) The maximum number of buffer cycles that can be provided for a temporary write cache line (such as 8 cycles in this embodiment). This existing formula rigorously supports the fact that by multiplexing SRAM cache lines to a depth of... The write buffer queue can exponentially reduce the extremely high blocking probability under the unbuffered architecture and absorb the transient bus pressure brought by the fast write requests of the whole line.

[0043] S413: Establish a sequential mapping relationship between the write pen sequence number and the write position within the row according to the writing order. Determine the next write pen sequence number corresponding to the number of writes already sent to the eFlash device as the candidate read pen sequence number. Read the candidate position within the row corresponding to the candidate read pen sequence number according to the sequential mapping relationship. If the data validity status of the candidate position within the row is valid, then the candidate position within the row is determined as the downstream read position; if the data validity status of the candidate position within the row is invalid, maintain the read-wait flag and latch the candidate read pen sequence number. After latching the candidate read pen sequence number, when a subsequent write action makes the candidate position within the row valid, the eFlash controller can continue to recover the downstream read judgment from that position.

[0044] S5 reads the write data to be sent from the downstream read position and sends it to the eFlash device. It releases the corresponding position according to the write response status and clears the write occupancy status when the condition for the entire line is met, so that the temporary write cache line can re-participate in the read cache or write cache allocation.

[0045] The input to S5 is the downstream read position and read permission flag determined by S4. The eFlash controller reads the data validity status corresponding to the downstream read position and the cached data in the temporary write buffer line. When the data validity status is valid, a device write address is generated based on the line start address and the downstream read position, and the cached data is associated with the device write address to form the write data to be sent. After the write data to be sent is formed, the eFlash controller sends it to the eFlash device, enabling the eFlash device to receive this write data according to the corresponding device write address. Under typical automotive-grade 28nm or 40nm eFlash process parameters, the physical time taken for the device to complete one line reception and programming state machine processing is typically between 20μs and 30μs.

[0046] In S511, when sending data to be transmitted, the eFlash controller establishes a response association record between the transmission sequence number, the device write address, and the downstream read location, and writes the response association record to the transmission status table. To avoid out-of-order data transmission, the transmission status table typically has 4 to 8 sets of hardware trace entries (Tag IDs). The transmission status table is used to confirm the cache line position corresponding to the write response status when the downstream write response returns, ensuring that the release action does not apply to locations that have not received a matching response.

[0047] S512, obtain the write response status returned by the eFlash device. In this embodiment, the write response status carries address return information, and the eFlash controller queries the transmission status table based on the address return information. When the query result matches the device write address in the response association record, the downstream read position is determined as the response release position. If the query result cannot match the response association record in the transmission status table, the write response status does not trigger the release of the corresponding position, and the temporary write buffer line still maintains the data validity state of the corresponding position, waiting for a subsequent matching write response status.

[0048] In step S513, upon receiving a write response status matching the device's write address, the valid status of the data corresponding to the downstream read position is released, and the number of data entries sent to the eFlash device is updated. The released in-line write position is no longer identified as a downstream read position. After the number of data entries sent to the eFlash device is updated, step S4 continues to search for the next written but not yet sent position based on the new transmission progress position. When all in-line write positions corresponding to the consecutive write count have completed writing, transmission, and release according to the write response status, the eFlash controller determines that the entire row completion condition is met, clears the write occupancy status of the temporary write buffer line, and allows the buffer line to re-participate in read or write buffer allocation.

[0049] Through the above execution process, free cache lines in the read cache or prefetch cache SRAM are temporarily switched to write cache usage during the write process. Continuous data writing is confirmed to be complete by the data validity status, the downstream transmission progress is constrained by the number of data sent to the eFlash device, and the correspondence between the write response status and the release position is confirmed by the transmission status table. The verifiable states of this process include the write occupancy status of the temporary write cache line, the cache usage identifier, the cache line validity bitmap, the read-allowed identifier, the read-wait identifier, the transmission status table record, and the write occupancy status clearing result after the entire line completion condition is met.

[0050] Example 2, please refer to Figure 1 , Figure 2 , Figure 4 and Figure 5 This embodiment provides a design method for a write cache of an automotive-grade MCU eFlash controller based on cache reuse. The difference between this embodiment and Embodiment 1 is that this embodiment focuses on continuous wraparound writes, and when the write response status carries sequence number return information, the eFlash controller queries the sending status table based on the sequence number return information; the remaining basic processing chain, such as cache line reuse, data validity status recording, downstream read position determination, and release after the entire line is completed, corresponds to Embodiment 1.

[0051] S1: Obtain the write operation type, starting write address, write data width, and number of consecutive writes from the entire row fast write request. Based on the offset of the starting write address relative to the flash row boundary, combined with the write operation type, write data width, and number of consecutive writes, determine the row start address and the writing order within the row.

[0052] S121: Obtain the starting write address from the entire fast write request, and perform boundary alignment processing on the starting write address according to the flash row capacity. Determine the row boundary address that is not greater than the starting write address and falls within the same flash row, and determine the row boundary address as the row start address. This row start address serves as the unified address reference for this wraparound continuous write in the temporary write cache row.

[0053] S122: The in-line offset is determined based on the address difference between the start write address and the row start address, and the in-line offset is converted into the in-line start position according to the write data width. The in-line start position is used to determine the initial write position of the first consecutive write data of the wraparound continuous write within the same flash row.

[0054] S123, when the write operation type is wraparound continuous write, the eFlash controller determines the first position sequence to the end of the flash line according to the address increment direction, and continues to determine the second position sequence from the beginning of the flash line. The first position sequence and the second position sequence are associated according to the arrival order of the write request to generate the wraparound write sequence. For example, in an application where the kernel performs a cache line write-back and triggers wraparound addressing, assuming the write request corresponds to a 64-byte flash line with a write width of 8 bytes, totaling 8 clock cycles, if the write starts from the 5th clock cycle offset within the line (i.e., address plus 40-byte offset), the first position sequence is clock cycles 5, 6, and 7, and then the write goes out of bounds and wraps back to form the second position sequence, which is clock cycles 0, 1, 2, 3, and 4. The first position sequence and the second position sequence belong to the intra-line write order of the same whole-line fast write request. They are not two independent write requests, but rather a wraparound write path (i.e., a continuous mapping sequence of 5-6-7-0-1-2-3-4) formed within the same flash line according to the arrival order of the write requests.

[0055] S2, based on the row start address, reads the read access occupancy status and write occupancy status of candidate cache lines in the read cache or prefetch cache SRAM of the eFlash controller, determines the candidate cache lines with both states being idle as temporary write cache lines, switches the temporary write cache lines to write cache use and marks them as write occupancy status.

[0056] In S2, the eFlash controller still generates cache line indexes and address tags based on the row start address, and reads the read access occupancy status, write occupancy status, cache usage identifier, and row address tag of candidate cache lines from the status storage area of ​​the read cache or prefetch cache SRAM. When the candidate matching status is "allowed for reuse" and both occupancy statuses are "idle," the eFlash controller confirms that the candidate cache line is still idle through a status lock request and a reread, then writes a write occupancy flag and establishes an address association between the temporary write cache line and the row start address. If the reread result shows that either occupancy status is occupied, the status lock request for the current candidate cache line is canceled, and the occupancy status of the next candidate cache line is obtained according to the preset candidate line order.

[0057] S3 writes consecutive write data to the corresponding positions in the temporary write cache line in the order of in-line writing, and records the validity status of the data at the corresponding positions.

[0058] In S3, the wraparound write sequence serves as the basis for the order of write data tick number mapping. The eFlash controller first maps the write data tick number to the in-line write position in the first position sequence; after the corresponding position in the first position sequence is mapped, it maps the subsequent write data tick numbers to the in-line write positions in the second position sequence. Each consecutive write data is written to the temporary write buffer line according to its write data tick number and the corresponding in-line write position in the wraparound write sequence, and the byte write enable range is determined according to the write data width. After each consecutive write data is completed, the data validity status of its corresponding in-line write position is updated to valid and enters the buffer line validity bitmap.

[0059] S4. Based on the in-line writing order, the number of entries written to the cache, and the number of entries sent to the eFlash device, determine the earliest position that has been written but not yet sent as the downstream position to be read.

[0060] In S4, the eFlash controller establishes a sequential mapping between write pen numbers and in-row write positions according to the wraparound write sequence. The next write pen number corresponding to the number of writes already sent to the eFlash device is determined as a candidate read pen number. The candidate in-row position corresponding to the candidate read pen number can be located in either the first position sequence or the second position sequence. If the data validity status of the candidate in-row position is valid, then the candidate in-row position is determined as the downstream read position; if the data validity status of the candidate in-row position is invalid, the read wait flag is maintained and the candidate read pen number is latched. This latching state ensures that if the write operation at the wraparound position is not yet completed, the downstream transmission will not skip this position to read subsequent positions.

[0061] S5 reads the write data to be sent from the downstream read position and sends it to the eFlash device. It releases the corresponding position according to the write response status and clears the write occupancy status when the condition for the entire line is met, so that the temporary write cache line can re-participate in the read cache or write cache allocation.

[0062] In S5, the eFlash controller reads the data validity status corresponding to the downstream read position and the cached data in the temporary write buffer line. When the data validity status is valid, a device write address is generated based on the line start address and the downstream read position, and the cached data is associated with the device write address to form the write data to be sent. When sending the write data to be sent, the eFlash controller establishes a response association record between the transmission sequence number, the device write address, and the downstream read position, and writes it to the transmission status table. In this embodiment, the write response status carries sequence number return information, and the eFlash controller queries the transmission status table based on the sequence number return information. When the query result matches the transmission sequence number in the response association record, the downstream read position corresponding to the record is determined as the response release position, the data validity status of the corresponding position is released, and the number of data sent to the eFlash device is updated. Thanks to the pipelined confirmation mechanism based on the transmission sequence number, the controller can concurrently process back-to-back cross-boundary data at the end of the first position sequence and the beginning of the second position sequence, thereby reducing the bus dead time during wraparound switching to 0 clock cycles. If the sequence number returned does not match the response associated record in the sending status table, the corresponding position will not be released, and the valid status of that position or the sending status table record will continue to be maintained to wait for a subsequent matching response.

[0063] Once all in-line write positions in the wraparound write sequence have completed writing, sending, and response release, the entire line completion condition is met. The eFlash controller clears the write occupancy status of the temporary write buffer line, so that the buffer line no longer retains its write buffer purpose and re-participates in read buffer or write buffer allocation. Thus, although the first and second position sequences in the wraparound continuous write scenario change from the end of the flash line to the beginning of the flash line in terms of row address, they still maintain the same write request arrival order in the write data sequence number, in-line write order, downstream read position, and send status table, ensuring a traceable correspondence between the send release process and the write order.

[0064] In the above embodiments, the source of temporary write cache lines is limited to candidate cache lines in the read cache or prefetch cache SRAM where both read access and write access states are idle; the data valid state is limited to the valid state generated after continuous write data is written to the corresponding storage location; the downstream read position is limited to the earliest position that has been written but not sent; the release function of the write response state is limited to the position corresponding to the response associated record that matches the device write address or send sequence number. The process sequence, state update, data item name, response matching method, and cache release condition involved in the embodiments are used to explain the possible implementations of the present invention and should not limit the present invention to the specific descriptions above. Without departing from the scope of the technical solutions described in the present invention, any equivalent substitutions, equivalent modifications, equivalent combinations, order adjustments, equivalent transformations of field names, equivalent inheritance of execution subjects, or equivalent changes in carrier forms that can be conceived by those skilled in the art should fall within the scope of protection of this patent; however, the substantive correspondence between technical objects should not be changed by changing the figure number, step number, or state name.

Claims

1. A design method for write cache of automotive-grade MCU eFlash controller based on cache reuse, characterized in that, include: Obtain the write operation type, starting write address, write data width, and number of consecutive writes from the entire row fast write request. Based on the offset of the starting write address relative to the flash row boundary, and in combination with the write operation type, the write data width, and the number of consecutive writes, determine the row start address and the writing order within the row. Based on the row start address, the read access occupancy status and write occupancy status of the candidate cache line are read from the read cache or prefetch cache SRAM of the eFlash controller. The candidate cache line that is idle in both states is determined as a temporary write cache line, and the temporary write cache line is switched to write cache use and marked as the write occupancy status. Write consecutive data into the corresponding positions of the temporary write cache lines in the in-line writing order, and record the data validity status of the corresponding positions; Based on the in-row writing order, the number of entries written to the cache, and the number of entries sent to the eFlash device, the earliest position that has been written but not yet sent is determined as the downstream position to be read. Read the write data to be sent from the downstream read position and send it to the eFlash device. Release the corresponding position according to the write response status and clear the write occupancy status when the condition for the entire line is met, so that the temporary write cache line can re-participate in the read cache or write cache allocation.

2. The method according to claim 1, characterized in that, The steps for determining the starting address of the line and the writing order within the line include: Obtain the starting write address in the entire row fast write request, and perform boundary alignment processing on the starting write address according to the flash row capacity. Determine the row boundary address that is not greater than the starting write address and falls into the same flash row, and determine the row boundary address as the row start address. The in-line offset is determined based on the address difference between the starting write address and the starting address of the row. The in-line offset is converted into an in-line starting position according to the write data width. Multiple in-line write positions are determined from the in-line starting position according to the number of consecutive writes, and the in-line write order is generated.

3. The method according to claim 2, characterized in that, The process of generating the in-line write order includes: When the write operation type is non-wrap-around continuous write, the multiple in-row write positions are determined sequentially from the starting position of the row in the address increment direction, and a sequential write sequence is output before the multiple in-row write positions reach the end of the flash row. When the write operation type is wraparound continuous write, the first position sequence to the end of the flash row is determined according to the address increment direction, and the second position sequence is determined from the beginning of the flash row. The first position sequence and the second position sequence are associated according to the order of arrival of the write request to generate the wraparound write sequence.

4. The method according to claim 1, characterized in that, The steps for determining the temporary write cache line include: A cache line index and address tag are generated based on the row start address. The cache line index is used to read the read access occupancy status, write occupancy status and cache usage identifier of the candidate cache line in the state storage area of ​​the read cache or the prefetch cache SRAM. The address tag is then compared with the row address tag of the candidate cache line to obtain the candidate matching status. When the candidate matching status is allowed to be reused, the read access occupancy status is idle, and the write occupancy status is idle, the candidate cache line is determined as the temporary write cache line, the cache usage identifier is updated to the write cache identifier, and the write occupancy status is updated to the occupancy status.

5. The method according to claim 4, characterized in that, The process of updating the write occupancy status includes: After reading the read access occupancy status and the write occupancy status, a status lock request is generated for the candidate cache line. When the status lock request receives a response, the read access occupancy status and the write occupancy status are read again. If the result of the reread is still that the cache is free, a write occupancy flag is written and an address association relationship is established between the temporary write cache line and the starting address of the line. If any of the occupancy statuses in the reread results is occupied, then the status locking request is cancelled, and the occupancy status of the next candidate cache line is read according to the preset candidate line order, and the reallocation result is output.

6. The method according to claim 1, characterized in that, The steps of writing the continuous write data to the temporary write cache line and recording the data validity status at the corresponding position include: Obtain the write data sequence number corresponding to the number of consecutive writes, map the write data sequence number to the in-line write position in the in-line write order, determine the byte write enable range corresponding to the in-line temporary write cache based on the write data width, and generate position write control information. The continuous write data is written to the corresponding storage location of the temporary write cache line according to the location write control information, and after each continuous write data is written, the data validity status of the corresponding storage location is updated to a valid status, generating a cache line valid bitmap.

7. The method according to claim 1, characterized in that, The steps for determining the downstream location to be read include: The following steps are taken: the in-line write order, the number of written buffer entries, the number of entries sent to the eFlash device, and the data validity status corresponding to the temporary write buffer line. Based on the number of entries sent to the eFlash device, the sending progress position is determined in the in-line write order. The first in-line write position that is located after the sending progress position and whose data validity status is valid is determined as the downstream read position. When the number of written buffer entries is greater than the number of entries sent to the eFlash device and the data validity status corresponding to the downstream read position is valid, a read-allowed flag is output; when the number of written buffer entries is equal to the number of entries sent to the eFlash device, a read-wait flag is output.

8. The method according to claim 7, characterized in that, The process of determining the sending progress position includes: Establish an order mapping relationship between the pen number and the pen position in the row according to the in-row writing order, and determine the next pen number corresponding to the number of pens sent to the eFlash device as the candidate pen number to be read. Read the candidate in-row position corresponding to the candidate pen number to be read according to the order mapping relationship. If the data at the candidate row position is valid, then the candidate row position is determined as the downstream position to be read. If the data at the candidate row position is invalid, then the waiting flag is maintained and the candidate pen number to be read is latched.

9. The method according to claim 1, characterized in that, The steps of reading the write data to be sent from the downstream read position and releasing the corresponding position include: Read the data validity status corresponding to the downstream read position and the cached data in the temporary write cache line. When the data validity status is valid, generate the device write address according to the line start address and the downstream read position, and associate the cached data with the device write address to form the write data to be sent. The data to be written is sent to the eFlash device, and when a write response state matching the write address of the device is received, the data validity state corresponding to the downstream read position is released, and the number of data sent to the eFlash device is updated.

10. The method according to claim 9, characterized in that, The process of receiving the write response status that matches the write address of the device includes: When sending the write data to be sent, a response association record is established between the sending sequence number, the device write address and the downstream read position, and the response association record is written into the sending status table; Obtain the write response status returned by the eFlash device, query the sending status table based on the address return information or sequence number return information carried by the write response status, and when the query result is consistent with the response associated record, determine the downstream read position as the response release position.