#include <mil.h>
#define CONSTANT_TO_ADD 50
#define NB_LOOP 100
#define IMAGE_FILE M_IMAGE_PATH MIL_TEXT("Board.mim")
void FpgaAddConstant(MIL_ID SrcImageId, MIL_ID DstImageId, MIL_INT ConstantToAdd,
MIL_INT ControlFlag);
int MosMain(void)
{
MIL_ID MilApplication;
MIL_ID MilSystem ;
MIL_ID MilDisplay ;
MIL_ID MilImageSrc ;
MIL_ID MilImageDst ;
MIL_ID MilImageDisp ;
MIL_INT SizeX, SizeY, n, BoardType;
MIL_DOUBLE Time;
MappAllocDefault(M_DEFAULT, &MilApplication, &MilSystem, &MilDisplay, M_NULL, M_NULL);
MsysInquire(MilSystem, M_BOARD_TYPE, &BoardType);
if(!(BoardType & M_PF))
{
MosPrintf(MIL_TEXT("Error: This example needs a processing FPGA installed on your\n"));
MosPrintf(MIL_TEXT("system to continue.\n"));
MosPrintf(MIL_TEXT("Press <Enter> to quit.\n"));
MosGetch();
MdispFree(MilDisplay);
MsysFree(MilSystem);
MappFree(MilApplication);
return(0);
}
SizeX = MbufDiskInquire(IMAGE_FILE, M_SIZE_X, M_NULL);
SizeY = MbufDiskInquire(IMAGE_FILE, M_SIZE_Y, M_NULL);
MbufAlloc2d(MilSystem, SizeX, SizeY,8+M_UNSIGNED,
M_IMAGE+M_PROC+M_GRAB+M_FPGA_ACCESSIBLE, &MilImageSrc);
MbufAlloc2d(MilSystem, SizeX, SizeY,8+M_UNSIGNED,
M_IMAGE+M_PROC+M_HOST_MEMORY+M_FPGA_ACCESSIBLE, &MilImageDst);
MbufAlloc2d(MilSystem, SizeX, SizeY,8+M_UNSIGNED,
M_IMAGE+M_DISP+M_NON_PAGED, &MilImageDisp);
MbufClear(MilImageSrc, 0);
MbufClear(MilImageDst, 0);
MbufClear(MilImageDisp, 0);
MbufLoad(IMAGE_FILE, MilImageSrc);
MbufLoad(IMAGE_FILE, MilImageDisp);
MdispSelect(MilDisplay, MilImageDisp);
MosPrintf(MIL_TEXT("This example demonstrates how to create and use an \n"));
MosPrintf(MIL_TEXT("FPGA accelerated Add Constant processing primitive.\n"));
MosPrintf(MIL_TEXT("Press <Enter> to continue.\n"));
MosGetchar();
FpgaAddConstant(MilImageSrc, MilImageDst, CONSTANT_TO_ADD, M_SATURATION);
MappTimer(M_DEFAULT, M_TIMER_RESET+M_SYNCHRONOUS, M_NULL);
for(n = 0; n < NB_LOOP; n++)
{
FpgaAddConstant(MilImageSrc, MilImageDst, CONSTANT_TO_ADD, M_SATURATION);
}
MappTimer(M_DEFAULT, M_TIMER_READ+M_SYNCHRONOUS, &Time);
MosPrintf(MIL_TEXT("Add constant time: %.3f ms.\n"), (Time*1000.0)/NB_LOOP);
MbufCopy(MilImageDst, MilImageDisp);
MosPrintf(MIL_TEXT("Press <Enter> to terminate.\n"));
MosGetchar();
MbufFree(MilImageSrc);
MbufFree(MilImageDst);
MappFreeDefault(MilApplication, MilSystem, MilDisplay, M_NULL, MilImageDisp);
return 0;
}