1 /**************************************************************************/ 2 /* */ 3 /* Copyright (c) Microsoft Corporation. All rights reserved. */ 4 /* */ 5 /* This software is licensed under the Microsoft Software License */ 6 /* Terms for Microsoft Azure RTOS. Full text of the license can be */ 7 /* found in the LICENSE file at https://aka.ms/AzureRTOS_EULA */ 8 /* and in the root directory of this software. */ 9 /* */ 10 /**************************************************************************/ 11 12 13 /**************************************************************************/ 14 /**************************************************************************/ 15 /** */ 16 /** LevelX Component */ 17 /** */ 18 /** NOR Flash */ 19 /** */ 20 /**************************************************************************/ 21 /**************************************************************************/ 22 23 #define LX_SOURCE_CODE 24 25 26 /* Disable ThreadX error checking. */ 27 28 #ifndef LX_DISABLE_ERROR_CHECKING 29 #define LX_DISABLE_ERROR_CHECKING 30 #endif 31 32 33 /* Include necessary system files. */ 34 35 #include "lx_api.h" 36 37 38 /**************************************************************************/ 39 /* */ 40 /* FUNCTION RELEASE */ 41 /* */ 42 /* _lx_nor_flash_sector_mapping_cache_invalidate PORTABLE C */ 43 /* 6.1.7 */ 44 /* AUTHOR */ 45 /* */ 46 /* William E. Lamie, Microsoft Corporation */ 47 /* */ 48 /* DESCRIPTION */ 49 /* */ 50 /* This function invalidates the sector's entry in the NOR flash */ 51 /* cache. */ 52 /* */ 53 /* INPUT */ 54 /* */ 55 /* nor_flash NOR flash instance */ 56 /* logical_sector Logical sector */ 57 /* */ 58 /* OUTPUT */ 59 /* */ 60 /* None */ 61 /* */ 62 /* CALLS */ 63 /* */ 64 /* None */ 65 /* */ 66 /* CALLED BY */ 67 /* */ 68 /* Internal LevelX */ 69 /* */ 70 /* RELEASE HISTORY */ 71 /* */ 72 /* DATE NAME DESCRIPTION */ 73 /* */ 74 /* 05-19-2020 William E. Lamie Initial Version 6.0 */ 75 /* 09-30-2020 William E. Lamie Modified comment(s), */ 76 /* resulting in version 6.1 */ 77 /* 06-02-2021 Bhupendra Naphade Modified comment(s), */ 78 /* resulting in version 6.1.7 */ 79 /* */ 80 /**************************************************************************/ _lx_nor_flash_sector_mapping_cache_invalidate(LX_NOR_FLASH * nor_flash,ULONG logical_sector)81VOID _lx_nor_flash_sector_mapping_cache_invalidate(LX_NOR_FLASH *nor_flash, ULONG logical_sector) 82 { 83 84 ULONG i; 85 LX_NOR_SECTOR_MAPPING_CACHE_ENTRY *sector_mapping_cache_entry_ptr; 86 87 88 /* Determine if the sector mapping cache is enabled. */ 89 if (nor_flash -> lx_nor_flash_sector_mapping_cache_enabled) 90 { 91 92 /* Calculate the starting index of the sector mapping cache for this sector entry. */ 93 i = (logical_sector & LX_NOR_SECTOR_MAPPING_CACHE_HASH_MASK) * LX_NOR_SECTOR_MAPPING_CACHE_DEPTH; 94 95 /* Build a pointer to the cache entry. */ 96 sector_mapping_cache_entry_ptr = &nor_flash -> lx_nor_flash_sector_mapping_cache[i]; 97 98 /* Determine if the sector is in the sector mapping cache - assuming the depth of the sector 99 mapping cache is LX_NOR_SECTOR_MAPPING_CACHE_DEPTH entries. */ 100 if ((sector_mapping_cache_entry_ptr -> lx_nor_sector_mapping_cache_logical_sector) == (logical_sector | LX_NOR_SECTOR_MAPPING_CACHE_ENTRY_VALID)) 101 { 102 103 /* Move all cache entries up and invalidate the last entry. */ 104 *(sector_mapping_cache_entry_ptr) = *(sector_mapping_cache_entry_ptr + 1); 105 *(sector_mapping_cache_entry_ptr + 1) = *(sector_mapping_cache_entry_ptr + 2); 106 *(sector_mapping_cache_entry_ptr + 2) = *(sector_mapping_cache_entry_ptr + 3); 107 108 /* Invalidate the last entry. */ 109 (sector_mapping_cache_entry_ptr + 3) -> lx_nor_sector_mapping_cache_logical_sector = 0; 110 } 111 else if (((sector_mapping_cache_entry_ptr + 1) -> lx_nor_sector_mapping_cache_logical_sector) == (logical_sector | LX_NOR_SECTOR_MAPPING_CACHE_ENTRY_VALID)) 112 { 113 114 /* Move all subsequent cache entries up and invalidate the last entry. */ 115 *(sector_mapping_cache_entry_ptr + 1) = *(sector_mapping_cache_entry_ptr + 2); 116 *(sector_mapping_cache_entry_ptr + 2) = *(sector_mapping_cache_entry_ptr + 3); 117 118 /* Invalidate the last entry. */ 119 (sector_mapping_cache_entry_ptr + 3) -> lx_nor_sector_mapping_cache_logical_sector = 0; 120 } 121 else if (((sector_mapping_cache_entry_ptr + 2) -> lx_nor_sector_mapping_cache_logical_sector) == (logical_sector | LX_NOR_SECTOR_MAPPING_CACHE_ENTRY_VALID)) 122 { 123 124 /* Move all subsequent cache entries up and invalidate the last entry. */ 125 *(sector_mapping_cache_entry_ptr + 2) = *(sector_mapping_cache_entry_ptr + 3); 126 127 /* Invalidate the last entry. */ 128 (sector_mapping_cache_entry_ptr + 3) -> lx_nor_sector_mapping_cache_logical_sector = 0; 129 } 130 else if (((sector_mapping_cache_entry_ptr + 3) -> lx_nor_sector_mapping_cache_logical_sector) == (logical_sector | LX_NOR_SECTOR_MAPPING_CACHE_ENTRY_VALID)) 131 { 132 133 /* Simply invalidate the last entry. */ 134 (sector_mapping_cache_entry_ptr + 3) -> lx_nor_sector_mapping_cache_logical_sector = 0; 135 } 136 } 137 } 138 139