GCC Code Coverage Report
Directory: ./ Exec Total Coverage
File: lx_nand_flash_mapped_block_list_add.c Lines: 13 14 92.9 %
Date: 2026-03-06 18:45:40 Branches: 5 6 83.3 %

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_add                PORTABLE C      */
43
/*                                                           6.2.1       */
44
/*  AUTHOR                                                                */
45
/*                                                                        */
46
/*    Xiuwen Cai, Microsoft Corporation                                   */
47
/*                                                                        */
48
/*  DESCRIPTION                                                           */
49
/*                                                                        */
50
/*    This function adds a block to mapped block 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
1328
UINT  _lx_nand_flash_mapped_block_list_add(LX_NAND_FLASH* nand_flash, ULONG block_mapping_index)
71
{
72
73
ULONG insert_position;
74
ULONG search_position;
75
UCHAR new_block_erase_count;
76
77
78
    /* Get insert position for the mapped block list.  */
79
1328
    insert_position = nand_flash -> lx_nand_flash_mapped_block_list_head;
80
81
    /* Check if the list if full.  */
82
1328
    if (insert_position < nand_flash -> lx_nand_flash_free_block_list_tail)
83
    {
84
85
        /* Return an error.  */
86
        return(LX_ERROR);
87
    }
88
89
    /* Get the erase count.  */
90
1328
    new_block_erase_count = nand_flash -> lx_nand_flash_erase_count_table[nand_flash -> lx_nand_flash_block_mapping_table[block_mapping_index]];
91
92
    /* Add one block to the free list.  */
93
1328
    nand_flash -> lx_nand_flash_mapped_block_list_head--;
94
95
    /* Initialize the search pointer.  */
96
1328
    search_position = insert_position + 1;
97
98
    /* Loop to search the insert position.  */
99
59165
    while ((search_position < nand_flash -> lx_nand_flash_block_list_size) &&
100
58998
           (nand_flash -> lx_nand_flash_erase_count_table[nand_flash -> lx_nand_flash_block_mapping_table[nand_flash -> lx_nand_flash_block_list[search_position]]] < new_block_erase_count))
101
    {
102
103
        /* Move the item in the list.  */
104
57837
        nand_flash -> lx_nand_flash_block_list[insert_position] = nand_flash -> lx_nand_flash_block_list[search_position];
105
57837
        search_position++;
106
57837
        insert_position++;
107
    }
108
109
    /* Insert the new block to the list.  */
110
1328
    nand_flash -> lx_nand_flash_block_list[insert_position] = (USHORT)block_mapping_index;
111
112
    /* Return successful completion.  */
113
1328
    return(LX_SUCCESS);
114
}
115