GCC Code Coverage Report
Directory: ./ Exec Total Coverage
File: lx_nor_flash_close.c Lines: 10 16 62.5 %
Date: 2026-03-06 18:45:40 Branches: 3 8 37.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_close                                 PORTABLE C      */
43
/*                                                           6.1.7        */
44
/*  AUTHOR                                                                */
45
/*                                                                        */
46
/*    William E. Lamie, Microsoft Corporation                             */
47
/*                                                                        */
48
/*  DESCRIPTION                                                           */
49
/*                                                                        */
50
/*    This function closes a NOR flash instance.                          */
51
/*                                                                        */
52
/*  INPUT                                                                 */
53
/*                                                                        */
54
/*    nor_flash                             NOR flash instance            */
55
/*                                                                        */
56
/*  OUTPUT                                                                */
57
/*                                                                        */
58
/*    return status                                                       */
59
/*                                                                        */
60
/*  CALLS                                                                 */
61
/*                                                                        */
62
/*    tx_mutex_delete                       Delete thread-safe mutex      */
63
/*                                                                        */
64
/*  CALLED BY                                                             */
65
/*                                                                        */
66
/*    Application Code                                                    */
67
/*                                                                        */
68
/**************************************************************************/
69
18
UINT  _lx_nor_flash_close(LX_NOR_FLASH *nor_flash)
70
{
71
72
LX_INTERRUPT_SAVE_AREA
73
74
75
    /* Lockout interrupts for NOR flash close.  */
76
18
    LX_DISABLE
77
78
    /* See if the media is the only one on the media opened list.  */
79
18
    if ((_lx_nor_flash_opened_ptr == nor_flash) &&
80
18
        (_lx_nor_flash_opened_ptr == nor_flash -> lx_nor_flash_open_next) &&
81
18
        (_lx_nor_flash_opened_ptr == nor_flash -> lx_nor_flash_open_previous))
82
    {
83
84
        /* Only opened NOR flash, just set the opened list to NULL.  */
85
18
        _lx_nor_flash_opened_ptr =  LX_NULL;
86
    }
87
    else
88
    {
89
90
        /* Otherwise, not the only opened NOR flash, link-up the neighbors.  */
91
        (nor_flash -> lx_nor_flash_open_next) -> lx_nor_flash_open_previous =
92
                                            nor_flash -> lx_nor_flash_open_previous;
93
        (nor_flash -> lx_nor_flash_open_previous) -> lx_nor_flash_open_next =
94
                                            nor_flash -> lx_nor_flash_open_next;
95
96
        /* See if we have to update the opened list head pointer.  */
97
        if (_lx_nor_flash_opened_ptr == nor_flash)
98
        {
99
100
            /* Yes, move the head pointer to the next opened NOR flash. */
101
            _lx_nor_flash_opened_ptr =  nor_flash -> lx_nor_flash_open_next;
102
        }
103
    }
104
105
    /* Decrement the opened NOR flash counter.  */
106
18
    _lx_nor_flash_opened_count--;
107
108
    /* Finally, indicate that this NOR flash is closed.  */
109
18
    nor_flash -> lx_nor_flash_state =  LX_NOR_FLASH_CLOSED;
110
111
    /* Restore interrupt posture.  */
112
18
    LX_RESTORE
113
114
#ifdef LX_THREAD_SAFE_ENABLE
115
116
    /* Delete the thread safe mutex.  */
117
    tx_mutex_delete(&nor_flash -> lx_nor_flash_mutex);
118
#endif
119
    /* Return success.  */
120
18
    return(LX_SUCCESS);
121
}
122
123