serial.c
来自「i.mx27 soc for wince 6.0」· C语言 代码 · 共 981 行 · 第 1/3 页
C
981 行
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 + =
减小字号Ctrl + -
显示快捷键?