Files
epics-base/src/rec/recTimer.c
Janet B. Anderson ba8266f850 jba 1/10/91
1991-01-11 15:19:35 +00:00

341 lines
9.5 KiB
C
Raw Blame History

This file contains invisible Unicode characters
This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
/* recTimer.c */
/* share/src/rec $Id$ */
/* recTimer.c - Record Support Routines for Timer records
*
* Author: Bob Dalesio
* Date: 1-9-89
*
* Control System Software for the GTA Project
*
* Copyright 1988, 1989, the Regents of the University of California.
*
* This software was produced under a U.S. Government contract
* (W-7405-ENG-36) at the Los Alamos National Laboratory, which is
* operated by the University of California for the U.S. Department
* of Energy.
*
* Developed by the Controls and Automation Group (AT-8)
* Accelerator Technology Division
* Los Alamos National Laboratory
*
* Direct inqueries to:
* Bob Dalesio, AT-8, Mail Stop H820
* Los Alamos National Laboratory
* Los Alamos, New Mexico 87545
* Phone: (505) 667-3414
* E-mail: dalesio@luke.lanl.gov
*
* Modification Log:
* -----------------
* .01 01-20-89 lrd fix vx includes
* .02 02-06-89 lrd add event post capability
* .03 03-29-89 lrd make hardware errors MAJOR
* remove hw severity spec from database
* .04 04-07-89 lrd service monitors
* .05 05-03-89 lrd removed process mask from arg list
* .06 05-03-89 lrd modified to read the timing on startup
* .07 05-03-89 lrd read trigger delay from trigger origin record
* .08 07-03-89 lrd add processing a forward link
* .09 08-15-89 lrd add post events for timing pulse 1 fields
* .10 10-15-90 mrk extensible record and device support
*/
#include <vxWorks.h>
#include <types.h>
#include <stdioLib.h>
#include <lstLib.h>
#include <alarm.h>
#include <dbAccess.h>
#include <dbDefs.h>
#include <dbFldTypes.h>
#include <devSup.h>
#include <errMdef.h>
#include <link.h>
#include <recSup.h>
#include <timerRecord.h>
/* Create RSET - Record Support Entry Table*/
#define report NULL
#define initialize NULL
long init_record();
long process();
#define special NULL
#define get_precision NULL
long get_value();
#define cvt_dbaddr NULL
#define get_array_info NULL
#define put_array_info NULL
#define get_enum_str NULL
#define get_units NULL
#define get_graphic_double NULL
#define get_control_double NULL
#define get_enum_strs NULL
struct rset timerRSET={
RSETNUMBER,
report,
initialize,
init_record,
process,
special,
get_precision,
get_value,
cvt_dbaddr,
get_array_info,
put_array_info,
get_enum_str,
get_units,
get_graphic_double,
get_control_double,
get_enum_strs };
/* because the driver does all the work just declare device support here*/
struct dset devTmMizar8310={4,NULL,NULL,NULL,NULL};
struct dset devTmDg535={4,NULL,NULL,NULL,NULL};
struct dset devTmVxiAt5={4,NULL,NULL,NULL,NULL};
extern int post_event();
void monitor();
void read_timer();
void convert_timer();
void write_timer();
static long init_record(ptimer)
struct timerRecord *ptimer;
{
/* read to maintain time pulses over a restart */
read_timer(ptimer);
return(0);
}
static long get_value(ptimer,pvdes)
struct timerRecord *ptimer;
struct valueDes *pvdes;
{
pvdes->field_type = DBF_SHORT;
pvdes->no_elements=1;
(short *)(pvdes->pvalue) = &ptimer->val;
return(0);
}
static long process(paddr)
struct dbAddr *paddr;
{
struct timerRecord *ptimer=(struct timerRecord *)(paddr->precord);
ptimer->pact=TRUE;
/* write the new value */
write_timer(ptimer);
/* check event list */
monitor(ptimer);
/* process the forward scan link record */
if (ptimer->flnk.type==DB_LINK) dbScanPassive(ptimer->flnk.value.db_link.pdbAddr);
ptimer->pact=FALSE;
return(0);
}
static void monitor(ptimer)
struct timerRecord *ptimer;
{
unsigned short monitor_mask;
short stat,sevr,nsta,nsev;
/* get previous stat and sevr and new stat and sevr*/
stat=ptimer->stat;
sevr=ptimer->sevr;
nsta=ptimer->nsta;
nsev=ptimer->nsev;
/*set current stat and sevr*/
ptimer->stat = nsta;
ptimer->sevr = nsev;
ptimer->nsta = 0;
ptimer->nsev = 0;
/* anyone waiting for an event on this record */
if (ptimer->mlis.count == 0) return;
/* Flags which events to fire on the value field */
monitor_mask = 0;
/* alarm condition changed this scan */
if (stat!=nsta || sevr!=nsev){
/* post events for alarm condition change*/
monitor_mask = DBE_ALARM;
/* post stat and sevr fields */
db_post_events(ptimer,&ptimer->stat,DBE_VALUE);
db_post_events(ptimer,&ptimer->sevr,DBE_VALUE);
}
monitor_mask |= (DBE_VALUE | DBE_LOG);
db_post_events(ptimer,&ptimer->val,monitor_mask);
db_post_events(ptimer,&ptimer->t1wd,monitor_mask);
db_post_events(ptimer,&ptimer->t1ld,monitor_mask);
db_post_events(ptimer,&ptimer->t1td,monitor_mask);
return;
}
/*
* These constants are indexed by the time units field in the timer record.
* Values are converted to seconds.
*/
static double constants[] = {1000,1000000,1000000000,1000000000000};
/*
* CONVERT_TIMER
*
*/
static void convert_timer(ptimer)
struct timerRecord *ptimer;
{
double constant;
/* check the tdisble bit */
if (ptimer->tdis == 1){
ptimer->t1dl = ptimer->t1wd = 0;
ptimer->t2dl = ptimer->t2wd = 0;
ptimer->t3dl = ptimer->t3wd = 0;
ptimer->t4dl = ptimer->t4wd = 0;
ptimer->t5dl = ptimer->t5wd = 0;
return;
}
/* convert according to time units */
constant = constants[ptimer->timu];
/* timing pulse 1 */
ptimer->t1dl = (ptimer->dut1 + ptimer->trdl) / constant; /* delay */
ptimer->t1wd = ptimer->opw1 / constant; /* width */
ptimer->t1ld = ptimer->dut1 + ptimer->trdl; /* leading edge delay */
ptimer->t1td = ptimer->t1ld + ptimer->opw1; /* trailing edge delay */
/* timing pulse 2 */
ptimer->t2dl = (ptimer->dut2 + ptimer->trdl) / constant; /* delay */
ptimer->t2wd = ptimer->opw2 / constant; /* width */
ptimer->t2ld = ptimer->dut2 + ptimer->trdl; /* leading edge delay */
ptimer->t2td = ptimer->t2ld + ptimer->opw2; /* trailing edge delay */
/* timing pulse 3 */
ptimer->t3dl = (ptimer->dut3 + ptimer->trdl) / constant; /* delay */
ptimer->t3wd = ptimer->opw3 / constant; /* width */
ptimer->t3ld = ptimer->dut3 + ptimer->trdl; /* leading edge delay */
ptimer->t3td = ptimer->t3ld + ptimer->opw3; /* trailing edge delay */
/* timing pulse 4 */
ptimer->t4dl = (ptimer->dut4 + ptimer->trdl) / constant; /* delay */
ptimer->t4wd = ptimer->opw4 / constant; /* width */
ptimer->t4ld = ptimer->dut4 + ptimer->trdl; /* leading edge delay */
ptimer->t4td = ptimer->t4ld + ptimer->opw4; /* trailing edge delay */
/* timing pulse 5 */
ptimer->t5dl = (ptimer->dut5 + ptimer->trdl) / constant; /* delay */
ptimer->t5wd = ptimer->opw5 / constant; /* width */
ptimer->t5ld = ptimer->dut5 + ptimer->trdl; /* leading edge delay */
ptimer->t5td = ptimer->t5ld + ptimer->opw5; /* trailing edge delay */
}
/*
* WRITE_TIMER
*
* convert the value and write it
*/
static void write_timer(ptimer)
struct timerRecord *ptimer;
{
struct vmeio *pvmeio;
long status,options,nRequest;
/* get the delay from trigger source */
if (ptimer->torg.type == DB_LINK) {
options=0;
nRequest=1;
status = dbGetLink(&(ptimer->torg.value.db_link),ptimer,DBR_FLOAT,
&(ptimer->trdl),&options,&nRequest);
if(status!=0) return;
}
if (ptimer->out.type != VME_IO) {
if(ptimer->nsev<MAJOR_ALARM) {
ptimer->nsta = WRITE_ALARM;
ptimer->nsev = MAJOR_ALARM;
}
return;
}
pvmeio = (struct vmeio *)(&ptimer->out.value);
/* convert the value */
convert_timer(ptimer);
/* put the value to the ao driver */
if (time_driver((int)pvmeio->card, /* card number */
(int)pvmeio->signal, /* signal number */
(int)ptimer->dtyp, /* card type */
(int)ptimer->tsrc, /* trigger source */
(int)ptimer->ptst, /* pre-trigger state */
&ptimer->t1dl, /* delay/width array */
1, /* number of pulses */
((ptimer->tevt == 0)?0:post_event), /* addr of event post routine */
(int)ptimer->tevt) /* event to post on trigger */
!= 0){
if (ptimer->nsev<MAJOR_ALARM) {
ptimer->nsta = WRITE_ALARM;
ptimer->nsev = MAJOR_ALARM;
}
}
return;
}
/*
* READ_TIMER
*
* read the current timer pulses and convert them to engineering units
*/
static void read_timer(ptimer)
struct timerRecord *ptimer;
{
struct vmeio *pvmeio;
int source;
int ptst;
int no_pulses;
double time_pulse[2]; /* delay and width */
double constant;
/* initiate the write */
if (ptimer->out.type != VME_IO) {
recGblRecordError(S_dev_badOutType,ptimer,"read_timer");
return;
}
/* only supports a one channel VME timer module !!!! */
pvmeio = (struct vmeio *)(&ptimer->out.value);
/* put the value to the ao driver */
if (time_driver_read((int)pvmeio->card, /* card number */
(int)pvmeio->signal, /* signal number */
(int)ptimer->dtyp, /* card type */
&source, /* trigger source */
&ptst, /* pre-trigger state */
&time_pulse[0], /* delay/width */
&no_pulses, /* number pulses found */
1) < 0) return;
if (no_pulses == 0) return;
/* convert according to time units */
constant = constants[ptimer->timu];
/* timing pulse 1 is currently active */
/* put its parameters into the database so that it will not change */
/* when the timer record is written */
ptimer->dut1 = time_pulse[0] * constant; /* delay to trigger */
ptimer->opw1 = time_pulse[1] * constant; /* pulse width */
ptimer->ptst = ptst; /* pre-trigger state */
ptimer->tsrc = source; /* clock source */
return;
}