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

📄 serial.c

📁 freescale i.mx31 BSP CE5.0全部源码
💻 C
📖 第 1 页 / 共 3 页
字号:
//
// Parameters:
//      pContext 
//          [in] Pointer to a context structure returned 
//                by SerInit function that contains implementation-
//                specific data describing the hardware device.
//
// Returns:  
//      TRUE if success. FALSE if failure.
//
//-----------------------------------------------------------------------------
static BOOL SerDeinit( PVOID pContext )
{
    PSER_INFO pSerHead = (PSER_INFO)pContext;

    DEBUGMSG(ZONE_INIT, (TEXT("SerDeinit+\r\n")));

    if (!pSerHead)
        return (FALSE);

    // Make sure device is closed before doing DeInit
    if (pSerHead->cOpenCount)
        SerClose( pContext );

	if (pSerHead->useDMA)
		DeInitDMA(pSerHead);

    // Release SYSINTR
    KernelIoControl(IOCTL_HAL_RELEASE_SYSINTR, &pSerHead->pHWObj->dwIntID, sizeof(DWORD), NULL, 0, NULL);
    pSerHead->pHWObj->dwIntID = SYSINTR_UNDEFINED;

	BSPUartConfigTranceiver(pSerHead->dwIOBase,FALSE);

    if (pSerHead->pBaseAddress)
        MmUnmapIoSpace(pSerHead->pBaseAddress, pSerHead->dwIOLen);

    SL_Deinit( pContext );

    // Free the HWObj
    LocalFree(pSerHead->pHWObj);

    // And now free the SER_INFO structure.
    LocalFree(pSerHead);

    DEBUGMSG(ZONE_INIT, (TEXT("SerDeinit-\r\n")));

    return (TRUE);
}


//-----------------------------------------------------------------------------
//
// Function: SerPowerOff
//
//  This function is called by driver to turn off
//  power to serial port.
//
// Parameters:
//      pContext 
//          [in] Pointer to a context structure returned 
//                by SerInit function that contains implementation-
//                specific data describing the hardware device.
//
// Returns:  
//      TRUE if success. FALSE if failure.
//
//-----------------------------------------------------------------------------
static BOOL SerPowerOff( PVOID pContext )
{
    DEBUGMSG(ZONE_FUNCTION, (TEXT("SerPowerOff+\r\n")));

    // First, power down the UART
    SL_PowerOff(pContext);

    // And then disable our IR and 9 Pin interface
    SL_SetOutputMode(pContext, FALSE, FALSE);

    DEBUGMSG(ZONE_FUNCTION, (TEXT("SerPowerOff-\r\n")));

    return (TRUE);
}


//-----------------------------------------------------------------------------
//
// Function: SerPowerOn
//
//  This function is called by driver to turn on
//  power to serial port.
//
// Parameters:
//      pContext 
//          [in] Pointer to a context structure returned 
//                by SerInit function that contains implementation-
//                specific data describing the hardware device.
//
// Returns:  
//      TRUE if success. FALSE if failure.
//
//-----------------------------------------------------------------------------
static BOOL SerPowerOn( PVOID pContext )
{
    PSER_INFO pSerHead = (PSER_INFO)pContext;

    DEBUGMSG(ZONE_FUNCTION, (TEXT("SerPowerOn+\r\n")));
    // First, power up the UART
    SL_PowerOn( pContext );

    // And then enable our IR interface (if needed)
    SL_SetOutputMode(pSerHead, pSerHead->fIRMode, !pSerHead->fIRMode);

    DEBUGMSG(ZONE_FUNCTION, (TEXT("SerPowerOn-\r\n")));

    return (TRUE);
}


//-----------------------------------------------------------------------------
//
// Function: SerEnableIR
//
//  This function enables the infrared (IR) 
//  serial interface.
//
// Parameters:
//      pContext 
//          [in] Pointer to a context structure returned 
//                by SerInit function that contains implementation-
//                specific data describing the hardware device.
//      BaudRate 
//          [in] Specifies the baud to set.
//
// Returns:  
//      TRUE if success. FALSE if failure.
//
//-----------------------------------------------------------------------------
static BOOL SerEnableIR( PVOID pContext, ULONG BaudRate )
{
    PSER_INFO pSerHead = (PSER_INFO)pContext;

    DEBUGMSG(ZONE_IR,(TEXT("SerEnableIR+\r\n")));

    pSerHead->fIRMode = TRUE;

    SL_SetOutputMode(pSerHead, pSerHead->fIRMode, !pSerHead->fIRMode);

    DEBUGMSG(ZONE_IR,(TEXT("SerEnableIR-\r\n")));

    return (TRUE);
}


//-----------------------------------------------------------------------------
//
// Function: SerDisableIR
//
//  This function disables the infrared (IR) 
//   serial interface.
//
// Parameters:
//      pContext 
//          [in] Pointer to a context structure returned 
//                by SerInit function that contains implementation-
//                specific data describing the hardware device.
//
// Returns:  
//      TRUE if success. FALSE if failure.
//
//-----------------------------------------------------------------------------
static BOOL SerDisableIR( PVOID pContext )
{
    PSER_INFO pSerHead = (PSER_INFO)pContext;

    DEBUGMSG(ZONE_IR,(TEXT("SerDisableIR+\r\n")));

    pSerHead->fIRMode = FALSE;

    SL_SetOutputMode(pSerHead, pSerHead->fIRMode, !pSerHead->fIRMode);

    DEBUGMSG(ZONE_IR,(TEXT("SerDisableIR-\r\n")));

    return (TRUE);
}


//-----------------------------------------------------------------------------
//
// Function: SerGetCommProperties
//
//  This function retrieves the current properties
//  of the communications device.
//
// Parameters:
//      pContext 
//          [in] Pointer to a context structure returned 
//                by SerInit function that contains implementation-
//                specific data describing the hardware device.
//      pCommProp 
//          [in] Pointer to a COMMPROP structure to 
//                hold the communications property information.
//
// Returns:  
//      None.
//
//-----------------------------------------------------------------------------
static VOID SerGetCommProperties( PVOID pContext, LPCOMMPROP pCommProp )
{
    PSER_INFO pSerHead = (PSER_INFO)pContext;

    DEBUGMSG(ZONE_FUNCTION,(TEXT("SerGetCommProperties+\r\n")));

    *pCommProp = pSerHead->CommProp;

    DEBUGMSG(ZONE_FUNCTION,(TEXT("SerGetCommProperties-\r\n")));

    return;
}


//-----------------------------------------------------------------------------
//
// Function: SerIRClearDTR
//
//  This routine clears DTR.
//
// Parameters:
//      pContext 
//          [in] Pointer to a context structure returned 
//                by SerInit function that contains implementation-
//                specific data describing the hardware device.
//
// Returns:  
//      None.
//
//-----------------------------------------------------------------------------
VOID SerIRClearDTR( PVOID   pContext )
{
    DEBUGMSG(ZONE_FUNCTION, (TEXT("SerIRClearDTR+\r\n")));
    return;
}


//-----------------------------------------------------------------------------
//
// Function: SerIRSetDTR
//
//  This routine sets DTR.
//
// Parameters:
//      pContext 
//          [in] Pointer to a context structure returned 
//                by SerInit function that contains implementation-
//                specific data describing the hardware device.
//
// Returns:  
//      None.
//
//-----------------------------------------------------------------------------
VOID SerIRSetDTR( PVOID pContext )
{    
    DEBUGMSG(ZONE_FUNCTION, (TEXT("SerIRSetDTR+\r\n")));
    return;
}


//-----------------------------------------------------------------------------
//
// Function: SerIRClearRTS
//
//  This routine clears RTS.
//
// Parameters:
//      pContext 
//          [in] Pointer to a context structure returned 
//                by SerInit function that contains implementation-
//                specific data describing the hardware device.
//
// Returns:  
//      None.
//
//-----------------------------------------------------------------------------
VOID SerIRClearRTS( PVOID pContext )
{
    DEBUGMSG(ZONE_FUNCTION, (TEXT("SerIRClearRTS+\r\n")));
    return;
}


//-----------------------------------------------------------------------------
//
// Function: SerIRSetRTS
//
//  This routine sets RTS.
//
// Parameters:
//      pContext 
//          [in] Pointer to a context structure returned 
//                by SerInit function that contains implementation-
//                specific data describing the hardware device.
//
// Returns:  
//      None.
//
//-----------------------------------------------------------------------------
VOID SerIRSetRTS( PVOID pContext )
{
    DEBUGMSG(ZONE_FUNCTION, (TEXT("SerIRSetRTS+\r\n")));
    return;
}


const HW_VTBL IoVTbl = {
    SerSerialInit,
    SerPostInit,
    SerDeinit,
    SerOpen,
    SerClose,
    SL_GetIntrType,
    SL_RxIntrHandler,
    SL_TxIntrHandler,
    SL_ModemIntrHandler,
    SL_LineIntrHandler,
    SL_GetRxBufferSize,
    SerPowerOff,
    SerPowerOn,
    SL_ClearDTR,
    SL_SetDTR,
    SL_ClearRTS,
    SL_SetRTS,
    SerEnableIR,
    SerDisableIR,
    SL_ClearBreak,
    SL_SetBreak,
    SL_XmitComChar,
    SL_GetStatus,
    SL_Reset,
    SL_GetModemStatus,
    SerGetCommProperties,
    SL_PurgeComm,
    SL_SetDCB,
    SL_SetCommTimeouts,
};

const HW_VTBL IrVTbl = {
    SerIRInit,
    SerPostInit,
    SerDeinit,
    SerOpen,
    SerClose,
    SL_GetIntrType,
    SL_RxIntrHandler,
    SL_TxIntrHandler,
    SL_ModemIntrHandler,
    SL_LineIntrHandler,
    SL_GetRxBufferSize,
    SerPowerOff,
    SerPowerOn,
    SL_ClearDTR,
    SL_SetDTR,
    SL_ClearRTS,
    SL_SetRTS,
    SerEnableIR,
    SerDisableIR,
    SL_ClearBreak,
    SL_SetBreak,
    SL_XmitComChar,
    SL_GetStatus,
    SL_Reset,
    SL_GetModemStatus,
    SerGetCommProperties,
    SL_PurgeComm,
    SL_SetDCB,
    SL_SetCommTimeouts,
};


//-----------------------------------------------------------------------------
//
// Function: GetSerialObject
//
//  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. 
//
// Parameters:
//      pContext 
//          [in] Index into an array of serial devices, 
//                  corresponding to the different lower layer 
//                  implementations that may be shared by a single 
//                  upper layer implementation.
//
// Returns:  
//      Zero indicates success.
//
//-----------------------------------------------------------------------------
PHWOBJ GetSerialObject( DWORD DeviceArrayIndex )
{
    PHWOBJ pSerObj;

    DEBUGMSG(ZONE_FUNCTION,(TEXT("GetSerialObject+ 0x%x\r\n"),DeviceArrayIndex));

    // 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(LMEM_ZEROINIT|LMEM_FIXED , sizeof(HWOBJ));
    if ( !pSerObj )
        return (NULL);

    // Now return this structure to the MDD.
    // Fill in the HWObj structure that we just allocated.
    pSerObj->BindFlags = THREAD_AT_INIT;     // Have MDD create thread when device is initialized.
    pSerObj->dwIntID = 0;                    // SysIntr is filled in at init time

    if ( DeviceArrayIndex == 1 )
        pSerObj->pFuncTbl = (HW_VTBL *) &IrVTbl; // Return pointer to appropriate functions
    else
        pSerObj->pFuncTbl = (HW_VTBL *) &IoVTbl; // Return pointer to appropriate functions

    DEBUGMSG(ZONE_FUNCTION,(TEXT("GetSerialObject-\r\n")));

    return (pSerObj);
}

⌨️ 快捷键说明

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