Specifications

Sample Driver Written in C
B.1 LRDRIVER Example
*
* Environment:
*
* Kernel mode, system context, fork IPL, fork lock held.
*/
void lr$startio (IRP *irp, LR_UCB *ucb) {
int orig_ipl;
/* Adjust ucb$l_svapte such that it points to the start of the data in
* the system buffer packet.
*/
ucb->ucb$r_ucb.ucb$l_svapte = (char *) ucb->ucb$r_ucb.ucb$l_svapte +
sizeof(SYSBUF_HDR);
/* Acquire the device lock, raise IPL, saving original IPL */
device_lock (ucb->ucb$r_ucb.ucb$l_dlck, RAISE_IPL, &orig_ipl);
/* Send the first character to the device. We can ignore the status,
* since we will timeout if the device is not ready.
*/
lr$send_char_dev (ucb);
/* Set up a wait for the completion of the I/O by using the wfikpch macro.
* Wfikpch will restore the device lock and restore IPL. When output of
* the entire buffer has been completed, the lr$interrupt routine will
* queue the lr$iodone_fork routine. If the I/O does not complete within
* LR_WFI_TMO seconds, then exe$timeout will call lr$wfi_timeout.
*/
wfikpch (lr$iodone_fork, lr$wfi_timeout, irp, 0, ucb, LR_WFI_TMO, orig_ipl);
return;
}
/*
* LR$SEND_CHAR_DEV - Send Character to the Device
*
* Functional description:
*
* This routine sends the next character from the system buffer to the
* device via the printer write data register. This routine decrements the
* count of remaining bytes (ucb$l_bcnt) and advances the pointer to the
* next character (ucb$l_svapte).
*
* This is an internal routine that is used by the start I/O, interrupt
* service, and periodic check device ready routines.
*
* Calling convention:
*
* status = lr$send_char_dev (ucb)
*
* Input parameters:
*
* ucb Pointer to unit control block
*
* Output parameters:
*
* None.
*
* Return value:
*
* status SS$_NORMAL if the next data byte was sent to the printer
* device.
* SS$_DEVOFFLINE if the next data byte was not sent to the
* printer device since it is not ready to accept
* data.
B–16