#include <mil.h>
#include <milfpga.h>
#include <fpga_gainoffset.h>
#define FUNCTION_NB_PARAM_OFFSET_GAIN 5
#define FUNCTION_OPCODE_FPGA_OFFSET_GAIN 8
#define FUNCTION_PARAMETER_ERROR_CODE 1
#define FUNCTION_WRONG_FPGA_ERROR_CODE 2
void MFTYPE FPGAOffsetGainSlave(MIL_ID Func);
void FPGAOffsetGainPrimitive(MIL_ID Func, MIL_ID SrcImageId,
MIL_ID OffsetImageId, MIL_ID GainImageId, MIL_INT Src4, MIL_ID DstImageId);
void FPGAInitializeShadowRegisters(MIL_ID Func, FPGA_GAINOFFSET_USER_ST* pOGShadow,
MIL_BUFFER_INFO Src1, MIL_BUFFER_INFO Src2, MIL_BUFFER_INFO Src3, MIL_INT Src4,
MIL_BUFFER_INFO Dst);
void FPGAOffsetGainPrimitive(MIL_ID Func, MIL_ID SrcImageId,
MIL_ID OffsetImageId, MIL_ID GainImageId,
MIL_INT Src4, MIL_ID DstImageId)
{
MIL_BUFFER_INFO Src, Offset, Gain, Dst;
MIL_FPGA_CONTEXT OffsetGainContext;
FPGA_GAINOFFSET_USER_ST GOShadow;
memset(&GOShadow, 0, sizeof(GOShadow));
MfuncInquire(SrcImageId, M_BUFFER_INFO, &Src);
MfuncInquire(OffsetImageId, M_BUFFER_INFO, &Offset);
MfuncInquire(GainImageId, M_BUFFER_INFO, &Gain);
MfuncInquire(DstImageId, M_BUFFER_INFO, &Dst);
if(MfpgaCommandAlloc(MfuncBufOwnerSystemId(Src), M_DEV0, FPGA_GAINOFFSET_FID,
M_DEFAULT, M_DEV0, M_ASYNCHRONOUS, M_DEFAULT, &OffsetGainContext))
{
FPGAInitializeShadowRegisters(Func, &GOShadow, Src,
Offset, Gain, Src4, Dst);
MfpgaSetSource(OffsetGainContext, Src, M_INPUT0, M_DEFAULT);
MfpgaSetSource(OffsetGainContext, Offset, M_INPUT1, M_DEFAULT);
MfpgaSetSource(OffsetGainContext, Gain, M_INPUT2, M_DEFAULT);
MfpgaSetRegister(OffsetGainContext, M_USER, 0, sizeof(GOShadow),
(void*)(&GOShadow), M_WHEN_DISPATCHED);
MfpgaSetDestination(OffsetGainContext, Dst, M_OUTPUT0, M_DEFAULT);
MfpgaCommandQueue(OffsetGainContext, M_DEFAULT, M_DEFAULT);
MfpgaCommandFree(OffsetGainContext, M_DEFAULT);
}
else
{
MfuncErrorReport(
Func, M_FUNC_ERROR+FUNCTION_WRONG_FPGA_ERROR_CODE,
MIL_TEXT("No OffsetGain 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 FPGAInitializeShadowRegisters( MIL_ID Func,
FPGA_GAINOFFSET_USER_ST* pOGShadow,
MIL_BUFFER_INFO Src1,
MIL_BUFFER_INFO Src2,
MIL_BUFFER_INFO Src3,
MIL_INT Src4,
MIL_BUFFER_INFO Dst)
{
MIL_UINT lMaxValue, Src1Type, Src2Type, Src3Type, DstType, i, j;
lMaxValue = (MIL_UINT)MfuncBufMaxValue(Src1);
Src1Type = MfuncBufType(Src1);
Src2Type = MfuncBufType(Src2);
Src3Type = MfuncBufType(Src3);
DstType = MfuncBufType(Dst);
switch(Src1Type)
{
case 8+M_UNSIGNED:
pOGShadow->ctrl.f.srctype = 0x1; break;
case 16+M_UNSIGNED:
pOGShadow->ctrl.f.srctype = 0x3; break;
default:
MfuncErrorReport(
Func, M_FUNC_ERROR+FUNCTION_PARAMETER_ERROR_CODE,
MIL_TEXT("Invalid source buffer type."),
M_NULL, M_NULL, M_NULL
);
break;
}
switch(Src2Type)
{
case 8+M_UNSIGNED:
pOGShadow->ctrl.f.offtype = 0x1; break;
case 16+M_UNSIGNED:
pOGShadow->ctrl.f.offtype = 0x3; break;
default:
MfuncErrorReport(
Func, M_FUNC_ERROR+FUNCTION_PARAMETER_ERROR_CODE,
MIL_TEXT("Invalid offset buffer type."),
M_NULL, M_NULL, M_NULL
);
break;
}
switch(Src3Type)
{
case 8+M_UNSIGNED:
pOGShadow->ctrl.f.gaintype = 0x1; break;
case 16+M_UNSIGNED:
pOGShadow->ctrl.f.gaintype = 0x3; break;
default:
MfuncErrorReport(
Func, M_FUNC_ERROR+FUNCTION_PARAMETER_ERROR_CODE,
MIL_TEXT("Invalid gain buffer type."),
M_NULL, M_NULL, M_NULL
);
break;
}
switch(DstType)
{
case 8+M_UNSIGNED:
pOGShadow->ctrl.f.dsttype = 0x1; break;
case 16+M_UNSIGNED:
pOGShadow->ctrl.f.dsttype = 0x3; break;
default:
MfuncErrorReport(
Func, M_FUNC_ERROR+FUNCTION_PARAMETER_ERROR_CODE,
MIL_TEXT("Invalid destination buffer type."),
M_NULL, M_NULL, M_NULL
);
break;
}
pOGShadow->clipval.f.clipval = lMaxValue;
j=1;
for(i=0; i<32; i++)
{
if(Src4 & j)
{
pOGShadow->ctrl.f.shift = i;
break;
}
j <<= 1;
}
}
void FPGAOffsetGain(MIL_ID SrcImageId, MIL_ID OffsetImageId,
MIL_ID GainImageId, MIL_INT Src4, MIL_ID DstImageId)
{
MIL_ID Func;
MfuncAlloc(MIL_TEXT("FPGAOffsetGain"),
FUNCTION_NB_PARAM_OFFSET_GAIN,
FPGAOffsetGainSlave, M_NULL, M_NULL,
M_USER_MODULE_1+FUNCTION_OPCODE_FPGA_OFFSET_GAIN,
M_DEFAULT,
&Func
);
MfuncParamMilId (Func, 1, SrcImageId, M_IMAGE, M_IN);
MfuncParamMilId (Func, 2, OffsetImageId, M_IMAGE, M_IN);
MfuncParamMilId (Func, 3, GainImageId, M_IMAGE, M_IN);
MfuncParamMilInt(Func, 4, Src4);
MfuncParamMilId (Func, 5, DstImageId, M_IMAGE, M_OUT);
MfuncCall(Func);
MfuncFree(Func);
}
void MFTYPE FPGAOffsetGainSlave(MIL_ID Func)
{
MIL_ID SrcImageId, OffsetImageId, GainImageId, DstImageId;
MIL_INT Src4;
MfuncParamValue(Func, 1, &SrcImageId);
MfuncParamValue(Func, 2, &OffsetImageId);
MfuncParamValue(Func, 3, &GainImageId);
MfuncParamValue(Func, 4, &Src4);
MfuncParamValue(Func, 5, &DstImageId);
FPGAOffsetGainPrimitive(Func, SrcImageId, OffsetImageId, GainImageId, Src4, DstImageId);
}