Specifications

Sample Driver Written in C
B.1 LRDRIVER Example
/*
* LR$CHECK_READY_FORK - Periodic Check for Device Ready
*
* Functional description:
*
* This routine performs a once-a-second check of the readiness of the
* device to resume output. While the device remains offline this fork
* routine reschedules itself via the fork wait queue. When the device
* is ready to resume, the next character is sent and the remainder of
* the output is done by the interrupt service routine.
*
* If the device remains offline for ucb$l_lr_msg_tmo seconds (initially
* set to LR_OFFLINE_TMO) then a "device offline" message is sent to
* OPCOM. The device offline message interval is doubled each time while
* it is less than an hour. When the device becomes ready again, the offline
* message interval is reset to its initial LR_OFFLINE_TMO value.
*
* Calling convention:
*
* lr$check_ready_fork (irp, not_used, ucb)
*
* Input parameters:
*
* irp Pointer to I/O request packet
* not_used Unused fork routine parameter fr4
* ucb Pointer to unit control block
*
* Output parameters:
*
* None.
*
* Return value:
*
* None.
*
* Environment:
*
* Kernel mode, system context, fork IPL, fork lock held.
*/
void lr$check_ready_fork (IRP *irp, void *not_used, LR_UCB *ucb) {
int orig_ipl;
int status;
/* If the I/O request has been canceled while we’ve been waiting or there
* are no more characters to send to the device then call our I/O done fork
* routine directly to complete the I/O request and then return from this
* routine.
*/
if (ucb->ucb$r_ucb.ucb$v_cancel || ucb->ucb$r_ucb.ucb$l_bcnt == 0) {
lr$iodone_fork (irp, 0, ucb);
return;
}
/* Acquire the device lock, raise IPL, saving original IPL */
device_lock (ucb->ucb$r_ucb.ucb$l_dlck, RAISE_IPL, &orig_ipl);
/* Attempt to send the next character to the device. If the device is
* still not ready, then the character will not be sent and an error status
* will be returned.
*/
status = lr$send_char_dev (ucb);
B–21