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

📄 driv_internal_uart_c.c

📁 UCOS-II2.76在ADI-BF533上的移植.在UCOS-II网站提供的源码基础上修改了几处汇编代码.采用2.76版系统内核移植,在DSP++4.0上调试成功
💻 C
字号:
/*
*********************************************************************************************************
*                                                uC/OS-II
*                                          The Real-Time Kernel
*
*										  Utility functions for
*										  ADSP-BF533 Internal Uart
*
* File : Driv_Internal_UART_C.c
* By   : Ron Territo   ron@territocomputerservices.com
*********************************************************************************************************

Copyright...

This code is placed in the public domain, and can be distributed freely with no restrictions provided that the heading
of each source module file is not modified to remove the credit to the original author.
  
Disclaimer...

This program code is provided "as is". There is no warranty, either expressed or implied as to its fitness for use in
any application. It is provided only as an example of porting the MicroC/OS operating system to the Blackfin processor.
Its use is strictly at the risk of the user. The author will not be liable for any damages direct or consequential related
to the use of this software including, but not limited to loss of profit.

*/




#include <uCOS-II_V2.70\source\ucos_ii.h>
#include <Internal_UART.h>
#include <cdefBF533.h>


/*
*****************************************************************************
*
*	Get a character
*
* 	Arguments  	: timeout value in mS, 0 if no timeout
*
*	Returns		: next available char received on UART, -1 if error or timeout
*
*****************************************************************************
*/

int InternalUartGetChar( int timeout )
{
	unsigned char OSErr;
	unsigned char charRx;		
	
	/*  1st wait for the event that there's at least 1 character avail */
	
	
	OS_ENTER_CRITICAL();
	
	while ( RxIntBufferEptr == RxIntBufferFptr )	// is the buffer empty ?
	{
		RxIntBufferFptr = &RxIntBuffer[0];		// reset to head
		RxIntBufferEptr = &RxIntBuffer[0];
		
		OS_EXIT_CRITICAL();
		
		// wait for a character to arrive
		if ( OSFlagPend( EvUARTFlags, EV_UART_FLAG_RX_AVAIL, OS_FLAG_WAIT_SET_ANY | OS_FLAG_CONSUME, timeout, &OSErr ) == 0 )
		{
			return (-1);
		}

		OS_ENTER_CRITICAL();
	}

	// see if buffer beyond limits
	if ( RxIntBufferEptr > RxIntBufferTptr )
	{
		return (-1);
	}
	
	// get the next character, bump pointer
	charRx =  *RxIntBufferEptr++;
	
	OS_EXIT_CRITICAL();
	
	return ( charRx );	
}







/*
*****************************************************************************
*
*	Put a character
*
* 	Arguments  	: Character to output
*
*	Returns		: true, if successful
*
*****************************************************************************
*/

bool InternalUartPutChar( char charTx )
{
	unsigned char OSErr;
	
	if ( TxIntBufferFptr == TxIntBufferTptr )
	{
		OSFlagPost( EvUARTFlags, EV_UART_FLAG_TX_EMPTY, OS_FLAG_CLR,  &OSErr );
		if ( OSFlagPend( EvUARTFlags, EV_UART_FLAG_TX_EMPTY , OS_FLAG_WAIT_SET_ANY | OS_FLAG_CONSUME, 0, &OSErr ) == 0 )
		{
			return (false);
		}
		
	}

	OS_ENTER_CRITICAL();
	
	if ( !(*pUART_IER & 0x02) )					// are interrupts off ?
	{
		*pUART_THR = charTx;					// write character directly to UART
		*pUART_IER |= 0x02;						// enable Tx Interrupts
	}
	else
	{
		*TxIntBufferFptr++ = charTx;			// put char in buffer
	}
	

	OS_EXIT_CRITICAL();

	return ( true );	
}

⌨️ 快捷键说明

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