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

📄 ser2410_hw.c

📁 SBC2410 WinCE 5.0 BSP.绝大多数驱动已经调通。
💻 C
📖 第 1 页 / 共 5 页
字号:
	RETAILMSG (DEBUGMODE, (TEXT("SL_ModemIntr - pHWHead->OpenCount %d \r\n"), pHWHead->OpenCount));
	if ( !pHWHead->OpenCount ) {
		// We want to indicate a cable event.
		RETAILMSG (DEBUGMODE, (TEXT("Indicating RS232 Cable Event\r\n")));

		if ( IsAPIReady(SH_WMGR) ) {
			CeEventHasOccurred (NOTIFICATION_EVENT_RS232_DETECTED,NULL);
		}
	}
	else
	{
		RETAILMSG(1,(TEXT("+SL_ModemIntr 0x%X\r\n"), pHead));
		SL_OtherIntr(pHead);
	}
}

//  
// @doc OEM
// @func    ULONG | SL_GetStatus | This structure is called by the MDD
//   to retrieve the contents of a COMSTAT structure.
//
// @rdesc    The return is a ULONG, representing success (0) or failure (-1).
//
ULONG
SL_GetStatus(
            PVOID    pHead,    // @parm PVOID returned by HWInit.
            LPCOMSTAT    lpStat    // Pointer to LPCOMMSTAT to hold status.
            )
{
    PS2410_UART_INFO pHWHead = (PS2410_UART_INFO)pHead;
    ULONG      RetVal  = pHWHead->CommErrors;

	RETAILMSG(1, (TEXT("+SL_GetStatus 0x%X\r\n"), pHead));
	pHWHead->CommErrors = 0; // Clear old errors each time

    if ( lpStat ) {
        try {
            if (pHWHead->CTSFlowOff)
                pHWHead->Status.fCtsHold = 1;
            else
                pHWHead->Status.fCtsHold = 0;

            if (pHWHead->DSRFlowOff)
                pHWHead->Status.fDsrHold = 1;
            else
                pHWHead->Status.fDsrHold = 0;

            // NOTE - I think what they really want to know here is
            // the amount of data in the MDD buffer, not the amount
            // in the UART itself.  Just set to 0 for now since the
            // MDD doesn't take care of this.
            pHWHead->Status.cbInQue  = 0;
            pHWHead->Status.cbOutQue = 0;

            memcpy(lpStat, &(pHWHead->Status), sizeof(COMSTAT));
        }
        except (GetExceptionCode() == EXCEPTION_ACCESS_VIOLATION ?
                EXCEPTION_EXECUTE_HANDLER : EXCEPTION_CONTINUE_SEARCH) {
            RetVal = (ULONG)-1;
        }        
    } else
        RetVal = (ULONG)-1;

    DEBUGMSG (ZONE_FUNCTION,
              (TEXT("-SL_GetStatus 0x%X\r\n"), pHead));
    return(RetVal);
}

//
// @doc OEM
// @func    ULONG | SL_Reset | Perform any operations associated
//   with a device reset
//
// @rdesc    None.
//
VOID
SL_Reset(
        PVOID   pHead    // @parm PVOID returned by HWInit.
        )
{
	PS2410_UART_INFO pHWHead = (PS2410_UART_INFO)pHead;

	RETAILMSG(DEBUGMODE,(TEXT("+SL_Reset 0x%X\r\n"), pHead));

	memset(&pHWHead->Status, 0, sizeof(COMSTAT));

	EnterCriticalSection(&(pHWHead->RegCritSec));
	try {
		DisEnINT(pHWHead, pHWHead->bINT);
		DisEnSubINT(pHWHead, pHWHead->bTxINT);
		//	if ( GetSubINTStatus(pHWHead) )
		pHWHead->fSW_EnTxINT = FALSE;
		pHWHead->RxDiscard = FALSE;
	}
	except (GetExceptionCode() == EXCEPTION_ACCESS_VIOLATION ?
		EXCEPTION_EXECUTE_HANDLER : EXCEPTION_CONTINUE_SEARCH) {
		// Do nothing
	}
	LeaveCriticalSection(&(pHWHead->RegCritSec));

	DEBUGMSG (ZONE_FUNCTION,
			(TEXT("-SL_Reset 0x%X\r\n"), pHead));
}

//
// @doc OEM
// @func    VOID | SL_GetModemStatus | Retrieves modem status.
//
// @rdesc    None.
//
VOID
SL_GetModemStatus(
                 PVOID   pHead,        // @parm PVOID returned by HWInit.
                 PULONG  pModemStatus    // @parm PULONG passed in by user.
                 )
{
	PS2410_UART_INFO pHWHead = (PS2410_UART_INFO)pHead;
	UINT8 ubModemStatus;

	RETAILMSG(DEBUGMODE,  (TEXT("SL_GetModemStatus:\r\n")));

	ReadMSR( pHWHead );
	ubModemStatus = (unsigned char)pHWHead->vUMSTAT;
	RETAILMSG(DEBUGMODE,  (TEXT("SL_GetModemStatus: ubModemStatus = 0x%x\r\n"), ubModemStatus));

	if ( ubModemStatus & COM2410_MSR_CTS )
		*pModemStatus |= MS_CTS_ON;
	if ( ubModemStatus & COM2410_MSR_DSR )  {
		*pModemStatus |= MS_DSR_ON;
		*pModemStatus |= MS_RLSD_ON;
	}

	RETAILMSG(DEBUGMODE,(TEXT("-SL_GetModemStatus 0x%X (stat x%X) \r\n"), pHead, *pModemStatus));
	return;
}

//
// @doc OEM
// @func    VOID | SL_PurgeComm | Purge RX and/or TX
// 
// @rdesc    None.
//

VOID
SL_PurgeComm(
            PVOID   pHead,        // @parm PVOID returned by HWInit.
            DWORD   fdwAction        // @parm Action to take. 
            )
{
	PS2410_UART_INFO pHWHead = (PS2410_UART_INFO)pHead;

	RETAILMSG(DEBUGMODE,(TEXT("+SL_PurgeComm 0x%X\r\n"), fdwAction));
	return;
}

//
// @doc OEM
// @func    BOOL | SL_XmitComChar | Transmit a char immediately
// 
// @rdesc    TRUE if succesful
//
BOOL
SL_XmitComChar(
              PVOID   pHead,    // @parm PVOID returned by HWInit.
              UCHAR   ComChar   // @parm Character to transmit. 
              )
{
	PS2410_UART_INFO pHWHead = (PS2410_UART_INFO)pHead;
	ULONG       rFifoStat, TxFifoCnt; 

	RETAILMSG (DEBUGMODE,(TEXT("+SL_XmitComChar 0x%X\r\n"), pHead));
	// Get critical section, then transmit when buffer empties
	RETAILMSG(DEBUGMODE, (TEXT("XmitComChar wait for CritSec %x.\r\n"),&(pHWHead->TransmitCritSec)));
	EnterCriticalSection(&(pHWHead->TransmitCritSec));
	RETAILMSG(DEBUGMODE, (TEXT("XmitComChar got CritSec %x.\r\n"),&(pHWHead->TransmitCritSec)));
	try {
		while ( TRUE ) {  // We know THR will eventually empty
			EnterCriticalSection(&(pHWHead->RegCritSec));
			// Write the character if we can
			rFifoStat = INREG(pHWHead,rUFSTAT);
			TxFifoCnt = (rFifoStat & SER2410_FIFOCNT_MASK_TX) >> 4;

			if (!(rFifoStat & SER2410_FIFOFULL_TX) && (TxFifoCnt < (SER2410_FIFO_DEPTH_TX-1))) {
				// FIFO is empty, send this character
				//OUTB(pHWHead, pData, ComChar);
				OUTREG(pHWHead,rUTXH,ComChar);
				// Make sure we release the register critical section
				LeaveCriticalSection(&(pHWHead->RegCritSec));

				RETAILMSG(DEBUGMODE, (TEXT("XmitComChar wrote x%X\r\n"),ComChar));
				break;
			}

			// If we couldn't write the data yet, then wait for a
			// TXINTR to come in and try it again.

			// Enable xmit intr.
			EnINT(pHWHead, pHWHead->bINT);
			EnSubINT(pHWHead, pHWHead->bTxINT | pHWHead->bRxINT | pHWHead->bErrINT);
			pHWHead->fSW_EnTxINT = TRUE;
			LeaveCriticalSection(&(pHWHead->RegCritSec));

			// Wait until the txintr has signalled.
			DEBUGMSG (ZONE_WRITE, (TEXT("XmitComChar WaitIntr x%X\r\n"),
						pHWHead->FlushDone));
			WaitForSingleObject(pHWHead->FlushDone, (ULONG)1000);
		}
	}
	except (GetExceptionCode() == EXCEPTION_ACCESS_VIOLATION ?
		EXCEPTION_EXECUTE_HANDLER : EXCEPTION_CONTINUE_SEARCH) {
		// Make sure we release the register critical section
		LeaveCriticalSection(&(pHWHead->RegCritSec));
	}

	LeaveCriticalSection(&(pHWHead->TransmitCritSec));
	DEBUGMSG (ZONE_WRITE, (TEXT("XmitComChar released CritSec %x.\r\n"),
					&(pHWHead->TransmitCritSec)));

	DEBUGMSG (ZONE_FUNCTION,
				(TEXT("-SL_XmitComChar 0x%X\r\n"), pHead));

	return(TRUE);
}

//
// @doc OEM
// @func    BOOL | SL_PowerOff | Perform powerdown sequence.
// 
// @rdesc    TRUE if succesful
//
VOID
SL_PowerOff(
           PVOID   pHead        // @parm    PVOID returned by HWInit.
           )
{
	PS2410_UART_INFO   pHWHead   = (PS2410_UART_INFO)pHead;

	RETAILMSG(DEBUGMODE, (TEXT("SL_PowerOff \r\n")));
	pHWHead->sULCON = INREG(pHWHead, rULCON);
	pHWHead->sUCON  = INREG(pHWHead, rUCON);
	pHWHead->sUMCON = INREG(pHWHead, rUMCON);
	pHWHead->sUFCON = INREG(pHWHead, rUFCON);        
	pHWHead->sINTstat = (*(pHWHead->UART_INTSUBMASK) & (pHWHead->bTxINT | pHWHead->bRxINT));
}

//
// @doc OEM
// @func    BOOL | SL_PowerOn | Perform poweron sequence.
// 
// @rdesc    TRUE if succesful
//
VOID
SL_PowerOn(
          PVOID   pHead        // @parm    PVOID returned by HWInit.
          )
{
	PS2410_UART_INFO pHWHead = (PS2410_UART_INFO)pHead;

	// Restore any registers that we need
	RETAILMSG(DEBUGMODE, (TEXT("SL_PowerOn \r\n")));

	// In power handler context, so don't try to do a critical section
	OUTREG(pHWHead, rULCON, pHWHead->sULCON); 
	OUTREG(pHWHead, rUCON,  pHWHead->sUCON); 
	OUTREG(pHWHead, rUMCON, pHWHead->sUMCON); 
	OUTREG(pHWHead, rUFCON, pHWHead->sUFCON); 
	if((pHWHead->sINTstat) & (pHWHead->bTxINT))  {
		EnINT(pHWHead, pHWHead->bINT);
		EnSubINT(pHWHead, pHWHead->bTxINT);
		pHWHead->fSW_EnTxINT = TRUE;
		pHWHead->RxDiscard = FALSE;
	}
	if((pHWHead->sINTstat) & (pHWHead->bRxINT))
	{
		EnINT(pHWHead, pHWHead->bINT);
		EnSubINT(pHWHead, pHWHead->bRxINT);
	}

	// And we didn't save the Divisor Reg, so set baud rate
	// But don't call SL_SetBaud, since it does DebugMsg.
	// Call our internal function instead.  Can't acquire
	// the RegCritSec, but shouldn't really need to since
	// we are in power context.
	SetBaudRate( pHWHead, pHWHead->dcb.BaudRate );
}

//
// @doc OEM
// @func    BOOL | SL_SetDCB | Sets new values for DCB.  This
// routine gets a DCB from the MDD.  It must then compare
// this to the current DCB, and if any fields have changed take
// appropriate action.
// 
// @rdesc    BOOL
//
BOOL
SL_SetDCB(
         PVOID   pHead,        // @parm    PVOID returned by HWInit.
         LPDCB   lpDCB       // @parm    Pointer to DCB structure
         )
{
	PS2410_UART_INFO pHWHead = (PS2410_UART_INFO)pHead;
	BOOL bRet;

	bRet = TRUE;

	RETAILMSG(DEBUGMODE,(TEXT("SL_SetDCB : BaudRate is %d\r\n"), lpDCB->BaudRate));
	RETAILMSG(DEBUGMODE,(TEXT("SL_SetDCB : Set ByteSize is %d\r\n"), lpDCB->ByteSize));
	RETAILMSG(DEBUGMODE,(TEXT("SL_SetDCB : Set Parity is %d\r\n"), lpDCB->Parity));
	RETAILMSG(DEBUGMODE,(TEXT("SL_SetDCB : Set StopBits is %d\r\n"), lpDCB->StopBits));

	// If the device is open, scan for changes and do whatever
	// is needed for the changed fields.  if the device isn't
	// open yet, just save the DCB for later use by the open.
	if ( pHWHead->OpenCount ) {
		// Note, fparity just says whether we should check
		// receive parity.  And the 16550 won't let us NOT
		// check parity if we generate it.  So this field
		// has no effect on the hardware.

		if ( lpDCB->BaudRate != pHWHead->dcb.BaudRate ) {
			RETAILMSG(DEBUGMODE,(TEXT("SL_SetDCB : Set BaudRate to %d\r\n"), lpDCB->BaudRate));
			bRet = SL_SetBaudRate( pHWHead, lpDCB->BaudRate );
		}

		if ( bRet && (lpDCB->ByteSize != pHWHead->dcb.ByteSize )) {
			RETAILMSG(DEBUGMODE,(TEXT("SL_SetDCB : Set ByteSize to %d\r\n"), lpDCB->ByteSize));
			bRet = SL_SetByteSize( pHWHead, lpDCB->ByteSize );
		}

		if ( bRet && (lpDCB->Parity != pHWHead->dcb.Parity )) {
			RETAILMSG(DEBUGMODE,(TEXT("SL_SetDCB : Set Parity to %d\r\n"), lpDCB->Parity));
			bRet = SL_SetParity( pHWHead, lpDCB->Parity );
		}

		if ( bRet && (lpDCB->StopBits != pHWHead->dcb.StopBits )) {
			RETAILMSG(DEBUGMODE,(TEXT("SL_SetDCB : Set StopBits to %d\r\n"), lpDCB->StopBits));
			bRet = SL_SetStopBits( pHWHead, lpDCB->StopBits );
		}

		// Don't worry about fOutxCtsFlow.  It is a flag which
		// will be examined every time we load the TX buffer.
		// No special action required here.
	}

	if (bRet) {
		// Now that we have done the right thing, store this DCB
		pHWHead->dcb = *lpDCB;
	}

	RETAILMSG(DEBUGMODE,(TEXT("-SL_SetDCB 0x%X\r\n"), pHead));

	return(bRet);
}

//
// @doc OEM
// @func    BOOL | SL_SetCommTimeouts | Sets new values for the
// CommTimeouts structure. routine gets a DCB from the MDD.  It
// must then compare this to the current DCB, and if any fields
// have changed take appropriate action.
// 
// @rdesc    ULONG
//
ULONG
SL_SetCommTimeouts(
                  PVOID   pHead,        // @parm    PVOID returned by HWInit.
                  LPCOMMTIMEOUTS   lpCommTimeouts // @parm Pointer to CommTimeout structure
                  )
{
	PS2410_UART_INFO pHWHead = (PS2410_UART_INFO)pHead;
	ULONG retval = 0;

	RETAILMSG(DEBUGMODE,(TEXT("+SL_SetCommTimeout 0x%X\r\n"), pHead));
//	ShowSerialRegisters(pHead);

	// OK, first check for any changes and act upon them
	if ( lpCommTimeouts->WriteTotalTimeoutMultiplier !=
		pHWHead->CommTimeouts.WriteTotalTimeoutMultiplier ) {
	}

	// Now that we have done the right thing, store this DCB
	pHWHead->CommTimeouts = *lpCommTimeouts;

	RETAILMSG(DEBUGMODE,(TEXT("-SL_SetCommTimeout 0x%X\r\n"), pHead));

	return(retval);
}



//
//  @doc OEM
//  @func    BOOL | SL_Ioctl | Device IO control routine.  
//  @parm DWORD | dwOpenData | value returned from COM_Open call
//    @parm DWORD | dwCode | io control code to be performed
//    @parm PBYTE | pBufIn | input data to the device
//    @parm DWORD | dwLenIn | number of bytes being passed in
//    @parm PBYTE | pBufOut | output data from the device
//    @parm DWORD | dwLenOut |maximum number of bytes to receive from device
//    @parm PDWORD | pdwActualOut | actual number of bytes received from device
//
//    @rdesc        Returns TRUE for success, FALSE for failure
//
//  @remark  The MDD will pass any unrecognized IOCTLs through to this function.
//
BOOL
SL_Ioctl(PVOID pHead, DWORD dwCode,PBYTE pBufIn,DWORD dwLenIn,
         PBYTE pBufOut,DWORD dwLenOut,PDWORD pdwActualOut)
{
	BOOL RetVal = TRUE;
	RETAILMSG(DEBUGMODE, (TEXT("+SL_Ioctl 0x%X\r\n"), pHead));
	switch (dwCode) {
	// Currently, no defined IOCTLs
	default:
		RetVal = FALSE;
		DEBUGMSG (ZONE_FUNCTION, (TEXT(" Unsupported ioctl 0x%X\r\n"), dwCode));
	break;            
	}
	RETAILMSG(DEBUGMODE, (TEXT("-SL_Ioctl 0x%X\r\n"), pHead));
	return(RetVal);
}


⌨️ 快捷键说明

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