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

📄 fdi_mpll.c

📁 Flash file system
💻 C
📖 第 1 页 / 共 5 页
字号:
  ###   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)
{ 
   volatile FLASH_DATA_PTR flash_ptr;
   UNIT_HDR_PTR pHdr;
   DWORD preempted_state;
   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 */
   BYTE suspended = (BYTE) FALSE;

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

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

   /* set current flash state */
   preempted_state = CurrentFlashState;
   CurrentFlashState = SET_PARTITION_STATE(address, HW_STATE_STATUS);

   /* suspend if partition is busy */
   *flash_ptr = FLASH_COMMAND_STATUS;
   if (IS_PARTITION_BUSY(flash_ptr))
   {
      *flash_ptr = FLASH_COMMAND_SUSPEND;
      *flash_ptr = FLASH_COMMAND_STATUS;
      while ((*flash_ptr & FLASH_STATUS_READY) != FLASH_STATUS_READY) { }
      if (*flash_ptr & (FLASH_STATUS_WRITE_SUSPENDED | 
          FLASH_STATUS_ERASE_SUSPENDED))
      {
         suspended = (BYTE) TRUE;
      }
   }

   CurrentFlashState = SET_PARTITION_STATE(address, HW_STATE_READ);
   *flash_ptr = FLASH_COMMAND_READ;

   /* 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 */

   /* if suspended, resume */
   if (suspended)
   {
      /* E5.0.480 START */
      CurrentFlashState = SET_PARTITION_STATE((DWORD) flash_ptr,
                                              HW_STATE_STATUS);
      *flash_ptr = FLASH_COMMAND_STATUS;
      if (*flash_ptr & FLASH_STATUS_WRITE_SUSPENDED)
      {
         RESUME_WRITE_SUSPENDED_FLASH(flash_ptr);
      }
      else
      {
         *flash_ptr = FLASH_COMMAND_RESUME;
      }
      /* E5.0.480 END */
   }

   /* restore flash state */
   CurrentFlashState = preempted_state;
   flash_ptr = (FLASH_DATA_PTR) GET_PARTITION_ADDRESS(CurrentFlashState);
   switch (GET_PARTITION_STATE(CurrentFlashState))
   {
      case HW_STATE_READ:
         *flash_ptr = FLASH_COMMAND_READ;
         break;
      case HW_STATE_STATUS:
         *flash_ptr = FLASH_COMMAND_STATUS;
         break;
      default:
         break;
   }
   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)
{
   volatile FLASH_DATA_PTR flash_ptr;
   UNIT_HDR_PTR pHdr;
   DWORD preempted_state;
   HW_ERROR status = HW_ERR_SYSTEM;
   BYTE suspended = (BYTE) FALSE;

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

   flash_ptr = (FLASH_DATA_PTR) ALIGN_ADDRESS(address);
   pHdr = (UNIT_HDR_PTR) (address + FIRST_HEADER_OFFSET);

   /* set current flash state */
   preempted_state = CurrentFlashState;
   CurrentFlashState = SET_PARTITION_STATE(address, HW_STATE_STATUS);

   /* suspend if partition is busy */
   *flash_ptr = FLASH_COMMAND_STATUS;
   if (IS_PARTITION_BUSY(flash_ptr))
   {
      *flash_ptr = FLASH_COMMAND_SUSPEND;
      *flash_ptr = FLASH_COMMAND_STATUS;
      while ((*flash_ptr & FLASH_STATUS_READY) != FLASH_STATUS_READY) { }
      if (*flash_ptr & (FLASH_STATUS_WRITE_SUSPENDED | 
          FLASH_STATUS_ERASE_SUSPENDED))
      {
         suspended = (BYTE) TRUE;
      }
   }

   CurrentFlashState = SET_PARTITION_STATE(address, HW_STATE_READ);
   *flash_ptr = FLASH_COMMAND_READ;

   /* 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 grp 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));

   /* if suspended, resume */
   if (suspended)
   {
      /* E5.0.480 START */
      CurrentFlashState = SET_PARTITION_STATE((DWORD) flash_ptr,
                                              HW_STATE_STATUS);
      *flash_ptr = FLASH_COMMAND_STATUS;
      if (*flash_ptr & FLASH_STATUS_WRITE_SUSPENDED)
      {
         RESUME_WRITE_SUSPENDED_FLASH(flash_ptr);
      }
      else
      {
         *flash_ptr = FLASH_COMMAND_RESUME;
      }
      /* E5.0.480 END */
   }

   /* restore flash state */
   CurrentFlashState = preempted_state;
   flash_ptr = (FLASH_DATA_PTR) GET_PARTITION_ADDRESS(CurrentFlashState);
   switch (GET_PARTITION_STATE(CurrentFlashState))
   {
      case HW_STATE_READ:
         *flash_ptr = FLASH_COMMAND_READ;
         break;
      case HW_STATE_STATUS:
         *flash_ptr = FLASH_COMMAND_STATUS;
         break;
      default:
         break;
   }

   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;


   /**/
   DISABLE_INTERRUPTS(key0, key1);
   status_reg = PtrLowLvlReadStat(flash_ptr);
   ENABLE_INTERRUPTS(key0, key1);

   if ((status_reg & FLASH_STATUS_READY) != FLASH_STATUS_READY)
   {
      retval = HW_ERR_NOTRDY;
   }
   else if (status_reg &
      (FLASH_STATUS_WRITE_SUSPENDED | FLASH_STATUS_ERASE_SUSPENDED))
   {
      retval = HW_ERR_SUSPEND;
   }
   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
  ###   

⌨️ 快捷键说明

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