GCC Code Coverage Report


Directory: common/src/
Coverage: low: ≥ 0% medium: ≥ 75.0% high: ≥ 90.0%
Coverage Exec / Excl / Total
Lines: 100.0% 19 / 0 / 19
Functions: 100.0% 1 / 0 / 1
Branches: 90.0% 9 / 0 / 10

lx_nor_flash_sector_mapping_cache_invalidate.c
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 174582 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
1/2
✓ Branch 2 → 3 taken 174582 times.
✗ Branch 2 → 11 not taken.
174582 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 174582 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 174582 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
2/2
✓ Branch 3 → 4 taken 27262 times.
✓ Branch 3 → 5 taken 147320 times.
174582 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 27262 *(sector_mapping_cache_entry_ptr) = *(sector_mapping_cache_entry_ptr + 1);
95 27262 *(sector_mapping_cache_entry_ptr + 1) = *(sector_mapping_cache_entry_ptr + 2);
96 27262 *(sector_mapping_cache_entry_ptr + 2) = *(sector_mapping_cache_entry_ptr + 3);
97
98 /* Invalidate the last entry. */
99 27262 (sector_mapping_cache_entry_ptr + 3) -> lx_nor_sector_mapping_cache_logical_sector = 0;
100 }
101
2/2
✓ Branch 5 → 6 taken 4960 times.
✓ Branch 5 → 7 taken 142360 times.
147320 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 4960 *(sector_mapping_cache_entry_ptr + 1) = *(sector_mapping_cache_entry_ptr + 2);
106 4960 *(sector_mapping_cache_entry_ptr + 2) = *(sector_mapping_cache_entry_ptr + 3);
107
108 /* Invalidate the last entry. */
109 4960 (sector_mapping_cache_entry_ptr + 3) -> lx_nor_sector_mapping_cache_logical_sector = 0;
110 }
111
2/2
✓ Branch 7 → 8 taken 4380 times.
✓ Branch 7 → 9 taken 137980 times.
142360 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 4380 *(sector_mapping_cache_entry_ptr + 2) = *(sector_mapping_cache_entry_ptr + 3);
116
117 /* Invalidate the last entry. */
118 4380 (sector_mapping_cache_entry_ptr + 3) -> lx_nor_sector_mapping_cache_logical_sector = 0;
119 }
120
2/2
✓ Branch 9 → 10 taken 2480 times.
✓ Branch 9 → 11 taken 135500 times.
137980 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 2480 (sector_mapping_cache_entry_ptr + 3) -> lx_nor_sector_mapping_cache_logical_sector = 0;
125 }
126 }
127 174582 }
128
129