?? driv_internal_uart_c.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 );
}
?? 快捷鍵說明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -