CSTATUS EnableInterrupts(int nHandle)
{
	CARRIERDATA_STRUCT* pCarrier;
	PCI_BOARD_MEMORY_MAP* pPCICard;
        word nValue; 

	pCarrier = GetCarrier(nHandle);
	if(pCarrier == 0)
		return E_INVALID_HANDLE;

	if(pCarrier->bInitialized == FALSE)
		return E_NOT_INITIALIZED;

	pPCICard = (PCI_BOARD_MEMORY_MAP*)pCarrier->lBaseAddress;		

	nValue = input_word(nHandle,(word*)&pPCICard->controlReg);
	nValue |= APC_INT_PENDING_CLEAR;	/*  Clear any pending interrupts */
	output_word(nHandle,(word*)&pPCICard->controlReg, nValue );

	nValue |= APC_INT_ENABLE;		/* Enable interrupts */
	output_word(nHandle,(word*)&pPCICard->controlReg, nValue );

	pCarrier->bIntEnabled = TRUE;	/*  Interrupts are Enabled */
	return (CSTATUS)S_OK;
}
CSTATUS SetIPClockControl(int nHandle, char chSlot, word uControl)
{
	CARRIERDATA_STRUCT* pCarrier;
	PCI_BOARD_MEMORY_MAP* pPCICard;
	word nValue;
	
	pCarrier = GetCarrier(nHandle);
	if(pCarrier == 0)
	  return E_INVALID_HANDLE;

	if(pCarrier->bInitialized == FALSE)
	  return E_NOT_INITIALIZED;

	/* check carrier ID to see if 32MHZ IP clocking is supported */
	if( pCarrier->uCarrierID & CARRIER_CLK )	/* nonzero can support 32MHZ IP clock */
	  {
	    pPCICard = (PCI_BOARD_MEMORY_MAP*)pCarrier->lBaseAddress;		
	    nValue = input_word(nHandle, (word*)&pPCICard->IPClockControl);

	    switch(chSlot)
	      {
	      case SLOT_A:
		nValue &= 0x00FE;		/* default force bit 0 = 0 = 8MHZ IP clock */
		if( uControl )			/* does caller want 32MHZ? */
		  nValue |= 1;		/* make slot A IP clock 32MHZ */
		break;
	      case SLOT_B:
		nValue &= 0x00FD;		/* default force bit 1 = 0 = 8MHZ IP clock */
		if( uControl )			/* does caller want 32MHZ? */
		  nValue |= 2;		/* make slot B IP clock 32MHZ */
		break;
	      case SLOT_C:
		nValue &= 0x00FB;		/* default force bit 2 = 0 = 8MHZ IP clock */
		if( uControl )			/* does caller want 32MHZ? */
		  nValue |= 4;		/* make slot C IP clock 32MHZ */
		break;
	      case SLOT_D:
		nValue &= 0x00F7;		/* default force bit 3 = 0 = 8MHZ IP clock */
		if( uControl )			/* does caller want 32MHZ? */
		  nValue |= 8;			/* make slot D IP clock 32MHZ */
		break;
	      case SLOT_E:
		nValue &= 0x00EF;		/* default force bit 4 = 0 = 8MHZ IP clock */
		if( uControl )			/* does caller want 32MHZ? */
		  nValue |= 0x10;		/* make slot E IP clock 32MHZ */
		break;
	      default:
		return E_INVALID_SLOT;
		break;
	      }
	    output_word(nHandle, (word*)&pPCICard->IPClockControl, nValue ); /* write value */
	    return (CSTATUS)S_OK;
	  }
	return (CSTATUS)E_NOT_IMPLEMENTED;
}
CSTATUS CarrierInitialize(int nHandle)
{
	CARRIERDATA_STRUCT* pCarrier;
	PCI_BOARD_MEMORY_MAP* pPCICard;
        word nValue; 

	pCarrier = GetCarrier(nHandle);
	if(pCarrier == 0)
		return E_INVALID_HANDLE;

	/* determine the carrier type and initialize */
	pPCICard = (PCI_BOARD_MEMORY_MAP*)pCarrier->lBaseAddress;		

	/* now reset the carrier */
	output_word(nHandle, (word*)&pPCICard->controlReg, SOFTWARE_RESET );

	/* following a software reset 8620a type products will return either */
	/* 0xAyyy or 0xByyyy values in the MS nibble of the control register (yyy = dont care)*/
	/* original 8620 carriers will return 0x0yyy in the MS nibble of the control register */
	/* 0x0yyy = original 8620 board - no extended features */
	/* 0xAyyy = 8620a board with 32MHZ IP clock without extra memory space */
	/* 0xByyy = 8620a board with 32MHZ IP clock and extra memory space */
	nValue = input_word( nHandle,(word*)&pPCICard->controlReg);	/* read again */

	/* pCarrier->uCarrierID value is saved in the carrier structure for later use */
	/* see include file apc8620.h for carrier attributes */

	pCarrier->uCarrierID = PCI_CARRIER;	/* attributes PCI */

	/* test the result */
	if((nValue & 0xF000) == 0xA000)
		pCarrier->uCarrierID |= CARRIER_CLK;

	if((nValue & 0xF000) == 0xB000)
	{
		pCarrier->uCarrierID |= CARRIER_CLK;
		pCarrier->uCarrierID |= CARRIER_MEM;
	}		
	pCarrier->bInitialized = TRUE;	/*  Carrier is now initialized */

	return (CSTATUS)S_OK;
}
CSTATUS ReadIpackID(int nHandle, char chSlot, word* pWords, int nWords)
{
	int i;		/* 	local index */	
	word* pWord;	/*  local variable */
	CARRIERDATA_STRUCT* pCarrier;	/*  local carrier */

	pCarrier = GetCarrier(nHandle);
	if(pCarrier == 0)
		return E_INVALID_HANDLE;

	if(pCarrier->bInitialized == FALSE)
		return E_NOT_INITIALIZED;

	switch(chSlot)
	{
	case SLOT_A:
		pWord = (word *)(pCarrier->lBaseAddress + SLOT_A_ID_OFFSET);
		break;
	case SLOT_B:
		pWord = (word *)(pCarrier->lBaseAddress + SLOT_B_ID_OFFSET);
		break;
	case SLOT_C:
		pWord = (word *)(pCarrier->lBaseAddress + SLOT_C_ID_OFFSET);
		break;
	case SLOT_D:
		pWord = (word *)(pCarrier->lBaseAddress + SLOT_D_ID_OFFSET);
		break;
	case SLOT_E:
		pWord = (word *)(pCarrier->lBaseAddress + SLOT_E_ID_OFFSET);
		break;
	default:
		pWord = 0;
		return E_INVALID_SLOT;
		break;
	}


	for(i = 0; i < nWords; i++, pWords++, pWord++)
		*pWords	= input_word(nHandle, pWord );

	return (CSTATUS)S_OK;
}
CSTATUS GetIPErrorBit(int nHandle, word* pState)
{
  CARRIERDATA_STRUCT* pCarrier;
  PCI_BOARD_MEMORY_MAP* pPCICard;
  word nValue;

  pCarrier = GetCarrier(nHandle);
  if(pCarrier == 0)
    return E_INVALID_HANDLE;

  pPCICard = (PCI_BOARD_MEMORY_MAP*)pCarrier->lBaseAddress;		
  /* get control register */
  nValue = input_word(nHandle, (word*)&pPCICard->controlReg);

  if( nValue & 0x0001 )	/* mask for IP error bit */
    *pState = TRUE;
  else
    *pState = FALSE;

  return (CSTATUS)S_OK;
}
CSTATUS DisableInterrupts(int nHandle)
{
	CARRIERDATA_STRUCT* pCarrier;
	PCI_BOARD_MEMORY_MAP* pPCICard;
        word nValue; 

	pCarrier = GetCarrier(nHandle);
	if(pCarrier == 0)
		return E_INVALID_HANDLE;

	if(pCarrier->bInitialized == FALSE)
		return E_NOT_INITIALIZED;

	pPCICard = (PCI_BOARD_MEMORY_MAP*)pCarrier->lBaseAddress;		

	nValue = input_word(nHandle,(word*)&pPCICard->controlReg);
	nValue &= ~APC_INT_ENABLE;	/* Disable interrupts */
	output_word(nHandle,(word*)&pPCICard->controlReg, nValue );

	pCarrier->bIntEnabled = FALSE;

	return (CSTATUS)S_OK;
}
예제 #7
0
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 */
CSTATUS GetIPClockControl(int nHandle, char chSlot, word* pControl)
{
  CARRIERDATA_STRUCT* pCarrier;
  PCI_BOARD_MEMORY_MAP* pPCICard;
  word nValue;
	
  *pControl = 0;	/* default */

  pCarrier = GetCarrier(nHandle);
  if(pCarrier == 0)
    return E_INVALID_HANDLE;

  if(pCarrier->bInitialized == FALSE)
    return E_NOT_INITIALIZED;

  /* check carrier ID to see if 32MHZ IP clocking is supported */
  if( pCarrier->uCarrierID & CARRIER_CLK )	/* nonzero can support 32MHZ IP clock */
    {
      pPCICard = (PCI_BOARD_MEMORY_MAP*)pCarrier->lBaseAddress;		
      nValue = input_word(nHandle, (word*)&pPCICard->IPClockControl);

      switch(chSlot)
	{
	case SLOT_A:
	  if( nValue & 1 )	/* test IP clock bit 0 = 8MHZ, 1 = 32MHZ */
	    nValue = 1;
	  else
	    nValue = 0;
	  break;
	case SLOT_B:
	  if( nValue & 2 )	/* bit 1 */
	    nValue = 1;
	  else
	    nValue = 0;
	  break;
	case SLOT_C:
	  if( nValue & 4 )	/* bit 2 */
	    nValue = 1;
	  else
	    nValue = 0;
	  break;
	case SLOT_D:
	  if( nValue & 8 )	/* bit 3 */
	    nValue = 1;
	  else
	    nValue = 0;
	  break;
	case SLOT_E:
	  if( nValue & 0x10 )	/* bit 4 */
	    nValue = 1;
	  else
	    nValue = 0;
	  break;
	default:
	  return E_INVALID_SLOT;
	  break;
	}
      *pControl = nValue;			/* write value */
      return (CSTATUS)S_OK;
    }
  return (CSTATUS)E_NOT_IMPLEMENTED;
}