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

📄 cserpdd.cpp

📁 wince下的串口驱动源码
💻 CPP
📖 第 1 页 / 共 3 页
字号:
}
VOID
SerLineIntr(
           PVOID pHead                // Hardware Head
           )
{
    DEBUGMSG (ZONE_EVENTS,(TEXT("+SerLineIntr 0x%X\r\n"), pHead));
    if (pHead)
        ((CSerialPDD *)pHead)->LineInterruptHandler();
    DEBUGMSG (ZONE_EVENTS,(TEXT("-SerLineIntr 0x%X\r\n"), pHead));
}
ULONG
SerGetRxBufferSize(
                  PVOID pHead
                  )
{
    return(0);
}
BOOL
SerPowerOff(
           PVOID   pHead       // @parm PVOID returned by SerInit.
           )
{
    DEBUGMSG (ZONE_INIT,(TEXT("+SerPowerOff 0x%X\r\n"), pHead));
    BOOL bReturn = FALSE;
    if (pHead)
        bReturn = ((CSerialPDD *)pHead)->PowerOff();
    DEBUGMSG (ZONE_INIT,(TEXT("-SerPowerOff 0x%X return %d\r\n"), pHead,bReturn));
    return bReturn;
}
BOOL
SerPowerOn(
          PVOID   pHead       // @parm  PVOID returned by SerInit.
          )
{
    DEBUGMSG (ZONE_INIT,(TEXT("+SerPowerOn 0x%X\r\n"), pHead));
    BOOL bReturn = FALSE;
    if (pHead)
        bReturn = ((CSerialPDD *)pHead)->PowerOn();
    DEBUGMSG (ZONE_INIT,(TEXT("-SerPowerOn 0x%X return %d\r\n"), pHead,bReturn));
    return bReturn;
}
VOID
SerClearDTR(
           PVOID   pHead // @parm PVOID returned by HWinit.
           )
{
    DEBUGMSG (ZONE_FUNCTION,(TEXT("+SerClearDTR 0x%X\r\n"), pHead));
    if (pHead)
        ((CSerialPDD *)pHead)->SetDTR(FALSE);
    DEBUGMSG (ZONE_FUNCTION,(TEXT("-SerClearDTR 0x%X\r\n"), pHead));
}
VOID
SerSetDTR(
           PVOID   pHead // @parm PVOID returned by HWinit.
           )
{
    DEBUGMSG (ZONE_FUNCTION,(TEXT("+SerSetDTR 0x%X\r\n"), pHead));
    if (pHead)
        ((CSerialPDD *)pHead)->SetDTR(TRUE);
    DEBUGMSG (ZONE_FUNCTION,(TEXT("-SerSetDTR 0x%X\r\n"), pHead));
}
VOID
SerClearRTS(
           PVOID   pHead // @parm PVOID returned by HWinit.
           )
{
    DEBUGMSG (ZONE_FUNCTION,(TEXT("+SerClearRTS 0x%X\r\n"), pHead));
    if (pHead)
        ((CSerialPDD *)pHead)->SetRTS(FALSE);
    DEBUGMSG (ZONE_FUNCTION,(TEXT("-SerClearRTS 0x%X\r\n"), pHead));
}
VOID
SerSetRTS(
           PVOID   pHead // @parm PVOID returned by HWinit.
           )
{
    DEBUGMSG (ZONE_FUNCTION,(TEXT("+SerSetRTS 0x%X\r\n"), pHead));
    if (pHead)
        ((CSerialPDD *)pHead)->SetRTS(TRUE);
    DEBUGMSG (ZONE_FUNCTION,(TEXT("-SerSetRTS0x%X\r\n"), pHead));
}
BOOL
SerEnableIR(
           PVOID   pHead, // @parm PVOID returned by Serinit.
           ULONG   BaudRate  // @parm PVOID returned by HWinit.
           )
{
    DEBUGMSG (ZONE_FUNCTION,(TEXT("+SerEnableIR 0x%X\r\n"), pHead));
    CSerialPDD * pSerialPDD  = ( CSerialPDD * )pHead;
    if (pSerialPDD)  {
        pSerialPDD->SetOutputMode(TRUE, FALSE);
        pSerialPDD->SetBaudRate(BaudRate,TRUE);
    }
    DEBUGMSG (ZONE_FUNCTION,(TEXT("-SerEnableIR 0x%X\r\n"), pHead));
    return (TRUE);
}
BOOL
SerDisableIR(
            PVOID   pHead /*@parm PVOID returned by Serinit. */
            )
{
    DEBUGMSG (ZONE_FUNCTION,(TEXT("+SerDisableIR 0x%X\r\n"), pHead));
    CSerialPDD * pSerialPDD  = ( CSerialPDD * )pHead;
    if (pSerialPDD)  {
        pSerialPDD->SetOutputMode(FALSE, TRUE);
    }
    DEBUGMSG (ZONE_FUNCTION,(TEXT("-SerDisableIR 0x%X \r\n"), pHead));
    return (TRUE);
}
VOID
SerClearBreak(
             PVOID   pHead // @parm PVOID returned by HWinit.
             )
{
    DEBUGMSG (ZONE_FUNCTION, (TEXT("+SL_ClearBreak, 0x%X\r\n"), pHead));
    if (pHead)
        ((CSerialPDD *)pHead)->SetBreak(FALSE);
    DEBUGMSG (ZONE_FUNCTION, (TEXT("-SL_ClearBreak, 0x%X\r\n"), pHead));
}
VOID
SerSetBreak(
           PVOID   pHead // @parm PVOID returned by HWinit.
           )
{
    DEBUGMSG (ZONE_FUNCTION, (TEXT("+SL_SetBreak, 0x%X\r\n"), pHead));
    if (pHead)
        ((CSerialPDD *)pHead)->SetBreak(TRUE);
    DEBUGMSG (ZONE_FUNCTION, (TEXT("-SL_SetBreak, 0x%X\r\n"), pHead));
}

BOOL
SerXmitComChar(
              PVOID   pHead,    // @parm PVOID returned by HWInit.
              UCHAR   ComChar   // @parm Character to transmit. 
              )
{
    DEBUGMSG (ZONE_FUNCTION,(TEXT("+SerXmitComChar 0x%X\r\n"), pHead));
    if (pHead)
        ((CSerialPDD *)pHead)->XmitComChar(ComChar);    
    DEBUGMSG (ZONE_FUNCTION,(TEXT("-SerXmitComChar 0x%X return %d \r\n"), pHead));
    return TRUE;
}
ULONG
SerGetStatus(
            PVOID    pHead,    // @parm PVOID returned by HWInit.
            LPCOMSTAT    lpStat    // Pointer to LPCOMMSTAT to hold status.
            )
{
    DEBUGMSG (ZONE_FUNCTION,(TEXT("+SerGetStatus 0x%X\r\n"), pHead));
    ULONG ulReturn = (ULONG)-1;
    if (pHead && lpStat) {
        CSerialPDD * pSerialPDD  = ( CSerialPDD * )pHead;
        lpStat->fCtsHold = (((pSerialPDD->GetDCB()).fOutxCtsFlow && pSerialPDD->IsCTSOff())?1:0);
        lpStat->fDsrHold = (((pSerialPDD->GetDCB()).fOutxDsrFlow && pSerialPDD->IsDSROff())?1:0);
        // NOTE - I think what they really want to know here is
        // the amount of data in the MDD buffer, not the amount
        // in the UART itself.  Just set to 0 for now since the
        // MDD doesn't take care of this.
        lpStat->cbInQue = 0;
        lpStat->cbOutQue = 0;
        ulReturn = pSerialPDD->GetReceivedError();
    }        
    DEBUGMSG (ZONE_FUNCTION,(TEXT("-SerGetStatus 0x%X reutnr 0x%X\r\n"), pHead,ulReturn));
    return ulReturn;
}
VOID
SerReset(
        PVOID   pHead    // @parm PVOID returned by HWInit.
        )
{
    DEBUGMSG (ZONE_FUNCTION,(TEXT("+SL_Reset 0x%X\r\n"), pHead));
    if (pHead)
        ((CSerialPDD *)pHead)->Reset();    
    DEBUGMSG (ZONE_FUNCTION,(TEXT("-SL_Reset 0x%X\r\n"), pHead));
}
VOID
SerGetModemStatus(
                 PVOID   pHead,        // @parm PVOID returned by HWInit.
                 PULONG  pModemStatus    // @parm PULONG passed in by user.
                 )
{
    DEBUGMSG (ZONE_FUNCTION,(TEXT("+SL_GetModemStatus 0x%X\r\n"), pHead));
    if (pHead && pModemStatus ) {
        *pModemStatus = ((CSerialPDD *)pHead)->GetModemStatus();
    }
    DEBUGMSG (ZONE_FUNCTION | ZONE_EVENTS,
              (TEXT("-SL_GetModemStatus 0x%X (stat x%X) \r\n"), pHead, (pModemStatus!=NULL?*pModemStatus:0)));
    return;
}
VOID
SerGetCommProperties(
                    PVOID   pHead,      // @parm PVOID returned by SerInit. 
                    LPCOMMPROP  pCommProp   // @parm Pointer to receive COMMPROP structure. 
                    )
{
    DEBUGMSG (ZONE_FUNCTION,(TEXT("+SerGetCommProperties 0x%X\r\n"), pHead));
    if (pHead && pCommProp ) {
        *pCommProp = ((CSerialPDD *)pHead)->GetCommProperties();
    }
    DEBUGMSG (ZONE_FUNCTION | ZONE_EVENTS,
              (TEXT("-SerGetCommProperties 0x%X \r\n"), pHead));
    return;
}
VOID
SerPurgeComm(
            PVOID   pHead,        // @parm PVOID returned by HWInit.
            DWORD   fdwAction        // @parm Action to take. 
            )
{
    DEBUGMSG (ZONE_FUNCTION,(TEXT("+SL_PurgeComm 0x%X\r\n"), pHead));
    if (pHead ) {
        ((CSerialPDD *)pHead)->PurgeComm( fdwAction);
    }
    DEBUGMSG (ZONE_FUNCTION,(TEXT("-SL_PurgeComm 0x%X\r\n"), pHead));
    return;
}
BOOL
SerSetDCB(
         PVOID   pHead,        // @parm    PVOID returned by HWInit.
         LPDCB   lpDCB       // @parm    Pointer to DCB structure
         )
{
    BOOL bRet = FALSE;
    DEBUGMSG (ZONE_FUNCTION,(TEXT("+SL_SetDCB 0x%X\r\n"), pHead));
    if (pHead  &&  lpDCB ) {
        bRet=((CSerialPDD *)pHead)->SetDCB(lpDCB);
    }
    DEBUGMSG (ZONE_FUNCTION, (TEXT("-SL_SetDCB 0x%X return %d \r\n"), pHead,bRet));
    return(bRet);
}
BOOL
SerSetCommTimeouts(
                  PVOID   pHead,        // @parm    PVOID returned by HWInit.
                  LPCOMMTIMEOUTS   lpCommTimeouts // @parm Pointer to CommTimeout structure
                  )
{
    DEBUGMSG (ZONE_FUNCTION,(TEXT("+SL_SetCommTimeout 0x%X\r\n"), pHead));
    // I do not think PDD need CommTimeouts parameter for operation.
    // All timeouts are taken care of by the MDD.
    DEBUGMSG (ZONE_FUNCTION,(TEXT("-SL_SetCommTimeout 0x%X\r\n"), pHead));
    return(TRUE);
}
BOOL
SerIoctl(PVOID pHead, DWORD dwCode,PBYTE pBufIn,DWORD dwLenIn,
         PBYTE pBufOut,DWORD dwLenOut,PDWORD pdwActualOut)
{
    BOOL RetVal = FALSE;
    DEBUGMSG (ZONE_FUNCTION, (TEXT("+SerIoctl 0x%X\r\n"), pHead));
    if (pHead)
        RetVal= ((CSerialPDD *)pHead)->Ioctl( dwCode, pBufIn, dwLenIn, pBufOut, dwLenOut, pdwActualOut);
    DEBUGMSG (ZONE_FUNCTION, (TEXT("-SerIoctl( 0x%X\r\n"), pHead));
    return(RetVal);
}
const
HW_VTBL IoVTbl = {
    SerInit,
    SerPostInit,
    SerDeinit,
    SerOpen,
    SerClose,
    SerGetInterruptType,
    SerRxIntr,
    SerTxIntrEx,
    SerModemIntr,
    SerLineIntr,
    SerGetRxBufferSize,
    SerPowerOff,
    SerPowerOn,
    SerClearDTR,
    SerSetDTR,
    SerClearRTS,
    SerSetRTS,
    SerEnableIR,
    SerDisableIR,
    SerClearBreak,
    SerSetBreak,
    SerXmitComChar,
    SerGetStatus,
    SerReset,
    SerGetModemStatus,
    SerGetCommProperties,
    SerPurgeComm,
    SerSetDCB,
    SerSetCommTimeouts,
    SerIoctl
    };


// GetSerialObj : The purpose of this function is to allow multiple PDDs to be
// linked with a single MDD creating a multiport driver.  In such a driver, the
// MDD must be able to determine the correct vtbl and associated parameters for
// each PDD.  Immediately prior to calling HWInit, the MDD calls GetSerialObject
// to get the correct function pointers and parameters.
//
extern "C" PHWOBJ
GetSerialObject(
               DWORD DeviceArrayIndex
               )
{
    PHWOBJ pSerObj;

    // Unlike many other serial samples, we do not have a statically allocated
    // array of HWObjs.  Instead, we allocate a new HWObj for each instance
    // of the driver.  The MDD will always call GetSerialObj/HWInit/HWDeinit in
    // that order, so we can do the alloc here and do any subsequent free in
    // HWDeInit.
    // Allocate space for the HWOBJ.
    pSerObj=(PHWOBJ)LocalAlloc( LPTR ,sizeof(HWOBJ) );
    if ( !pSerObj )
        return (NULL);

    // Fill in the HWObj structure that we just allocated.

    pSerObj->BindFlags = THREAD_IN_PDD;     // PDD create thread when device is first attached.
    pSerObj->dwIntID = DeviceArrayIndex;   // Only it is useful when set set THREAD_AT_MDD. We use this to transfer DeviceArrayIndex
    pSerObj->pFuncTbl = (HW_VTBL *) &IoVTbl; // Return pointer to appropriate functions

    // Now return this structure to the MDD.
    return (pSerObj);
}


⌨️ 快捷键说明

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