/* $Id: devPac.c,v 1.1.1.1 2009/03/07 20:57:17 ernesto Exp $ */ /* To fill in this template search for * Aao (record type) * Pac (device type) */ /*============================================================================= Name: devPac.c Abs: Pac Device support for Aao. Auth: 10-oct-2006, Till Straumann (TSS) Rev: 17-feb-2009, S. Allison (renamed from devAaoPac.c, added waveform support) -----------------------------------------------------------------------------*/ /*----------------------------------------------------------------------------- Mod: (see CVS log) =============================================================================*/ #include #include #include #include #include #include #include #include #include #include /* Which chip select we are using - this is setup by the BSP * but not published :-( */ #define CS1_BASE_ADDR 0x30000000 #define CS1 1 #define DEVSUPNAM "devPac" static int uninitialized = 1; static long report_aao(int interest) { epicsPrintf(DEVSUPNAM": Pac device support for Aao\n"); return 0; } static long report_wfm(int interest) { epicsPrintf(DEVSUPNAM": Pac device support for Waveform\n"); return 0; } static long init(int after) { if ( uninitialized ) { uninitialized = 0; coldfCsSetup(CS1, MCF5282_CS_CSCR_BEM); devBusMappedRegister("PAC", (volatile void*)CS1_BASE_ADDR); } return 0; } static long init_record_aao(void *record_p) { aaoRecord *aao_ps = record_p; unsigned s; union { unsigned short s; unsigned char c[2]; } isBE = { s: 1 }; if ( VME_IO != aao_ps->out.type ) { epicsPrintf(DEVSUPNAM": OUT link not VME_IO\n"); aao_ps->pact = 1; return -1; } if ( (s = aao_ps->out.value.vmeio.signal) > 1 ) { epicsPrintf(DEVSUPNAM": OUT link: 'signal' %u too big (0..1)\n",s); aao_ps->pact = 1; return -1; } if ( ! isBE.c[1] ) { epicsPrintf(DEVSUPNAM": Support for little-endian CPU not implemented\n"); aao_ps->pact = 1; return -1; } aao_ps->bptr = (void*)(CS1_BASE_ADDR + (s*0x1000)); if (aao_ps->nelm >= 2048) aao_ps->nord = 2048; else aao_ps->nord = aao_ps->nelm; return 0; } static long init_record_wfm(void *record_p) { waveformRecord *wfm_ps = record_p; int idx; unsigned s; union { unsigned short s; unsigned char c[2]; } isBE = { s: 1 }; if ( VME_IO != wfm_ps->inp.type ) { epicsPrintf(DEVSUPNAM": INP link not VME_IO\n"); wfm_ps->pact = 1; return -1; } if ( (s = wfm_ps->inp.value.vmeio.signal) > 1 ) { epicsPrintf(DEVSUPNAM": INP link: 'signal' %u too big (0..1)\n",s); wfm_ps->pact = 1; return -1; } if ( ! isBE.c[1] ) { epicsPrintf(DEVSUPNAM": Support for little-endian CPU not implemented\n"); wfm_ps->pact = 1; return -1; } wfm_ps->dpvt = (void*)(CS1_BASE_ADDR + (s*0x1000)); if (wfm_ps->nelm >= 2048) wfm_ps->nord = 2048; else wfm_ps->nord = wfm_ps->nelm; for (idx = 0; idx < wfm_ps->nord; idx++) { short short_value = *(((short *)wfm_ps->dpvt) + idx); if (DBF_SHORT == wfm_ps->ftvl) *(((short *)wfm_ps->bptr) + idx) = (short) short_value; else if (DBF_LONG == wfm_ps->ftvl) *(((long *)wfm_ps->bptr) + idx) = (long) short_value; else if (DBF_FLOAT == wfm_ps->ftvl) *(((float *)wfm_ps->bptr) + idx) = (float) short_value; else if (DBF_DOUBLE == wfm_ps->ftvl) *(((double *)wfm_ps->bptr) + idx) = (double)short_value; else { epicsPrintf(DEVSUPNAM": invalid FTVL value\n"); wfm_ps->pact = 1; return -1; } } return 0; } /* unused; would have to do byte-swapping on little-endian CPU here */ static long write_aao(void *record_p) { /* aaoRecord *aao_ps = record_p; PacDpvt_tps dpvt_ps = aao_ps->dpvt; */ return 0; } static long write_wfm(void *record_p) { waveformRecord *wfm_ps = record_p; int idx; for (idx = 0; idx < wfm_ps->nord; idx++) { short short_value; if (DBF_SHORT == wfm_ps->ftvl) short_value = (short)*(((short *)wfm_ps->bptr) + idx); else if (DBF_LONG == wfm_ps->ftvl) short_value = (short)*(((long *)wfm_ps->bptr) + idx); else if (DBF_FLOAT == wfm_ps->ftvl) short_value = (short)*(((float *)wfm_ps->bptr) + idx); else if (DBF_DOUBLE == wfm_ps->ftvl) short_value = (short)*(((double *)wfm_ps->bptr) + idx); else short_value = (short)*(((short *)wfm_ps->dpvt) + idx); if (idx < 2048) { *(((short *)wfm_ps->dpvt) + idx) = short_value; } } for (; idx < 2048; idx++) *(((short *)wfm_ps->dpvt) + idx) = 0; return 0; } struct { long number; DEVSUPFUN report; DEVSUPFUN init; DEVSUPFUN init_record; DEVSUPFUN get_ioint_info; DEVSUPFUN read; } devAaoPac = { 5, report_aao, init, init_record_aao, NULL, write_aao }; epicsExportAddress(dset, devAaoPac); struct { long number; DEVSUPFUN report; DEVSUPFUN init; DEVSUPFUN init_record; DEVSUPFUN get_ioint_info; DEVSUPFUN read; } devWfmPac = { 5, report_wfm, init, init_record_wfm, NULL, write_wfm }; epicsExportAddress(dset, devWfmPac);