📄 davsmpl.c
字号:
/* ###########################################################################
### Intel Confidential
### Copyright (c) Intel Corporation 1995-2002
### All Rights Reserved.
### -------------------------------------------------------------------------
### Object: FDI V2.3 Sample Module for testing FMM capability
###
### Module: sample.c
###
### $NoKeywords: $
########################################################################### */
/*
*****************************************************************
* NOTICE OF LICENSE AGREEMENT
*
* This code is provided by Intel Corp., and the use is governed
* under the terms of a license agreement. See license agreement
* for complete terms of license.
*
* YOU MAY ONLY USE THE SOFTWARE WITH INTEL FLASH PRODUCTS. YOUR
* USE OF THE SOFTWARE WITH ANY OTHER FLASH PRODUCTS IS EXPRESSLY
* PROHIBITED UNLESS AND UNTIL YOU APPLY FOR, AND ARE GRANTED IN
* INTEL'S SOLE DISCRETION, A SEPARATE WRITTEN SOFTWARE LICENSE
* FROM INTEL LICENSING ANY SUCH USE.
*****************************************************************
*/
/* ### Include Files
######################### */
#include <errno.h>
#include <stdio.h>
#include <string.h>
#include "vxWorks.h"
#include "stdioLib.h"
#include "strLib.h"
#include "taskLib.h"
#include "logLib.h"
#include "debug.h"
#include "fdi_ext.h"
#include "fdi_err.h"
#include <message.h>
#include "dav.h"
#if (DIRECT_ACCESS_VOLUME == TRUE)
/* FDI_Test(filename, type, size, test command) */
/* test command:
0 -> allocate and write file
1 -> deallocate file
2 -> reallocate file
3 -> verify pattern
4 -> interpret file (verify contents)
*/
void FDI_Test(char *filename, WORD type, DWORD size, WORD command)
{
FDI_ObjectInfo obj_info;
ERR_CODE fdi_status;
int offset, i, recl_chk;
DWORD dtabuf[FDI_PageSize/4], dta;
BYTE *file_addr, dta_byt;
/* Build control structure */
strcpy((char *)&obj_info.Name, filename);
obj_info.NameSize = strlen(filename);
obj_info.ObjectType = type;
obj_info.ObjectSize = TO_SIZE(size,FDI_PageSize);
obj_info.Alignment = FDI_ALIGN_Page;
obj_info.SecurityKey = 0; /* Does nothing */
obj_info.PrivilegeLevel = 0; /* Does nothing */
obj_info.RecoveryLevel = FDI_PLR_Level0; /* Does nothing */
switch (command)
{
/* Allocate and write file */
case 0:
fdi_status = FDI_AllocateFlash(&obj_info);
if (fdi_status != ERR_NONE)
{
printf("ERROR - Allocate Failed. Status:0x%d\n",fdi_status);
break;
}
/* Write file into object a page at a time. (This will write beyond
the requested size of the file and fill up to the end of final page.) */
for (dta = offset = 0 ; offset < size ; offset += FDI_PageSize)
{
/* Read portion of file into buffer */
for (i = 0; i < FDI_PageSize/4 ; i++ )
{
dtabuf[i] = dta++;
}
/* Now write a page of file into the object. */
fdi_status = FDI_WriteObject( obj_info.Name, obj_info.NameSize,
obj_info.ObjectType, (BYTE_PTR)dtabuf, FDI_PageSize, offset);
if (fdi_status)
{
printf(" DAV ERROR - WriteObject Failed. Status:0x%d\n",fdi_status);
break;
}
}
/* call WriteComplete */
fdi_status = FDI_WriteComplete(obj_info.Name, obj_info.NameSize,
obj_info.ObjectType);
if (fdi_status)
{
printf("DAV ERROR - Write Complete Failed. Status:0x%d\n",fdi_status);
break;
}
/* Access the file location */
fdi_status = FDI_GetObjectHeader(&obj_info, SearchByNameType, TRUE);
if (fdi_status)
{
printf("DAV ERROR - Get Next Object Failed. Status:0x%d\n",fdi_status);
break;
}
/* Verify file data */
for (dta = offset = 0 ; offset < size ; offset += 4, dta++)
{
if (dta != *(DWORD *)(obj_info.ObjectAddress + offset))
{
printf("DAV ERROR - direct access compare failed\n");
break;
}
}
break;
/* Deallocate */
case 1:
fdi_status = FDI_DeAllocateFlash((UINT8_PTR)&obj_info.Name,
obj_info.NameSize, obj_info.ObjectType);
if (fdi_status != ERR_NONE)
{
printf("DAV ERROR - Deallocate Failed. Status:0x%d\n",fdi_status);
break;
}
break;
/* Reallocate - This probably won't be used because the new file
must be the same size as the old file (the file is replaced in place).
Reallocate has not been tested. */
case 2:
fdi_status = FDI_ReAllocateFlash(&obj_info);
if (fdi_status != ERR_NONE)
{
printf("DAV ERROR - Reallocate Failed. Status:0x%d\n",fdi_status);
break;
}
/* Write file into object a page at a time. (This will write beyond
the requested size of the file and fill up to the end of final page.) */
for (dta = offset = 0 ; offset < size ; offset += FDI_PageSize)
{
/* Read portion of file into buffer */
for (i = 0; i < FDI_PageSize/4 ; i++ )
{
dtabuf[i] = dta++;
}
/* Now write a page of file into the object. */
fdi_status = FDI_WriteObject( obj_info.Name, obj_info.NameSize,
obj_info.ObjectType, (BYTE_PTR)dtabuf, FDI_PageSize, offset);
if (fdi_status)
{
printf(" DAV ERROR - WriteObject Failed. Status:0x%d\n",fdi_status);
break;
}
}
/* call WriteComplete */
fdi_status = FDI_WriteComplete(obj_info.Name, obj_info.NameSize,
obj_info.ObjectType);
if (fdi_status)
{
printf("DAV ERROR - Write Complete Failed. Status:0x%d\n",fdi_status);
break;
}
/* Access the file location */
fdi_status = FDI_GetObjectHeader(&obj_info, SearchByNameType, TRUE);
if (fdi_status)
{
printf("DAV ERROR - Get Next Object Failed. Status:0x%d\n",fdi_status);
break;
}
/* Verify file data */
for (dta = offset = 0 ; offset < size ; offset += 4, dta++)
{
if (dta != *(DWORD *)(obj_info.ObjectAddress + offset))
{
printf("DAV ERROR - direct access compare failed\n");
break;
}
}
break;
/* Verify data pattern */
case 3:
fdi_status = FDI_GetObjectHeader(&obj_info, SearchByNameType, TRUE);
if (fdi_status)
{
printf("DAV ERROR - Get Next Object Failed. Status:0x%d\n",fdi_status);
break;
}
/* Verify file data */
for (dta = offset = 0 ; offset < size ; offset += 4, dta++)
{
if (dta != *(DWORD *)(obj_info.ObjectAddress + offset))
{
printf("DAV ERROR - direct access compare failed\n");
break;
}
}
break;
/* Interpret - this is for testing how the DAV capability should be
used for Java class file interpretation. */
case 4:
/* Force DAV reclaim request. This should be invoked before
FDI_GetObjectHeader() so that reclaim is locked out before the physical
address of the class file is obtained. Once reclaim is locked, FMM
must request permission to reclaim. */
FDI_ReclLock();
/* Get the address of the file to interpret */
fdi_status = FDI_GetObjectHeader(&obj_info, SearchByNameType, TRUE);
if (fdi_status)
{
printf("DAV ERROR - Get Next Object Failed. Status:0x%d\n",fdi_status);
break;
}
file_addr = (BYTE *)obj_info.ObjectAddress;
/* Verify file contents one byte at a time */
for (dta = offset = recl_chk = 0, i = 3 ; offset < size ; offset++)
{
/* Calc expected data byte */
dta_byt = dta>>(i*8);
if (i-- == 0)
{
i = 3;
dta++;
}
/* Get and verify byte */
if (dta_byt != *file_addr++)
{
printf("DAV ERROR - direct access compare failed\n");
break;
}
/* Check for reclaim request every so often */
if (recl_chk++ == 1024)
{
recl_chk = 0;
/* Check for reclaim request (doesn't wait) */
if (FDI_ReclPending())
{
/* DAV is waiting for permission to reclaim */
/* Grant the reclaim and wait for completion */
FDI_ReclUnlock();
FDI_ReclWait();
/* Relock the Flash from reclaim */
FDI_ReclLock();
/* Get new file address */
file_addr -= obj_info.ObjectAddress;
fdi_status = FDI_GetObjectHeader(&obj_info, SearchByNameType, TRUE);
if (fdi_status)
{
printf("DAV ERROR - Get Next Object Failed. Status:0x%d\n",fdi_status);
break;
}
file_addr += obj_info.ObjectAddress;
}
}
}
/* DAV Reclaim request no longer required. This should be invoked after
final DMA from interpreter. DAV reclaim can then reclaim without
making a request. */
FDI_ReclUnlock();
break;
default:
break;
}
}
#endif /* DIRECT_ACCESS_VOLUME */
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -