15 #include <epicsVersion.h> 16 #include <epicsAssert.h> 17 #include <epicsTypes.h> 18 #include <epicsInterrupt.h> 21 #include <epicsStdio.h> 22 #include <epicsExport.h> 26 int validate_widths(epicsUInt32 addr,
int amod,
int dmod,
int count,
volatile void** mptr)
28 epicsAddressType atype;
38 fprintf(stderr,
"Invalid data width %d\n",dmod);
43 case 16: atype=atVMEA16; alim = 0xffff;
break;
44 case 24: atype=atVMEA24; alim = 0xffffff;
break;
45 case 32: atype=atVMEA32; alim = 0xffffffff;
break;
47 fprintf(stderr,
"Invalid address width %d\n",amod);
54 if(dbytes <=0 || dbytes>4){
55 fprintf(stderr,
"Invalid data width\n");
60 (addr+count*dbytes >= alim)) {
61 fprintf(stderr,
"Address/count out of range\n");
68 fprintf(stderr,
"Invalid register address\n");
72 printf(
"Mapped to %p\n",*mptr);
84 void vmeread(
int rawaddr,
int amod,
int dmod,
int count)
86 epicsUInt32 addr = rawaddr;
94 printf(
"Reading from 0x%08x A%d D%d\n",addr,amod,dmod);
96 if(validate_widths(addr, amod, dmod, count, &mptr))
101 for(i=0, dptr=mptr; i<count; i++, dptr+=dbytes) {
102 epicsUInt32 tval = -1;
103 if ((i*dbytes)%16==0)
104 printf(
"\n0x%08x ",i*dbytes);
105 else if ((i*dbytes)%4==0)
111 case 8: printf(
"%02x",(tval>>24)&0xff);
break;
112 case 16: printf(
"%04x",(tval>>16)&0xffff);
break;
113 case 32: printf(
"%08x",tval&0xffffffff);
break;
119 fprintf(stderr,
"*** Bus errors occurred ***\n");
122 static const iocshArg vmereadArg0 = {
"address",iocshArgInt};
123 static const iocshArg vmereadArg1 = {
"amod",iocshArgInt};
124 static const iocshArg vmereadArg2 = {
"dmod",iocshArgInt};
125 static const iocshArg vmereadArg3 = {
"count",iocshArgInt};
126 static const iocshArg *
const vmereadArgs[4] =
127 {&vmereadArg0,&vmereadArg1,&vmereadArg2,&vmereadArg3};
128 static const iocshFuncDef vmereadFuncDef =
129 {
"vmeread",4,vmereadArgs};
131 static void vmereadCall(
const iocshArgBuf *args)
133 vmeread(args[0].ival, args[1].ival, args[2].ival, args[3].ival);
143 void vmewrite(
int rawaddr,
int amod,
int dmod,
int rawvalue)
145 epicsUInt32 addr = rawaddr, value = rawvalue;
149 printf(
"Writing to 0x%08x A%d D%d value 0x%08x\n",addr,amod,dmod, (
unsigned)value);
151 if(validate_widths(addr, amod, dmod, 1, &mptr))
155 case 8: value<<=24;
break;
156 case 16: value<<=16;
break;
164 fprintf(stderr,
"*** Bus Error detected ***\n");
167 static const iocshArg vmewriteArg0 = {
"address",iocshArgInt};
168 static const iocshArg vmewriteArg1 = {
"amod",iocshArgInt};
169 static const iocshArg vmewriteArg2 = {
"dmod",iocshArgInt};
170 static const iocshArg vmewriteArg3 = {
"count",iocshArgInt};
171 static const iocshArg *
const vmewriteArgs[4] =
172 {&vmewriteArg0,&vmewriteArg1,&vmewriteArg2,&vmewriteArg3};
173 static const iocshFuncDef vmewriteFuncDef =
174 {
"vmewrite",4,vmewriteArgs};
176 static void vmewriteCall(
const iocshArgBuf *args)
178 vmewrite(args[0].ival, args[1].ival, args[2].ival, args[3].ival);
181 static volatile epicsUInt8 vmeautodisable[256];
183 static const char hexchars[] =
"0123456789ABCDEF";
186 void vmesh_handler(
void *raw)
188 volatile epicsUInt8 *ent = raw;
189 unsigned char vect = (
unsigned char)(ent-vmeautodisable);
190 char msg[] =
"VME IRQ on vector 0xXY\n";
191 unsigned I =
sizeof(msg)-3;
193 msg[I--] = hexchars[vect&0xf];
195 msg[I--] = hexchars[vect&0xf];
196 epicsInterruptContextMessage(msg);
199 epicsInterruptContextMessage(
"oops, can't disable level");
218 if(strcmp(itype,
"rora")==0) {
220 }
else if(strcmp(itype,
"roak")==0) {
223 fprintf(stderr,
"Unknown IRQ ack method '%s' (must be \"rora\" or \"roak\")\n", itype);
226 if(level<1 || level>7) {
227 fprintf(stderr,
"IRQ level %d out of range (1-7)\n", level);
231 fprintf(stderr,
"IRQ vector %d out of range (1-7)\n", vector);
234 if(vmeautodisable[vector]) {
235 fprintf(stderr,
"Vector already in use\n");
239 iowrite8(&vmeautodisable[vector], level);
240 if(devConnectInterruptVME(vector, &vmesh_handler, (
void*)&vmeautodisable[vector]))
241 fprintf(stderr,
"Failed to install ISR\n");
244 static const iocshArg vmeirqattachArg0 = {
"level",iocshArgInt};
245 static const iocshArg vmeirqattachArg1 = {
"vector",iocshArgInt};
246 static const iocshArg vmeirqattachArg2 = {
"acktype",iocshArgString};
247 static const iocshArg *
const vmeirqattachArgs[3] =
248 {&vmeirqattachArg0,&vmeirqattachArg1,&vmeirqattachArg2};
249 static const iocshFuncDef vmeirqattachFuncDef =
250 {
"vmeirqattach",3,vmeirqattachArgs};
252 static void vmeirqattachCall(
const iocshArgBuf *args)
264 if(level<1 || level>7) {
265 fprintf(stderr,
"IRQ level %d out of range (1-7)\n", level);
269 if(devEnableInterruptLevelVME(level))
270 fprintf(stderr,
"Failed to enable level\n");
273 fprintf(stderr,
"Failed to disable level\n");
277 static const iocshArg vmeirqArg0 = {
"level",iocshArgInt};
278 static const iocshArg vmeirqArg1 = {
"en/disable",iocshArgInt};
279 static const iocshArg *
const vmeirqArgs[2] =
280 {&vmeirqArg0,&vmeirqArg1};
281 static const iocshFuncDef vmeirqFuncDef =
282 {
"vmeirq",2,vmeirqArgs};
284 static void vmeirqCall(
const iocshArgBuf *args)
286 vmeirq(args[0].ival, args[1].ival);
289 static void vmesh(
void)
291 iocshRegister(&vmereadFuncDef,vmereadCall);
292 iocshRegister(&vmewriteFuncDef,vmewriteCall);
293 iocshRegister(&vmeirqattachFuncDef,vmeirqattachCall);
294 iocshRegister(&vmeirqFuncDef,vmeirqCall);
295 #if EPICS_VERSION==3 && EPICS_REVISION==14 && EPICS_MODIFICATION<10 void vmeirqattach(int level, int vector, const char *itype)
#define devBusToLocalAddr
void vmeread(int rawaddr, int amod, int dmod, int count)
long devDisableInterruptLevelVME(unsigned level)
epicsExportRegistrar(vmesh)
INLINE void iowrite8(volatile void *addr, epicsUInt8 val)
Write a single byte.
void vmeirq(int level, int act)
void devReplaceVirtualOS(void)
void vmewrite(int rawaddr, int amod, int dmod, int rawvalue)
long devWriteProbe(unsigned wordSize, volatile void *ptr, const void *pValueWritten)
long devReadProbe(unsigned wordSize, volatile const void *ptr, void *pValueRead)