GCC Code Coverage Report
Directory: ./ Exec Total Coverage
File: lx_nor_flash_defragment.c Lines: 6 6 100.0 %
Date: 2026-03-06 18:45:40 Branches: 3 4 75.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_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.                            */
51
/*                                                                        */
52
/*  INPUT                                                                 */
53
/*                                                                        */
54
/*    nor_flash                             NOR flash instance            */
55
/*                                                                        */
56
/*  OUTPUT                                                                */
57
/*                                                                        */
58
/*    return status                                                       */
59
/*                                                                        */
60
/*  CALLS                                                                 */
61
/*                                                                        */
62
/*    _lx_nor_flash_block_reclaim           Reclaim a NOR flash block     */
63
/*    tx_mutex_get                          Get thread protection         */
64
/*    tx_mutex_put                          Release thread protection     */
65
/*                                                                        */
66
/*  CALLED BY                                                             */
67
/*                                                                        */
68
/*    Application Code                                                    */
69
/*    Internal LevelX                                                     */
70
/*                                                                        */
71
/**************************************************************************/
72
10
UINT  _lx_nor_flash_defragment(LX_NOR_FLASH *nor_flash)
73
{
74
75
ULONG    i;
76
77
78
#ifdef LX_THREAD_SAFE_ENABLE
79
80
    /* Obtain the thread safe mutex.  */
81
    tx_mutex_get(&nor_flash -> lx_nor_flash_mutex, TX_WAIT_FOREVER);
82
#endif
83
84
    /* Loop for max number of blocks, while there are obsolete count.  */
85
30
    for (i = 0; i < nor_flash -> lx_nor_flash_total_blocks; i++)
86
    {
87
88
        /* Determine if there is any more defragment work.  */
89
30
        if (nor_flash -> lx_nor_flash_obsolete_physical_sectors == 0)
90
10
            break;
91
92
        /* Call the block reclaim function to defragment.  */
93
20
        _lx_nor_flash_block_reclaim(nor_flash);
94
    }
95
96
#ifdef LX_THREAD_SAFE_ENABLE
97
98
    /* Release the thread safe mutex.  */
99
    tx_mutex_put(&nor_flash -> lx_nor_flash_mutex);
100
#endif
101
102
    /* Return successful completion.  */
103
10
    return(LX_SUCCESS);
104
}
105
106