mirror of
https://github.com/eclipse-threadx/levelx.git
synced 2026-09-14 04:06:00 +08:00
Merge pull request #79 from fdesbiens/fix-nor-zero-base-extended-cache
Fixed NOR extended cache zero base handling
This commit is contained in:
+3
-1
@@ -10,6 +10,8 @@
|
|||||||
* SPDX-License-Identifier: MIT
|
* SPDX-License-Identifier: MIT
|
||||||
**************************************************************************/
|
**************************************************************************/
|
||||||
|
|
||||||
|
// Some portions generated by Codex (GPT-5).
|
||||||
|
|
||||||
|
|
||||||
/**************************************************************************/
|
/**************************************************************************/
|
||||||
/**************************************************************************/
|
/**************************************************************************/
|
||||||
@@ -537,6 +539,7 @@ typedef struct LX_NOR_FLASH_EXTENDED_CACHE_ENTRY_STRUCT
|
|||||||
ULONG *lx_nor_flash_extended_cache_entry_sector_address;
|
ULONG *lx_nor_flash_extended_cache_entry_sector_address;
|
||||||
ULONG *lx_nor_flash_extended_cache_entry_sector_memory;
|
ULONG *lx_nor_flash_extended_cache_entry_sector_memory;
|
||||||
ULONG lx_nor_flash_extended_cache_entry_access_count;
|
ULONG lx_nor_flash_extended_cache_entry_access_count;
|
||||||
|
UINT lx_nor_flash_extended_cache_entry_valid;
|
||||||
} LX_NOR_FLASH_EXTENDED_CACHE_ENTRY;
|
} LX_NOR_FLASH_EXTENDED_CACHE_ENTRY;
|
||||||
|
|
||||||
|
|
||||||
@@ -814,4 +817,3 @@ VOID _lx_nor_flash_system_error(LX_NOR_FLASH *nor_flash, UINT error_code);
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|||||||
@@ -9,6 +9,8 @@
|
|||||||
* SPDX-License-Identifier: MIT
|
* SPDX-License-Identifier: MIT
|
||||||
**************************************************************************/
|
**************************************************************************/
|
||||||
|
|
||||||
|
// Some portions generated by Codex (GPT-5).
|
||||||
|
|
||||||
|
|
||||||
/**************************************************************************/
|
/**************************************************************************/
|
||||||
/**************************************************************************/
|
/**************************************************************************/
|
||||||
@@ -76,15 +78,19 @@ UINT status;
|
|||||||
#ifndef LX_NOR_DISABLE_EXTENDED_CACHE
|
#ifndef LX_NOR_DISABLE_EXTENDED_CACHE
|
||||||
|
|
||||||
UINT i;
|
UINT i;
|
||||||
ULONG *block_start_address;
|
ULONG block_start_address;
|
||||||
ULONG *block_end_address;
|
ULONG block_end_address;
|
||||||
ULONG *cache_entry_start;
|
ULONG *cache_entry_start;
|
||||||
ULONG *cache_entry_end;
|
ULONG cache_entry_start_value;
|
||||||
|
ULONG cache_entry_end_value;
|
||||||
|
|
||||||
|
|
||||||
/* Calculate the block starting address. */
|
/* Calculate the block starting address.
|
||||||
block_start_address = nor_flash -> lx_nor_flash_base_address + (block * nor_flash -> lx_nor_flash_words_per_block);
|
MISRA C:2012 Rule 11.4 deviation: NOR driver addresses may be logical
|
||||||
block_end_address = block_start_address + nor_flash -> lx_nor_flash_words_per_block;
|
address tokens, including zero, so compare address values without
|
||||||
|
dereferencing them. */
|
||||||
|
block_start_address = (ULONG)(nor_flash -> lx_nor_flash_base_address) + (block * nor_flash -> lx_nor_flash_words_per_block * sizeof(ULONG));
|
||||||
|
block_end_address = block_start_address + (nor_flash -> lx_nor_flash_words_per_block * sizeof(ULONG));
|
||||||
|
|
||||||
/* Loop through the cache entries to see if there is a sector in cache. */
|
/* 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++)
|
for (i = 0; i < nor_flash -> lx_nor_flash_extended_cache_entries; i++)
|
||||||
@@ -94,15 +100,21 @@ ULONG *cache_entry_end;
|
|||||||
|
|
||||||
/* Determine the cache entry addresses. */
|
/* 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_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. */
|
/* Determine if the cache entry is in the block being erased. */
|
||||||
if ((cache_entry_start) && (block_start_address <= cache_entry_start) && (block_end_address > cache_entry_end))
|
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, this cache entry is in the block to be erased so invalidate it. */
|
if ((block_start_address <= cache_entry_start_value) && (block_end_address >= cache_entry_end_value))
|
||||||
nor_flash -> lx_nor_flash_extended_cache[i].lx_nor_flash_extended_cache_entry_sector_address = LX_NULL;
|
{
|
||||||
nor_flash -> lx_nor_flash_extended_cache[i].lx_nor_flash_extended_cache_entry_access_count = 0;
|
|
||||||
|
/* Yes, this cache entry is in the block to be erased so invalidate it. */
|
||||||
|
nor_flash -> lx_nor_flash_extended_cache[i].lx_nor_flash_extended_cache_entry_sector_address = LX_NULL;
|
||||||
|
nor_flash -> lx_nor_flash_extended_cache[i].lx_nor_flash_extended_cache_entry_access_count = 0;
|
||||||
|
nor_flash -> lx_nor_flash_extended_cache[i].lx_nor_flash_extended_cache_entry_valid = LX_FALSE;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
@@ -117,5 +129,3 @@ ULONG *cache_entry_end;
|
|||||||
/* Return completion status. */
|
/* Return completion status. */
|
||||||
return(status);
|
return(status);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -9,6 +9,8 @@
|
|||||||
* SPDX-License-Identifier: MIT
|
* SPDX-License-Identifier: MIT
|
||||||
**************************************************************************/
|
**************************************************************************/
|
||||||
|
|
||||||
|
// Some portions generated by Codex (GPT-5).
|
||||||
|
|
||||||
|
|
||||||
/**************************************************************************/
|
/**************************************************************************/
|
||||||
/**************************************************************************/
|
/**************************************************************************/
|
||||||
@@ -76,8 +78,11 @@ UINT _lx_nor_flash_driver_read(LX_NOR_FLASH *nor_flash, ULONG *flash_address, U
|
|||||||
UINT status;
|
UINT status;
|
||||||
UINT i;
|
UINT i;
|
||||||
ULONG *cache_entry_start;
|
ULONG *cache_entry_start;
|
||||||
ULONG *cache_entry_end;
|
ULONG cache_entry_start_value;
|
||||||
|
ULONG cache_entry_end_value;
|
||||||
ULONG cache_offset;
|
ULONG cache_offset;
|
||||||
|
ULONG flash_address_value;
|
||||||
|
ULONG base_address_value;
|
||||||
UINT least_used_cache_entry;
|
UINT least_used_cache_entry;
|
||||||
|
|
||||||
|
|
||||||
@@ -91,6 +96,11 @@ UINT least_used_cache_entry;
|
|||||||
/* Initialize the least used cache entry. */
|
/* Initialize the least used cache entry. */
|
||||||
least_used_cache_entry = 0;
|
least_used_cache_entry = 0;
|
||||||
|
|
||||||
|
/* 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;
|
||||||
|
|
||||||
do
|
do
|
||||||
{
|
{
|
||||||
|
|
||||||
@@ -102,52 +112,55 @@ UINT least_used_cache_entry;
|
|||||||
|
|
||||||
/* Determine the cache entry addresses. */
|
/* 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_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. */
|
/* Determine if the flash address is in the cache entry. */
|
||||||
if ((cache_entry_start) && (flash_address >= cache_entry_start) && (flash_address < cache_entry_end))
|
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))
|
||||||
|
|
||||||
/* Increment the accessed count. */
|
|
||||||
nor_flash -> lx_nor_flash_extended_cache[i].lx_nor_flash_extended_cache_entry_access_count++;
|
|
||||||
|
|
||||||
/* Calculate the offset into the cache entry. */
|
|
||||||
cache_offset = (ULONG)(flash_address - cache_entry_start);
|
|
||||||
|
|
||||||
/* Copy the word from the cache. */
|
|
||||||
*destination = *(nor_flash -> lx_nor_flash_extended_cache[i].lx_nor_flash_extended_cache_entry_sector_memory + cache_offset);
|
|
||||||
|
|
||||||
/* Increment the number of cache hits. */
|
|
||||||
nor_flash -> lx_nor_flash_extended_cache_hits++;
|
|
||||||
|
|
||||||
/* Return success. */
|
|
||||||
return(LX_SUCCESS);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
|
|
||||||
/* Determine if we have a new least used sector. */
|
|
||||||
if (i != least_used_cache_entry)
|
|
||||||
{
|
{
|
||||||
|
|
||||||
/* Determine if this entry has a smaller accessed count. */
|
/* Yes, we found the entry. */
|
||||||
if (nor_flash -> lx_nor_flash_extended_cache[i].lx_nor_flash_extended_cache_entry_access_count <
|
|
||||||
nor_flash -> lx_nor_flash_extended_cache[least_used_cache_entry].lx_nor_flash_extended_cache_entry_access_count)
|
|
||||||
{
|
|
||||||
|
|
||||||
/* New least used entry. */
|
/* Increment the accessed count. */
|
||||||
least_used_cache_entry = i;
|
nor_flash -> lx_nor_flash_extended_cache[i].lx_nor_flash_extended_cache_entry_access_count++;
|
||||||
}
|
|
||||||
|
/* Calculate the offset into the cache entry. */
|
||||||
|
cache_offset = (flash_address_value - cache_entry_start_value) / sizeof(ULONG);
|
||||||
|
|
||||||
|
/* Copy the word from the cache. */
|
||||||
|
*destination = *(nor_flash -> lx_nor_flash_extended_cache[i].lx_nor_flash_extended_cache_entry_sector_memory + cache_offset);
|
||||||
|
|
||||||
|
/* Increment the number of cache hits. */
|
||||||
|
nor_flash -> lx_nor_flash_extended_cache_hits++;
|
||||||
|
|
||||||
|
/* Return success. */
|
||||||
|
return(LX_SUCCESS);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Determine if we have a new least used sector. */
|
||||||
|
if (i != least_used_cache_entry)
|
||||||
|
{
|
||||||
|
|
||||||
|
/* Determine if this entry has a smaller accessed count. */
|
||||||
|
if (nor_flash -> lx_nor_flash_extended_cache[i].lx_nor_flash_extended_cache_entry_access_count <
|
||||||
|
nor_flash -> lx_nor_flash_extended_cache[least_used_cache_entry].lx_nor_flash_extended_cache_entry_access_count)
|
||||||
|
{
|
||||||
|
|
||||||
|
/* New least used entry. */
|
||||||
|
least_used_cache_entry = i;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Now read in the sector into the cache. */
|
/* Now read in the sector into the cache. */
|
||||||
cache_offset = (ULONG)(flash_address - nor_flash -> lx_nor_flash_base_address);
|
base_address_value = (ULONG)(nor_flash -> lx_nor_flash_base_address);
|
||||||
|
cache_offset = (flash_address_value - base_address_value) / sizeof(ULONG);
|
||||||
cache_offset = cache_offset & ~((ULONG) (LX_NOR_SECTOR_SIZE-1));
|
cache_offset = cache_offset & ~((ULONG) (LX_NOR_SECTOR_SIZE-1));
|
||||||
cache_entry_start = nor_flash -> lx_nor_flash_base_address + cache_offset;
|
cache_entry_start = (ULONG *)(base_address_value + (cache_offset * sizeof(ULONG)));
|
||||||
|
|
||||||
/* Call the actual driver read function. */
|
/* Call the actual driver read function. */
|
||||||
#ifdef LX_NOR_ENABLE_CONTROL_BLOCK_FOR_DRIVER_INTERFACE
|
#ifdef LX_NOR_ENABLE_CONTROL_BLOCK_FOR_DRIVER_INTERFACE
|
||||||
@@ -171,6 +184,7 @@ UINT least_used_cache_entry;
|
|||||||
/* Setup the cache entry. */
|
/* Setup the cache entry. */
|
||||||
nor_flash -> lx_nor_flash_extended_cache[least_used_cache_entry].lx_nor_flash_extended_cache_entry_sector_address = cache_entry_start;
|
nor_flash -> lx_nor_flash_extended_cache[least_used_cache_entry].lx_nor_flash_extended_cache_entry_sector_address = cache_entry_start;
|
||||||
nor_flash -> lx_nor_flash_extended_cache[least_used_cache_entry].lx_nor_flash_extended_cache_entry_access_count = 0;
|
nor_flash -> lx_nor_flash_extended_cache[least_used_cache_entry].lx_nor_flash_extended_cache_entry_access_count = 0;
|
||||||
|
nor_flash -> lx_nor_flash_extended_cache[least_used_cache_entry].lx_nor_flash_extended_cache_entry_valid = LX_TRUE;
|
||||||
|
|
||||||
/* Increment the number of cache misses. */
|
/* Increment the number of cache misses. */
|
||||||
nor_flash -> lx_nor_flash_extended_cache_misses++;
|
nor_flash -> lx_nor_flash_extended_cache_misses++;
|
||||||
@@ -211,5 +225,3 @@ UINT status;
|
|||||||
return(status);
|
return(status);
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -9,6 +9,8 @@
|
|||||||
* SPDX-License-Identifier: MIT
|
* 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 status;
|
||||||
UINT i;
|
UINT i;
|
||||||
ULONG *cache_entry_start;
|
ULONG *cache_entry_start;
|
||||||
ULONG *cache_entry_end;
|
ULONG cache_entry_start_value;
|
||||||
|
ULONG cache_entry_end_value;
|
||||||
ULONG cache_offset;
|
ULONG cache_offset;
|
||||||
|
ULONG flash_address_value;
|
||||||
|
|
||||||
|
|
||||||
/* Is the request a whole sector or a partial sector. */
|
/* 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. */
|
/* 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. */
|
/* 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++)
|
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. */
|
/* 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_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. */
|
/* Determine if the flash address is in the cache entry. */
|
||||||
if ((cache_entry_start) && (flash_address >= cache_entry_start) && (flash_address < cache_entry_end))
|
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. */
|
/* Yes, we found the entry. */
|
||||||
cache_offset = (ULONG)(flash_address - cache_entry_start);
|
|
||||||
|
|
||||||
/* Copy the word into the cache. */
|
/* Calculate the offset into the cache entry. */
|
||||||
*(nor_flash -> lx_nor_flash_extended_cache[i].lx_nor_flash_extended_cache_entry_sector_memory + cache_offset) = *source;
|
cache_offset = (flash_address_value - cache_entry_start_value) / sizeof(ULONG);
|
||||||
|
|
||||||
/* Get out of the loop. */
|
/* Copy the word into the cache. */
|
||||||
break;
|
*(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);
|
return(status);
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -278,6 +278,7 @@ ULONG block_word;
|
|||||||
nor_flash -> lx_nor_flash_extended_cache[i].lx_nor_flash_extended_cache_entry_sector_address = LX_NULL;
|
nor_flash -> lx_nor_flash_extended_cache[i].lx_nor_flash_extended_cache_entry_sector_address = LX_NULL;
|
||||||
nor_flash -> lx_nor_flash_extended_cache[i].lx_nor_flash_extended_cache_entry_sector_memory = cache_memory;
|
nor_flash -> lx_nor_flash_extended_cache[i].lx_nor_flash_extended_cache_entry_sector_memory = cache_memory;
|
||||||
nor_flash -> lx_nor_flash_extended_cache[i].lx_nor_flash_extended_cache_entry_access_count = 0;
|
nor_flash -> lx_nor_flash_extended_cache[i].lx_nor_flash_extended_cache_entry_access_count = 0;
|
||||||
|
nor_flash -> lx_nor_flash_extended_cache[i].lx_nor_flash_extended_cache_entry_valid = LX_FALSE;
|
||||||
|
|
||||||
/* Move the cache memory forward. */
|
/* Move the cache memory forward. */
|
||||||
cache_memory = cache_memory + LX_NOR_SECTOR_SIZE;
|
cache_memory = cache_memory + LX_NOR_SECTOR_SIZE;
|
||||||
|
|||||||
@@ -34,11 +34,30 @@ ULONG readbuffer[128];
|
|||||||
UCHAR nor_cache_memory[2048+16+8];
|
UCHAR nor_cache_memory[2048+16+8];
|
||||||
UCHAR nor_cache_memory2[8192];
|
UCHAR nor_cache_memory2[8192];
|
||||||
UCHAR nor_cache_memory_invalid[256];
|
UCHAR nor_cache_memory_invalid[256];
|
||||||
|
#ifndef LX_NOR_DISABLE_EXTENDED_CACHE
|
||||||
|
UCHAR nor_zero_base_cache_memory[512];
|
||||||
|
ULONG nor_zero_base_memory[LX_NOR_SECTOR_SIZE * 2];
|
||||||
|
ULONG nor_zero_base_driver_read_count;
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|
||||||
/* Define LevelX NOR flash simulator prototoypes. */
|
/* Define LevelX NOR flash simulator prototoypes. */
|
||||||
|
|
||||||
UINT _lx_nor_flash_simulator_initialize(LX_NOR_FLASH *nor_flash);
|
UINT _lx_nor_flash_simulator_initialize(LX_NOR_FLASH *nor_flash);
|
||||||
|
#ifndef LX_NOR_DISABLE_EXTENDED_CACHE
|
||||||
|
#ifdef LX_NOR_ENABLE_CONTROL_BLOCK_FOR_DRIVER_INTERFACE
|
||||||
|
static UINT zero_base_nor_read(LX_NOR_FLASH *nor_flash, ULONG *flash_address, ULONG *destination, ULONG words);
|
||||||
|
static UINT zero_base_nor_write(LX_NOR_FLASH *nor_flash, ULONG *flash_address, ULONG *source, ULONG words);
|
||||||
|
static UINT zero_base_nor_block_erase(LX_NOR_FLASH *nor_flash, ULONG block, ULONG erase_count);
|
||||||
|
static UINT zero_base_nor_block_erased_verify(LX_NOR_FLASH *nor_flash, ULONG block);
|
||||||
|
#else
|
||||||
|
static UINT zero_base_nor_read(ULONG *flash_address, ULONG *destination, ULONG words);
|
||||||
|
static UINT zero_base_nor_write(ULONG *flash_address, ULONG *source, ULONG words);
|
||||||
|
static UINT zero_base_nor_block_erase(ULONG block, ULONG erase_count);
|
||||||
|
static UINT zero_base_nor_block_erased_verify(ULONG block);
|
||||||
|
#endif
|
||||||
|
static UINT zero_base_nor_initialize(LX_NOR_FLASH *nor_flash);
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@@ -76,12 +95,177 @@ void tx_application_define(void *first_unused_memory)
|
|||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#ifndef LX_NOR_DISABLE_EXTENDED_CACHE
|
||||||
|
static UINT zero_base_nor_initialize(LX_NOR_FLASH *nor_flash)
|
||||||
|
{
|
||||||
|
|
||||||
|
UINT status;
|
||||||
|
|
||||||
|
|
||||||
|
/* Setup the base address as a logical zero offset. */
|
||||||
|
nor_flash -> lx_nor_flash_base_address = LX_NULL;
|
||||||
|
|
||||||
|
/* Setup geometry of the test flash. */
|
||||||
|
nor_flash -> lx_nor_flash_total_blocks = 1;
|
||||||
|
nor_flash -> lx_nor_flash_words_per_block = LX_NOR_SECTOR_SIZE * 2;
|
||||||
|
|
||||||
|
/* Setup function pointers for the NOR flash services. */
|
||||||
|
nor_flash -> lx_nor_flash_driver_read = zero_base_nor_read;
|
||||||
|
nor_flash -> lx_nor_flash_driver_write = zero_base_nor_write;
|
||||||
|
nor_flash -> lx_nor_flash_driver_block_erase = zero_base_nor_block_erase;
|
||||||
|
nor_flash -> lx_nor_flash_driver_block_erased_verify = zero_base_nor_block_erased_verify;
|
||||||
|
|
||||||
|
/* Setup local buffer for NOR flash operation. */
|
||||||
|
nor_flash -> lx_nor_flash_sector_buffer = buffer;
|
||||||
|
|
||||||
|
/* Erase the test flash. */
|
||||||
|
#ifdef LX_NOR_ENABLE_CONTROL_BLOCK_FOR_DRIVER_INTERFACE
|
||||||
|
status = zero_base_nor_block_erase(nor_flash, 0, 0);
|
||||||
|
#else
|
||||||
|
status = zero_base_nor_block_erase(0, 0);
|
||||||
|
#endif
|
||||||
|
|
||||||
|
/* Return completion status. */
|
||||||
|
return(status);
|
||||||
|
}
|
||||||
|
|
||||||
|
#ifdef LX_NOR_ENABLE_CONTROL_BLOCK_FOR_DRIVER_INTERFACE
|
||||||
|
static UINT zero_base_nor_read(LX_NOR_FLASH *nor_flash, ULONG *flash_address, ULONG *destination, ULONG words)
|
||||||
|
#else
|
||||||
|
static UINT zero_base_nor_read(ULONG *flash_address, ULONG *destination, ULONG words)
|
||||||
|
#endif
|
||||||
|
{
|
||||||
|
|
||||||
|
ULONG offset;
|
||||||
|
|
||||||
|
#ifdef LX_NOR_ENABLE_CONTROL_BLOCK_FOR_DRIVER_INTERFACE
|
||||||
|
LX_PARAMETER_NOT_USED(nor_flash);
|
||||||
|
#endif
|
||||||
|
|
||||||
|
/* MISRA C:2012 Rule 11.4 deviation: this test driver intentionally treats
|
||||||
|
NOR flash addresses as logical offsets, including zero. */
|
||||||
|
offset = ((ULONG)flash_address) / sizeof(ULONG);
|
||||||
|
|
||||||
|
if ((offset + words) > (LX_NOR_SECTOR_SIZE * 2))
|
||||||
|
{
|
||||||
|
return(LX_ERROR);
|
||||||
|
}
|
||||||
|
|
||||||
|
nor_zero_base_driver_read_count++;
|
||||||
|
|
||||||
|
while (words--)
|
||||||
|
{
|
||||||
|
*destination++ = nor_zero_base_memory[offset++];
|
||||||
|
}
|
||||||
|
|
||||||
|
return(LX_SUCCESS);
|
||||||
|
}
|
||||||
|
|
||||||
|
#ifdef LX_NOR_ENABLE_CONTROL_BLOCK_FOR_DRIVER_INTERFACE
|
||||||
|
static UINT zero_base_nor_write(LX_NOR_FLASH *nor_flash, ULONG *flash_address, ULONG *source, ULONG words)
|
||||||
|
#else
|
||||||
|
static UINT zero_base_nor_write(ULONG *flash_address, ULONG *source, ULONG words)
|
||||||
|
#endif
|
||||||
|
{
|
||||||
|
|
||||||
|
ULONG offset;
|
||||||
|
|
||||||
|
#ifdef LX_NOR_ENABLE_CONTROL_BLOCK_FOR_DRIVER_INTERFACE
|
||||||
|
LX_PARAMETER_NOT_USED(nor_flash);
|
||||||
|
#endif
|
||||||
|
|
||||||
|
/* MISRA C:2012 Rule 11.4 deviation: this test driver intentionally treats
|
||||||
|
NOR flash addresses as logical offsets, including zero. */
|
||||||
|
offset = ((ULONG)flash_address) / sizeof(ULONG);
|
||||||
|
|
||||||
|
if ((offset + words) > (LX_NOR_SECTOR_SIZE * 2))
|
||||||
|
{
|
||||||
|
return(LX_ERROR);
|
||||||
|
}
|
||||||
|
|
||||||
|
while (words--)
|
||||||
|
{
|
||||||
|
nor_zero_base_memory[offset++] = *source++;
|
||||||
|
}
|
||||||
|
|
||||||
|
return(LX_SUCCESS);
|
||||||
|
}
|
||||||
|
|
||||||
|
#ifdef LX_NOR_ENABLE_CONTROL_BLOCK_FOR_DRIVER_INTERFACE
|
||||||
|
static UINT zero_base_nor_block_erase(LX_NOR_FLASH *nor_flash, ULONG block, ULONG erase_count)
|
||||||
|
#else
|
||||||
|
static UINT zero_base_nor_block_erase(ULONG block, ULONG erase_count)
|
||||||
|
#endif
|
||||||
|
{
|
||||||
|
|
||||||
|
ULONG offset;
|
||||||
|
ULONG words;
|
||||||
|
|
||||||
|
#ifdef LX_NOR_ENABLE_CONTROL_BLOCK_FOR_DRIVER_INTERFACE
|
||||||
|
LX_PARAMETER_NOT_USED(nor_flash);
|
||||||
|
#endif
|
||||||
|
LX_PARAMETER_NOT_USED(erase_count);
|
||||||
|
|
||||||
|
if (block != 0)
|
||||||
|
{
|
||||||
|
return(LX_ERROR);
|
||||||
|
}
|
||||||
|
|
||||||
|
offset = 0;
|
||||||
|
words = LX_NOR_SECTOR_SIZE * 2;
|
||||||
|
|
||||||
|
while (words--)
|
||||||
|
{
|
||||||
|
nor_zero_base_memory[offset++] = LX_ALL_ONES;
|
||||||
|
}
|
||||||
|
|
||||||
|
return(LX_SUCCESS);
|
||||||
|
}
|
||||||
|
|
||||||
|
#ifdef LX_NOR_ENABLE_CONTROL_BLOCK_FOR_DRIVER_INTERFACE
|
||||||
|
static UINT zero_base_nor_block_erased_verify(LX_NOR_FLASH *nor_flash, ULONG block)
|
||||||
|
#else
|
||||||
|
static UINT zero_base_nor_block_erased_verify(ULONG block)
|
||||||
|
#endif
|
||||||
|
{
|
||||||
|
|
||||||
|
ULONG offset;
|
||||||
|
ULONG words;
|
||||||
|
|
||||||
|
#ifdef LX_NOR_ENABLE_CONTROL_BLOCK_FOR_DRIVER_INTERFACE
|
||||||
|
LX_PARAMETER_NOT_USED(nor_flash);
|
||||||
|
#endif
|
||||||
|
|
||||||
|
if (block != 0)
|
||||||
|
{
|
||||||
|
return(LX_ERROR);
|
||||||
|
}
|
||||||
|
|
||||||
|
offset = 0;
|
||||||
|
words = LX_NOR_SECTOR_SIZE * 2;
|
||||||
|
|
||||||
|
while (words--)
|
||||||
|
{
|
||||||
|
if (nor_zero_base_memory[offset++] != LX_ALL_ONES)
|
||||||
|
{
|
||||||
|
return(LX_ERROR);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return(LX_SUCCESS);
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
/* Define the test threads. */
|
/* Define the test threads. */
|
||||||
|
|
||||||
void thread_0_entry(ULONG thread_input)
|
void thread_0_entry(ULONG thread_input)
|
||||||
{
|
{
|
||||||
|
|
||||||
ULONG i, j, sector;
|
ULONG i, j, sector;
|
||||||
|
#ifndef LX_NOR_DISABLE_EXTENDED_CACHE
|
||||||
|
ULONG read_count;
|
||||||
|
ULONG *last_sector_address;
|
||||||
|
#endif
|
||||||
UINT status;
|
UINT status;
|
||||||
|
|
||||||
ULONG *word_ptr;
|
ULONG *word_ptr;
|
||||||
@@ -90,6 +274,148 @@ ULONG *word_ptr;
|
|||||||
/* Initialize LevelX. */
|
/* Initialize LevelX. */
|
||||||
_lx_nor_flash_initialize();
|
_lx_nor_flash_initialize();
|
||||||
|
|
||||||
|
#ifndef LX_NOR_DISABLE_EXTENDED_CACHE
|
||||||
|
/* Test 0: Extended cache with a zero NOR flash base address. */
|
||||||
|
printf("Test 0: Extended cache with zero base address....");
|
||||||
|
|
||||||
|
LX_MEMSET(&nor_sim_flash, 0, sizeof(nor_sim_flash));
|
||||||
|
status = zero_base_nor_initialize(&nor_sim_flash);
|
||||||
|
nor_zero_base_memory[0] = 0x12345678;
|
||||||
|
/* MISRA C:2012 Rule 11.6 deviation: this test driver intentionally
|
||||||
|
treats NOR flash addresses as logical offset tokens. */
|
||||||
|
last_sector_address = (ULONG *)(LX_NOR_SECTOR_SIZE * sizeof(ULONG));
|
||||||
|
nor_zero_base_driver_read_count = 0;
|
||||||
|
|
||||||
|
if (status == LX_SUCCESS)
|
||||||
|
{
|
||||||
|
status = lx_nor_flash_extended_cache_enable(&nor_sim_flash, nor_zero_base_cache_memory, sizeof(nor_zero_base_cache_memory));
|
||||||
|
}
|
||||||
|
|
||||||
|
if (status == LX_SUCCESS)
|
||||||
|
{
|
||||||
|
status = _lx_nor_flash_driver_read(&nor_sim_flash, LX_NULL, readbuffer, 1);
|
||||||
|
}
|
||||||
|
|
||||||
|
if ((status != LX_SUCCESS) || (readbuffer[0] != 0x12345678) || (nor_zero_base_driver_read_count != 1))
|
||||||
|
{
|
||||||
|
printf("FAILED!\n");
|
||||||
|
#ifdef BATCH_TEST
|
||||||
|
exit(1);
|
||||||
|
#endif
|
||||||
|
while(1)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
status = _lx_nor_flash_driver_read(&nor_sim_flash, LX_NULL, readbuffer, 1);
|
||||||
|
|
||||||
|
if ((status != LX_SUCCESS) || (readbuffer[0] != 0x12345678) || (nor_zero_base_driver_read_count != 1))
|
||||||
|
{
|
||||||
|
printf("FAILED!\n");
|
||||||
|
#ifdef BATCH_TEST
|
||||||
|
exit(1);
|
||||||
|
#endif
|
||||||
|
while(1)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
buffer[0] = 0x87654321;
|
||||||
|
status = _lx_nor_flash_driver_write(&nor_sim_flash, LX_NULL, buffer, 1);
|
||||||
|
|
||||||
|
if ((status != LX_SUCCESS) || (nor_zero_base_memory[0] != 0x87654321))
|
||||||
|
{
|
||||||
|
printf("FAILED!\n");
|
||||||
|
#ifdef BATCH_TEST
|
||||||
|
exit(1);
|
||||||
|
#endif
|
||||||
|
while(1)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
status = _lx_nor_flash_driver_read(&nor_sim_flash, LX_NULL, readbuffer, 1);
|
||||||
|
|
||||||
|
if ((status != LX_SUCCESS) || (readbuffer[0] != 0x87654321) || (nor_zero_base_driver_read_count != 1))
|
||||||
|
{
|
||||||
|
printf("FAILED!\n");
|
||||||
|
#ifdef BATCH_TEST
|
||||||
|
exit(1);
|
||||||
|
#endif
|
||||||
|
while(1)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
read_count = nor_zero_base_driver_read_count;
|
||||||
|
status = _lx_nor_flash_driver_block_erase(&nor_sim_flash, 0, 0);
|
||||||
|
|
||||||
|
if (status == LX_SUCCESS)
|
||||||
|
{
|
||||||
|
status = _lx_nor_flash_driver_read(&nor_sim_flash, LX_NULL, readbuffer, 1);
|
||||||
|
}
|
||||||
|
|
||||||
|
if ((status != LX_SUCCESS) || (readbuffer[0] != LX_ALL_ONES) || (nor_zero_base_driver_read_count != (read_count + 1)))
|
||||||
|
{
|
||||||
|
printf("FAILED!\n");
|
||||||
|
#ifdef BATCH_TEST
|
||||||
|
exit(1);
|
||||||
|
#endif
|
||||||
|
while(1)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
nor_zero_base_memory[LX_NOR_SECTOR_SIZE] = 0xABCDEF01;
|
||||||
|
|
||||||
|
status = _lx_nor_flash_driver_read(&nor_sim_flash, last_sector_address, readbuffer, 1);
|
||||||
|
|
||||||
|
if ((status != LX_SUCCESS) || (readbuffer[0] != 0xABCDEF01) || (nor_zero_base_driver_read_count != (read_count + 2)))
|
||||||
|
{
|
||||||
|
printf("FAILED!\n");
|
||||||
|
#ifdef BATCH_TEST
|
||||||
|
exit(1);
|
||||||
|
#endif
|
||||||
|
while(1)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
status = _lx_nor_flash_driver_read(&nor_sim_flash, last_sector_address, readbuffer, 1);
|
||||||
|
|
||||||
|
if ((status != LX_SUCCESS) || (readbuffer[0] != 0xABCDEF01) || (nor_zero_base_driver_read_count != (read_count + 2)))
|
||||||
|
{
|
||||||
|
printf("FAILED!\n");
|
||||||
|
#ifdef BATCH_TEST
|
||||||
|
exit(1);
|
||||||
|
#endif
|
||||||
|
while(1)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
read_count = nor_zero_base_driver_read_count;
|
||||||
|
status = _lx_nor_flash_driver_block_erase(&nor_sim_flash, 0, 0);
|
||||||
|
|
||||||
|
if (status == LX_SUCCESS)
|
||||||
|
{
|
||||||
|
status = _lx_nor_flash_driver_read(&nor_sim_flash, last_sector_address, readbuffer, 1);
|
||||||
|
}
|
||||||
|
|
||||||
|
if ((status != LX_SUCCESS) || (readbuffer[0] != LX_ALL_ONES) || (nor_zero_base_driver_read_count != (read_count + 1)))
|
||||||
|
{
|
||||||
|
printf("FAILED!\n");
|
||||||
|
#ifdef BATCH_TEST
|
||||||
|
exit(1);
|
||||||
|
#endif
|
||||||
|
while(1)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
printf("SUCCESS!\n");
|
||||||
|
#endif
|
||||||
|
|
||||||
/* Test 1: Simple write 100 sectors and read 100 sectors. */
|
/* Test 1: Simple write 100 sectors and read 100 sectors. */
|
||||||
printf("Test 1: Simple write-read 100 sectors...........");
|
printf("Test 1: Simple write-read 100 sectors...........");
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user