|
这是微软给ce5.0的 init函数
- PVOID
- SerInit(
- 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
- )
- {
- DEBUGMSG (ZONE_CLOSE,(TEXT("+SerInit, 0x%X\r\n"), Identifier));
- CSerialPDD * pSerialPDD = NULL;
- if (pHWObj) {
- DWORD dwIndex= pHWObj->dwIntID;
- pHWObj->dwIntID = 0;
- pSerialPDD = CreateSerialObject((LPTSTR)Identifier,pMddHead, pHWObj,dwIndex);
- }
- if (pSerialPDD==NULL) {
- ASSERT(FALSE);
- LocalFree(pHWObj);
- }
- DEBUGMSG (ZONE_CLOSE,(TEXT("-SerInit, 0x%X\r\n"), pSerialPDD));
- return pSerialPDD;
- }
复制代码
]
这是4.2移植到5.0的代码
- static
- PVOID
- SerInit(
- BOOL bIR,
- 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_INFO pHWHead;
- #ifdef EXAMINE_BOOTARGS
- PVOID *ppBootArgs = NULL; // Pointer to pointer to bootargs.
- PHYSICAL_ADDRESS PhysicalAddress = {0,0};
- #endif
- // Note on defaults. While the PC typcially considers COM1 to be at
- // 3F8, irq4 and COM2 to be 2F8, irq3, NKPC uses COM1 internally for the
- // debugger. So, when NK tells me to start "COM1" it really means the
- // first one that's available, which is what the PC calls COM2. Confused?
- // The end result is that COM1 on NK is what the PC considers to be COM2.
- // But wait, there's more. On a Puzzle, the debugger is on COM2 and the
- // COM1 for NK is ACTUALLY COM1. So PCs need 2F8 for their port base
- // and Puzzles need 3F8.
- RETAILMSG(DEBUGMODE, (TEXT("SerInit - !!! \r\n")));
- // Allocate for our main data structure and one of it's fields.
- pHWHead = (PSER_INFO)LocalAlloc( LMEM_ZEROINIT|LMEM_FIXED, sizeof(SER_INFO) );
- if ( !pHWHead )
- return( NULL );
- RETAILMSG(DEBUGMODE, (TEXT("SerInit 1- !!! \r\n")));
- if ( ! Ser_GetRegistryData(pHWHead, (LPCTSTR)Identifier) )
- {
- RETAILMSG(DEBUGMODE, (TEXT("SerInit2 - !!! \r\n")));
- DEBUGMSG (ZONE_INIT|ZONE_ERROR, (TEXT("SerInit - Unable to read registry data. Failing Init !!! \r\n")));
- goto ALLOCFAILED;
- }
- RETAILMSG(DEBUGMODE, (TEXT("SerInit 3- !!! \r\n")));
- pHWHead->pBaseAddress = Ser_InternalMapRegisterAddresses(pHWHead->dwIOBase, pHWHead->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;
- RETAILMSG(DEBUGMODE, (TEXT("SerInitxxx - !!! \r\n")));
- if ( ppBootArgs = MmMapIoSpace(PhysicalAddress, sizeof( PVOID ), TRUE ) )
- {
- DEBUGMSG (ZONE_INIT, (TEXT("SerInit - ppBootArgs (%X) at %X\r\n"), PhysicalAddress.LowPart, ppBootArgs ));
- }
- else
- {
- RETAILMSG(DEBUGMODE, (TEXT("SerInit 22222- !!! \r\n")));
- DEBUGMSG (ZONE_INIT | ZONE_ERROR, (TEXT("SerInit - ppBootArgs failure at %X\r\n"), PhysicalAddress.LowPart ));
- goto ALLOCFAILED;
- }
- RETAILMSG(DEBUGMODE, (TEXT("SerInit 11111- !!! \r\n")));
- // Now map the bootargs structure itself
- PhysicalAddress.LowPart = (DWORD) *ppBootArgs;
- if ( pHWHead->pBootArgs = MmMapIoSpace(PhysicalAddress, sizeof(BOOT_ARGS), TRUE ) )
- {
- DEBUGMSG (ZONE_INIT, (TEXT("SerInit - pBootArgs (%X) at %X\r\n"), PhysicalAddress.LowPart, pHWHead->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("SerInit4 - !!! \r\n")));
- pHWHead->pMddHead = pMddHead;
- pHWHead->pHWObj = pHWObj;
- pHWHead->cOpenCount = 0;
- RETAILMSG(DEBUGMODE,(TEXT("SerInit - IRQ %d = SYSINTR %d\r\n"),
- pHWHead->dwIRQ, pHWHead->pHWObj->dwIntID));
- // Set up our Comm Properties data
- pHWHead->CommProp.wPacketLength = 0xffff;
- pHWHead->CommProp.wPacketVersion = 0xffff;
- pHWHead->CommProp.dwServiceMask = SP_SERIALCOMM;
- pHWHead->CommProp.dwReserved1 = 0;
- pHWHead->CommProp.dwMaxTxQueue = 16;
- pHWHead->CommProp.dwMaxRxQueue = 16;
- pHWHead->CommProp.dwMaxBaud = BAUD_115200;
- pHWHead->CommProp.dwProvSubType = PST_RS232;
- pHWHead->CommProp.dwProvCapabilities =
- PCF_DTRDSR | PCF_RLSD | PCF_RTSCTS |
- PCF_SETXCHAR |
- PCF_INTTIMEOUTS |
- PCF_PARITY_CHECK |
- PCF_SPECIALCHARS |
- PCF_TOTALTIMEOUTS |
- PCF_XONXOFF;
- pHWHead->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;
- pHWHead->CommProp.dwSettableParams =
- SP_BAUD | SP_DATABITS | SP_HANDSHAKING | SP_PARITY |
- SP_PARITY_CHECK | SP_RLSD | SP_STOPBITS;
- pHWHead->CommProp.wSettableData =
- DATABITS_5 | DATABITS_6 | DATABITS_7 | DATABITS_8;
- pHWHead->CommProp.wSettableStopParity =
- STOPBITS_10 | STOPBITS_20 |
- PARITY_NONE | PARITY_ODD | PARITY_EVEN | PARITY_SPACE |
- PARITY_MARK;
- pHWHead->fIRMode = bIR;
- pHWHead->s2440COM.UseIrDA = bIR;
- #ifdef EXAMINE_BOOTARGS
- // Don't actually init the hardware if it is being used for debugging
- 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)) ) {
- DEBUGMSG (ZONE_INIT|ZONE_ERROR, (TEXT("\r\nSerInit - Skipping hardware init of debug port\r\n\r\n")));
- } else
- #endif
- {
- DEBUGMSG (ZONE_INIT|USERDBG, (TEXT("SerInit - Init 16550 data\r\n")));
- SL_Init( pHWHead, pHWHead->pBaseAddress, 1,
- EvaluateEventFlag, pMddHead, (PLOOKUP_TBL)&BaudTable);
- DEBUGMSG (ZONE_INIT,
- (TEXT("SerInit - Disabling UART Power\r\n")));
- SerSetOutputMode(pHWHead, FALSE, FALSE );
- }
- return (pHWHead);
- ALLOCFAILED:
- if ( pHWHead->pBaseAddress )
- VirtualFree(pHWHead->pBaseAddress, 0, MEM_RELEASE);
- if ( ppBootArgs )
- MmUnmapIoSpace( ppBootArgs, sizeof( PVOID ) );
- if ( pHWHead->pBootArgs )
- MmUnmapIoSpace( pHWHead->pBootArgs, sizeof(BOOT_ARGS) );
- LocalFree(pHWHead);
- return (NULL);
- }
复制代码
明显思路很清楚。。。 |
|