GCC Code Coverage Report
Directory: ./ Exec Total Coverage
File: lx_nor_flash_driver_block_erase.c Lines: 11 11 100.0 %
Date: 2026-03-06 18:45:40 Branches: 7 8 87.5 %

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
/**   NOR 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_nor_flash_driver_block_erase                    PORTABLE C      */
43
/*                                                           6.2.1       */
44
/*  AUTHOR                                                                */
45
/*                                                                        */
46
/*    William E. Lamie, Microsoft Corporation                             */
47
/*                                                                        */
48
/*  DESCRIPTION                                                           */
49
/*                                                                        */
50
/*    This function performs a NOR flash block erase.                     */
51
/*                                                                        */
52
/*  INPUT                                                                 */
53
/*                                                                        */
54
/*    nor_flash                             NOR flash instance            */
55
/*    block                                 Block number to erase         */
56
/*    erase_count                           Erase count for this block    */
57
/*                                                                        */
58
/*  OUTPUT                                                                */
59
/*                                                                        */
60
/*    return status                                                       */
61
/*                                                                        */
62
/*  CALLS                                                                 */
63
/*                                                                        */
64
/*    (lx_nor_flash_driver_block_erase)     Actual driver block erase     */
65
/*                                                                        */
66
/*  CALLED BY                                                             */
67
/*                                                                        */
68
/*    Application Code                                                    */
69
/*                                                                        */
70
/**************************************************************************/
71
1218
UINT  _lx_nor_flash_driver_block_erase(LX_NOR_FLASH *nor_flash, ULONG block, ULONG erase_count)
72
{
73
74
UINT    status;
75
76
#ifndef LX_NOR_DISABLE_EXTENDED_CACHE
77
78
UINT    i;
79
ULONG   *block_start_address;
80
ULONG   *block_end_address;
81
ULONG   *cache_entry_start;
82
ULONG   *cache_entry_end;
83
84
85
    /* Calculate the block starting address.  */
86
1218
    block_start_address =  nor_flash -> lx_nor_flash_base_address + (block * nor_flash -> lx_nor_flash_words_per_block);
87
1218
    block_end_address =    block_start_address + nor_flash -> lx_nor_flash_words_per_block;
88
89
    /* Loop through the cache entries to see if there is a sector in cache.  */
90
3538
    for (i = 0; i < nor_flash -> lx_nor_flash_extended_cache_entries; i++)
91
    {
92
93
        /* Search through the cache to see if this cache entry needs to be invalidated.  */
94
95
        /* Determine the cache entry addresses.  */
96
2320
        cache_entry_start =  nor_flash -> lx_nor_flash_extended_cache[i].lx_nor_flash_extended_cache_entry_sector_address;
97
2320
        cache_entry_end =    cache_entry_start + LX_NOR_SECTOR_SIZE;
98
99
        /* Determine if the flash address in in the cache entry.  */
100

2320
        if ((cache_entry_start) && (block_start_address <= cache_entry_start) && (block_end_address > cache_entry_end))
101
        {
102
103
            /* Yes, this cache entry is in the block to be erased so invalidate it.  */
104
252
            nor_flash -> lx_nor_flash_extended_cache[i].lx_nor_flash_extended_cache_entry_sector_address =  LX_NULL;
105
252
            nor_flash -> lx_nor_flash_extended_cache[i].lx_nor_flash_extended_cache_entry_access_count =    0;
106
        }
107
    }
108
#endif
109
110
    /* Call the actual driver block erase function.  */
111
#ifdef LX_NOR_ENABLE_CONTROL_BLOCK_FOR_DRIVER_INTERFACE
112
    status =  (nor_flash -> lx_nor_flash_driver_block_erase)(nor_flash, block, erase_count);
113
#else
114
1218
    status =  (nor_flash -> lx_nor_flash_driver_block_erase)(block, erase_count);
115
#endif
116
117
    /* Return completion status.  */
118
1218
    return(status);
119
}
120
121