mirror of
https://github.com/eclipse-threadx/levelx.git
synced 2026-09-14 20:48:51 +08:00
Fixed NOR extended cache zero base handling
Co-authored-by: Codex <codex@openai.com>
This commit is contained in:
co-authored by
Codex
parent
3729d2f2c2
commit
6122a080be
@@ -9,6 +9,8 @@
|
||||
* SPDX-License-Identifier: MIT
|
||||
**************************************************************************/
|
||||
|
||||
// Some portions generated by Codex (GPT-5).
|
||||
|
||||
|
||||
/**************************************************************************/
|
||||
/**************************************************************************/
|
||||
@@ -77,8 +79,10 @@ UINT _lx_nor_flash_driver_write(LX_NOR_FLASH *nor_flash, ULONG *flash_address,
|
||||
UINT status;
|
||||
UINT i;
|
||||
ULONG *cache_entry_start;
|
||||
ULONG *cache_entry_end;
|
||||
ULONG cache_entry_start_value;
|
||||
ULONG cache_entry_end_value;
|
||||
ULONG cache_offset;
|
||||
ULONG flash_address_value;
|
||||
|
||||
|
||||
/* Is the request a whole sector or a partial sector. */
|
||||
@@ -87,6 +91,11 @@ ULONG cache_offset;
|
||||
|
||||
/* One word request, which implies that it is a NOR flash metadata write. */
|
||||
|
||||
/* MISRA C:2012 Rule 11.4 deviation: NOR driver addresses may be logical
|
||||
address tokens, including zero, so compare address values without
|
||||
dereferencing them. */
|
||||
flash_address_value = (ULONG)flash_address;
|
||||
|
||||
/* Loop through the cache entries to see if there is a sector in cache. */
|
||||
for (i = 0; i < nor_flash -> lx_nor_flash_extended_cache_entries; i++)
|
||||
{
|
||||
@@ -95,22 +104,27 @@ ULONG cache_offset;
|
||||
|
||||
/* Determine the cache entry addresses. */
|
||||
cache_entry_start = nor_flash -> lx_nor_flash_extended_cache[i].lx_nor_flash_extended_cache_entry_sector_address;
|
||||
cache_entry_end = cache_entry_start + LX_NOR_SECTOR_SIZE;
|
||||
|
||||
/* Determine if the flash address in in the cache entry. */
|
||||
if ((cache_entry_start) && (flash_address >= cache_entry_start) && (flash_address < cache_entry_end))
|
||||
/* Determine if the flash address is in the cache entry. */
|
||||
if (nor_flash -> lx_nor_flash_extended_cache[i].lx_nor_flash_extended_cache_entry_valid)
|
||||
{
|
||||
cache_entry_start_value = (ULONG)cache_entry_start;
|
||||
cache_entry_end_value = cache_entry_start_value + (LX_NOR_SECTOR_SIZE * sizeof(ULONG));
|
||||
|
||||
/* Yes, we found the entry. */
|
||||
if ((flash_address_value >= cache_entry_start_value) && (flash_address_value < cache_entry_end_value))
|
||||
{
|
||||
|
||||
/* Calculate the offset into the cache entry. */
|
||||
cache_offset = (ULONG)(flash_address - cache_entry_start);
|
||||
/* Yes, we found the entry. */
|
||||
|
||||
/* Copy the word into the cache. */
|
||||
*(nor_flash -> lx_nor_flash_extended_cache[i].lx_nor_flash_extended_cache_entry_sector_memory + cache_offset) = *source;
|
||||
/* Calculate the offset into the cache entry. */
|
||||
cache_offset = (flash_address_value - cache_entry_start_value) / sizeof(ULONG);
|
||||
|
||||
/* Get out of the loop. */
|
||||
break;
|
||||
/* Copy the word into the cache. */
|
||||
*(nor_flash -> lx_nor_flash_extended_cache[i].lx_nor_flash_extended_cache_entry_sector_memory + cache_offset) = *source;
|
||||
|
||||
/* Get out of the loop. */
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -140,4 +154,3 @@ UINT status;
|
||||
return(status);
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user