|
发表于 2009-10-31 09:24:15
|
显示全部楼层
20091031:
任务切换宏更新
IAR:
#define SAVE_REGS() \
do{ \
asm ("ST -Y, R0 "); \
asm ("ST -Y, R1 "); \
asm ("ST -Y, R2 "); \
asm ("ST -Y, R3 "); \
asm ("ST -Y, R4 "); \
asm ("ST -Y, R5 "); \
asm ("ST -Y, R6 "); \
asm ("ST -Y, R7 "); \
asm ("ST -Y, R8 "); \
asm ("ST -Y, R9 "); \
asm ("ST -Y, R10 "); \
asm ("ST -Y, R11 "); \
asm ("ST -Y, R12 "); \
asm ("ST -Y, R13 "); \
asm ("ST -Y, R14 "); \
asm ("ST -Y, R15 "); \
asm ("ST -Y, R16 "); \
asm ("ST -Y, R17 "); \
asm ("ST -Y, R18 "); \
asm ("ST -Y, R19 "); \
asm ("ST -Y, R20 "); \
asm ("ST -Y, R21 "); \
asm ("ST -Y, R22 "); \
asm ("ST -Y, R23 "); \
asm ("ST -Y, R24 "); \
asm ("ST -Y, R25 "); \
asm ("ST -Y, R26 "); \
asm ("ST -Y, R27 "); \
asm ("ST -Y, R30 "); \
asm ("ST -Y, R31 "); \
asm ("IN R24, 0x3D "); \
asm ("ST -Y, R24 "); \
asm ("IN R24, 0x3E "); \
asm ("ST -Y, R24 "); \
asm ("IN R24, 0x3F "); \
asm ("ST -Y, R24 "); \
}while(0)
#define RESTORE_REGS() \
do{ \
asm ("LD R24, Y+ "); \
asm ("OUT 0X3F, R24 "); \
asm ("LD R24, Y+ "); \
asm ("OUT 0X3E, R24 "); \
asm ("LD R24, Y+ "); \
asm ("OUT 0X3D, R24 "); \
asm ("LD R31, Y+ "); \
asm ("LD R30, Y+ "); \
asm ("LD R27, Y+ "); \
asm ("LD R26, Y+ "); \
asm ("LD R25, Y+ "); \
asm ("LD R24, Y+ "); \
asm ("LD R23, Y+ "); \
asm ("LD R22, Y+ "); \
asm ("LD R21, Y+ "); \
asm ("LD R20, Y+ "); \
asm ("LD R19, Y+ "); \
asm ("LD R18, Y+ "); \
asm ("LD R17, Y+ "); \
asm ("LD R16, Y+ "); \
asm ("LD R15, Y+ "); \
asm ("LD R14, Y+ "); \
asm ("LD R13, Y+ "); \
asm ("LD R12, Y+ "); \
asm ("LD R11, Y+ "); \
asm ("LD R10, Y+ "); \
asm ("LD R9, Y+ "); \
asm ("LD R8, Y+ "); \
asm ("LD R7, Y+ "); \
asm ("LD R6, Y+ "); \
asm ("LD R5, Y+ "); \
asm ("LD R4, Y+ "); \
asm ("LD R3, Y+ "); \
asm ("LD R2, Y+ "); \
asm ("LD R1, Y+ "); \
asm ("LD R0, Y+ "); \
asm ("RET " ); \
}while(0)
#define INT_SAVE_REGS() \
do{ \
asm ("CLI "); \
asm ("ST -Y, R0 "); \
asm ("ST -Y, R1 "); \
asm ("ST -Y, R2 "); \
asm ("ST -Y, R3 "); \
asm ("ST -Y, R4 "); \
asm ("ST -Y, R5 "); \
asm ("ST -Y, R6 "); \
asm ("ST -Y, R7 "); \
asm ("ST -Y, R8 "); \
asm ("ST -Y, R9 "); \
asm ("ST -Y, R10 "); \
asm ("ST -Y, R11 "); \
asm ("ST -Y, R12 "); \
asm ("ST -Y, R13 "); \
asm ("ST -Y, R14 "); \
asm ("ST -Y, R15 "); \
asm ("ST -Y, R16 "); \
asm ("ST -Y, R17 "); \
asm ("ST -Y, R18 "); \
asm ("ST -Y, R19 "); \
asm ("ST -Y, R20 "); \
asm ("ST -Y, R21 "); \
asm ("ST -Y, R22 "); \
asm ("ST -Y, R23 "); \
asm ("ST -Y, R24 "); \
asm ("ST -Y, R25 "); \
asm ("ST -Y, R26 "); \
asm ("ST -Y, R27 "); \
asm ("ST -Y, R30 "); \
asm ("ST -Y, R31 "); \
asm ("IN R24, 0x3D "); \
asm ("ST -Y, R24 "); \
asm ("IN R24, 0x3E "); \
asm ("ST -Y, R24 "); \
asm ("IN R24, 0x3F "); \
asm ("ST -Y, R24 "); \
}while(0)
#define INT_RESTORE_REGS() \
do{ \
asm ("LD R24, Y+ "); \
asm ("OUT 0X3F, R24 "); \
asm ("LD R24, Y+ "); \
asm ("OUT 0X3E, R24 "); \
asm ("LD R24, Y+ "); \
asm ("OUT 0X3D, R24 "); \
asm ("LD R31, Y+ "); \
asm ("LD R30, Y+ "); \
asm ("LD R27, Y+ "); \
asm ("LD R26, Y+ "); \
asm ("LD R25, Y+ "); \
asm ("LD R24, Y+ "); \
asm ("LD R23, Y+ "); \
asm ("LD R22, Y+ "); \
asm ("LD R21, Y+ "); \
asm ("LD R20, Y+ "); \
asm ("LD R19, Y+ "); \
asm ("LD R18, Y+ "); \
asm ("LD R17, Y+ "); \
asm ("LD R16, Y+ "); \
asm ("LD R15, Y+ "); \
asm ("LD R14, Y+ "); \
asm ("LD R13, Y+ "); \
asm ("LD R12, Y+ "); \
asm ("LD R11, Y+ "); \
asm ("LD R10, Y+ "); \
asm ("LD R9, Y+ "); \
asm ("LD R8, Y+ "); \
asm ("LD R7, Y+ "); \
asm ("LD R6, Y+ "); \
asm ("LD R5, Y+ "); \
asm ("LD R4, Y+ "); \
asm ("LD R3, Y+ "); \
asm ("LD R2, Y+ "); \
asm ("LD R1, Y+ "); \
asm ("LD R0, Y+ "); \
asm ("RETI " ); \
}while(0)
#define SAVE_OLD_PCONTEXT() \
do{ \
__require(&VTCurrentTask); \
__require(&VTToTask); \
asm(" LDS R30, VTCurrentTask"); \
asm(" LDS R31, (VTCurrentTask + 1)"); \
asm(" STD Z+5, R28 "); \
asm(" STD Z+6, R29 "); \
}while(0)
#define LOAD_NEW_PCONTEXT() \
do{ \
__require(&VTCurrentTask); \
__require(&VTToTask); \
asm(" LDS R30, VTToTask"); \
asm(" LDS R31, (VTToTask + 1)"); \
asm(" STS VTCurrentTask,R30 "); \
asm(" STS (VTCurrentTask+1),R31 "); \
asm(" LDD R28,Z+5 "); \
asm(" LDD R29,Z+6 "); \
}while(0);
#define SET_INT_CONTEXT_FLAG() \
do{ \
asm(" LDI R24, 1" ); \
asm(" STD Z+7, R24" ); \
}while(0)
#define CLR_INT_CONTEXT_FLAG() \
do{ \
asm(" LDI R24, 0" ); \
asm(" STD Z+7, R24" ); \
}while(0)
#define SWAP_CTX_ENTER() \
do{ \
SAVE_REGS(); \
SAVE_OLD_PCONTEXT(); \
CLR_INT_CONTEXT_FLAG(); \
}while(0)
#define SWAP_CTX_EXIT() \
do{ \
LOAD_NEW_PCONTEXT(); \
if(VTCurrentTask->IntSwapFlag==0) \
{ \
RESTORE_REGS(); \
} \
else \
{ \
INT_RESTORE_REGS(); \
} \
}while(0)
#define INT_SWAP_CTX_ENTER() \
do{ \
INT_SAVE_REGS(); \
SAVE_OLD_PCONTEXT(); \
SET_INT_CONTEXT_FLAG(); \
}while(0)
#define INT_SWAP_CTX_EXIT() SWAP_CTX_EXIT()
#define DELETE_SWAP_CTX_EXIT() SWAP_CTX_EXIT()
#define VT_IntEnter() \
do{ \
__require((void *)&VTIntNest); \
INT_SWAP_CTX_ENTER(); \
VTIntNest++; \
}while(0)
#define VT_IntExit() \
do{ \
__require((void *)&VTIntNest); \
cli(); \
if(--VTIntNest==0) \
{ \
TSK_IntSwap(); \
} \
INT_RESTORE_REGS(); \
}while(0);
GCC:
#define SAVE_REGS() \
do{ \
asm volatile ("PUSH R0 "); \
asm volatile ("PUSH R1 "); \
asm volatile ("PUSH R2 "); \
asm volatile ("PUSH R3 "); \
asm volatile ("PUSH R4 "); \
asm volatile ("PUSH R5 "); \
asm volatile ("PUSH R6 "); \
asm volatile ("PUSH R7 "); \
asm volatile ("PUSH R8 "); \
asm volatile ("PUSH R9 "); \
asm volatile ("PUSH R10 "); \
asm volatile ("PUSH R11 "); \
asm volatile ("PUSH R12 "); \
asm volatile ("PUSH R13 "); \
asm volatile ("PUSH R14 "); \
asm volatile ("PUSH R15 "); \
asm volatile ("PUSH R16 "); \
asm volatile ("PUSH R17 "); \
asm volatile ("PUSH R18 "); \
asm volatile ("PUSH R19 "); \
asm volatile ("PUSH R20 "); \
asm volatile ("PUSH R21 "); \
asm volatile ("PUSH R22 "); \
asm volatile ("PUSH R23 "); \
asm volatile ("PUSH R24 "); \
asm volatile ("PUSH R25 "); \
asm volatile ("PUSH R26 "); \
asm volatile ("PUSH R27 "); \
asm volatile ("PUSH R28 "); \
asm volatile ("PUSH R29 "); \
asm volatile ("PUSH R30 "); \
asm volatile ("PUSH R31 "); \
asm volatile ("IN R24, 0x3F "); \
asm volatile ("PUSH R24 "); \
}while(0)
#define RESTORE_REGS() \
do{ \
asm volatile ("POP R24 "); \
asm volatile ("OUT 0X3F, R24 "); \
asm volatile ("POP R31 "); \
asm volatile ("POP R30 "); \
asm volatile ("POP R29 "); \
asm volatile ("POP R28 "); \
asm volatile ("POP R27 "); \
asm volatile ("POP R26 "); \
asm volatile ("POP R25 "); \
asm volatile ("POP R24 "); \
asm volatile ("POP R23 "); \
asm volatile ("POP R22 "); \
asm volatile ("POP R21 "); \
asm volatile ("POP R20 "); \
asm volatile ("POP R19 "); \
asm volatile ("POP R18 "); \
asm volatile ("POP R17 "); \
asm volatile ("POP R16 "); \
asm volatile ("POP R15 "); \
asm volatile ("POP R14 "); \
asm volatile ("POP R13 "); \
asm volatile ("POP R12 "); \
asm volatile ("POP R11 "); \
asm volatile ("POP R10 "); \
asm volatile ("POP R9 "); \
asm volatile ("POP R8 "); \
asm volatile ("POP R7 "); \
asm volatile ("POP R6 "); \
asm volatile ("POP R5 "); \
asm volatile ("POP R4 "); \
asm volatile ("POP R3 "); \
asm volatile ("POP R2 "); \
asm volatile ("POP R1 "); \
asm volatile ("POP R0 "); \
asm volatile ("RET " ); \
}while(0)
#define INT_SAVE_REGS() \
do{ \
asm volatile ("CLI "); \
asm volatile ("PUSH R0 "); \
asm volatile ("PUSH R1 "); \
asm volatile ("PUSH R2 "); \
asm volatile ("PUSH R3 "); \
asm volatile ("PUSH R4 "); \
asm volatile ("PUSH R5 "); \
asm volatile ("PUSH R6 "); \
asm volatile ("PUSH R7 "); \
asm volatile ("PUSH R8 "); \
asm volatile ("PUSH R9 "); \
asm volatile ("PUSH R10 "); \
asm volatile ("PUSH R11 "); \
asm volatile ("PUSH R12 "); \
asm volatile ("PUSH R13 "); \
asm volatile ("PUSH R14 "); \
asm volatile ("PUSH R15 "); \
asm volatile ("PUSH R16 "); \
asm volatile ("PUSH R17 "); \
asm volatile ("PUSH R18 "); \
asm volatile ("PUSH R19 "); \
asm volatile ("PUSH R20 "); \
asm volatile ("PUSH R21 "); \
asm volatile ("PUSH R22 "); \
asm volatile ("PUSH R23 "); \
asm volatile ("PUSH R24 "); \
asm volatile ("PUSH R25 "); \
asm volatile ("PUSH R26 "); \
asm volatile ("PUSH R27 "); \
asm volatile ("PUSH R28 "); \
asm volatile ("PUSH R29 "); \
asm volatile ("PUSH R30 "); \
asm volatile ("PUSH R31 "); \
asm volatile ("IN R24, 0x3F "); \
asm volatile ("PUSH R24 "); \
}while(0)
#define INT_RESTORE_REGS() \
do{ \
asm volatile ("POP R24 "); \
asm volatile ("OUT 0X3F, R24 "); \
asm volatile ("POP R31 "); \
asm volatile ("POP R30 "); \
asm volatile ("POP R29 "); \
asm volatile ("POP R28 "); \
asm volatile ("POP R27 "); \
asm volatile ("POP R26 "); \
asm volatile ("POP R25 "); \
asm volatile ("POP R24 "); \
asm volatile ("POP R23 "); \
asm volatile ("POP R22 "); \
asm volatile ("POP R21 "); \
asm volatile ("POP R20 "); \
asm volatile ("POP R19 "); \
asm volatile ("POP R18 "); \
asm volatile ("POP R17 "); \
asm volatile ("POP R16 "); \
asm volatile ("POP R15 "); \
asm volatile ("POP R14 "); \
asm volatile ("POP R13 "); \
asm volatile ("POP R12 "); \
asm volatile ("POP R11 "); \
asm volatile ("POP R10 "); \
asm volatile ("POP R9 "); \
asm volatile ("POP R8 "); \
asm volatile ("POP R7 "); \
asm volatile ("POP R6 "); \
asm volatile ("POP R5 "); \
asm volatile ("POP R4 "); \
asm volatile ("POP R3 "); \
asm volatile ("POP R2 "); \
asm volatile ("POP R1 "); \
asm volatile ("POP R0 "); \
asm volatile ("RETI " ); \
}while(0)
#define SAVE_OLD_PCONTEXT() \
do{ \
asm volatile ("IN R28,0x3D"); \
asm volatile ("IN R29,0x3E"); \
asm volatile (" LDS R30, VTCurrentTask"); \
asm volatile (" LDS R31, (VTCurrentTask + 1)"); \
asm volatile (" STD Z+5, R28 "); \
asm volatile (" STD Z+6, R29 "); \
}while(0)
#define LOAD_NEW_PCONTEXT() \
do{ \
asm volatile (" LDS R30, VTToTask"); \
asm volatile (" LDS R31, (VTToTask + 1)"); \
asm volatile (" STS VTCurrentTask,R30 "); \
asm volatile (" STS (VTCurrentTask+1),R31 ");\
asm volatile (" LDD R28,Z+5 "); \
asm volatile (" LDD R29,Z+6 "); \
asm volatile (" OUT 0x3E,R29 "); \
asm volatile (" OUT 0x3D,R28 "); \
}while(0)
#define SET_INT_CONTEXT_FLAG() \
do{ \
asm(" LDI R24, 1" ); \
asm(" STD Z+7, R24" ); \
}while(0)
#define CLR_INT_CONTEXT_FLAG() \
do{ \
asm(" LDI R24, 0" ); \
asm(" STD Z+7, R24" ); \
}while(0)
#define SWAP_CTX_ENTER() \
do{ \
SAVE_REGS(); \
SAVE_OLD_PCONTEXT(); \
CLR_INT_CONTEXT_FLAG(); \
}while(0)
#define SWAP_CTX_EXIT() \
do{ \
LOAD_NEW_PCONTEXT(); \
if(VTCurrentTask->IntSwapFlag==0) \
{ \
RESTORE_REGS(); \
} \
else \
{ \
INT_RESTORE_REGS(); \
} \
}while(0)
#define INT_SWAP_CTX_ENTER() \
do{ \
INT_SAVE_REGS(); \
SAVE_OLD_PCONTEXT(); \
SET_INT_CONTEXT_FLAG(); \
}while(0)
#define INT_SWAP_CTX_EXIT() SWAP_CTX_EXIT()
#define DELETE_SWAP_CTX_EXIT() SWAP_CTX_EXIT()
#define VT_IntEnter() \
do{ \
INT_SWAP_CTX_ENTER(); \
VTIntNest++; \
}while(0)
#define VT_IntExit() \
do{ \
cli(); \
if(--VTIntNest==0) \
{ \
TSK_IntSwap(); \
} \
INT_RESTORE_REGS(); \
}while(0);
点击此处下载 ourdev_497947.rar(文件大小:322K) (原文件名:voidtask.rar) |
|