|
各位大侠,请教一下 ,我的UCOSII是基于ATMEGA128的
基本功能 都可以实现,就是在 中断函数处理的时候 就会出问题
中断部分函数如下
/***串口接收中断**/
#pragma interrupt_handler uart0_rx_isr:iv_USART0_RXC
void uart0_rx_isr(void)
{
INT8U BUFF0;
BUFF0 = UDR0;
OSIntEnter ( );
if (BUFF0 == 0x55 )
{
OSMboxPost(MBox,&MSg[2]);
}
uart_transmit0(BUFF0);
OSIntExit ( );
}
/*外部中断INT6,下降沿触发*/
#pragma interrupt_handler Int6: 8
void Int6(void)
{
OS_CPU_SR cpu_sr;
OSIntEnter ( );
PORTB ^= (1 << PB6); /*PB1电平取反*/
OSMboxPost(MBox,&MSg[2]);
OSIntExit ( );
}
不知道为什么 ,只要 触发中断 (串口中断和 外部中断 都一样) ,整个系统 就会复位。。。
后来 我把 OSIntExit 函数中的 ,中断调度 函数OSIntCtxSw(); 换成 任务调度函数 OSCtxSw() ,测试 结果 就完全正常。。。。。。不知道为什么??、
求OS达人 指点 迷津
void OSIntExit (void)
{
INT8U y;
#if OS_CRITICAL_METHOD == 3 /* Allocate storage for CPU status register */
OS_CPU_SR cpu_sr;
cpu_sr = 0; /* Prevent compiler warning */
#endif
if (OSRunning == TRUE) {
OS_ENTER_CRITICAL();
if (OSIntNesting > 0) { /* Prevent OSIntNesting from wrapping */
OSIntNesting--;
}
if (OSIntNesting == 0) { /* Reschedule only if all ISRs complete ... */
if (OSLockNesting == 0) { /* ... and not locked. */
y = OSUnMapTbl[OSRdyGrp];
OSPrioHighRdy = (INT8U)((y << 3) + OSUnMapTbl[OSRdyTbl[y]]);
if (OSPrioHighRdy != OSPrioCur) { /* No Ctx Sw if current task is highest rdy */
OSTCBHighRdy = OSTCBPrioTbl[OSPrioHighRdy];
#if OS_TASK_PROFILE_EN > 0
OSTCBHighRdy->OSTCBCtxSwCtr++; /* Inc. # of context switches to this task */
#endif
OSCtxSwCtr++; /* Keep track of the number of ctx switches */
//OSIntCtxSw(); /* Perform interrupt level ctx switch */
OSCtxSw();
}
}
}
OS_EXIT_CRITICAL();
}
}
中断调度函数 和 任务调度函数的 汇编源码如下
/*$PAGE*/.
;********************************************************************************************************
; TASK LEVEL CONTEXT SWITCH
;
; Description : This function is called when a task makes a higher priority task ready-to-run.
;
; Note(s) : 1) Upon entry,
; OSTCBCur points to the OS_TCB of the task to suspend
; OSTCBHighRdy points to the OS_TCB of the task to resume
;
; 2) The stack frame of the task to suspend looks as follows:
;
; SP+0 --> LSB of task code address
; +1 MSB of task code address (High memory)
;
; 3) The saved context of the task to resume looks as follows:
;
; OSTCBHighRdy->OSTCBStkPtr --> SPL of (return) stack pointer (Low memory)
; SPH of (return) stack pointer
; Flags to load in status register
; R31
; R30
; R27
; .
; .
; R0
; PCH
; PCL (High memory)
;********************************************************************************************************
_OSCtxSw::
PUSH_ALL ; Save current task's context
PUSH_SREG
PUSH_SP
LDS R30,_OSTCBCur ; Z = OSTCBCur->OSTCBStkPtr
LDS R31,_OSTCBCur+1 ;
ST Z+,R28 ; Save Y (R29:R28) pointer
ST Z+,R29 ;
CALL _OSTaskSwHook ; Call user defined task switch hook
LDS R16,_OSPrioHighRdy ; OSPrioCur = OSPrioHighRdy
STS _OSPrioCur,R16
LDS R30,_OSTCBHighRdy ; Let Z point to TCB of highest priority task
LDS R31,_OSTCBHighRdy+1 ; ready to run
STS _OSTCBCur,R30 ; OSTCBCur = OSTCBHighRdy
STS _OSTCBCur+1,R31 ;
LD R28,Z+ ; Restore Y pointer
LD R29,Z+ ;
POP_SP ; Restore stack pointer
POP_SREG ; Restore status register
POP_ALL ; Restore all registers
RET
;/*$PAGE*/.
;*********************************************************************************************************
; INTERRUPT LEVEL CONTEXT SWITCH
;
; Description : This function is called by OSIntExit() to perform a context switch to a task that has
; been made ready-to-run by an ISR.
;
; Note(s) : 1) Upon entry,
; OSTCBCur points to the OS_TCB of the task to suspend
; OSTCBHighRdy points to the OS_TCB of the task to resume
;
; 2) The stack frame of the task to suspend looks as follows:
;
; OSTCBCur->OSTCBStkPtr ------> SPL of (return) stack pointer (Low memory)
; SPH of (return) stack pointer
; Flags to load in status register
; R31
; R30
; R27
; .
; .
; R0
; PCH
; PCL (High memory)
;
; 3) The saved context of the task to resume looks as follows:
;
; OSTCBHighRdy->OSTCBStkPtr --> SPL of (return) stack pointer (Low memory)
; SPH of (return) stack pointer
; Flags to load in status register
; R31
; R30
; R27
; .
; .
; R0
; PCH
; PCL (High memory)
;*********************************************************************************************************
_OSIntCtxSw::
CALL _OSTaskSwHook ; Call user defined task switch hook
LDS R16,_OSPrioHighRdy ; OSPrioCur = OSPrioHighRdy
STS _OSPrioCur,R16 ;
LDS R30,_OSTCBHighRdy ; Z = OSTCBHighRdy->OSTCBStkPtr
LDS R31,_OSTCBHighRdy+1 ;
STS _OSTCBCur,R30 ; OSTCBCur = OSTCBHighRdy
STS _OSTCBCur+1,R31 ;
LD R28,Z+ ; Restore Y pointer
LD R29,Z+ ;
POP_SP ; Restore stack pointer
POP_SREG ; Restore status register
POP_ALL ; Restore all registers
RET
;/*$PAGE*/. |
阿莫论坛20周年了!感谢大家的支持与爱护!!
你熬了10碗粥,别人一桶水倒进去,淘走90碗,剩下10碗给你,你看似没亏,其实你那10碗已经没有之前的裹腹了,人家的一桶水换90碗,继续卖。说白了,通货膨胀就是,你的钱是挣来的,他的钱是印来的,掺和在一起,你的钱就贬值了。
|