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

📄 dpx_rtos.c

📁 交换机中常用芯片链路复用7350的驱动源代码(vxworks中实现)
💻 C
📖 第 1 页 / 共 2 页
字号:
/******************************************************************************/
/**  COPYRIGHT (C) 1999 PMC-SIERRA, INC. ALL RIGHTS RESERVED.                **/
/**--------------------------------------------------------------------------**/
/** This software embodies materials and concepts which are proprietary and  **/
/** confidential to PMC-Sierra, Inc.                                         **/
/** PMC-Sierra distributes this software to its customers pursuant to the    **/ 
/** terms and conditions of the Device Driver Software License Agreement     **/ 
/** contained in the text file software.lic that is distributed along with   **/ 
/** the device driver software. This software can only be utilized if all    **/ 
/** terms and conditions of the Device Driver Software License Agreement are **/ 
/** accepted. If there are any questions, concerns, or if the Device Driver  **/
/** Software License Agreement text file, software.lic, is missing please    **/
/** contact PMC-Sierra for assistance.                                       **/
/**--------------------------------------------------------------------------**/
/**                                                                          **/
/******************************************************************************/
/*******************************************************************************
**    MODULE     : Duplex device drivers RTOS interface source file
**
**    FILE       : Dpx_rtos.c
**      
**    DESCRIPTION: This file contains Duplex device driver RTOS interface.
**                 i.e. some RTOS specific code.
**
**
**    NOTES      :
**
*******************************************************************************/
/* 
**    MODIFICATION HISTORY:
**
** $Log: dpx_rtos.c.rca $
** 
**  Revision: 1.1 Wed Aug 16 16:22:17 2000 bhalwani
**    Beta-1.0
**
** 
**  4   06/15/00    Bhalwani        Vortex chipset driver beta-1.0
**  3   06/15/00    Bhalwani        Vortex chipset driver Alpha-1.30
**  2   02/16/00    chenkemi        alpha-001
**  1   07/22/99    chenkemi        Initial Version
**
**  17  07/22/99    chenkemi        Beta-1.0
**  16  07/22/99    chenkemi        removed '#if 0'
**  15  07/19/99    chenkemi        removed path reference for syspci.h header file
**  14  06/11/99    chenkemi        changed softIntClear() prototype
**  13  06/04/99    chenkemi        using DPX_DPR_TASK_PRIORITY and DPX_DPR_TASK_STACK_SZ ,
**                                  instead of hard coded for the DPR task.
**  12  06/02/99    chenkemi        renamed the compile switch DPX_INTERRUPT_MODE to 
**                                  DPX_CSW_INTERRUPT_MODE
**  11  05/27/99    chenkemi        Re-organized header files
**  10  05/26/99    chenkemi        code cleanup after code review.
**                                  added polling mode for interrupt status processing.
**  9   04/14/99    chenkemi        removed "sysIntDisablePIC( )" 
**  8   04/12/99    chenkemi        rephrase some printf messages.
**  7   04/12/99    chenkemi        changed "#ifdef CSW_PV_FLAG" to "#if CSW_PV_FLAG".
**  6   04/09/99    chenkemi        removed "CSW_PV_FLAG"
**  5   04/09/99    chenkemi        added feature to handle multiple IRQs.
**  4   03/26/99    chenkemi        added statistical couns data structure and API.
**  3   03/17/99    chenkemi        Version Alpha1.1
**  2   03/10/99    chenkemi        Fixed interrupt bug
**  1   03/02/99    chenkemi        Initial Version
**
*/


/** include files **/
#include <msgQLib.h>
#include <iv.h>
#include <intLib.h>
#include <time.h>
#include <drv/pci/pciIntLib.h>
#include <config.h>
#include <vxworks.h>

#include "sysPci.h"
#include "dpx_api.h"
#include "dpx.h"


/** external functions **/
#if CSW_PV_FLAG
extern void softIntClr(void *usrCtxt);
#endif

/** external data **/
extern sDPX_GDD         *psDpxGdd;

/** public data **/

/** public functions **/

/** private data **/	
static UINT1 u1ActiveDevNumber = 0;
static UINT1 u1DPRactive = 0; /* flag for DPR task loop */

sTSK_CTL_BLK sDpxDprTsk =
{
   0x00,   /* Id */
  (INT1*)"DpxDPRtask",
   DPX_DPR_TASK_PRIORITY,   /* priority */
   0x00,   /* options */
   DPX_DPR_TASK_STACK_SZ,   /* stack size */
   (FUNCPTR)sysDuplexDPRtask   
};

/** private functions **/




/*******************************************************************************
**
**  sysDuplexMemset
**  ___________________________________________________________________________ 
**
**  DESCRIPTION:   Set a block of memory to a certain value.  
**                 For driver internal use only
**
**  VALID STATES:  Not applicable
**
**  SIDE EFFECTS:  None.
**
**  INPUTS:		   ptr - pointer to the memory block
**                 u1Byte - value to be written into the block
**                 u4ByteCnt - length or size of the memory block in byte
**
**  OUTPUTS:	   None
**
**  RETURN CODES:  0 (Successful)
**                 -1 (device not detected)
**
*******************************************************************************/
VOID sysDuplexMemset(VOID *ptr, INT1 u1Byte, UINT4 u4ByteCnt)
{
    UINT4   u4next;
    UINT1    *pcaddr;
    
    pcaddr = (UINT1 *) ptr;
    for(u4next=0; u4next < u4ByteCnt; ++u4next)
    {
        *pcaddr = u1Byte;
        ++pcaddr;
    }
} 


/*******************************************************************************
**
**  duplexGetIndBuf
**  ___________________________________________________________________________ 
**
**  DESCRIPTION:  Gets a buffer that is used to save the indication context info
**
**  VALID STATES:	Not Applicable
**
**  SIDE EFFECTS: 
**
**  INPUTS:			None
**
**  OUTPUTS:		None
**
**  RETURN CODES:	Pointer to indication context buffer
**                  DPX_NULL pointer if buffer is unavailable.
**
*******************************************************************************/
sDPX_IND_BUF *duplexGetIndBuf(VOID)
{
    sDPX_IND_BUF *psDpxIndBuf = NULL;

    psDpxIndBuf = (sDPX_IND_BUF *) sysDuplexMemAlloc(sizeof(sDPX_IND_BUF));

    return psDpxIndBuf;
}

/*******************************************************************************
**
**  duplexReturnIndBuf
**  ___________________________________________________________________________ 
**
**  DESCRIPTION:  Returns the indication context buffer to the free pool.
**
**  VALID STATES:	Not Applicable
**
**  SIDE EFFECTS: 
**
**  INPUTS:			pBuf - Pointer to indication context buffer
**
**  OUTPUTS:		None
**
**  RETURN CODES:	None.
**
*******************************************************************************/
VOID duplexReturnIndBuf(sDPX_IND_BUF *pBuf)
{

     sysDuplexMemFree(pBuf);

}

/*******************************************************************************
**
**  sysDuplexDelayFn
**  ___________________________________________________________________________ 
**
**  DESCRIPTION: Suspends execution of the calling routine's task for specified
**               number of milliseconds.
**
**  VALID STATES: Not Applicable
**
**  SIDE EFFECTS: 
**
**  INPUTS:	      u4Msecs - number of millisecond
**
**  OUTPUTS:      None
**
**  RETURN CODES: None
**
*******************************************************************************/
 VOID sysDuplexDelayFn(UINT4 u4Msecs)
 {
   struct timespec time;
    INT4 Seconds;

    Seconds = u4Msecs / 1000;

    time.tv_sec = Seconds;
    time.tv_nsec = (u4Msecs - Seconds *1000) * 1000000; /* in nanosecond */

    /* system call */
    nanosleep(&time, NULL); 

 }
 

#if DPX_CSW_INTERRUPT_MODE   /** Interrupt mode **/
static MSG_Q_ID IntMsgQId;
static sDPX_IRQ_TABLE IrqInstalled[DPX_MAX_NUM_DEVS] = {{0,0}};    

/*******************************************************************************
**
**  sysDuplexIntInstallHandler
**  ___________________________________________________________________________ 
**
**  DESCRIPTION: Install sysDuplexHandler in the processor vector table, spawn
**               the sysDuplexDPRtask routine as a task  and creates a 
**               communication channel between two. Also adds the DUPLEX device
**               to a list of devices for which interrupts will be serviced.
**
**  VALID STATES:  Not applicable
**
**  SIDE EFFECTS: 
**
**  INPUTS:	     duplex - device handler
**
**  OUTPUTS:	 None
**
**  RETURN CODES:
**                 DPX_SUCCESS  
**                 DPX_ERR_INVALID_DEVICE  (invalid device handle)
**                 DPX_ERR_INT_ALREADY_INSTALLED
**                 DPX_ERR_CREATE_MSG_Q 
**                 DPX_ERR_INSTALL_INT_VECTOR
**                 DPX_ERR_SPAWN_DPR_TASK
**
*******************************************************************************/
INT4 sysDuplexIntInstallHandler(DUPLEX duplex)
{
    DPX_ADAPTER_PCI_HANDLE *pSysInfo;
    sDPX_DDB *psDpxDdb;
    INT4 i;
    
    psDpxDdb = (sDPX_DDB *)duplex;
    

    if(u1ActiveDevNumber == 0)
    {
        /* create a message queue used as a communication channel */
        IntMsgQId = msgQCreate(	DPX_MAX_MSGS, sizeof(sDPX_INT_CTXT), 
                                                               MSG_Q_PRIORITY);
        if(IntMsgQId == NULL)
        	return DPX_ERR_INT_INSTALL; 
        
        u1DPRactive = 1; /* set the DPR task loop flag */
        /* spawn sysDuplexDPRtask as a separate task in the RTOS */
        sDpxDprTsk.i4Id = taskSpawn(sDpxDprTsk.pi1Name, sDpxDprTsk.i4Pri, 
                            sDpxDprTsk.i4Opt, 
                            sDpxDprTsk.i4StckSz,sDpxDprTsk.FEntryPtr, 
                            0, 0, 0, 0, 0, 0, 0, 0, 0, 0);

         if( sDpxDprTsk.i4Id == ERROR)
        	return DPX_ERR_INT_INSTALL;              
     }
     
     /* set the Interrupt Processing Enable Flag in the device DDB */
     psDpxDdb->u1IntrProcEn = 1;

     u1ActiveDevNumber++;
     
     
     /* check if a handle with the same IRQ has already been installed or not */
     pSysInfo = (DPX_ADAPTER_PCI_HANDLE *)(psDpxDdb->pSysInfo);
     for(i=0; i < DPX_MAX_NUM_DEVS; i++)
     {
        if(pSysInfo->irq == IrqInstalled[i].irq)
        {
            /* it has been installed, quit here */
            (IrqInstalled[i].count)++;
            return(DPX_SUCCESS);
        }
     }
            
     /* Not installed yet: install Handler by adding to PCI handle chain now */
     if(pciIntConnect(INUM_TO_IVEC(pSysInfo->irq + INT_NUM_IRQ0),
                         sysDuplexIntHandler, pSysInfo->irq ) == ERROR)
        	return DPX_ERR_INT_INSTALL; 
        
     sysIntEnablePIC(pSysInfo->irq);
 
     /* update the record for IRQ installed */
     for(i=0; i < DPX_MAX_NUM_DEVS; i++)
     {
        /* find the next available entry in the record table */
        if(IrqInstalled[i].irq == 0)
        {
            IrqInstalled[i].irq = pSysInfo->irq;
            IrqInstalled[i].count = 1;
            break;
        }
     }
     
#if CSW_PV_FLAG     
    if(i == DPX_MAX_NUM_DEVS)
    {
        /* we didn't find the Irq in the record table, something is terrible wrong */
        printf("Duplex error:  Irq table overflow for irq %d\n", pSysInfo->irq);
        for(i=0; i < DPX_MAX_NUM_DEVS; i++)
            printf(" (%d, %d) ", IrqInstalled[i].irq, IrqInstalled[i].count); 
    }     
#endif
 
     return DPX_SUCCESS;
}


/*******************************************************************************
**
**  sysDuplexIntRemoveHandler
**  ___________________________________________________________________________ 
**
**  DESCRIPTION: Remove the specified device from the list of devices for which
**               interrupt processing will be done. If this is the last active 
**               device, the sysDuplexDPRtask and associated message queue are 
**               deleted. The handler routine is removed from the processor's
**               interrupt vector table as well.
**
**  VALID STATES:  Not applicable
**
**  SIDE EFFECTS: 
**
**  INPUTS:	     duplex - device handler
**
**  OUTPUTS:	 None
**
**  RETURN CODES:None
**
*******************************************************************************/
VOID sysDuplexIntRemoveHandler(DUPLEX duplex)
{
    sDPX_DDB *psDpxDdb;
    DPX_ADAPTER_PCI_HANDLE *pSysInfo;
    INT4 i;
    

⌨️ 快捷键说明

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