GCC Code Coverage Report


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

lx_nor_flash_partial_defragment.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_partial_defragment PORTABLE C */
43 /* 6.1.7 */
44 /* AUTHOR */
45 /* */
46 /* William E. Lamie, Microsoft Corporation */
47 /* */
48 /* DESCRIPTION */
49 /* */
50 /* This function defragments the NOR flash up to the specified */
51 /* number of blocks. . */
52 /* */
53 /* INPUT */
54 /* */
55 /* nor_flash NOR flash instance */
56 /* max_blocks Maximum number of blocks to */
57 /* defragment */
58 /* */
59 /* OUTPUT */
60 /* */
61 /* return status */
62 /* */
63 /* CALLS */
64 /* */
65 /* _lx_nor_flash_block_reclaim Reclaim a NOR flash block */
66 /* tx_mutex_get Get thread protection */
67 /* tx_mutex_put Release thread protection */
68 /* */
69 /* CALLED BY */
70 /* */
71 /* Application Code */
72 /* Internal LevelX */
73 /* */
74 /**************************************************************************/
75 ✗ UINT _lx_nor_flash_partial_defragment(LX_NOR_FLASH *nor_flash, UINT max_blocks)
76 {
77
78 ULONG i;
79
80
81 #ifdef LX_THREAD_SAFE_ENABLE
82
83 /* Obtain the thread safe mutex. */
84 ✗ tx_mutex_get(&nor_flash -> lx_nor_flash_mutex, TX_WAIT_FOREVER);
85 #endif
86
87 /* Determine if the maximum number of blocks exceeds the total blocks in this flash instance. */
88 ✗ if (max_blocks >= nor_flash -> lx_nor_flash_total_blocks)
89 {
90
91 /* Adjust the maximum to the total number of blocks. */
92 ✗ max_blocks = nor_flash -> lx_nor_flash_total_blocks;
93 }
94
95 /* Loop for max number of blocks, while there are obsolete count. */
96 ✗ for (i = 0; i < max_blocks; i++)
97 {
98
99 /* Determine if there is any more defragment work. */
100 ✗ if (nor_flash -> lx_nor_flash_obsolete_physical_sectors == 0)
101 ✗ break;
102
103 /* Call the block reclaim function to defragment. */
104 ✗ _lx_nor_flash_block_reclaim(nor_flash);
105 }
106
107 #ifdef LX_THREAD_SAFE_ENABLE
108
109 /* Release the thread safe mutex. */
110 ✗ tx_mutex_put(&nor_flash -> lx_nor_flash_mutex);
111 #endif
112
113 /* Return successful completion. */
114 ✗ return(LX_SUCCESS);
115 }
116
117
118