lx_nand_flash_block_mapping_set.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_block_mapping_set PORTABLE C */ | ||
| 43 | /* 6.2.1 */ | ||
| 44 | /* AUTHOR */ | ||
| 45 | /* */ | ||
| 46 | /* Xiuwen Cai, Microsoft Corporation */ | ||
| 47 | /* */ | ||
| 48 | /* DESCRIPTION */ | ||
| 49 | /* */ | ||
| 50 | /* This function sets block mappings. */ | ||
| 51 | /* */ | ||
| 52 | /* INPUT */ | ||
| 53 | /* */ | ||
| 54 | /* nand_flash NAND flash instance */ | ||
| 55 | /* logical_sector Logical sector number */ | ||
| 56 | /* block Block number */ | ||
| 57 | /* */ | ||
| 58 | /* OUTPUT */ | ||
| 59 | /* */ | ||
| 60 | /* return status */ | ||
| 61 | /* */ | ||
| 62 | /* CALLS */ | ||
| 63 | /* */ | ||
| 64 | /* _lx_nand_flash_metadata_write Write metadata */ | ||
| 65 | /* */ | ||
| 66 | /* CALLED BY */ | ||
| 67 | /* */ | ||
| 68 | /* Internal LevelX */ | ||
| 69 | /* */ | ||
| 70 | /**************************************************************************/ | ||
| 71 | 13250 | UINT _lx_nand_flash_block_mapping_set(LX_NAND_FLASH *nand_flash, ULONG logical_sector, ULONG block) | |
| 72 | { | ||
| 73 | |||
| 74 | UINT block_mapping_index; | ||
| 75 | UCHAR page_number; | ||
| 76 | UINT status; | ||
| 77 | |||
| 78 | |||
| 79 | /* Get the mapping index from logic sector address. */ | ||
| 80 | 13250 | block_mapping_index = logical_sector / nand_flash -> lx_nand_flash_pages_per_block; | |
| 81 | |||
| 82 | /* Check the address range. */ | ||
| 83 |
1/2✗ Branch 2 → 3 not taken.
✓ Branch 2 → 4 taken 13250 times.
|
13250 | if (block_mapping_index > nand_flash -> lx_nand_flash_block_mapping_table_size / sizeof(*nand_flash -> lx_nand_flash_block_mapping_table)) |
| 84 | { | ||
| 85 | |||
| 86 | /* Out of range, return an error. */ | ||
| 87 | ✗ | return(LX_ERROR); | |
| 88 | } | ||
| 89 | |||
| 90 | /* Save the block number to mapping table. */ | ||
| 91 | 13250 | nand_flash -> lx_nand_flash_block_mapping_table[block_mapping_index] = (USHORT)block; | |
| 92 | |||
| 93 | /* Get the page number to write. */ | ||
| 94 | 13250 | page_number = (UCHAR)(block_mapping_index * sizeof(*nand_flash -> lx_nand_flash_block_mapping_table) / nand_flash -> lx_nand_flash_bytes_per_page); | |
| 95 | |||
| 96 | /* Save the mapping table. */ | ||
| 97 | 13250 | status = _lx_nand_flash_metadata_write(nand_flash, ((UCHAR*)nand_flash -> lx_nand_flash_block_mapping_table) + | |
| 98 | 13250 | page_number * nand_flash -> lx_nand_flash_bytes_per_page, | |
| 99 | 13250 | LX_NAND_PAGE_TYPE_BLOCK_MAPPING_TABLE | page_number); | |
| 100 | |||
| 101 | /* Return status. */ | ||
| 102 | 13250 | return(status); | |
| 103 | } | ||
| 104 | |||
| 105 |