void acromagSetup(int ip470BoardLocation, char *ip470carrier)
{

  long addr=0;
  
  /* Check for Carrier Library */
  if(InitCarrierLib() != S_OK) {
    printf("\nCarrier library failure");
    exit(1);
  }
  
  /* Connect to Carrier */
//  if(CarrierOpenDev(0, &carrierHandle, ip470carrier) != S_OK) {
  //    printf("\nUnable to Open instance of carrier.\n");
//    exit(2);
//  }
 if(CarrierOpen(0, &carrierHandle) != S_OK) {
     printf("\nUnable to Open instance of carrier.\n");
   exit(2);
 }

  cblk_470.nHandle = carrierHandle;
  
  switch (ip470BoardLocation) {
      case 0: cblk_470.slotLetter='A'; break;
      case 1: cblk_470.slotLetter='B'; break;
      case 2: cblk_470.slotLetter='C'; break;
      case 3: cblk_470.slotLetter='D'; break;
      default: 
	  printf("No idea what board %d is.\n",ip470BoardLocation);
	  exit(3);
  }
  printf("Inititalizing IP470 in slot %c\n",cblk_470.slotLetter); 


  if(CarrierInitialize(carrierHandle) == S_OK) 
    { /* Initialize Carrier */
      SetInterruptLevel(carrierHandle, INTERRUPT_LEVEL);
      /* Set carrier interrupt level */
    } 
  else 
    {
      printf("\nUnable initialize the carrier %lX", addr);
      exit(3);
    }


  cblk_470.bCarrier=TRUE;

  /* GetCarrierAddress(carrierHandle, &addr);
     SetCarrierAddress(carrierHandle, addr); */

  if(GetIpackAddress(carrierHandle,cblk_470.slotLetter,
		     (long *) &cblk_470.brd_ptr) != S_OK)
    {
      printf("\nIpack address failure for IP470\n.");
      exit(6);
    }
  cblk_470.bInitialized = TRUE;
}
int main()
{
    

/*
    DECLARE LOCAL DATA AREAS:
*/

    char cmd_buff[40];   /* command line input buffer */
    long item;           /* menu item selection variable */
    long status;         /* returned status of driver routines */
    long hstatus;        /* interrupt handler returned status */
    unsigned finished;   /* flag to exit program */
    long addr;           /* long to hold board address */
    long flag;           /* general flag for exiting loops */
    long i;              /* loop index */
    unsigned point;      /* I/O point number */
    unsigned port;       /* I/O port number */
    unsigned val;        /* value of port or point */
    int hflag;           /* interrupt handler installed flag */
    struct sblk1k100 s_block; /* allocate status param. blk */
    struct cblk1k100 c_block; /* configuration block */
    struct handler_data hdata;/* interrupt handler data structure */
    int pld_flag;        /* PLD in config mode = 0, in user mode = 1 */
/*
    ENTRY POINT OF ROUTINE:
    INITIALIZATION
*/
 
    pld_flag = 0;     /* PLD in config mode = 0 */
    flag = 0;         /* indicate board address not yet assigned */
    finished = 0;     /* indicate not finished with program */
    hflag = 0;        /* indicate interrupt handler not installed yet */
    hstatus = 0;

/*
    Initialize the Configuration Parameter Block to default values.
*/

    memset( &c_block, 0, sizeof(struct cblk1k100));

    c_block.vector = VECTOR;       /* interrupt vector */
    c_block.bCarrier = FALSE;      /* indicate no carrier initialized and set up yet */
    c_block.bInitialized = FALSE;  /* indicate not ready to talk to IP */
    c_block.slotLetter = SLOT_A;

    s_block.model = 0;             /* model unselected */
    s_block.direction = 0;         /* direction */
    s_block.int_status = 0;        /* pending interrupts to clear */
    s_block.enable = 0;            /* interrupt enable (per bit) */
    s_block.polarity = 0;          /* interrupt polarity */
    s_block.type = 0;              /* interrupt type */
    s_block.vector = 0;

    hdata.h_pid = getpid();    /* save it in the interrupt handler data structure */
    hdata.hd_ptr = (char *)&c_block;/* put in address of c_block structure also */
    c_block.sblk_ptr = (struct sblk1k100*)&s_block;

/*
	Initialize the Carrier library
*/
    if(InitCarrierLib() != S_OK)
    {
	printf("\nUnable to initialize the carrier library. Exiting program.\n");
	exit(0);
    }

/*
	Open an instance of a carrier device 
*/
    if(CarrierOpen(0, &c_block.nHandle) != S_OK)
    {
	printf("\nUnable to Open instance of carrier.\n");
	finished = 1;	 /* indicate finished with program */
    }
    else
	flag = 1;

/*
    Enter main loop
*/      

    while(!finished) {

	printf("\n\nIP1k100 Library Demonstration  Version A\n\n");
        printf(" 1. Exit this Program\n");
	printf(" 2. Set Carrier Base Address\n");
	printf(" 3. Set IP Slot Letter\n");
  	printf(" 4. PLD Configuration\n");
  	printf(" 5. Set Up Configuration Block Parameters\n");
	printf(" 6. Configure Board Command\n");
	printf(" 7. Read Status Command and ID\n");
	printf(" 8. N/A\n");
	printf(" 9. N/A\n");
	printf("10. Read Input Point\n");
	printf("11. Read Input Port\n");
	printf("12. Write Output Point\n");
	printf("13. Write Output Port\n");

	printf("\nSelect: ");
	scanf("%ld",&item);

    if( ( item == 6 || item > 7) && pld_flag == 0 ) /* still in configuration mode */
	{
           printf("Please Configure PLD Now.\n");
           item = 0;
	}
/*
    perform the menu item selected.
*/  
	switch(item) {

	case 1: /* exit program command */

	    printf("Exit program(y/n)?: ");
	    scanf("%s",cmd_buff);
	    if( cmd_buff[0] == 'y' || cmd_buff[0] == 'Y' )
		finished++;
	    break;
	
	case 2: /* set board address command */
	    do 
	    {
		if(flag == 0)
		{
		  printf("\n\nenter base address of carrier board in hex: ");
		  scanf("%lx",&addr);
		  /* Set Carrier Address for Open Carrier Device */
		  SetCarrierAddress(c_block.nHandle, addr);	/* Set Carrier Address */
		}
		GetCarrierAddress(c_block.nHandle, &addr);	/* Read back carrier address */
		printf("address: %lX\n",addr);
		printf("is this value correct(y/n)?: ");
		scanf("%s",cmd_buff);
		if( cmd_buff[0] == 'y' || cmd_buff[0] == 'Y' )
		{
                  SetCarrierAddress(c_block.nHandle, addr);	/* Set Carrier Address */
		  if(CarrierInitialize(c_block.nHandle) == S_OK)/* Initialize Carrier */
		  {
		        c_block.bCarrier = TRUE;
			SetInterruptLevel(c_block.nHandle, INTERRUPT_LEVEL);/* Set carrier interrupt level */
		  }
		  flag = 1;
		}
		else
		  flag = 0;

				
	    }while( cmd_buff[0] != 'y' && cmd_buff[0] != 'Y' );
	    break;

	case 3: /* set IP Slot Letter */
		if(flag == 0 || c_block.bCarrier == FALSE)
			printf("\n>>> ERROR: BOARD ADDRESS NOT SET <<<\n");
		else
		{
			printf("\n\nEnter IP slot letter (A, B etc...): ");
			scanf("%s",cmd_buff);
			cmd_buff[0] = toupper(cmd_buff[0]);
			if(cmd_buff[0] < 'A' || cmd_buff[0] > GetLastSlotLetter())
			{
				printf("\nInvalid Slot Letter!\n");
				c_block.bCarrier = FALSE;
			}
			else
			{
				c_block.slotLetter = cmd_buff[0];
																					
/*
	Get the IPACK's base address based on the Slot letter,
        and initialize the IPACK's data structure with the returned address
*/
				if(GetIpackAddress(c_block.nHandle, c_block.slotLetter, &addr) != S_OK)
				{
					printf("\nUnable to Get Ipack Address.\n");
					c_block.bInitialized = FALSE;
				}
				else	              
				{	
			                c_block.brd_ptr = (struct map1k100 *)addr;
					c_block.bInitialized = TRUE;
				}
			}
		}
	break;

	case 4: /* PLD configuration */

	    if( PLDConfig1k100( &c_block) == 0)
            pld_flag = 1;			/* PLD in user mode = 1 */

		break;

	case 5: /* set up configuration block parameters */

	    scfg1k100(&c_block);
	    break;

	case 6:     /* configure board command */
	
            if(!c_block.bInitialized)
		printf("\n>>> ERROR: BOARD ADDRESS NOT SET <<<\n");
	    else
	    {
/*
    Check for pending interrupts and check the
    "interrupt handler attached" flag.  If interrupts are pending or
    if interrupt handlers are not attached, then print an error message.
    If both conditions were false, then go ahead and execute the command.
*/

		if( input_word( c_block.nHandle, (word*)&c_block.brd_ptr->sts_reg ) && 0x00FF )
		      printf(">>> ERROR: INTERRUPTS ARE PENDING <<<\n");
		else
		{
		   if( hflag == 0 && ( c_block.enable ))
			printf(">>> ERROR: INTERRUPT HANDLER NOT ATTACHED <<<\n");
		   else
		        cnfg1k100(&c_block); /* configure the board */
		}
	    }
	    break;

	case 7:     /* read board status command */
	
            if(!c_block.bInitialized)
		printf("\n>>> ERROR: BOARD ADDRESS NOT SET <<<\n");
	    else
		psts1k100(&c_block); /* read board status */
	    break;

	case 8:     /* attach exception handler */

            break;

	case 9: /* detach exception handlers */
		hflag = 0;
		DisableInterrupts(c_block.nHandle);
	 break;

	case 10: /* Read Digital Input Point */

            if(!c_block.bInitialized)
		printf("\n>>> ERROR: BOARD ADDRESS NOT SET <<<\n");
	    else
	    {
		printf("\nEnter Input port number   (0 - 2): ");
		scanf("%d",&port);
		printf("\nEnter Input point number (0 - 15): ");
		scanf("%d",&point);
		status = rpnt1k100(&c_block,port,point);
		if(status == -1)
		    printf("\n>>> ERROR: PARAMETER OUT OF RANGE <<<\n");
		else
		    printf("\nValue of port %d point %d: %lX\n",port,point,status);
	    }
	    break;

	case 11: /* Read Digital Input Port */

            if(!c_block.bInitialized)
		printf("\n>>> ERROR: BOARD ADDRESS NOT SET <<<\n");
	    else
	    {
		printf("\nEnter Input port number  (0 - 2):  ");
		scanf("%d",&port);
		status = rprt1k100(&c_block,port);
		if(status == -1)
		    printf("\n>>> ERROR: PARAMETER OUT OF RANGE <<<\n");
		else
		    printf("\nValue of port %d: %lX\n",port,status);
	    }
	    break;


	case 12: /* Write Digital Point */

            if(!c_block.bInitialized)
		printf("\n>>> ERROR: BOARD ADDRESS NOT SET <<<\n");
	    else
	    {
		printf("\nEnter Output port number (0 - 2):  ");
		scanf("%d",&port);
		printf("\nEnter I/O point number  (0 - 15): ");
		scanf("%d",&point);
		printf("\nEnter point value (0 - 1): ");
		scanf("%x",&val);
		status = wpnt1k100(&c_block,port,point,val);
		if(status == -1)
		    printf("\n>>> ERROR: PARAMETER OUT OF RANGE <<<\n");
	    }
	    break;

	case 13: /* Write Digital Port */

            if(!c_block.bInitialized)
		printf("\n>>> ERROR: BOARD ADDRESS NOT SET <<<\n");
	    else
	    {
		printf("\nEnter Output port number (0 - 2):  ");
		scanf("%d",&port);
		printf("\nEnter output value in hex (0000 - FFFF): ");
		scanf("%x",&val);
		status = wprt1k100(&c_block,port,val);
		if(status == -1)
		    printf("\n>>> ERROR: PARAMETER OUT OF RANGE <<<\n");
	    }
	    break;

		case 0:  /* The following is an example of how to address the memory space on an IP module. */
		ip_mem_ram_test(&c_block);
	    break;

	}   /* end of switch */
    }   /* end of while */

/*
    disable interrupts from IP module
*/
    if(pld_flag)            		/* PLD was configured */
    {
      c_block.param = 0xFFFF;		/* parameter mask */
      c_block.int_status = 0xff;        /* pending interrupts to clear */
      c_block.enable = 0;               /* interrupt enable (per bit) */
      cnfg1k100(&c_block);		/* configure the board */
    }


    DisableInterrupts(c_block.nHandle);
    if(c_block.bCarrier)
	CarrierClose(c_block.nHandle);

    printf("\nEXIT PROGRAM\n");

}   /* end of main */
Example #3
0
int main()
{


/*
    DECLARE LOCAL DATA AREAS:
*/

    char cmd_buff[80];		/* command line input buffer */
    unsigned finished, finished1; /* flag to exit program */
    int hstatus;		/* returned status of routines */
    int item;			/* menu item selection variable */
    float ideal_volt_span;	/* storage span info */
    float f_data;
    long addr;			/* board address */
    int flag;			/* general flag for exiting loops */
    int i,j;			/* loop index */
    int temp;
    struct conf_blk c_block;	/* configuration block */
    int hflag;                  /* interrupt handler installed flag */
    struct handler_data hdata;  /* interrupt data structure (see exception.h) */
    float fb[MAXSIZE];		/* storage buffer for floats */
    float fs, zs, slope, ge;

/*
    ENTRY POINT OF ROUTINE:
    INITIALIZATION
*/

    flag = 0;		/* indicate board address not yet assigned */
    finished = 0;	/* indicate not finished with program */
    hflag = 0;          /* indicate interrupt handler not installed yet */

    for(j = 0; j < MAXSIZE; j++)	/* clear float buffer */
    	fb[j] = 0.0;
    
    for(i = 0; i < NUM_CHAN;i++)
    {
      for(j = 0; j < MAXSIZE; j++)
      {
	c_block.ideal_data[i][j] = 0;	/* clear ideal data buffer */
	c_block.cor_data[i][j] = 0;	/* clear corrected data buffer */
      }
      c_block.coef_bufu10[i][0] = c_block.coef_bufu10[i][1] = 0;
      c_block.coef_bufb10[i][0] = c_block.coef_bufb10[i][1] = 0;
      c_block.coef_bufb5[i][0]  = c_block.coef_bufb5[i][1] = 0;

      /* Initialize the Configuration Parameter Block to default values */

      c_block.mode[i] = 0;		/* mode */
      c_block.trigger[i] = 0;		/* default triggering */
      c_block.interrupt_enable[i] = 0;	/* interrupt enable */
      c_block.threshold[i] = 0;	/* empty threshold */
      c_block.range[i] = BIPOLAR_10;/* channel range storage */
      c_block.prescaler[i] = 53;	/* timer prescaler */
      c_block.counter[i] = 1;		/* conversion counter */
      c_block.write_size[i] = 1;
    }
    c_block.interrupt_flag = 0;	/* default to no interrupts */
    c_block.current_channel = 0;	/* default channel */

    c_block.interrupt_vector = VECTOR;	/* default interrupt vector */
    c_block.bCarrier = FALSE;		/* indicate no carrier initialized and set up yet */
    c_block.bInitialized = FALSE;	/* indicate not ready to talk to IP */
    c_block.slotLetter = SLOT_A;
    c_block.nHandle = 0;		/* make handle to a closed carrier board */

    hdata.h_pid = getpid();		/* save it in the interrupt handler data structure */
    hdata.hd_ptr = (char *)&c_block;/* put in address of c_block structure also */

/*
	Initialize the Carrier library
*/
    if(InitCarrierLib() != S_OK)
    {
	printf("\nUnable to initialize the carrier library. Exiting program.\n");
	exit(0);
    }

/*
	Open an instance of a carrier device 
*/
    if(CarrierOpen(0, &c_block.nHandle) != S_OK)
    {
	printf("\nUnable to Open instance of carrier.\n");
	finished = 1;	 /* indicate finished with program */
    }
    else
	flag = 1;


/* Enter main loop */

    while(!finished)
    {
      printf("\nIP236 Library Demonstration  Rev. A \n\n");
      printf(" 1. Exit this Program\n");
      printf(" 2. Set Board Base Address\n");
      printf(" 3. Set IP Slot Letter\n");
      printf(" 4. Read Module I.D./Display Event Status\n");
      printf(" 5. Read Calibration Coefficients\n");
      printf(" 6. Set/Change Channel Number\n");
      printf(" 7. Issue Software Reset to Board\n");
      printf(" 8. Set Up Configuration Parameters\n");
      printf(" 9. Configure Channel\n");
      printf("10. Enter/Change Output Values\n");
      printf("11. Correct Output Values\n");
      printf("12. Write Values to Output FIFO\n");
      printf("13. N/A\n");
      printf("14. Start/Stop Conversions\n");
      printf("15. View Data Buffers & Offset/Gain Coefficients\n");
      printf("16. Clear All Data Buffers\n");
      printf("17. Modify Offset/Gain Coefficients\n");
      printf("18. N/A\n\n");
      printf("Select: ");
      scanf("%d",&item);

/*
    perform the menu item selected.
*/  

      switch(item)
      {
       case 1: /* exit program command */
            printf("Exit program(y/n)?: ");
            scanf("%s",cmd_buff);
            if( cmd_buff[0] == 'y' || cmd_buff[0] == 'Y' )
                finished++;
            break;
        

	case 2: /* set board address command */
	    do 
	    {
		if(flag == 0)
		{
		  printf("\n\nenter base address of carrier board in hex: ");
		  scanf("%lx",&addr);
		  /* Set Carrier Address for Open Carrier Device */
		  SetCarrierAddress(c_block.nHandle, addr);	/* Set Carrier Address */
		}
		GetCarrierAddress(c_block.nHandle, &addr);	/* Read back carrier address */
		printf("address: %lX\n",addr);
		printf("is this value correct(y/n)?: ");
		scanf("%s",cmd_buff);
		if( cmd_buff[0] == 'y' || cmd_buff[0] == 'Y' )
		{
          SetCarrierAddress(c_block.nHandle, addr);	/* Set Carrier Address */
		  if(CarrierInitialize(c_block.nHandle) == S_OK)/* Initialize Carrier */
		  {
		        c_block.bCarrier = TRUE;
			SetInterruptLevel(c_block.nHandle, INTERRUPT_LEVEL);/* Set carrier interrupt level */
		  }
		  flag = 1;
		}
		else
		  flag = 0;

            }while( cmd_buff[0] != 'y' && cmd_buff[0] != 'Y' );
        break;


	  case 3: /* set IP Slot Letter */
		if(flag == 0 || c_block.bCarrier == FALSE)
			printf("\n>>> ERROR: BOARD ADDRESS NOT SET <<<\n");
		else
		{
			printf("\n\nEnter IP slot letter (A, B etc...): ");
			scanf("%s",cmd_buff);
			cmd_buff[0] = toupper(cmd_buff[0]);
			if(cmd_buff[0] < 'A' || cmd_buff[0] > GetLastSlotLetter())
			{
				printf("\nInvalid Slot Letter!\n");
				c_block.bCarrier = FALSE;
			}
			else
			{
				c_block.slotLetter = cmd_buff[0];
																					
/*
	Get the IPACK's base address based on the Slot letter,
        and initialize the IPACK's data structure with the returned address
*/
				if(GetIpackAddress(c_block.nHandle, c_block.slotLetter, &addr) != S_OK)
				{
					printf("\nUnable to Get Ipack Address.\n");
					c_block.bInitialized = FALSE;
				}
				else	              
				{	
			            c_block.brd_ptr = (struct map236 *)addr;
					c_block.bInitialized = TRUE;
				}
			}
		}
	  break;


        case 4: /* Read ID Prom */
            if(!c_block.bInitialized)
                printf("\n>>> ERROR: BOARD ADDRESS NOT SET <<<\n");
            else
		 readid(&c_block);
        break;

        case 5: /* Read calibration coeficients*/
            if(!c_block.bInitialized)
                printf("\n>>> ERROR: BOARD ADDRESS NOT SET <<<\n");
            else
	      {
	       for( i = 0; i < NUM_CHAN; i++ )
	       {
		  c_block.coef_bufu10[i][0] = (word)ReadOffsetError( &c_block, i, UNIPOLAR_10 );
                  c_block.coef_bufu10[i][1] = (word)ReadGainError( &c_block, i, UNIPOLAR_10 );

                  c_block.coef_bufb5[i][0]  = (word)ReadOffsetError( &c_block, i, BIPOLAR_5 );
                  c_block.coef_bufb5[i][1]  = (word)ReadGainError( &c_block, i, BIPOLAR_5 );

                  c_block.coef_bufb10[i][0] = (word)ReadOffsetError( &c_block, i, BIPOLAR_10 );
                  c_block.coef_bufb10[i][1] = (word)ReadGainError( &c_block, i, BIPOLAR_10 );
	       }
	    }
            break;    

        case 6: /* channel number */
	    finished1 = 0;
	    while(!finished1)
	    {
 	       printf("\n\nChannel: %x\n\n",c_block.current_channel);
	       printf(" 1. Return to Previous Menu\n");
	       printf(" 2. Change Channel Number\n");
	       printf("\nSelect: ");
	       scanf("%d",&temp);
	       switch(temp)
	       {
		 case 1: /* return to previous menu */
		    finished1++;
		 break;

		 case 2: /* Select channel */
		     printf("New Channel Number (0 - %d)\n",(NUM_CHAN - 1));
		     c_block.current_channel = (int)get_param();
		 break;
	       }
	    }
	    break;

        case 7: /* Reset channel */
            if(!c_block.bInitialized)
                printf("\n>>> ERROR: BOARD ADDRESS NOT SET <<<\n");
            else
		    reset_board(&c_block);
        break;

        case 8: /* set up configuration block parameters */
	      setconf236(&c_block);
        break;

        case 9: /* configure */
            if(!c_block.bInitialized)
                printf("\n>>> ERROR: BOARD ADDRESS NOT SET <<<\n");
            else
	          cnfg236(&c_block);
        break;

        case 10: /* Enter Ideal Data */
	    finished1 = 0;
	    while(!finished1)
	    {
	 	printf("\n\nChannel: %x\n\n",c_block.current_channel);
		printf(" 1. Return to Previous Menu\n");
		printf(" 2. Enter Value(s)\n");
		printf("\nSelect: ");
		scanf("%d",&temp);
		switch(temp)
		{
			case 1: /* return to previous menu */
			    finished1++;
			break;

			case 2: /* enter channel values */
	 		    printf("\nEnter desired voltage: ie: 1.25, follow each with CR %d max)",MAXSIZE);
			    printf("\n  CR alone moves to next value,");
       			    printf("\n  SPACE CR moves to previous value,");
	       		    printf("\n  Q CR quits:\n\n");
			    gets( &cmd_buff[0] );	      /* purge input stream */
         	 	    for( j = 0; j < MAXSIZE; j++ )
           	            {
              		      printf("[%02X]: %f ",j,fb[j]);
              		      gets( &cmd_buff[0] );

	                      if(( cmd_buff[0] == 'Q') || ( cmd_buff[0] == 'q'))
	                           break;
	                      else
	                      {
	                        if( cmd_buff[0] == ' ' )      /* check for space */
 	                            j -= 2; 	   	      /* back up if so */

	                        if( cmd_buff[0] != 0 && cmd_buff[0] != ' ' ) /* check for CR */
	                            sscanf( &cmd_buff[0], "%f", &fb[j]);  /* save */
 	                      }
  	                    }

                            for( i = 0; i < j; i++ )	/* convert data */
                            {
			      if(c_block.range[c_block.current_channel] == BIPOLAR_10)
 			         ideal_volt_span = VOLT_SPAN_B10;
			      else	
			         ideal_volt_span = VOLT_SPAN;

			      f_data = (((float)65536 * fb[i]) / ideal_volt_span);

			      if( c_block.range[c_block.current_channel] == UNIPOLAR_10 )
			    	f_data -= 32768.0;

			      if( f_data < 0.0)		/* round */
		 		f_data -= 0.5;
		 	      else
				f_data += 0.5;

			      if( f_data > 32767.0 )	/* clip high */
				f_data = 32767.0;

			      if( f_data < -32768.0 )	/* clip low */
				f_data = -32768.0;

			      c_block.ideal_data[c_block.current_channel][i] = (short)f_data;
			    }

			    c_block.write_size[c_block.current_channel] = j;
			break;
		}
	    }
        break;

        case 11: /* Correct Data */
	    cd236(&c_block);		/* correct data */ 
        break;

        case 12: /* Write Data to output */
            if(!c_block.bInitialized)
                printf("\n>>> ERROR: BOARD ADDRESS NOT SET <<<\n");
            else
	      {
	      finished1 = 0;
	      while(!finished1)
	      {

 	        printf("\n\nChannel: %x\n\n",c_block.current_channel);
	        printf(" 1. Return to Previous Menu\n");
	        printf(" 2. Write Ideal Data Values\n");
	        printf(" 3. Write Corrected Data Values\n");
	        printf("\nSelect: ");
	        scanf("%d",&temp);
	        switch(temp)
	       { 
		      case 1: /* return to previous menu */
			    finished1++;
	   	      break;
		      case 2: /* Ideal */
			    c_block.current_ptr[c_block.current_channel] =
			    c_block.head_ptr[c_block.current_channel] = &c_block.ideal_data[c_block.current_channel][0];
			    c_block.tail_ptr[c_block.current_channel] = &c_block.ideal_data[c_block.current_channel][0] + c_block.write_size[c_block.current_channel];
			    wro236(&c_block, c_block.current_channel);
		      break;
		      case 3: /* Corrected */
			    c_block.current_ptr[c_block.current_channel] =
			    c_block.head_ptr[c_block.current_channel] = &c_block.cor_data[c_block.current_channel][0];
			    c_block.tail_ptr[c_block.current_channel] = &c_block.cor_data[c_block.current_channel][0] + c_block.write_size[c_block.current_channel];
			    wro236(&c_block, c_block.current_channel);
		      break;
	       }
	      }
	    }
	break;

        case 13:     /* attach exception handler */

            if(!c_block.bInitialized)
                printf("\n>>> ERROR: BOARD ADDRESS NOT SET <<<\n");
        break;

        case 14:  /* Start Conversion */
	    finished1 = 0;
	    while(!finished1)
	    {
 	       printf("\n\nChannel: %x\n\n",c_block.current_channel);
	       printf(" 1. Return to Previous Menu\n");
	       printf(" 2. Start Current Channel\n");
	       printf(" 3. Start Multiple Channels\n");
	       printf(" 4. Stop/Reset Current Channel\n");
	       printf(" 5. Stop/Reset Multiple Channels\n");
	       printf("\nSelect: ");
	       scanf("%d",&temp);
	       switch(temp)
	       { 
		      case 1: /* return to previous menu */
			    finished1++;
	   	      break;
		      case 2: /* Current channel */
		           start_single(&c_block);
		      break;
		      case 3: /* multiple channels */
		          printf("8 Bit Channel Mask to Start\n");
		          start_multiple(&c_block,(byte)get_param());
		      break;
		      case 4: /* Current channel */
			   reset_channel(&c_block);
		      break;
		      case 5: /* stop multiple channels */
		          printf("8 Bit Channel Mask to Stop\n");
		          stop_multiple(&c_block,(byte)get_param());
		      break;
	       }
	    }
           break;

        case 15:	/* Display Ideal/Corrected Data, Offset/Gain Coefficients */
previous:
	    printf("\n\nChannel: %1d  Range: ",c_block.current_channel);

	    if(c_block.range[c_block.current_channel] == BIPOLAR_5)
		   printf("Bipolar 5  ");
	    if(c_block.range[c_block.current_channel] == BIPOLAR_10)
		   printf("Bipolar 10 ");
	    if(c_block.range[c_block.current_channel] == UNIPOLAR_10)
		   printf("Unipolar 10");

	    printf("  Coefficients: Offset ");
	    if(c_block.range[c_block.current_channel] == BIPOLAR_5)
		   printf("%04X",(c_block.coef_bufb5[c_block.current_channel][0] & 0xFFFF));
	    if(c_block.range[c_block.current_channel] == BIPOLAR_10)
		   printf("%04X",(c_block.coef_bufb10[c_block.current_channel][0] & 0xFFFF));
	    if(c_block.range[c_block.current_channel] == UNIPOLAR_10)
		   printf("%04X",(c_block.coef_bufu10[c_block.current_channel][0] & 0xFFFF));

	    printf("  Gain ");
	    if(c_block.range[c_block.current_channel] == BIPOLAR_5)
		   printf("%04X",(c_block.coef_bufb5[c_block.current_channel][1] & 0xFFFF));
	    if(c_block.range[c_block.current_channel] == BIPOLAR_10)
		   printf("%04X",(c_block.coef_bufb10[c_block.current_channel][1] & 0xFFFF));
	    if(c_block.range[c_block.current_channel] == UNIPOLAR_10)
		   printf("%04X",(c_block.coef_bufu10[c_block.current_channel][1] & 0xFFFF));

	    printf("\n\nIdeal Data");
	    for( j = 0; j < 8; j++)
	    {
		printf("\n[%02X]",j*8);
		for(i = 0; i < 8; i++)
		      printf("    %04x",c_block.ideal_data[c_block.current_channel][j*8+i] & 0xFFFF);
	    }

	    printf("\n\nCorrected Data ");
	    for( j = 0; j < 8; j++)
	    {
		printf("\n[%02X]",j*8);
		for(i = 0; i < 8; i++)
		      printf("    %04x",c_block.cor_data[c_block.current_channel][j*8+i] & 0xFFFF);
	    }

	    printf("\n 1. Return to Previous Menu");
	    printf("\n 2. View Next Data Block");
	    printf("\nSelect: ");
	    scanf("%d",&temp);
	    if(temp == 1)
		break;

	    printf("\n\nChannel: %1d  Range: ",c_block.current_channel);

	    if(c_block.range[c_block.current_channel] == BIPOLAR_5)
		   printf("Bipolar 5  ");
	    if(c_block.range[c_block.current_channel] == BIPOLAR_10)
		   printf("Bipolar 10 ");
	    if(c_block.range[c_block.current_channel] == UNIPOLAR_10)
		   printf("Unipolar 10");

	    printf("  Coefficients: Offset ");
	    if(c_block.range[c_block.current_channel] == BIPOLAR_5)
		   printf("%04X",(c_block.coef_bufb5[c_block.current_channel][0] & 0xFFFF));
	    if(c_block.range[c_block.current_channel] == BIPOLAR_10)
		   printf("%04X",(c_block.coef_bufb10[c_block.current_channel][0] & 0xFFFF));
	    if(c_block.range[c_block.current_channel] == UNIPOLAR_10)
		   printf("%04X",(c_block.coef_bufu10[c_block.current_channel][0] & 0xFFFF));

	    printf("  Gain ");
	    if(c_block.range[c_block.current_channel] == BIPOLAR_5)
		   printf("%04X",(c_block.coef_bufb5[c_block.current_channel][1] & 0xFFFF));
	    if(c_block.range[c_block.current_channel] == BIPOLAR_10)
		   printf("%04X",(c_block.coef_bufb10[c_block.current_channel][1] & 0xFFFF));
	    if(c_block.range[c_block.current_channel] == UNIPOLAR_10)
		   printf("%04X",(c_block.coef_bufu10[c_block.current_channel][1] & 0xFFFF));

	    printf("\n\nIdeal Data");
	    for( j = 8; j < 16; j++)
	    {
		printf("\n[%02X]",j*8);
		for(i = 0; i < 8; i++)
		      printf("    %04x",c_block.ideal_data[c_block.current_channel][j*8+i] & 0xFFFF);
	    }

	    printf("\n\nCorrected Data ");
	    for( j = 8; j < 16; j++)
	    {
		printf("\n[%02X]",j*8);
		for(i = 0; i < 8; i++)
		      printf("    %04x",c_block.cor_data[c_block.current_channel][j*8+i] & 0xFFFF);
	    }

	    printf("\n 1. Return to Previous Menu");
	    printf("\n 2. View Previous Data Block");
	    printf("\nSelect: ");
	    scanf("%d",&temp);
	    if( temp == 2)
		goto previous;
	 break;


        case 16:        /* clear all data buffers */
	    for(i = 0; i < NUM_CHAN; i++)
	    {
	      for(j = 0; j < MAXSIZE; j++)
	      {
		c_block.ideal_data[i][j] = 0;	/* clear ideal data buffer */
		c_block.cor_data[i][j] = 0;	/* clear corrected data buffer */
	      }
	      c_block.coef_bufu10[i][0] = c_block.coef_bufu10[i][1] = 0;
	      c_block.coef_bufb10[i][0] = c_block.coef_bufb10[i][1] = 0;
	      c_block.coef_bufb5[i][0]  = c_block.coef_bufb5[i][1] = 0;
	    }
            break;

  
        case 17: /* modify gain & offset coefficients for a channel */
         if(flag == 0)
                printf("\n>>> ERROR: BOARD ADDRESS NOT SET <<<\n");
         else
	 {
	    finished1 = 0;
	    while(!finished1)
	    {
 	       printf("\n\nChannel: %x\n\n",c_block.current_channel);
	       printf(" 1. Return to Previous Menu\n");
	       printf(" 2. Change Channel Number\n");
	       printf(" 3. Change Bipolar   5 Offset & Gain\n");
	       printf(" 4. Change Bipolar  10 Offset & Gain\n");
	       printf(" 5. Change Unipolar 10 Offset & Gain\n");
	       printf(" 6. Calculate Offset & Gain from End Points\n");
	       printf(" 7. Write All Current Channel Coefficients to EEPROM\n");
	       printf("\nSelect: ");
	       scanf("%d",&temp);
	       switch(temp)
	       {
		 case 1: /* return to previous menu */
		    finished1++;
		 break;

		 case 2: /* Select channel */
		     printf("New Channel Number (0 - %d)\n",(NUM_CHAN - 1));
		     c_block.current_channel = (int)get_param();
		 break;

		 case 3: /* Select Bipolar   5 */
		     printf("New Offset Value\n");
		     c_block.coef_bufb5[c_block.current_channel][0] = (short)get_param();
		     printf("New Gain Value\n");
		     c_block.coef_bufb5[c_block.current_channel][1] = (short)get_param();
		 break;

		 case 4: /* Select Bipolar  10 */
		     printf("New Offset Value\n");
		     c_block.coef_bufb10[c_block.current_channel][0] = (short)get_param();
		     printf("New Gain Value\n");
		     c_block.coef_bufb10[c_block.current_channel][1] = (short)get_param();
		 break;

		 case 5: /* Select Unipolar  10 */
		     printf("New Offset Value\n");
		     c_block.coef_bufu10[c_block.current_channel][0] = (short)get_param();
		     printf("New Gain Value\n");
		     c_block.coef_bufu10[c_block.current_channel][1] = (short)get_param();
		 break;

		 case 6: /* calculate */
		     printf("\nSpan 10 or 20: ");
		     scanf("%d",&temp);
		     printf("\nFull Scale Value: ");
		     scanf("%f",&fs);
		     printf("\nZero Scale Value: ");
		     scanf("%f",&zs);

		     if((fs - zs) == 0.0)
			break;

		     /* do gain calculation */
		     slope = 65536.0 / (fs - zs);
		     /* gain error */
		     ge = (((float)temp * slope) / 65536.0) - 1.0;
		     printf("\nGain = %X", ((short)((ge * 65536.0 * 4) + 0.5) & 0xFFFF));
 
		     /* do offset calculation */
		     slope *= -1;
		     printf("  Offset = %X",((short)((((slope * zs) - 32768.0) * 4) + 0.5) & 0xFFFF));
		 break;


		 case 7: /* Write values to EEPROM */
		  WriteCoefficients( &c_block, c_block.current_channel, c_block.coef_bufu10[c_block.current_channel][0],
			 c_block.coef_bufu10[c_block.current_channel][1], UNIPOLAR_10 );

		  WriteCoefficients( &c_block, c_block.current_channel, c_block.coef_bufb5[c_block.current_channel][0],
			 c_block.coef_bufb5[c_block.current_channel][1], BIPOLAR_5 );

		  WriteCoefficients( &c_block, c_block.current_channel, c_block.coef_bufb10[c_block.current_channel][0],
			 c_block.coef_bufb10[c_block.current_channel][1], BIPOLAR_10 );

		 break;
	       }
	    }
         }
        break;

      
        case 18: /* detach exception handlers */
		hflag = 0;
		DisableInterrupts(c_block.nHandle);
         break;

        }   /* end of switch */
    }   /* end of while */
/*
    Reset board to disable interrupts from all counters on this IP module
*/
    if(!c_block.bInitialized)    /* module address was set */
       reset_board(&c_block);	  /* reset board */

    DisableInterrupts(c_block.nHandle);
    if(c_block.bCarrier)
	CarrierClose(c_block.nHandle);

    printf("\nEXIT PROGRAM\n");
}   /* end of main */
Example #4
0
int main()
{


/*
    DECLARE LOCAL DATA AREAS:
*/

    char cmd_buff[40];  /* command line input buffer */
    int item;           /* menu item selection variable */
    long status;        /* returned status of driver routines */
    //    int hstatus;        /* interrupt handler returned status */
    unsigned finished;  /* flag to exit program */
    long addr;          /* long to hold board address */
    int flag;           /* general flag for exiting loops */
    int i;              /* loop index */
    int point;          /* I/O point number */
    int port;           /* I/O port number */
    int val;            /* value of port or point */
    int hflag;          /* interrupt handler installed flag */
    struct cblk470 c_block; /* configuration block */
    struct handler_data hdata;  /* interrupt handler data structure */

    
/*
    ENTRY POINT OF ROUTINE:
    INITIALIZATION
*/

    flag = 0;         /* indicate board address not yet assigned */
    finished = 0;     /* indicate not finished with program */
    hflag = 0;        /* indicate interrupt handler not installed yet */

/*
    Initialize the Configuration Parameter Block to default values.
*/

    c_block.param = 0;          /* parameter mask */
    c_block.e_mode = 0;         /* e_mode flag */
    c_block.mask_reg = 0;       /* output mask register */
    c_block.deb_control = 0;    /* debounce control register */
    c_block.deb_clock = 1;      /* debounce control register */
    c_block.enable = 0;         /* interrupt enable register */
    c_block.vector = VECTOR;    /* interrupt vector */

    c_block.bCarrier = FALSE;	/* indicate no carrier initialized and set up yet */
    c_block.bInitialized = FALSE;/* indicate not ready to talk to IP */
    c_block.slotLetter = SLOT_A;
    c_block.nHandle = 0;	/* make handle to a closed carrier board */
    
    for(i = 0; i != 2; i++)
    {
      c_block.ev_control[i] = 0;/* event control registers */
      c_block.deb_duration[i] = 0;/* debounce duration registers */
    }

    for(i = 0; i < 6; i++)
      c_block.event_status[i] = 0; /* initialize event status flags */


    hdata.h_pid = getpid();		/* save it in the interrupt handler data structure */
    hdata.hd_ptr = (char *)&c_block;	/* put in address of c_block structure also */

/*
	Initialize the Carrier library
*/
    if(InitCarrierLib() != S_OK)
    {
	printf("\nUnable to initialize the carrier library. Exiting program.\n");
	exit(0);
    }

/*
	Open an instance of a carrier device 
*/
    if(CarrierOpen(0, &c_block.nHandle) != S_OK)
    {
	printf("\nUnable to Open instance of carrier.\n");
	finished = 1;	 /* indicate finished with program */
    }
    else
	flag = 1;


/*
    Enter main loop
*/      

    while(!finished) {

        printf("\n\nIP470 Library Demonstration Version A\n\n");
	printf(" 1. Exit this Program\n");
	printf(" 2. Set IP Module Base Address\n");
	printf(" 3. Set IP Slot Letter\n");
        printf(" 4. Set Up Configuration Parameters\n");
	printf(" 5. Configure Board Command\n");
	printf(" 6. Read Status Command and ID\n");
	printf(" 7. N/A\n");
	printf(" 8. N/A\n");
	printf(" 9. Read Input Point\n");
	printf("10. Read Input Port\n");
	printf("11. Write Output Point\n");
	printf("12. Write Output Port\n");

	printf("\nSelect: ");
	scanf("%d",&item);

/*
    perform the menu item selected.
*/  
	switch(item) {

	case 1: /* exit program command */

	    printf("Exit program(y/n)?: ");
	    scanf("%s",cmd_buff);
	    if( cmd_buff[0] == 'y' || cmd_buff[0] == 'Y' )
		finished++;
	    break;
	
	case 2: /* set IP address command */
	    do 
	    {
		if(flag == 0)
		{
		  printf("\n\nenter base address of carrier board in hex: ");
		  scanf("%lx",&addr);
		  /* Set Carrier Address for Open Carrier Device */
		  SetCarrierAddress(c_block.nHandle, addr);	/* Set Carrier Address */
		}
		GetCarrierAddress(c_block.nHandle, &addr);	/* Read back carrier address */
		printf("address: %lX\n",addr);
		printf("is this value correct(y/n)?: ");
		scanf("%s",cmd_buff);
		if( cmd_buff[0] == 'y' || cmd_buff[0] == 'Y' )
		{
          SetCarrierAddress(c_block.nHandle, addr);	/* Set Carrier Address */
		  if(CarrierInitialize(c_block.nHandle) == S_OK)/* Initialize Carrier */
		  {
		        c_block.bCarrier = TRUE;
			SetInterruptLevel(c_block.nHandle, INTERRUPT_LEVEL);/* Set carrier interrupt level */
		  }
		  flag = 1;
		}
		else
		  flag = 0;

				
	    }while( cmd_buff[0] != 'y' && cmd_buff[0] != 'Y' );
	    break;

	case 3: /* set IP Slot Letter */
		if(flag == 0 || c_block.bCarrier == FALSE)
			printf("\n>>> ERROR: BOARD ADDRESS NOT SET <<<\n");
		else
		{
			printf("\n\nEnter IP slot letter (A, B etc...): ");
			scanf("%s",cmd_buff);
			cmd_buff[0] = toupper(cmd_buff[0]);
			if(cmd_buff[0] < 'A' || cmd_buff[0] > GetLastSlotLetter())
			{
				printf("\nInvalid Slot Letter!\n");
				c_block.bCarrier = FALSE;
			}
			else
			{
				c_block.slotLetter = cmd_buff[0];
																					
/*
	Get the IPACK's base address based on the Slot letter,
        and initialize the IPACK's data structure with the returned address
*/
				if(GetIpackAddress(c_block.nHandle, c_block.slotLetter, &addr) != S_OK)
				{
					printf("\nUnable to Get Ipack Address.\n");
					c_block.bInitialized = FALSE;
				}
				else	              
				{	
			        c_block.brd_ptr = (struct map470 *)addr;
					c_block.bInitialized = TRUE;
				}
			}
		}
	break;

	case 4: /* set up configuration parameters */

	    scfg470(&c_block);
	    break;

	case 5: /* configure board command */
	
            if(!c_block.bInitialized)
		printf("\n>>> ERROR: BOARD ADDRESS NOT SET <<<\n");
	    else
	    {
/*
    Check the "interrupt handler attached" flag. If interrupt handlers
    are not attached, then print an error message.
*/

              if( (c_block.enable == 1 || c_block.enable == 3 ) && hflag == 0 )
		   printf(">>> ERROR: INTERRUPT HANDLER NOT ATTACHED <<<\n");
	       else  /* select enhanced mode & configure */
		   cnfg470(&c_block); /* configure the board */
	    }
	    break;

	case 6:     /* read board status command */
	
            if(!c_block.bInitialized)
		printf("\n>>> ERROR: BOARD ADDRESS NOT SET <<<\n");
	    else
		psts470(&c_block); /* read board status */
	    break;

	case 7:     /* attach exception handler */
/*
	    if(hflag)
   	         printf("\n>>> ERROR: HANDLERS ARE ATTACHED <<<\n");
            else
            {

		hstatus = 0;
	        hstatus |= SetInterruptHandler(c_block.nHandle, c_block.slotLetter, INT_REQUEST_0,
					 c_block.vector, (void*)isr_470, (void*)&hdata);
		if(hstatus )
	        {
	                printf(">>> ERROR WHEN ATTACHING HANDLER <<<\n");
			hflag = 0;
                }
		else
		{
			hstatus = 0;
			hstatus = EnableInterrupts(c_block.nHandle);
			if(hstatus != S_OK)
			{
			  printf(">>> ERROR WHEN ENABLING INTERRUPTS <<<\n");
			  hflag = 0;
			}
			else
			{
	                  hflag = 1;
 		          printf("\nHandlers are now attached\n");
			}
  	        }
	    } / * end of if/else * /
*/
	    break;

	case 8: /* detach exception handlers */
		hflag = 0;
		DisableInterrupts(c_block.nHandle);
/*		printf("\n>>> NO WAY TO DETACH AT THIS TIME <<<n"); */
	 break;

	 case 9: /* Read Digital Input Point */

        if(!c_block.bInitialized)
		printf("\n>>> ERROR: BOARD ADDRESS NOT SET <<<\n");
	    else
	    {
		printf("\nEnter Input port number   (0 - 5): ");
		scanf("%d",&port);
		printf("\nEnter Input point number  (0 - 7): ");
		scanf("%d",&point);
		status = rpnt470(&c_block,port,point);
		if(status == -1)
		    printf("\n>>> ERROR: PARAMETER OUT OF RANGE <<<\n");
		else
		    printf("\nValue of port %d point %d: %lx\n",port,point,status);
	    }
	    break;

	case 10: /* Read Digital Input Port */

            if(!c_block.bInitialized)
		printf("\n>>> ERROR: BOARD ADDRESS NOT SET <<<\n");
	    else
	    {
		printf("\nEnter Input port number  (0 - 5): ");
		scanf("%d",&port);
		status = rprt470(&c_block,port);
		if(status == -1)
		    printf("\n>>> ERROR: PARAMETER OUT OF RANGE <<<\n");
		else
		    printf("\nValue of port %d: %lx\n",port,status);
	    }
	    break;

	case 11: /* Write Digital Point */

            if(!c_block.bInitialized)
		printf("\n>>> ERROR: BOARD ADDRESS NOT SET <<<\n");
	    else
	    {
		printf("\nEnter Output port number (0 - 5): ");
		scanf("%d",&port);
		printf("\nEnter I/O point number   (0 - 7): ");
		scanf("%d",&point);
		printf("\nEnter point value (0 - 1): ");
		scanf("%x",&val);
		status = wpnt470(&c_block,port,point,val);
		if(status == -1)
		    printf("\n>>> ERROR: PARAMETER OUT OF RANGE <<<\n");
	    }
	    break;

	case 12: /* Write Digital Port */

            if(!c_block.bInitialized)
		printf("\n>>> ERROR: BOARD ADDRESS NOT SET <<<\n");
	    else
	    {
		printf("\nEnter Output port number  (0 - 5):  ");
		scanf("%d",&port);
		printf("\nEnter output value in hex (0 - FF): ");
		scanf("%x",&val);
		status = wprt470(&c_block,port,val);
		if(status == -1)
		    printf("\n>>> ERROR: PARAMETER OUT OF RANGE <<<\n");
	    }
	    break;
	}   /* end of switch */
    }   /* end of while */

/*
    disable interrupts from IP module
*/
    if(flag != 0)                 /* module address was set */
    {
      c_block.param = RESET_INTEN; /* parameter mask */
      c_block.enable = 0;
      c_block.enable |= RESET;
      cnfg470(&c_block);          /* configure the board */
    }

    DisableInterrupts(c_block.nHandle);
    if(c_block.bCarrier)
	CarrierClose(c_block.nHandle);

    printf("\nEXIT PROGRAM\n");
    return 0;
}   /* end of main */
int main()
{
    
/*
    DECLARE LOCAL DATA AREAS:
*/
    char cmd_buff[40];  /* command line input buffer */
    long item;           /* menu item selection variable */
    long status;         /* returned status of driver routines */
    long addr;           /* long to hold board address */
    long flag;           /* general flag for exiting loops */
    unsigned finished;   /* flag to exit program */
    unsigned port;       /* I/O port number */
    unsigned point;      /* I/O point number */
    unsigned val;        /* value of port or point */

    struct status_blk s_block405;  /* allocate status param. blk */


/*
    ENTRY POINT OF ROUTINE:
    INITIALIZATION
*/

    flag = 0;       /* indicate board address not yet assigned */
    finished = 0;   /* indicate not finished with program */

    s_block405.bCarrier = FALSE;		/* indicate no carrier initialized and set up yet */
    s_block405.bInitialized = FALSE;	/* indicate not ready to talk to IP */
    s_block405.slotLetter = SLOT_A;
    s_block405.nHandle = 0;		/* make handle to a closed carrier board */

/*
	Initialize the Carrier library
*/
    if(InitCarrierLib() != S_OK)
    {
	printf("\nUnable to initialize the carrier library. Exiting program.\n");
	exit(0);
    }
	
/*
	Open an instance of a carrier device 
*/
    if(CarrierOpen(0, &s_block405.nHandle) != S_OK)
    {
	printf("\nUnable to Open instance of carrier.\n");
	finished = 1;	 /* indicate finished with program */
    }
    else
	flag = 1;

/*
    Enter main loop
*/      

    while(!finished) {
        printf("\n\nIP405 Library Demonstration  Version A\n\n");
        printf(" 1. Exit this Program\n");
		printf(" 2. Set Carrier Base Address\n");
		printf(" 3. Set IP Slot Letter\n");
        printf(" 4. Read ID PROM Command\n");
        printf(" 5. Read Output Point (from output data latch)\n");
        printf(" 6. Read Output Port  (from output data latch)\n");
        printf(" 7. Write Output Point\n");
        printf(" 8. Write Output Port\n");

        printf("\nSelect: ");
        scanf("%ld",&item);

/*
    perform the menu item selected.
*/  
        switch(item) {

        case 1: /* exit program command */

            printf("Exit program(y/n)?: ");
            scanf("%s",cmd_buff);
            if( cmd_buff[0] == 'y' || cmd_buff[0] == 'Y' )
                finished++;
            break;
        
        case 2: /* set board address command */
		do 
		{
		  if(flag == 0)
		  {
			printf("\n\nenter base address of carrier board in hex: ");
			scanf("%lx",&addr);
			/* Set Carrier Address for Open Carrier Device */
			SetCarrierAddress(s_block405.nHandle, addr);	/* Set Carrier Address */
		  }

	 	  GetCarrierAddress(s_block405.nHandle, &addr);	/*  Read back carrier address */
		  printf("address: %lx\n",addr);
		  printf("is this value correct(y/n)?: ");
		  scanf("%s",cmd_buff);
		  if( cmd_buff[0] == 'y' || cmd_buff[0] == 'Y' )
		  {
                        SetCarrierAddress(s_block405.nHandle, addr);	/* Set Carrier Address */
			if(CarrierInitialize(s_block405.nHandle) == S_OK)		/* Initialize Carrier */
			{
				s_block405.bCarrier = TRUE;
			}
			flag = 1;
		  }
		  else
		  {
		    flag = 0;
		  }
		 }while( cmd_buff[0] != 'y' && cmd_buff[0] != 'Y' );
		break;

		case 3: /* set IP Slot Letter */
		if(flag == 0 || s_block405.bCarrier == FALSE)
			printf("\n>>> ERROR: BOARD ADDRESS NOT SET <<<\n");
		else
		{
			printf("\n\nEnter IP slot letter (A, B etc...): ");
			scanf("%s",cmd_buff);
			cmd_buff[0] = toupper(cmd_buff[0]);
			if(cmd_buff[0] < 'A' || cmd_buff[0] > GetLastSlotLetter())
			{
				printf("\nInvalid Slot Letter!\n");
				s_block405.bCarrier = FALSE;
			}
			else
			{
				s_block405.slotLetter = cmd_buff[0];
																					
/*
	Get the IPACK's base address based on the Slot letter,
        and initialize the IPACK's data structure with the returned address
*/
				if(GetIpackAddress(s_block405.nHandle, s_block405.slotLetter, &addr) != S_OK)
				{
					printf("\nUnable to Get Ipack Address.\n");
					s_block405.bInitialized = FALSE;
				}
				else	              
				{	
			                s_block405.brd_ptr = (struct map405 *)addr;
					s_block405.bInitialized = TRUE;
				}
			}
		}
	break;

        case 4:     /* read board I.D. command */
        
		if(!s_block405.bInitialized)
			printf("\n>>> ERROR: BOARD NOT SET UP <<<\n");
		else
		{
			psts405(&s_block405, s_block405.nHandle, s_block405.slotLetter);  /* read board */
		}
	break;

        case 5: /* Read Digital I/O Point */
        
		if(!s_block405.bInitialized)
                printf("\n>>> ERROR: BOARD ADDRESS NOT SET <<<\n");
            else
	    {
                printf("Enter port number (0 - 2): ");
                scanf("%d",&port);
                printf("\nEnter I/O point number (0 - 15): ");
                scanf("%d",&point);
                status = rpnt405(&s_block405,port,point);
                if(status == -1)
                    printf("\n>>> ERROR: PARAMETER OUT OF RANGE <<<\n");
                else
		{
                    printf("\nValue of port %d, point %d: %lx\n",port
                       ,point,status);
                }
            }
            break;

        case 6: /* Read Digital I/O Port */
        
		if(!s_block405.bInitialized)
                printf("\n>>> ERROR: BOARD ADDRESS NOT SET <<<\n");
            else
	    {
                printf("Enter port number (0 - 2): ");
                scanf("%d",&port);
                status = rprt405(&s_block405,port);
                if(status == -1)
                    printf("\n>>> ERROR: PARAMETER OUT OF RANGE <<<\n");
                else
                    printf("\nValue of port %d: %lx\n",port,status);
            }
            break;

        case 7: /* Write Digital I/O Point */

		if(!s_block405.bInitialized)
                printf("\n>>> ERROR: BOARD ADDRESS NOT SET <<<\n");
            else
	    {
                printf("Enter port number (0 - 2): ");
                scanf("%d",&port);
                printf("\nEnter I/O point number (0 - 15): ");
                scanf("%d",&point);
                printf("\nEnter point output value (0 or 1): ");
                scanf("%x",&val);
                status = wpnt405(&s_block405,port,point,val);
                if(status == -1)
                    printf("\n>>> ERROR: PARAMETER OUT OF RANGE <<<\n");
            }
            break;

        case 8: /* Write Digital I/O Port */

		if(!s_block405.bInitialized)
                printf("\n>>> ERROR: BOARD ADDRESS NOT SET <<<\n");
            else
	    {
                printf("Enter port number (0 - 2): ");
                scanf("%d",&port);
                printf("\nEnter port output value in hex (0 - 0xFFFF): ");
                scanf("%x",&val);
                status = wprt405(&s_block405,port,val);
                if(status == -1)
                    printf("\n>>> ERROR: PARAMETER OUT OF RANGE <<<\n");
            }
            break;
        }   /* end of switch */
    }   /* end of while */

    DisableInterrupts(s_block405.nHandle);
    if(s_block405.bCarrier)
	CarrierClose(s_block405.nHandle);

    printf("\nEXIT PROGRAM\n");

}   /* end of main */
int main()
{

/*
    DECLARE LOCAL DATA AREAS:
*/

    char cmd_buff[32];		/* command line input buffer */
    unsigned finished;		/* flag to exit program */
    int item;			/* menu item selection variable */
    unsigned finished2;		/* flag to exit a loop */
    long addr;			/* board address */
    int flag;			/* general flag for exiting loops */
    int i;			/* loop index */
    int temp;
    int channel;
    float zero, span;		/* storage for zero and span info */
    char o, g;			/* storage for temp offset/gain info */
    struct cblk220 c_block220;    /* configuration block */

    char off_data[A_SIZE];	/* allocate data storage area */
    char gain_data[A_SIZE];	/* allocate data storage area */
    word ideal_data[A_SIZE];	/* allocate data storage area */
    word cor_data[A_SIZE];	/* allocate data storage area */

/*
    ENTRY POINT OF ROUTINE:
    INITIALIZATION
*/

    flag = 0;		 /* indicate board address not yet assigned */
    finished = 0;	 /* indicate not finished with program */

    for(i = 0; i < A_SIZE;i++)
    {
	off_data[i] = 0;		/* clear offset buffer */
	gain_data[i] = 0;		/* clear gain buffer */
	ideal_data[i] = 0;		/* clear ideal buffer */
	cor_data[i] = 0;		/* clear corrected buffer */
    }


/*
    Initialize the Configuration Parameter Block to default values.
*/

    c_block220.mode = TM;			/* mode */
    c_block220.bit_constant = CON12;	/* constant for data correction */
    c_block220.ideal_buf = &ideal_data[0];	/* ideal value */
    c_block220.off_buf = &off_data[0];	/* offset buffer start */
    c_block220.gain_buf = &gain_data[0];	/* gain buffer start */
    c_block220.cor_buf = &cor_data[0];	/* corrected */
    c_block220.bCarrier = FALSE;		/* indicate no carrier initialized and set up yet */
    c_block220.bInitialized = FALSE;	/* indicate not ready to talk to IP */
    c_block220.slotLetter = SLOT_A;
    c_block220.nHandle = 0;		/* make handle to a closed carrier board */

/*
	Initialize the Carrier library
*/
    if(InitCarrierLib() != S_OK)
    {
	printf("\nUnable to initialize the carrier library. Exiting program.\n");
	exit(0);
    }
	
/*
	Open an instance of a carrier device 
*/
    if(CarrierOpen(0, &c_block220.nHandle) != S_OK)
    {
	printf("\nUnable to Open instance of carrier.\n");
	finished = 1;	 /* indicate finished with program */
    }
    else
	flag = 1;

/*
    Enter main loop
*/      

    while(!finished)
    {
      printf("\nIP220 Library Demonstration  Rev. A\n");
      printf(" 1. Exit this Program\n");
      printf(" 2. Set Board Base Address\n");
      printf(" 3. Set IP Slot Letter\n");
      printf(" 4. Transparent Mode Select\n");
      printf(" 5. Simultaneous Mode Select\n");
      printf(" 6. Simultaneous Trigger\n");
      printf(" 7. Read Calibration Coefficients and I.D.\n");
      printf(" 8. Write Ideal Data To Output\n");
      printf(" 9. Write Corrected Data To Output\n");
      printf("10. Display Ideal/Corrected Data, Offset/Gain Coefficients\n");
      printf("11. Clear All Data Buffers\n");
      printf("12. Alter Offset/Gain Coefficients\n");
      printf("Select: ");
      scanf("%d",&item);

/*
    perform the menu item selected.
*/  

      switch(item)
      {
        case 1: /* exit program command */
            printf("Exit program(y/n)?: ");
            scanf("%s",cmd_buff);
            if( cmd_buff[0] == 'y' || cmd_buff[0] == 'Y' )
                finished++;
            break;
        
	case 2: /* set board address command */
	    do 
	    {
		if(flag == 0)
		{
		  printf("\n\nenter base address of carrier board in hex: ");
		  scanf("%lx",&addr);
		  /* Set Carrier Address for Open Carrier Device */
		  SetCarrierAddress(c_block220.nHandle, addr);	/* Set Carrier Address */
		}
		GetCarrierAddress(c_block220.nHandle, &addr);	/* Read back carrier address */
		printf("address: %lX\n",addr);
		printf("is this value correct(y/n)?: ");
		scanf("%s",cmd_buff);
		if( cmd_buff[0] == 'y' || cmd_buff[0] == 'Y' )
		{
          SetCarrierAddress(c_block220.nHandle, addr);	/* Set Carrier Address */
		  if(CarrierInitialize(c_block220.nHandle) == S_OK)/* Initialize Carrier */
		  {
		        c_block220.bCarrier = TRUE;
			SetInterruptLevel(c_block220.nHandle, INTERRUPT_LEVEL);/* Set carrier interrupt level */
		  }
		  flag = 1;
		}
		else
		  flag = 0;
				
	    }while( cmd_buff[0] != 'y' && cmd_buff[0] != 'Y' );
            break;

	case 3: /* set IP Slot Letter */
		if(flag == 0 || c_block220.bCarrier == FALSE)
			printf("\n>>> ERROR: BOARD ADDRESS NOT SET <<<\n");
		else
		{
			printf("\n\nEnter IP slot letter (A, B etc...): ");
			scanf("%s",cmd_buff);
			cmd_buff[0] = toupper(cmd_buff[0]);
			if(cmd_buff[0] < 'A' || cmd_buff[0] > GetLastSlotLetter())
			{
				printf("\nInvalid Slot Letter!\n");
				c_block220.bCarrier = FALSE;
			}
			else
			{
				c_block220.slotLetter = cmd_buff[0];
																					
/*
	Get the IPACK's base address based on the Slot letter,
        and initialize the IPACK's data structure with the returned address
*/
				if(GetIpackAddress(c_block220.nHandle, c_block220.slotLetter, &addr) != S_OK)
				{
					printf("\nUnable to Get Ipack Address.\n");
					c_block220.bInitialized = FALSE;
				}
				else	              
				{	
			                c_block220.brd_ptr = (struct map220 *)addr;
					c_block220.bInitialized = TRUE;
				}
			}
		}
	break;

        case 4:				/* Transparent Mode Select */
            if(!c_block220.bInitialized)
                printf("\n>>> ERROR: BOARD ADDRESS NOT SET <<<\n");
            else
	    {
	      c_block220.mode = TM;	/* mode */
              mode_select220(&c_block220);
	    }
            break;

        case 5:				/* Simultaneous Mode Select */
            if(!c_block220.bInitialized)
                printf("\n>>> ERROR: BOARD ADDRESS NOT SET <<<\n");
            else
	    {
	      c_block220.mode = SM;	/* mode */
              mode_select220(&c_block220);
	    }
            break;

        case 6:				/* Simultaneous Output Trigger */
            if(!c_block220.bInitialized)
                printf("\n>>> ERROR: BOARD ADDRESS NOT SET <<<\n");
            else
	    {
	      c_block220.mode = SMOT;	/* mode */
              mode_select220(&c_block220);
	    }
            break;

        case 7: /* Read Calibration Coefficients and I.D. */
            if(!c_block220.bInitialized)
                printf("\n>>> ERROR: BOARD ADDRESS NOT SET <<<\n");
            else
	      readstat220(&c_block220);	/* read and display status */

            break;

        case 8: /* Write Ideal Data To Output */
            if(!c_block220.bInitialized)
                printf("\n>>> ERROR: BOARD ADDRESS NOT SET <<<\n");
            else
	    {
gloop1:
		printf("\nEnter channel number (HEX)      : ");
		scanf("%x", &channel);
                if(channel > 16 || channel < 0)
		  goto gloop1;

		printf("\nEnter right justified data (HEX): ");
		scanf("%x", &temp);
		ideal_data[channel] = (word)temp;
		wro220(&c_block220, channel, (ideal_data[channel] << 4));
	    }
            break;

        case 9: /* Write Corrected Data To Output */
            if(!c_block220.bInitialized)
                printf("\n>>> ERROR: BOARD ADDRESS NOT SET <<<\n");
            else
	    {
gloop2:
		printf("\nEnter channel number (HEX)      : ");
		scanf("%x", &channel);
                if(channel > 16 || channel < 0)
		  goto gloop2;

		printf("\nEnter right justified data (HEX): ");
		scanf("%x", &temp);
		ideal_data[channel] = (word)temp;

		cd220(&c_block220, channel);	/* correct data */

		/* Check for end points - can not correct data for end points */

		if(ideal_data[channel] == 0 || ideal_data[channel] == 0xFFF)
		    cor_data[channel] = ideal_data[channel];

		wro220(&c_block220, channel, (cor_data[channel] << 4));
	    }
            break;

        case 10:	/* Display Ideal/Corrected Data, Offset/Gain Coefficients */
	    printf("\n  ");
	    for(i = 0; i != 8; i++)
	      printf("    CH %02d",i);

	    printf("\nID");
	    for(i = 0; i != 8; i++)
	      printf("     %04X",ideal_data[i]);

	    printf("\nCD");
	    for(i = 0; i != 8; i++)
	      printf("     %04X",cor_data[i]);

	    printf("\nGD");
	    for(i = 0; i != 8; i++)
	      printf("       %02X",(gain_data[i] & 0xFF));

	    printf("\nOD");
	    for(i = 0; i != 8; i++)
 	      printf("       %02X",(off_data[i] & 0xFF));

	    printf("\n\n  ");

	    for(i = 8; i != 16; i++)
	      printf("    CH %02d",i);

	    printf("\nID");
	    for(i = 8; i != 16; i++)
	      printf("     %04X",ideal_data[i]);

	    printf("\nCD");
	    for(i = 8; i != 16; i++)
	      printf("     %04X",cor_data[i]);

	    printf("\nGD");
	    for(i = 8; i != 16; i++)
	      printf("       %02X",(gain_data[i] & 0xFF));

	    printf("\nOD");
	    for(i = 8; i != 16; i++)
 	      printf("       %02X",(off_data[i] & 0xFF));

            break;

        case 11:        /* clear all data buffers */
	    for(i = 0; i < A_SIZE;i++)
	    {
		off_data[i] = 0;	/* clear offset buffer */
		gain_data[i] = 0;	/* clear gain buffer */
		ideal_data[i] = 0;	/* clear ideal buffer */
		cor_data[i] = 0;	/* clear corrected buffer */
	    }
            break;

        case 12:        /* alter data buffers */
            if(!c_block220.bInitialized)
                printf("\n>>> ERROR: BOARD ADDRESS NOT SET <<<\n");
            else
	    {
	      finished2 = 0;
	      channel = 0;
	      while(!finished2)
	      {
	        printf("\n\nAlter Gain/Offset Coefficients\n\n");
	        printf("\nCurrent Channel Number:     %X",channel);
	        printf("\nCurrent Gain Coefficient:   %X", (gain_data[channel] & 0xFF));
	        printf("\nCurrent Offset Coefficient: %X\n\n", (off_data[channel] & 0xFF));

	        printf("1. Return to Previous Menu\n");
		printf("2. Change Gain Coefficient\n");
		printf("3. Change Offset Coefficient\n");
		printf("4. Change Channel Number\n");
		printf("5. Calculate New Gain/Offset Cofficient\n");
	        printf("\nselect: ");
	        scanf("%d",&item);

	        switch(item)
	        {
	          case 1: /* return to previous menu */
	            finished2++;
	          break;

	          case 2: /* get gain */
			printf("\nEnter coefficient (HEX)       : ");
			scanf("%x", &temp);
			gain_data[channel] = (char)temp;
	          break;

	          case 3: /* get offset */
			printf("\nEnter coefficient (HEX)       : ");
			scanf("%x", &temp);
			off_data[channel] = (char)temp;
	          break;

	          case 4: /* Select new channel */
			printf("\nEnter channel number (HEX)    : ");
			scanf("%x", &channel);
        	  break;

	          case 5: /* Cal channel */
			wro220(&c_block220, channel, 0);
			printf("\nEnter measured output value from DVM connected to channel %x: ",channel);
			scanf("%f",&zero);
			wro220(&c_block220, channel, 0xFFF0);
			printf("\nEnter measured output value from DVM connected to channel %x: ",channel);
			scanf("%f",&span);
			coef220(&zero, &span, (signed char *)&o, (signed char *)&g);	/* compute coefficients */
			printf("\nOffset Coefficient = %X",(o & 0xFF));
			printf("\nGain   Coefficient = %X",(g & 0xFF));
			printf("\n\nDo you wish to update the gain/offset data arrays Y or N : ");
			scanf("%s",cmd_buff);
            		if( cmd_buff[0] == 'y' || cmd_buff[0] == 'Y' )
			{
			  off_data[channel] = o;
			  gain_data[channel] = g;
			}
        	  break;
       	    	}
	      }
	    }
            break;
        }   /* end of switch */
    }   /* end of while */

    DisableInterrupts(c_block220.nHandle);
    if(c_block220.bCarrier)
	CarrierClose(c_block220.nHandle);

    printf("\nEXIT PROGRAM\n");

}   /* end of main */
Example #7
0
void acromagSetup()
{
  long addr=0;
  
  /* Check for Carrier Library */
  if(InitCarrierLib() != S_OK) {
    printf("\nCarrier library failure");
    handleBadSigs(1000);
  }
  
  /* Connect to Carrier */
  if(CarrierOpen(digitalCarrierNum, &carrierHandle) != S_OK) {
    printf("\nUnable to Open instance of carrier.\n");
    handleBadSigs(1001);
  }

  config470.nHandle = carrierHandle;
  config470.slotLetter=IP470_SLOT;
  config320.nHandle = carrierHandle;
  config320.slotLetter=IP320_SLOT;



  if(printToScreen) {
      printf("Inititalizing IP470 in slot %c\n",config470.slotLetter); 
      printf("Inititalizing IP320 in slot %c\n",config320.slotLetter); 
  }

  if(CarrierInitialize(carrierHandle) == S_OK) 
    { /* Initialize Carrier */
      SetInterruptLevel(carrierHandle, INTERRUPT_LEVEL);
      /* Set carrier interrupt level */
    } 
  else 
    {
      printf("\nUnable initialize the carrier %lX", addr);
      handleBadSigs(1002);
    }

  config470.bCarrier=TRUE;
  config320.bCarrier=TRUE;

  /* GetCarrierAddress(carrierHandle, &addr);
     SetCarrierAddress(carrierHandle, addr); */

  if(GetIpackAddress(carrierHandle,config470.slotLetter,
		     (long *) &config470.brd_ptr) != S_OK)
    {
      printf("\nIpack address failure for IP470\n.");
      handleBadSigs(10003);
    }
  config470.bInitialized = TRUE;

  if(GetIpackAddress(carrierHandle,config320.slotLetter,
		     (long *) &config320.brd_ptr) != S_OK)
    {
      printf("\nIpack address failure for IP320\n.");
      handleBadSigs(10003);
    }
  config320.bInitialized = TRUE;
}