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

📄 fdi_spll.c

📁 FDI Intel开发的FLASH文件系统,功能很强大
💻 C
📖 第 1 页 / 共 5 页
字号:
  ###    OUT: buffer_ptr - Contains the contents read.
  ###
  ### RETURNS:
  ###   If the entire source buffer does not lie within the data managed area
  ###   (or code managed area if DAV is enabled), the function returns
  ###   HW_ERR_PARAM.  Otherwise, the function returns HW_ERR_NONE.
  ###
 */

HW_ERROR FlashDevRead(BYTE_PTR buffer_ptr, DWORD address, DWORD size)
{
   BYTE_PTR       src_byte_ptr, dst_byte_ptr;
   FLASH_DATA_PTR src_data_ptr, dst_data_ptr;
   DWORD          src_offset,   dst_offset;


   /* validate address */
   address += LOWLVL_FLASH_START_ADDRESS;
   VALIDATE_ADDRESS(address, size);

   /* return if nothing to read */
   if (size == 0)
   {
      return HW_ERR_NONE;
   }

   /* determine address offsets */
   src_offset = UNALIGNED_BYTES(address);
   dst_offset = UNALIGNED_BYTES((DWORD) buffer_ptr);
   src_byte_ptr = (BYTE_PTR) address;
   dst_byte_ptr = buffer_ptr;

   /*
    * determine if source and destination addresses allow the reading on
    * aligned addresses
    */
   if ((src_offset == dst_offset) && (size > sizeof(FLASH_DATA)))
   {
      /* read initial unaligned bytes */
      if (src_offset != 0)
      {
         while (src_offset < sizeof(FLASH_DATA))
         {
            *dst_byte_ptr = *src_byte_ptr;
            dst_byte_ptr++;
            src_byte_ptr++;
            size--;
            src_offset++;
         }
      }

      /* read aligned data */
      dst_data_ptr = (FLASH_DATA_PTR) dst_byte_ptr;
      src_data_ptr = (FLASH_DATA_PTR) src_byte_ptr;
      while (size >= sizeof(FLASH_DATA))
      {
         *dst_data_ptr = *src_data_ptr;
         dst_data_ptr++;
         src_data_ptr++;
         size -= sizeof(FLASH_DATA);
      }

      /* read remaining unaligned bytes */
      if (size > 0)
      {
         dst_byte_ptr = (BYTE_PTR) dst_data_ptr;
         src_byte_ptr = (BYTE_PTR) src_data_ptr;

         while (size > 0)
         {
            *dst_byte_ptr = *src_byte_ptr;
            dst_byte_ptr++;
            src_byte_ptr++;
            size--;
         }
      }
   }

   /*
    * source and destination addresses do not allow the reading on aligned
    * addresses; therefore, a byte-by-byte copy needs to be done
    */
   else
   {
      while (size > 0)
      {
         *dst_byte_ptr = *src_byte_ptr;
         dst_byte_ptr++;
         src_byte_ptr++;
         size--;
      }
   }

   return HW_ERR_NONE;
}



#if (CONSISTENT_ACCESS_TIME == TRUE)
/*#############################################################################
  ### FlashDevUpdateDLT
  ###
  ### DESCRIPTION:
  ###   Allows the Reclaim Task to update the data lookup table when the
  ###   status of the spare block is BLOCK_ERASING.  It scans the unit
  ###   headers in the spare block and updates the header index field in
  ###   the data lookup table.
  ###
  ### PARAMETERS:
  ###    IN:  address (DWORD) - The starting address within flash of the
  ###          block to scan the unit headers.
  ###    OUT:
  ###
  ### RETURNS:
  ###   HW_ERR_NONE    function execution is successful
  ###
 */

HW_ERROR
FlashDevUpdateDLT(DWORD address)
{
   UNIT_HDR_PTR pHdr;
   DWORD hdr_offset;
   WORD hdr_status;                     /* local buf for hdr status */
   WORD hdr_id;                         /* local buf for identifier */
   BYTE hdr_type_attribute;             /* local buf for hdr type_attribute */

   /* validate address */
   address += LOWLVL_FLASH_START_ADDRESS;
   VALIDATE_ADDRESS(address, FDV_BLOCK_SIZE);

   /* Build pointer to first header in block */
   pHdr = (UNIT_HDR_PTR) (address + FIRST_HEADER_OFFSET);

   /* Scan headers to locate requested header */
   while (!(HDR_STATE(HDR_EMPTY, (hdr_status = pHdr->status))))
   {
      hdr_id = pHdr->identifier;
      hdr_type_attribute = pHdr->type_attribute;

      /* Compare status to header valid.
       * In the case of Packet Data, also allow HDR_VALID_HDR
       * for the active Packet Data unit header(s). */

      if (HDR_STATE(HDR_VALID, hdr_status)
#if (PACKET_DATA == TRUE)
          || HDR_STATE(HDR_VALID_HDR, hdr_status)
#endif /* PACKET_DATA */
         )
      {
         /* Status valid */
         /* Compare attribute, must be grp table or multi/single instance */
         if ((NIBBLE_LOW(hdr_type_attribute) != ATTR_SEQ_TABLE) &&
             (NIBBLE_LOW(hdr_type_attribute) != ATTR_DATA_FRAG) &&
             (NOT_EMPTY_LOOKUP_TABLE(NIBBLE_HIGH(hdr_type_attribute),hdr_id)))
         {

            /* update header index for the corresponding header
             * according to id, type and hdr offset. */
            hdr_offset = (WORD)((DWORD)(pHdr)&(DWORD)(FDV_BLOCK_SIZE - 1));
            SET_LOOKUP_TABLE_HDR(NIBBLE_HIGH(hdr_type_attribute), hdr_id,
                                 hdr_offset);
         }
      }

      /* increment offset pointer by size of the UNIT_HEADER */
      pHdr = (UNIT_HDR_PTR)((BYTE_PTR)pHdr + sizeof(UNIT_HEADER));

   } /* end while */
   return HW_ERR_NONE;
}

#endif /* CONSISTENT_ACCESS_TIME */


/*#############################################################################
  ### FlashDevReadHeader
  ###
  ### DESCRIPTION:
  ###   Scans all unit headers in the block designated by the address
  ###   specified looking for a valid header that matches the specified type
  ###   and identifier.  The Background Manager determines the relative
  ###   address by using the FDI mapping structure.  The FlashDevReadHeader()
  ###   function translates the relative address into a physical system
  ###   address and verifies the address range.  The function the scans the
  ###   block for the specified header and returns the appropriate value.
  ###
  ### PARAMETERS:
  ###    IN:  hdr_offset_ptr (DWORD_PTR) - A pointer to the DWORD that will
  ###          contain the header's offset into the block.
  ###         hdr_data_ptr (UNIT_HDR_PTR) - A pointer to the UNIT_HEADER that
  ###          will contain the header found.
  ###         address (DWORD) - The starting address within flash of the block
  ###          in which to search for the unit header.
  ###         identifier (WORD) - The identifier to look for in the unit
  ###          header.
  ###         type (BYTE) - The type to look for in the unit header.
  ###    OUT: hdr_offset_ptr - Contains the offset of the header into the
  ###          block if a valid instance can be found; otherwise, the contents
  ###          are unknown.
  ###         hdr_data_ptr - Contains the unit header being searched for if
  ###          a valid instance can be found; otherwise, the contents are
  ###          unknown.
  ###
  ### RETURNS:
  ###   If the address does noe lie within the data managed area (or the code
  ###   managed area if DAV is enabled), the function returns HW_ERR_PARAM.
  ###   If a header whose type and identifier match the values passed in
  ###   cannot be found, the function returns HW_ERR_SYSTEM.  Finally, if a
  ###   valid or allocated header is found, the function returns HW_ERR_NONE.
  ###
 */

HW_ERROR FlashDevReadHeader(DWORD_PTR hdr_offset_ptr,
                            UNIT_HDR_PTR hdr_data_ptr, DWORD address,
                            WORD identifier, BYTE type)
{
   UNIT_HDR_PTR pHdr;
   HW_ERROR status = HW_ERR_SYSTEM;


   /* validate address */
   address += LOWLVL_FLASH_START_ADDRESS;
   VALIDATE_ADDRESS(address, FDV_BLOCK_SIZE);

   pHdr = (UNIT_HDR_PTR) (address + FIRST_HEADER_OFFSET);

   /* Scan headers to located requested header */
   while (!(HDR_STATE(HDR_EMPTY, pHdr->status)))
   {
      /*
       * Compare status to header valid or header allocated.
       * In the case of packet data, also allow allocating
       * for the active Packet Group Table header.
       */
      if (HDR_STATE(HDR_VALID, pHdr->status) ||
#if (PACKET_DATA == TRUE)
         ((FDI_Pckt.ID == identifier) &&
         (FDI_Pckt.type == type) &&
         (identifier != WORDMAX) &&
         HDR_STATE(HDR_VALID_HDR, pHdr->status)) ||
#endif /* PACKET_DATA */
         HDR_STATE(HDR_ALLOCATED, pHdr->status))
      {
         /*
          * status valid; compare attribute for group table, single or
          * multi instance
          */
         if ((NIBBLE_LOW(pHdr->type_attribute) != ATTR_SEQ_TABLE) &&
            (NIBBLE_LOW(pHdr->type_attribute) != ATTR_DATA_FRAG))
         {
            /* attribute valid; compare type and id */
            if ((NIBBLE_HIGH(pHdr->type_attribute) == type) &&
               (pHdr->identifier == identifier))
            {
               *hdr_data_ptr = *pHdr;
               status = HW_ERR_NONE;
               break;
            }
         }
      }

      /* increment offset pointer by size of UNIT_HEADER */
      pHdr++;
   }

   /* update header offset return value */
   *hdr_offset_ptr = ((DWORD) pHdr & (DWORD)(FDV_BLOCK_SIZE - 1));

   return status;
}



#if (BLOCK_LOCK_SUPPORT == TRUE)
/*#############################################################################
  ### FlashDevLock
  ###
  ### DESCRIPTION:
  ###   Performs one of the following operations on the flash hardware:
  ###   lock a block, lock down a block, unlock a block, or read the lock
  ###   status of a block.
  ###
  ### PARAMETERS:
  ###    IN:  block_status_ptr (FLASH_DATA_PTR) - A pointer to a buffer to
  ###          store the lock status of a block.
  ###         address (DWORD) - The starting address within flash to perform
  ###          the lock operation on.
  ###         command (HW_CMD) - The lock-related command to issue: lock
  ###          (HW_CMD_LOCK), lock down (HW_CMD_LOCKDOWN), unlock
  ###          (HW_CMD_UNLOCK), or read the block's lock status
  ###          (HW_CMD_READLOCKSTATUS).
  ###    OUT: block_status_ptr - Contains the contents of the block's lock
  ###          status if the command issued was HW_CMD_READLOCKSTATUS;
  ###          otherwise, the contents are unknown.
  ###
  ### RETURNS:
  ###   If the flash hardware is not CFI-compliant, the address is not the
  ###   starting address of a block, or the command issued is invalid, the
  ###   function returns HW_ERR_PARAM.  If the flash hardware is not ready,
  ###   the function returns HW_ERR_NOTRDY.  If the flash hardware is
  ###   suspended, the function returns HW_ERR_SUSPEND.  Finally, if all the
  ###   parameters are correct and the flash hardware is able to perform the
  ###   command, the function returns HW_ERR_NONE.
  ###
 */

HW_ERROR FlashDevLock(FLASH_DATA_PTR block_status_ptr,
                      DWORD address, HW_CMD command)
{
   volatile FLASH_DATA_PTR flash_ptr = (FLASH_DATA_PTR) address;
   FLASH_DATA status_reg;
   DWORD key0, key1;
   HW_ERROR retval;


   /* check to see if flash is ready */
   DISABLE_INTERRUPTS(key0, key1);
   status_reg = PtrLowLvlReadStat(flash_ptr);
   ENABLE_INTERRUPTS(key0, key1);

   /* check if flash is ready */
   if ((status_reg & FLASH_STATUS_READY) != FLASH_STATUS_READY)
   {
      retval = HW_ERR_NOTRDY;
   }

   /* check if flash is suspended */
   else if (status_reg &
      (FLASH_STATUS_WRITE_SUSPENDED | FLASH_STATUS_ERASE_SUSPENDED))
   {
      retval = HW_ERR_SUSPEND;
   }

   /* flash ready and not suspended, issue command */
   else
   {
      HARDWARE_PRECONDITION;
      DISABLE_INTERRUPTS(key0, key1);
      retval = PtrLowLvlLock(flash_ptr, block_status_ptr, command);
      ENABLE_INTERRUPTS(key0, key1);
      HARDWARE_POSTCONDITION;
   }

   return retval;
}
#endif /* BLOCK_LOCK_SUPPORT */



#if (ENABLE_PR != FDI_NONE)
/*#############################################################################
  ### FlashDevProtectReg
  ###
  ### DESCRIPTION:
  ###   Reads/writes the protection registers and lock.  When the configuration
  ###   is paired 16-bit parts, the user will address the matching registers
  ###   as a single 32-bit register, instead of addresssing them as two 16-bit
  ###   registers on a 32-bit bus.
  ###
  ### PARAMETERS:
  ###    IN:  factory_reg_ptr (FLASH_DATA_PTR) - A pointer to the buffer to
  ###          contain the factory programmed protection registers.
  ###         user_reg_ptr (FLASH_DATA_PTR) - A pointer to the buffer to
  ###          contain the user programmed protection registers, or the data
  ###          to program if the command is HW_CMD_WRITE.
  ###         lock_reg_ptr (FLASH_DATA_PTR) - A pointer to the buffer to
  ###          contain the protection lock register.
  ###         command (HW_CMD) The protection register related command to
  ###          issue: write protection lock register (HW_CMD_WRITE_PR_LOCK),
  ###          read protection lock register (HW_CMD_READ_PR_LOCK), write
  ###          protection register (HW_CMD_WRITE_PR), or read protection
  ###          registers (HW_CMD_READ_PR).
  ###         register_num (BYTE) - The user register number to write to if
  ###          the command is HW_CMD_WRITE_PR.
  ###         lock_flag (BYTE) - A non-zero value tells the function to lock
  ###          the protection registers upon a successful write to the
  ###          protection register.
  ###    OUT: factory_reg_ptr - The contents of the factory programmed
  ###          protection registers if the command issued was HW_CMD_READ_PR;
  ###          otherwise, the contents are unknown.
  ###         user_reg_ptr - The contents of the user programmed protection
  ###          registers if the command issued was HW_CMD_READ_PR; otherwise,
  ###          the contents are unknown.
  ###         lock_reg_ptr - The contents of the protection lock reigster
  ###          if the command was HW_CMD_READ_PR_LOCK; otherwise, the contents
  ###          are unknown.
  ###
  ### RETURNS:
  ###   If the flash hardware is not ready, the funciton returns HW_ERR_NOTRDY.
  ###   If the flash hardware is suspended, the function returns
  ###   HW_ERR_SUSPEND.  If the incorrect protection lock register is specifed
  ###   for a read, the function returns HW_ERR_PARAM.  If the maximum time

⌨️ 快捷键说明

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