lx_nand_flash_page_ecc_check.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_page_ecc_check PORTABLE C */ | ||
| 43 | /* 6.1.7 */ | ||
| 44 | /* AUTHOR */ | ||
| 45 | /* */ | ||
| 46 | /* William E. Lamie, Microsoft Corporation */ | ||
| 47 | /* */ | ||
| 48 | /* DESCRIPTION */ | ||
| 49 | /* */ | ||
| 50 | /* This function checks the NAND page and ECC for errors and */ | ||
| 51 | /* attempts to correct 1 bit errors. */ | ||
| 52 | /* */ | ||
| 53 | /* INPUT */ | ||
| 54 | /* */ | ||
| 55 | /* nand_flash NAND flash instance */ | ||
| 56 | /* page_buffer Page buffer */ | ||
| 57 | /* ecc_buffer Returned ECC buffer */ | ||
| 58 | /* */ | ||
| 59 | /* OUTPUT */ | ||
| 60 | /* */ | ||
| 61 | /* return status */ | ||
| 62 | /* */ | ||
| 63 | /* CALLS */ | ||
| 64 | /* */ | ||
| 65 | /* _lx_nand_flash_256byte_ecc_check Check 256 bytes and ECC */ | ||
| 66 | /* */ | ||
| 67 | /* CALLED BY */ | ||
| 68 | /* */ | ||
| 69 | /* NAND flash driver */ | ||
| 70 | /* */ | ||
| 71 | /**************************************************************************/ | ||
| 72 | 41000 | UINT _lx_nand_flash_page_ecc_check(LX_NAND_FLASH *nand_flash, UCHAR *page_buffer, UCHAR *ecc_buffer) | |
| 73 | { | ||
| 74 | |||
| 75 | UINT bytes_checked; | ||
| 76 | UINT status; | ||
| 77 | 41000 | UINT return_status = LX_SUCCESS; | |
| 78 | |||
| 79 | |||
| 80 | /* Loop to check the entire NAND flash page. */ | ||
| 81 | 41000 | bytes_checked = 0; | |
| 82 |
2/2✓ Branch 10 → 3 taken 81990 times.
✓ Branch 10 → 11 taken 40980 times.
|
122970 | while (bytes_checked < nand_flash -> lx_nand_flash_bytes_per_page) |
| 83 | { | ||
| 84 | |||
| 85 | /* Check this 256 byte piece of the NAND page. */ | ||
| 86 | 81990 | status = _lx_nand_flash_256byte_ecc_check(page_buffer, ecc_buffer); | |
| 87 | |||
| 88 | /* Determine if there was an error. */ | ||
| 89 |
2/2✓ Branch 4 → 5 taken 41010 times.
✓ Branch 4 → 9 taken 40980 times.
|
81990 | if (status != LX_SUCCESS) |
| 90 | { | ||
| 91 | |||
| 92 | /* Determine if a non-correctable error is present. */ | ||
| 93 |
2/2✓ Branch 5 → 6 taken 20 times.
✓ Branch 5 → 7 taken 40990 times.
|
41010 | if (status == LX_NAND_ERROR_NOT_CORRECTED) |
| 94 | { | ||
| 95 | |||
| 96 | /* Always return a non-correctable error, if present. */ | ||
| 97 | 20 | return_status = LX_NAND_ERROR_NOT_CORRECTED; | |
| 98 | 20 | break; | |
| 99 | } | ||
| 100 | |||
| 101 | /* A single-bit error was corrected, return this status | ||
| 102 | if there is no LX_ERROR status already detected. */ | ||
| 103 |
2/2✓ Branch 7 → 8 taken 40980 times.
✓ Branch 7 → 9 taken 10 times.
|
40990 | else if (return_status == LX_SUCCESS) |
| 104 | { | ||
| 105 | |||
| 106 | /* Return a notice that the single bit error was corrected. */ | ||
| 107 | 40980 | return_status = LX_NAND_ERROR_CORRECTED; | |
| 108 | } | ||
| 109 | } | ||
| 110 | |||
| 111 | /* Move to the next 256 byte portion of the page. */ | ||
| 112 | 81970 | bytes_checked = bytes_checked + 256; | |
| 113 | |||
| 114 | /* Move the page buffer forward. */ | ||
| 115 | 81970 | page_buffer = page_buffer + 256; | |
| 116 | |||
| 117 | /* Move the ECC buffer forward, note there are 3 bytes of ECC per page. */ | ||
| 118 | 81970 | ecc_buffer = ecc_buffer + 3; | |
| 119 | } | ||
| 120 | |||
| 121 | /* Return status. */ | ||
| 122 | 41000 | return(return_status); | |
| 123 | } | ||
| 124 | |||
| 125 |