;;; -*- Mode:Lisp; Readtable:T; Package:USER; Base:8; Patch-File:T -*-
;;; Private patches made by NICK
;;; Reason:
;;;  Changed :reset for sdu-serial-stream-mixin so as to ALWAYS set stop bits to :1bit (Robert Putnam)
;;; Written 19-Nov-85 18:13:57 by NICK,
;;; while running on Lambda A from band 3
;;; with System 102.158, Local-File 56.11, FILE-Server 13.2, Unix-Interface 5.6, MagTape 40.22, ZMail 57.10, Tiger 20.6, KERMIT 26.20, MEDIUM-RESOLUTION-COLOR 17.4, Experimental Sited 1.0, Experimental window-maker 1.0, Experimental TCP-Kernel 30.0, Experimental TCP-User 57.0, Experimental TCP-Server 33.0, microcode 768, chaos/tcp loaded.



; From file SDU-SERIAL.LISP#> QL.IO1; LMI: (18)
#8R SYSTEM-INTERNALS#:
(COMPILER-LET ((*PACKAGE* (PKG-FIND-PACKAGE "SYSTEM-INTERNALS")))
  (COMPILER#:PATCH-SOURCE-FILE "LMI: QL.IO1; SDU-SERIAL.#"

(defmethod (sdu-serial-stream-mixin :reset) (&optional (abort-output :abort) (reset-chip t))
  abort-output
  (cond ((or (> input-buffer-size %array-max-short-index-length)
	     (> output-buffer-size %array-max-short-index-length))
	 (ferror nil "buffer sizes must be <= ~s" %array-max-short-index-length)))
  (let ((new-mode-word (assemble-word-from-description
			 *8251-mode-word-description*
			 'baud-rate-factor :16x
			 'char-length char-length
			 'parity-enable nil
			 'generate-parity nil
			 'stop-bits :1bit))
	(new-command-word   (assemble-word-from-description
			      *8251-command-word-description*
			      'transmit-enable t
			      'dtr t
			      'receive-enable t
			      'reset-errors t
			      'rts t)))
    (send self :remove-unibus-channels)		;Get rid of unibus channels if any
    (cond (reset-chip
	   (%multibus-write-8 pci-csr 0)
	   (%multibus-write-8 pci-csr 0)
	   (%multibus-write-8 pci-csr 0)
	   (%multibus-write-8 pci-csr #x40)	; reset chip
	   (%multibus-write-8 pci-csr new-mode-word)
	   (%multibus-write-8 pci-csr new-command-word)))
						; now do the baud rate
    (%multibus-write-8 pit-mode (logior pit-channel #x36))
    (let ((counter-value (// 76800. baud-rate)))
      (%multibus-write-8 pit-counter counter-value)
      (%multibus-write-8 pit-counter (ash counter-value -8)))
    
    (setq input-unibus-channel
	  (get-unibus-channel rcv-interrupt-number
			      0 0 0 1 (ceiling input-buffer-size page-size))
	  output-unibus-channel
	  (get-unibus-channel xmit-interrupt-number
			      0 0 0 1 (ceiling output-buffer-size page-size)))
    ))

))
