Kazuro Furukawa, KEK, Jan.2009. Developing Device Support EPICS Workshop 2009, RRCAT, India Writing Device Support Kazuro Furukawa for EPICS2009 at RRCAT.

Slides:



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

1 1999/Ph 514: Working With an IOC EPICS Working with an IOC Marty Kraimer APS.
1 1999/Ph 514: Channel Access Concepts EPICS Channel Access Concepts Bob Dalesio LANL.
More on Processes Chapter 3. Process image _the physical representation of a process in the OS _an address space consisting of code, data and stack segments.
C Structures and Memory Allocation There is no class in C, but we may still want non- homogenous structures –So, we use the struct construct struct for.
1 CS345 Operating Systems Φροντιστήριο Άσκησης 1.
Module R2 CS450. Next Week R1 is due next Friday ▫Bring manuals in a binder - make sure to have a cover page with group number, module, and date. You.
CSCC69: Operating Systems
IOC Application Development/Debugging Beijing EPICS Seminar Tuesday, 8/ J.Odagiri.
Chapter 7 Protocol Software On A Conventional Processor.
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.
Threads CNS What is a thread?  an independent unit of execution within a process  a "lightweight process"  an independent unit of execution within.
OS Spring’04 Introduction Operating Systems Spring 2004.
Chapter 13: I/O Systems I/O Hardware Application I/O Interface
Asyn Device/Driver Support
CGI Programming Languages Web Based Software Development July 21, 2005 Song, JaeHa.
CSE 451: Operating Systems Autumn 2013 Module 6 Review of Processes, Kernel Threads, User-Level Threads Ed Lazowska 570 Allen.
dcDB Stored Procedures: An Overview
1 Lecture 4: Threads Operating System Fall Contents Overview: Processes & Threads Benefits of Threads Thread State and Operations User Thread.
Real-time Systems Lab, Computer Science and Engineering, ASU Linux Input Systems (ESP – Fall 2014) Computer Science & Engineering Department Arizona State.
CSC 322 Operating Systems Concepts Lecture - 25: by Ahmed Mumtaz Mustehsan Special Thanks To: Tanenbaum, Modern Operating Systems 3 e, (c) 2008 Prentice-Hall,
Hardware Definitions –Port: Point of connection –Bus: Interface Daisy Chain (A=>B=>…=>X) Shared Direct Device Access –Controller: Device Electronics –Registers:
Contact Information Office: 225 Neville Hall Office Hours: Monday and Wednesday 12:00-1:00 and by appointment.
Recall: Three I/O Methods Synchronous: Wait for I/O operation to complete. Asynchronous: Post I/O request and switch to other work. DMA (Direct Memory.
ICS – Software Engineering Group 1 GeneralTime Proposal Status at SNS and Ideas for EPICS base David Thompson Sheng Peng Kay-Uwe Kasemir.
1 1999/Ph 514: Record Support EPICS Record Support Marty Kraimer APS.
Silberschatz, Galvin and Gagne  Operating System Concepts Chapter 3: Operating-System Structures System Components Operating System Services.
UNIX Commands. Why UNIX Commands Are Noninteractive Command may take input from the output of another command (filters). May be scheduled to run at specific.
Lecture 3 Process Concepts. What is a Process? A process is the dynamic execution context of an executing program. Several processes may run concurrently,
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
CE Operating Systems Lecture 3 Overview of OS functions and structure.
NT Kernel CS Spring Overview Interrupts and Exceptions: Trap Handler Interrupt Request Levels and IRT DPC’s, and APC’s System Service Dispatching.
1 EPICS Bus Errors & Power PC u VME Bus Error can generate a Machine Check Exception (MCE) u The WRS mv2700 BSP doesn’t have code to do this u Write cycles.
IOC Application Development/Debugging Shanghai EPICS Seminar Tuesday, 8/29 J.Odagiri.
Processes CS 6560: Operating Systems Design. 2 Von Neuman Model Both text (program) and data reside in memory Execution cycle Fetch instruction Decode.
1 1999/Ph 514: Flow of Control EPICS Flow of Control Marty Kraimer APS.
How to write a MSGQ Transport (MQT) Overview Nov 29, 2005 Todd Mullanix.
© Janice Regan, CMPT 300, May CMPT 300 Introduction to Operating Systems Operating Systems Processes and Threads.
Copyright 2003 Scott/Jones Publishing Standard Version of Starting Out with C++, 4th Brief Edition Chapter 6 Functions.
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)
Processes. Process Concept Process Scheduling Operations on Processes Interprocess Communication Communication in Client-Server Systems.
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)
What is a Process ? A program in execution.
1 EPICS Flow of Control: EPICS Workshop at IHEP, Beijing, August 2001 EPICS Flow of Control Marty Kraimer APS.
Control System Overview J. Frederick Bartlett Fermilab June 1,1999.
Writing Device Support Eric Norum November 16, 2004 Getting Started with EPICS Lecture Series.
Embedded Real-Time Systems Processing interrupts Lecturer Department University.
Case Study: Pthread Synchronization Dr. Yingwu Zhu.
Introduction to Operating Systems Concepts
Module 12: I/O Systems I/O hardware Application I/O Interface
User-Written Functions
Chapter 3: Process Concept
Chapter 7 Text Input/Output Objectives
CS 6560: Operating Systems Design
Chapter 7 Text Input/Output Objectives
I/O in C Lecture 6 Winter Quarter Engineering H192 Winter 2005
CS703 - Advanced Operating Systems
CSE 451: Operating Systems Spring 2012 Module 6 Review of Processes, Kernel Threads, User-Level Threads Ed Lazowska 570 Allen.
Introduction to Classes and Objects
Threads Chapter 4.
Operating Systems Lecture 3.
EPICS Record/Device/Driver Support Interfaces
Channel Access Concepts
Channel Access Concepts
Chapter 3: Process Management
Presentation transcript:

Kazuro Furukawa, KEK, Jan Developing Device Support EPICS Workshop 2009, RRCAT, India Writing Device Support Kazuro Furukawa for EPICS2009 at RRCAT January 30, 2009 Based on presentations by Eric Norum, 2004 Ralph Lange, 2006

Kazuro Furukawa, KEK, Jan Developing Device Support EPICS Workshop 2009, RRCAT, India Writing Device Support – Scope An overview of the concepts associated with writing EPICS Device Support routines. Examples show the stone knives and bearskins approach. The ASYN package provides a framework which makes writing device support much easier. The concepts presented here still apply.

Kazuro Furukawa, KEK, Jan Developing Device Support EPICS Workshop 2009, RRCAT, India Writing Device Support – Outline What is Device Support? The.dbd file entry The driver DSET Device addresses Support routines Using interrupts Asynchronous input/output Callbacks

Kazuro Furukawa, KEK, Jan Developing Device Support EPICS Workshop 2009, RRCAT, India What is Device Support? Interface between record and hardware A set of routines for record support to call The record type determines the required set of routines These routines have full read/write access to any record field Determines synchronous/asynchronous nature of record Performs record I/O Provides interrupt handling mechanism

Kazuro Furukawa, KEK, Jan Developing Device Support EPICS Workshop 2009, RRCAT, India Why use Device Support? Could instead make a different record type for each hardware interface, with fields to allow full control over the provided facilities. A separate device support level provides several advantages: Users need not learn a new record type for each type of device Increases modularity I/O hardware changes are less disruptive Device support is simpler than record support Hardware interface code is isolated from record API Custom records are available if really needed. By which I mean really, really, really needed! Existing record types are sufficient for most applications.

Kazuro Furukawa, KEK, Jan Developing Device Support EPICS Workshop 2009, RRCAT, India How Does a Record Find Its Device Support? Through.dbd device statements:

Kazuro Furukawa, KEK, Jan Developing Device Support EPICS Workshop 2009, RRCAT, India The.dbd File Entry The IOC discovers device support from entries in.dbd files device(recType,addrType,dsetName, dtypeName ) addrType is one of AB_IOBITBUS_IOCAMAC_IOGPIB_IO INST_IORF_IOVME_IOVXI_IO dsetName is the name of the C Device Support Entry Table (DSET) By convention name indicates record and hardware type: device(ai, GPIB_IO, devAidg535, "dg535") device(bi, VME_IO, devBiXy240, "XYCOM-240")

Kazuro Furukawa, KEK, Jan Developing Device Support EPICS Workshop 2009, RRCAT, India The DSET A C structure containing pointers to functions Content dependent upon record type Each device support layer defines a DSET with pointers to its own functions A DSET structure declaration looks like: struct dset { long number; long (*report)(int level); long (*initialize)(int pass); long (*initRecord)(struct … *precord); long (*getIoIntInfo)( … ); … read/write and other routines as required }; number specifies number of pointers (often 5 or 6) A NULL is given when an optional routine is not implemented DSET structures and functions are usually declared static

Kazuro Furukawa, KEK, Jan Developing Device Support EPICS Workshop 2009, RRCAT, India The DSET – initialize long initialize(int pass); Initializes the device support layer Optional routine, not always needed Used for one-time startup operations: Start background tasks Create shared tables Called twice by iocInit() pass=0 – Before any record initialization Doesnt usually access hardware since device address information is not yet known pass=1 – After all record initialization Can be used as a final startup step. All device address information is now known

Kazuro Furukawa, KEK, Jan Developing Device Support EPICS Workshop 2009, RRCAT, India The DSET – initRecord long initRecord(struct … *precord); Called by iocInit() once for each record with matching DTYP Optional routine, but usually supplied Routines often Validate the INP or OUTP field Verify that addressed hardware is present Allocate device-specific storage for the record Each record contains a void *dpvt pointer for this purpose Program device registers Set record-specific fields needed for conversion to/from engineering units

Kazuro Furukawa, KEK, Jan Developing Device Support EPICS Workshop 2009, RRCAT, India The DSET – initRecord – Device Addresses Device support.dbd entry was device(recType,addrType,dset,"name") addrType specifies the type to use for the address link, e.g. device(bo,VME_IO,devBoXy240,"Xycom XY240") sets pbo->out : pbo->out.type = VME_IO Device support uses pbo->out.value.vmeio which is a struct vmeio { short card; short signal; char *parm; }; IOC Application Developers Guide describes all types

Kazuro Furukawa, KEK, Jan Developing Device Support EPICS Workshop 2009, RRCAT, India The DSET – report long report(int level); Called by dbior shell command Prints information about current state, hardware status, I/O statistics, etc. Amount of output is controlled by the level argument level=0 – list hardware connected, one device per line level>0 – provide different type or more detailed information

Kazuro Furukawa, KEK, Jan Developing Device Support EPICS Workshop 2009, RRCAT, India The DSET – read/write long read(struct … *precord); long write(struct … *precord); Called when record is processed Perform (or initiate) the I/O operation: Synchronous input Copy value from hardware into precord->rval Return 0 (to indicate success) Synchronous output Copy value from precord->rval to hardware Return 0 (to indicate success)

Kazuro Furukawa, KEK, Jan Developing Device Support EPICS Workshop 2009, RRCAT, India A Simple Example (VME / vxWorks or RTEMS) #include static long initRecord(struct biRecord *prec){ char *pbyte, dummy; if ((prec->inp.type != VME_IO) || (prec->inp.value.vmeio.signal inp.value.vmeio.signal > 7)) { recGblRecordError(S_dev_badInpType, (void *)prec, "devBiFirst: Bad INP"); return -1; } if (devRegisterAddress("devBiFirst", atVMEA16, prec->inp.value.vmeio.card, 0x1, &pbyte) != 0) { recGblRecordError(S_dev_badCard, (void *)prec, "devBiFirst: Bad VME address"); return -1; } if (devReadProbe(1, pbyte, &dummy) < 0) { recGblRecordError(S_dev_badCard, (void *)prec, "devBiFirst: Nothing there!"); return -1; } prec->dpvt = pbyte; prec->mask = 1 inp.value.vmeio.signal; return 0; }

Kazuro Furukawa, KEK, Jan Developing Device Support EPICS Workshop 2009, RRCAT, India A Simple Example (VME / vxWorks or RTEMS) static long read(struct biRecord *prec) { volatile char *pbyte = (volatile char *)prec->dpvt; prec->rval = *pbyte; return 0; } static struct { long number; long (*report)(int); long (*initialize)(int); long (*initRecord)(struct biRecord *); long (*getIoIntInfo)(); long (*read)(struct biRecord *); } devBiFirst = { 5, NULL, NULL, initRecord, NULL, read }; epicsExportAddress(dset,devBiFirst);

Kazuro Furukawa, KEK, Jan Developing Device Support EPICS Workshop 2009, RRCAT, India A Simple Example – Device Support.dbd File The.dbd file for the device support routines shown on the preceding pages might be device(bi, VME_IO, devBiFirst, simpleInput )

Kazuro Furukawa, KEK, Jan Developing Device Support EPICS Workshop 2009, RRCAT, India A Simple Example – Application.db File An application.db file using the device support routines shown on the preceding pages might contain record(bi, "$(P):statusBit") { field(DESC, "Simple example binary input") field(DTYP, "simpleInput") field(INP, "#C$(C) S$(S)") }

Kazuro Furukawa, KEK, Jan Developing Device Support EPICS Workshop 2009, RRCAT, India A Simple Example – Application Startup Script An application startup script (st.cmd) using the device support routines shown on the preceding pages might contain dbLoadRecords("db/example.db","P=test,C=0x1E0,S=0") which would expand the.db file into record(bi, "test:statusBit") { field(DESC, "Simple example binary input") field(DTYP, "simpleInput") field(INP, "#C0x1E0 S0") }

Kazuro Furukawa, KEK, Jan Developing Device Support EPICS Workshop 2009, RRCAT, India Useful Facilities ANSI C routines (EPICS headers fill in vendor holes) epicsStdio.h – printf, sscanf, epicsSnprintf epicsString.h – strcpy, memcpy, epicsStrDup epicsStdlib.h – getenv, abs, epicsScanDouble OS-independent hardware access (devLib.h) Bus address Local address conversion Interrupt control Bus probing EPICS routines epicsEvent.h – process synchronization semaphore epicsMutex.h – mutual-exclusion semaphore epicsThread.h – multithreading support recGbl.h – record error and alarm reporting

Kazuro Furukawa, KEK, Jan Developing Device Support EPICS Workshop 2009, RRCAT, India Device Interrupts vxWorks/RTEMS interrupt handlers can be written in C VME interrupts have two parameters Interrupt level (1-7, but dont use level 7) – often set with on-board jumpers or DIP switches Interrupt vector (0-255, <64 reserved on MC680x0) – often set by writing to an on-board register OS initialization takes two calls 1.Connect interrupt handler to vector devConnectInterruptVME(unsigned vectorNumber, void (*pFunction)(void *),void *parameter); 2.Enable interrupt from VME to CPU devEnableInterruptLevelVME (unsigned level);

Kazuro Furukawa, KEK, Jan Developing Device Support EPICS Workshop 2009, RRCAT, India I/O Interrupt Record Processing Record is processed when hardware interrupt occurs Granularity depends on device support and hardware Interrupt per-channel vs. interrupt per-card #include to get additional declarations Call scanIoInit once for each interrupt source to initialize a local value: scanIoInit(&ioscanpvt); DSET must provide a getIoIntInfo routine to specify the interrupt source associated with a record – a single interrupt source can be associated with more than one record Interrupt handler calls scanIoRequest with the ioscanpvt value for that source – this is one of the very few routines which may be called from an interrupt handler

Kazuro Furukawa, KEK, Jan Developing Device Support EPICS Workshop 2009, RRCAT, India The DSET – getIoIntInfo long getIoIntInfo(int cmd, struct … *precord, IOSCANPVT *ppvt); Set *ppvt to the value of the IOSCANPVT variable for the interrupt source to be associated with this record Must have already called scanIoInit to initialize the IOSCANPVT variable Return 0 to indicate success or non-zero to indicate failure – in which case the record SCAN field will be set to Passive Routine is called with ( cmd=0 ) when record is set to SCAN=I/O Intr ( cmd=1 ) when record SCAN field is set to any other value

Kazuro Furukawa, KEK, Jan Developing Device Support EPICS Workshop 2009, RRCAT, India The DSET – specialLinconv long specialLinconv(struct … *precord, int after); Analog input (ai) and output (ao) record DSETs include this sixth routine Called just before ( after=0 ) and just after ( after=1 ) the value of the LINR, EGUL or EGUF fields changes Before usually does nothing After recalculates ESLO from EGUL / EGUF and the hardware range If record LINR field is Linear ai record processing will compute val as val = ((rval + roff) * aslo + aoff) * eslo + eoff Ao record processing is similar, but in reverse

Kazuro Furukawa, KEK, Jan Developing Device Support EPICS Workshop 2009, RRCAT, India Asynchronous I/O Device support must not wait for slow I/O Hardware read/write operations which take a long time to complete must use asynchronous record processing T I/O 100 s – definitely a long time T I/O 10 s– definitely not a long time 10 s < T I/O < 100 s– ??? If device does not provide a completion interrupt a worker thread can be created to perform the I/O this technique is used for Ethernet-attached devices

Kazuro Furukawa, KEK, Jan Developing Device Support EPICS Workshop 2009, RRCAT, India Asynchronous I/O – Read/Write Operation Check value of precord->pact and if zero: Set precord->pact to 1 Start the I/O operation write hardware or send message to worker thread Return 0 When operation completes run the following code from a thread (i.e. NOT from an interrupt handler) struct rset *prset = (struct rset *)precord->rset; dbScanLock(precord); (*prset->process)(precord); dbScanUnlock(precord); The record s process routine will call the device support read/write routine – with precord->pact=1 -Complete the I/O, set rval, etc.

Kazuro Furukawa, KEK, Jan Developing Device Support EPICS Workshop 2009, RRCAT, India Asynchronous I/O – Callbacks An interrupt handler must not call a records process routine directly Use the callback system ( callback.h ) to do this Declare a callback variable CALLBACK myCallback; Issue the following from the interrupt handler callbackRequestProcessCallback(&myCallBack, priorityLow, precord); This queues a request to a callback handler thread which will perform the lock/process/unlock operations shown on the previous page There are three callback handler threads With priorities Low, Medium and High

Kazuro Furukawa, KEK, Jan Developing Device Support EPICS Workshop 2009, RRCAT, India Asynchronous I/O – ASYN This should be your first consideration for new device support It provides a powerful, flexible framework for writing device support for Message-based asynchronous devices Register-based synchronous devices Will be completely described in a subsequent lecture ASYN will be covered in the next session. You will find the package and documentation on the EPICS web site. Caveat – there is a learning curve for ASYN … my rule of thumb: ASYN makes it easy to do the hard stuff, but hard to do the easy stuff.

Kazuro Furukawa, KEK, Jan Developing Device Support EPICS Workshop 2009, RRCAT, India Hands on # Commands to build a very simple device support # k.furukawa, jan # get rrcat.tar.gz from # # open terminal mkdir second cd second makeBaseApp.pl -t ioc Clock1 makeBaseApp.pl -t ioc -i -p Clock1 Clock1 tar xzf ~/Desktop/rrcat.tar.gz perl -i -pe s/CLOCK/{your-username}/ Clock1App/Db/aiSecond.db # example: perl -i -pe s/CLOCK/user7/ Clock1App/Db/aiSecond.db make clean install 2>&1 | tee make.log # (if your shell is csh : make clean install |& tee make.log) cd iocBoot/iocClock1 chmod +x st.cmd./st.cmd # from another terminal camonitor {your-username}:SEC1 {your-username}:SEC10 # example: camonitor user7:SEC1 user7:SEC10 # Please look in the files Clock1App/src/devAiSecond.c Clock1App/src/aiSecond.dbd Clock1App/Db/aiSecond.db

Kazuro Furukawa, KEK, Jan Developing Device Support EPICS Workshop 2009, RRCAT, India Thank you