/* Read the received data */
data = UDR0;
/* Calculate buffer index */
tmphead = ( USART_RxHead + 1 ) & USART_RX_BUFFER_MASK;
USART_RxHead = tmphead; /* Store new index */
if ( tmphead == USART_RxTail )
{
/* ERROR! Receive buffer overflow */
}
USART_RxBuf[tmphead] = data; /* Store received data in buffer */
_SEI();
}
这是串口接收函数
void USART0_TXISR_Handler( void )
{
unsigned char tmptail;
_CLI();
/* Check if all data is transmitted */
if ( USART_TxHead != USART_TxTail )
{
/* Calculate buffer index */
tmptail = ( USART_TxTail + 1 ) & USART_TX_BUFFER_MASK;
USART_TxTail = tmptail; /* Store new index */
我在中断服务程序中已经使用汇编调用了:
USART0_RXISR:
PUSH_ALL ; Save all registers and status register
IN R16,SREG ; Save the SREG but with interrupts enabled
SBR R16,BIT07
ST -Y,R16
PUSH_SP ; Save the task's hardware stack pointer onto task's stack
CPI R16,1 ; if (OSIntNesting == 1) {
BRNE USART0_RXISR_1
LDS R30,OSTCBCur ; OSTCBCur->OSTCBStkPtr = Y
LDS R31,OSTCBCur+1
ST Z+,R28
ST Z+,R29 ; }
USART0_RXISR_1:
CALL USART0_RXISR_Handler ; Call tick ISR Handler written in C
CALL OSIntExit ; Notify uC/OS-II about end of ISR
POP_SP ; Restore the hardware stack pointer from task's stack
POP_SREG_INT
POP_ALL ; Restore all registers
RETI
/* Read the received data */
data = UDR0;
/* Calculate buffer index */
tmphead = ( USART_RxHead + 1 ) & USART_RX_BUFFER_MASK;
USART_RxHead = tmphead; /* Store new index */
if ( tmphead == USART_RxTail )
{
/* ERROR! Receive buffer overflow */
}