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

📄 dbmflash.c

📁 norflash的文件系统。 用于中低端手机开发的参考。 存储文件或短消息或电话簿。
💻 C
📖 第 1 页 / 共 3 页
字号:
	}

	/* Set the number of bytes */
	RspMsgP->NumBytes = NumBytes;

	RspMsgP->DataBaseSize = item_length;

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

/*	MonPrintf("\n Block DBM read done -----<<<<<<<<\n");*/
}


/*****************************************************************************
 
  FUNCTION NAME: DbmBlkWriteFlashDbMsg 

  DESCRIPTION:

    This routine handles the write block data base message. When this 
    message is received, if the message type is data then data from the 
    message is written to flash. The address is calculated based on the 
    offset contained in the message and the associated flash section's 
    base address. Then the amount of data specified by the message is 
    written to the data base address.

  PARAMETERS:

    MsgDataP - Pointer to message structure

  RETURNED VALUES:

    None

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

void DbmBlkWriteFlashDbMsg(void *MsgDataP)
{
	DbmBlkWriteMsgT      *RxMsgP;
	DbmAckTypeT           AckType;

	char				filename[FILE_NAME_SIZE];
	static HFSMFILE		handle = INVALID_FILE_HANDLE;
	static uint32		init_length = 0;
	static uint8		databaseid = 0;

	/* Set nack type */
	AckType = DBM_NACK_TYPE;

	/* Cast pointer to msg struct */
	RxMsgP = (DbmBlkWriteMsgT *) MsgDataP;

	MonPrintf("\n Write BLOCK DB: Task Id = %d, Database ID = %x \n", 
			RxMsgP->RspInfo.TaskId, 
			RxMsgP->DataBaseId);

	/* Determine the flash section to be programmed */
	switch(RxMsgP->DataBaseId)
	{
	case DBM_DS_DATA_BASE:
		break;

	case DBM_PRL1_DATA_BASE:
		break;

	case DBM_PRL2_DATA_BASE:
		break;

	case DBM_VREC1_DATA_BASE:
		break;

	case DBM_VREC2_DATA_BASE:
		break;

	case DBM_VMEM1_DATA_BASE:
		break;

	case DBM_VMEM2_DATA_BASE:
		break;

	default:
		MonFault(MON_DBM_FAULT_UNIT, DBM_BLK_DB_ID_ERR, 
				 RxMsgP->DataBaseId, MON_CONTINUE); 
		goto exit;
	}

	/* Check if init or data message */
	if (RxMsgP->MsgType == DBM_PROG_INIT_TYPE)
	{
		if(handle != INVALID_FILE_HANDLE)
		{
			FsmClose(handle);
			handle = INVALID_FILE_HANDLE;
		}

		sprintf(filename, "%s/blockdb%04x.dbf", DBM_PATH, RxMsgP->DataBaseId);

		handle = FsmOpen(filename, FSM_OPEN_ALWAYS | FSM_OPEN_WRITE | FSM_OPEN_READ);

		if(handle != INVALID_FILE_HANDLE)
		{
			AckType = DBM_ACK_TYPE;
		}

		databaseid = RxMsgP->DataBaseId;
		init_length = RxMsgP->Offset;

		goto exit;
	}

	if(handle == INVALID_FILE_HANDLE)
	{
		goto exit;
	}

	if(databaseid != RxMsgP->DataBaseId)
	{
		goto exit;
	}

	if(FsmSeek(handle, RxMsgP->Offset, FSM_FILE_BEGIN) == ERR_NONE)
	{
		if(FsmWrite(handle, (void *)&RxMsgP->Data[0], RxMsgP->NumBytes) != 0)
		{
			AckType = DBM_ACK_TYPE;

			if(init_length <= (RxMsgP->Offset + RxMsgP->NumBytes))
			{
				FsmTruncate(handle, init_length);

				FsmClose(handle);

				handle = INVALID_FILE_HANDLE;
			}
		}
	}

exit:;

	 if(RxMsgP->RspInfo.TaskId != EXE_IOP_ID)
	 {
		 DbmBlkWriteRspMsgT   *RspMsgP;

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

		 /* 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));
	 }
	 else
	 {
		 MonBlkDbWriteRspMsgT   *RspMsgP;

		 /* Allocate msg buffer for block data base write response message */
		 RspMsgP = (MonBlkDbWriteRspMsgT *) ExeMsgBufferGet(sizeof(MonBlkDbWriteRspMsgT));

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

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

	 MonPrintf("\n Block DBM Write done ----->>>>>>>\n");
}

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

static bool ReadItem(uint16 type, uint16 id, uint32 offset, void *data, uint32 length)
{
	uint32		status;
	uint32		fill_size;
	uint32		read_size;

	read_size = FsmDataItemRead(type, id, offset, data, length);

	if(read_size == (uint32)length)
		return TRUE;

	status = FsmDataItemGetError();

	if(status == ERR_NONE)
	{
		fill_size = (uint32)length - read_size;

		memset(((uint8 *)data) + read_size, 0x0, fill_size);

		return TRUE;
	}
	else
		return	FALSE;  
}

static bool WriteItem(uint16 type, uint16 id, uint32 offset, void *data, uint32 length)
{
	uint32		count = 0;
	uint32		write_len;

	count = 0;

	while(TRUE)
	{
		write_len = FsmDataItemWrite(type, id, offset, data, length);

		if(write_len != length)
		{
			count++;

			if(count > DBM_MAX_WRITE_TRY)
				break;

			ExeEventWait(EXE_DBM_ID, EXE_SIGNAL_FALSE, EXE_MESSAGE_FALSE, DBM_SLEEP_TICKS);
		}
		else
			break;
	}

	return (write_len == length);
}

/*****************************************************************************
* $Log: dbmflash.c $
* Revision 1.10  2004/04/19 10:54:46  jjs
* fix bug #1108,  when write block, dbm will adjust the file length of the corresponding file.
* Revision 1.9  2004/01/16 10:15:17  jjs
* added some debug information.
* Revision 1.8  2004/01/15 17:04:08  gzhu
* Change Data to DataP in DbmBlkReadFlashDbMsg()
* Revision 1.7  2004/01/15 11:03:57  jjs
* Flush flash when DbmFlushFlashDbMsg is called.
* Revision 1.6  2004/01/15 11:53:10  jjs
* 1. Set ReadItem function as local.
* 2. Fix a bug in Block DB read funtion.
* Revision 1.5  2004/01/06 18:13:03  heyi
* Change function:ReadItem to global function
* Revision 1.4  2003/11/30 10:48:11  xuhua
* don't split NAM into many items
* 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 + -