/*============================================================================= Name: drvPnet.c pnetInitialise - hardware initialisation pnetReport - driver report pnetISR - interrupt service routine pnetTask - high priority pnet processing task Abs: Driver support for VME PNET Receiver module. Refs: See list of docs under the heading "VME PNET Module" on page: http://www.slac.stanford.edu/grp/lcls/controls/global/subsystems/timing Compiler Flags: DEBUG_PRINT - To define debug flag. Auth: 07-jul-2005, Dayle Kotturi (dayle): Rev: 13-mar-2007, S. Allison (saa) -----------------------------------------------------------------------------*/ #include "copyright_SLAC.h" /* SLAC copyright comments */ /*----------------------------------------------------------------------------- Mod: (newest to oldest) DD-MMM-YYYY, My Name: Changed such and such to so and so. etc. etc. DD-MMM-YYYY, Your Name: More changes ... The ordering of the revision history should be such that the NEWEST changes are at the HEAD of the list. =============================================================================*/ #include /* for DRVSUPFN */ #ifdef __rtems__ #include /* for dev*routines, atVMEA16 */ #include /* for in_be32 */ #endif #include /* for errlogPrintf */ #include /* for epicsExportAddress */ #include /* for epicsEvent* */ #include /* for epicsThreadCreate */ #include /* for DEBUGPRINT */ #include /* for evrMessage* protos */ #define PNET_IRQ_LEVEL (1) /* PNET interrupt level */ #define PNET_IRQ_VECTOR (0xAA) /* PNET interrupt vector */ #define PNET_DEF_BASE_ADDRESS (0x110) /* PNET default base address */ #define PNET_TIMEOUT (0.05) /* Timeout in sec waiting for 360hz input. */ static int pnetReport(); static int pnetInitialise(); struct drvet drvPnet = { 2, (DRVSUPFUN) pnetReport, /* subroutine defined in this file */ (DRVSUPFUN) pnetInitialise /* subroutine defined in this file */ }; epicsExportAddress(drvet, drvPnet); #ifdef DEBUG_PRINT /* ENUM with values: DP_FATAL, DP_ERROR, DP_WARN, DP_INFO, DP_DEBUG Anything less than or equal to drvPnetFlag gets printed out. Can be set to 0 here and altered via prompt or in st.cmd file */ int drvPnetFlag = 0; #endif int pnetDoFiducial = 1; static int intrEnabled = 0; static int readyForPnet = 1; /* pnetTask ready for new data */ static unsigned long vmePnetAddr = PNET_DEF_BASE_ADDRESS; /* base addr of PNET */ static epicsUInt32 *pLocalBuf = NULL; /* keep pLocalBuf a ptr for devRegAddr */ static epicsEventId pnetTaskEventSem = NULL; /* pnet task semaphore */ /*============================================================================= Name: pnetReport Abs: Driver support registered function for reporting system info =============================================================================*/ static int pnetReport( int interest ) { if (interest > 0) { printf ("PNET Card Address = %8.8x, Vector = %3.3X, Level = %d, %s\n", (unsigned int)pLocalBuf, PNET_IRQ_VECTOR, PNET_IRQ_LEVEL, intrEnabled? "Enabled" : "Disabled"); evrMessageReport(EVR_MESSAGE_PNET, EVR_MESSAGE_PNET_NAME, interest); if (pnetDoFiducial) { evrMessageReport(EVR_MESSAGE_FIDUCIAL, EVR_MESSAGE_FIDUCIAL_NAME, interest); } } return interest; } /*============================================================================= Name: pnetISR Abs: Process interrupts at PNET_IRQ_LEVEL - record start time and wake up pnetTask. Rem: Strategy 1: read the entire buffer in before incrementing the pointer. This way the pointer always points to a complete buffer and so there is no chance of reading a partial buffer. Strategy 2: keep this routine to a minimum, so that CPU not blocked too long processing each interrupt. Some lessons learned about what can't be in an ISR, for the record. - no printfs - no floating point calculations - no calls to epicsTimeGetCurrent (while it's true that an epicsTime- stamp variable only contains longs, there is some sys call deep down that uses f.p. and throws the ISR into this error: rtems-4.6.2(PowerPC/PowerPC 7455/mvme5500) FATAL ERROR: Internal error: No Environment: RTEMS Core Error occurred in a Thread Dispatching DISABLED context (level 1) Error occurred from ISR context (ISR nest level 1) Error 18: INTERNAL_ERROR_CALLED_FROM_WRONG_ENVIRONMENT Stack Trace: 0x000B9D2C--> 0x000B9D2C--> 0x000DE6B8--> 0x001103CC--> 0x01F3798C 0x01F36EEC--> 0x01DA63B8--> 0x01D011A4--> 0x000BF460--> 0x000B8AA0 0x000B8844--> 0x000B8ED8 =============================================================================*/ void pnetISR ( /* if there was more than one PNET board, this would spec which one */ void *arg) { #ifdef __rtems__ unsigned long ii; evrMessage_tu message_u; #endif evrMessageStart(EVR_MESSAGE_PNET); #ifdef __rtems__ for (ii=0; ii