|
发表于 2010-7-6 16:36:16
|
显示全部楼层
楼上的 兄台 厉害!
我最近在玩 ucos ATMEGA128 . 在运行中断函数的时候,总是会 复位!
/*外部中断INT6,下降沿触发*/
#pragma interrupt_handler Int6: 8
void Int6(void)
{
OSIntEnter ( );
PORTB ^= (1 << PB6); /*PB1电平取反*/
OSMboxPost(MBox,&MSg[2]);
OSIntExit ( );
}
OSIntExit()函数如下:
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 */
}
}
}
OS_EXIT_CRITICAL();
}
}
/*$PAGE*/
下面是 中断任务调度的 汇编代码
;/*$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*/.
请大侠 不吝赐教 |
|