From:	CRDGW2::CRDGW2::MRGATE::"SMTP::CRVAX.SRI.COM::RELAY-INFO-VAX" 28-MAY-1991 18:22:38.59
To:	ARISIA::EVERHART
CC:	
Subj:	Re: real time clock driver

From:	RELAY-INFO-VAX@CRVAX.SRI.COM@SMTP@CRDGW2
To:	Everhart@Arisia@MRGATE

Received:  by crdgw1.ge.com (5.57/GE 1.97)
	 id AA06535; Tue, 28 May 91 17:09:40 EDT
Received: From UCBVAX.BERKELEY.EDU by CRVAX.SRI.COM with TCP; Tue, 28 MAY 91 12:56:56 PDT
Received: by ucbvax.Berkeley.EDU (5.63/1.42)
	id AA10593; Tue, 28 May 91 12:42:00 -0700
Received: from USENET by ucbvax.Berkeley.EDU with netnews
	for info-vax@kl.sri.com (info-vax@kl.sri.com)
	(contact usenet@ucbvax.Berkeley.EDU if you have questions)
Date: 28 May 91 08:16:22 GMT
From: dac.mdcbbs.com!tdh@uunet.uu.net
Organization: MDC - Douglas Aircraft, Long Beach, CA
Subject: Re: real time clock driver
Message-Id: <1991May28.081622.1@dac.mdcbbs.com>
Sender: info-vax-request@kl.sri.com
To: info-vax@kl.sri.com

Here's a little connect to interrupt routine iI put together to run
a KW clock to do interval timing on processes. It takes a Fortran or other
HL to call it and get it ticking.  Email to me if you need help.



;***********************************************************************
;
;  NAME:INT.MAR
;
;
;  LANGUAGE:MACRO11 ASSEMBLY LANGUAGE
;
;
;  DESCRIPTION:THIS MODULE SETS UP THE KWV11-C CLOCK TO WORK AS A CONNECT TO 
;		INTERRUPT DEVICE.
;
;
;  CALLING CONVENTION: CALL CONNECT(ICHAN)
;
;
;  INPUTS:
;
;     VARIABLE     LOCATION   TYPE    UNITS    DESCRIPTION
;     ICHAN        CLOCK      I*2     N/A      CHANNEL NUMBER
;     AST          CLOCK      I*2     N/A      AST NAME
;
;  OUTPUTS:
;
;     VARIABLE     LOCATION   TYPE    UNITS    DESCRIPTION
;     INT_DATA     CLOCK      I*4     N/A      OUT PUTBUFFER
;
;  REVISIONS:
;      DATE     WHO   DESCRIPTION                            VERSION  PCR
;   ---------   ---   -----------------------------------    -------  ---
;   01-17-89    TDH   ORIGINAL                                1.0     N/A
;***********************************************************************

;***********************************************************************
;  LOCAL VARIABLES:
;     VARIABLE     TYPE    UNITS    DESCRIPTION
;     KW_MODE      I*2     N/A      INTERRUPT INTERVAL MODE
;     KW_INT2      I*2     N/A      INTERRUPT FOR CLOCK COUNT
;     KW_EN        I*2     N/A      INTERRUPT ENABLE
;     KW_RATE      I*2     N/A      CLOCK OSCILLATION RATE
;     KW_GO        I*2     N/A      GO BIT FOR CLOCK
;
;***********************************************************************

;***********************************************************************
;  BEGIN
;***********************************************************************

	.TITLE	INT
;
	.PSECT	INT_DATA	PIC,OVR,REL,GBL,SHR,NOEXE,RD,WRT,LONG

BUFF_START:
KW_DATA:
INIT_CT: .WORD	0.,0.		;Inital KWV11 count
FLY_CT:	.WORD	0,0		;KWV11 count when int. occures

	.BLKW	96.

	.LIBRARY	/SYS$LIBRARY:LIB.MLB/
	.LINK		/SYS$SYSTEM:SYS.STB/

;	$SSDEF
	$CINDEF
	$IDBDEF
	$UCBDEF
	$IODEF
	$CRBDEF
	$VECDEF

	.SHOW  BINARY
;++
; KW_START - Starts the KWV11-C clock
;
; Functional description:
;
;	This routine starts the KWV11-C
;		Rate = 
;		Repeated interrupt
;		
; Inputs:
;
;	0(R2)  - arg count of 4
;	4(R2)  - Address of the process buffer
;	8(R2)  - Address of the IRP (I/O request packet)
;	12(R2) - Address of the device's CSR
;	16(R2) - Address of the UCB (Unit control block)
;
; Outputs:
;	none
;
;	The routine must preserve all registers except R0-R2 and R4.
;
;--

KW_MODE = ^O004		; INTERVAL TIMER MODE
KW_INT2 = ^O40000	;INT2 FOR CLOCK COUNT
KW_EN   = ^O100		;ENABLE INTERRUPT
KW_RATE = ^O020		;CLOCK RATE = 1 Khz
KW_GO   =     1		;ENABLE COUNTER

KW_CSR = KW_MODE!KW_EN!KW_RATE!KW_GO

KW_START::
	MOVL	12(R2),R0		;Address of CSR
	CLRW	(R0)			;Reset Clock
	MNEGW	INIT_CT,2(R0)		;Set counter
	MOVW	#KW_CSR,(R0)		;Start clock

	MOVW	#SS$_NORMAL,R0		;is OK
	RSB				;Return
;++
; KW_INT
; Functional description:
;
;
; Inputs:
;
;	0(R2)  - arg count of 5
;	4(R2)  - Address of the process buffer
;	8(R2)  - Address of the AST parameter
;	12(R2) - Address of the device's CSR
;	16(R2) - Address of the IDB (interrupt dispatch block)
;	20(R2) - Address of the UCB (Unit control block)
;
;
; Outputs:
;	Sets those bits in the AST parameter for those
;	channels who had a buffer filled
;
;	The routine must preserve all registers except R0-R4
;
;--
CIN_CSR_ADD = 12			;Address of CSR

KW_INT::
	MOVL	CIN_CSR_ADD(R2),R4	;Address of the KWV11 CSR
	MOVW	^O2(R4),FLY_CT		;SAVE COUNTER
	INCW	FLY_CT			;Keep track of ticks

	MOVW	#SS$_NORMAL,R0		;is OK
	RSB


;++
; KW_CANCEL, Cancels an I/O operation in progress
;
; Functional description:
;
;	This routine turns off the KWV11-C
;
; Inputs:
;	R5	-  Addr of the UCB
;
; Outputs:
;
;	The routine must preserve all registers except R0-R3.
;
;
;--

KW_CANCEL::
	MOVL	UCB$L_CRB(R5),R0		;Add of CRB
	MOVL	CRB$L_INTD+VEC$L_IDB(R0),R0	;Add of IDB
	MOVL	IDB$L_CSR(R0),R0		;Add of CSR
	CLRW	(R0)				;Reset Clock
	MOVW	#SS$_NORMAL,R0
	RSB

BUFF_END:
	.PAGE
;	CALL CONNECT( CHANNEL )
;
;		AST  Address of routine for AST

CONNECT::
	.WORD	0

	$QIO_S	CHAN=@4(AP),-		;CHANNEL
		FUNC=#IO$_CONINTWRITE,-	;R/W BUFFER
		P1=BUF_DES,-		;Buffer descriptor
		P2=#BUF_ENTRY,-		;Entry list
		P3=#FLAGS		;Flags

FLAGS = CIN$M_REPEAT!CIN$M_START!CIN$M_ISR!CIN$M_CANCEL


	RET

INT_CH:	.BLKL	1			;Channel no. placed here

BUF_DES:
	.LONG	BUFF_END-BUFF_START	;Size
	.LONG	BUFF_START		;Address

BUF_ENTRY:
	.LONG	0			;No init. code
	.LONG	KW_START-BUFF_START	;Start code
	.LONG	KW_INT-BUFF_START	;Interrupt service code
	.LONG	KW_CANCEL-BUFF_START	;Cancel code
	
	.END

