📄 ser2440_ser.c
字号:
PHWOBJ pHWObj // @parm Pointer to our own HW OBJ for this device
)
{
return (SerInit(FALSE, Identifier, pMddHead, pHWObj));
}
PVOID
SerInitSerial2(
ULONG Identifier, // @parm Device identifier.
PVOID pMddHead, // @parm First argument to mdd callbacks.
PHWOBJ pHWObj // @parm Pointer to our own HW OBJ for this device
)
{
return (SerInit(FALSE, Identifier, pMddHead, pHWObj));
}
PVOID
SerInitSerial3(
ULONG Identifier, // @parm Device identifier.
PVOID pMddHead, // @parm First argument to mdd callbacks.
PHWOBJ pHWObj // @parm Pointer to our own HW OBJ for this device
)
{
return (SerInit(FALSE, Identifier, pMddHead, pHWObj));
}
PVOID
SerInitIR(
ULONG Identifier, // @parm Device identifier.
PVOID pMddHead, // @parm First argument to mdd callbacks.
PHWOBJ pHWObj // @parm Pointer to our own HW OBJ for this device
)
{
return (SerInit(TRUE, Identifier, pMddHead, pHWObj));
}
/*
@doc OEM
@func ULONG | SerClose | This routine closes the device identified by the PVOID returned by SerInit.
* Not exported to users, only to driver.
*
@rdesc The return value is 0.
*/
static
ULONG
SerClose(
PVOID pHead // @parm PVOID returned by SerInit.
)
{
PSER_INFO pHWHead = (PSER_INFO)pHead;
ULONG uTries;
RETAILMSG (DEBUGMODE,(TEXT("+SerClose\r\n")));
if ( pHWHead->cOpenCount )
{
DEBUGMSG (ZONE_CLOSE, (TEXT("SerClose, closing device\r\n")));
pHWHead->cOpenCount--;
// while we are still transmitting, sleep.
uTries = 0;
while((pHWHead->s2440COM.s2440SerReg->rUFSTAT & SER2440_FIFOSTAT_MASK) & (uTries++ < 100)) // TxFifo not empty..
{
DEBUGMSG (ZONE_CLOSE, (TEXT("SerClose, TX in progress.\r\n")));
Sleep(10);
}
// When the device is closed, we power it down.
DEBUGMSG (ZONE_CLOSE, (TEXT("SerClose - Powering down UART\r\n")));
pHWHead->fIRMode = FALSE;
SerSetOutputMode(pHWHead, FALSE, FALSE );
DEBUGMSG (ZONE_CLOSE, (TEXT("SerClose - Calling SL_Close\r\n")));
SL_Close( pHWHead );
}
RETAILMSG(DEBUGMODE,(TEXT("-SerClose\r\n")));
return (0);
}
/*
@doc OEM
@func PVOID | SerDeinit | Deinitializes device identified by argument.
* This routine frees any memory allocated by SerInit.
*
*/
static
BOOL
SerDeinit(PVOID pHead) // @parm PVOID returned by SerInit.
{
PSER_INFO pHWHead = (PSER_INFO)pHead;
DEBUGMSG (1, (TEXT("SerDeinit\r\n")));
RETAILMSG(1,(TEXT("SerDeinit \r\n")));
if ( !pHWHead )
return (FALSE);
// Make sure device is closed before doing DeInit
if ( pHWHead->cOpenCount )
SerClose( pHead );
SL_Deinit( pHead );
if ( pHWHead->pBaseAddress )
VirtualFree(pHWHead->pBaseAddress, 0, MEM_RELEASE);
if ( pHWHead->pBootArgs )
MmUnmapIoSpace( pHWHead->pBootArgs, sizeof(BOOT_ARGS) );
// Free the HWObj
LocalFree(pHWHead->pHWObj);
// And now free the SER_INFO structure.
LocalFree(pHWHead);
return (TRUE);
}
/*
@doc OEM
@func VOID | SerGetCommProperties | Retrieves Comm Properties.
*
@rdesc None.
*/
static
VOID
SerGetCommProperties(
PVOID pHead, // @parm PVOID returned by SerInit.
LPCOMMPROP pCommProp // @parm Pointer to receive COMMPROP structure.
)
{
PSER_INFO pHWHead = (PSER_INFO)pHead;
RETAILMSG(DEBUGMODE,(TEXT("+SerGetCommProperties\r\n")));
*pCommProp = pHWHead->CommProp;
return;
}
/*
@doc OEM
@func VOID | SerSetBaudRate |
* This routine sets the baud rate of the device.
* Not exported to users, only to driver.
*
@rdesc None.
*/
static
BOOL
SerSetBaudRate(
PVOID pHead, // @parm PVOID returned by SerInit
ULONG BaudRate // @parm ULONG representing decimal baud rate.
)
{
PSER_INFO pHWHead = (PSER_INFO)pHead;
RETAILMSG(DEBUGMODE,(TEXT("IRDA : SerSetBaudRate \r\n")));
// If we are running in IR mode, try to set the IR baud
// first, since it supports a subset of the rates supported
// by the UART. If we fail setting the IR rate, then
// return an error and leave the UART alone.
if ( IRDA )
{
if ( ! SerSetIRBaudRate( pHWHead, BaudRate ) )
{
DEBUGMSG (ZONE_ERROR,
(TEXT("Unsupported IR BaudRate\r\n")));
// We should return an error, but vtbl doesn't expect one
return (FALSE);
}
}
// Now set buadrate on the UART
return ( SL_SetBaudRate( pHead, BaudRate ) );
}
/*
@doc OEM
@func BOOL | SerPowerOff |
* Called by driver to turn off power to serial port.
* Not exported to users, only to driver.
*
@rdesc This routine returns a status.
*/
BOOL
SerPowerOff(PVOID pHead) // @parm PVOID returned by SerInit.
{
PSER_INFO pHWHead = (PSER_INFO)pHead;
RETAILMSG(DEBUGMODE,(TEXT("SerPowerOff\r\n")));
SerClose( pHWHead );
// First, power down the UART
SL_PowerOff( pHWHead );
// And then disable our IR and 9 Pin interface
SerSetOutputMode( pHWHead, FALSE, FALSE );
return (TRUE);
}
/*
@doc OEM
@func BOOL | SerPowerOn |
* Called by driver to turn on power to serial port.
* Not exported to users, only to driver.
*
@rdesc This routine returns a status.
*/
BOOL
SerPowerOn(PVOID pHead) // @parm PVOID returned by SerInit.
{
PSER_INFO pHWHead = (PSER_INFO)pHead;
RETAILMSG(DEBUGMODE,(TEXT("SerPowerOn\r\n")));
// First, power up the UART
SL_PowerOn( pHWHead );
// And then enable our IR interface (if needed)
SerSetOutputMode( pHWHead, pHWHead->fIRMode, !pHWHead->fIRMode );
return (TRUE);
}
/*
@doc OEM
@func BOOL | SerEnableIR | This routine enables ir.
* Not exported to users, only to driver.
*
@rdesc Returns TRUE if successful, FALSEotherwise.
*/
static
BOOL
SerEnableIR(
PVOID pHead, // @parm PVOID returned by Serinit.
ULONG BaudRate // @parm PVOID returned by HWinit.
)
{
PSER_INFO pHWHead = (PSER_INFO)pHead;
RETAILMSG(DEBUGMODE,(TEXT("SerEnableIR\r\n")));
pHWHead->fIRMode = TRUE;
SerSetOutputMode( pHWHead, pHWHead->fIRMode, !pHWHead->fIRMode );
return (TRUE);
}
/*
@doc OEM
@func BOOL | SerDisableIR | This routine disable the ir.
* Not exported to users, only to driver.
*
@rdesc Returns TRUE if successful, FALSEotherwise.
*/
static
BOOL
SerDisableIR(PVOID pHead) // @parm PVOID returned by Serinit.
{
PSER_INFO pHWHead = (PSER_INFO)pHead;
RETAILMSG(DEBUGMODE,(TEXT("SerDisableIR\r\n")));
pHWHead->fIRMode = FALSE;
SerSetOutputMode( pHWHead, pHWHead->fIRMode, !pHWHead->fIRMode );
return (TRUE);
}
/*
@doc OEM
@func BOOL | SerEnableIR | This routine enables ir.
* Not exported to users, only to driver.
*
@rdesc Returns TRUE if successful, FALSEotherwise.
*/
static
BOOL
SerEnableSerial(
PVOID pHead, // @parm PVOID returned by Serinit.
ULONG BaudRate // @parm PVOID returned by HWinit.
)
{
PSER_INFO pHWHead = (PSER_INFO)pHead;
RETAILMSG(DEBUGMODE,(TEXT("SerEnableSerial\r\n")));
pHWHead->fIRMode = FALSE;
SerSetOutputMode( pHWHead, pHWHead->fIRMode, !pHWHead->fIRMode );
return (TRUE);
}
/*
@doc OEM
@func BOOL | SerDisableIR | This routine disable the ir.
* Not exported to users, only to driver.
*
@rdesc Returns TRUE if successful, FALSEotherwise.
*/
static
BOOL
SerDisableSerial(PVOID pHead) // @parm PVOID returned by Serinit.
{
PSER_INFO pHWHead = (PSER_INFO)pHead;
RETAILMSG(DEBUGMODE,(TEXT("SerDisableSerial\r\n")));
pHWHead->fIRMode = TRUE;
SerSetOutputMode( pHWHead, pHWHead->fIRMode, !pHWHead->fIRMode );
return (TRUE);
}
/*
@doc OEM
@func BOOL | SerOpen | This routine is called when the port is opened.
* Not exported to users, only to driver.
*
@rdesc Returns TRUE if successful, FALSEotherwise.
*/
static
BOOL
SerOpen(PVOID pHead) // @parm PVOID returned by Serinit.
{
PSER_INFO pHWHead = (PSER_INFO)pHead;
// Disallow multiple simultaneous opens
if ( pHWHead->cOpenCount )
return (FALSE);
//RETAILMSG(1, (TEXT("seropen 1\r\n")));
#ifdef EXAMINE_BOOTARGS
RETAILMSG(DEBUGMODE, (TEXT("SerOpen - Bootargs ComPort %x\r\n"), pHWHead->pBootArgs->ucComPort));
// If the port is in use as a debugger port, don't allow opens.
if ( ((pHWHead->pBootArgs->ucComPort == 1) && (pHWHead->dwIOBase == COM1_BASE)) ||
((pHWHead->pBootArgs->ucComPort == 2) && (pHWHead->dwIOBase == COM2_BASE)) ||
((pHWHead->pBootArgs->ucComPort == 3) && (pHWHead->dwIOBase == COM3_BASE)) ||
((pHWHead->pBootArgs->ucComPort == 4) && (pHWHead->dwIOBase == COM4_BASE)) )
{
RETAILMSG (DEBUGMODE, (TEXT("SerOpen - Fail open of debug port\r\n")));
return (FALSE);
}
#endif
//RETAILMSG(1, (TEXT("seropen 2\r\n")));
pHWHead->cOpenCount++;
if ( pHWHead->fIRMode == TRUE )
RETAILMSG(DEBUGMODE,(TEXT("Use IrDA \r\n")));
else
RETAILMSG(DEBUGMODE,(TEXT("Use Serail \r\n")));
SerSetOutputMode(pHWHead, pHWHead->fIRMode, !pHWHead->fIRMode );
// NOTE: - If we wanted to support 16450s, we'll could dynamically
// identify them here.
// Init SER2440 info
RETAILMSG(DEBUGMODE, (TEXT("SerOpen - Calling SL_Open\r\n")));
SL_Open( pHWHead );
RETAILMSG(DEBUGMODE, (TEXT("SerOpen - Return TRUE\r\n")));
RETAILMSG(DEBUGMODE, (TEXT("seropen end\r\n")));
return (TRUE);
}
//for 16C552
static
PVOID
Ser4Init(
ULONG Identifier, // @parm Device identifier.
PVOID pMddHead, // @parm First argument to mdd callbacks.
PHWOBJ pHWObj // @parm Pointer to our own HW OBJ for this device
)
{
PSER_16552_INFO pHWHeadq;
#ifdef EXAMINE_BOOTARGS
PVOID *ppBootArgs = NULL; // Pointer to pointer to bootargs.
PHYSICAL_ADDRESS PhysicalAddress = {0,0};
#endif
RETAILMSG(QYDEBUG,(TEXT("Ser4Init begin\r\n")));
// Allocate for our main data structure and one of it's fields.
pHWHeadq = (PSER_16552_INFO)LocalAlloc( LMEM_ZEROINIT|LMEM_FIXED ,
sizeof(SER_16552_INFO) );
if ( !pHWHeadq )
{
RETAILMSG(QYDEBUG,(TEXT("SERILA4 SerInit memory alloc failed")));
goto ALLOCFAILED;
}
if ( ! Ser4_GetRegistryData(pHWHeadq, (LPCTSTR)Identifier) ) {
DEBUGMSG (ZONE_INIT|ZONE_ERROR,
(TEXT("SerInit - Unable to read registry data. Failing Init !!! \r\n")));
goto ALLOCFAILED;
}
pHWHeadq->pBaseAddress = Ser_InternalMapRegisterAddresses(pHWHeadq->dwIOBase, pHWHeadq->dwIOLen);
#ifdef EXAMINE_BOOTARGS
// Allocate a pointer to our bootargs since they may indicate that we don't have
// access to the hardware resource.
// First, map the bootargs pointer itself. Note that I'm reading/writing
// directly on the physical address. I can do this since I know this is CEPC and
// know the adress is not in IO space. For OEM platforms you would want to do
// HalTranslateBusAddress first.
PhysicalAddress.LowPart = BOOT_ARG_PTR_LOCATION & ~0x80000000;
if ( ppBootArgs = MmMapIoSpace(PhysicalAddress, sizeof( PVOID ), TRUE ) ) {
DEBUGMSG (ZONE_INIT,
(TEXT("SerInit - ppBootArgs (%X) at %X\r\n"),
PhysicalAddress.LowPart, ppBootArgs ));
} else {
DEBUGMSG (ZONE_INIT | ZONE_ERROR,
(TEXT("SerInit - ppBootArgs failure at %X\r\n"), PhysicalAddress.LowPart ));
goto ALLOCFAILED;
}
// Now map the bootargs structure itself
PhysicalAddress.LowPart = (DWORD) *ppBootArgs;
if ( pHWHeadq->pBootArgs = MmMapIoSpace(PhysicalAddress, sizeof(BOOT_ARGS), TRUE ) ) {
DEBUGMSG (ZONE_INIT,
(TEXT("SerInit - pBootArgs (%X) at %X\r\n"),
PhysicalAddress.LowPart, pHWHeadq->pBootArgs ));
} else {
DEBUGMSG (ZONE_INIT | ZONE_ERROR,
(TEXT("SerInit - pBootArgs failure at %X\r\n"),
(DWORD)PhysicalAddress.LowPart));
goto ALLOCFAILED;
}
// We no longer need ppBootArgs
MmUnmapIoSpace( ppBootArgs, sizeof(PVOID) );
#endif // EXAMINE_BOOTARGS
//RETAILMSG(DEBUGMODE,(TEXT("Ser4Init - IRQ %d = SYSINTR %d\r\n"),
//pHWHead->dwIRQ, pHWHead->pHWObj->dwIntID));
pHWHeadq->pMddHead = pMddHead;
pHWHeadq->pHWObj = pHWObj;
pHWHeadq->cOpenCount = 0;
// Set up our Comm Properties data
pHWHeadq->CommProp.wPacketLength = 0xffff;
pHWHeadq->CommProp.wPacketVersion = 0xffff;
pHWHeadq->CommProp.dwServiceMask = SP_SERIALCOMM;
pHWHeadq->CommProp.dwReserved1 = 0;
pHWHeadq->CommProp.dwMaxTxQueue = 16;
pHWHeadq->CommProp.dwMaxRxQueue = 16;
pHWHeadq->CommProp.dwMaxBaud = BAUD_115200;
pHWHeadq->CommProp.dwProvSubType = PST_RS232;
pHWHeadq->CommProp.dwProvCapabilities =
PCF_DTRDSR | PCF_RLSD | PCF_RTSCTS |
PCF_SETXCHAR |
PCF_INTTIMEOUTS |
PCF_PARITY_CHECK |
PCF_SPECIALCHARS |
PCF_TOTALTIMEOUTS |
PCF_XONXOFF;
pHWHeadq->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;
pHWHeadq->CommProp.dwSettableParams =
SP_BAUD | SP_DATABITS | SP_HANDSHAKING | SP_PARITY |
SP_PARITY_CHECK | SP_RLSD | SP_STOPBITS;
pHWHeadq->CommProp.wSettableData =
DATABITS_5 | DATABITS_6 | DATABITS_7 | DATABITS_8;
pHWHeadq->CommProp.wSettableStopParity =
STOPBITS_10 | STOPBITS_20 |
PARITY_NONE | PARITY_ODD | PARITY_EVEN | PARITY_SPACE |
PARITY_MARK;
pHWHeadq->fIRMode = FALSE; // Select wired by default
RETAILMSG(QYDEBUG,(TEXT("Ser4Init before SL_Initq\r\n")));
SL_Initq( pHWHeadq, pHWHeadq->pBaseAddress, 1,
EvaluateEventFlag, pMddHead, (PLOOKUP_TBL)&LS_SER_BaudTable);
RETAILMSG(QYDEBUG,(TEXT("Ser4Init after SL_Initq\r\n")));
RETAILMSG(QYDEBUG,(TEXT("Ser4Init pHWHeadq=0x%X\r\n"),pHWHeadq));
return (pHWHeadq);
ALLOCFAILED:
if ( pHWHeadq->pBaseAddress )
VirtualFree(pHWHeadq->pBaseAddress, 0, MEM_RELEASE);
LocalFree(pHWHeadq);
RETAILMSG(QYDEBUG,(TEXT("Ser4Init end\r\n")));
return (NULL);
}
//for 16C552
static
BOOL
Ser4Open(
PVOID pHead /*@parm PVOID returned by Serinit. */
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -