/****************************************************************************** * Module: Llrf pad Temperature Monitoring driver definitions * Filename: devAiPadQspi.c * Author: Shantha Condamoor * Created: 8-Aug-2014 * Description: * LLRF PAD Temperature monitoring related device support functions. * LLRF PAD's use The slow-speed 24-bit ADC in the ADS1218 chipset * interfaces to coldFire module's slow, queued serial port interface perifpheral. * ****************************************************************************** * Modification history * Mod: Shantha Condamoor 08-Aug-2014 * Initial Release. * Defines Ai record for reading the temps from the QSPI driver for 8 channels *****************************************************************************/ #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include /* for SCAN_IO_EVENT */ #include #include /* for aiRecord structure */ #include /* for epicsExportAddress */ #include /* for epicsThreadSleepQuantum */ #include /* for DEBUGPRINT */ #include /* for epicsPrintf */ #define DEVSUPNAM "devAiPad" #include "drvPadQspi.h" #define DEBUG_PRINT 1 extern IOSCANPVT padQspiIoscan[]; typedef struct aiPad_s { int channel; } aiPad_t; LOCAL long init_record(); LOCAL long read_ai(); #ifdef DEBUG_PRINT int devAiPadFlag = 1; int devAiSlowADCPadFlag = 1; #endif static long report(int interest) { epicsPrintf(DEVSUPNAM": Qspi Llrf Signal device support for analog in\n"); return 0; } LOCAL long init_record(aiRecord *pai) { aiPad_t *paip; /* Allocate the memory for this records private data structure */ paip = (aiPad_t *) malloc(sizeof(aiPad_t)); if (paip == NULL) { DEBUGPRINT(DP_ERROR, devAiPadFlag, ("init_ai: %s: out of memory\n", pai->name)); return S_dev_noMemory; } paip->channel = 99; /* for debug */ /* Tell the record about its private data structure */ pai->dpvt = paip; switch(pai->inp.type) { case(INST_IO): sscanf(pai->inp.value.instio.string, "%d", &(paip->channel)); DEBUGPRINT(DP_INFO, devAiPadFlag, ("init_ai: %s: init routine with channel: %d\n", pai->name, paip->channel)); break; default: DEBUGPRINT(DP_ERROR, devAiPadFlag, ("init_ai: %s: unrecognized link type\n", pai->name)); return -1; } return 0; } /** for sync scan records **/ static long ai_ioint_info(int cmd,aiRecord *pai,IOSCANPVT *iopvt) { int channel = 99; sscanf(pai->inp.value.instio.string, "%d", &channel); /* Do some range checks */ if (( channel < 0 ) || ( channel > 8 )) { errlogPrintf("devAiPadQspi: %s: ai_ioint_info() -- Illegal INP: channel # %i out of range\n", pai->name, channel); pai->pact = TRUE; return (S_db_badField); } *iopvt = padQspiIoscan[channel]; return 0; } LOCAL long read_ai(aiRecord *pai) { aiPad_t *paip; /* Set this to facilitate easy access to channel field */ if (pai->dpvt == NULL) { DEBUGPRINT(DP_ERROR, devAiPadFlag, ("read_ai: %s: dpvt is NULL\n", pai->name)); return -1; } paip = (aiPad_t *)pai->dpvt; pai->rval = llrfGetPadTemperatureValue(paip->channel); DEBUGPRINT(DP_INFO, devAiSlowADCPadFlag, ("read_ai: %s: read routine with channel: %d has rval: %lu gets val: %lu\n", pai->name, paip->channel, pai->rval, pai->val)); /* ASLO and AOFF applied by EPICS */ return 0; } struct { long number; DEVSUPFUN report; DEVSUPFUN init; DEVSUPFUN init_record; DEVSUPFUN get_ioint_info; DEVSUPFUN read_ai; DEVSUPFUN special_linconv; /* LESSON LEARNED! if you don't put this in, (even when you don't use it), you get the iocInit error that device support for init_record is missing, even though record is created and read_ai processes!!! */ } devAiPad = { 6, report, NULL, init_record, ai_ioint_info, read_ai, NULL }; epicsExportAddress(dset,devAiPad);