Using #INCLUDE in CASLAN

The CASLAN language allows for the use of include files (referencing CASLAN code contained in other files that are to be included in the CASLAN program of interest).

The following example illustrates this principle:

Group
  gRamAddr/D      U1:PB01_09/O;
Proc P;   -- 
 begin
  gRamAddr := 0; 
 DrShift;
  gRamAddr := 1;
 DrShift;
end;
Proc PParam( Param : ref); --- using ref as parameter type allows the use of Group names
 begin
   Param := 0;
  DrShift; 
   Writeln(gRamAddr);  -- to verify that setting Param modifies the value of gRamAddr
   Param := 1;
  DrShift;
   Writeln(gRamAddr); 
 end;
Group
  grp/D      U1:PB01_09/O
begin
 call P;
 PParam(gRamAddr);
 PParam(Grp);
end.
Instead of having all this code written into a single CASLAN file, one could move the two procedures into one or two separate files and include these into the main program:
Include file "ExampleInclude.cas", stored in the system include folder or in the UUT's include folder:
Proc P;   -- directly manipulating group values
 begin
   gRamAddr := 0;
  DrShift;
   gRamAddr := 1;
  DrShift;
 end;
Proc PParam( Param : ref); --- using ref as parameter type allows the use of Group names
 begin   -- indirectly manipulating group values
   Param := 0;
  DrShift; 
  Writeln(gRamAddr);  -- to verify that setting Param modifies the value of gRamAddr
   Param := 1;
  DrShift;
  Writeln(gRamAddr); 
 end;<br>
	
Main program:
Group
  gRamAddr/D  U1:PB01_09/O;
  grp/D       U1:PB01_09/O;
#INCLUDE 'ExampleInclude.cas'; -- referencing include file
begin
 call P;            -- procedure is defined in the include file
 PParam(gRamAddr);  -- procedure is defined in the include file
 PParam(Grp);       -- procedure is defined in the include file
end.<br>
	
A more useful example is the test of clock signals. The following include file defines a couple of simple test routines for verifying a clock signal with a boundary-scan pin.
Include file "clock_test.cas":
VAR
  vLowAndHigh :   2;
  iLowCnt     : INT;
  iHighCnt    : INT;
PROC pCLK_test_and_DutyCycle(vRepeat: INT; fTest: INT; fDC: INT);
 BEGIN
-- Measurements
  LOOP vRepeat DO
    DRSHIFT;
    SWITCH (gINPUT_CLK/M)
      CASE 0: iLowCnt := iLowCnt +1;
      CASE 1: iHighCnt := iHighCnt +1;
    END;
  END;
 if fTest == 1 then
  -- Evaluation of measurements
  IF iLowCnt == 0 THEN
     WRITELN(' --> "Stuck-at-HIGH" --> FAIL');
     iError := 300;
  END;
  IF iHighCnt == 0 THEN
    WRITELN(' --> "Stuck-at-LOW" --> FAIL');
     iError := 310;
  END;
 end;
 if fDC == 1 then
  -- duty cycle test, +/- 10%
  WRITE ('   Duty cycle LOW : HIGH = ', iLowCnt, ' : ',iHighCnt);
  IF iLowCnt < ((vRepeat / 2) - (vRepeat / 20)) THEN
     WRITE('  --> duty cycle low --> FAIL');
    iError := 320;
  END;
  IF iHighCnt < ((vRepeat / 2) - (vRepeat / 20)) THEN
     WRITE('  --> duty cycle high --> FAIL');
     iError := 330;
  END;
  WRITELN;
 end;
  WRITELN;
 END;
PROC pClockTest(vCnt: int);
 begin
vLowAndHigh := 0;
   -- capturing clock signal (reading vCnt times)
loop vCnt do
  DRSHIFT;
      SWITCH (gINPUT_CLK/M)
         CASE 0: WRITE('0');
                 vLowAndHigh := vLowAndHigh | 10b;
         CASE 1: WRITE('1');
                 vLowAndHigh := vLowAndHigh | 01b;
      END;
   END;
   -- Evaluation of the measurements
   SWITCH (vLowAndHigh)
      CASE 01b: WRITELN(' -> "Stuck at HIGH -> FAIL!');
                iError := 401;
      CASE 10b: WRITELN(' -> "Stuck at LOW -> FAIL!');
                iError := 402;
      CASE 11b: WRITELN(' -> PASS');
   END;
 END;<br>
	
Main program calling the include file:
-- -------------------------------------------------------------------------------
--
-- Caslan File (*.CAS)
--
-- Name      : Clock Test.CAS
-- Date      : 6/24/2015
-- Author    : HE
--
-- -------------------------------------------------------------------------------
-- Checking existence of the following clock signals:
--
-- CLK_100_main U1.12
--
-- -------------------------------------------------------------------------------
-- Version     Date        Change
-- 1.0         6/24/2015  Creation
-- 
-- -------------------------------------------------------------------------------
PROGRAM 'Test_Clock';
#TCR (U1: #12, 
      U6: #5,
      R15:#1, #2
     );
GROUP                         
 gINPUT_CLK   U1:#12/I;  -- <----------------------------- specify correct BScan pin
VAR                                 
 iError      : INT;
CONST
 cRepeat     := 1000;  -- <----- adjust number of repeats, if desired (for pCLK_test_and_DutyCycle)
 cNumberOf   := 50;    -- <----- adjust number of reads, if desired (for pClockTest)
#INCLUDE 'clock_test.cas';
PROC pSetup();
 begin
 iError := 0;
   LDI U1, SAMPLE;  -- <---------- specify correct BScan device 
   IRSHIFT;
 end;
BEGIN
  pSetup();
  WRITELN;
  WRITELN('  Verifying presence and duty cycle of clock signal CLK_100_main on U1 pin 12:');   -- <--------- modify string according to the tested clock signal
  WRITELN;
  WRITE  ('   ');
  pClockTest(cNumberOf); 
  pCLK_test_and_DutyCycle(cRepeat, 0, 1); -- number of captures, test for presence (1 = yes), test duty cycle (1 = yes)
  STOP iError;
END.
	
For more information on CASLAN in general and on Include files in particular, please refer to the SYSTEM CASCON Reference Manual.