#include #include #include #include #include /*convert value to 2bit signed 2's comp */ static int convFloattoSigned18(double v) { int i = (int) v; i &= (0x3ffff); return i; } /* convert value to 18.5 fixed point */ static int convFloattoFixed1805(double v) { int i; if(v == 0.) return 0; i = (int)(v * (double) ((0x1f) +1)); i &= (0x3ffff); if(v>0. && (i & (0x1<<17))) i -= 1; return i; } /* convert value to 18.17 fixed point */ static int convFloattoFixed1817(double v) { int i; if(v == 0.) return 0; i = (int)(v * (double) ((0x1ffff) +1)); i &= (0x3ffff); if(v>0. &&(i & (0x1<<17))) i -= 1; return i; } /* conversion 2's comp signed (18bits) to floating point */ static double convSigned18toFloat(unsigned u) { int u32; int length = 18; u32 = (u & (1<<(length-1)))? ((~0x3ffff) | u) : u; return (double) u32; } /* conversion 2's comp fixed point (18.17bit) to floating point */ static double convFixed1817toFloat(unsigned u) { return convSigned18toFloat(u) / (double) (0x1ffff +1); } /* conversion 2's comp fixed point (18. 5bit) to floating point */ static double convFixed1805toFloat(unsigned u) { return convSigned18toFloat(u) / (double) (0x1f +1); } /* subroutine record, get DAC voltage */ static long getDACVolt(subRecord *psub) { psub->val = convFixed1817toFloat((unsigned)(psub->a)) * 5.; return 0; } /* subroutine record, get voltage */ static long getADCVolt(subRecord *psub) { psub->val = convFixed1817toFloat((unsigned)(psub->a)) * 1.8; return 0; } /* subroutine record, get degreee */ static long getDegree(subRecord *psub) { psub->val = convFixed1817toFloat((unsigned)(psub->a)) * 180.; return 0; } /* subroutine record, get 18bit signed integer */ static long getSigned18(subRecord *psub) { psub->val = convSigned18toFloat((unsigned)(psub->a)); return 0; } /* subroutine record, get Fixed 18.17 */ static long getFixed1817(subRecord *psub) { psub->val = convFixed1817toFloat((unsigned)(psub->a)); return 0; } /* subroutine record, get Fixed 18.5 */ static long getFixed1805(subRecord *psub) { psub->val = convFixed1805toFloat((unsigned)(psub->a)); return 0; } /* subroutine record, set signed 18 bit */ static long setSigned18(subRecord *psub) { psub->val = (double) convFloattoSigned18(psub->a); return 0; } /* subroutine record, set fixed 18.5 bit */ static long setFixed1805(subRecord *psub) { psub->val = (double) convFloattoFixed1805(psub->a); return 0; } /* subroutine record, set fixed 18.17 bit */ static long setFixed1817(subRecord *psub) { psub->val = (double) convFloattoFixed1817(psub->a); return 0; } /* subroutine record, set degree */ static long setDegree(subRecord *psub) { psub->val = (double) convFloattoFixed1817(psub->a / 180.); return 0; } epicsRegisterFunction(getDACVolt); epicsRegisterFunction(getADCVolt); epicsRegisterFunction(getDegree); epicsRegisterFunction(getSigned18); epicsRegisterFunction(getFixed1817); epicsRegisterFunction(getFixed1805); epicsRegisterFunction(setSigned18); epicsRegisterFunction(setFixed1805); epicsRegisterFunction(setFixed1817); epicsRegisterFunction(setDegree);