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

📄 dbmflash2.c

📁 norflash的文件系统。 用于中低端手机开发的参考
💻 C
📖 第 1 页 / 共 4 页
字号:

      /* Get the size of the flash section associated with this block data base */

      FlashSectionSize =  HwdFlashSectionSize(FlashSection);

      /* Program the flash with Rx msg data */
      for (Index = 0; Index < NumBytes; Index += 2)
      {
         /*  
            Write 8 bit data to lower byte, set upper byte 
            to 0xff (keep it in the erased state) in case 
            there isn't an upper byte 
         */
         Data = 0xff00 | *DataPtr++;

         /* If there is another byte for the upper byte */
         if (Index + 1 < NumBytes)
         {
            /* Write 8 bit data to upper byte */
            Data = (Data & 0xff) | *DataPtr++ << 8;
         }

         /* 
            Check if this write would program the flash beyond 
            the end of the allotted size for this data base 
         */
         if (FlashOffset * 2 >= FlashSectionSize - sizeof(BlkDbSizeT))
         {
            /* Would have written beyond the end of this data base */
            MonFault(MON_DBM_FAULT_UNIT, DBM_BLK_DB_WRITE_ERR, FlashOffset * 2, 
                     MON_CONTINUE); 
            /* Set ack type */
            AckType = DBM_NACK_TYPE;
            goto exit;
         }

         /* Program the flash with one 16 bit word */
         HwdFlashProgram16(FlashSection, FlashOffset, Data);

         /* Increment the flash offset by one */
         FlashOffset++;
      }
   }

   exit:;

   /* Allocate a msg buffer for response message */
   RspMsgP = (DbmBlkWriteRspMsgT *) ExeMsgBufferGet(sizeof(DbmBlkWriteRspMsgT));

   /* Build the response message */
   RspMsgP->AckType = AckType;

   /* Fill in the data base id */
   RspMsgP->DataBaseId = RxMsgP->DataBaseId;

   /* Send response message to message originator */
   ExeMsgSend(RxMsgP->RspInfo.TaskId, RxMsgP->RspInfo.MailboxId, 
              RxMsgP->RspInfo.MsgId, (void *) RspMsgP, 
              sizeof(DbmBlkWriteRspMsgT));


}

/*****************************************************************************
 
  FUNCTION NAME: DbmNAMlockUnlockDbMsg 

  DESCRIPTION:

    This routine handles a request to lock/unlock the NAM. The static
	struct Nam which includes the Lock field is updated according to the
	boolean value in the recieved message. If NamLock is set to TRUE then
	the NAM is locked & any request to write to it will be denied.

  PARAMETERS:

    MsgDataP - Pointer to message structure

  RETURNED VALUES:

    None

*****************************************************************************/
void DbmNAMlockUnlockDbMsg(void *MsgDataP)
{
   DbmLockUnlockMsgT      *RxMsgP;
   DbmLockUnlockRspMsgT   *RspMsgP;
   uint32                  RspMsgSize;

   /* Save pointer to request message */
   RxMsgP = (DbmLockUnlockMsgT *)MsgDataP;
   
   /* Set NAM status */
   NamLock = RxMsgP->Lock;

   /* Get response message size */
   RspMsgSize = sizeof(DbmLockUnlockRspMsgT);
   
   /* Allocate memory for response message */
   RspMsgP = (DbmLockUnlockRspMsgT *)(ExeMsgBufferGet(RspMsgSize));
   
   /* Set current NAM status in response message */
   RspMsgP->Lock = NamLock;

   /* Send response message back to sender of request message */
   ExeMsgSend(RxMsgP->RspInfo.TaskId, RxMsgP->RspInfo.MailboxId, 
              RxMsgP->RspInfo.MsgId, (void *)RspMsgP, RspMsgSize);
}  

/*****************************************************************************
 
   FUNCTION NAME: FlashProgram
 
   DESCRIPTION:
 
     This routine programs the flash starting at a specific offset into a 
     specific flash section

   PARAMETERS:
 
     FlashSection - The specific flash section to be programmed
     FlashOffset  - Offset into the flash, in words
     Source       - Pointer to data to be programmed
     ByteCount    - Number of bytes to be programmed

   RETURNED VALUES:
 
     None.
 
*****************************************************************************/
static void FlashProgram(HwdFlashSectionTypeT FlashSection, uint16 FlashOffset, 
                         uint8 *Source, uint16 ByteCount)
{
   uint8 ByteData;
   uint16 Data;
   uint32 Index;
   
   /* Program the flash with the requested data, taking into account
      an odd number of requested bytes. */

   for (Index = 0; Index < ByteCount / 2; Index ++)
   {
      /* 8 bit reads because the Source address may not be aligned to 16 bits */
      Data = *Source++;
      Data |= *Source++ << 8;
      HwdFlashProgram16(FlashSection, FlashOffset + Index, Data);

   }

   /* If an odd number of bytes are to be burned then there is
      one byte remaining to be programmed. Pad that byte with the data 
	  currently in flash to create a 16 bit word. */

   if (ByteCount & 0x01) 
   {
      /* 8 bit reads because the Source address may not be aligned to 16 bits */
      Data = *Source++;
	  HwdFlashRead(FlashSection, 2*(FlashOffset + Index) + 1, &ByteData, 1);
      Data |= ByteData << 8;
      HwdFlashProgram16(FlashSection, FlashOffset + Index, Data);
   }

}

/*****************************************************************************
    
  FUNCTION NAME: CacheDb

  DESCRIPTION:

    Reads all of the data from the current data base located in flash 
    into the data base cache.

  PARAMETERS:

    None

  RETURNED VALUES:

    None

*****************************************************************************/

static void CacheDb(void)
{

   /* Read data base from flash into cache. */
   HwdFlashRead(FlashDbmP->FlashSection2, 2*FlashDbmP->Db[0].FlashOffset, 
                &FlashDbmP->Db[0].DataBaseP[0], FlashDbmP->Db[0].DbTotalSize);
   HwdFlashRead(FlashDbmP->FlashSection2, 2*FlashDbmP->Db[1].FlashOffset, 
                &FlashDbmP->Db[1].DataBaseP[0], FlashDbmP->Db[1].DbTotalSize);

   /* Write the Marker value to the data base, to be used to indicate
      this flash section is "dirty".
      (Two byte operations are done because DataBaseP is a byte pointer
       and can point to an odd location). */
   FlashDbmP->Db[0].DataBaseP[0] = (DBM_MARKER_VALUE & 0xff);
   FlashDbmP->Db[0].DataBaseP[1] = (DBM_MARKER_VALUE >> 8);
   FlashDbmP->Db[1].DataBaseP[0] = (DBM_MARKER_VALUE & 0xff);
   FlashDbmP->Db[1].DataBaseP[1] = (DBM_MARKER_VALUE >> 8);

   /* Set DB changed array to indicate cache valid */
   FlashDbmP->DbChanged = FALSE;

   /* Set DB cached flag */
   FlashDbmP->DbCached = TRUE;
}


/*****************************************************************************
    
  FUNCTION NAME: SwapFlashSections

  DESCRIPTION:

    Swaps the primary and secondary flash sections in the FlashDbm data 
    structure. This is called each time a write is performed to flash and
    after the secondary flash section has been erased.

  PARAMETERS:

    None 

  RETURNED VALUES:

    None

*****************************************************************************/

static void SwapFlashSections(void)
{
   HwdFlashSectionTypeT Temp;

   Temp = FlashDbmP->FlashSection1;

   FlashDbmP->FlashSection1 = FlashDbmP->FlashSection2;
   FlashDbmP->FlashSection2 = Temp;
}

/*****************************************************************************
* $Log: dbmflash2.c $
* Revision 1.1  2003/11/23 11:55:50  shitong
* Initial revision
* Revision 1.1  2003/09/30 11:09:20  shitong
* Initial revision
* Revision 1.11  2003/08/15 13:34:16  mshaver
* During UIM development, it was noticed that PSW was receiving 
* the PSW_NAM_CHANGED_BY_ETS_MSG when in fact the NAM
* had not been changed by ETS. The software that determines 
* whether or not PSW should be notified of the NAM change was 
* flawed. The software keys on the mailbox ID being 
* Revision 1.10  2002/07/30 11:15:18  mmalopy
* - DbmWriteFlashDbMsg() modified to check NAM lock boolean for
*   both NAM1 and NAM2 segments and to respond to PSW when
*   writing to the NAM2 segment.
* - DbmBlkReadFlashDbMsg() and DbmBlkWriteFlashDbMsg()
*   modified to use the 2 PRL FLASH section indentifiers.
* Revision 1.9  2002/05/29 08:51:36  mshaver
* Added VIA Technologies copyright.
* Revision 1.8  2002/04/10 15:35:42  mshaver
* Changed DbmClearFlashDbMsg(), DbmWriteFlashDbMsg(), and
* DbmFlushFlashDbMsg() to write the marker value, which indicates
* which of the two flash sectors contains valid data, after the data
* has been written to flash.
* Revision 1.7  2002/03/13 16:49:39  byang
* Modified DbmWriteFlashDbMsg() to redirect the message to PSW.
* The approach allows PSW to calculate the checksum and
* updates its copy. Lastly, PSW to write to DBM with the correct
* checksum calculated.
* Revision 1.6  2002/02/06 12:50:49  mshaver
* Added NAM lock/unlock message handler, DbmNAMlockUnlockDbMsg().  Also, use the lock to prevent writes
* to the NAM while the lock is true. In that case, generate a
* MonFault.
* Revision 1.5  2001/11/20 12:05:01  mclee
*  Add PswNamChangedByEtsMsg to inform PS to get fresh Nam copy because user changed Nam through ETS.
* Revision 1.4  2001/11/14 17:51:23  AMALA
* Modified function DbmWriteFlashDbMsg() to fix problem where MS did not power-up again after powering it down.
* Revision 1.3  2001/11/13 12:54:24  mshaver
* Merge in revision 1.1.2.2 which added fixes to handle odd 
* database sizes. Removed SetDbPointers routine, no longer
* needed.
* Revision 1.1.2.2  2001/11/01 16:22:56  mshaver
* Added fixes to handle odd database sizes. Removed
* SetDbPointers routine, no longer needed.
* Revision 1.1.2.1  2000/10/06 13:40:19  mshaver
* Duplicate revision
* Revision 1.1  2000/10/06 13:40:19  mshaver
* Initial revision
* Revision 1.1  2000/10/06 18:26:48Z  mshaver
* Initial revision
* Revision 1.12  2000/07/21 17:27:28Z  mshaver
* Changed dbmflash.c to allow both CP and RF data bases to be
* resident in the same flash sector. The CP data base starts at an
* offset of 0, the RF data base starts at an offset of 4096 bytes.
* Revision 1.11  2000/06/14 22:52:29Z  mshaver
* Fold changes from rev 1.10.1.2 into the baseline.
* Revision 1.10.1.2  2000/06/14 21:17:25Z  mshaver
* Added support for the additional voice memo & voice recognition
* data bases. Changed the block data base read function to return
* a pointer to the requested data base as it resides in flash.
* Revision 1.10.1.1  2000/06/07 15:08:18Z  mshaver
* Duplicate revision
* Revision 1.10  2000/06/07 15:08:18Z  mshaver
* Added support for dbm block read/writes with the functions
* DbmBlkWriteFlashDbMsg and DbmBlkReadFlashDbMsg.
* Revision 1.9  2000/06/01 15:33:25Z  bcolford
* Added CP database sections for Amps related baseband configuration
* parameters and Amps related Dspv configuration paramaters. Also
* added a section in the RF database for Amps related radio
* configuration parameters.
* Revision 1.8.2.3  2000/05/19 22:59:28Z  bcolford
* Move RF related AMPS calibration values to the RF database.
* Define a new section for baseband related AMPS calibration values
* and define a new section for AMPS related DSP calibration values.
* Revision 1.8.2.2  2000/05/15 20:56:29Z  bcolford
* Revision 1.8.2.1  2000/01/29 02:19:25Z  bcolford
* Duplicate revision
* Revision 1.8  2000/01/29 02:19:25Z  etarolli
* Updated flash and eeprom DB code so they are similar
* Revision 1.7  2000/01/24 18:13:13Z  mshaver
* Set the DbChanged flag to false also in DbmWriteFlashDbMsg()
* when the write through flag is true.
* Revision 1.6  2000/01/24 18:04:18Z  mshaver
* In DbmFlushFlashDbMsg() set the DbChanged flag false after
* having flushed the data base.
* Revision 1.5  2000/01/21 22:40:53Z  etarolli
* Rearranged data and defines 
* Revision 1.4  2000/01/21 22:17:09Z  bcolford
* Added new DBM segments for MMI and AMPS. Updated the size 
* of the NAM segment.
* Revision 1.3.1.2  2000/01/21 21:28:13Z  bcolford
* Added DBM segments for MMI and AMPS.
* Revision 1.3.1.1  2000/01/19 21:41:24Z  bcolford
* Duplicate revision
* Revision 1.3  2000/01/19 21:41:24Z  etarolli
* Added amps segment to DBM
* Revision 1.2  2000/01/19 20:27:48Z  mshaver
* Fold changes into the baseline
* Revision 1.1 2000/01/14 19:23:50Z  mshaver
* Added 16 bit marker word at beginning of the dbm flash section used
* to indicate that the section contains data.
* The DbChanged element of the FlashDbmT data structure was 
* collapsed into a single boolean as the array was unneeded.
* Code was added to check if the data base is larger than the 
* amount of space allocated in flash. If so then monFault.
*****************************************************************************/

⌨️ 快捷键说明

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