GCC Code Coverage Report
Directory: ./ Exec Total Coverage
File: lx_nand_flash_mapped_block_list_remove.c Lines: 12 13 92.3 %
Date: 2026-03-06 18:45:40 Branches: 6 8 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
/**   NAND 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_nand_flash_mapped_block_list_remove             PORTABLE C      */
43
/*                                                           6.2.1       */
44
/*  AUTHOR                                                                */
45
/*                                                                        */
46
/*    Xiuwen Cai, Microsoft Corporation                                   */
47
/*                                                                        */
48
/*  DESCRIPTION                                                           */
49
/*                                                                        */
50
/*    This function removes mapped block from list.                       */
51
/*                                                                        */
52
/*  INPUT                                                                 */
53
/*                                                                        */
54
/*    nand_flash                            NAND flash instance           */
55
/*    block_mapping_index                   Block mapping index           */
56
/*                                                                        */
57
/*  OUTPUT                                                                */
58
/*                                                                        */
59
/*    return status                                                       */
60
/*                                                                        */
61
/*  CALLS                                                                 */
62
/*                                                                        */
63
/*    None                                                                */
64
/*                                                                        */
65
/*  CALLED BY                                                             */
66
/*                                                                        */
67
/*    Internal LevelX                                                     */
68
/*                                                                        */
69
/**************************************************************************/
70
1142
UINT  _lx_nand_flash_mapped_block_list_remove(LX_NAND_FLASH* nand_flash, ULONG block_mapping_index)
71
{
72
73
ULONG search_position;
74
75
76
    /* Initialize the search pointer.  */
77
1142
    search_position = nand_flash -> lx_nand_flash_mapped_block_list_head + 1;
78
79
    /* Loop to search the block in the list.  */
80
52352
    while (search_position < nand_flash -> lx_nand_flash_block_list_size)
81
    {
82
83
        /* Check if there is a match in the list.  */
84
52352
        if (nand_flash -> lx_nand_flash_block_list[search_position] == block_mapping_index)
85
        {
86
87
            /* Get out of the loop.  */
88
1142
            break;
89
        }
90
91
        /* Move to next position.  */
92
51210
        search_position++;
93
    }
94
95
    /* Check if the block is found.  */
96
1142
    if (search_position < nand_flash -> lx_nand_flash_block_list_size)
97
    {
98
99
        /* Remove one item from the list.  */
100
1142
        nand_flash -> lx_nand_flash_mapped_block_list_head++;
101
102
        /* Loop to move items in the list.  */
103
52352
        while (search_position > nand_flash -> lx_nand_flash_mapped_block_list_head)
104
        {
105
106
            /* Move the item in the list.  */
107
51210
            nand_flash -> lx_nand_flash_block_list[search_position] = nand_flash -> lx_nand_flash_block_list[search_position - 1];
108
51210
            search_position--;
109
        }
110
    }
111
    else
112
    {
113
114
        /* Return error.  */
115
        return(LX_NO_BLOCKS);
116
    }
117
118
    /* Return successful completion.  */
119
1142
    return(LX_SUCCESS);
120
}
121