最近在做几个ucos 移植,但是我使用多中断接收和发送,在系统的中断管理里能够中断嵌套,但是在任务中中断接收数据然后中断发送数据,但是现在中断只能够进几次系统就死机了。。。。。
下面是任务。。
static void AppTaskMain(void *p_arg)
{
//#if OS_CRITICAL_METHOD == 3 /* Allocate storage for CPU status register */
// OS_CPU_SR cpu_sr = 0;
//#endif
unsigned char getchar;
while (TRUE) {
BIT_LED_WORK = 1;
OSTimeDly(5);
getchar=USART0_Receive();
USART0_Transmit(getchar);
BIT_LED_WORK = 0;
OSTimeDly(20);
}
}
这是串口接收中断函数
void USART0_RXISR_Handler( void )
{
unsigned char data;
unsigned char tmphead;
_CLI();
/* 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 */
UDR0 = USART_TxBuf[tmptail]; /* Start transmition */
}
else
{
UCSR0B &= ~(1<<UDRIE0); /* Disable UDRE interrupt */
}
_SEI();
}
我在中断服务程序中已经使用汇编调用了:
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
LDS R16,OSIntNesting ; Notify uC/OS-II of ISR
INC R16 ;
STS OSIntNesting,R16 ;
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
堆栈大小也设定为128字节 我觉得够用了 但是程序运行一段时间,就死机了。。