GCC Code Coverage Report


Directory: common/src/
Coverage: low: ≥ 0% medium: ≥ 75.0% high: ≥ 90.0%
Coverage Exec / Excl / Total
Lines: 100.0% 15 / 0 / 15
Functions: 100.0% 1 / 0 / 1
Branches: 87.5% 7 / 0 / 8

lx_nor_flash_driver_block_erase.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 // Portions of this file were generated with AI assistance.
13
14
15 /**************************************************************************/
16 /**************************************************************************/
17 /** */
18 /** LevelX Component */
19 /** */
20 /** NOR Flash */
21 /** */
22 /**************************************************************************/
23 /**************************************************************************/
24
25 #define LX_SOURCE_CODE
26
27
28 /* Disable ThreadX error checking. */
29
30 #ifndef LX_DISABLE_ERROR_CHECKING
31 #define LX_DISABLE_ERROR_CHECKING
32 #endif
33
34
35 /* Include necessary system files. */
36
37 #include "lx_api.h"
38
39
40 /**************************************************************************/
41 /* */
42 /* FUNCTION RELEASE */
43 /* */
44 /* _lx_nor_flash_driver_block_erase PORTABLE C */
45 /* 6.2.1 */
46 /* AUTHOR */
47 /* */
48 /* William E. Lamie, Microsoft Corporation */
49 /* */
50 /* DESCRIPTION */
51 /* */
52 /* This function performs a NOR flash block erase. */
53 /* */
54 /* INPUT */
55 /* */
56 /* nor_flash NOR flash instance */
57 /* block Block number to erase */
58 /* erase_count Erase count for this block */
59 /* */
60 /* OUTPUT */
61 /* */
62 /* return status */
63 /* */
64 /* CALLS */
65 /* */
66 /* (lx_nor_flash_driver_block_erase) Actual driver block erase */
67 /* */
68 /* CALLED BY */
69 /* */
70 /* Application Code */
71 /* */
72 /**************************************************************************/
73 12196 UINT _lx_nor_flash_driver_block_erase(LX_NOR_FLASH *nor_flash, ULONG block, ULONG erase_count)
74 {
75
76 UINT status;
77
78 #ifndef LX_NOR_DISABLE_EXTENDED_CACHE
79
80 UINT i;
81 ULONG block_start_address;
82 ULONG block_end_address;
83 ULONG *cache_entry_start;
84 ULONG cache_entry_start_value;
85 ULONG cache_entry_end_value;
86
87
88 /* Calculate the block starting address.
89 MISRA C:2012 Rule 11.4 deviation: NOR driver addresses may be logical
90 address tokens, including zero, so compare address values without
91 dereferencing them. */
92 9760 block_start_address = (ULONG)(nor_flash -> lx_nor_flash_base_address) + (block * nor_flash -> lx_nor_flash_words_per_block * sizeof(ULONG));
93 9760 block_end_address = block_start_address + (nor_flash -> lx_nor_flash_words_per_block * sizeof(ULONG));
94
95 /* Loop through the cache entries to see if there is a sector in cache. */
96
2/2
✓ Branch 8 → 3 taken 18576 times.
✓ Branch 8 → 9 taken 9760 times.
28336 for (i = 0; i < nor_flash -> lx_nor_flash_extended_cache_entries; i++)
97 {
98
99 /* Search through the cache to see if this cache entry needs to be invalidated. */
100
101 /* Determine the cache entry addresses. */
102 18576 cache_entry_start = nor_flash -> lx_nor_flash_extended_cache[i].lx_nor_flash_extended_cache_entry_sector_address;
103
104 /* Determine if the cache entry is in the block being erased. */
105
1/2
✓ Branch 3 → 4 taken 18576 times.
✗ Branch 3 → 7 not taken.
18576 if (nor_flash -> lx_nor_flash_extended_cache[i].lx_nor_flash_extended_cache_entry_valid)
106 {
107 18576 cache_entry_start_value = (ULONG)cache_entry_start;
108 18576 cache_entry_end_value = cache_entry_start_value + (LX_NOR_SECTOR_SIZE * sizeof(ULONG));
109
110
4/4
✓ Branch 4 → 5 taken 9943 times.
✓ Branch 4 → 7 taken 8633 times.
✓ Branch 5 → 6 taken 2005 times.
✓ Branch 5 → 7 taken 7938 times.
18576 if ((block_start_address <= cache_entry_start_value) && (block_end_address >= cache_entry_end_value))
111 {
112
113 /* Yes, this cache entry is in the block to be erased so invalidate it. */
114 2005 nor_flash -> lx_nor_flash_extended_cache[i].lx_nor_flash_extended_cache_entry_sector_address = LX_NULL;
115 2005 nor_flash -> lx_nor_flash_extended_cache[i].lx_nor_flash_extended_cache_entry_access_count = 0;
116 2005 nor_flash -> lx_nor_flash_extended_cache[i].lx_nor_flash_extended_cache_entry_valid = LX_FALSE;
117 }
118 }
119 }
120 #endif
121
122 /* Call the actual driver block erase function. */
123 #ifdef LX_NOR_ENABLE_CONTROL_BLOCK_FOR_DRIVER_INTERFACE
124 1220 status = (nor_flash -> lx_nor_flash_driver_block_erase)(nor_flash, block, erase_count);
125 #else
126 10976 status = (nor_flash -> lx_nor_flash_driver_block_erase)(block, erase_count);
127 #endif
128
129 /* Return completion status. */
130 12196 return(status);
131 }
132