1 /**************************************************************************/ 2 /* */ 3 /* Copyright (c) Microsoft Corporation. All rights reserved. */ 4 /* */ 5 /* This software is licensed under the Microsoft Software License */ 6 /* Terms for Microsoft Azure RTOS. Full text of the license can be */ 7 /* found in the LICENSE file at https://aka.ms/AzureRTOS_EULA */ 8 /* and in the root directory of this software. */ 9 /* */ 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 /* RELEASE HISTORY */ 69 /* */ 70 /* DATE NAME DESCRIPTION */ 71 /* */ 72 /* 05-19-2020 William E. Lamie Initial Version 6.0 */ 73 /* 09-30-2020 William E. Lamie Modified comment(s), */ 74 /* resulting in version 6.1 */ 75 /* 06-02-2021 Bhupendra Naphade Modified comment(s), */ 76 /* resulting in version 6.1.7 */ 77 /* */ 78 /**************************************************************************/ _lx_nand_flash_close(LX_NAND_FLASH * nand_flash)79UINT _lx_nand_flash_close(LX_NAND_FLASH *nand_flash) 80 { 81 82 LX_INTERRUPT_SAVE_AREA 83 84 85 /* Lockout interrupts for NAND flash close. */ 86 LX_DISABLE 87 88 /* See if the media is the only one on the media opened list. */ 89 if ((_lx_nand_flash_opened_ptr == nand_flash) && 90 (_lx_nand_flash_opened_ptr == nand_flash -> lx_nand_flash_open_next) && 91 (_lx_nand_flash_opened_ptr == nand_flash -> lx_nand_flash_open_previous)) 92 { 93 94 /* Only opened NAND flash, just set the opened list to NULL. */ 95 _lx_nand_flash_opened_ptr = LX_NULL; 96 } 97 else 98 { 99 100 /* Otherwise, not the only opened NAND flash, link-up the neighbors. */ 101 (nand_flash -> lx_nand_flash_open_next) -> lx_nand_flash_open_previous = 102 nand_flash -> lx_nand_flash_open_previous; 103 (nand_flash -> lx_nand_flash_open_previous) -> lx_nand_flash_open_next = 104 nand_flash -> lx_nand_flash_open_next; 105 106 /* See if we have to update the opened list head pointer. */ 107 if (_lx_nand_flash_opened_ptr == nand_flash) 108 { 109 110 /* Yes, move the head pointer to the next opened NAND flash. */ 111 _lx_nand_flash_opened_ptr = nand_flash -> lx_nand_flash_open_next; 112 } 113 } 114 115 /* Decrement the opened NAND flash counter. */ 116 _lx_nand_flash_opened_count--; 117 118 /* Finally, indicate that this NAND flash is closed. */ 119 nand_flash -> lx_nand_flash_state = LX_NAND_FLASH_CLOSED; 120 121 /* Restore interrupt posture. */ 122 LX_RESTORE 123 124 #ifdef LX_THREAD_SAFE_ENABLE 125 126 /* Delete the thread safe mutex. */ 127 tx_mutex_delete(&nand_flash -> lx_nand_flash_mutex); 128 #endif 129 /* Return success. */ 130 return(LX_SUCCESS); 131 } 132 133 134