GCC Code Coverage Report
Directory: ./ Exec Total Coverage
File: lx_nand_flash_block_find.c Lines: 8 9 88.9 %
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
/**   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_block_find                           PORTABLE C      */
43
/*                                                           6.2.1       */
44
/*  AUTHOR                                                                */
45
/*                                                                        */
46
/*    Xiuwen Cai, Microsoft Corporation                                   */
47
/*                                                                        */
48
/*  DESCRIPTION                                                           */
49
/*                                                                        */
50
/*    This function attempts to find the mapped block for the logical     */
51
/*    sector in the mapping table.                                        */
52
/*                                                                        */
53
/*  INPUT                                                                 */
54
/*                                                                        */
55
/*    nand_flash                            NAND flash instance           */
56
/*    logical_sector                        Logical sector number         */
57
/*    superceded_check                      Check for page being          */
58
/*                                            superceded (can happen if   */
59
/*                                            on interruptions of page    */
60
/*                                            write)                      */
61
/*    block                                 Destination for block         */
62
/*    page                                  Destination for page          */
63
/*                                                                        */
64
/*  OUTPUT                                                                */
65
/*                                                                        */
66
/*    return status                                                       */
67
/*                                                                        */
68
/*  CALLS                                                                 */
69
/*                                                                        */
70
/*    None                                                                */
71
/*                                                                        */
72
/*  CALLED BY                                                             */
73
/*                                                                        */
74
/*    Internal LevelX                                                     */
75
/*                                                                        */
76
/**************************************************************************/
77
86624
UINT  _lx_nand_flash_block_find(LX_NAND_FLASH *nand_flash, ULONG logical_sector, ULONG *block, USHORT *block_status)
78
{
79
80
 UINT    block_mapping_index;
81
 USHORT  block_number;
82
83
84
    /* Get the mapping index from logic sector address.  */
85
86624
    block_mapping_index = logical_sector / nand_flash -> lx_nand_flash_pages_per_block;
86
87
    /* Check the address range.  */
88
86624
    if (block_mapping_index >= nand_flash -> lx_nand_flash_block_mapping_table_size / sizeof(*nand_flash -> lx_nand_flash_block_mapping_table))
89
    {
90
91
        /* Out of range, return an error. */
92
        return(LX_ERROR);
93
    }
94
95
    /* Get the block number from mapping table.  */
96
86624
    block_number = nand_flash -> lx_nand_flash_block_mapping_table[block_mapping_index];
97
98
    /* Check if it is mapped.  */
99
86624
    if (block_number != LX_NAND_BLOCK_UNMAPPED)
100
    {
101
102
        /* Return the block status.  */
103
37812
        *block_status = nand_flash -> lx_nand_flash_block_status_table[block_number];
104
    }
105
106
    /* Return the block number.  */
107
86624
    *block = (ULONG)block_number;
108
109
    /* Return successful completion.  */
110
86624
    return(LX_SUCCESS);
111
}
112