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_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 NAND flash instance. */ |
51 |
|
|
/* */ |
52 |
|
|
/* INPUT */ |
53 |
|
|
/* */ |
54 |
|
|
/* nand_flash NAND 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 |
|
4 |
UINT _lx_nand_flash_close(LX_NAND_FLASH *nand_flash) |
70 |
|
|
{ |
71 |
|
|
|
72 |
|
|
LX_INTERRUPT_SAVE_AREA |
73 |
|
|
|
74 |
|
|
|
75 |
|
|
/* Lockout interrupts for NAND flash close. */ |
76 |
|
4 |
LX_DISABLE |
77 |
|
|
|
78 |
|
|
/* See if the media is the only one on the media opened list. */ |
79 |
✓✗ |
4 |
if ((_lx_nand_flash_opened_ptr == nand_flash) && |
80 |
✓✗ |
4 |
(_lx_nand_flash_opened_ptr == nand_flash -> lx_nand_flash_open_next) && |
81 |
✓✗ |
4 |
(_lx_nand_flash_opened_ptr == nand_flash -> lx_nand_flash_open_previous)) |
82 |
|
|
{ |
83 |
|
|
|
84 |
|
|
/* Only opened NAND flash, just set the opened list to NULL. */ |
85 |
|
4 |
_lx_nand_flash_opened_ptr = LX_NULL; |
86 |
|
|
} |
87 |
|
|
else |
88 |
|
|
{ |
89 |
|
|
|
90 |
|
|
/* Otherwise, not the only opened NAND flash, link-up the neighbors. */ |
91 |
|
|
(nand_flash -> lx_nand_flash_open_next) -> lx_nand_flash_open_previous = |
92 |
|
|
nand_flash -> lx_nand_flash_open_previous; |
93 |
|
|
(nand_flash -> lx_nand_flash_open_previous) -> lx_nand_flash_open_next = |
94 |
|
|
nand_flash -> lx_nand_flash_open_next; |
95 |
|
|
|
96 |
|
|
/* See if we have to update the opened list head pointer. */ |
97 |
|
|
if (_lx_nand_flash_opened_ptr == nand_flash) |
98 |
|
|
{ |
99 |
|
|
|
100 |
|
|
/* Yes, move the head pointer to the next opened NAND flash. */ |
101 |
|
|
_lx_nand_flash_opened_ptr = nand_flash -> lx_nand_flash_open_next; |
102 |
|
|
} |
103 |
|
|
} |
104 |
|
|
|
105 |
|
|
/* Decrement the opened NAND flash counter. */ |
106 |
|
4 |
_lx_nand_flash_opened_count--; |
107 |
|
|
|
108 |
|
|
/* Finally, indicate that this NAND flash is closed. */ |
109 |
|
4 |
nand_flash -> lx_nand_flash_state = LX_NAND_FLASH_CLOSED; |
110 |
|
|
|
111 |
|
|
/* Restore interrupt posture. */ |
112 |
|
4 |
LX_RESTORE |
113 |
|
|
|
114 |
|
|
#ifdef LX_THREAD_SAFE_ENABLE |
115 |
|
|
|
116 |
|
|
/* Delete the thread safe mutex. */ |
117 |
|
|
tx_mutex_delete(&nand_flash -> lx_nand_flash_mutex); |
118 |
|
|
#endif |
119 |
|
|
/* Return success. */ |
120 |
|
4 |
return(LX_SUCCESS); |
121 |
|
|
} |
122 |
|
|
|
123 |
|
|
|