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 |
|
|
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 |
|
|
UINT return_status = LX_SUCCESS; |
78 |
|
|
|
79 |
|
|
|
80 |
|
|
/* Loop to check the entire NAND flash page. */ |
81 |
|
|
bytes_checked = 0; |
82 |
|
|
while (bytes_checked < nand_flash -> lx_nand_flash_bytes_per_page) |
83 |
|
|
{ |
84 |
|
|
|
85 |
|
|
/* Check this 256 byte piece of the NAND page. */ |
86 |
|
|
status = _lx_nand_flash_256byte_ecc_check(page_buffer, ecc_buffer); |
87 |
|
|
|
88 |
|
|
/* Determine if there was an error. */ |
89 |
|
|
if (status != LX_SUCCESS) |
90 |
|
|
{ |
91 |
|
|
|
92 |
|
|
/* Determine if a non-correctable error is present. */ |
93 |
|
|
if (status == LX_NAND_ERROR_NOT_CORRECTED) |
94 |
|
|
{ |
95 |
|
|
|
96 |
|
|
/* Always return a non-correctable error, if present. */ |
97 |
|
|
return_status = LX_NAND_ERROR_NOT_CORRECTED; |
98 |
|
|
break; |
99 |
|
|
} |
100 |
|
|
|
101 |
|
|
/* A single-bit error was corrected, return this status |
102 |
|
|
if there is no LX_ERROR status already detected. */ |
103 |
|
|
else if (return_status == LX_SUCCESS) |
104 |
|
|
{ |
105 |
|
|
|
106 |
|
|
/* Return a notice that the single bit error was corrected. */ |
107 |
|
|
return_status = LX_NAND_ERROR_CORRECTED; |
108 |
|
|
} |
109 |
|
|
} |
110 |
|
|
|
111 |
|
|
/* Move to the next 256 byte portion of the page. */ |
112 |
|
|
bytes_checked = bytes_checked + 256; |
113 |
|
|
|
114 |
|
|
/* Move the page buffer forward. */ |
115 |
|
|
page_buffer = page_buffer + 256; |
116 |
|
|
|
117 |
|
|
/* Move the ECC buffer forward, note there are 3 bytes of ECC per page. */ |
118 |
|
|
ecc_buffer = ecc_buffer + 3; |
119 |
|
|
} |
120 |
|
|
|
121 |
|
|
/* Return status. */ |
122 |
|
|
return(return_status); |
123 |
|
|
} |
124 |
|
|
|