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_compute PORTABLE C */ |
43 |
|
|
/* 6.1.7 */ |
44 |
|
|
/* AUTHOR */ |
45 |
|
|
/* */ |
46 |
|
|
/* William E. Lamie, Microsoft Corporation */ |
47 |
|
|
/* */ |
48 |
|
|
/* DESCRIPTION */ |
49 |
|
|
/* */ |
50 |
|
|
/* This function computes the ECC for a NAND flash page. */ |
51 |
|
|
/* */ |
52 |
|
|
/* INPUT */ |
53 |
|
|
/* */ |
54 |
|
|
/* nand_flash NAND flash instance */ |
55 |
|
|
/* page_buffer Page buffer */ |
56 |
|
|
/* ecc_buffer Returned ECC buffer */ |
57 |
|
|
/* */ |
58 |
|
|
/* OUTPUT */ |
59 |
|
|
/* */ |
60 |
|
|
/* return status */ |
61 |
|
|
/* */ |
62 |
|
|
/* CALLS */ |
63 |
|
|
/* */ |
64 |
|
|
/* _lx_nand_flash_256byte_ecc_compute Compute ECC for 256 bytes */ |
65 |
|
|
/* */ |
66 |
|
|
/* CALLED BY */ |
67 |
|
|
/* */ |
68 |
|
|
/* NAND flash driver */ |
69 |
|
|
/* */ |
70 |
|
|
/**************************************************************************/ |
71 |
|
|
UINT _lx_nand_flash_page_ecc_compute(LX_NAND_FLASH *nand_flash, UCHAR *page_buffer, UCHAR *ecc_buffer) |
72 |
|
|
{ |
73 |
|
|
|
74 |
|
|
UINT bytes_computed; |
75 |
|
|
|
76 |
|
|
|
77 |
|
|
/* Loop to compute the ECC over the entire NAND flash page. */ |
78 |
|
|
bytes_computed = 0; |
79 |
|
|
while (bytes_computed < nand_flash -> lx_nand_flash_bytes_per_page) |
80 |
|
|
{ |
81 |
|
|
|
82 |
|
|
/* Compute the ECC for this 256 byte piece of the page. */ |
83 |
|
|
_lx_nand_flash_256byte_ecc_compute(page_buffer, ecc_buffer); |
84 |
|
|
|
85 |
|
|
/* Move to the next 256 byte portion of the page. */ |
86 |
|
|
bytes_computed = bytes_computed + 256; |
87 |
|
|
|
88 |
|
|
/* Move the page buffer forward. */ |
89 |
|
|
page_buffer = page_buffer + 256; |
90 |
|
|
|
91 |
|
|
/* Move the ECC buffer forward, note there are 3 bytes of ECC per page. */ |
92 |
|
|
ecc_buffer = ecc_buffer + 3; |
93 |
|
|
} |
94 |
|
|
|
95 |
|
|
/* Return success. */ |
96 |
|
|
return(LX_SUCCESS); |
97 |
|
|
} |
98 |
|
|
|