projplan.txt : Project plan for Printer Driver Project Author : Sowmya Venkat Project : lp driver Date : 05/07/03 External Specification: ----------------------- Syscalls supported by the lp driver: -------------------------------- open() and close() are optional. User can directly write or putc to a LPT without open(). open(LPT#) : Opens a printer device LPT#, where LPT# is the name specified in conf.h to identify the printer device close(LPT#) : Closes a printer device LPT# putc(LPT#,ch): Prints the character ch using printer LPT# write(LPT#,str,count):Prints the string str of length count using printer LPT Internal Specification: ----------------------- lp data structure has the following members: started/busy flag--at least one char has been output in current string semaphore to wait for queue space Queue in which a char is enqueued by putc and dequeued by int handler The lp data structure is shared between upper and lower halves of driver. One instance is created per printer device General working: --------------- Each printer device is identified by an unique integer descriptor defined in conf.h. The lp driver is added to the global device switch table. The descriptor is used as an index in the global table to invoke the printer driver routines and retrieve other information such as irq number, base address required by the driver. Process context lp driver routines: ----------------------------- In the following routines, devptr is the pointer to the device switch table devtab. When user issues a system call (mentioned in external specification) on LPT, the respective lp driver routine is invoked as given below: lpopen(devptr,name,mode): can be trivial lpclose(devptr) : can be trivial lpputc(devptr,ch): if started==FALSE, Calls lpout() to output the first char to the printer. and sets started flag. This flag is reset in the int handler when no more data is available for it to send to printer. If started, ch is enqueued in the queue. If the queue gets filled up, the process blocks on semaphore till the queue has a minimum number of free spaces (if doing watermarking, optional.) NOTE: We can't use "enqueue" as function name for the queue, because it's already in use in Xinu, so modify the provided queue package a bit. lpwrite(devptr,str,count) : Validates count and calls lpputc to process chars. Interrupt context lp driver routine: --------------------------------- lpptr is the pointer to the printer data structure. void irq7inthandc(void) Output Interrupt handler for printer device Dequeues a char from queue, signals the semaphore and outputs it to printer using the printer protocol. If the queue is empty, clear the start flag. The printer itself needs no acknowledgement. Initializaton: ---------------------------------- lpinit(devptr): Initialization routine for printer driver. Initialize the lp data structure and enable printer interrupts. Initialize the queue, Register the interrupt handler and enable IRQs in PIC (done by set_evec) Helper functions: ----------------- lpout(base,ch) : Sends data on printer data register, Sends a strobe signal with ints enabled to the printer control register. Removes the strobe after a delay.