$SYSPROG$

PROGRAM isrtest(INPUT,OUTPUT);

$SEARCH 'GPIO5'$      {Or wherever it's hidden}

IMPORT iodeclarations, general_0, general_1, gpio_5;

VAR i, count, dummy: INTEGER;

PROCEDURE myproc(temp: INTEGER);
BEGIN
  writeln('           ISR');
  TRY
    i := ioread_word(12,4);      {The SDG specifies sc 15 -- we use 12}
    writeln('               ',i:6);
    count := count-1;
    if count > 0 then
     iowrite_byte(12,0,0)       {start next handshake}
    else
     off_flag(12);              {finished, so turn off interrupt}
  RECOVER
   writeln('             ISR ESCAPE!');
END; {PROCEDURE myproc}

BEGIN
  i     := -1;                  {set i to known value}
  count := 10;                  {input 10 data words from GPIO card}
  set_timeout(12,1.0);
  dummy := ioread_word(12,4);    {set I/O direction to "input"}
  iowrite_byte(12,0,0);         {start first handshake with peripheral}
  on_flag(12,myproc,0);
  WHILE count > 0 DO
   WRITELN('Waiting....',i:6)
END.
