Back to home page

LXR

 
 

    


File indexing completed on 2025-05-11 08:24:04

0001 /******************************************************************************
0002 * Copyright (C) 2015 - 2022 Xilinx, Inc.  All rights reserved.
0003 * SPDX-License-Identifier: MIT
0004 ******************************************************************************/
0005 
0006 /*****************************************************************************/
0007 /**
0008 *
0009 * @file xnandpsu_onfi.c
0010 * @addtogroup Overview
0011 * @{
0012 *
0013 * This file contains the implementation of ONFI specific functions.
0014 *
0015 * @note     None
0016 *
0017 * <pre>
0018 * MODIFICATION HISTORY:
0019 *
0020 * Ver   Who    Date    Changes
0021 * ----- ----   ----------  -----------------------------------------------
0022 * 1.0   nm     05/06/2014  First release
0023 * </pre>
0024 *
0025 ******************************************************************************/
0026 
0027 /***************************** Include Files *********************************/
0028 #include "xnandpsu_onfi.h"
0029 #include "xnandpsu.h"
0030 
0031 /************************** Constant Definitions *****************************/
0032 
0033 /**************************** Type Definitions *******************************/
0034 
0035 /***************** Macros (Inline Functions) Definitions *********************/
0036 
0037 /************************** Function Prototypes ******************************/
0038 
0039 /*****************************************************************************/
0040 /**
0041 *
0042 * This function calculates ONFI parameter page CRC.
0043 *
0044 * @param    ParamBuf is a pointer to the ONFI parameter page buffer.
0045 * @param    StartOff is the starting offset in buffer to calculate CRC.
0046 * @param    Length is the number of bytes for which CRC is calculated.
0047 *
0048 * @return
0049 *       CRC value.
0050 * @note
0051 *       None.
0052 *
0053 ******************************************************************************/
0054 u32 XNandPsu_OnfiParamPageCrc(u8 *ParamBuf, u32 StartOff, u32 Length)
0055 {
0056     const u32 CrcInit = 0x4F4EU;
0057     const u32 Order = 16U;
0058     const u32 Polynom = 0x8005U;
0059     u32 i, j, c, Bit;
0060     u32 Crc = CrcInit;
0061     u32 DataIn;
0062     u32 DataByteCount = 0U;
0063     u32 CrcMask, CrcHighBit;
0064 
0065     CrcMask = ((u32)(((u32)1 << (Order - (u32)1)) -(u32)1) << (u32)1) | (u32)1;
0066     CrcHighBit = (u32)((u32)1 << (Order - (u32)1));
0067     /*
0068      * CRC covers the data bytes between byte 0 and byte 253
0069      * (ONFI 1.0, section 5.4.1.36)
0070      */
0071     for(i = StartOff; i < Length; i++) {
0072         DataIn = *(ParamBuf + i);
0073         c = (u32)DataIn;
0074         DataByteCount++;
0075         j = 0x80U;
0076         while(j != 0U) {
0077             Bit = Crc & CrcHighBit;
0078             Crc <<= 1U;
0079             if ((c & j) != 0U) {
0080                 Bit ^= CrcHighBit;
0081             }
0082             if (Bit != 0U) {
0083                 Crc ^= Polynom;
0084             }
0085             j >>= 1U;
0086         }
0087         Crc &= CrcMask;
0088     }
0089     return Crc;
0090 }
0091 /** @} */