⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 m512_mtd.c

📁 M-System DOC(Disk on a Chip) Flash芯片的诊断工具, 可以从Flash芯片中获取特定的数据信息, 用于判断芯片当前的状态.
💻 C
📖 第 1 页 / 共 5 页
字号:

/***********************************************************************
 * Name : IsBCHError
 *    check if BCH syndrom occurred.
 *        None 0  - BCH ECC ERROR
 *        0       - NO ECC ERROR.
 ***********************************************************************/
#define M512_IsBCHError(flashPtr) \
    (M512_Read8BitReg(flashPtr,M512_ECC_CONTROL_REG_1) & \
     (Reg8bitType)M512_BCH_SYNDROM_ERROR)

/***********************************************************************
 * Name : IsHMError
 *    Check if Humming syndrom occurred.
 *        None 0  - HM ECC ERROR
 *        0       - NO ECC ERROR.
  ***********************************************************************/ 
#define M512_IsHMError(flashPtr) \
    (M512_Read8BitReg(flashPtr,M512_HAMMING_PARITY_REG))

/***********************************************************************
 * Name : IsPageInUse
 *    Check if the page is in use - was written.
 *    at least 2 zero bits in the hamming area.
 *        None 0  - Page in use.
 *        0       - Page not in use.
 ***********************************************************************/
#define M512_IsPageInUse(flashPtr) \
    (M512_Read8BitReg(flashPtr,M512_ECC_CONTROL_REG_1) & \
     (Reg8bitType)M512_PAGE_READ_IS_USED)

/***********************************************************************
 * Name : IsCustomerOTPLocked
 *   Checks if the customer OTP is M512_LOCKED
 *   None 0 - Customer OTP is locked
 *   0      - Customer OTP is not locked
 ***********************************************************************/
#define M512_IsCustomerOTPLocked(flashPtr) \
    (M512_Read8BitReg(flashPtr,M512_PROTECTION_STATUS_REG) & \
     (Reg8bitType)M512_CUSTOMER_OTP_LOCKED)

/***********************************************************************
 * Name : WriteEndOfData
 *   Write to M512_END_OF_DATA_REG 
 *
 * Returns: None
 ***********************************************************************/
#define M512_WriteEndOfData(flashPtr) (M512_Write8BitReg (flashPtr,M512_FLASH_END_OF_DATA_REG,0x00))

/***********************************************************************
 * Name : NOP
 *   Write to M512_NOP_REG 
 *
 * Returns: None
 ***********************************************************************/
#define M512_NOP(flashPtr) M512_Write8BitReg (flashPtr,M512_NOP_REG,0x00)


/***********************************************************************
 * Name : M512_Read8BitReg
 *  Read 8 bit register in two stages
 *  1. Write the address to the M512_ADDRESS_REG
 *  2. Read from the specified address (only important for debugging)
 *
 * Parameters:
 *    flashPtr:   The flash struct.
 *    wOffset:    The offset of the FLASH_DATA_REGISTER
 *
 * Returns: The value of this register 
 ***********************************************************************/
FLByte M512_Read8BitReg(FLFlash *flashPtr,FLWord wOffset) 
{       
  M512_Write16BitReg (flashPtr,M512_READ_ADDRESS_REG,wOffset) ;
  return (M512_DirectRead8BitReg (flashPtr,wOffset)) ;
}

/***********************************************************************
 * Name : M512_Read16BitReg
 *  Read 16 bit register in two stages
 *  1. Write the address to the M512_ADDRESS_REG
 *  2. Read from the specified address (only important for debugging)
 *
 * Parameters:
 *    flashPtr:   The flash struct.
 *    wOffset:    The offset of the FLASH_DATA_REGISTER
 *
 * Returns: The value of this register 
 ***********************************************************************/

FLWord M512_Read16BitReg(FLFlash *flashPtr,FLWord wOffset) 
{ 
  FLWord val,wTemp ;  
  
  if (flashPtr->if_cfg==16)     
  {   
    M512_Write16BitReg (flashPtr,M512_READ_ADDRESS_REG,wOffset) ;
    wTemp = M512_DirectRead16BitReg (flashPtr,wOffset) ;
    return LE2(*(LEushort *)&(wTemp)) ;
  }
  else
  {
    M512_Write16BitReg (flashPtr,M512_READ_ADDRESS_REG,wOffset) ;
    val = M512_DirectRead8BitReg (flashPtr,wOffset) ;
    M512_Write16BitReg (flashPtr,M512_READ_ADDRESS_REG,(FLWord)(wOffset+1)) ;
    return (val | M512_DirectRead8BitReg (flashPtr,wOffset)<<8) ;
 }
}

/************************************************************************
 ************************** Download functions **************************
 ************************************************************************/

/************************************************************************
 *  Name : M512_downloadStatus ()
 *
 *    Returns the download status of the current floor 
 *
 * Parameters:                                                          
 *    flashPtr: The flash struct.
 *
 * Returns : 
 *    flOK          : On success
 *    flBadDownload : Download failed
 ************************************************************************/
static FLStatus M512_downloadStatus (FLFlash *flashPtr)
{ 
  FLByte bTemp = M512_Read8BitReg(flashPtr,M512_DOWNLOAD_STATUS_REG);

#ifndef DEBUG_MTD
  if(bTemp & M512_DOWNLOAD_ERROR_BITS)
  { 
     DBG_PRINT_ERR(FLZONE_MTD,"Download failed \r\n");
     DBG_PRINT_ERR(FLZONE_MTD,"ERROR in M512_downloadStatus:Failed downloading.\r\n");
     return flBadDownload;
  }
  DBG_PRINT_FLOW(FLZONE_MTD,"Download status O.K ! \r\n");
  return flOK;

#else

  FLBoolean fDownloadSuccessFlag = TRUE ;

  if (bTemp & M512_DPS0_DOWNLOAD_ERROR_BITS)
  {  
    DBG_PRINT_ERR(FLZONE_MTD,"ERROR in M512_downloadStatus:DPS_0 Download Error.\r\n");
    fDownloadSuccessFlag=FALSE ;
  }
  
  if (bTemp & M512_DPS1_DOWNLOAD_ERROR_BITS)  
  {
    DBG_PRINT_ERR(FLZONE_MTD,"ERROR in M512_downloadStatus:DPS_1 Download Error.\r\n");
    fDownloadSuccessFlag=FALSE ;
  }

  if (bTemp & M512_IPL_DOWNLOAD_ERROR_BITS)  
  {
    DBG_PRINT_ERR(FLZONE_MTD,"ERROR in M512_downloadStatus:IPL Download Error.\r\n");  
    fDownloadSuccessFlag=FALSE ;
  }

  if (bTemp & M512_OTP_DOWNLOAD_ERROR)
  {
    DBG_PRINT_ERR(FLZONE_MTD,"ERROR in M512_downloadStatus:OTP Download Error.\r\n");
    fDownloadSuccessFlag=FALSE ;
  }

  return ((fDownloadSuccessFlag==TRUE) ? flOK : flBadDownload) ;  
#endif /* DEBUG_MTD */
}

/************************************************************************
 *  Name : M512_waitUntilDownloadFinished ()
 *
 *    Wait until download is finished (or timeout)
 *
 * Parameters:
 *    flashPtr: The flash struct.
 *
 * Returns :
 *    flOK      : Download is finished
 *    flTimedOut: Download TimeOut
 *    argsPackPtr->maxBitError : Reports the floor the did not download
 *
 ************************************************************************/
static FLStatus M512_waitUntilDownloadFinished (FLFlash *flashPtr,FLByte bNoOfFloorsToCheck)
{
  FLDword         i ;
  FLByte          bNoOfTimes      = 0;
  FLByte          bCurFloor;
  volatile FLWord wChipId,wChipIdConfirm;

  DBG_PRINT_FLOW(FLZONE_MTD,"Flow: M512_waitUntilDownloadFinished Entered.\r\n");

  /* perform 4 NOP reads before polling the ready register */
  for(i = 0 ; i < 4 ; i++)
     M512_NOP (flashPtr) ; 

  /* Loop over the floors and check chip_id, until we read it twice
   * Making sure the download is complete. Note the first floor can be 
   * detected using a dedicated register even in reset mode.
   */

  for (bCurFloor=0,i=0;bCurFloor<bNoOfFloorsToCheck;i++)
  {
     if(i>=M512_BUSY_DELAY)
     {
        DBG_PRINT_ERR (FLZONE_MTD,"ERROR: M512_waitUntilDownloadFinished download timeout \r\n");
        DBG_PRINT_ERR_PRM(FLZONE_MTD,(FLTXT("On floor %u.\r\n"),(FLWord)bCurFloor));      
        flashPtr->args.maxBitError = 1 << (bCurFloor+1);
        return flTimedOut;
     }

     M512_asicSetMode (flashPtr,NORMAL_MODE) ;
     M512_AsicSetFloor (flashPtr,bCurFloor) ;
     wChipId        = M512_ReadChipID(flashPtr);
     wChipIdConfirm = M512_ReadChipID_Confirm(flashPtr) ;      

     if((wChipId        != MTD_VARS->wChipId) || 
        (wChipIdConfirm != (FLWord)~MTD_VARS->wChipId))
     {
       bNoOfTimes = 0;
       continue;
     }

     bNoOfTimes++;
     if(bNoOfTimes == 2)
        bCurFloor++;
  } /* End of loop over the floors */

   /* Dummy read from M512 device to initialize state machine */
  M512_NOP (flashPtr) ;

  DBG_PRINT_FLOW(FLZONE_MTD,"Flow: M512_waitUntilDownloadFinished Exit success.\r\n");

  return flOK ; /* Exit when download finishes */
}

/************************************************************************
 *  Name : M512_FirstGoodUnitInit ()
 *
 *    Remove write protection from first good unit of each floor
 *
 * Parameters:
 *    flashPtr: The flash struct.
 *
 * Returns : void
 ************************************************************************/
static void M512_FirstGoodUnitInit(FLFlash * flashPtr)
{
  FLByte bNumOfFloors,bFirstGoodUnit;

  for (bNumOfFloors=0;bNumOfFloors<flashPtr->noOfFloors;bNumOfFloors++)
  {
    M512_AsicSetFloor (flashPtr,bNumOfFloors) ;
    /*** Write enable to the first Good Block ***/ 
    bFirstGoodUnit = M512_ReadFirstGoodUnit (flashPtr) ;
    M512_WriteEnableToFirstGoodBlock (flashPtr,bFirstGoodUnit) ;    
    DBG_PRINT_WRN_PRM(FLZONE_MTD,(FLTXT("Write Protection over unit %u is removed \r\n"),(FLWord)bFirstGoodUnit));
    MTD_VARS->FirstUsableBlock[bNumOfFloors] = (M512_DPS_1_MAIN_UNIT+2)<<1 ; 
  }
}

/************************************************************************
 ************************ Registration functions ************************
 ************************************************************************/

/************************************************************************
 * Name : M512_docWindowBaseAddress                                     *
 *                                                                      *
 * Return the host base address of the window.                          *
 * If the window base address is programmable, this routine selects     *
 * where the base address will be programmed to.                        *
 *                                                                      *
 * Parameters:                                                          *
 *      bSocketNo    :  Socket No (0..SOCKETS-1)                        *
 *      dwLowAddress :  host memory range to search - low address       *
 *      dwHighAddress:  host memory range to search - high address      *
 *      fResetAll    :  TRUE  - Send reset command before identifing    *
 *                      FALSE - Do not send the reset command, in order *
 *                              not clear the alias resolution register *
 *      dwNextAddressPtr: Returns the next address to start searching   *
 *                        the next socket in.                           * 
 *      dwDOC_PhyAddress: DOC Address found shifted left by 12          *
 * Returns:                                                             *
 *      Host physical address of window divided by 4 KB                 *
 *      dwNextAddressPtr :   The address of the next DiskOnChip.        *
 ************************************************************************/
FLStatus M512_docWindowBaseAddress       (FLByte    bSocketNo,
                                          FLDword   dwLowAddress,
                                          FLDword   dwHighAddress,

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -