1 1999/Ph 514: Device and Driver Support EPICS Device and Driver Support Andrew Johnson APS.

Slides:



Advertisements
Similar presentations
1 2009: Device Support EPICS Device Support Andy Foster Observatory Sciences Limited.
Advertisements

Kazuro Furukawa, KEK, Jan Developing Device Support EPICS Workshop 2009, RRCAT, India Writing Device Support Kazuro Furukawa for EPICS2009 at RRCAT.
CSCC69: Operating Systems
6-1 I/O Methods I/O – Transfer of data between memory of the system and the I/O device Most devices operate asynchronously from the CPU Most methods involve.
Chapter 8 I/O. Copyright © The McGraw-Hill Companies, Inc. Permission required for reproduction or display. 8-2 I/O: Connecting to Outside World So far,
I/O Hardware n Incredible variety of I/O devices n Common concepts: – Port – connection point to the computer – Bus (daisy chain or shared direct access)
OS Spring’03 Introduction Operating Systems Spring 2003.
Midterm Tuesday October 23 Covers Chapters 3 through 6 - Buses, Clocks, Timing, Edge Triggering, Level Triggering - Cache Memory Systems - Internal Memory.
Computer System Structures memory memory controller disk controller disk controller printer controller printer controller tape-drive controller tape-drive.
Mehmet Can Vuran, Instructor University of Nebraska-Lincoln Acknowledgement: Overheads adapted from those provided by the authors of the textbook.
I/O Systems CSCI 444/544 Operating Systems Fall 2008.
Chapter 13: I/O Systems I/O Hardware Application I/O Interface
I/O Tanenbaum, ch. 5 p. 329 – 427 Silberschatz, ch. 13 p
MICROPROCESSOR INPUT/OUTPUT
FINAL MPX DELIVERABLE Due when you schedule your interview and presentation.
Contact Information Office: 225 Neville Hall Office Hours: Monday and Wednesday 12:00-1:00 and by appointment.
1-1 Embedded Network Interface (ENI) API Concepts Shared RAM vs. FIFO modes ENI API’s.
Chapter 8 I/O. Copyright © The McGraw-Hill Companies, Inc. Permission required for reproduction or display. 8-2 I/O: Connecting to Outside World So far,
1 1999/Ph 514: Record Support EPICS Record Support Marty Kraimer APS.
Tami Meredith, Ph.D. CSCI  Devices need CPU access  E.g., NIC has a full buffer it needs to empty  These device needs are often asynchronous.
Operating Systems Lecture 7 OS Potpourri Adapted from Operating Systems Lecture Notes, Copyright 1997 Martin C. Rinard. Zhiqing Liu School of Software.
A U.S. Department of Energy Office of Science Laboratory Operated by The University of Chicago Argonne National Laboratory Office of Science U.S. Department.
EPICS record/device/driver Support many slides copied from
Device Drivers CPU I/O Interface Device Driver DEVICECONTROL OPERATIONSDATA TRANSFER OPERATIONS Disk Seek to Sector, Track, Cyl. Seek Home Position.
NT Kernel CS Spring Overview Interrupts and Exceptions: Trap Handler Interrupt Request Levels and IRT DPC’s, and APC’s System Service Dispatching.
13-Nov-15 (1) CSC Computer Organization Lecture 7: Input/Output Organization.
Fast Fault Finder A Machine Protection Component.
CE Operating Systems Lecture 2 Low level hardware support for operating systems.
Operating Systems 1 K. Salah Module 1.2: Fundamental Concepts Interrupts System Calls.
1 1999/Ph 514: Flow of Control EPICS Flow of Control Marty Kraimer APS.
1 VxWorks 5.4 Group A3: Wafa’ Jaffal Kathryn Bean.
Silberschatz, Galvin and Gagne  Applied Operating System Concepts Chapter 2: Computer-System Structures Computer System Architecture and Operation.
How to write a MSGQ Transport (MQT) Overview Nov 29, 2005 Todd Mullanix.
CE Operating Systems Lecture 2 Low level hardware support for operating systems.
New IP Drivers using drvIpac Module Driver:CANopen Carrier Driver:GPFC drvIpac ?? CANopen Tip810 CAN Tip810 mv162GPFCatc40vipc310vipc616 Module driver.
4P13 Week 12 Talking Points Device Drivers 1.Auto-configuration and initialization routines 2.Routines for servicing I/O requests (the top half)
Input/Output Problems Wide variety of peripherals —Delivering different amounts of data —At different speeds —In different formats All slower than CPU.
Input Output Techniques Programmed Interrupt driven Direct Memory Access (DMA)
1 1999/Ph 514: Supported Hardware EPICS Supported Hardware Ned D. Arnold APS.
1 Channel Access Concepts – IHEP EPICS Training – K.F – Aug EPICS Channel Access Concepts Kazuro Furukawa, KEK (Bob Dalesio, LANL)
1 EPICS Flow of Control: EPICS Workshop at IHEP, Beijing, August 2001 EPICS Flow of Control Marty Kraimer APS.
I/O Software CS 537 – Introduction to Operating Systems.
Writing Device Support Eric Norum November 16, 2004 Getting Started with EPICS Lecture Series.
Interrupts and Exception Handling. Execution We are quite aware of the Fetch, Execute process of the control unit of the CPU –Fetch and instruction as.
Embedded Real-Time Systems Processing interrupts Lecturer Department University.
Real Numbers Device driver process within the operating system that interacts with I/O controller logical record 1 logical record 2 logical record 3.
Lecture 8 Task Utilization. Theoretical Analysis.
1 2003/P571: Device and Driver Support EPICS Device and Driver Support (needs updating to R3.14.1) Andrew Johnson APS.
Chapter 8 I/O.
User-Written Functions
Interrupts and signals
Microprocessor Systems Design I
Topics Covered What is Real Time Operating System (RTOS)
CS 3305 System Calls Lecture 7.
Chapter 8 I/O.
Module 2: Computer-System Structures
Operating Systems Chapter 5: Input/Output Management
Chapter 8 I/O.
File Input and Output.
Operating Systems Lecture 3.
CSE 451: Operating Systems Autumn 2003 Lecture 2 Architectural Support for Operating Systems Hank Levy 596 Allen Center 1.
EPICS Record/Device/Driver Support Interfaces
CSE 451: Operating Systems Autumn 2001 Lecture 2 Architectural Support for Operating Systems Brian Bershad 310 Sieg Hall 1.
Chapter 8 I/O.
CSE 451: Operating Systems Winter 2003 Lecture 2 Architectural Support for Operating Systems Hank Levy 412 Sieg Hall 1.
Intertask Communication
Chapter 13: I/O Systems.
Lecture 12 Input/Output (programmer view)
Presentation transcript:

1 1999/Ph 514: Device and Driver Support EPICS Device and Driver Support Andrew Johnson APS

2 1999/Ph 514: Device and Driver Support EPICS Outline u What is device support? u The.dbd file entry u The DSET u Device addresses u Facilities available from u vxWorks u EPICS u Using Interrupts u Asynchronous I/O u Callbacks and Watchdogs u Driver Support u The DrvET

3 1999/Ph 514: Device and Driver Support EPICS What is device support u Interface between record and hardware u Provides an API for record support to call u Record type determines routines needed u Intimate knowledge of the record type u Full read/write access to any record field u Performs record I/O on request u Determines whether a record is to be synchronous or asynchronous u Provides I/O Interrupt support u Determines whether I/O Interrupt allowed

4 1999/Ph 514: Device and Driver Support EPICS Why use it u Why not make record types for each hardware interface, with fields to allow full control over the facilities it provides? u Users don't have to learn about a new record type for each I/O board they want to use u Changing the I/O hardware is much easier u Record types provided are sufficient for most hardware interfacing tasks u It is still possible to create new record types for special purposes if necessary u Device support is simpler than record support u Device support isolates the hardware interface code from changes to the record API u Bug-fixes or enhancements to record support only need to happen in one place u Modularity (good software engineering practice)

5 1999/Ph 514: Device and Driver Support EPICS The.dbd file entry u The IOC discovers what device supports are present from entries in the.dbd file device(recType,addrType,dset,"name") u addrType is one of AB_IOBITBUS_IOBBGPIB_IO CAMAC_IOGPIB_IOINST_IO RF_IOVME_IOVXI_IO u dset is the ‘C’ symbol name for the Device Support Entry Table (DSET) u By convention the dset name indicates the record type and hardware interface u This is how record support and the database code call device support routines u For example device(ai,INST_IO,devAiSymb,"vxWorks var") device(bo,VME_IO,devBoXy240,"Xycom XY240")

6 1999/Ph 514: Device and Driver Support EPICS The DSET  … is a ‘C’ struct containing function pointers, the content of which can vary by record type u Each device support layer defines a named DSET with pointers to its own routines u All DSET structure declarations start struct dset { long number; long (*report)(int type); long (*initialize)(int pass); long (*initRecord)(struct … *precord); long (*getIoIntInfo)(…) … read/write and other routines as required }; u number gives the number of function pointers in the DSET, usually 5 or 6 for standard types u A NULL pointer is given when an optional routine is not implemented  DSET routines are usually declared static (local) as their symbol names are not needed at runtime

7 1999/Ph 514: Device and Driver Support EPICS DSET: initialize long initialize(int pass); u Initializes the device support layer u Optional routine, not always needed u Used for one-time startup operations, e.g. u Start background tasks u Create shared tables u Routine called twice by iocInit:  pass=0 — Before record initialization u Doesn’t usually access hardware as it doesn’t know what I/O is to be used by this database  pass=1 — After all record initialization u Can be used as a final startup step, all devices addressed by database are known by this point

8 1999/Ph 514: Device and Driver Support EPICS DSET: initRecord long initRecord(struct … *precord); u Called at iocInit once for each record, to tell device support about the record u Optional routine, but usually supplied u Device support code should u Check the INP or OUT field address u Check if addressed hardware is present u Allocate any private storage required  Every record type has a void *dpvt field for device support to use as it wishes u Program device registers etc. as needed u Set some record-specific fields needed for I/O conversion to/from engineering units

9 1999/Ph 514: Device and Driver Support EPICS DSET: read/write u Most record types need a DSET routine long read(struct … *precord); or long write(struct … *precord); u This implements the I/O operation which occurs when the record is processed. u Precise action depends on the record type and whether synchronous or async. u Generally, synchronous input support  Reads hardware value into precord->rval u Returns 0 (meaning OK) u and synchronous output support  Copies value in precord->rval to hardware u Returns 0 (OK again) u Except in practice there’s usually a bit more than this to do…

/Ph 514: Device and Driver Support EPICS Device addresses u Device support.dbd entry was device(recType,addrType,dset,"name") u addrType tells database software what type to use for the address link, e.g. device(bo,VME_IO,devBoXy240,"Xycom XY240") applies to the pbo->out field: u pbo->out.type = VME_IO  Device support uses pbo->out.value.vmeio which is a struct vmeio { short card; short signal; char *parm; };  See /include/link.h for other structs, and my Database lecture or IOC Application Developers Guide for the format of addresses.

/Ph 514: Device and Driver Support EPICS A first example … #include long initRecord(struct biRecord *prec){ char *pbyte, dummy; prec->pact = 1; if ((prec->inp.type != VME_IO) || (prec->inp.value.vmeio.signal < 0) || (prec->inp.value.vmeio.signal > 7)) { recGblRecordError(S_dev_badInpType, (void *)prec, "devBiFirst: Bad INP address"); return S_dev_badInpType; } if (sysBusToLocalAdrs(VME_AM_SUP_SHORT_IO, (char *)prec->inp.value.vmeio.card, &pbyte) == ERROR) { recGblRecordError(S_dev_badCard, (void *)prec, "devBiFirst: Can't convert VME address"); return S_dev_badCard; } if (vxMemProbe(pbyte,READ,1,&dummy) < 0) { recGblRecordError(S_dev_badCard, (void *)prec, "devBiFirst: Nothing there!"); return S_dev_badCard; } prec->dpvt = pbyte; prec->mask = 1 inp.value.vmeio.signal; prec->pact = 0; return OK; }

/Ph 514: Device and Driver Support EPICS … continued long read(struct biRecord *prec){ char *pbyte = (char *)prec->dpvt; prec->rval = *pbyte; return OK; } struct { long number; long (*report)(int); long (*initialize)(int); long (*initRecord)(struct biRecord *); long (*getIoIntInfo)(int, struct biRecord *, IOSCANPVT *) long (*read)(struct biRecord *); } = { 5, NULL, NULL, initRecord, NULL, read };

/Ph 514: Device and Driver Support EPICS vxWorks Facilities u vxWorks Operating System provides u ANSI C libraries u stdio.h — fopen, printf, sscanf, etc. u string.h — memcpy, strcat, strcmp etc. u math.h — sin, log, fabs etc. u stdlib.h — strtol, calloc, cfree etc. u Board Support Package: sysLib u Bus address  Local address conversions u Bus interrupt control (enable, disable) u Other useful libraries v wdLib — watchdog timers v intLib, intArchLib — interrupt connection u taskLib — creating and controlling tasks u semLib, semBLib, senCLib, semMLib — binary, counting and mutual exclusion semaphores u rngLib — ring buffer handling u msgQLib — inter-task message queues u logLib — error messages from ISR  Use man intLib to see the list of routines or man memcpy for individual details

/Ph 514: Device and Driver Support EPICS EPICS facilities u EPICS core software provides u recGbl.h — error and alarm reporting for records v callback.h — task level callbacks u taskwd.h — callback if background task dies u devLib.h — OS-neutral h/w interface library u Good idea but not widely used, API not brilliant u ellLib.h — general-purpose linked-list support u epicsAssert.h — preferred to ANSI assert.h u errlog.h — error message logging (printf etc.) u See IOC Application Developers Guide for descriptions of most routines available

/Ph 514: Device and Driver Support EPICS Using Interrupts u vxWorks ISRs can be written in ‘C’ u On VME two parameters are needed: u Interrupt level — prioritization, 1-7 u Often set with I/O board DIP switches or jumpers u Level 7 is non-maskable and can crash vxWorks u Interrupt vector — unique within this CPU u Vector numbers < 64 are reserved by MC680x0  Use veclist on IOC to see vectors in use u Written to a register on the card u OS Initialization requires two actions: u Connect ISR to relevent interrupt vector intLib.h: long intConnect(VOIDFUNCPTR *ivec, void (*fp)(int param), int param); iv.h: #define INUM_TO_IVEC(num) … u Enable VME interrupt level onto CPU board sysLib.h: long sysIntEnable(int level); NB not intEnable

/Ph 514: Device and Driver Support EPICS Interrupt Scanning u Records are processed when hardware signal occurs (e.g. input bit changed) u Granularity depends on hardware and device support software u Interrupt per signal … Interrupt per card u Can be simulated using a background task  #include  Call scanIoInit once for each interrupt ‘source’ to initialize a pointer void scanIoInit(IOSCANPVT *ppvt); u The same interrupt ‘source’ can be used for any number of records and record types  DSET must have a getIoIntInfo routine which indicates which ‘source’ to use  When interrupt occurs, call scanIoRequest passing back the pointer for this source void scanIoRequest(IOSCANPVT pvt);

/Ph 514: Device and Driver Support EPICS DSET: getIoIntInfo long (*getIoIntInfo)(int cmd, struct … *precord, IOSCANPVT *ppvt);  Device support copies the IOSCANPVT value for this record into *ppvt  You may call scanIoInit from here if you haven’t done so yet for this interrupt source  Return 0 if Ok, else non-zero when scan will be reset to Passive  Can usually ignore the cmd value  Whenever a record is set to scan=I/O Intr the routine is called with cmd=0  If scan field is later to be changed to something else, routine will be called again with cmd=1

/Ph 514: Device and Driver Support EPICS DSET: report long report(int type);  Optional, called by dbior shell command u Omitted if device support calls driver support, as this will give the I/O status u Should print out information about current state, hardware connected etc.  If type=0, just give a list of the hardware connected one card per line  Higher values of type provide increasing amounts of data, or different pages u Additional Suggestions: u Collect I/O statistics (count successful reads, write, interrupts, errors etc.) and use one page to display this data u Have a page to list the card’s registers, which will help you to debug your device support

/Ph 514: Device and Driver Support EPICS Other routines u Analogue Input and Output record DSETs include a sixth DSET routine: long specialLinconv(struct … *precord, int after);  Called just before ( after=0 ) and just after ( after=1 ) the database changes the value of the linr, egul or eguf fields of the record u “Before” usually does nothing. u “After” call must recalculate eslo from egul, eguf and the ADC/DAC range  If linr=Linear, ai will convert rval using val=((rval+roff)*aslo+aoff)*eslo+eoff u The ao conversion is similar but in reverse

/Ph 514: Device and Driver Support EPICS Asynchronous I/O u Device support must not wait for slow I/O u If hardware read/ write operations take “a long time,” use asynchronous record processing u If the device doesn’t provide a suitable completion interrupt, a background task can poll it periodically u An asynchronous read/write routine  Looks at precord->pact, and if false (idle) it: u Starts the I/O operation  Sets precord->pact true, then returns 0 u When the operation completes, device support must run the following code at task level, not in the ISR: struct rset *prset = (struct rset *)precord->rset; dbScanLock((dbCommon *) precord); (*prset->process)(precord); dbScanUnlock((dbCommon *) precord);  The record’s process routine will call the device support read/write routine again. Now pact is true  Completes the I/O, sets the rval field etc. u Returns 0

/Ph 514: Device and Driver Support EPICS Using Callbacks u An ISR cannot call the record’s process routine directly u Very few operations are allowed inside an ISR u Use the callback system to do this u It has ring buffers to queue callback requests, which can be made from interrupt level u One of three (prioritized) callback tasks executes the registered callback function  Header file callback.h contains typedef struct … CALLBACK; These are defined as macros: callbackSetCallback(void (*pfunc)(CALLBACK *cb), CALLBACK *cb); callbackSetPriority(int prio, CALLBACK *cb); callbackSetUser(void *user, CALLBACK *cb); callbackGetUser(void *user, CALLBACK *cb); This is a procedure: void callbackRequest(CALLBACK *cb);

/Ph 514: Device and Driver Support EPICS Watchdog Timers u A common requirement is for a timeout if the interrupt might never occur u Use vxWorks watchdog library wdLib u Create watchdog timer, returns a wdId u Start timer giving timeout period, wdId, callback routine, and an integer context value u Cancel timer, else callback executed in an ISR if not cancelled by end of timeout period  Header file wdLib.h defines: typedef … WDOG_ID; WDOG_ID wdCreate (void); long wdStart(WDOG_ID wdId, int delay, void (*pfunc)(int param), int param); long wdCancel(WDOG_ID wdId);

/Ph 514: Device and Driver Support EPICS Asynchronous example /* devAiTestAsyn.c - Device Support to test async processing */ /* * Experimental Physics and Industrial Control System (EPICS) * * Copyright 1991, the Regents of the University of California, * and the University of Chicago Board of Governors. * * This software was produced under U.S. Government contracts: * (W-7405-ENG-36) at the Los Alamos National Laboratory, * and (W ENG-38) at Argonne National Laboratory. */ #include /* Device private information structure */ struct dpvt { CALLBACK callback; /* MUST be first member */ struct dbCommon *precord; WDOG_ID wdId; }; /* Routine executed by callback task (NOT watchdog timer!) */ static void myCallback(CALLBACK *pCallback) { struct dpvt *pdpvt = (struct dpvt *) pCallback; struct rset *prset = (struct rset *) pdpvt->precord->rset; dbScanLock(pdpvt->precord); (*prset->process)(pdpvt->precord); dbScanUnlock(pdpvt->precord); }

/Ph 514: Device and Driver Support EPICS … continued static long initRecord(struct aiRecord *pai) { struct dpvt *pdpvt; if (recGblInitConstantLink(&pai->inp, DBF_DOUBLE, &pai->val)) { pdpvt = (struct dpvt *) calloc(1, sizeof(struct dpvt)); pai->dpvt = (void *) pdpvt; callbackSetCallback(myCallback, &pdpvt->callback); pdpvt->precord = (struct dbCommon *) pai; pdpvt->wdId = wdCreate(); return 0; } pai->pact = TRUE; /* Stop record from processing */ recGblRecordError(S_dev_badInpType, (void *) pai, "devAiTestAsyn (initRecord) Bad INP field"); return S_dev_badInpType; } static long readAi(struct aiRecord *pai) { struct dpvt *pdpvt = (struct dpvt *) pai->dpvt; if (!pai->pact) { if (pai->disv <= 0) return 2; /* don't convert, synchronous */ printf("Starting asynchronous processing: %s\n", pai->name); callbackSetPriority(pai->prio, &pdpvt->callback); wdStart(pdpvt->wdId, pai->disv * vxTicksPerSecond, (FUNCPTR) callbackRequest, (int) pdpvt); pai->pact = TRUE; /* asynchronous... */ return 0; } printf("Completed asynchronous processing: %s\n", pai->name); return 2; /*... don`t convert */ } DSET omitted …

/Ph 514: Device and Driver Support EPICS Driver Support u Optional layer below device support u No formal behavioral requirements u Does not use the open/close/read/write interface, which doesn’t map well into EPICS u Usually used to: u Share code between similar device support layers for different record types u Most digital I/O interfaces support record types bi, bo, mbbi, mbbo, mbbiDirect and mbboDirect u Initialize a software module before individual device layers using it are initialized u The order in which device support initialization is called is not guaranteed u Provide a common interface to an I/O bus such as GPIB, Bitbus, Allen-Bradley etc. u I/O devices placed on this bus need their own device support, but share the interface hardware u Provide a wrapper around commercial device drivers or other software libraries

/Ph 514: Device and Driver Support EPICS The DrvET u … is a struct containing function pointers u Each driver defines a named DrvET with pointers to its own routines u Drivers have an entry in the.dbd file: driver(DrvETname) u All DrvET structure declarations start struct drvet { long number; long (*report)(int type); long (*initialize)(int pass); }; u A driver may extend the DrvET, adding routines for device support to call u In practice very few do this, usually providing named library routines to call instead