zt-C51±à??:2005°?uCOS?ò C51????????
C51±à??:2005°?uCOS?ò C51???????????????? [pwl999] 2005-1-24 11:40:02
×??ü????????uCOS c51????????
???é×??????±?ò·?????????·?????×???±????????ù??????×?????±??????í?????????????ó??
×?uCOS?????????ù??·???
???????ó???à?à????????????
Chapter 1 [pwl999] 2005-1-24 11:43:25
uCOS-?ò C51????±???
??????????×????? CyberTeam ?í?°??
?¨1?????±???????°/?ó?¨??????
?°/?ó?¨???????????ó???·?????·?é???÷??±ê??????????±ê?????????????????à????·?????
?ò??±ê????????±ê????????·??ú???????ì?????±?????????¤??×?????×??????é???????·???ù
????????????·??????ò?????ê?????ì???±?°??????????·????????????±/?????ì?????????ü
?????÷???·???¨?????????¨?????÷???·???à????±ê???????ê??????
???±?????¨uCOS???????????ò·??????????????????ó??????????????????????????????????
??·??ú???ò??uCOS???§???±??????×???????×??????????????¨??uCOS????IDLE????????????
?·???????????????????????????·???????????????????????¤×÷?????????????????ú?ú????
????????×????????÷????????????????????/?????????????¨???????¨???à?????????????ê
??????
??????????
????????????????CPU?????????±???¤×÷??CPU???¤×÷?????÷???????????????????¤×÷????
CPU???ê??????????????????·??????ò???ó??????IDLE??????????????????????·??ú??°ü?¨
???±???????°/?ó?¨??????????????????????????????????
°???uCOS??????????????????·??????à??
1?????? ?¨Event????°ü?¨??????(Semaphores)??????±ê??×é(Flag)??????(Message Box)??
????????(Message Queue)??
2???±???¨Time Tick????°ü?¨?±?????±?????????±??
3???????¨Interrupt????????·????÷??event??
??????1?????????¨??????????2??3??×?????·????????ù???????????????????????????±??
?¨?¨?±?????????¨?÷???ì??????????
?±?????????????????????????????????ò????????????????????????????????
?°/?ó?¨?????????????????????????ú?ú?????÷???·?????????é??????±?????°????¨?±?é
?????????é?????????????????ì???±??????×????????????????é?????¨?±?¨?±??????????
?¨2??uCOS C51??????×?±??¤×÷??
2004?ê8??·????????é???ò????±???uCOS-?ò ??2°??·??×?±??§?°RTOS???ò?????°????????
RTOS?????¤×÷???à??????????????3??4???????±??12???????±?ò?????????????è????????
??????????°?uCOS??????c51????????RTOS?§?°????????????
?ò????OS?ò?ù????????????????????Down??????????????OS???ò??×?????OS??????????????
OS????????????????OS???????????ú????????????????×?????±??????÷????????????uCOS??
????????????????????uCOS c51??????????????°??ú??????OS???????????ú???????????÷±?
???à???????????????????????????ó???±??????????????????????????????
×??????????????????????é??????uCOS-?ò ??2°??·?????ê??±???°??????ó±?±????¨????2??
°????????ò?????¤×÷?è???????????????ù??°??í?????????????????é^_^,???à??9????????
????????×?????????????±??????°?ì?????á??????????????????uCOS??×??????????·??×???
????uCOS-?ò???é????????????????????×??¨????×????????????é???±?ò???????á??×?±?
????°????ì?????????÷°×?????÷?????????????????±???????????????????ó±?±????°?ó????
?????à???????????????????ó?????????¨°???
??????uCOS????????????±??é?????????????ú????????C51Windows?·??±à?????????·??????
Keil C?????????ì?????????¨??2??3?ì?????°??????????????C51????±à??×????á????????
????/????????????????C&Asm?ì??±à????????????????CPU??uCOS??????C???????????ú????
???????????????????????????¨?ó°??±??????
??uCOS-?ò ??2°??·?????????ú????????C51Windows?·??±à?????????·????±??é??????????
????×??????????????????¨?ó???è???????????÷??????
uCOS??C51???é?????ê??????????????????uCOS??C51????×????????????????ò?????à??°?±?
?????????ê????????????????????°?±??????ú?????ó????"uCOS C51????????"???à?????à??
????????????×?????×÷??????????????????????????????????×???????????°????????ü????
·¨±????????ò??????????·???????×??????ó?à?????????í?ó?????????±??????????????????
?????????????????????????ò?????????°±????ù???????ù???????????ó?????ú????
?????????ú???????????¨???ó???????????±????
?¨3??uCOS C51????????????
1???¤????
uCOS 2.52°???
Keil C V6.23a??
2??uCOS V2.52???????á?????????ù?è??????????
A???????í?÷????????????
OS_CORE.C
OS_FLAG.C
OS_MBOX.C
OS_MEM.C
OS_MUTEX.C
OS_Q.C
OS_SEM.C
OS_TASK.C
OS_TIME.C
uCOS_II.C
uCOS_II.H
??????????c51?????????????????è??????????????????????????
B?????????à??????????
INCLUDES.H?? °ü??C51??±ê×????·????????"pdata"??c51???ü×??????¨??
OS_CFG.H?? "OS_TICKS_PER_SEC"??" OS_FLAGS"×????????è????????
C???????í?÷?à??????????
OS_CPU.H?? ?????à??????????·?·¨??????????·??ò?????????????ê?¨?????è????????
OS_CPU_A.ASM?? OSTickISR()??OSStartHighRdy()??OSCtxSw()??OSIntCtxSw()??????????
??±à???????????????????ü??
OS_CPU_C.C??OSTaskStkInit()??????±à????
?¨4??uCOS C51????????????????
1??C51???????á????
???????????????????????????????ù????±??ê???é????
A?? ??????????
c51?????????????????×???·??"?STACK"??????????????"SP"?????????ú?¤·??ò???ò??????
??????·?????51??????RAM?¨idata??????"?STACK"·??????ù??????RAM????????×??ó?????ù
????????????·??§?????STACK??????RAM??×?????(0x80?ò??0xFF)??
B?? ??????????
c51????????????????OS????????LARGE±à??????,?ù??????????????????"?C_XBP"?? ?????ú
?¤·??ò???ò????????????·?????51??????RAM?¨xdata??????
C?? C51????????????±??¤??
????????????????±??¤?????????????ò??uCOS??????????????±??í??????????????????·?
?ú??±??¤Task1??CPU?????÷??SP??????Task2????????????Task2??CPU?????÷????C51??????
???????±?ò??±à???÷?á×???±??¤CPU???????÷???ù??????·????±?????÷??OSIntCtxSw()????
????????±??¤?????÷??
C51???????÷??????????·????????é???¨????????±??í???è??reentrant????
???? ?????????÷????
???? ?÷??·?reentrant???????????????????×?÷????????????
???? ?÷??·?reentrant???????????????×?÷????????????
???? ?÷??reentrant??????
t0_isr:
PUSH ACC
PUSH B
PUSH DPH
PUSH DPL
PUSH PSW
MOV PSW,#00H
PUSH AR0
PUSH AR1
PUSH AR2
PUSH AR3
PUSH AR4
PUSH AR5
PUSH AR6
PUSH AR7
???§?ú??
POP AR7
POP AR6
POP AR5
POP AR4
POP AR3
POP AR2
POP AR1
POP AR0
POP PSW
POP DPL
POP DPH
POP B
POP ACC
RETI
?ò??uCOS???ù??????????±????????????????ò?????????è?????????????é??????????±??¤??
?????????é???????¤??????c51?????????¨×??????????ò??c51±à???÷??°?±???????????????
?????ò????????????
2??uCOS C51?????????±????????×÷??
????????????????????????????????????????????????????
±??¤Task1??CPU?????÷?? ?×????CPU?????÷°?????????Task1??????????????????Task1????
????????Task1??????????
SP???????C_XBP = Task2 ?????????????????·??
????Task2??CPU?????÷????Task2???????????????????????????????????ó????Task2??????
????????CPU?????÷????
??????·?·¨?????à????????×???uCOS?????????????í??????????
??×? [shenxian] 2005-1-24 11:45:55
Chapter 2 [pwl999] 2005-1-24 11:48:34
3??INCLUDES.H????????
??????
"pdata"??C51???ü×????ù?????????¨??
???ú????
#include <reg52.h>
#include <stdio.h>
#include <string.h>
#include <ctype.h>
#include <stdlib.h>
#include <setjmp.h>
#define TASK_REENTRANT large reentrant
#define KCREENTRANT large reentrant
#include "os_cpu.h"
#include "os_cfg.h"
#define data ucos51_data
#define idata ucos51_idata
#define pdata ucos51_pdata
#define xdata ucos51_xdata
#include "ucos_ii.h"
4??OS_CPU.H????????
typedef unsigned char BOOLEAN;
typedef unsigned char INT8U;
typedef signed char INT8S;
typedef unsigned int INT16U;
typedef signed int INT16S;
typedef unsigned long INT32U;
typedef signed long INT32S;
typedef float FP32;
typedef unsigned char OS_STK;
#define BYTE INT8S
#define UBYTE INT8U
#define WORD INT16S
#define UWORD INT16U
#define LONG INT32S
#define ULONG INT32U
Chapter 3 [pwl999] 2005-1-24 11:55:14
5??OS_CPU_A.ASM????????
??????
1??C51?????±?????÷?????????ò
2??Asm????" ?C_XBP"??" ?STACK'??????
3????????????·??ò?????????????????ó???????????????ó????????
???ú????
NAME OS_CPU_A
;******************************************************************
; PUBLIC and EXTERNAL REFERENCES
;******************************************************************
?PR?_?OSStartHighRdy?OS_CPU_A SEGMENT CODE
?PR?_?OSCtxSw?OS_CPU_A SEGMENT CODE
?PR?_?OSIntCtxSw?OS_CPU_A SEGMENT CODE
?PR?_?OSTickISR?OS_CPU_A SEGMENT CODE
?STACK SEGMENT IDATA
DT?OS_CPU_A SEGMENT DATA
PUBLIC _?OSTickISR
PUBLIC _?OSStartHighRdy
PUBLIC _?OSCtxSw
PUBLIC _?OSIntCtxSw
PUBLIC OSTickRate
PUBLIC OSTickCtr
EXTRN DATA (?C_XBP)
EXTRN XDATA (OSTCBCur)
EXTRN XDATA (OSTCBHighRdy)
EXTRN XDATA (OSPrioCur)
EXTRN XDATA (OSPrioHighRdy)
EXTRN XDATA (OSRunning)
EXTRN CODE (_?OSIntEnter)
EXTRN CODE (_?OSIntExit)
EXTRN CODE (_?OSTimeTick)
EXTRN CODE (_?OSTaskSwHook)
??~ [pwl999] 2005-1-24 12:04:14
???í?±??????16k??????????????°??????????????í????°???????·???????
[caoqing] 2005-1-24 12:56:40
????,?? [huzimax] 2005-1-24 13:32:38
[??±?] 2005-1-24 13:42:43
??????????????????×??????????????????????????????ê???±???¨?????? [?ú?????ì] 2005-1-24 13:56:47
good?? [leifeng] 2005-1-24 18:33:31
Chapter 4 [pwl999] 2005-1-24 19:31:46
;******************************************************************
; MACRO DEFINE
;******************************************************************
PUSHALL MACRO
PUSH ACC
PUSH B
PUSH DPH
PUSH DPL
PUSH PSW
IRP REG, <R0, R1, R2, R3, R4, R5, R6, R7>
MOV A, REG
PUSH ACC
ENDM
ENDM
POPALL MACRO
IRP REG, <R7, R6, R5, R4, R3, R2, R1, R0>
POP ACC
MOV REG, A
ENDM
POP PSW
POP DPL
POP DPH
POP B
POP ACC
ENDM
Chapter 5 [pwl999] 2005-1-24 19:34:13
LoadXBP MACRO
MOV DPH, ?C_XBP
MOV DPL, ?C_XBP+1
ENDM
SaveXBP MACRO
;PUSH IE
;CLR EA
MOV ?C_XBP, DPH
MOV ?C_XBP+1,DPL
;POP IE
ENDM
LoadReg MACRO REG
MOVX A, @DPTR
MOV REG, A
ENDM
SaveReg MACRO REG
MOV A, REG
MOVX @DPTR, A
ENDM
Chapter 6 [pwl999] 2005-1-24 19:34:59
;******************************************************************
; VARIABLE DEFINE
;******************************************************************
RSEG ?STACK
DS 1 ;
RSEG DT?OS_CPU_A
OSTickRate:
DS 1
OSTickCtr:
DS 1
;******************************************************************
; void _?OSStartHighRdy(void);
;******************************************************************
RSEG ?PR?_?OSStartHighRdy?OS_CPU_A
_?OSStartHighRdy:
LCALL _?OSTaskSwHook
; OSRunning = TRUE;
MOV DPL, #LOW(OSRunning)
MOV DPH, #HIGH(OSRunning)
SaveReg #01
LJMP ?C_XBP_Load
Chapter 7 [pwl999] 2005-1-24 19:36:32
;******************************************************************
; void OSCtxSw(void);
;******************************************************************
RSEG ?PR?_?OSCtxSw?OS_CPU_A
_?OSCtxSw:
PUSHALL
SP_Offset:
LoadXBP
MOV A, SP
CLR C
SUBB A, #?STACK-1
MOV R5, A
INC A
CLR C
XCH A, DPL
SUBB A, DPL
JNC SP_Save
DEC DPH
SP_Save:
MOV DPL, A
SaveXBP
Chapter 8 [pwl999] 2005-1-24 19:37:17
SaveREG R5
MOV R0, #?STACK-1
Stack_Save_Loop:
INC DPTR
INC R0
SaveREG @R0
DJNZ R5, Stack_Save_Loop
;POPALL
; OSTCBCur->OSTCBStkPtr = ?C_XBP;
MOV DPL, #LOW(OSTCBCur)
MOV DPH, #HIGH(OSTCBCur)
INC DPTR
LoadReg R0
INC DPTR
LoadReg DPL
MOV DPH, R0
INC DPTR
SaveReg ?C_XBP
INC DPTR
SaveReg ?C_XBP+1
Chapter 9 [pwl999] 2005-1-24 19:39:21
; OSTCBCur = OSTCBHighRdy;
MOV DPL, #LOW(OSTCBHighRdy)
MOV DPH, #HIGH(OSTCBHighRdy)
LoadReg R0
INC DPTR
LoadReg R1
INC DPTR
LoadReg R2
MOV DPL, #LOW(OSTCBCur)
MOV DPH, #HIGH(OSTCBCur)
SaveReg R0
INC DPTR
SaveReg R1
INC DPTR
SaveReg R2
; OSPrioCur = OSPrioHighRdy;
MOV DPL, #LOW(OSPrioHighRdy)
MOV DPH, #HIGH(OSPrioHighRdy)
LoadReg R0
MOV DPL, #LOW(OSPrioCur)
MOV DPH, #HIGH(OSPrioCur)
SaveReg R0
Chapter 10 [pwl999] 2005-1-24 19:39:54
?C_XBP_Load:
; ?C_XBP = OSTCBCur->OSTCBStkPtr;
MOV DPL, #LOW(OSTCBCur)
MOV DPH, #HIGH(OSTCBCur)
INC DPTR
LoadReg R0
INC DPTR
LoadReg DPL
MOV DPH, R0
INC DPTR
LoadReg ?C_XBP
INC DPTR
LoadReg ?C_XBP+1
SP_Load:
LoadXBP
LoadREG R5
MOV R0, #?STACK-1
Stack_Load_Loop:
INC DPTR
INC R0
LoadREG @R0
DJNZ R5, Stack_Load_Loop
MOV SP, R0
INC DPTR
SaveXBP
; OSTCBCur->OSTCBStkPtr = ?C_XBP;
POPALL
RET
Chapter 11 [pwl999] 2005-1-24 19:40:30
;******************************************************************
; void OSIntCtxSw(void);
;******************************************************************
RSEG ?PR?_?OSIntCtxSw?OS_CPU_A
_?OSIntCtxSw:
DEC SP
DEC SP
DEC SP
DEC SP
LJMP SP_Offset
;******************************************************************
; void OSTickISR(void);
;******************************************************************
CSEG AT 000BH
LJMP _?OSTickISR
RSEG ?PR?_?OSTickISR?OS_CPU_A
_?OSTickISR:
LCALL ResetHwIntr
PUSHALL
;DEC OSTickCtr
;MOV A, OSTickCtr
;JNZ OSTick_End
;MOV OSTickCtr, OSTickRate
LCALL _?OSIntEnter
LCALL _?OSTimeTick
LCALL _?OSIntExit
OSTick_End:
POPALL
RET
ResetHwIntr:
RETI
END
Chapter 12 [pwl999] 2005-1-24 19:41:15
6??OS_CPU_C.C????????
??????
1??OSTaskStkInit??????pdata??????????????????·???
???ú????
OS_STK *OSTaskStkInit (void (*task)(void *pd) KCREENTRANT, void *pdata, OS_STK
*ptos, INT16U opt) KCREENTRANT
{
INT8U * stk;
opt = opt; /* 'opt' is not used, prevent
warning */
stk = (INT8U *) ptos; /* Load stack
pointer */
/*
stk -= sizeof(void *);
*(void**)stk = pdata;
*/
/*
*--stk = 0x01;
*--stk = ((INT16U)pdata >> 8);
*--stk = ((INT16U)pdata & 0xFF);
*/
*--stk = ((INT32U)pdata & 0xFF0000) >> 8;
*--stk = ((INT32U)pdata & 0x00FF00) >> 4;
*--stk = (INT32U)pdata & 0xFF;
*--stk = 7;
*--stk = 6;
*--stk = 5;
*--stk = 4;
/*
*--stk = 3;
*--stk = 2;
*--stk = 1;
*/
/*
stk -= sizeof(void *);
*(void**)stk = pdata;
*/
*--stk = 0x01;
*--stk = ((INT16U)pdata >> 8);
*--stk = ((INT16U)pdata & 0xFF);
*--stk = 0;
*--stk = PSW;
*--stk = 'L';
*--stk = 'H';
*--stk = 'B';
*--stk = 'A';
*--stk = ((INT16U)task >> 8);
*--stk = ((INT16U)task & 0x00FF);
*--stk = 15;
return ((void *)stk);
}
7????????
?ê?????ú???????????÷?????????????????ó????QQ????????
????Email:marine_love@163.com QQ:63467764
|