GCC Code Coverage Report
Directory: ./ Exec Total Coverage
File: lx_nand_flash_free_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_free_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 free block list.                      */
51
/*                                                                        */
52
/*  INPUT                                                                 */
53
/*                                                                        */
54
/*    nand_flash                            NAND flash instance           */
55
/*    block                                 Block number                  */
56
/*                                                                        */
57
/*  OUTPUT                                                                */
58
/*                                                                        */
59
/*    return status                                                       */
60
/*                                                                        */
61
/*  CALLS                                                                 */
62
/*                                                                        */
63
/*    None                                                                */
64
/*                                                                        */
65
/*  CALLED BY                                                             */
66
/*                                                                        */
67
/*    Internal LevelX                                                     */
68
/*                                                                        */
69
/**************************************************************************/
70
6511
UINT  _lx_nand_flash_free_block_list_add(LX_NAND_FLASH* nand_flash, ULONG block)
71
{
72
73
ULONG insert_position;
74
INT search_position;
75
UCHAR new_block_erase_count;
76
77
78
    /* Get insert position for the free block list.  */
79
6511
    insert_position = nand_flash -> lx_nand_flash_free_block_list_tail;
80
81
    /* Check if the list if full.  */
82
6511
    if (insert_position > nand_flash -> lx_nand_flash_mapped_block_list_head)
83
    {
84
85
        /* Return an error.  */
86
        return(LX_ERROR);
87
    }
88
89
    /* Get the erase count.  */
90
6511
    new_block_erase_count = nand_flash -> lx_nand_flash_erase_count_table[block];
91
92
    /* Add one block to the free list.  */
93
6511
    nand_flash -> lx_nand_flash_free_block_list_tail++;
94
95
    /* Initialize the search pointer.  */
96
6511
    search_position = (INT)insert_position - 1;
97
98
    /* Loop to search the insert position by block erase count.  */
99
764242
    while ((search_position >= 0) &&
100
764233
           (nand_flash -> lx_nand_flash_erase_count_table[nand_flash -> lx_nand_flash_block_list[search_position]] < new_block_erase_count))
101
    {
102
103
        /* Move the item in the list.  */
104
757731
        nand_flash -> lx_nand_flash_block_list[insert_position] = nand_flash -> lx_nand_flash_block_list[search_position];
105
757731
        search_position--;
106
757731
        insert_position--;
107
    }
108
109
    /* Insert the new block to the list.  */
110
6511
    nand_flash -> lx_nand_flash_block_list[insert_position] = (USHORT)block;
111
112
    /* Return successful completion.  */
113
6511
    return(LX_SUCCESS);
114
}
115