Nuclear Instruments and Methods 174 (1980) 21-34 © North-Holland Publishing Company
CAMAC SUBROUTINES IN FORTRAN FOR REAL-TIME CAMAC DATA AND COMMAND HANDLING Ozer CIFTCIOGLU Technical University o f Istanbul, Electrical Engineering Faculty, Department o f Nuclear Power, Teknik Universite, Instanbul, Turkey Received 8 January 1980
Assembly written CAMAC subroutines have been developed to be used in FORTRAN for CAMACdata and command handling in conjunction with PDP-I1 * type of computers. Subroutines have the standard form recommended by the ESONEt Committee. By means of the general Block Transfer Subroutines, real-time CAMACdata and command handling was brought to the FORTRAN environment for real-time programming and data acquisition applications. Although the implementation was particularly performed for a dedicated CAMACCrate Controller DC-011 developed by ORTEC, the subroutines were so designed that they have the recommended conventional features including Multi-Crate Systems.
1. Introduction
A BASIC overlay for CAMAC data and command handling was reported earlier [1]. This paper describes the implementation of CAMAC subroutines for FORTRAN in accordance with the related ESONE publication [2] concerning FORTRAN realtime programming and data acquisition implementation together with the CAMAC system.
Introducing a BASIC overlay to the run-time systems greatly facilitaties the communication between the computer and the devices coupled to the computer. However, because of the interpretive nature of BASIC, this type of communication is too slow for many real-time applications. In such cases, for rapid data and command handling, assembly written programs introduced in the present software would be very efficient in many respects. One drawback is the need of good knowledge of assembly programming which is not easy to acquire without investing some time for gaining experience. Therefore, the advantages of high level programming with a standard language and compiler become obvious for an average experimenter having no intention or further need to be familiar with any details of the system more than he needs for a particular experiment. Such high level programs for data and command handling between the host system and the peripheral unit require additional software to be added to the present real-time system if no other hardware or software modifications were made in the compilers or interpreters for this purpose. The inclusion of some standard features in that additional software provides further ease to the experimenter or high-level language programmer for his particular computer-based application.
2. Description of the functional specifications of the subroutines This section describes in detail all the subroutines implemented. Since many implementations will not require the complete set, the subroutines implemented are grouped into three subsets corresponding to the recommended implementation described in the relevant ESONE publication [2]. These are a) primary subroutines, b) single action subroutines, c) block transfers, multiple actions and inverse declarations. The implementation of subroutines was carried out for PDP-11 type computers. Although the implementation was particularly performed for a dedicated CAMAC Crate Controller DC-011 [3] developed by ORTEC, the subroutines were so designed that they have the recommended conventional features including Multi-Crate Systems [4]. Therefore they can easily be implemented, with some minute modifications and the relevant address assignments, for any type of Ded-
* Trade Mark by DEC (Digital Equipment Corporation). t European Standards of Nuclear Electronics. 21
O. Ciftcioglu / CAMAC subroutines in FORTRAN
22
icated Crate Controller appropriately connected to the computer system, or standard controllers in Parallel Branch Highway. All subroutines are called, by a CALL command, in the standard way and recommended naming conventions for them were adopted i.e. they are, in general, in the form of CALL NAME (argl, arg2 ..... argi, ..., argn), where the NAME stands for the recommended name of the CAMAC subroutine to be implemented. The symbols argl, arg2, .... argn are appropriate arguments, for instance, corresponding to B, C, N, A, F, D, Q... which are respectively denoting Branch Number, Crate Number, Station Number, Subaddress, Function, Data to be read or written, Q response and so on... in the CAMAC system. Definition and functional description of the parameters used in the subroutines are given in section 3.
2.1. Primary subroutines Two primary subroutines are required in all implementations. The first provides the capability to define the address of a CAMAC entity for accessing. The second is used to perform CAMAC operations on the defined entities. Any CAMAC entity for which there is a defined standard mode of access, can be accessed through the use of these two subroutines. There is no restriction involved in this implementation on the use of crate controllers or other system modules.
2.1.1. Declare CAMA C Register ( CDREG ) The FORTRAN form for calling the Declare CAMAC Register subroutine implemented is CALL CDREG (IEXT, IB, I f , N, IA),
(1)
where the arguments are as follows. IEXT IB IC N IA
= external address, = branch number, = crate number, = station number, = subaddress.
According to the implicit type of variable declaration convention in FORTRAN, all variables are supposed to be integers. Functional description of the arguments is given in section 3. Subroutine CDREG combines the components IB, IC, N and IA into a single CAMAC register reference
75
1& 13
12
11 lO
9
8
7
6
5
&
3
2
l
0
Fig. 1. Branch (B), Crate (C), Station (N) and subaddress (A) information accomodated in a 16-bit computer word by the CAMACsubroutine CDREG.
IEXT which is a return variable. IEXT uniquely defines the specified CAMAC register and crate for other subroutines in the implementation. The coding protocol showing the accomodation of the components in a 16-bit computer word is given in fig. 1 where S is the sign bit used for the indication to approach the tables of register references explained in the following section. By means of this type of coding a maximum of 7 branch drivers, each having a maximum of 7 crates can be addressed. For the action which does not require station number (hi) and subaddress (A) information, the subroutine CDREG requires only three arguments i.e. IEXT, IB, IC, while the other two arguments IN and IA become irrelevant. This situation arises mostly in case of the utilization of single action subroutines which perform actions common to all modules. Accordingly the t'orm for calling the subroutine can alternatively be expressed by CALL CDREG (IEXT, IB, IC),
(2)
in place of subroutine call (1). Before calling any other subroutine, the subroufine CDREG must always be performed once to test whether the Branch and Crate being addressed are appropriately connected to the system. If they are duly connected a Branch and a Crate identification bit are set at two specified memory locations and they are tested whenever the Branch and Crate are referenced by single CAMAC action subroutine calls or block transfer subroutine calls initiated by the appropriate LAM signal. This ensures that the Branch and Crate being addressed are on-line, before a CAMAC command which is common to all modules in a crate, is issued. Otherwise a DEVICE ERROR message is delivered to the terminal.
2.1.1.1. Table o f register references. It is advantageous in many applications to have tables of CAMAC register references, identical in form to the value returned by CDREG, i.e. IEXT. Such tables save the time required to define the register references each time a program is executed. In this work, these refer-
(9. Ciftcioglu / CAMAC subroutines in FORTRAN ences are created in assembler code by means of an additional CAMAC table of register references subroutine CTRR. The form for calling is CALL CTRR (IRR1, IRR2, ..., I R R N ) ,
(3)
where the argument IRRJ is the/'th register reference to be recorded in a table particularly defined in the assembler code for this purpose. It is identical in form to the variable IEXT.
2.1.2. Perform single CAMAC action The FORTRAN form for calling the Perform Single CAMAC Action subroutine implemented is CALL CFSA (JF, IEXT, RNT, Q ) , or alternatively CALL CFSA (JF, IEXT, RNT, Q) , where the arguments are as follows. JF IEXT INT RNT Q
= function code, = external address, = CAMAC data word (integer representation), = CAMAC data word (floating-point representation), = Q response.
Functional description of the arguments is given in section 3. The subroutine CFSA causes the CAMAC action specified by the function code JF to be performed at the CAMAC address specified by IEXT. If JF contains a read or write code, a 24-bit data transfer occurs between the CAMAC register addressed by IEXT and the computer storage location INT (or RTN). Otherwise INT (or RNT) is ignored. The state of Q resulting from the operation is stored in Q; ".TRUE." if Q = 1, ".FALSE." if Q = 0.
2.1.2.1. Table of register references. To approach the table of register references, the second argument of subroutine CFSA, i.e. IEXT, was used. In case the value assigned to the argument 1EXT is minus, the absolute value (i) is considered as a pointer to the ith register reference in the table of register references already defined in the assembler code. The register references are written by means of the subroutine CTRR (section 2.1.1.1). This type of assignment takes precedence over the assignment performed by means of the subroutine CDREG for the variable IEXT.
23
2.2. Single action subroutines These subroutines, together with those described in section 2.1, form the implementation which provides a complete facility for specifying single CAMAC actions in a way which is mnemonic, compact and independent of the type of highway or crate controller. By these subroutines, first, Branch and Crate specified by IEXT are tested if they are properly connected to the system and addressed by the subroutine CDREG before one of the subroutines is performed. This prevents the false execution of the subroutines in an unwanted crate. Any attempt for such an execution causes an error message at the terminal.
2.2.1. Generate Dataway Initialize The FORTRAN form for calling the Generate Dataway Initialize subroutine implemented is CALL CCCZ (IEXT) , where IEXT = external address. The functional description of the argument is given in section 3. The subroutine CCCZ checks if the crate being addressed is on-line and causes Dataway Initialize (Z) to be generated in the crate specified by IEXT.
2.2.2. Generate Crate Clear The FORTRAN form for calling the Generate Crate Clear subroutine implemented is CALL CCCC (IEXT), where IEXT = external address. The functional description of the argument is given in section 3. The subroutine CCCC checks if the crate being addressed is on-line and causes Dataway Clear (C) to be generated in the crate specified by IEXT.
2.2.3. Set or Clear Dataway lnhibit The FORTRAN form for calling the Set or Clear Dataway Inhibit subroutine implemented is CALL CCCI (IEXT, L ) , where IEXT = external address, L = logical truth value.
24
O. Ciftcioglu / CAMA C subrou tines in FOR TRAN
The functional description of the arguments is given in section 3. The subroutine CCCI checks if the crate being addressed is on-line and causes Dataway Inhibit (I) to be set in the crate specified by IEXT if the value of L is ".TRUE." and to be reset if the value of L is ".FALSE.".
assigned to LAM and used by other subroutines to determine whether the LAM is accessed via special functions for LAM access or via writing or reading group 2 registers.
2.2.4. Test Dataway Inhibit The FORTRAN form for calling the Test Dataway Inhibit subroutine implemented is
CALL CCLM (LAM, INTA, L ) ,
CALL CTCI (IEXT, L), where IEXT = external address, L = logical truth value. The functional description of the arguments is given in section 3. The subroutine CTCI checks if the crate being addressed is on-line and sets the value of L to ".TRUE." if Dataway Inhibit is set in the crate specified by IEXT and sets the value of L to ".FALSE." if Dataway Intfibit is not set.
2.2.6. Enable or disable L A M The FORTRAN form for calling the Enable or Disable LAM subroutine implemented is
where LAM = LAM identifier, INTA = integer array, L = logical truth value. The functional description of the arguments is given in section 3. The subroutine CCLM causes the LAM specified by LAM to be enabled if the value of L is ".TRUE." and causes it to be disabled if the value of L is ".FALSE.". 2.2.7. Clear L A M The FORTRAN form for calling the Clear LAM subroutine implemented is
CALL CCLC (LAM, INTA),
2.2.5. Declare L A M The FORTRAN form for calling the Declare LAM subroutine implemented is
where
CALL CDLAM (LAM, IB, IC, N, M, INTA) ,
LAM = LAM identifier, INTA = integer array.
where LAM IB IC N M INTA
= LAM identifier, = branch number, = crate number, = station number, = LAM access specifier, = integer array.
The functional description of the arguments is given in section 3. The subroutine CDLAM encodes the branch number IB, the crate number IC, the station number N and all other necessary information concerning a LAM into an integer form and stores the result in LAM. The parameter M is interpreted as a subaddress if its value is greater than or equal to zero. In this case the coding protocol for the components of the variable LAM in a 16-bit computer word is the same as shown in fig. 1. The parameter M is interpreted as the negative of a bit position if its value is less than zero. This information is encoded as a sign bit in the value
The functional description of the arguments is given in section 3. The subroutine CCLC causes the LAM specified by LAM to be cleared, 2.2.8. Test L A M The FORTRAN form for calling the Test LAM subroutine implemented is
CALL CTLM (LAM, INTA, L), where LAM = LAM identifier, INTA = integer array, L = logical truth value. The functional description of the arguments is given in section 3. The subroutine CTLM sets L to the value ".TRUE." if the LAM specified by LAM is asserted, and sets L to the value ".FALSE." if the LAM is not asserted.
O. Ciftcioglu / CAMA C subroutines in FORTRAN 2.2.9. Load L A M lnterrupt Service Routine Addresses The FORTRAN form for calling the Load LAM Interrupt Service Routine Addresses subroutine is CALL CISRTS. There is no argument associated to this subroutine. The subroutine CISRTS loads the address of the LAM interrupt service routine processor of each branch, to the associated memory location which is called interrupt vector. Therefore, before using any LAM interrupt, the subroutine must be executed once within the program to be run. 2.3. Block transfers, multiple actions, and inverse declarations These subroutines, together with those described in sections 2.1 and 2.2, form a comprehensive CAMAC support system with very general features and a potential for efficient execution of block transfers and multiple actions. All the action subroutines in this section employ a "control block", ICB, which is an integer array containing four elements as follows: Element Element Element Element
1 : repeat count, 2: tally, 3: LAM identification, 4: channel identification.
The repeat count specifies the number of CAMAC actions or the maximum number of data words to be transferred. The tally is returned by the subroutine and indicates the number of actions actually executed or the number of data words actually transferred. Thus the calling program can detect and analyze a premature termination of an activity. The LAM identification is a coded identifier of the same form and interpretation as that returned by the subroutine CDLAM. The channel identification is a systemdependent parameter which is not required in all implementations. It represents the channel number used for various data transfers between the computer and the peripheral unit in conjunction with the CAMAC system. 2.3.1. General Multiple Action The FORTRAN form for calling the General Multiple Action subroutine implemented is CALL CFGA (JFA, IEXTA, INTC, QA, ICB), or alternatively
25
CALL CFGA (JFA, IEXTA, RNTC, QA, ICB), where JFA IEXTA INTC RNTC QA , ICB
= function code array, = external addresses array, = CAMAC data array (integer array), = CAMAC data array (floating-point array), = Q response array, = control block array.
The functional description of the arguments is given given in section 3 The subroutine CFGA performs a sequence of CAMAC functions at a corresponding sequence of CAMAC addresses and returns a sequence of Q responses. The number of functions executed, addresses accessed, and Q responses returned is given by the value of the parameter ICB (1). CAMAC data words are transferred between the CAMAC system and the array INTC (or RNTC) whenever the specified function is Read or Write. Since the array JFA can contain both Read and Write functions, data words may be written to and read from the same array by a single call to this subroutine. CAMAC-dataword positions in the array INTC (or RNTC) which correspond to functions in the array JFA which are neither Read nor Write are not accessed by this subroutine. If the third element of ICB contains the value zero, the specified sequence of actions is executed immediately. If it contains a LAM identification, then the sequence of actions is not initiated until the LAM is recognized. 2.3.2. Address-Scan The FORTRAN form for calling the Address-Scan subroutine implemented is CALL CFMAD (JF, IEXTB, INTC, ICB), or alternatively CALL CFMAD (JF, IEXTB, RNTC, ICB), where JF IEXTB INTC RNTC ICB
-- function code, = external addresses array, = CAMAC data array (integer array), = CAMAC data array (floating-point array), = control block array.
The functional description of the arguments is given in section 3. The subroutine CFMAD causes a single CAMAC function specified by the value of JF to be executed
O. Cif~cioglu / CAMA C subroutines in FORTRAN
26
at a succession of addresses computed using the Address Scan Algorithm. In the Address Scan Mode (ACA) [5,6] implemented, the specified function is executed first at the address given by the first element of the array IEXTB. Then if the Q response is 1, the subaddress is incremented by 1 and the index into the data array INTC (or RNTC) is incremented by 1, and the function is executed at this new subaddress. If the subaddress is incremented beyond 15, it is set to zero, and the station number is incremented. If the Q response is 0, the subaddress is set to zero and the station number is incremented, but the index into INTC (or RNTC) is not changed. Execution of specified function is attempted at the resulting new address, and the process is repeated until either the requested number of actions (given in the first element of ICB) has been performed or the address computed by the procedure described above exceeds the address contained in the second element of IEXTB. If the third element of ICB contains the value 0, execution of the CAMAC actions begins immediately. If it contains a LAM identifier, execution does not begin until the specified LAM is recognized. Address scan is extended to other address as follows. If the station number is incremented beyond the number of stations in a crate, it is set to 1, and the crate number is incremented. If the crate number is incremented beyond the number of crates in the branch, the crate number is set to 1, and the branch number is incremented. The Q responses to the CAMAC functions are not saved during the execution.
The subroutine CFUBC causes a single CAMAC function given by the value of JF to be executed at the CAMAC address specified by the value of IEXT. In this mode the CAMAC address is never changed, but single register is expected to supply or accept many words of data. It is assumed capable to supply or accept a data word whenever the controller addresses it until the block is exhausted or the controller terminates the process because the number of data transfers exceeds the limit given by the first element of ICB. If the third element of ICB contains the value 0, execution of the CAMAC actions begins immediately. If it contains a LAM identifier, execution does not begin until the specified LAM is recognized. The module indicates that the block is exhausted by its Q response. There are two methods for doing this which are Stop Mode and Stop-On-Word Mode [5]. In this work only Stop Mode (UCS) [5] is permissible, then the fourth element of ICB which is reserved for system-dependent facilities is used to specify the mode which the module is using. The Q responses to the CAMAC functions are not saved. Since the Q response is used by the module to indicate end of block, it carries no other information to the calling program.
2.3.4. LAM-Synchronized Block Transfer The FORTRAN form for calling the LAM-Synchronized Block Transfer subroutine implemented is CALL CFUBL (JF, IEXT, INTC, ICB) , or alternatively
2.3.3. Controller-Synchronized Block Transfer The FORTRAN form for calling the ControllerSynchronized Block Transfer subroutine implemented is CALL CFUBC (JF, IEXT, INTC, ICB) , or
CALL CFUBC (JF, IEXT, RNTC, ICB), where JF IEXT INTC RNTC ICB
= = = = =
function code, external address, CAMAC data array (integer array), CAMAC data array (floating-point array), control block array.
The functional description of the arguments is given in section 3.
CALL CFUBL (JF, IEXT, RNTC, ICB), where JF IEXT INTC RNTC ICB
= function code, = external address, = CAMAC data array (integer array), = CAMAC data array (floating-point array), = control block array.
The functional description of the arguments is given in section 3. The subroutine CFUBL causes the single CAMAC function specified by the contents of JF to be executed at the CAMAC address specified by the content of IEXT, with the usage of the Q response and the LAM signal defined as ULS mode [5]. In the ULS mode the CAMAC address is not changed, but the single address is expected to supply or accept many
O. Ciftcioglu / CAMAC subroutines in FORTRAN words of data. In the ULS mode, the module asserts a LAM whenever it is ready to participate in a data transfer, and the controller responds with tile appropriate command to effect the transfer. Any data words transferred are placed into or taken from the array INTC (or RNTC). The controller terminates the process if the number of executions exceeds the limit given by the contents of the first element ICB, or the module may terminate the process by responding with Q = 0. The response Q = 1 indicates that the specified function was properly executed. The response Q = 0 indicates that the attempted data transfer was not completed and that the process should be terminated. The LAM which synchronizes the process is specified by the contents of the third element of ICB; upon termination the number of Q = 1 response is stored in the second element of ICB. The Q responses to the CAMAC functions are not saved. Since the Q response is used by the module to indicate end of block, it can carry no other information to the calling program. Modules designed to be used in this mode must clear the synchronizing LAM during the execution of a Read or Write conmaand. 2.3.5. Repeat Mode Block Tranfer The FORTRAN form for calling the Repeat Mode Block Transfer subroutine implemented is CALL CFUBR (JF, IEXT, INTC, ICB), or alternatively CALL CFUBR (JF, IEXT, RNTC, ICB),
ceeded; Q = 0 indicates that the module was not ready to execute the function and that the controller should try again. Any data words transferred are placed into or taken from the array INTC (or RNTC). If the response is Q = 0, no transfer took place, and the index into the array INTC (or RNTC) is not changed. The number of Q = 1 responses expected is given by the contents of the first element of ICB. If the third element of ICB contains zero, the process is initiated immediately; if it contains a LAM identifier, the process is initiated only when the specified LAM is recognized. The Q responses to the CAMAC functions are not saved. Since the Q response is used by the module to indicate data synchronization, it can carry no other information to the calling program. A malfunction or erroneous operation may produce a situation in which a module will never respond with Q = 1, causing an unending loop. To guard against this case a maximum repetition count of 4096 was implemented in the software. A sample FORTRAN program for transferring CAMAC d a t a words from 4096-channel CAMAC Memory to a FORTRAN real array is given in Example 1 where four CM-024 CAMAC Memory Modules [7] each having data of 1024 channels and a MC-024 CAMAC Memory Control Module [8] from ORTEC are being considered. Example 1. A Sample FORTRAN program showing the block transfer of CAMAC data words from 4096channel CAMAC Memory to a real array in UQC [5] (Repeat) Mode.
where JF IEXT INTC RNTC ICB
C C C C C C C C C C
= function code, = external address, = CAMAC data array (integer array), = CAMAC data array (floating-point array), = control block array.
The functional description of the arguments is given in section 3. The subroutine CFUBR causes the single CAMAC function specified by the contents of JF to be executed at the CAMAC address specified by the contents of IEXT with the usage of the Q response as defined [5,6] for the Repeat Mode. In the Repeat Mode, the CAMAC address is never changed, but the single address is expected to supply or accept many words of data. Q is used as a timing signal. Q = 1 indicates that the previously executed function suc-
27
0001 C C C 0002 0003 C
A FORTRAN PROGRAM FOR TRANSFERRING 4096-CHANNEL CAMAC DATA WORDS FROM FOUR ORTEC CM024 CAMAC MEMORY MODULES TO A FORTRAN REAL ARRAY (RNTC). ORTEC MC024 MEMORY CONTROL MODULE IS BEING USED FOR MEMORY CONTROL AT THE STATION 4. DIMENSION ICB(4), RNTC(4096) DECLARE THE NUMBER OF DATA TO BE TRANSFERRED IN IMMEDIATE TRANSFER MODE DATA ICB/4096,0,0,0/ DATA IB,IC,N,IA 1 ,IA2/1,1,4,0,0/ DECLARE CAMAC ADDRESS FOR CAMAC ADDRESS REGISTER
O. Ciftcioglu / CAMAC subroutines in FORTRAN
28 0004 C C C C C 0005 C C 0006 0007 C C 0008 0009
CALL CDREG(IEXT 1 ,IB,IC,N,IA1) WRITE THE INITIAL ADDRESS TO THE CAMAC ADDRESS REGISTER (8192 CORRESPONDS TO THE FIRST ADDRESS OF THE CAMAC MEMORY) .... CALL CFSA(17 ,IEXT 1,8192.,Q) INITIATE THE BLOCK TRANSFER IN REPEAT MODE CALL CDREG(IEXT2,IB,IC,N,IA2) CALL CFUBR(0,IEXT2,RNTC,ICB) 4096-CHANNEL CAMAC DATA ARE IN ARRAY RNTC CALL EXIT END
2.3.6. Analyze LAM Identifier The FORTRAN form for calling the Analyze LAM Identifier subroutine implemented is CALL CGLAM (LAM, IB, IC, N, M, INTA), where
2.3.8. INCREMENT INCREMENT is not a recommended subroutine to be implemented according to ref. 2. But since the Crate Controller DC-011 contains an additional feature called "Increment Mode Operation" which provides a facility enabling a CAMAC crate to be scanned for data points, the INCREMENT subroutine was implemented to make use of this feature. The FORTRAN form for calling the INCREMENT subroutine is CALL CINC (JF, IEXT), where
LAM IB IC N
= LAM identifier, = branch number, = crate number, = station number, = LAM access identifier, M INTA = integer array. The functional description of the arguments is given in section 3. The subroutine CGLAM decodes the LAM identifier LAM into its component parts, consisting of the branch number IB, the crate number IC, the station N, the subaddress or bit-position M, and the system dependent information INTA. It performs the inverse transformation of CDLAM and all the parameters have the same interpretation and form.
2.3. 7. Analyze Register Identifier The FORTRAN form for calling the Analyze Register Identifier subroutine implemented is CALL CGREG (IEXT, IB, IC, N, I A ) , where IEXT IB IC N IA
The functional description of the arguments is given in section 3. The subroutine CGREG decodes the CAMAC address identifier IEXT into its component parts, consisting of the branch number IB, the crate number IC, the station number N, and the subaddress IA. This subroutine exactly reverses the process performed by CDREG, and all parameters have the same interpretation and form.
= external address, = branch number, = crate number, = station number, = subaddress.
JF = function code, IEXT = externaladdress. The functional description of the arguments is given in section 3. The more general form of CINC is the AddressScan (CFMAD) subroutine which is described in section 2.3.2. It is the recommended version for addressscanning routine and implemented in this work for both generality and compatibility. Nevertheless the .subroutine CINC was implemented in order to make use of the address-scanning feature of DC-011. When the increment bit in the Control Monitor Register (CMR) is set to logical 1, a scanning process starts at a CAMAC address defined by IEXT. Each time that a CAMAC data word is transferred, the subaddress (A) is incremented by 1 until a Q = 0 is received on the CAMAC Dataway Q line in response to a CA_MAC data transfer attempt. Then the station number (N) is incremented by 1, the subaddress (A) is reset to 0, and the scanning process is begun again. Consecutive CAMAC data transfer attempts, that yield Q = 0 result in N being incremented by 1, with A = 0, upon each such attempt. If each of nine consecutive CAMAC data transfer attempts yield Q = 0, the endof-range (EOR) bit is set to logical 1 and the scanning process is stopped. With the A portion having been reset to 0, the N portion of the CAMAC command in
O. Ciftcioglu / CAMAC subroutines in FORTRAN the CMR then contains the address of the next station at which the same type of CAMAC transfer is to be attempted. 2.3.9. Test End-of-Range The FORTRAN form for calling the Test End-ofRange subroutine is CALL CTEOR (IEXT, L ) , where IEXT = external address, L = logical truth value. The functional description of the arguments is given in section 3. The subroutine CTEOR (IEXT, L) checks if the crate being addressed is on-line and sets L to the value ".TRUE." for unsuccesful and ".FALSE." for successful End of the Scanning process initiated by subroutine CINC described in section 2.3.8.
29
The functional description of the arguments is given in section 3. The subroutine CINFL causes twenty-four bit integer-to-floating-point conversion of the CAMAC data words from the integer data array INTC to the real data array RNTC. For each CAMAC data word two 16-bit elements are assigned in both arrays. The number of the CAMAC data word conversions expected is given by the contents of the first element of ICB. Each element of INTC and RNTC has the same form as the CAMAC data word variables INT and RNT described in sections 3.7 and 3.8 respectively. 2.4.2. Floating-Point to Twenty-Four Bit lnteger Conversion The FORTRAN form of the Floating-Point to Twenty-Four Bit Integer Conversion subroutine is CALL CFLIN (RNTC, INTC, ICB), where
2.4. Twenty-four bit conversion routines These conversion routines porform conversions from 24-bit integer to floating-point and from floating-point to 24-bit integer form. The FORTRAN being used may include this type of conversion routines. However such adahoc, routines should, in general, be included to the implementation for the sake of completeness. Since the computer being used is a 16-bit machine, a 24-bit integer CAMAC data word is acommodated in two 16-bit elements which are defined as elements of an array of length 2, say ARRAY. Then bits 1 - 1 6 are stored in ARRAY(2) with bit 1 the lowest and bit 16 the highest. Bits 1 7 - 2 4 are stored in ARRAY(l) with bit 17 in the lowest order position in the word. The upper eight bits of ARRAY(I) are cleared to zero. Functional descriptions of the routines are given in the following section.
RNTC = CAMAC data array (floating-point array), INTC =CAMAC data array (integer array), ICB = control block array. The functional description of the arguments is given in section 3. The subroutine CFLIN causes floating-point-totwenty-four bit integer conversion of the CAMAC data words from the real data array RNTC to the integer data array INTC. For each CAMAC data word two 16-bit elements are designed in both arrays. The number of the CAMAC data word conversions expected is given by the contents of the first element of ICB. Each element of RNTC and INTC has the same form as the CAMAC data word variables INT and RNT described in sections 3.7 and 3.8 respectively.
3. Definition of parameters and implementation notes 2.4.1. Twenty-Four Bit lnteger to Floating-Point Conversion The FORTRAN form of the Twenty-Four Bit Integer to Floating-Point Conversion subroutine is CALL CINFL (INTC, RNTC, ICB), where INTC = CAMAC data array (integer array), RNTC = CAMAC data array (floating-point array), ICB = control block array.
The meaning of the parameters seen as arguments in the subroutines implemented are already mentioned, in a brief form, in the description of the functions performed by the subroutines. Since similar parameters are used in different subroutines, the various symbols involved are defined and discussed more completely in the subsections that follow. In principle, the subroutines are so designed that they have the same functions as defined in ref. 2, and this is also the case for the parameters. Nevertheless the
O. Ciftcioglu / CAMACsubroutines in FORTRAN
30
Committee recommendations and it represent a physical highway number in a multiple highway system. The crate being used was assumed to be in the branch number 1.
definition and discussion of the parameters are described here for the sake of clarity and completness of the description of the subroutines implemented. This information can also be interpreted as a confirmation of the compatibility between the subroutines implemented in this work and subroutines recommended by ESONE Committee [2].
3.3. IC (crate number) The symbol IC represents an integer which is the crate number component of a CAMAC address. "Crate Number", in this particular implementation, is interpreted as a physical crate number in a Multiple Crate System.
3.1.1EXT {external address) The symbol IEXT represents an integer which is used as an identifier of an external CAMAC address. The address may represent a register which can be read or written, a complete CAMAC address which can be accessed by control or test function, or a crate address. The value of IEXT is explicitly defined to be an integer. It is an encoded version of the address components according to the protocol shown in fig. 1.
3.4. N (station number) The symbol N represents an integer which is the station number component of a CAMAC address.
3.5. IA (subaddress) The symbol IA represents an integer which is the subaddress component of a CAMAC address.
3.2. IB (branch number) The symbol IB represents an integer which is the branch number component of a CAMAC address. Although, in this particular implementation the branch was not used, it is included in the parameter list for generality and compatibility with the ESONE
3.6. JF (function code) The symbol JF represents an integer which is the function code for a CAMAC action.
C A M A C C R A T E F ............................ I I I
~HP-3720A
>-
SPECTRUM I DISPLAY I HP - 3721A I CORRELATORI
I
D
1 <
HP-3722A l NOISE GENERATOR]
<:::
. . . . . . -IORTEC DC-011II CRATE I [CONTROLLER l PDP
11
U
N
I
B
U
S
I I I l 1
1.
INTERFACE I
Fig. 2. Basic scheme of the analog computer system connected to the digital computer through the CAMAC interface.
o. ciftcioglu / CAMAC subroutines in FOR TRAN 3. 7. I N T (CAMA C data word) The symbol INT represents a 24-bit CAMAC data word stored in computer memory. Since the computer being used is a 16-bit machine which does not have an addressable unit of storage which can contain twenty four bits, the CAMAC data word is contained in the integer format in two 16-bit computer words called low order and high order element. Therefore the symbol INT represent an integer array containing a CAMAC data word. The array has two elements. The CAMAC word is so placed that the element with the highest index is filled with the lowest order bits of the data word and any bits not required to contain data are at the highest order positions of the element with the lowest index. Hence, bit 1 is the lowest order bit in the high numbered element. All the bits in the high numbered element are filled and the remaining bits are stored beginning in the lowest order bit of the preceding low numbered element.
3.8. R N T {CAMAC data word) The symbol RNT represents a 24-bit CAMAC data word stored in computer memory. Since the computer being used is a 16-bit machine which does not have an addressable unit of storage which can contain twenty four bits, the CAMAC data word is contained in the floating-point format occupying two 16-bit computer words. The CAMAC data word RNT provides an alternative way which is more practical at the cost of somewhat slower execution compared to the implementation with the integer array INT, for using the subroutine CFGA. The following are two FORTRAN programs which read a CAMAC data word from a CAMAC address and write it at the output.
Example 2. A FORTRAN program to read a CAMAC data word from a CAMAC address and write it at the output unit.
0001 0002 0003 0004 0005
C A FORTRAN PROGRAM TO READ A C CAMAC DATA WORD FROM C A CAMAC ADDRESS DATA IB,IC,N,IA/1,1,17,1/ C DECLARE CAMAC ADDRESS CALL CDREG(IEXT,IB,IC,N,IA) CALL CCCZ(IEXT) CALL CCCC(IEXT) C INHIBIT RESET CALL CCCI(IEXT,0)
0006
0007 0008 0009 0010
31
C READ A CAMAC DATA WORD IN C FLOATING-POINT FORMAT CALL CFSA(0,IEXT,RNT,Q) C TYPE THE CAMAC DATA WORD C ALREADY READ WRITE(7,10) RNT 10 FORMAT(1X,F 10.0) CALL EXIT END
Example 3. A FORTRAN program to read a CAMAC data word from a CAMAC address and write it at the output unit.
0001 0002 0003 0004 0005 0006 0007
0008
0009 0010 0011 0012 0013
C A FORTRAN PROGRAM TO READ A C CAMAC DATA WORD FROM C A CAMAC ADDRESS DIMENSION INT(2), ICB(4) C DECLARE CAMAC ADDRESS DATA IB,IC,N,IA/1,1,17,1 / DATA ICB/1,0,0,0/ CALL CDREG(IEXT,IB,IC,N,IA) CALL CCCZ(IEXT) CALL CCCC(IEXT) C INHIBIT RESET CALL CCCI(IEXT,0) C READ A CAMAC DATA WORD IN 24-BIT C INTEGER FORMAT CALL CFSA(4,IEXT.INT,0) C TYPE THE CAMAC DATA WORD C ALREADY READ CALL CINFL(INT,RNT,ICB) WRITE(7,10) RNT 10 FORMAT(IX,F10.0) CALL EXIT END
In Example 3, the subroutine CINFL is executed for 24-bit integer to floating-point conversion. Although most FORTRANs provide facilities for this type and reverse conversion, the subroutines CINFL and CFLIN are to be included to the software for completeness. In Example 3, if the CAMAC data word INT is to be used in another CAMAC subroutine, the conversion by CINFL is not necessary and this speeds up the execution. However in Example 2, if the CAMAC data word RNT is to be used in another CAMAC subroutine, two internal conversions, i.e., 24-bit integer to floating-point and floating point to 24-bit integer conversion, are necessary which slow down the execution. Mention may also be made of the different func-
32
O. Ciftcioglu / CAMAC subroutines in FOR TRAN
tion codes used in the subroutine CFSA in Examples 2 and 3. For Write command, the implicit declaration of the type of CAMAC data word variable, i.e. INT or RNT explicitly defines the subroutine to be used, i.e. CFSA (16, IEXT, INT, Q) or CFSA (16, IEXT, RNT, Q) respectively where the function code 16 explicity defines the 24-bit CAMAC write operation. However for read operation one has to define the type of read operation in advance. For this purpose function code 0 is used for the 24-bit CAMAC read operation in the floating-point format and function code 4 is used for the 24-bit CAMAC read operation in the 24-bit integer format. 3.9. Q (Q response) The symbol Q represents a logical truth value which corresponds to the CAMAC Q response. It is set to ".TRUE." if the Q response is 1, to ".FALSE." if the Q response is 0. 3.10. L (logical truth value) The symbol L represents a logical truth value which can be either ".TRUE." or ".FALSE.". 3.11. L A M (LAM identifier) The symbol LAM represents an integer which is used as the identifier of a CAMAC LAM signal. The information associated with the identifier include not only the CAMAC address but also information about the means of accessing and controlling the LAM. The value of LAM is explicitly defined to be a non-zero integer; it is an encoded representation of the information required to describe the LAM. The value 0 is used to indicate that no LAM is being specified. 3.11.i. Look-at-me structure and interrupt handling A typical DC-011 address is address 76WXYZs, where W is 4, 5, 6, or 7, X and Y are each any num-
Table 1 Address assignments of registers in the DC-011. Address
Register
76 WXYOs 761#XYZ 8 76WXY48 76WXY6a
Control Monitor Register (CMR) Data Low Register (DLOR) Data/LAMHigh Register (DLHR) LAM Low Register (LLR)
ber from 0 through 7 and Z is 0, 2, 4 or 6. Each value of Z, together with the predetermined 7, 6, W, X and Y, forms an address of a different register within DC-011. The register assignments are shown in table 1. The CMR is a read/write register that holds the F, N and A components of the CAMAC command, together with control information on data transfers and that also holds system status information for monitoring purposes. The DLOR is used for transferring the low order 16-bits of the data word to and from the CAMAC system. The DLHR contains the 8 high-order data bits and the 7 high-order LAM bits [L(23) through L(17)] during a read instruction. During a write instruction, bits 8 through 15 are ignored. LLR is a read-only buffer. It contains the current low-order 16-bit LAM line pattern [L(16) through L(1)]. Write transfers to this register are acknowledged and then ignored. The DC-011 contains a computer interrupt enable/ disable latch that is controlled by the CAIVlAC F(26) • N(30) • A(10) command to enable the latch and by the CAMAC F(24)" N(30). A(10) command to disable the latch. In the DC-011, only a true look-at-me (LAM) signal on one or more of the CAMAC Dataway L lines can cause a computer interrupt. If the latch is set so that the interrupt is enabled and if one or more CAMAC Dataway L lines have true LAM signals, a computer interrupt signal will be generated only if the computer central processor unit priority level is lower than the assigned priority level of the DC-011 and if no other item of peripheral equipment operating at a higher priority level has asserted mastery of the UNIBUS. The logical OR of the CAMAC Dataway L lines is introduced into the CMR for interrupt. When the DC-011 interrupt signal has been acknowledged, the computer automatically jumps to one of the individual interrupt service routines defined by the true LAIVl signal having the highest priority in the LAM registers. The CAMAC handler for interrupt implemented in this work is so designed that each crate has an interrupt vector and it is loaded with the address of the relevant handier routine. Whenever an interrupt occurs, the interrupt handler will read the LAM priority register of the DC-011 which generated the interrupt and identify which station produced the LAM by reading the LAM pattern in the DLHR and the LLR with a computer bit test instruction. Thereafter
O. Ciftcioglu / CAMACsubroutines in FORTRAN the handler will jump to the entry point having the symbol as LAXYZZ, where X = integer from 0 to 7 indicating branch number, Y = integer from 0 to 7 indicating crate number, ZZ = two digit decimal number from 1 to 23 indicating station number with the designated crate. The relevant program is then executed by the routine. If no entry point exists under the designated symbol, an error message is delivered at the terminal. 3.12. M (LAM access specifier) The symbol M represents an integer which is used to indicate the mode of access of a LAM and the lowest-order address component for LAM addressing. If M is zero or positive, it is interpreted as a subaddress and the LAM is assumed to be accessed via dataless functions at this subaddress. If M is negative, it is interpreted as the negative of a bit position for a LAM which is accessed via setting or clearing bits in the group 2 registers at subaddress 12, 13, or 14.
3.13. INTA (integer array) Originally INTA represents an integer array and it is so defined that the information contained in the array INTA is completely implementation-dependent. In this particular implementation, the array has only one element having the function code information which might be required by a particular module to be used for a LAM operation.
3.14. JFA (function code) The symbol JFA represents an array of integers, each of which is the function code for a CA_MAC action. The length of JFA is given by the value of the first element of ICB (control block) at the time the subroutine is executed.
3.15. 1EXTA ( CAMA C external address) The symbol IEXTA represents an array of integers, each of which is used as an identifier of an external CAMAC address. The address may represent a CAMAC register which can be read or written, a complete CAMAC address which can be accessed by con-
33
trol or test functions, or a crate address. The value of each element of IEXTA is explicitly defined to be an integer and it uniquely defines the specified CAMAC register and crate for other subroutines in the implementation. The coding protocol for the address components is shown in fig. 1.
3.16. INTC {CAMAC data array) The symbol INTC represents an integer array of CAMAC data words. However since the computer being used is a 16-bit machine which does not have an addressable unit of storage which can contain twenty-four bits, each CAMAC data word is contained in an integral number of elements (a "block") sufficiently large to contain twenty-four bits i.e. two 16-bit computer words called low-order and order element. The length of the array must be great enough to include a block for each CAMAC data word transferred. Each CAMAC data word is positioned Within its block so that the element within the block with the highest index is t'dled with the lowest order bits of the data word, any bits not required to contain data are at the highest order positions of the element with the lowest index. In other words, the bits of a CAMAC data word are stored in the array elements such that bit 1 is the lowest order bit in the high numbered element. All the bits in the high numbered element are filled and the remaining bits are stored beginning in the lowest order bit of the preceding low numbered element. The next CAMAC data word is placed in the same way into the text two higher numbered (low-order and high-order) elements, etc. Thus, for instance, should a block consist of elemnts n and n + 1, element n contains CAMAC bits 24 through 17 in its low-eight bits and element n + 1 contains bits 16 through I. The length of INTC is given by the value of the first element of ICB (control block).
3.17. RNTC (CAMAC data array) The symbol RNTC represents a floating-point array of CAMAC data word each of which occupies two 16-bit words (a "block")in the computer memory. The length of the array must be great enough to include a block transfer for each CAMAC data word transferred. The internal reference RNTC, unless all functions in the array JFA are control or test functions, which use no data, must be able to contain a CAMAC data word for each function executed. In
O. ciftcioglu / CAMAC subroutines in FOR TRAN
34
order to maintain the positional correspondence between values in JFA, IEXTA, RNTC and QA, a position in RNTC is skipped whenever a control or test function is executed. The length of RNTC is given by the value of the first element of ICB (control block). The array RNTC provides another way of using the subroutine CFGA which is more practical at the cost of somewhat slower execution compared to the implementation with the integer array INTC.
3.18. QA (Q responses) The symbol QA represents an array of Q response values. Each element of QA represents a logical truth value which corresponds to the CAMAC Q response. It is set to ".TRUE." if the Q response is 1, to ".FALSE." if the Q response is 0. The length of QA is given by the value of the first element of ICB at the time the subroutine is executed.
3.19. ICB {control block) The symbol ICB represents an integer array having four elements. The contents of these elements are: element element element element
1 : repeat count, 2: tally, 3: LAM identification, 4: channel identification.
as described earlier (see section 2.3).
each element is explicitly defined to be an integer. It is an encoded version of the address components according to the protocol shown in fig. 1.
4. Concluding remarks CAMAC subroutines to be used in FORTRAN were implemented according to the relevant recommendation of the ESONE Committee. By means of the block transfer subroutines, rapid data handling and real-time data acquisition facilities with CAMAC were brought to the FORTRAN evnironment for the purpose of laboratory automation, data handling and data acquisition. One of the ample uses of the subroutines in our laboratory is due to handling the data from Ge(Li) gamma detector in connection with the computer based Gamma Spectroscopy System [9]. The subroutines are also going to be used for handhng the data obtained from the EAI 180 analog computer which is being used together with the HP * 3720A Correlator, HP3721A Spectrum Display for nuclear reactor noise analysis and it is intended to be connected to the digital computer system through the CAMAC interface. The block scheme of the system, present in our laboratory, is shown in fig. 2. The author wishes to express his deep appreciation to Prof. A. Dalfes, Head of the Department of Nuclear Power, for his continuous support and encouragement throughout the work.
3.20. IEXTB (external address) References The symbol IEXTB represents an array of integers containing external CAMAC addresses. The array has two elements; the first contains the starting address for an Address Scan multiple action. The second contains the final address which can be permitted to participate in the Address Scan sequence. Each element represents an integer which is used as an identifier of an external CAMAC address. The address may represent a register which can be read or written, a complete CAMAC address which can be accessed by control or test functions, or a crate address. The value of
[1] O. Ciftcioglu, Nucl. Instr. and Meth. 166 (1979). [2] Subroutines for CAMAC, ESONE Committee, ESONE SR]01 (September 1978). [3] DC-011 CAMAC Crate Controller, EG & G/Ortec (1974). [4] EUTATOM Report EUR 4600e (1972). [5] EURATOM Report EUR 4100e-Suppl. (1977). [61 EURATOM Report EUR 4100e (1972). [7] CM-024 CAMAC Memory Module, EG & G/Ortec (1976). [8] MC-024 CAMAC Memory Control, EG &G/Ortec (1976). [9] O. Ciftcioglu,Nucl. Instr. and Meth., this issue, p. 209.
* Trade Mark (Hewlett-Packard).