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

📄 pm5002k_lib.c

📁 pm518采集卡驱动源码
💻 C
📖 第 1 页 / 共 2 页
字号:
//   None.
void PM5002K_WriteDword (PM5002K_HANDLE hPM5002K, PM5002K_ADDR addrSpace, DWORD dwOffset, UINT32 data)
{
    if (hPM5002K->cardReg.Card.Item[addrSpace].item==ITEM_MEMORY)
    {
        UINT32 *pData = (UINT32 *) (hPM5002K->cardReg.Card.Item[addrSpace].I.Mem.dwUserDirectAddr + dwOffset);
        *pData = data; // write directly to the memory mapped range
    }
    else PM5002K_ReadWriteBlock(hPM5002K, addrSpace, dwOffset, FALSE, &data, sizeof(UINT32), PM5002K_MODE_DWORD);
}

// Function: PM5002K_Interrupt5IsEnabled()
//   Check if the interrupt is enabled.
// Parameters:
//   hPM5002K [in] handle to the card as received from PM5002K_Open().
// Return Value:
//   TRUE if the interrupt is enabled. FALSE otherwise.
BOOL PM5002K_Interrupt5IsEnabled (PM5002K_HANDLE hPM5002K)
{
    if (!hPM5002K->Interrupt5.hThread) return FALSE;
    return TRUE;
}

void DLLCALLCONV PM5002K_Interrupt5Handler (PVOID pData)
{
    PM5002K_HANDLE hPM5002K = (PM5002K_HANDLE) pData;
    PM5002K_Interrupt5_RESULT intResult;
    intResult.dwCounter = hPM5002K->Interrupt5.Int.dwCounter;
    intResult.dwLost = hPM5002K->Interrupt5.Int.dwLost;
    intResult.fStopped = hPM5002K->Interrupt5.Int.fStopped;
	//funcIntHandler->PM5002K_Interrupt5_HANDLER是回调函数的指针
	//这里是定义,声明在lib.h中,加一个sdata[],要在lib.h中声明一下
	//hPM5002K->Interrupt5.funcIntHandler(hPM5002K, &intResult,m_sdata);	
	hPM5002K->Interrupt5.funcIntHandler(hPM5002K, &intResult,m_sdata,m_inttime);//第2次修改
}

//void PM5002K_ReadHFifo(PM5002K_HANDLE hPM5002K, PM5002K_ADDR addrSpace,
//                       DWORD dwOffset, unsigned short *buf, DWORD dwBytes)
//{
//    WD_TRANSFER trans;
//
//    BZERO(trans);
//
//    trans.cmdTrans = RP_SWORD; //读端口
//
//    trans.dwPort = hPM5002K->cardReg.Card.Item[addrSpace].I.IO.dwAddr;
//    trans.dwPort += dwOffset;
//
//    trans.fAutoinc = FALSE; //不自动加,TRUE;
//    trans.dwBytes = dwBytes;
//    trans.dwOptions = 0;
//    trans.Data.pBuffer = buf;
//    WD_Transfer (hPM5002K->hWD, &trans);
//}
///////////////////////////////////修改readhfifo////////////////////////
void PM5002K_ReadHFifo(PM5002K_HANDLE hPM5002K,\
					   PM5002K_ADDR addrSpace,\
					   DWORD dwOffset,\
					   unsigned short *buf,\
					   DWORD dwBytes)
{
//读HFIFO
    WD_TRANSFER trans;
//    BOOL fMem = hPM5002K->cardReg.Card.Item[addrSpace].item==ITEM_MEMORY;
    BZERO(trans);

    trans.cmdTrans = RP_SWORD; //读端口

	trans.dwPort = hPM5002K->cardReg.Card.Item[addrSpace].I.IO.dwAddr;
    trans.dwPort += dwOffset;

    trans.fAutoinc = FALSE; //不自动加,TRUE;
    trans.dwBytes = dwBytes;
    trans.dwOptions = 0;
    trans.Data.pBuffer = buf;
    WD_Transfer (hPM5002K->hWD, &trans);
}
////////////////////////////////////////////////////////////////////////////
// Function: PM5002K_Interrupt5Enable()
//   Enable the interrupt.
// Parameters:
//   hPM5002K [in] handle to the card as received from PM5002K_Open.
//   funcIntHandler [in] The call back function to be called upon interrupt.
// Return Value:
//   TRUE if the interrupt was successfully enabled. FALSE otherwise.
BOOL PM5002K_Interrupt5Enable (PM5002K_HANDLE hPM5002K, PM5002K_Interrupt5_HANDLER funcIntHandler)
{
    DWORD dwStatus;

    // Check if interrupt is already enabled
    if (hPM5002K->Interrupt5.hThread)
        return FALSE;

    // Calls WD_IntEnable() and creates an interrupt handler thread
    hPM5002K->Interrupt5.funcIntHandler = funcIntHandler;
    dwStatus = InterruptEnable(&hPM5002K->Interrupt5.hThread, hPM5002K->hWD, &hPM5002K->Interrupt5.Int, PM5002K_Interrupt5Handler, (PVOID) hPM5002K);
    if (dwStatus)
    {
        sprintf(PM5002K_ErrorString, "InterruptEnable() failed with status 0x%lx - %s\n",
            dwStatus, Stat2Str(dwStatus));
        return FALSE;
    }

    return TRUE;
}

// Function: PM5002K_Interrupt5Disable()
//   Disable the interrupt.
// Parameters:
//   hPM5002K [in] handle to the card as received from PM5002K_Open().
// Return Value:
//   None.
void PM5002K_Interrupt5Disable (PM5002K_HANDLE hPM5002K)
{
    if (!hPM5002K->Interrupt5.hThread) return;

    // this calls WD_IntDisable()
    InterruptDisable(hPM5002K->Interrupt5.hThread);

    hPM5002K->Interrupt5.hThread = NULL;
}

// Function: PM5002K_Interrupt7IsEnabled()
//   Check if the interrupt is enabled.
// Parameters:
//   hPM5002K [in] handle to the card as received from PM5002K_Open().
// Return Value:
//   TRUE if the interrupt is enabled. FALSE otherwise.
BOOL PM5002K_Interrupt7IsEnabled (PM5002K_HANDLE hPM5002K)
{
    if (!hPM5002K->Interrupt7.hThread) return FALSE;
    return TRUE;
}

void DLLCALLCONV PM5002K_Interrupt7Handler (PVOID pData)
{
    PM5002K_HANDLE hPM5002K = (PM5002K_HANDLE) pData;
    PM5002K_Interrupt7_RESULT intResult;
    intResult.dwCounter = hPM5002K->Interrupt7.Int.dwCounter;
    intResult.dwLost = hPM5002K->Interrupt7.Int.dwLost;
    intResult.fStopped = hPM5002K->Interrupt7.Int.fStopped;
    hPM5002K->Interrupt7.funcIntHandler(hPM5002K, &intResult);
}

// Function: PM5002K_Interrupt7Enable()
//   Enable the interrupt.
// Parameters:
//   hPM5002K [in] handle to the card as received from PM5002K_Open.
//   funcIntHandler [in] The call back function to be called upon interrupt.
// Return Value:
//   TRUE if the interrupt was successfully enabled. FALSE otherwise.
BOOL PM5002K_Interrupt7Enable (PM5002K_HANDLE hPM5002K, PM5002K_Interrupt7_HANDLER funcIntHandler)
{
    DWORD dwStatus;

    // Check if interrupt is already enabled
    if (hPM5002K->Interrupt7.hThread)
        return FALSE;

    // Calls WD_IntEnable() and creates an interrupt handler thread
    hPM5002K->Interrupt7.funcIntHandler = funcIntHandler;
    dwStatus = InterruptEnable(&hPM5002K->Interrupt7.hThread, hPM5002K->hWD, &hPM5002K->Interrupt7.Int, PM5002K_Interrupt7Handler, (PVOID) hPM5002K);
    if (dwStatus)
    {
        sprintf(PM5002K_ErrorString, "InterruptEnable() failed with status 0x%lx - %s\n",
            dwStatus, Stat2Str(dwStatus));
        return FALSE;
    }

    return TRUE;
}

// Function: PM5002K_Interrupt7Disable()
//   Disable the interrupt.
// Parameters:
//   hPM5002K [in] handle to the card as received from PM5002K_Open().
// Return Value:
//   None.
void PM5002K_Interrupt7Disable (PM5002K_HANDLE hPM5002K)
{
    if (!hPM5002K->Interrupt7.hThread) return;

    // this calls WD_IntDisable()
    InterruptDisable(hPM5002K->Interrupt7.hThread);

    hPM5002K->Interrupt7.hThread = NULL;
}

// Function: PM5002K_Interrupt10IsEnabled()
//   Check if the interrupt is enabled.
// Parameters:
//   hPM5002K [in] handle to the card as received from PM5002K_Open().
// Return Value:
//   TRUE if the interrupt is enabled. FALSE otherwise.
BOOL PM5002K_Interrupt10IsEnabled (PM5002K_HANDLE hPM5002K)
{
    if (!hPM5002K->Interrupt10.hThread) return FALSE;
    return TRUE;
}

void DLLCALLCONV PM5002K_Interrupt10Handler (PVOID pData)
{
    PM5002K_HANDLE hPM5002K = (PM5002K_HANDLE) pData;
    PM5002K_Interrupt10_RESULT intResult;
    intResult.dwCounter = hPM5002K->Interrupt10.Int.dwCounter;
    intResult.dwLost = hPM5002K->Interrupt10.Int.dwLost;
    intResult.fStopped = hPM5002K->Interrupt10.Int.fStopped;
    hPM5002K->Interrupt10.funcIntHandler(hPM5002K, &intResult);
}

// Function: PM5002K_Interrupt10Enable()
//   Enable the interrupt.
// Parameters:
//   hPM5002K [in] handle to the card as received from PM5002K_Open.
//   funcIntHandler [in] The call back function to be called upon interrupt.
// Return Value:
//   TRUE if the interrupt was successfully enabled. FALSE otherwise.
BOOL PM5002K_Interrupt10Enable (PM5002K_HANDLE hPM5002K, PM5002K_Interrupt10_HANDLER funcIntHandler)
{
    DWORD dwStatus;

    // Check if interrupt is already enabled
    if (hPM5002K->Interrupt10.hThread)
        return FALSE;

    // Calls WD_IntEnable() and creates an interrupt handler thread
    hPM5002K->Interrupt10.funcIntHandler = funcIntHandler;
    dwStatus = InterruptEnable(&hPM5002K->Interrupt10.hThread, hPM5002K->hWD, &hPM5002K->Interrupt10.Int, PM5002K_Interrupt10Handler, (PVOID) hPM5002K);
    if (dwStatus)
    {
        sprintf(PM5002K_ErrorString, "InterruptEnable() failed with status 0x%lx - %s\n",
            dwStatus, Stat2Str(dwStatus));
        return FALSE;
    }

    return TRUE;
}

// Function: PM5002K_Interrupt10Disable()
//   Disable the interrupt.
// Parameters:
//   hPM5002K [in] handle to the card as received from PM5002K_Open().
// Return Value:
//   None.
void PM5002K_Interrupt10Disable (PM5002K_HANDLE hPM5002K)
{
    if (!hPM5002K->Interrupt10.hThread) return;

    // this calls WD_IntDisable()
    InterruptDisable(hPM5002K->Interrupt10.hThread);

    hPM5002K->Interrupt10.hThread = NULL;
}

// Function: PM5002K_Interrupt11IsEnabled()
//   Check if the interrupt is enabled.
// Parameters:
//   hPM5002K [in] handle to the card as received from PM5002K_Open().
// Return Value:
//   TRUE if the interrupt is enabled. FALSE otherwise.
BOOL PM5002K_Interrupt11IsEnabled (PM5002K_HANDLE hPM5002K)
{
    if (!hPM5002K->Interrupt11.hThread) return FALSE;
    return TRUE;
}

void DLLCALLCONV PM5002K_Interrupt11Handler (PVOID pData)
{
    PM5002K_HANDLE hPM5002K = (PM5002K_HANDLE) pData;
    PM5002K_Interrupt11_RESULT intResult;
    intResult.dwCounter = hPM5002K->Interrupt11.Int.dwCounter;
    intResult.dwLost = hPM5002K->Interrupt11.Int.dwLost;
    intResult.fStopped = hPM5002K->Interrupt11.Int.fStopped;
    hPM5002K->Interrupt11.funcIntHandler(hPM5002K, &intResult);
}

// Function: PM5002K_Interrupt11Enable()
//   Enable the interrupt.
// Parameters:
//   hPM5002K [in] handle to the card as received from PM5002K_Open.
//   funcIntHandler [in] The call back function to be called upon interrupt.
// Return Value:
//   TRUE if the interrupt was successfully enabled. FALSE otherwise.
BOOL PM5002K_Interrupt11Enable (PM5002K_HANDLE hPM5002K, PM5002K_Interrupt11_HANDLER funcIntHandler)
{
    DWORD dwStatus;

    // Check if interrupt is already enabled
    if (hPM5002K->Interrupt11.hThread)
        return FALSE;

    // Calls WD_IntEnable() and creates an interrupt handler thread
    hPM5002K->Interrupt11.funcIntHandler = funcIntHandler;
    dwStatus = InterruptEnable(&hPM5002K->Interrupt11.hThread, hPM5002K->hWD, &hPM5002K->Interrupt11.Int, PM5002K_Interrupt11Handler, (PVOID) hPM5002K);
    if (dwStatus)
    {
        sprintf(PM5002K_ErrorString, "InterruptEnable() failed with status 0x%lx - %s\n",
            dwStatus, Stat2Str(dwStatus));
        return FALSE;
    }

    return TRUE;
}

// Function: PM5002K_Interrupt11Disable()
//   Disable the interrupt.
// Parameters:
//   hPM5002K [in] handle to the card as received from PM5002K_Open().
// Return Value:
//   None.
void PM5002K_Interrupt11Disable (PM5002K_HANDLE hPM5002K)
{
    if (!hPM5002K->Interrupt11.hThread) return;

    // this calls WD_IntDisable()
    InterruptDisable(hPM5002K->Interrupt11.hThread);

    hPM5002K->Interrupt11.hThread = NULL;
}

// Function: PM5002K_Interrupt12IsEnabled()
//   Check if the interrupt is enabled.
// Parameters:
//   hPM5002K [in] handle to the card as received from PM5002K_Open().
// Return Value:
//   TRUE if the interrupt is enabled. FALSE otherwise.
BOOL PM5002K_Interrupt12IsEnabled (PM5002K_HANDLE hPM5002K)
{
    if (!hPM5002K->Interrupt12.hThread) return FALSE;
    return TRUE;
}

void DLLCALLCONV PM5002K_Interrupt12Handler (PVOID pData)
{
    PM5002K_HANDLE hPM5002K = (PM5002K_HANDLE) pData;
    PM5002K_Interrupt12_RESULT intResult;
    intResult.dwCounter = hPM5002K->Interrupt12.Int.dwCounter;
    intResult.dwLost = hPM5002K->Interrupt12.Int.dwLost;
    intResult.fStopped = hPM5002K->Interrupt12.Int.fStopped;
    hPM5002K->Interrupt12.funcIntHandler(hPM5002K, &intResult);
}

// Function: PM5002K_Interrupt12Enable()
//   Enable the interrupt.
// Parameters:
//   hPM5002K [in] handle to the card as received from PM5002K_Open.
//   funcIntHandler [in] The call back function to be called upon interrupt.
// Return Value:
//   TRUE if the interrupt was successfully enabled. FALSE otherwise.
BOOL PM5002K_Interrupt12Enable (PM5002K_HANDLE hPM5002K, PM5002K_Interrupt12_HANDLER funcIntHandler)
{
    DWORD dwStatus;

    // Check if interrupt is already enabled
    if (hPM5002K->Interrupt12.hThread)
        return FALSE;

    // Calls WD_IntEnable() and creates an interrupt handler thread
    hPM5002K->Interrupt12.funcIntHandler = funcIntHandler;
    dwStatus = InterruptEnable(&hPM5002K->Interrupt12.hThread, hPM5002K->hWD, &hPM5002K->Interrupt12.Int, PM5002K_Interrupt12Handler, (PVOID) hPM5002K);
    if (dwStatus)
    {
        sprintf(PM5002K_ErrorString, "InterruptEnable() failed with status 0x%lx - %s\n",
            dwStatus, Stat2Str(dwStatus));
        return FALSE;
    }

    return TRUE;
}

// Function: PM5002K_Interrupt12Disable()
//   Disable the interrupt.
// Parameters:
//   hPM5002K [in] handle to the card as received from PM5002K_Open().
// Return Value:
//   None.
void PM5002K_Interrupt12Disable (PM5002K_HANDLE hPM5002K)
{
    if (!hPM5002K->Interrupt12.hThread) return;

    // this calls WD_IntDisable()
    InterruptDisable(hPM5002K->Interrupt12.hThread);

    hPM5002K->Interrupt12.hThread = NULL;
}



//{
//WD_DMA dma;
//BZERO (dma);
/////////////allocate the DMA buffer (100000 bytes)
//dma.pUserAddr = NULL;
//dma.dwBytes = 10000;
//dma.dwOptions = DMA_KERNEL_BUFFER_ALLOC;
//WD_DMALock(hWD, &dma);
//if (dma.hDma==0)
//return FALSE;
///////////// prepare data into buffer
//PrepareDataInBuffer(dma.pUserAddr);
///////////// transfer data from the buffer to the card
//My_Program_DMA_Transfer(dma.Page[0].pPhysicalAddr,
//LocalAddr);
///////////// Wait for transfer to end
//while(!My_Dma_Done());
////////////// release the buffer
//WD_DMAUnlock(hWD,&dma);
//}



⌨️ 快捷键说明

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