GCC Code Coverage Report
Directory: ./ Exec Total Coverage
File: lx_nor_flash_sector_mapping_cache_invalidate.c Lines: 19 19 100.0 %
Date: 2026-03-06 18:45:40 Branches: 9 10 90.0 %

Line Branch Exec Source
1
/***************************************************************************
2
 * Copyright (c) 2024 Microsoft Corporation
3
 * Copyright (c) 2026-present Eclipse ThreadX contributors
4
 *
5
 * This program and the accompanying materials are made available under the
6
 * terms of the MIT License which is available at
7
 * https://opensource.org/licenses/MIT.
8
 *
9
 * SPDX-License-Identifier: MIT
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
/**************************************************************************/
71
17458
VOID  _lx_nor_flash_sector_mapping_cache_invalidate(LX_NOR_FLASH *nor_flash, ULONG logical_sector)
72
{
73
74
ULONG                           i;
75
LX_NOR_SECTOR_MAPPING_CACHE_ENTRY  *sector_mapping_cache_entry_ptr;
76
77
78
    /* Determine if the sector mapping cache is enabled.  */
79
17458
    if (nor_flash -> lx_nor_flash_sector_mapping_cache_enabled)
80
    {
81
82
        /* Calculate the starting index of the sector mapping cache for this sector entry.  */
83
17458
        i =  (logical_sector & LX_NOR_SECTOR_MAPPING_CACHE_HASH_MASK) * LX_NOR_SECTOR_MAPPING_CACHE_DEPTH;
84
85
        /* Build a pointer to the cache entry.  */
86
17458
        sector_mapping_cache_entry_ptr =  &nor_flash -> lx_nor_flash_sector_mapping_cache[i];
87
88
        /* Determine if the sector is in the sector mapping cache - assuming the depth of the sector
89
           mapping cache is LX_NOR_SECTOR_MAPPING_CACHE_DEPTH entries.  */
90
17458
        if ((sector_mapping_cache_entry_ptr -> lx_nor_sector_mapping_cache_logical_sector) == (logical_sector | LX_NOR_SECTOR_MAPPING_CACHE_ENTRY_VALID))
91
        {
92
93
            /* Move all cache entries up and invalidate the last entry.  */
94
2726
            *(sector_mapping_cache_entry_ptr) =      *(sector_mapping_cache_entry_ptr + 1);
95
2726
            *(sector_mapping_cache_entry_ptr + 1) =  *(sector_mapping_cache_entry_ptr + 2);
96
2726
            *(sector_mapping_cache_entry_ptr + 2) =  *(sector_mapping_cache_entry_ptr + 3);
97
98
            /* Invalidate the last entry.  */
99
2726
            (sector_mapping_cache_entry_ptr + 3) -> lx_nor_sector_mapping_cache_logical_sector =   0;
100
        }
101
14732
        else if (((sector_mapping_cache_entry_ptr + 1) -> lx_nor_sector_mapping_cache_logical_sector) == (logical_sector | LX_NOR_SECTOR_MAPPING_CACHE_ENTRY_VALID))
102
        {
103
104
            /* Move all subsequent cache entries up and invalidate the last entry.  */
105
496
            *(sector_mapping_cache_entry_ptr + 1) =  *(sector_mapping_cache_entry_ptr + 2);
106
496
            *(sector_mapping_cache_entry_ptr + 2) =  *(sector_mapping_cache_entry_ptr + 3);
107
108
            /* Invalidate the last entry.  */
109
496
            (sector_mapping_cache_entry_ptr + 3) -> lx_nor_sector_mapping_cache_logical_sector =   0;
110
        }
111
14236
        else if (((sector_mapping_cache_entry_ptr + 2) -> 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
438
            *(sector_mapping_cache_entry_ptr + 2) =  *(sector_mapping_cache_entry_ptr + 3);
116
117
            /* Invalidate the last entry.  */
118
438
            (sector_mapping_cache_entry_ptr + 3) -> lx_nor_sector_mapping_cache_logical_sector =   0;
119
        }
120
13798
        else if (((sector_mapping_cache_entry_ptr + 3) -> lx_nor_sector_mapping_cache_logical_sector) == (logical_sector | LX_NOR_SECTOR_MAPPING_CACHE_ENTRY_VALID))
121
        {
122
123
            /* Simply invalidate the last entry.  */
124
248
            (sector_mapping_cache_entry_ptr + 3) -> lx_nor_sector_mapping_cache_logical_sector =   0;
125
        }
126
    }
127
17458
}
128