GCC Code Coverage Report
Directory: ./ Exec Total Coverage
File: lx_nand_flash_mapped_block_list_add.c Lines: 13 14 92.9 %
Date: 2024-03-11 05:20:25 Branches: 5 6 83.3 %

Line Branch Exec Source
1
/***************************************************************************
2
 * Copyright (c) 2024 Microsoft Corporation
3
 *
4
 * This program and the accompanying materials are made available under the
5
 * terms of the MIT License which is available at
6
 * https://opensource.org/licenses/MIT.
7
 *
8
 * SPDX-License-Identifier: MIT
9
 **************************************************************************/
10
11
12
/**************************************************************************/
13
/**************************************************************************/
14
/**                                                                       */
15
/** LevelX Component                                                      */
16
/**                                                                       */
17
/**   NAND Flash                                                          */
18
/**                                                                       */
19
/**************************************************************************/
20
/**************************************************************************/
21
22
#define LX_SOURCE_CODE
23
24
25
/* Disable ThreadX error checking.  */
26
27
#ifndef LX_DISABLE_ERROR_CHECKING
28
#define LX_DISABLE_ERROR_CHECKING
29
#endif
30
31
32
/* Include necessary system files.  */
33
34
#include "lx_api.h"
35
36
37
/**************************************************************************/
38
/*                                                                        */
39
/*  FUNCTION                                               RELEASE        */
40
/*                                                                        */
41
/*    _lx_nand_flash_mapped_block_list_add                PORTABLE C      */
42
/*                                                           6.2.1       */
43
/*  AUTHOR                                                                */
44
/*                                                                        */
45
/*    Xiuwen Cai, Microsoft Corporation                                   */
46
/*                                                                        */
47
/*  DESCRIPTION                                                           */
48
/*                                                                        */
49
/*    This function adds a block to mapped block list.                    */
50
/*                                                                        */
51
/*  INPUT                                                                 */
52
/*                                                                        */
53
/*    nand_flash                            NAND flash instance           */
54
/*    block_mapping_index                   Block mapping index           */
55
/*                                                                        */
56
/*  OUTPUT                                                                */
57
/*                                                                        */
58
/*    return status                                                       */
59
/*                                                                        */
60
/*  CALLS                                                                 */
61
/*                                                                        */
62
/*    None                                                                */
63
/*                                                                        */
64
/*  CALLED BY                                                             */
65
/*                                                                        */
66
/*    Internal LevelX                                                     */
67
/*                                                                        */
68
/*  RELEASE HISTORY                                                       */
69
/*                                                                        */
70
/*    DATE              NAME                      DESCRIPTION             */
71
/*                                                                        */
72
/*  03-08-2023     Xiuwen Cai               Initial Version 6.2.1        */
73
/*                                                                        */
74
/**************************************************************************/
75
1328
UINT  _lx_nand_flash_mapped_block_list_add(LX_NAND_FLASH* nand_flash, ULONG block_mapping_index)
76
{
77
78
ULONG insert_position;
79
ULONG search_position;
80
UCHAR new_block_erase_count;
81
82
83
    /* Get insert position for the mapped block list.  */
84
1328
    insert_position = nand_flash -> lx_nand_flash_mapped_block_list_head;
85
86
    /* Check if the list if full.  */
87
1328
    if (insert_position < nand_flash -> lx_nand_flash_free_block_list_tail)
88
    {
89
90
        /* Return an error.  */
91
        return(LX_ERROR);
92
    }
93
94
    /* Get the erase count.  */
95
1328
    new_block_erase_count = nand_flash -> lx_nand_flash_erase_count_table[nand_flash -> lx_nand_flash_block_mapping_table[block_mapping_index]];
96
97
    /* Add one block to the free list.  */
98
1328
    nand_flash -> lx_nand_flash_mapped_block_list_head--;
99
100
    /* Initialize the search pointer.  */
101
1328
    search_position = insert_position + 1;
102
103
    /* Loop to search the insert position.  */
104
59165
    while ((search_position < nand_flash -> lx_nand_flash_block_list_size) &&
105
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))
106
    {
107
108
        /* Move the item in the list.  */
109
57837
        nand_flash -> lx_nand_flash_block_list[insert_position] = nand_flash -> lx_nand_flash_block_list[search_position];
110
57837
        search_position++;
111
57837
        insert_position++;
112
    }
113
114
    /* Insert the new block to the list.  */
115
1328
    nand_flash -> lx_nand_flash_block_list[insert_position] = (USHORT)block_mapping_index;
116
117
    /* Return successful completion.  */
118
1328
    return(LX_SUCCESS);
119
}
120