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

📄 device.c

📁 嵌入式单片机下可做对Intel flash编程的代码
💻 C
📖 第 1 页 / 共 3 页
字号:
   offset++;

   extquery->OptionalFeature = 0;
   for ( i=0; i < 4; i++ )
   {
      stat = TMPL_GetQueryAddress(offset, &add);

      if ( stat.Result != StatCompleted )
      {
         return( stat );
      }

      TMPL_ReadF( add, &item );
      item &= 0xff;
	  longitem = (UINT32)((UINT32)item << (8*i));
      extquery->OptionalFeature = (UINT32)
                                 ( extquery->OptionalFeature | longitem ); 
      offset++;
   }

   /* read after suspend functions */
   stat = TMPL_GetQueryAddress(offset, &add);

   if ( stat.Result != StatCompleted )
   {
      return( stat );
   }

   TMPL_ReadF( add, &item );
   item &= 0xff;
   extquery->AfterSuspendFunctions = (UINT8)item;
   offset++;

   /* read vendor id */
   extquery->BlockLockStatus = 0;
   for ( i=0; i < 2; i++ )
   {
      stat = TMPL_GetQueryAddress(offset, &add);

      if ( stat.Result != StatCompleted )
      {
         return( stat );
      }

      TMPL_ReadF( add, &item );
      item &= 0xff;
	  item = item << (8*i);
      extquery->BlockLockStatus = (UINT16)
                                    ( extquery->BlockLockStatus | item ); 
      offset++;
   }

   /* read vcc optimum */
   stat = TMPL_GetQueryAddress(offset, &add);

   if ( stat.Result != StatCompleted )
   {
      return( stat );
   }

   TMPL_ReadF( add, &item );
   item &= 0xff;
   extquery->VccOptimum = (UINT8)item;
   offset++;

   /* read vpp optimum */
   stat = TMPL_GetQueryAddress(offset, &add);

   if ( stat.Result != StatCompleted )
   {
      return( stat );
   }

   TMPL_ReadF( add, &item );
   item &= 0xff;
   extquery->VppOptimum = (UINT8)item;
   offset++;

   stat.Result = StatCompleted;

   TMPL_WriteF(TMPL_BASE_FLASH_ADDRESS, TMPL_READ_ARRAY );

   return( stat );

}
#endif /* X_16 */

/****************************************************************************
 *
 * TMPL_GetBlockAddress
 *
 * Description:   
 *
 *    This procedure is called to get the flash starting address for the
 *    specified block number.
 *
 * Parameters:
 *
 *    IN      blocknum - the block number on the device.
 *
 *    OUT     address  - the starting flash address for the specified
 *                       block.
 *
 * Returns:   
 *
 *    TMPL_Status - includes function return status defined by enum
 *                  TMPL_CommandStat.
 *
 * Assumptions:
 *
 *    NONE
 *
 ***************************************************************************/
TMPL_Status TMPL_GetBlockAddress( UINT16 blocknum, UINT32_PTR address )
{
   TMPL_Status stat;
   UINT32 temp;

   if ( blocknum > ( TMPL_TOTAL_NUMBLOCKS - 1 ) )
   {
      stat.Result = StatBadBlock;
      return( stat );  
   }

   if ( blocknum < TMPL_SET1_NUMBLOCKS )
   {
      *address = TMPL_BASE_FLASH_ADDRESS + ( blocknum * TMPL_SET1_NUMBYTES );
   }
   else
   {
      *address = TMPL_BASE_FLASH_ADDRESS + ( TMPL_SET1_SIZE ) +
             ( ( blocknum - TMPL_SET1_NUMBLOCKS ) * TMPL_SET2_NUMBYTES );


   }

   stat.Result = StatCompleted;

   return( stat );
}


/****************************************************************************
 *
 * TMPL_LockBlock
 *
 * Description:   
 *
 *    This procedure is called to lock the specified block on the flash
 *    device.  See the flash device datasheet for specific details on this 
 *    command.
 *
 * Parameters:
 *
 *    IN      blocknum - the block number on the device.
 *
 *    IN      returnSR - flag to indicate whether the device status register
 *                       value should be returned by this function.
 *
 * Returns:   
 *
 *    TMPL_Status - includes function return status defined by enum
 *                  command_stat and optionally the flash device
 *                  status register value.
 *
 * Assumptions:
 *
 *    NONE
 *
 ***************************************************************************/
TMPL_Status TMPL_LockBlock      ( UINT16 blocknum,
                                  UINT8  returnSR )
{
   TMPL_Status   stat;
   UINT32   blockadd;
   
   stat = TMPL_GetBlockAddress( blocknum, &blockadd );

   if ( stat.Result != StatCompleted )
   {
	  return( stat );
   }

   if ( returnSR )
   {
      TMPL_ClearStatus();
   }

   TMPL_WriteF(blockadd, TMPL_CONFIG_SETUP);

   TMPL_WriteF(blockadd, TMPL_LOCK_BIT_SET);

   if ( !TMPL_WaitUntilReady( TMPL_PROGRAM_TIMEOUT ) )
   {
      /* timeout during erase */
	  stat.Result = StatTimeout;
   }
   else
   {
	  stat.Result = StatCompleted;
   }

   if ( returnSR )
   {
      stat.SR = TMPL_ReadStatus();
   }

   /* return device to read array mode */
   TMPL_WriteF(TMPL_BASE_FLASH_ADDRESS, TMPL_READ_ARRAY );

   return( stat ); /* return values tbd */

}


/****************************************************************************
 *
 * TMPL_LockDownBlock
 *
 * Description:   
 *
 *    This procedure is called to lockdown the specified block on the flash
 *    device.  See the flash device datasheet for specific details on this 
 *    command.
 *
 * Parameters:
 *
 *    IN      blocknum - the block number on the device.
 *
 *    IN      returnSR - flag to indicate whether the device status register
 *                       value should be returned by this function.
 *
 * Returns:   
 *
 *    TMPL_Status - includes function return status defined by enum
 *                  TMPL_CommandStat and optionally the flash device
 *                  status register value.
 *
 * Assumptions:
 *
 *    NONE
 *
 ***************************************************************************/
TMPL_Status TMPL_LockDownBlock      ( UINT16 blocknum,
                                      UINT8  returnSR )
{
   TMPL_Status   stat;
   UINT32 blockadd;
   
   stat = TMPL_GetBlockAddress( blocknum, &blockadd );

   if ( stat.Result != StatCompleted )
   {
	  return( stat );
   }

   if ( returnSR )
   {
      TMPL_ClearStatus();
   }

   TMPL_WriteF(blockadd, TMPL_CONFIG_SETUP);

   TMPL_WriteF(blockadd, TMPL_LOCKDOWN_BIT_SET);

   if ( !TMPL_WaitUntilReady( TMPL_PROGRAM_TIMEOUT ) )
   {
      /* timeout during erase */
	  stat.Result = StatTimeout;
   }
   else
   {
	  stat.Result = StatCompleted;
   }

   if ( returnSR )
   {
      stat.SR = TMPL_ReadStatus();
   }

   /* return device to read array mode */
   TMPL_WriteF(TMPL_BASE_FLASH_ADDRESS, TMPL_READ_ARRAY );

   return( stat ); /* return values tbd */

}


/****************************************************************************
 *
 * TMPL_LockProtection
 *
 * Description:   
 *
 *    This procedure is called to program the protection register user lock
 *    bit on the flash device.  See the flash device datasheet for specific
 *    details on this command.
 *
 * Parameters:
 *
 *    IN      returnSR - flag to indicate whether the device status register
 *                       value should be returned by this function.
 *
 * Returns:   
 *
 *    TMPL_Status - includes function return status defined by enum
 *                  command_stat and optionally the flash device status
 *                  register value.
 *
 * Assumptions:
 *
 *    NONE
 *
 ***************************************************************************/
TMPL_Status TMPL_LockProtection( UINT8 returnSR )
{

   UINT32 baseadd;
   UINT32 location;
   UINT32 address;
   TMPL_Status stat;

   location = TMPL_PROTECTION_LOCK_LOCATION;

   baseadd = TMPL_BASE_FLASH_ADDRESS;

   address = TMPL_OTP_BASE + TMPL_BASE_FLASH_ADDRESS;

   address += ( location * sizeof(TMPL_FDATA) );

   if ( returnSR )
   {
      TMPL_ClearStatus();
   }

   TMPL_WriteF(baseadd, TMPL_OTP_PROGRAM );

   TMPL_WriteF(address, TMPL_OTP_LOCK);

   if ( !TMPL_WaitUntilReady( TMPL_PROGRAM_TIMEOUT ) )
   {
      stat.Result = StatTimeout;
   }
   else
   {
      stat.Result = StatCompleted;
   }

   if ( returnSR )
   {
      stat.SR = TMPL_ReadStatus();
   }

   /* return device to read array mode */
   TMPL_WriteF(TMPL_BASE_FLASH_ADDRESS, TMPL_READ_ARRAY );

   return( stat );

}

#if X_16
/****************************************************************************
 *
 * TMPL_ProgramProtection
 *
 * Description:   
 *
 *    This procedure is called to program the protection register on
 *    the flash device at the specified location with the specified data
 *    value.  See the flash device datasheet for specific details on this
 *    command.
 *
 * Parameters:
 *
 *    IN      location - the protection register location on the flash
 *                       device to be programmed.
 *
 *    IN      value    - the data item to be programmed.
 *
 *    IN      returnSR - flag to indicate whether the device status register
 *                       value should be returned by this function.
 *
 * Returns:   
 *
 *    TMPL_Status - includes function return status defined by enum
 *                  command_stat and optionally the flash device status
 *                  register value.
 *
 * Assumptions:
 *
 *    NONE
 *
 ***************************************************************************/
TMPL_Status TMPL_ProgramProtection( UINT32 location, 

⌨️ 快捷键说明

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