lx_nand_flash_mapped_block_list_add.c
| 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 | /** 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_mapped_block_list_add PORTABLE C */ | ||
| 43 | /* 6.2.1 */ | ||
| 44 | /* AUTHOR */ | ||
| 45 | /* */ | ||
| 46 | /* Xiuwen Cai, Microsoft Corporation */ | ||
| 47 | /* */ | ||
| 48 | /* DESCRIPTION */ | ||
| 49 | /* */ | ||
| 50 | /* This function adds a block to mapped block list. */ | ||
| 51 | /* */ | ||
| 52 | /* INPUT */ | ||
| 53 | /* */ | ||
| 54 | /* nand_flash NAND flash instance */ | ||
| 55 | /* block_mapping_index Block mapping index */ | ||
| 56 | /* */ | ||
| 57 | /* OUTPUT */ | ||
| 58 | /* */ | ||
| 59 | /* return status */ | ||
| 60 | /* */ | ||
| 61 | /* CALLS */ | ||
| 62 | /* */ | ||
| 63 | /* None */ | ||
| 64 | /* */ | ||
| 65 | /* CALLED BY */ | ||
| 66 | /* */ | ||
| 67 | /* Internal LevelX */ | ||
| 68 | /* */ | ||
| 69 | /**************************************************************************/ | ||
| 70 | 13280 | UINT _lx_nand_flash_mapped_block_list_add(LX_NAND_FLASH* nand_flash, ULONG block_mapping_index) | |
| 71 | { | ||
| 72 | |||
| 73 | ULONG insert_position; | ||
| 74 | ULONG search_position; | ||
| 75 | UCHAR new_block_erase_count; | ||
| 76 | |||
| 77 | |||
| 78 | /* Get insert position for the mapped block list. */ | ||
| 79 | 13280 | insert_position = nand_flash -> lx_nand_flash_mapped_block_list_head; | |
| 80 | |||
| 81 | /* Check if the list if full. */ | ||
| 82 |
1/2✗ Branch 2 → 3 not taken.
✓ Branch 2 → 4 taken 13280 times.
|
13280 | if (insert_position < nand_flash -> lx_nand_flash_free_block_list_tail) |
| 83 | { | ||
| 84 | |||
| 85 | /* Return an error. */ | ||
| 86 | ✗ | return(LX_ERROR); | |
| 87 | } | ||
| 88 | |||
| 89 | /* Get the erase count. */ | ||
| 90 | 13280 | new_block_erase_count = nand_flash -> lx_nand_flash_erase_count_table[nand_flash -> lx_nand_flash_block_mapping_table[block_mapping_index]]; | |
| 91 | |||
| 92 | /* Add one block to the free list. */ | ||
| 93 | 13280 | nand_flash -> lx_nand_flash_mapped_block_list_head--; | |
| 94 | |||
| 95 | /* Initialize the search pointer. */ | ||
| 96 | 13280 | search_position = insert_position + 1; | |
| 97 | |||
| 98 | /* Loop to search the insert position. */ | ||
| 99 |
2/2✓ Branch 6 → 7 taken 589980 times.
✓ Branch 6 → 8 taken 1670 times.
|
591650 | while ((search_position < nand_flash -> lx_nand_flash_block_list_size) && |
| 100 |
2/2✓ Branch 7 → 5 taken 578370 times.
✓ Branch 7 → 8 taken 11610 times.
|
589980 | (nand_flash -> lx_nand_flash_erase_count_table[nand_flash -> lx_nand_flash_block_mapping_table[nand_flash -> lx_nand_flash_block_list[search_position]]] < new_block_erase_count)) |
| 101 | { | ||
| 102 | |||
| 103 | /* Move the item in the list. */ | ||
| 104 | 578370 | nand_flash -> lx_nand_flash_block_list[insert_position] = nand_flash -> lx_nand_flash_block_list[search_position]; | |
| 105 | 578370 | search_position++; | |
| 106 | 578370 | insert_position++; | |
| 107 | } | ||
| 108 | |||
| 109 | /* Insert the new block to the list. */ | ||
| 110 | 13280 | nand_flash -> lx_nand_flash_block_list[insert_position] = (USHORT)block_mapping_index; | |
| 111 | |||
| 112 | /* Return successful completion. */ | ||
| 113 | 13280 | return(LX_SUCCESS); | |
| 114 | } | ||
| 115 | |||
| 116 |