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

📄 p9050_lib.c

📁 adlink master board 6760 pci driver for control powerspan slave pci driver
💻 C
📖 第 1 页 / 共 3 页
字号:
}


BOOL P9050_IntEnable (P9050_HANDLE hPlx, P9050_INT_HANDLER funcIntHandler)
{
    // commented begin by pgn
    //BOOL P9050_IntEnable (P9050_HANDLE hPlx, P9050_INT_HANDLER funcIntHandler)
    /*
    DWORD dwIntStatus;
    DWORD dwAddr;

    // check if interrupt is already enabled
    if (hPlx->Int.hThread)
        return FALSE;

    dwIntStatus = P9050_ReadReg (hPlx, P9050_INTCSR);

    BZERO(hPlx->Int.Trans);
    // This is a sample of handling interrupts:
    // Two transfer commands are issued. First the value of the interrupt control/status
    // register is read. Then, a value of ZERO is written.
    // This will cancel interrupts after the first interrupt occurs.
    // When using interrupts, this section will have to change:
    // you must put transfer commands to CANCEL the source of the interrupt, otherwise, the 
    // PC will hang when an interrupt occurs!
    dwAddr = hPlx->addrDesc[P9050_ADDR_REG].dwAddr + P9050_INTCSR;
    hPlx->Int.Trans[0].cmdTrans = hPlx->addrDesc[P9050_ADDR_REG].fIsMemory ? RM_DWORD : RP_DWORD;
    hPlx->Int.Trans[0].dwPort = dwAddr;
    hPlx->Int.Trans[1].cmdTrans = hPlx->addrDesc[P9050_ADDR_REG].fIsMemory ? WM_DWORD : WP_DWORD;
    hPlx->Int.Trans[1].dwPort = dwAddr;
    hPlx->Int.Trans[1].Data.Dword = dwIntStatus & ~BIT6; // put here the data to write to the control register
    hPlx->Int.Int.dwCmds = 2; 
    hPlx->Int.Int.Cmd = hPlx->Int.Trans;
    hPlx->Int.Int.dwOptions |= INTERRUPT_CMD_COPY;

    // this calls WD_IntEnable() and creates an interrupt handler thread
    hPlx->Int.funcIntHandler = funcIntHandler;
    if (!InterruptThreadEnable(&hPlx->Int.hThread, hPlx->hWD, &hPlx->Int.Int, P9050_IntHandler, (PVOID) hPlx))
        return FALSE;

    // this physically enables interrupts
    P9050_WriteReg (hPlx, P9050_INTCSR, dwIntStatus | BIT6);

    return TRUE;
    */
    
    // commented end by pgn
    
    
    DWORD dwIntStatus;
    DWORD dwAddr;
    
    WD_INT wd_int;

    // check if interrupt is already enabled
    if (hPlx->Int.hThread)
        return FALSE;

    dwIntStatus = P9050_ReadReg (hPlx, P9054_INTCSR);
    
    BZERO(hPlx->Int.Trans);
    
    // This is a sample of handling interrupts:
    // Two transfer commands are issued. First the value of the interrupt control/status
    // register is read. Then, a value of ZERO is written.
    // This will cancel interrupts after the first interrupt occurs.
    // When using interrupts, this section will have to change:
    // you must put transfer commands to CANCEL the source of the interrupt, otherwise, the 
    // PC will hang when an interrupt occurs!
    P9050_WriteReg (hPlx, P9054_INTCSR, dwIntStatus & ~(BIT8) ); // put here the data to write to the control register

    // this calls WD_IntEnable() and creates an interrupt handler thread
    wd_int.pci = hPlx->pciSlot;
    wd_int.int_routine = funcIntHandler;
    if( WD_IntEnable(hPlx->hWD,&wd_int) != 0 )
    {
    	return FALSE;	
    }
    
    
    hPlx->Int.hThread = ~NULL;

    // this physically enables interrupts
    P9050_WriteReg (hPlx, P9054_INTCSR, dwIntStatus | (BIT8) );

    return TRUE;    
    
    
}


void P9050_IntDisable (P9050_HANDLE hPlx, P9050_INT_HANDLER funcIntHandler)
{
    /////////////////////////////////////////////////////////////////	
    // commented begin by pgn
    // void P9050_IntDisable (P9050_HANDLE hPlx)
    /*	
    DWORD dwIntStatus;

    if (!hPlx->Int.hThread)
        return;

    // this disables interrupts
    dwIntStatus = P9050_ReadReg (hPlx, P9050_INTCSR);
    P9050_WriteReg (hPlx, P9050_INTCSR, dwIntStatus & ~BIT6);

    // this calls WD_IntDisable()
    InterruptThreadDisable(hPlx->Int.hThread);

    hPlx->Int.hThread = NULL;
    */
    
    // commented end by pgn
    ////////////////////////////////////////////////////////////////////  

      
    DWORD dwIntStatus;
    WD_INT wd_int;

    if (!hPlx->Int.hThread)
        return;

    // this disables interrupts
    dwIntStatus = P9050_ReadReg (hPlx, P9054_INTCSR);
    P9050_WriteReg (hPlx, P9054_INTCSR, dwIntStatus & ~(BIT8));

    // this calls WD_IntDisable()
    wd_int.pci = hPlx->pciSlot;
    wd_int.int_routine = funcIntHandler;
        
    WD_IntDisable(hPlx->hWD,&wd_int);

    hPlx->Int.hThread = NULL;
    
}


void P9050_IntSet (P9050_HANDLE hPlx)
{
      
    DWORD dwIntStatus;

    if (!hPlx->Int.hThread)
        return;

    // this disables interrupts
    dwIntStatus = P9050_ReadReg (hPlx, P9054_INTCSR);
    P9050_WriteReg (hPlx, P9054_INTCSR, dwIntStatus | (BIT8) );

}


void P9050_IntClear (P9050_HANDLE hPlx)
{
      
    DWORD dwIntStatus;

    if (!hPlx->Int.hThread)
        return;

    // this disables interrupts
    dwIntStatus = P9050_ReadReg (hPlx, P9054_INTCSR);
    P9050_WriteReg (hPlx, P9054_INTCSR, dwIntStatus & ~(BIT8));

}


void P9050_EEPROMDelay(P9050_HANDLE hPlx)
{
    WD_SLEEP sleep;
    BZERO (sleep);
    sleep.dwMicroSeconds = 500;
    WD_Sleep( hPlx->hWD, &sleep);
}


void P9050_EEPROMChipSelect(P9050_HANDLE hPlx, BOOL fSelect)
{
    DWORD dwCNTRL = P9050_ReadReg(hPlx, P9050_CNTRL);
    if (fSelect)
        dwCNTRL |= BIT25;
    else
        dwCNTRL &= ~BIT25;
    P9050_WriteReg(hPlx, P9050_CNTRL, dwCNTRL);
    P9050_EEPROMDelay(hPlx);
}


BOOL P9050_EEPROMValid(P9050_HANDLE hPlx)
{
    return (P9050_ReadReg(hPlx, P9050_CNTRL) & BIT28)==BIT28;
}


void P9050_EEPROMWriteBit(P9050_HANDLE hPlx, BOOL fBit)
{
    DWORD dwCNTRL = P9050_ReadReg(hPlx, P9050_CNTRL);

    dwCNTRL &= ~BIT24;
    if (fBit) // data
        dwCNTRL |= BIT26;
    else
        dwCNTRL &= ~BIT26;
    P9050_WriteReg( hPlx, P9050_CNTRL, dwCNTRL);
    P9050_EEPROMDelay(hPlx);

    dwCNTRL |= BIT24; // clock
    P9050_WriteReg( hPlx, P9050_CNTRL, dwCNTRL);
    P9050_EEPROMDelay(hPlx);

    dwCNTRL &= ~BIT24;
    P9050_WriteReg( hPlx, P9050_CNTRL, dwCNTRL);
    P9050_EEPROMDelay(hPlx);
}


BOOL P9050_EEPROMReadBit(P9050_HANDLE hPlx)
{
    BOOL fRet;
    DWORD dwCNTRL = P9050_ReadReg(hPlx, P9050_CNTRL);

    dwCNTRL &= ~BIT24;
    P9050_WriteReg( hPlx, P9050_CNTRL, dwCNTRL);
    P9050_EEPROMDelay(hPlx);

    dwCNTRL |= BIT24; // clock
    P9050_WriteReg( hPlx, P9050_CNTRL, dwCNTRL);
    P9050_EEPROMDelay(hPlx);

    dwCNTRL &= ~BIT24;
    P9050_WriteReg( hPlx, P9050_CNTRL, dwCNTRL);
    P9050_EEPROMDelay(hPlx);

    fRet = (P9050_ReadReg( hPlx, P9050_CNTRL) & BIT27)==BIT27;

    return fRet;
}


void P9050_EEPROMWriteEnableDisable(P9050_HANDLE hPlx, BOOL fEnable)
{
    P9050_EEPROMChipSelect(hPlx, TRUE);

    // send a WEN instruction
    P9050_EEPROMWriteBit(hPlx, 1);
    P9050_EEPROMWriteBit(hPlx, 0);
    P9050_EEPROMWriteBit(hPlx, 0);
    P9050_EEPROMWriteBit(hPlx, fEnable ? 1 : 0);
    P9050_EEPROMWriteBit(hPlx, fEnable ? 1 : 0);

    P9050_EEPROMWriteBit(hPlx, 0);
    P9050_EEPROMWriteBit(hPlx, 0);
    P9050_EEPROMWriteBit(hPlx, 0);
    P9050_EEPROMWriteBit(hPlx, 0);

    P9050_EEPROMChipSelect(hPlx, FALSE);
}


BOOL P9050_EEPROMReadWord(P9050_HANDLE hPlx, DWORD dwOffset, PWORD pwData)
{
    DWORD dwAddr = dwOffset >> 1;
    DWORD i;

    *pwData = 0;

    P9050_EEPROMChipSelect(hPlx, TRUE);
    P9050_EEPROMWriteBit(hPlx, 1);
    P9050_EEPROMWriteBit(hPlx, 1);
    P9050_EEPROMWriteBit(hPlx, 0);
    // if it's a CS46 EEPROM send only 5 bit address
    for (i=BIT5; i; i = i>>1)
    {
        P9050_EEPROMWriteBit(hPlx, (dwAddr & i) == i);
    }
    for (i=BIT15; i; i = i>>1)
    {
        *pwData |= P9050_EEPROMReadBit(hPlx) ? i : 0;
    }

    P9050_EEPROMWriteEnableDisable(hPlx, FALSE);
    
    return TRUE;
}


BOOL P9050_EEPROMWriteWord(P9050_HANDLE hPlx, DWORD dwOffset, WORD wData)
{
    DWORD dwAddr = dwOffset >> 1;
    DWORD i;
    WORD readback;

    P9050_EEPROMWriteEnableDisable(hPlx, TRUE);

    P9050_EEPROMChipSelect(hPlx, TRUE);

    // send a PRWRITE instruction
    P9050_EEPROMWriteBit(hPlx, 1);
    P9050_EEPROMWriteBit(hPlx, 0);
    P9050_EEPROMWriteBit(hPlx, 1);
    // if it's a CS46 EEPROM send only a 6 bit address
    for (i=BIT5; i; i = i>>1)
    {
        P9050_EEPROMWriteBit(hPlx, (dwAddr & i) == i);
    }
    for (i=BIT15; i; i = i>>1)
    {
        P9050_EEPROMWriteBit(hPlx, (wData & i) == i);
    }

    P9050_EEPROMChipSelect(hPlx, FALSE);
    
    P9050_EEPROMWriteEnableDisable(hPlx, FALSE);

    if (P9050_EEPROMReadWord(hPlx, dwOffset, &readback))
    {
        if (wData != readback)
        {
            sprintf( P9050_ErrorString, "Write 0x%04x, Read 0x%04x\n", wData, readback);
            return FALSE;
        }
    }
    else
        return FALSE;

    return TRUE;
}


BOOL P9050_EEPROMReadDWord(P9050_HANDLE hPlx, DWORD dwOffset, PDWORD pdwData)
{
    WORD wData1, wData2;
    if (dwOffset % 4)
    {
        sprintf( P9050_ErrorString, "The offset is not a multiple of 4\n");
        return FALSE;
    }

    if (!P9050_EEPROMReadWord(hPlx, dwOffset, &wData1))
        return FALSE;
    if (!P9050_EEPROMReadWord(hPlx, dwOffset+2, &wData2))
        return FALSE;

    *pdwData = (DWORD) ((wData1 << 16) + wData2);
    return TRUE;
}


BOOL P9050_EEPROMWriteDWord(P9050_HANDLE hPlx, DWORD dwOffset, DWORD dwData)
{
    WORD wData1, wData2;

    if (dwOffset % 4)
    {
        sprintf( P9050_ErrorString, "The offset is not a multiple of 4\n");
        return FALSE;
    }

    wData1 = (WORD) (dwData >> 16);
    wData2 = (WORD) (dwData & 0xffff);

    if (!P9050_EEPROMWriteWord(hPlx, dwOffset, wData1))
        return FALSE;
    if (!P9050_EEPROMWriteWord(hPlx, dwOffset+2, wData2))
        return FALSE;

    return TRUE;
}

⌨️ 快捷键说明

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