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

📄 ser2410_hw.c

📁 SBC2410 WinCE 5.0 BSP.绝大多数驱动已经调通。
💻 C
📖 第 1 页 / 共 5 页
字号:
}

//
// @doc OEM
// @func VOID | SL_SetRTS | This routine sets RTS.
// 
// @rdesc None.
//
VOID
SL_SetRTS(
         PVOID   pHead // @parm PVOID returned by HWinit.
         )
{
	PS2410_UART_INFO   pHWHead   = (PS2410_UART_INFO)pHead;

	RETAILMSG(DEBUGMODE, (TEXT("+SL_SetRTS, 0x%X\r\n"), pHead));
	EnterCriticalSection(&(pHWHead->RegCritSec));
	try {
		SETREG(pHWHead, rUMCON, SER2410_RTS);
	}
	except (GetExceptionCode() == EXCEPTION_ACCESS_VIOLATION ?
		EXCEPTION_EXECUTE_HANDLER : EXCEPTION_CONTINUE_SEARCH) {
		// Just exit
	}
	LeaveCriticalSection(&(pHWHead->RegCritSec));
	RETAILMSG(DEBUGMODE, (TEXT("-SL_SetRTS, 0x%X\r\n"), pHead));
}

//
// @doc OEM
// @func VOID | SL_ClearBreak | This routine clears break.
// 
// @rdesc None.
// 
VOID
SL_ClearBreak(
             PVOID   pHead // @parm PVOID returned by HWinit.
             )
{
	PS2410_UART_INFO   pHWHead   = (PS2410_UART_INFO)pHead;

	RETAILMSG(DEBUGMODE,  (TEXT("SL_ClearBreak:\r\n"))); 
	// S2410 does not need to clear break signal, for cleared by automatic.
}

//
// @doc OEM
// @func VOID | SL_SetBreak | This routine sets break.
// 
// @rdesc None.
//
VOID
SL_SetBreak(
           PVOID   pHead // @parm PVOID returned by HWinit.
           )
{
	PS2410_UART_INFO    pHWHead = (PS2410_UART_INFO)pHead;

	RETAILMSG(DEBUGMODE, (TEXT("+SL_SetBreak, 0x%X\r\n"), pHead));
	EnterCriticalSection(&(pHWHead->RegCritSec));
	try {
		SETREG(pHWHead,rUCON,BS_SEND);
	}
	except (GetExceptionCode() == EXCEPTION_ACCESS_VIOLATION ?
		EXCEPTION_EXECUTE_HANDLER : EXCEPTION_CONTINUE_SEARCH) {
		// Just exit
	}
	LeaveCriticalSection(&(pHWHead->RegCritSec));
	RETAILMSG(DEBUGMODE, (TEXT("-SL_SetBreak, 0x%X\r\n"), pHead));
}

//
// SetBaudRate
//
// Internal function.  The only real reason for splitting this out
// is so that we can call it from PowerOn and still allow SL_SetBaud
// to do debug messages, acquire critical sections, etc.
//
BOOL
SetBaudRate(
           PVOID   pHead,
           ULONG   BaudRate
           )
{
	PS2410_UART_INFO    pHWHead = (PS2410_UART_INFO)pHead;

	RETAILMSG(DEBUGMODE, (TEXT("SetBaudRate -> %d\r\n"), BaudRate));
	if ( (pHWHead->s2410SerReg->rUCON & CS_MASK) == CS_PCLK )
		OUTREG(pHWHead,rUBRDIV,( (int)(S2410PCLK/16.0/BaudRate) -1 ));
	else		// if  ( (pHWHead2->s2410SerReg->rUCON & CS_MASK) == CS_UCLK )
		OUTREG(pHWHead,rUBRDIV,( (int)(S2410UCLK/16.0/BaudRate) -1 ));

	return( TRUE );
}

//
// @doc OEM
// @func BOOL | SL_SetBaudRate |
//  This routine sets the baud rate of the device.
//
// @rdesc None.
//
BOOL
SL_SetBaudRate(
              PVOID   pHead,    // @parm     PVOID returned by HWInit
              ULONG   BaudRate    // @parm     ULONG representing decimal baud rate.
              )
{
	BOOL fRet;
	PS2410_UART_INFO    pHWHead = (PS2410_UART_INFO)pHead;

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

	try {
		// Enter critical section before calling function, since
		// we can't make sys calls inside SetBaudRate
		EnterCriticalSection(&(pHWHead->RegCritSec));
		fRet = SetBaudRate(pHead, BaudRate);
		LeaveCriticalSection(&(pHWHead->RegCritSec));
	}except (GetExceptionCode() == EXCEPTION_ACCESS_VIOLATION ?
		EXCEPTION_EXECUTE_HANDLER : EXCEPTION_CONTINUE_SEARCH) {
		return( FALSE );
	}

	if ( fRet ) {
		pHWHead->dcb.BaudRate = BaudRate;

		RETAILMSG(DEBUGMODE,
			(TEXT("-SL_SetbaudRate 0x%X (%d Baud)\r\n"),
			pHead, BaudRate));
		return( TRUE );
	} else {
		RETAILMSG(DEBUGMODE,
			(TEXT("-SL_SetbaudRate - Error setting %d, failing to %d\r\n"),
			BaudRate, pHWHead->dcb.BaudRate) );
		return( FALSE );
	}
}

//
// @doc OEM
// @func BOOL | SL_SetByteSize |
//  This routine sets the WordSize of the device.
//
// @rdesc None.
//
BOOL
SL_SetByteSize(
              PVOID   pHead,        // @parm     PVOID returned by HWInit
              ULONG   ByteSize    // @parm     ULONG ByteSize field from DCB.
              )
{
	PS2410_UART_INFO    pHWHead = (PS2410_UART_INFO)pHead;
	UINT32 lcr;
	BOOL bRet;

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

	bRet = TRUE;

	EnterCriticalSection(&(pHWHead->RegCritSec));
	try {      
		lcr = (UINT32)INREG(pHWHead,rULCON);
		lcr &= ~SER2410_DATABIT_MASK;

		switch ( ByteSize ) {
		case 5:
			lcr |= 0;//SERIAL_5_DATA;
		break;
		case 6:
			lcr |= 1;//SERIAL_6_DATA;
		break;
		case 7:
			lcr |= 2;//SERIAL_7_DATA;
		break;
		case 8:
			lcr |= 3;//SERIAL_8_DATA;
		break;
		default:
			bRet = FALSE;
		break;
		}
		if (bRet) {
			OUTREG(pHWHead,rULCON,lcr); 
		}
	}
	except (GetExceptionCode() == EXCEPTION_ACCESS_VIOLATION ?
		EXCEPTION_EXECUTE_HANDLER : EXCEPTION_CONTINUE_SEARCH) {
		bRet = FALSE;
	}
	LeaveCriticalSection(&(pHWHead->RegCritSec));

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

	return(bRet);
}

//
// @doc OEM
// @func BOOL | SL_SetParity |
//  This routine sets the parity of the device.
//
// @rdesc None.
//
BOOL
SL_SetParity(
            PVOID   pHead,    // @parm     PVOID returned by HWInit
            ULONG   Parity    // @parm     ULONG parity field from DCB.
            )
{
	PS2410_UART_INFO    pHWHead = (PS2410_UART_INFO)pHead;

	UINT32 lcr;
	BOOL bRet;

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

	bRet = TRUE;

	EnterCriticalSection(&(pHWHead->RegCritSec));
	try {
		lcr = (UINT32)INREG(pHWHead,rULCON);      
		lcr &= ~SER2410_PARITY_MASK;

		switch ( Parity ) {
		case ODDPARITY:
			lcr |= 0x20;//SERIAL_ODD_PARITY;
		break;

		case EVENPARITY:
			lcr |= 0x28;//SERIAL_EVEN_PARITY;
		break;

		case MARKPARITY:
			lcr |= 0x30;//SERIAL_MARK_PARITY;
		break;

		case SPACEPARITY:
			lcr |= 0x38;//SERIAL_SPACE_PARITY;
		break;

		case NOPARITY:
			lcr |= 0;//SERIAL_NONE_PARITY;
		break;
		default:
			bRet = FALSE;
		break;
		}
		if (bRet) {
			OUTREG(pHWHead,rULCON,lcr) ;
		}
	}
	except (GetExceptionCode() == EXCEPTION_ACCESS_VIOLATION ?
		EXCEPTION_EXECUTE_HANDLER : EXCEPTION_CONTINUE_SEARCH) {
		bRet = FALSE;
	}
	LeaveCriticalSection(&(pHWHead->RegCritSec));

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

	return(bRet);
}
//
// @doc OEM
// @func VOID | SL_SetStopBits |
//  This routine sets the Stop Bits for the device.
//
// @rdesc None.
//
BOOL
SL_SetStopBits(
              PVOID   pHead,      // @parm     PVOID returned by HWInit
              ULONG   StopBits  // @parm     ULONG StopBits field from DCB.
              )
{
	PS2410_UART_INFO    pHWHead = (PS2410_UART_INFO)pHead;

	UINT32 lcr;
	BOOL bRet;

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

	bRet = TRUE;

	EnterCriticalSection(&(pHWHead->RegCritSec));

	try {
		lcr = INREG(pHWHead,rULCON);
		lcr &= ~SER2410_STOPBIT_MASK;

		// Note that 1.5 stop bits only works if the word size
		// is 5 bits.  Any other xmit word size will cause the
		// 1.5 stop bit setting to generate 2 stop bits.        
		switch ( StopBits ) {
		case ONESTOPBIT :
			lcr |= 0;//SERIAL_1_STOP ;
		break;
		case ONE5STOPBITS :
			//lcr |= SERIAL_1_5_STOP ;
			//break;
		case TWOSTOPBITS :
			lcr |= 4;//SERIAL_2_STOP ;
		break;
		default:
			bRet = FALSE;
		break;
		}

		if (bRet) {
			OUTREG(pHWHead,rULCON,lcr);
		}
	}
	except (GetExceptionCode() == EXCEPTION_ACCESS_VIOLATION ?
		EXCEPTION_EXECUTE_HANDLER : EXCEPTION_CONTINUE_SEARCH) {
		bRet = FALSE;
	}

	LeaveCriticalSection(&(pHWHead->RegCritSec));

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

	return(bRet);
}

//
// @doc OEM
// @func ULONG | SL_GetRxBufferSize | This function returns
// the size of the hardware buffer passed to the interrupt
// initialize function.  It would be used only for devices
// which share a buffer between the MDD/PDD and an ISR.
//
// 
// @rdesc This routine always returns 0 for 16550 UARTS.
// 
ULONG
SL_GetRxBufferSize(
                  PVOID pHead
                  )
{
	RETAILMSG(DEBUGMODE, (TEXT("SL_GetRxBufferSize \r\n")));
	return(0);
}

//
// @doc OEM
// @func PVOID | SC_GetRxStart | This routine returns the start of the hardware
// receive buffer.  See SL_GetRxBufferSize.
// 
// @rdesc The return value is a pointer to the start of the device receive buffer.
// 
PVOID
SL_GetRxStart(
             PVOID   pHead // @parm PVOID returned by SC_init.
             )
{
	RETAILMSG(DEBUGMODE, (TEXT("SL_GetRxStart \r\n")));
	return(NULL);
}

//
// @doc OEM
// @func ULONG | SL_GetInterruptType | This function is called
//   by the MDD whenever an interrupt occurs.  The return code
//   is then checked by the MDD to determine which of the four
//   interrupt handling routines are to be called.
// 
// @rdesc This routine returns a bitmask indicating which interrupts
//   are currently pending.
// 
INTERRUPT_TYPE
SL_GetInterruptType(
                   PVOID pHead      // Pointer to hardware head
                   )
{
	PS2410_UART_INFO    pHWHead = (PS2410_UART_INFO)pHead;
	INTERRUPT_TYPE interrupts;
	ULONG IntPndVal=0;
	ULONG IntSubPndVal=0;

	try {
		IntPndVal = *(pHWHead->UART_INTSRCPND);
		IntSubPndVal = *(pHWHead->UART_INTSUBSRCPND);
	}
	except (GetExceptionCode() == EXCEPTION_ACCESS_VIOLATION ?
		EXCEPTION_EXECUTE_HANDLER : EXCEPTION_CONTINUE_SEARCH) {
		RETAILMSG(DEBUGMODE, (TEXT("ACCESS VIOLATION ERROR \r\n")));
		IntPndVal = SER2410_INT_INVALID; // simulate no interrupt
	}

	RETAILMSG(DEBUGMODE, (TEXT("SL_GetInterruptType : 0x%X, 0x%X, 0x%X, 0x%X, 0x%X, 0x%X\r\n"),
		*(pHWHead->UART_INTMASK),
		*(pHWHead->UART_INTSUBMASK),
		*(pHWHead->UART_INTSRCPND),
		*(pHWHead->UART_INTSUBSRCPND),
		~(*(pHWHead->UART_INTSUBMASK)) & *(pHWHead->UART_INTSUBSRCPND),
		pHWHead->fSW_EnTxINT));

	if ( IntPndVal & (pHWHead->bINT) )
	{
		if ( IntSubPndVal == SER2410_INT_INVALID ) {      
			RETAILMSG (DEBUGMODE, (TEXT("SL_GetInterruptType: SER2410_INT_INVALID\r\n")));
			interrupts = INTR_NONE;
		}
		else if(IntSubPndVal & (pHWHead->bErrINT) )  {
			RETAILMSG (DEBUGMODE, (TEXT("SL_GetInterruptType: INTR_LINE\r\n")));
			interrupts = INTR_LINE;  // Error status
		}
		else if(IntSubPndVal & (pHWHead->bRxINT) )  {
			RETAILMSG (DEBUGMODE, (TEXT("SL_GetInterruptType: INTR_RX\r\n")));
			interrupts = INTR_RX;    // Received valid data.
		}
		else if((IntSubPndVal & (pHWHead->bTxINT)) && pHWHead->fSW_EnTxINT )  {
			RETAILMSG (DEBUGMODE, (TEXT("SL_GetInterruptType: INTR_TX\r\n")));
			interrupts = INTR_TX;
		}
		else 
		{
//			RETAILMSG (DEBUGMODE, (TEXT("SL_GetInterruptType: INTR_NONE\r\n")));
			interrupts = INTR_NONE;  // No interrupts pending, vector is useless
//			ClearINTPnd(pHWHead, pHWHead->bINT);
		}
	}
	else {
		RETAILMSG (DEBUGMODE, (TEXT("SL_GetInterruptType: INTR_NONE(pHWHead->bINT)\r\n")));
		interrupts = INTR_NONE;  // No interrupts pending, vector is useless
	}

	return(interrupts);

⌨️ 快捷键说明

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