mirror of
https://github.com/eclipse-threadx/levelx.git
synced 2026-09-15 04:55:33 +08:00
Updated copyright headers and removed trailing whitespace
This commit is contained in:
@@ -1,18 +1,19 @@
|
||||
/***************************************************************************
|
||||
* Copyright (c) 2024 Microsoft Corporation
|
||||
*
|
||||
* Copyright (c) 2024 Microsoft Corporation
|
||||
* Copyright (c) 2026-present Eclipse ThreadX contributors
|
||||
*
|
||||
* This program and the accompanying materials are made available under the
|
||||
* terms of the MIT License which is available at
|
||||
* https://opensource.org/licenses/MIT.
|
||||
*
|
||||
*
|
||||
* SPDX-License-Identifier: MIT
|
||||
**************************************************************************/
|
||||
|
||||
|
||||
/**************************************************************************/
|
||||
/**************************************************************************/
|
||||
/** */
|
||||
/** LevelX Component */
|
||||
/** */
|
||||
/** LevelX Component */
|
||||
/** */
|
||||
/** NAND Flash */
|
||||
/** */
|
||||
@@ -34,51 +35,38 @@
|
||||
#include "lx_api.h"
|
||||
|
||||
|
||||
/**************************************************************************/
|
||||
/* */
|
||||
/* FUNCTION RELEASE */
|
||||
/* */
|
||||
/* _lx_nand_flash_256byte_ecc_compute PORTABLE C */
|
||||
/**************************************************************************/
|
||||
/* */
|
||||
/* FUNCTION RELEASE */
|
||||
/* */
|
||||
/* _lx_nand_flash_256byte_ecc_compute PORTABLE C */
|
||||
/* 6.2.1 */
|
||||
/* AUTHOR */
|
||||
/* */
|
||||
/* William E. Lamie, Microsoft Corporation */
|
||||
/* */
|
||||
/* DESCRIPTION */
|
||||
/* */
|
||||
/* This function computes the ECC for 256 bytes of a NAND flash page. */
|
||||
/* The resulting ECC code is returned in 3 bytes. */
|
||||
/* */
|
||||
/* INPUT */
|
||||
/* */
|
||||
/* page_buffer Page buffer */
|
||||
/* ecc_buffer Returned ECC buffer */
|
||||
/* */
|
||||
/* OUTPUT */
|
||||
/* */
|
||||
/* return status */
|
||||
/* */
|
||||
/* CALLS */
|
||||
/* */
|
||||
/* None */
|
||||
/* */
|
||||
/* CALLED BY */
|
||||
/* */
|
||||
/* _lx_nand_flash_page_ecc_compute NAND page ECC compute */
|
||||
/* _lx_nand_flash_256byte_ecc_check Check 256 bytes and ECC */
|
||||
/* */
|
||||
/* RELEASE HISTORY */
|
||||
/* */
|
||||
/* DATE NAME DESCRIPTION */
|
||||
/* DESCRIPTION */
|
||||
/* */
|
||||
/* 05-19-2020 William E. Lamie Initial Version 6.0 */
|
||||
/* 09-30-2020 William E. Lamie Modified comment(s), */
|
||||
/* resulting in version 6.1 */
|
||||
/* 06-02-2021 Bhupendra Naphade Modified comment(s), */
|
||||
/* resulting in version 6.1.7 */
|
||||
/* 03-08-2023 Xiuwen Cai Modified comment(s), */
|
||||
/* inverted output, */
|
||||
/* resulting in version 6.2.1 */
|
||||
/* This function computes the ECC for 256 bytes of a NAND flash page. */
|
||||
/* The resulting ECC code is returned in 3 bytes. */
|
||||
/* */
|
||||
/* INPUT */
|
||||
/* */
|
||||
/* page_buffer Page buffer */
|
||||
/* ecc_buffer Returned ECC buffer */
|
||||
/* */
|
||||
/* OUTPUT */
|
||||
/* */
|
||||
/* return status */
|
||||
/* */
|
||||
/* CALLS */
|
||||
/* */
|
||||
/* None */
|
||||
/* */
|
||||
/* CALLED BY */
|
||||
/* */
|
||||
/* _lx_nand_flash_page_ecc_compute NAND page ECC compute */
|
||||
/* _lx_nand_flash_256byte_ecc_check Check 256 bytes and ECC */
|
||||
/* */
|
||||
/**************************************************************************/
|
||||
UINT _lx_nand_flash_256byte_ecc_compute(UCHAR *page_buffer, UCHAR *ecc_buffer)
|
||||
@@ -105,27 +93,27 @@ USHORT odd_byte_parity;
|
||||
ecc_buffer[0]= 0;
|
||||
ecc_buffer[1]= 0;
|
||||
ecc_buffer[2]= 0;
|
||||
|
||||
|
||||
/* Setup a 16-bit pointer to the buffer area. */
|
||||
data = (USHORT *) page_buffer;
|
||||
|
||||
|
||||
/* Loop through the 256 byte buffer, 16 bits at a time. */
|
||||
for (i = 0; i < 128; i++)
|
||||
for (i = 0; i < 128; i++)
|
||||
{
|
||||
|
||||
/* Compute the ECC value. */
|
||||
bit_parity = bit_parity ^ data[i];
|
||||
|
||||
|
||||
/* Now count the bits in the current data word. */
|
||||
bits = 0;
|
||||
mask = 1;
|
||||
for (j = 0; j < 16; j++)
|
||||
{
|
||||
|
||||
/* Is the bit set? */
|
||||
/* Is the bit set? */
|
||||
if (data[i] & mask)
|
||||
{
|
||||
|
||||
|
||||
/* Yes, increment the bit count. */
|
||||
bits++;
|
||||
}
|
||||
@@ -133,11 +121,11 @@ USHORT odd_byte_parity;
|
||||
/* Move the mask to the next bit. */
|
||||
mask = (USHORT) ((mask << 1) & 0xFFFF);
|
||||
}
|
||||
|
||||
|
||||
/* Determine if the number of bits is odd. */
|
||||
if ((bits & 1) == 1)
|
||||
if ((bits & 1) == 1)
|
||||
{
|
||||
|
||||
|
||||
/* Odd number of bits. Adjust the odd/even byte parity. */
|
||||
even_byte_parity = (USHORT) ((even_byte_parity ^ (0xffff - i)) & 0xFFFF);
|
||||
odd_byte_parity = odd_byte_parity ^ i;
|
||||
@@ -145,11 +133,11 @@ USHORT odd_byte_parity;
|
||||
}
|
||||
|
||||
/* Now look for bits set in the bit parity. */
|
||||
for (i = 0; i < 16; i++)
|
||||
for (i = 0; i < 16; i++)
|
||||
{
|
||||
|
||||
/* Is the bit set? */
|
||||
if (bit_parity & 1)
|
||||
if (bit_parity & 1)
|
||||
{
|
||||
|
||||
/* Yes, adjust the odd even byte parity. */
|
||||
@@ -160,21 +148,21 @@ USHORT odd_byte_parity;
|
||||
/* Look at next bit position. */
|
||||
bit_parity = bit_parity >> 1;
|
||||
}
|
||||
|
||||
|
||||
/* At this point, we need to pack the 22 ECC bits into the 3 byte return area. */
|
||||
|
||||
|
||||
/* Pack bit 21. */
|
||||
ecc_buffer[(21+2)/8] = ((UCHAR)(ecc_buffer[(21+2)/8] | ((odd_byte_parity >> 6) & 1) << (21+2)%8) & 0xFF);
|
||||
|
||||
|
||||
/* Pack bit 20. */
|
||||
ecc_buffer[(20+2)/8] = ((UCHAR)(ecc_buffer[(20+2)/8] | ((even_byte_parity >> 6) & 1) << (20+2)%8) & 0xFF);
|
||||
|
||||
|
||||
/* Pack bit 19. */
|
||||
ecc_buffer[(19+2)/8] = ((UCHAR)(ecc_buffer[(19+2)/8] | ((odd_byte_parity >> 5) & 1) << (19+2)%8) & 0xFF);
|
||||
|
||||
/* Pack bit 18. */
|
||||
ecc_buffer[(18+2)/8] = ((UCHAR)(ecc_buffer[(18+2)/8] | ((even_byte_parity >> 5) & 1) << (18+2)%8) & 0xFF);
|
||||
|
||||
|
||||
/* Pack bit 17. */
|
||||
ecc_buffer[(17+2)/8] = ((UCHAR)(ecc_buffer[(17+2)/8] | ((odd_byte_parity >> 4) & 1) << (17+2)%8) & 0xFF);
|
||||
|
||||
@@ -189,7 +177,7 @@ USHORT odd_byte_parity;
|
||||
|
||||
/* Pack bit 13. */
|
||||
ecc_buffer[(13+2)/8] = ((UCHAR)(ecc_buffer[(13+2)/8] | ((odd_byte_parity >> 2) & 1) << (13+2)%8) & 0xFF);
|
||||
|
||||
|
||||
/* Pack bit 12. */
|
||||
ecc_buffer[(12+2)/8] = ((UCHAR)(ecc_buffer[(12+2)/8] | ((even_byte_parity >> 2) & 1) << (12+2)%8) & 0xFF);
|
||||
|
||||
@@ -199,18 +187,18 @@ USHORT odd_byte_parity;
|
||||
/* Pack bit 10. */
|
||||
ecc_buffer[(10+2)/8] = ((UCHAR)(ecc_buffer[(10+2)/8] | ((even_byte_parity >> 1) & 1) << (10+2)%8) & 0xFF);
|
||||
|
||||
/* Pack bit 9. */
|
||||
/* Pack bit 9. */
|
||||
ecc_buffer[(9+2)/8] = ((UCHAR)(ecc_buffer[(9+2)/8] | ((odd_byte_parity >> 0) & 1) << (9+2)%8) & 0xFF);
|
||||
|
||||
/* Pack bit 8. */
|
||||
/* Pack bit 8. */
|
||||
ecc_buffer[(8+2)/8] = ((UCHAR)(ecc_buffer[(8+2)/8] | ((even_byte_parity >> 0) & 1) << (8+2)%8) & 0xFF);
|
||||
|
||||
/* Pack bit 7. */
|
||||
ecc_buffer[(7+2)/8] = ((UCHAR)(ecc_buffer[(7+2)/8] | ((odd_bit_parity >> 3) & 1) << (7+2)%8) & 0xFF);
|
||||
|
||||
|
||||
/* Pack bit 6. */
|
||||
ecc_buffer[(6+2)/8] = ((UCHAR)(ecc_buffer[(6+2)/8] | ((even_bit_parity >> 3) & 1) << (6+2)%8) & 0xFF);
|
||||
|
||||
|
||||
/* Pack bit 5. */
|
||||
ecc_buffer[(5+2)/8] = ((UCHAR)(ecc_buffer[(5+2)/8] | ((odd_bit_parity >> 2) & 1) << (5+2)%8) & 0xFF);
|
||||
|
||||
@@ -223,10 +211,10 @@ USHORT odd_byte_parity;
|
||||
/* Pack bit 2. */
|
||||
ecc_buffer[(2+2)/8] = ((UCHAR)(ecc_buffer[(2+2)/8] | ((even_bit_parity >> 1) & 1) << (2+2)%8) & 0xFF);
|
||||
|
||||
/* Pack bit 1. */
|
||||
/* Pack bit 1. */
|
||||
ecc_buffer[(1+2)/8] = ((UCHAR)(ecc_buffer[(1+2)/8] | ((odd_bit_parity >> 0) & 1) << (1+2)%8) & 0xFF);
|
||||
|
||||
/* Pack bit 0. */
|
||||
/* Pack bit 0. */
|
||||
ecc_buffer[(0+2)/8] = ((UCHAR)(ecc_buffer[(0+2)/8] | ((even_bit_parity >> 0) & 1) << (0+2)%8) & 0xFF);
|
||||
|
||||
ecc_buffer[0] = (UCHAR)~ecc_buffer[0];
|
||||
|
||||
Reference in New Issue
Block a user