serial.c
来自「i.mx27 soc for wince 6.0」· C语言 代码 · 共 981 行 · 第 1/3 页
C
981 行
pSerHead->CommProp.wPacketVersion = 0xffff;
pSerHead->CommProp.dwServiceMask = SP_SERIALCOMM;
pSerHead->CommProp.dwReserved1 = 0;
pSerHead->CommProp.dwMaxTxQueue = 32;
pSerHead->CommProp.dwMaxRxQueue = 32;
pSerHead->CommProp.dwMaxBaud = BAUD_115200;
pSerHead->CommProp.dwProvSubType = PST_RS232;
pSerHead->CommProp.dwProvCapabilities =
PCF_DTRDSR | PCF_RLSD | PCF_RTSCTS |
PCF_SETXCHAR | PCF_INTTIMEOUTS |
PCF_PARITY_CHECK | PCF_SPECIALCHARS |
PCF_TOTALTIMEOUTS | PCF_XONXOFF;
pSerHead->CommProp.dwSettableBaud =
BAUD_075 | BAUD_110 | BAUD_150 | BAUD_300 |
BAUD_600 | BAUD_1200 | BAUD_1800 | BAUD_2400 |
BAUD_4800 | BAUD_7200 | BAUD_9600 | BAUD_14400 |
BAUD_19200 | BAUD_38400 | BAUD_56K | BAUD_128K |
BAUD_115200 | BAUD_57600 | BAUD_USER;
pSerHead->CommProp.dwSettableParams =
SP_BAUD | SP_DATABITS | SP_HANDSHAKING | SP_PARITY |
SP_PARITY_CHECK | SP_RLSD | SP_STOPBITS;
pSerHead->CommProp.wSettableData = DATABITS_7 | DATABITS_8;
pSerHead->CommProp.wSettableStopParity = STOPBITS_10 | STOPBITS_20 |
PARITY_NONE | PARITY_ODD | PARITY_EVEN;
pSerHead->fIRMode = bIR;
SL_Init(bIR, type, pSerHead->dwIOBase, pSerHead->pBaseAddress,
pSerHead, EvaluateEventFlag, pMDDContext, (PLOOKUP_TBL)&BaudTable);
return (pSerHead);
}
else {
if (pSerHead->pBaseAddress)
MmUnmapIoSpace(pSerHead->pBaseAddress, pSerHead->dwIOLen);
LocalFree(pSerHead);
DEBUGMSG(ZONE_FUNCTION, (TEXT("SerInit - Initialization failed!!\r\n")));
return (NULL);
}
}
//-----------------------------------------------------------------------------
//
// Function: SerSerialInit
//
// This function calls SerInit to initialize serial device.
//
// Parameters:
// Identifier
// [in] Device identifier.
// pMDDContext
// [in] First argument to mdd callbacks.
// pHWObj
// [in] Pointer to our own HW OBJ for this device.
//
// Returns:
// The return value is a PVOID to be passed back
// into the HW dependent layer when HW functions are
// called.
//
//-----------------------------------------------------------------------------
static PVOID SerSerialInit( ULONG Identifier, PVOID pMDDContext, PHWOBJ pHWObj )
{
DEBUGMSG(ZONE_FUNCTION,(TEXT("SerSerialInit+\r\n")));
return (SerInit(FALSE, Identifier, pMDDContext, pHWObj));
}
//-----------------------------------------------------------------------------
//
// Function: SerIRInit
//
// This function calls SerInit to initialize serial IR device.
//
// Parameters:
// Identifier
// [in] Device identifier.
// pMDDContext
// [in] First argument to mdd callbacks.
// pHWObj
// [in] Pointer to our own HW OBJ for this device.
//
// Returns:
// The return value is a PVOID to be passed back
// into the HW dependent layer when HW functions are
// called.
//
//-----------------------------------------------------------------------------
static PVOID SerIRInit( ULONG Identifier, PVOID pMDDContext, PHWOBJ pHWObj )
{
DEBUGMSG(ZONE_FUNCTION,(TEXT("SerIRInit+\r\n")));
return (SerInit(TRUE, Identifier, pMDDContext, pHWObj));
}
//-----------------------------------------------------------------------------
//
// Function: SerPostInit
//
// This function is called by the upper layer to
// perform any necessary operations after initializing
// all data structures and prepare the serial IST to
// begin handling interrupts. This call occurs as the
// last step of the COM_Init routine.
//
// 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 SerPostInit( PVOID pContext )
{
DEBUGMSG(ZONE_FUNCTION,(TEXT("SerPostInit+\r\n")));
// Since we are just a library which might get used for
// builtin ports which init at boot, or by PCMCIA ports
// which init at Open, we can't do anything too fancy.
// Lets just make sure we cancel any pending interrupts so
// that if we are being used with an edge triggered PIC, he
// will see an edge after the MDD hooks the interrupt.
SL_ClearPendingInts( pContext );
DEBUGMSG(ZONE_FUNCTION,(TEXT("SerPostInit-\r\n")));
return(TRUE);
}
//-----------------------------------------------------------------------------
//
// Function: SerOpen
//
// This function is called by the upper layer to
// open the serial device. This function applies
// power to the serial hardware.
//
// 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 SerOpen( PVOID pContext )
{
PSER_INFO pSerHead = (PSER_INFO)pContext;
DEBUGMSG(ZONE_OPEN,(TEXT("SerOpen+ \r\n")));
// Disallow multiple simultaneous opens
if (pSerHead->cOpenCount)
return (FALSE);
pSerHead->cOpenCount++;
SL_Reset(pSerHead);
SL_Open(pSerHead);
SL_SetOutputMode(pSerHead, pSerHead->fIRMode, !pSerHead->fIRMode);
DEBUGMSG(ZONE_OPEN,(TEXT("SerOpen-\r\n")));
return (TRUE);
}
//-----------------------------------------------------------------------------
//
// Function: SerClose
//
// This function is called by the upper layer to
// close the serial device.
//
// Parameters:
// pContext
// [in] Pointer to a context structure returned
// by SerInit function that contains implementation-
// specific data describing the hardware device.
//
// Returns:
// Zero indicates success.
//
//-----------------------------------------------------------------------------
static ULONG SerClose( PVOID pContext )
{
PSER_INFO pSerHead = (PSER_INFO)pContext;
ULONG uTries;
DEBUGMSG(ZONE_CLOSE,(TEXT("SerClose+ \r\n")));
if (pSerHead->cOpenCount) {
DEBUGMSG(ZONE_CLOSE, (TEXT("SerClose - closing device\r\n")));
pSerHead->cOpenCount--;
// while we are still transmitting, sleep.
uTries = 0;
while(!(pSerHead->uart_info.pUartReg->USR2 & 0x00004000)
&& (uTries++ < 100)){ // TxFifo not empty..
DEBUGMSG(ZONE_WARN, (TEXT("SerClose, TX in progress.\r\n")));
Sleep(10);
}
// When the device is closed, we power it down.
SL_Close(pSerHead);
}
DEBUGMSG(ZONE_CLOSE,(TEXT("SerClose-\r\n")));
return (0);
}
//-----------------------------------------------------------------------------
//
// Function: SerDeinit
//
// This function is called by the upper layer to
// de-initialize the serial device.
//
// 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_FUNCTION, (TEXT("SerDeinit+\r\n")));
if (!pSerHead)
return (FALSE);
// Make sure device is closed before doing DeInit
if (pSerHead->cOpenCount)
SerClose( pContext );
// Release SYSINTR
KernelIoControl(IOCTL_HAL_RELEASE_SYSINTR, &pSerHead->pHWObj->dwIntID, sizeof(DWORD), NULL, 0, NULL);
pSerHead->pHWObj->dwIntID = SYSINTR_UNDEFINED;
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_FUNCTION, (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 )
{
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?