vme2Pci.c
上传用户:luoyougen
上传日期:2008-05-12
资源大小:23136k
文件大小:5k
源码类别:

VxWorks

开发平台:

C/C++

  1. /* vme2Pci.c - VME2PCI device configuration library */
  2. /* Copyright 1984-1997 Wind River Systems, Inc. */
  3. #include "copyright_wrs.h"
  4. /*
  5. modification history
  6. --------------------
  7. 01f,03jan97,wlf  doc: cleanup.
  8. 01e,13nov96,mas  int levels read in IO space instead of config space (SPR 7475).
  9. 01d,04mar96,tpr  reworked interrupt handling.
  10. 01c,23feb96,tpr  added intVecNum initialization in vme2PciIntr().
  11. 01b,20jan95,vin  enhancements and clean up.
  12. 01a,09jan95,kvk  created.
  13. */
  14. /*
  15. DESCRIPTION
  16. This library provides routines which configure the VME2PCI chip for a
  17. device which is located on the Peripheral Component Interconnect
  18. (PCI) bus. This library has been designed with respect to the Genesis
  19. 1.5 Engineering Specification Version 1.0A of Motorola
  20. MVME1600/PM603-604 preliminary engineering specification guide.  The
  21. macro VME2PCI_BASE_ADRS has to defined before using this library.
  22. INCLUDE FILES: vme2Pci.h
  23. */
  24. /* include files */
  25. #include "drv/intrCtl/i82378Ibc.h"
  26. #include "drv/vme/vme2Pci.h"
  27. /* extern declarations */
  28. IMPORT INT_HANDLER_DESC * sysIntTbl [256];
  29. /* locals */
  30. /* ptr to regs in PCI IO space */
  31. LOCAL ULONG  vme2PciRegBase = VME2PCI_BASE_ADRS + VME2PCI_IO_OFFSET;
  32. /*******************************************************************************
  33. *
  34. * sysVme2PciInit - initialize a VME2PCI chip 
  35. *
  36. * This routine initializes additional chip-specific features of a VME2PCI
  37. * chip, such as the PCI slave addresses.  It should be called only at
  38. * initialization time.
  39. *
  40. * RETURNS: OK, always.
  41. */
  42. STATUS sysVme2PciInit 
  43.     ( 
  44.     VME2PCI_CNFG_HDR * pVme2PciCnfgHdr, /* ptr to VME2PCI config hdr */
  45.     ULONG  vme2PciCnfgBase /* ptr to VME2PCI reg base */
  46.     )
  47.     {
  48.     int  ix;
  49.     ULONG * cnfgPtr;
  50.     ULONG * pVme2PciRegBase;
  51.     pVme2PciRegBase = (ULONG *)(vme2PciCnfgBase + VME2PCI_CNFG_OFFSET);
  52.     /* Program the PCI command register */
  53.     
  54.     ix = sizeof (VME2PCI_CNFG_HDR) / sizeof (long);
  55.     for (cnfgPtr = (ULONG *)(pVme2PciCnfgHdr); ix > 0; cnfgPtr++, ix--)
  56. #if (_BYTE_ORDER == _BIG_ENDIAN)
  57. *pVme2PciRegBase++ = LONGSWAP(*cnfgPtr);
  58. #else
  59. *pVme2PciRegBase++ = *cnfgPtr;
  60. #endif /* _BYTE_ORDER == _BIG_ENDIAN */    
  61.     
  62.     return (OK);
  63.     }
  64. /*******************************************************************************
  65. *
  66. * vme2PciIntr - handle a VMEbus interrupt
  67. *
  68. * This routine gets called to handle VMEbus interrupts.
  69. *
  70. * NOMANUAL
  71. */
  72. void vme2PciIntr (void)
  73.     {
  74.     UCHAR  intVecNum = 0;
  75.     int  vmeIntLvl;
  76.     INT_HANDLER_DESC * currHandler;
  77. #if (_BYTE_ORDER == _BIG_ENDIAN)
  78.     vmeIntLvl = VME2PCI_INT_LVL_GET(LONGSWAP(((VME2PCI_CNFG_HDR *)
  79.      (vme2PciRegBase))->pciIntEnable));
  80. #else
  81.     vmeIntLvl = VME2PCI_INT_LVL_GET(((VME2PCI_CNFG_HDR *)
  82.      (vme2PciRegBase))->pciIntEnable);
  83. #endif /* _BYTE_ORDER == _BIG_ENDIAN */
  84.     switch (vmeIntLvl)
  85. {
  86. case 1:
  87. /* get the vector number by reading IACK registers in VME2PCI chip */
  88.     intVecNum = *(VME2PCI_IACK_LEVEL1);
  89.     break;
  90. case 2:
  91.     intVecNum = *(VME2PCI_IACK_LEVEL2);
  92.     break;
  93. case 3:
  94.     intVecNum = *(VME2PCI_IACK_LEVEL3);
  95.     break;
  96. case 4:
  97.     intVecNum = *(VME2PCI_IACK_LEVEL4);
  98.     break;
  99. case 5:
  100.     intVecNum = *(VME2PCI_IACK_LEVEL5);
  101.     break;
  102. case 6:
  103.     intVecNum = *(VME2PCI_IACK_LEVEL6);
  104.     break;
  105. case 7:
  106.     intVecNum = *(VME2PCI_IACK_LEVEL7);
  107.     break;
  108. }
  109.     /* call the respective interrupt handler(s) */
  110.     
  111.     if ((currHandler = sysIntTbl [intVecNum]) == NULL)
  112. logMsg ("uninitialized vme interrupt %dn", intVecNum, 0,0,0,0,0);
  113.     else
  114. {
  115. while (currHandler != NULL)
  116.     {
  117.     currHandler->vec (currHandler->arg);
  118.     currHandler = currHandler->next;
  119.     }
  120. }
  121.     }
  122. /*******************************************************************************
  123. *
  124. * vme2PciSlaveAddrSet - set address-related PCI features
  125. *
  126. * This routine sets the Peripheral Component Interconnect (PCI) slave start
  127. * address, the PCI slave end address, and the address offset.
  128. *
  129. * RETURNS: OK, always.
  130. */
  131. STATUS vme2PciSlaveAddrSet
  132.     (
  133.     VME2PCI_CNFG_HDR * pVme2PciCnfgHdr,  /* ptr to VME2PCI config hdr */
  134.     ULONG * pVme2PciRegBase, /* ptr to VME2PCI reg base */
  135.     ULONG startAddress, /* slave starting address */
  136.     ULONG endAddress, /* ending address */
  137.     ULONG  addrOffset, /* slave offset */
  138.     int  slaveNo   /* slave number */
  139.     )
  140.     {
  141.     int  ix;
  142.     ULONG * iy;
  143.     
  144.     switch(slaveNo)
  145. {
  146. case 0:
  147.     pVme2PciCnfgHdr->pciSlvStrtAddr1 = MSW(startAddress);
  148.     pVme2PciCnfgHdr->pciSlvEndAddr1 = MSW(endAddress);
  149.     pVme2PciCnfgHdr->pciSlvAddrOffset1 = MSW(addrOffset);
  150.     pVme2PciCnfgHdr->pciSlvEnable1 = VME2PCI_SLAVE_ENABLE;
  151.     break;
  152. case 1:
  153.     pVme2PciCnfgHdr->pciSlvStrtAddr2 = MSW(startAddress);
  154.     pVme2PciCnfgHdr->pciSlvEndAddr2 = MSW(endAddress);
  155.     pVme2PciCnfgHdr->pciSlvAddrOffset2 = MSW(addrOffset);
  156.     pVme2PciCnfgHdr->pciSlvEnable2 = VME2PCI_SLAVE_ENABLE;
  157.     break;
  158. default:
  159.     break;
  160. }
  161.     ix = sizeof (VME2PCI_CNFG_HDR) / sizeof (long);
  162.     for (iy = (ULONG *)(pVme2PciCnfgHdr); ix > 0; iy++, ix--)
  163. #if (_BYTE_ORDER == _BIG_ENDIAN)
  164. *pVme2PciRegBase++ = LONGSWAP(*iy);
  165. #else
  166. *pVme2PciRegBase++ = *iy;
  167. #endif /* _BYTE_ORDER == _BIG_ENDIAN */
  168.     return (OK);
  169.     }