#include <mil.h>
#include <milfpga.h>
#include <fpga_addconst.h>
#define FUNCTION_NB_PARAM 4
#define FUNCTION_OPCODE_FPGA_ADD_CONSTANT 1
#define FUNCTION_PARAMETER_ERROR_CODE 1
#define FUNCTION_WRONG_FPGA_ERROR_CODE 2
void FpgaAddConstant(MIL_ID SrcImageId, MIL_ID DstImageId, MIL_INT ConstantToAdd,
MIL_INT ControlFlag);
void MFTYPE FPGAAddConstantSlave(MIL_ID Func);
void FPGAAddConstantPrimitive(MIL_ID Func, MIL_ID MilSourceImage,
MIL_ID MilDestinationImage, MIL_INT ConstantValue, MIL_INT ControlFlag);
void FPGAAddConstantPrimitive(MIL_ID Func,MIL_ID MilSourceImage,
MIL_ID MilDestinationImage, MIL_INT ConstantValue, MIL_INT ControlFlag)
{
MIL_BUFFER_INFO Src, Dest;
MIL_FPGA_CONTEXT AddConstantContext;
FPGA_ADDCONST_USER_ST ShadowRegisters;
memset(&ShadowRegisters, 0, sizeof(ShadowRegisters));
MfuncInquire(MilSourceImage, M_BUFFER_INFO, &Src);
MfuncInquire(MilDestinationImage, M_BUFFER_INFO, &Dest);
if(((MfuncBufSizeBit(Src) != 8) && (MfuncBufSizeBand(Src) != 1)) ||
((MfuncBufSizeBit(Dest) != 8) && (MfuncBufSizeBand(Dest)!= 1))
)
{
MfuncErrorReport(Func, M_FUNC_ERROR+FUNCTION_PARAMETER_ERROR_CODE,
MIL_TEXT("Only 8 bit, monochrome buffers are supported for Add Constant."),
M_NULL, M_NULL, M_NULL );
return;
}
if(MfpgaCommandAlloc(MfuncBufOwnerSystemId(Src), M_DEV0, FPGA_ADDCONST_FID,
M_DEFAULT, M_DEV0, M_ASYNCHRONOUS, M_DEFAULT, &AddConstantContext)
)
{
MfpgaSetSource(AddConstantContext, Src, M_INPUT0, M_DEFAULT);
MfpgaSetDestination(AddConstantContext, Dest, M_OUTPUT0, M_DEFAULT);
ShadowRegisters.val.f.val = ConstantValue;
if(MfuncBufType(Src) == 8+M_SIGNED)
ShadowRegisters.ctrl.f.optype = 0;
else
ShadowRegisters.ctrl.f.optype = 1;
if(ControlFlag & M_SATURATION)
ShadowRegisters.ctrl.f.sat = 1;
else
ShadowRegisters.ctrl.f.sat = 0;
MfpgaSetRegister(AddConstantContext, M_USER, 0, sizeof(ShadowRegisters),
(void*)(&ShadowRegisters), M_WHEN_DISPATCHED);
MfpgaCommandQueue(AddConstantContext, M_DEFAULT, M_DEFAULT);
MfpgaCommandFree(AddConstantContext, M_DEFAULT);
}
else
{
MfuncErrorReport(
Func, M_FUNC_ERROR+FUNCTION_WRONG_FPGA_ERROR_CODE,
MIL_TEXT("No AddConstant acceleration supported by this FPGA configuration."),
MIL_TEXT("Please select the proper FPGA configuration file."),
MIL_TEXT("See the processing FPGA section of the milconfig utility."),
M_NULL
);
}
}
void FpgaAddConstant(MIL_ID SrcImageId, MIL_ID DstImageId, MIL_INT ConstantToAdd, MIL_INT ControlFlag)
{
MIL_ID Func;
MfuncAlloc(MIL_TEXT("FPGAAddConstant"),
FUNCTION_NB_PARAM,
FPGAAddConstantSlave, M_NULL, M_NULL,
M_USER_MODULE_1+FUNCTION_OPCODE_FPGA_ADD_CONSTANT,
M_DEFAULT,
&Func
);
MfuncParamMilId (Func, 1, SrcImageId, M_IMAGE, M_IN);
MfuncParamMilId (Func, 2, DstImageId, M_IMAGE, M_OUT);
MfuncParamMilInt(Func, 3, ConstantToAdd);
MfuncParamMilInt(Func, 4, ControlFlag);
MfuncCall(Func);
MfuncFree(Func);
}
void MFTYPE FPGAAddConstantSlave(MIL_ID Func)
{
MIL_ID SrcImageId, DstImageId;
MIL_INT ConstantToAdd, ControlFlag;
MfuncParamValue(Func, 1, &SrcImageId);
MfuncParamValue(Func, 2, &DstImageId);
MfuncParamValue(Func, 3, &ConstantToAdd);
MfuncParamValue(Func, 4, &ControlFlag);
FPGAAddConstantPrimitive(Func, SrcImageId, DstImageId, ConstantToAdd, ControlFlag);
}