1 |
|
|
/*************************************************************************** |
2 |
|
|
* Copyright (c) 2024 Microsoft Corporation |
3 |
|
|
* |
4 |
|
|
* This program and the accompanying materials are made available under the |
5 |
|
|
* terms of the MIT License which is available at |
6 |
|
|
* https://opensource.org/licenses/MIT. |
7 |
|
|
* |
8 |
|
|
* SPDX-License-Identifier: MIT |
9 |
|
|
**************************************************************************/ |
10 |
|
|
|
11 |
|
|
|
12 |
|
|
/**************************************************************************/ |
13 |
|
|
/**************************************************************************/ |
14 |
|
|
/** */ |
15 |
|
|
/** LevelX Component */ |
16 |
|
|
/** */ |
17 |
|
|
/** NAND Flash */ |
18 |
|
|
/** */ |
19 |
|
|
/**************************************************************************/ |
20 |
|
|
/**************************************************************************/ |
21 |
|
|
|
22 |
|
|
#define LX_SOURCE_CODE |
23 |
|
|
|
24 |
|
|
|
25 |
|
|
/* Disable ThreadX error checking. */ |
26 |
|
|
|
27 |
|
|
#ifndef LX_DISABLE_ERROR_CHECKING |
28 |
|
|
#define LX_DISABLE_ERROR_CHECKING |
29 |
|
|
#endif |
30 |
|
|
|
31 |
|
|
|
32 |
|
|
/* Include necessary system files. */ |
33 |
|
|
|
34 |
|
|
#include "lx_api.h" |
35 |
|
|
|
36 |
|
|
|
37 |
|
|
/**************************************************************************/ |
38 |
|
|
/* */ |
39 |
|
|
/* FUNCTION RELEASE */ |
40 |
|
|
/* */ |
41 |
|
|
/* _lx_nand_flash_page_ecc_compute PORTABLE C */ |
42 |
|
|
/* 6.1.7 */ |
43 |
|
|
/* AUTHOR */ |
44 |
|
|
/* */ |
45 |
|
|
/* William E. Lamie, Microsoft Corporation */ |
46 |
|
|
/* */ |
47 |
|
|
/* DESCRIPTION */ |
48 |
|
|
/* */ |
49 |
|
|
/* This function computes the ECC for a NAND flash page. */ |
50 |
|
|
/* */ |
51 |
|
|
/* INPUT */ |
52 |
|
|
/* */ |
53 |
|
|
/* nand_flash NAND flash instance */ |
54 |
|
|
/* page_buffer Page buffer */ |
55 |
|
|
/* ecc_buffer Returned ECC buffer */ |
56 |
|
|
/* */ |
57 |
|
|
/* OUTPUT */ |
58 |
|
|
/* */ |
59 |
|
|
/* return status */ |
60 |
|
|
/* */ |
61 |
|
|
/* CALLS */ |
62 |
|
|
/* */ |
63 |
|
|
/* _lx_nand_flash_256byte_ecc_compute Compute ECC for 256 bytes */ |
64 |
|
|
/* */ |
65 |
|
|
/* CALLED BY */ |
66 |
|
|
/* */ |
67 |
|
|
/* NAND flash driver */ |
68 |
|
|
/* */ |
69 |
|
|
/* RELEASE HISTORY */ |
70 |
|
|
/* */ |
71 |
|
|
/* DATE NAME DESCRIPTION */ |
72 |
|
|
/* */ |
73 |
|
|
/* 05-19-2020 William E. Lamie Initial Version 6.0 */ |
74 |
|
|
/* 09-30-2020 William E. Lamie Modified comment(s), */ |
75 |
|
|
/* resulting in version 6.1 */ |
76 |
|
|
/* 06-02-2021 Bhupendra Naphade Modified comment(s), */ |
77 |
|
|
/* resulting in version 6.1.7 */ |
78 |
|
|
/* */ |
79 |
|
|
/**************************************************************************/ |
80 |
|
|
UINT _lx_nand_flash_page_ecc_compute(LX_NAND_FLASH *nand_flash, UCHAR *page_buffer, UCHAR *ecc_buffer) |
81 |
|
|
{ |
82 |
|
|
|
83 |
|
|
UINT bytes_computed; |
84 |
|
|
|
85 |
|
|
|
86 |
|
|
/* Loop to compute the ECC over the entire NAND flash page. */ |
87 |
|
|
bytes_computed = 0; |
88 |
|
|
while (bytes_computed < nand_flash -> lx_nand_flash_bytes_per_page) |
89 |
|
|
{ |
90 |
|
|
|
91 |
|
|
/* Compute the ECC for this 256 byte piece of the page. */ |
92 |
|
|
_lx_nand_flash_256byte_ecc_compute(page_buffer, ecc_buffer); |
93 |
|
|
|
94 |
|
|
/* Move to the next 256 byte portion of the page. */ |
95 |
|
|
bytes_computed = bytes_computed + 256; |
96 |
|
|
|
97 |
|
|
/* Move the page buffer forward. */ |
98 |
|
|
page_buffer = page_buffer + 256; |
99 |
|
|
|
100 |
|
|
/* Move the ECC buffer forward, note there are 3 bytes of ECC per page. */ |
101 |
|
|
ecc_buffer = ecc_buffer + 3; |
102 |
|
|
} |
103 |
|
|
|
104 |
|
|
/* Return success. */ |
105 |
|
|
return(LX_SUCCESS); |
106 |
|
|
} |
107 |
|
|
|