/*;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;  Copyright (c) 1995-1999, ADLink Technology Inc.  All rights reserved.  ;;
;;                                                                         ;;
;;      File Name   :   7300BINT.C                                          ;;
;;      Purpose     :   This sample program demonstrates how to DIO through;;
;;                      interrupt operation                                ;;
;;      Date        :   07/07/1999                                         ;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;*/
 #include <stdio.h>
 #include <unistd.h>
 #include "dask.h"

I16 card=-1, card_number = 0;
int int2_count = 0;
int total_count =4000;
int sample_rate=1000;
int c1=20, c2=100;

void sig_handler2(int signo)
{
    if(int2_count < total_count) {
       int2_count++;
    }else if( int2_count == total_count ){
     // reset the Timer to stop generate INT2
       DIO_7300SetInterrupt (card, 0, 0, NULL, NULL);
       CTR_Setup (card, 2, RATE_GENERATOR, 0, BIN);
       printf("\n\n INT2 Count:%d \n\n\n",int2_count );
       int2_count++;
   }

   return;
}


int main(void)
{
    int err;

    setbuf( stdout, NULL );

    printf("PCI-7300B Interrupt Samples (INT2)\n");
    printf("The INT2 is used, and interrupt signals are generated by internal Timer Output.\n");

    int2_count = 0;

    if ((card=Register_Card(PCI_7300A_RevB, card_number))< 0) {
      printf ("Can't open device file: PCI7300B\n");
      exit(-1);
    }

    DIO_7300SetInterrupt (card, 0, 1, NULL, sig_handler2);
    c2=10000000/(sample_rate);
    // setup the Timer clock
    err = CTR_Setup (card, 2, 2, c2, BIN);
    if( err != NoError ){
       printf(" error from CTR_Setup : %d \n" , err );
       goto end_of_proc;
    }
    printf("**The INT2 Singal will be sent back in 4 secs, or you can press ENTER for exit**\n");
    getchar();

    if( int2_count < total_count ){
       CTR_Setup (card, 2, RATE_GENERATOR, 0, BIN);
       goto end_of_proc;
    }

end_of_proc:
    DIO_7300SetInterrupt (card, 0, 0, NULL, NULL);
exit_after_error:
    if (card >= 0) Release_Card(card);

    return (0);
}















