⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 int32pci.c

📁 网上下载的一个rtx例子
💻 C
字号:
/***********************************************************************

FILE
    int32.c -  functions for INT32 board

ROUTINES

REMARKS
    Clock rate into Zilog 8536 chip is 2.5 MHz


LAST UPDATE
    Dan Block  2/5/98


***********************************************************************/

/***********************************************************************
			  I M P O R T S

    This section contains ALL the declarations from other modules
    required in this program.  Such "imports" are gathered here
    instead of scattered all over this file to make them easier
    to find and reduces the chance of introducing bugs through
    inconsistent multiple declarations of the same item.

***********************************************************************/
#include "windows.h"
#include "rtapi.h"
#include "stdio.h"

#include "int32pci.h"      /* address and other declarations */


/***********************************************************************
	     F O R W A R D    D E C L A R A T I O N S

    This section only declares functions that are local to this
    module; functions visible outside this module are already
    declared in the header file timerbd.h #include'd above.

***********************************************************************/


/***********************************************************************
	   P R I V A T E    D A T A    V A R I A B L E S

    These variables and declarations are visible to all routines in
    this file.  Variables declared as "static" are not visible
    outside of this file.  In computer jargon, their "name space" is
    restricted to this file.  This enhances data security by preventing
    routines outside this file from inadvertently modidifying these
    values though accidental use of an external variable with the
    same name.

***********************************************************************/
ULONG BADR1, BADR2;
PCI_SLOT_NUMBER     SlotNumber;
PPCI_COMMON_CONFIG  PciData; 
UCHAR               buffer[PCI_COMMON_HDR_LENGTH]; 


/***********************************************************************
		  E N T R Y    R O U T I N E S

    Entry routines are those that can be called directly by functions
    outside this module or file.

***********************************************************************/

/*----------------------------------------------------------------------
PROCEDURE
    Int32_Initialize

SYNOPSIS
    

PARAMETERS
      
RETURNS
     
REMARKS

LAST UPDATE
    Dan Block 11/19/98
----------------------------------------------------------------------*/
ULONG Int32_Initialize(void) {

	ULONG       i;                    // logical slot number for the PCI adapter
    ULONG       f;                    // function number on the specified adapter
    ULONG       bytesWritten;         // return value from RtGetBusDataByOffset
    ULONG       bus;                  // bus number
    BOOLEAN     flag;                  
	ULONG       Offset= 0;
	ULONG       nothingWritten = 0;

	int find_card = 0;

    PciData = (PPCI_COMMON_CONFIG) buffer; 
    SlotNumber.u.bits.Reserved = 0; 
    flag = TRUE; 

	bus = 0;

	for (i=0; i<PCI_MAX_DEVICES && flag; i++) { 
	    SlotNumber.u.bits.DeviceNumber = i; 

	    for (f=0; f<PCI_MAX_FUNCTION; f++) {
			SlotNumber.u.bits.FunctionNumber = f; 
 
			bytesWritten = RtGetBusDataByOffset (
			    PCIConfiguration, 
			    bus, 
			    SlotNumber.u.AsULONG, 
			    PciData, 
			    Offset,
			    PCI_COMMON_HDR_LENGTH 
		    ); 
 
			if (bytesWritten == nothingWritten) { 
			    // out of PCI buses 
			    flag = FALSE; 
			    break; 
			} 
 
			if (PciData->VendorID == PCI_INVALID_VENDORID) { 
			    // no device at this slot number, skip to next slot 
			    break; 
			}

			if ((PciData->VendorID == 0x1307) && (PciData->DeviceID == 0x2c))
			{
				BADR1 = PciData->u.type0.BaseAddresses[1] - PCI_ADDRESS_IO_SPACE;
				BADR2 = PciData->u.type0.BaseAddresses[2] - PCI_ADDRESS_IO_SPACE;
				find_card = 1;
				break;
			}

		}
		if (find_card == 1)
		{
			break;
		}
	}
	if (find_card == 1) {
		RtEnablePortIo((PUCHAR)BADR1,0x4d);
		RtEnablePortIo((PUCHAR)BADR2,0xa);
		return(PciData->u.type0.InterruptLine);

	} else {
		return(-1);
	}

}
/*----------------------------------------------------------------------
PROCEDURE
    INT32_READ_REGISTER

SYNOPSIS
    int Int32_Read_Register(int chip, int reg)

PARAMETERS
      chip - either 1 or 2 ... there are two Zilog 8536 chips on the INT32 board
      reg - register address value.  Address values are given in the 8536 documentation
RETURNS
      Normal operation: The value in the given register
      On error:  -1
REMARKS

LAST UPDATE
    Dan Block 2/5/98
----------------------------------------------------------------------*/
int Int32_Read_Register(int chip, int reg) {

    int tmp;

    if (chip == 1) {
      RtWritePortUchar(INT_STA_CNTR_1, (UCHAR) reg);
      tmp = RtReadPortUchar(INT_STA_CNTR_1);
    } else if (chip == 2) {
      RtWritePortUchar(INT_STA_CNTR_2, (UCHAR) reg);
      tmp = RtReadPortUchar(INT_STA_CNTR_2);
    } else {
      tmp = -1;
    } /* endif */

    return(tmp);
}

/*----------------------------------------------------------------------
PROCEDURE
    INT32_WRITE_REGISTER

SYNOPSIS
    void Int32_Write_Register(int chip, int reg,int value)

PARAMETERS
      chip - either 1 or 2 ... there are two Zilog 8536 chips on the INT32 board
      reg - register address value.  Address values are given in the 8536 documentation
      value  -  value to write to the register
RETURNS
REMARKS

LAST UPDATE
    Dan Block 2/5/98
----------------------------------------------------------------------*/
void Int32_Write_Register(int chip, int reg, int value) {

    if (chip == 1) {
      RtWritePortUchar(INT_STA_CNTR_1, (UCHAR) reg);
      RtWritePortUchar(INT_STA_CNTR_1, (UCHAR) value);
    } else if (chip == 2) {
      RtWritePortUchar(INT_STA_CNTR_2, (UCHAR) reg);
      RtWritePortUchar(INT_STA_CNTR_2, (UCHAR) value);
    } /* endif */

}

/*----------------------------------------------------------------------
PROCEDURE
    INT32_RESET

SYNOPSIS
    void Int32_Reset(int chip)

PARAMETERS
      chip - either 1 or 2 ... there are two Zilog 8536 chips on the INT32 board
RETURNS
REMARKS

LAST UPDATE
    Dan Block 2/5/98
----------------------------------------------------------------------*/
void Int32_Reset(int chip) {

    int ii;

    if (chip == 1) {
      ii = RtReadPortUchar(INT_STA_CNTR_1);                 // In RESET or state 0
      RtWritePortUchar(INT_STA_CNTR_1,CLR_INT_RESET);
      ii = RtReadPortUchar(INT_STA_CNTR_1);                 // In state 0
      RtWritePortUchar(INT_STA_CNTR_1,MASTER_INT_CNTR);
      RtWritePortUchar(INT_STA_CNTR_1,INT_RESET);           // Trigger RESET
      RtWritePortUchar(INT_STA_CNTR_1,CLR_INT_RESET);       // Clear RESET -> state 0

      /* Now perform the rest of the setup for chip 1 */
      /* this sets up chip 1 for vectored interrupts */
      RtWritePortUchar(INT_STA_CNTR_1,MASTER_INT_CNTR);
      RtWritePortUchar(INT_STA_CNTR_1,INT_CONTROL_SETUP);

      RtWritePortUchar(INT_STA_CNTR_1,PORT_A_INT_VECT);
      RtWritePortUchar(INT_STA_CNTR_1,PORTA_VECTOR);

      RtWritePortUchar(INT_STA_CNTR_1,PORT_B_INT_VECT);
      RtWritePortUchar(INT_STA_CNTR_1,PORTB_VECTOR);

      RtWritePortUchar(INT_STA_CNTR_1,CNT_INT_VECT);
      RtWritePortUchar(INT_STA_CNTR_1,CNT_VECTOR);

    } else if (chip == 2) {
      ii = RtReadPortUchar(INT_STA_CNTR_2);                 // In RESET or state 0
      RtWritePortUchar(INT_STA_CNTR_2,CLR_INT_RESET);
      ii = RtReadPortUchar(INT_STA_CNTR_2);                 // In state 0
      RtWritePortUchar(INT_STA_CNTR_2,MASTER_INT_CNTR);
      RtWritePortUchar(INT_STA_CNTR_2,INT_RESET);           // Trigger RESET
      RtWritePortUchar(INT_STA_CNTR_2,CLR_INT_RESET);       // Clear RESET -> state 0
    } /* endif */

//    /* Now perform the rest of the setup for the chip */
//    RtWritePortUchar(INT_STA_CNTR_1,MASTER_INT_CNTR);
//    RtWritePortUchar(INT_STA_CNTR_1,INT_CONTROL_SETUP);

//    RtWritePortUchar(INT_STA_CNTR_1,PORT_A_INT_VECT);
//    RtWritePortUchar(INT_STA_CNTR_1,PORTA_VECTOR);

//    RtWritePortUchar(INT_STA_CNTR_1,PORT_B_INT_VECT);
//    RtWritePortUchar(INT_STA_CNTR_1,PORTB_VECTOR);

//    RtWritePortUchar(INT_STA_CNTR_1,CNT_INT_VECT);
//    RtWritePortUchar(INT_STA_CNTR_1,CNT_VECTOR);

}

/*----------------------------------------------------------------------
PROCEDURE
    INT32_READ_PORTA


SYNOPSIS
    int Int32_Read_PortA(int chip)


PARAMETERS
      chip - either 1 or 2 ... there are two Zilog 8536 chips on the INT32 board
RETURNS
      normal: value read on Port A
      error: -1
REMARKS

LAST UPDATE
    Dan Block 2/5/98
----------------------------------------------------------------------*/
int Int32_Read_PortA(int chip) {

    int tmp;

    if (chip == 1) {
      tmp = RtReadPortUchar(INT_PORTA_1);
    } else if (chip == 2) {
      tmp = RtReadPortUchar(INT_PORTA_2);
    } else {
      return(-1);
    } /* endif */
	return(tmp);

}

/*----------------------------------------------------------------------
PROCEDURE
    INT32_READ_PORTB


SYNOPSIS
    int Int32_Read_PortB(int chip)


PARAMETERS
      chip - either 1 or 2 ... there are two Zilog 8536 chips on the INT32 board
RETURNS
      normal: value read on Port B
      error: -1
REMARKS

LAST UPDATE
    Dan Block 2/5/98
----------------------------------------------------------------------*/
int Int32_Read_PortB(int chip) {

    int tmp;

    if (chip == 1) {
      tmp = RtReadPortUchar(INT_PORTB_1);
    } else if (chip == 2) {
      tmp = RtReadPortUchar(INT_PORTB_2);
    } else {
      return(-1);
    } /* endif */
	return(tmp);

}

/*----------------------------------------------------------------------
PROCEDURE
    INT32_READ_PORTC


SYNOPSIS
    int Int32_Read_PortC(int chip)


PARAMETERS
      chip - either 1 or 2 ... there are two Zilog 8536 chips on the INT32 board
RETURNS
      normal: value read on Port C
      error: -1
REMARKS

LAST UPDATE
    Dan Block 2/5/98
----------------------------------------------------------------------*/
int Int32_Read_PortC(int chip) {

    int tmp;

    if (chip == 1) {
      tmp = RtReadPortUchar(INT_PORTC_1);
    } else if (chip == 2) {
      tmp = RtReadPortUchar(INT_PORTC_2);
    } else {
      return(-1);
    } /* endif */
	return(tmp);

}

/*----------------------------------------------------------------------
PROCEDURE
    INT32_WRITE_PORTA


SYNOPSIS
    void Int32_Write_PortA(int chip,int value)


PARAMETERS
      chip - either 1 or 2 ... there are two Zilog 8536 chips on the INT32 board
      value - value to write to the Port
RETURNS
REMARKS

LAST UPDATE
    Dan Block 2/5/98
----------------------------------------------------------------------*/
void Int32_Write_PortA(int chip,int value) {

    if (chip == 1) {
      RtWritePortUchar(INT_PORTA_1,(UCHAR) value);
    } else if (chip == 2) {
      RtWritePortUchar(INT_PORTA_2,(UCHAR) value);
    } /* endif */

}

/*----------------------------------------------------------------------
PROCEDURE
    INT32_WRITE_PORTB


SYNOPSIS
    void Int32_Write_PortB(int chip,int value)


PARAMETERS
      chip - either 1 or 2 ... there are two Zilog 8536 chips on the INT32 board
      value - value to write to the Port
RETURNS
REMARKS

LAST UPDATE
    Dan Block 2/5/98
----------------------------------------------------------------------*/
void Int32_Write_PortB(int chip,int value) {

    if (chip == 1) {
      RtWritePortUchar(INT_PORTB_1,(UCHAR) value);
    } else if (chip == 2) {
      RtWritePortUchar(INT_PORTB_2,(UCHAR) value);
    } /* endif */

}

/*----------------------------------------------------------------------
PROCEDURE
    INT32_WRITE_PORTC


SYNOPSIS
    void Int32_Write_PortC(int chip,int value)


PARAMETERS
      chip - either 1 or 2 ... there are two Zilog 8536 chips on the INT32 board
      value - value to write to the Port
RETURNS
REMARKS

LAST UPDATE
    Dan Block 2/5/98
----------------------------------------------------------------------*/
void Int32_Write_PortC(int chip,int value) {

    if (chip == 1) {
      RtWritePortUchar(INT_PORTC_1,(UCHAR) value);
    } else if (chip == 2) {
      RtWritePortUchar(INT_PORTC_2,(UCHAR) value);
    } /* endif */

}

void Int32_EnableINT_Chip1(void) {


	RtWritePortUchar(INT_ICR, (UCHAR) 0x2);


}
void Int32_DisableINT_Chip1(void) {

	RtWritePortUchar(INT_ICR, (UCHAR) 0x0);

	
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -