/*************************************************************************\ * Copyright (c) 2015 Michael Davidsaver * Copyright (c) 2010 Brookhaven Science Associates, as Operator of * Brookhaven National Laboratory. * devLib2 is distributed subject to a Software License Agreement found * in file LICENSE that is included with this distribution. \*************************************************************************/ /* * Author: Michael Davidsaver */ #include #include #include #include #include #include #include #include #include #include static int validate_widths(epicsUInt32 addr, int amod, int dmod, int count, volatile void** mptr) { epicsUInt32 tval; epicsAddressType atype; short dbytes; switch(dmod){ case 8: case 16: case 32: break; default: epicsPrintf("Invalid data width %d\n",dmod); return 1; } switch(amod){ case 16: atype=atVMEA16; break; case 24: atype=atVMEA24; break; case 32: atype=atVMEA32; break; default: epicsPrintf("Invalid address width %d\n",amod); return 1; } dbytes=dmod/8; if(dmod%8) dbytes++; if(dbytes <=0 || dbytes>4){ epicsPrintf("Invalid data width\n"); return 1; } if( (addr > ((1<= ((1<>=4; msg[I--] = hexchars[vect&0xf]; epicsInterruptContextMessage(msg); if(*ent && devDisableInterruptLevelVME(*ent)) epicsInterruptContextMessage("oops, can't disable level"); } /** Attach a dummy interrupt handler which prints a message to screen * * @param level The interrupt level (1-7) * @param vector The vector code (0-255) * @param itype Either "rora" or "roak" acknowledgement type * * In "roak" (Release On AcKnowledge) the interrupt level * is left active when the interrupt occurs. * In "rora" (Release On Register Access) the interrupt level * is disabled each time the given vector is interrupted. * For "rora" vmeirq() should be called after each interrupt to * re-enabled the level. */ void vmeirqattach(int level, int vector, const char *itype) { int acktype; if(strcmp(itype, "rora")==0) { acktype = 1; } else if(strcmp(itype, "roak")==0) { acktype = 0; } else { epicsPrintf("Unknown IRQ ack method '%s' (must be \"rora\" or \"roak\")\n", itype); return; } if(level<1 || level>7) { epicsPrintf("IRQ level %d out of range (1-7)\n", level); return; } if(vector>255) { epicsPrintf("IRQ vector %d out of range (1-7)\n", vector); return; } if(vmeautodisable[vector]) { epicsPrintf("Vector already in use\n"); return; } if(acktype) iowrite8(&vmeautodisable[vector], level); if(devConnectInterruptVME(vector, &vmesh_handler, (void*)&vmeautodisable[vector])) epicsPrintf("Failed to install ISR\n"); } static const iocshArg vmeirqattachArg0 = { "level",iocshArgInt}; static const iocshArg vmeirqattachArg1 = { "vector",iocshArgInt}; static const iocshArg vmeirqattachArg2 = { "acktype",iocshArgString}; static const iocshArg * const vmeirqattachArgs[3] = {&vmeirqattachArg0,&vmeirqattachArg1,&vmeirqattachArg2}; static const iocshFuncDef vmeirqattachFuncDef = {"vmeirqattach",3,vmeirqattachArgs}; static void vmeirqattachCall(const iocshArgBuf *args) { vmeirqattach(args[0].ival, args[1].ival, args[2].sval); } /** En/Disable a VME interrupt level * * @param level The interrupt level (1-7) * @param act 0 - disable, 1 - enable the given level. */ void vmeirq(int level, int act) { if(level<1 || level>7) { epicsPrintf("IRQ level %d out of range (1-7)\n", level); return; } if(act) { if(devEnableInterruptLevelVME(level)) epicsPrintf("Failed to enable level\n"); } else { if(devDisableInterruptLevelVME(level)) epicsPrintf("Failed to disable level\n"); } } static const iocshArg vmeirqArg0 = { "level",iocshArgInt}; static const iocshArg vmeirqArg1 = { "en/disable",iocshArgInt}; static const iocshArg * const vmeirqArgs[2] = {&vmeirqArg0,&vmeirqArg1}; static const iocshFuncDef vmeirqFuncDef = {"vmeirq",2,vmeirqArgs}; static void vmeirqCall(const iocshArgBuf *args) { vmeirq(args[0].ival, args[1].ival); } static void vmesh(void) { iocshRegister(&vmereadFuncDef,vmereadCall); iocshRegister(&vmewriteFuncDef,vmewriteCall); iocshRegister(&vmeirqattachFuncDef,vmeirqattachCall); iocshRegister(&vmeirqFuncDef,vmeirqCall); #if EPICS_VERSION==3 && EPICS_REVISION==14 && EPICS_MODIFICATION<10 devReplaceVirtualOS(); #endif } epicsExportRegistrar(vmesh);