GCC Code Coverage Report
Directory: ./ Exec Total Coverage
File: lx_nand_flash_block_allocate.c Lines: 5 6 83.3 %
Date: 2026-03-06 18:45:40 Branches: 1 2 50.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_allocate                       PORTABLE C      */
43
/*                                                           6.2.1       */
44
/*  AUTHOR                                                                */
45
/*                                                                        */
46
/*    Xiuwen Cai, Microsoft Corporation                                   */
47
/*                                                                        */
48
/*  DESCRIPTION                                                           */
49
/*                                                                        */
50
/*    This function attempts to get a block in the free block list.       */
51
/*                                                                        */
52
/*  INPUT                                                                 */
53
/*                                                                        */
54
/*    nand_flash                            NAND flash instance           */
55
/*    block                                 Return 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
1611
UINT  _lx_nand_flash_block_allocate(LX_NAND_FLASH* nand_flash, ULONG* block)
71
{
72
73
74
    /* Check if the free block list is empty.  */
75
1611
    if (nand_flash -> lx_nand_flash_free_block_list_tail == 0)
76
    {
77
78
        /* Empty list, return error.  */
79
        return(LX_NO_BLOCKS);
80
    }
81
82
    /* Remove one block from the list.  */
83
1611
    nand_flash -> lx_nand_flash_free_block_list_tail--;
84
85
    /* Return the block number.  */
86
1611
    *block = nand_flash -> lx_nand_flash_block_list[nand_flash -> lx_nand_flash_free_block_list_tail];
87
88
    /* Return successful completion.  */
89
1611
    return(LX_SUCCESS);
90
}
91