'\"macro stdmacro
.if n .pH ddi_dki.delay @(#)delay	40.6 of 10/10/89
.\" Copyright 1989 AT&T
.de IX
.ie '\\n(.z'' .tm .Index: \\$1 \\$2 \\$3 \\$4 \\$5 \\$6 \\$7 \\$8 \\$9	\\n%
.el \\!.IX \\$1 \\$2 \\$3 \\$4 \\$5 \\$6 \\$7 \\$8 \\$9
..
.nr X
.if \nX=0 .ds x} delay D3DK "" "DDI/DKI" "\&"
.if \nX=1 .ds x} delay D3DK "" "DDI/DKI"
.if \nX=2 .ds x} delay D3DK "" "\&"
.if \nX=3 .ds x} delay "" "" "\&"
.TH \*(x}
.IX "\f4delay\fP(D3DK)"
.SH "NAME" 
\f4delay\f1 \- delay process execution for a specified number of clock ticks
.SH "SYNOPSIS" 
.nf
.na
\f4void delay(long \f2ticks\f4);\f1
.ad
.fi
.SH "ARGUMENT" 
.RS 0n 10
.IP "\f2ticks\f1" 10n
The number of clock cycles for a delay.
\f2ticks\f1 are
frequently set as an expression containing the system variable \f4HZ\f1,
the number of clock ticks in one second; \f4HZ\f1 is defined in \f4sys/param.h\f1.
.IX "HZ (clock cycles)"
.IX "clock cycles"
.RE
.SH "DESCRIPTION" 
\f4delay\f1 provides a way to wait for an event to happen.  Occasionally, a
driver may need to wait a given period of time until work is available.
The value of \f4HZ\f1 can vary from system to system, and so the function
\f4drv_hztousec\f1(D3DK) should be used when accurate timing is required.
.P
The \f4delay\f1 function calls
\f4timeout\f1(D3DK) to schedule a wakeup call after the specified amount of
time has elapsed.  \f4delay\f1 then goes to sleep until \f4timeout\f1 wakes
up the sleeping process.  While \f4delay\f1 is active, \f4splhi\f1 is
set.  At completion, the former priority level is returned through
\f4splx\f1.
.P
\f4delay\f1 requires user context.
.SH "RETURN VALUE" 
None
.SH "LEVEL" 
Base Only  (Do not call from an interrupt routine)
.SH "SEE ALSO" 
\f2BCI Driver Development Guide\f1, Chapter 10, ``Synchronizing Hardware and Software Events''
.P
.na
\f4biodone\f1(D3DK),
\f4biowait\f1(D3DK),
\f4drv_hztousec\f1(D3DK),
\f4drv_usectohz\f1(D3DK),
\f4sleep\f1(D3DK),
\f4timeout\f1(D3DK),
\f4untimeout\f1(D3DK),
\f4wakeup\f1(D3DK)
.ad
.SH "EXAMPLE" 
.IX "\f4cmn_err\fP(D3DK), example"
.IX "\f4delay\fP(D3DK), example"
.IX "\f4getminor\fP(D3DK), example"
.P
Before a driver I/O routine allocates buffers and stores any user data in them,
it checks the status of the device (line 12).  If the device needs 
manual intervention (such as, needing to be refilled with paper), a message is
displayed on the system console (line 14).  The driver waits an allotted time
(line 16) before repeating the procedure.
.ne 4
.P
.nf
.ft 4
.ps 7
 1  struct  device  {           /* layout of physical device registers */
 2          int      control;      /* physical device control word     */
 3          int      status;       /* physical device status word      */
 4          short    xmit_char;    /* transmit character to device     */
 5  }; /* end device */
 6
 7  extern struct device xx_addr[]; /* physical device regs.  location */
       . . .
 9                                            /* get device registers  */
10  register struct device *rp = &xx_addr[getminor(dev)>>4)];
11
12  while(rp->status & NOPAPER) {     /* while printer is out of paper */
13                  /* display message and ring bell on system console */
14      cmn_err(CE_WARN, "^xx_write: NO PAPER in printer %d\\007",
15                        (dev & 0xf));
16      delay(60 * HZ);           /* wait one minute and try again */
17  } /* endwhile */
.ps
.ft 1
.fi
.P
.FG "delay \- wait for paper to be put on a printer"
