GCC Code Coverage Report
Directory: ./ Exec Total Coverage
File: lx_nor_flash_close.c Lines: 10 16 62.5 %
Date: 2024-03-11 05:20:25 Branches: 3 8 37.5 %

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
/**   NOR 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_nor_flash_close                                 PORTABLE C      */
42
/*                                                           6.1.7        */
43
/*  AUTHOR                                                                */
44
/*                                                                        */
45
/*    William E. Lamie, Microsoft Corporation                             */
46
/*                                                                        */
47
/*  DESCRIPTION                                                           */
48
/*                                                                        */
49
/*    This function closes a NOR flash instance.                          */
50
/*                                                                        */
51
/*  INPUT                                                                 */
52
/*                                                                        */
53
/*    nor_flash                             NOR flash instance            */
54
/*                                                                        */
55
/*  OUTPUT                                                                */
56
/*                                                                        */
57
/*    return status                                                       */
58
/*                                                                        */
59
/*  CALLS                                                                 */
60
/*                                                                        */
61
/*    tx_mutex_delete                       Delete thread-safe mutex      */
62
/*                                                                        */
63
/*  CALLED BY                                                             */
64
/*                                                                        */
65
/*    Application Code                                                    */
66
/*                                                                        */
67
/*  RELEASE HISTORY                                                       */
68
/*                                                                        */
69
/*    DATE              NAME                      DESCRIPTION             */
70
/*                                                                        */
71
/*  05-19-2020     William E. Lamie         Initial Version 6.0           */
72
/*  09-30-2020     William E. Lamie         Modified comment(s),          */
73
/*                                            resulting in version 6.1    */
74
/*  06-02-2021     Bhupendra Naphade        Modified comment(s),          */
75
/*                                            resulting in version 6.1.7  */
76
/*                                                                        */
77
/**************************************************************************/
78
18
UINT  _lx_nor_flash_close(LX_NOR_FLASH *nor_flash)
79
{
80
81
LX_INTERRUPT_SAVE_AREA
82
83
84
    /* Lockout interrupts for NOR flash close.  */
85
18
    LX_DISABLE
86
87
    /* See if the media is the only one on the media opened list.  */
88
18
    if ((_lx_nor_flash_opened_ptr == nor_flash) &&
89
18
        (_lx_nor_flash_opened_ptr == nor_flash -> lx_nor_flash_open_next) &&
90
18
        (_lx_nor_flash_opened_ptr == nor_flash -> lx_nor_flash_open_previous))
91
    {
92
93
        /* Only opened NOR flash, just set the opened list to NULL.  */
94
18
        _lx_nor_flash_opened_ptr =  LX_NULL;
95
    }
96
    else
97
    {
98
99
        /* Otherwise, not the only opened NOR flash, link-up the neighbors.  */
100
        (nor_flash -> lx_nor_flash_open_next) -> lx_nor_flash_open_previous =
101
                                            nor_flash -> lx_nor_flash_open_previous;
102
        (nor_flash -> lx_nor_flash_open_previous) -> lx_nor_flash_open_next =
103
                                            nor_flash -> lx_nor_flash_open_next;
104
105
        /* See if we have to update the opened list head pointer.  */
106
        if (_lx_nor_flash_opened_ptr == nor_flash)
107
        {
108
109
            /* Yes, move the head pointer to the next opened NOR flash. */
110
            _lx_nor_flash_opened_ptr =  nor_flash -> lx_nor_flash_open_next;
111
        }
112
    }
113
114
    /* Decrement the opened NOR flash counter.  */
115
18
    _lx_nor_flash_opened_count--;
116
117
    /* Finally, indicate that this NOR flash is closed.  */
118
18
    nor_flash -> lx_nor_flash_state =  LX_NOR_FLASH_CLOSED;
119
120
    /* Restore interrupt posture.  */
121
18
    LX_RESTORE
122
123
#ifdef LX_THREAD_SAFE_ENABLE
124
125
    /* Delete the thread safe mutex.  */
126
    tx_mutex_delete(&nor_flash -> lx_nor_flash_mutex);
127
#endif
128
    /* Return success.  */
129
18
    return(LX_SUCCESS);
130
}
131
132