⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 os_flag.s

📁 ucos如何移植到单片机mega128
💻 S
📖 第 1 页 / 共 5 页
字号:
	.module OS_FLAG.C
	.area text(rom, con, rel)
	.dbfile E:\study\ucos_ii\ucos2_iccavr\iccavr\ucos2_without_cpu\OS_FLAG.C
	.dbfunc e OSFlagAccept _OSFlagAccept fc
	.dbstruct 0 4 .1
	.dbfield 0 OSFlagType c
	.dbfield 1 OSFlagWaitList pV
	.dbfield 3 OSFlagFlags c
	.dbend
;      flags_rdy -> R10
;        consume -> R12
;      flags_cur -> R20
;            err -> R22,R23
;      wait_type -> R20
;          flags -> R18
;           pgrp -> R16,R17
	.even
_OSFlagAccept::
	xcall push_gset4
	ldd R20,y+8
	ldd R22,y+10
	ldd R23,y+11
	.dbline -1
	.dbline 79
; /*
; *********************************************************************************************************
; *                                                uC/OS-II
; *                                          The Real-Time Kernel
; *                                         EVENT FLAG  MANAGEMENT
; *
; *                          (c) Copyright 2001-2002, Jean J. Labrosse, Weston, FL
; *                                           All Rights Reserved
; *
; * File : OS_FLAG.C
; * By   : Jean J. Labrosse
; *********************************************************************************************************
; */
; 
; #ifndef  OS_MASTER_FILE
; #include "..\ucos2_application\INCLUDES.H"
; #endif
; 
; #if (OS_VERSION >= 251) && (OS_FLAG_EN > 0) && (OS_MAX_FLAGS > 0)
; /*
; *********************************************************************************************************
; *                                            LOCAL PROTOTYPES
; *********************************************************************************************************
; */
; 
; static  void     OS_FlagBlock(OS_FLAG_GRP *pgrp, OS_FLAG_NODE *pnode, OS_FLAGS flags, INT8U wait_type, INT16U timeout);
; static  BOOLEAN  OS_FlagTaskRdy(OS_FLAG_NODE *pnode, OS_FLAGS flags_rdy);
; 
; /*$PAGE*/
; /*
; *********************************************************************************************************
; *                              CHECK THE STATUS OF FLAGS IN AN EVENT FLAG GROUP
; *
; * Description: This function is called to check the status of a combination of bits to be set or cleared
; *              in an event flag group.  Your application can check for ANY bit to be set/cleared or ALL
; *              bits to be set/cleared.
; *
; *              This call does not block if the desired flags are not present.
; *
; * Arguments  : pgrp          is a pointer to the desired event flag group.
; *
; *              flags         Is a bit pattern indicating which bit(s) (i.e. flags) you wish to check.
; *                            The bits you want are specified by setting the corresponding bits in
; *                            'flags'.  e.g. if your application wants to wait for bits 0 and 1 then
; *                            'flags' would contain 0x03.
; *
; *              wait_type     specifies whether you want ALL bits to be set/cleared or ANY of the bits
; *                            to be set/cleared.
; *                            You can specify the following argument:
; *
; *                            OS_FLAG_WAIT_CLR_ALL   You will check ALL bits in 'flags' to be clear (0)
; *                            OS_FLAG_WAIT_CLR_ANY   You will check ANY bit  in 'flags' to be clear (0)
; *                            OS_FLAG_WAIT_SET_ALL   You will check ALL bits in 'flags' to be set   (1)
; *                            OS_FLAG_WAIT_SET_ANY   You will check ANY bit  in 'flags' to be set   (1)
; *
; *                            NOTE: Add OS_FLAG_CONSUME if you want the event flag to be 'consumed' by
; *                                  the call.  Example, to wait for any flag in a group AND then clear
; *                                  the flags that are present, set 'wait_type' to:
; *
; *                                  OS_FLAG_WAIT_SET_ANY + OS_FLAG_CONSUME
; *
; *              err           is a pointer to an error code and can be:
; *                            OS_NO_ERR              No error
; *                            OS_ERR_EVENT_TYPE      You are not pointing to an event flag group
; *                            OS_FLAG_ERR_WAIT_TYPE  You didn't specify a proper 'wait_type' argument.
; *                            OS_FLAG_INVALID_PGRP   You passed a NULL pointer instead of the event flag
; *                                                   group handle.
; *                            OS_FLAG_ERR_NOT_RDY    The desired flags you are waiting for are not
; *                                                   available.
; *
; * Returns    : The state of the flags in the event flag group.
; *
; * Called from: Task or ISR
; *********************************************************************************************************
; */
; 
; #if OS_FLAG_ACCEPT_EN > 0
; OS_FLAGS  OSFlagAccept (OS_FLAG_GRP *pgrp, OS_FLAGS flags, INT8U wait_type, INT8U *err)
; {
	.dbline 89
; #if OS_CRITICAL_METHOD == 3                                /* Allocate storage for CPU status register */
;     OS_CPU_SR     cpu_sr;
; #endif
;     OS_FLAGS      flags_cur;
;     OS_FLAGS      flags_rdy;
;     BOOLEAN       consume;
; 
; 
; #if OS_ARG_CHK_EN > 0
;     if (pgrp == (OS_FLAG_GRP *)0) {                        /* Validate 'pgrp'                          */
	cpi R16,0
	cpc R16,R17
	brne L4
X0:
	.dbline 89
	.dbline 90
;         *err = OS_FLAG_INVALID_PGRP;
	ldi R24,150
	movw R30,R22
	std z+0,R24
	.dbline 91
;         return ((OS_FLAGS)0);
	clr R16
	xjmp L3
L4:
	.dbline 93
;     }
;     if (pgrp->OSFlagType != OS_EVENT_TYPE_FLAG) {          /* Validate event block type                */
	movw R30,R16
	ldd R24,z+0
	cpi R24,5
	breq L6
	.dbline 93
	.dbline 94
;         *err = OS_ERR_EVENT_TYPE;
	ldi R24,1
	movw R30,R22
	std z+0,R24
	.dbline 95
;         return ((OS_FLAGS)0);
	clr R16
	xjmp L3
L6:
	.dbline 98
;     }
; #endif
;     if (wait_type & OS_FLAG_CONSUME) {                     /* See if we need to consume the flags      */
	sbrs R20,7
	rjmp L8
	.dbline 98
	.dbline 99
;         wait_type &= ~OS_FLAG_CONSUME;
	andi R20,127
	.dbline 100
;         consume    = TRUE;
	clr R12
	inc R12
	.dbline 101
	xjmp L9
L8:
	.dbline 101
;     } else {
	.dbline 102
;         consume    = FALSE;
	clr R12
	.dbline 103
;     }
L9:
	.dbline 105
; /*$PAGE*/
;     *err = OS_NO_ERR;                                      /* Assume NO error until proven otherwise.  */
	clr R2
	movw R30,R22
	std z+0,R2
	.dbline 106
;     OS_ENTER_CRITICAL();
	st -y,r16
	in r16,0x3F
	cli
	push r16
	ld r16,y+
	.dbline 106
	.dbline 107
	clr R21
	cpi R20,0
	cpc R20,R21
	brne X3
	xjmp L23
X3:
X1:
	cpi R20,1
	ldi R30,0
	cpc R21,R30
	brne X4
	xjmp L28
X4:
	cpi R20,2
	ldi R30,0
	cpc R21,R30
	breq L13
	cpi R20,3
	ldi R30,0
	cpc R21,R30
	breq L18
	xjmp L10
X2:
	.dbline 107
;     switch (wait_type) {
L13:
	.dbline 109
;         case OS_FLAG_WAIT_SET_ALL:                         /* See if all required flags are set        */
;              flags_rdy = pgrp->OSFlagFlags & flags;        /* Extract only the bits we want            */
	movw R30,R16
	ldd R10,z+3
	and R10,R18
	.dbline 110
;              if (flags_rdy == flags) {                     /* Must match ALL the bits that we want     */
	cp R10,R18
	brne L14
	.dbline 110
	.dbline 111
;                  if (consume == TRUE) {                    /* See if we need to consume the flags      */
	mov R24,R12
	cpi R24,1
	brne L15
	.dbline 111
	.dbline 112
;                      pgrp->OSFlagFlags &= ~flags_rdy;      /* Clear ONLY the flags that we wanted      */
	movw R24,R16
	adiw R24,3
	mov R4,R10
	com R4
	movw R30,R24
	ldd R5,z+0
	and R5,R4
	std z+0,R5
	.dbline 113
;                  }
	.dbline 114
	xjmp L15
L14:
	.dbline 114
;              } else {
	.dbline 115
;                  *err  = OS_FLAG_ERR_NOT_RDY;
	ldi R24,152
	movw R30,R22
	std z+0,R24
	.dbline 116
;              }
L15:
	.dbline 117
;              flags_cur = pgrp->OSFlagFlags;                /* Will return the state of the group       */
	movw R30,R16
	ldd R20,z+3
	.dbline 118
;              OS_EXIT_CRITICAL();
	st -y,r16
	pop r16
	out 0x3F,r16
	ld r16,y+
	.dbline 118
	.dbline 119
;              break;
	xjmp L11
L18:
	.dbline 122
; 
;         case OS_FLAG_WAIT_SET_ANY:
;              flags_rdy = pgrp->OSFlagFlags & flags;        /* Extract only the bits we want            */
	movw R30,R16
	ldd R10,z+3
	and R10,R18
	.dbline 123
;              if (flags_rdy != (OS_FLAGS)0) {               /* See if any flag set                      */
	breq L19
	.dbline 123
	.dbline 124
;                  if (consume == TRUE) {                    /* See if we need to consume the flags      */
	mov R24,R12
	cpi R24,1
	brne L20
	.dbline 124
	.dbline 125
;                      pgrp->OSFlagFlags &= ~flags_rdy;      /* Clear ONLY the flags that we got         */
	movw R24,R16
	adiw R24,3
	mov R4,R10
	com R4
	movw R30,R24
	ldd R5,z+0
	and R5,R4
	std z+0,R5
	.dbline 126
;                  }
	.dbline 127
	xjmp L20
L19:
	.dbline 127
;              } else {
	.dbline 128
;                  *err  = OS_FLAG_ERR_NOT_RDY;
	ldi R24,152
	movw R30,R22
	std z+0,R24
	.dbline 129
;              }
L20:
	.dbline 130
;              flags_cur = pgrp->OSFlagFlags;                /* Will return the state of the group       */
	movw R30,R16
	ldd R20,z+3
	.dbline 131
;              OS_EXIT_CRITICAL();
	st -y,r16
	pop r16
	out 0x3F,r16
	ld r16,y+
	.dbline 131
	.dbline 132
;              break;
	xjmp L11
L23:
	.dbline 136
; 
; #if OS_FLAG_WAIT_CLR_EN > 0
;         case OS_FLAG_WAIT_CLR_ALL:                         /* See if all required flags are cleared    */
;              flags_rdy = ~pgrp->OSFlagFlags & flags;       /* Extract only the bits we want            */
	movw R30,R16
	ldd R10,z+3
	com R10
	and R10,R18
	.dbline 137
;              if (flags_rdy == flags) {                     /* Must match ALL the bits that we want     */
	cp R10,R18
	brne L24
	.dbline 137
	.dbline 138
;                  if (consume == TRUE) {                    /* See if we need to consume the flags      */
	mov R24,R12
	cpi R24,1
	brne L25
	.dbline 138
	.dbline 139
;                      pgrp->OSFlagFlags |= flags_rdy;       /* Set ONLY the flags that we wanted        */
	movw R24,R16
	adiw R24,3
	movw R30,R24
	ldd R4,z+0
	or R4,R10
	std z+0,R4
	.dbline 140
;                  }
	.dbline 141
	xjmp L25
L24:
	.dbline 141
;              } else {
	.dbline 142
;                  *err  = OS_FLAG_ERR_NOT_RDY;
	ldi R24,152
	movw R30,R22
	std z+0,R24
	.dbline 143
;              }
L25:
	.dbline 144
;              flags_cur = pgrp->OSFlagFlags;                /* Will return the state of the group       */
	movw R30,R16
	ldd R20,z+3
	.dbline 145
;              OS_EXIT_CRITICAL();
	st -y,r16
	pop r16
	out 0x3F,r16
	ld r16,y+
	.dbline 145
	.dbline 146
;              break;
	xjmp L11
L28:
	.dbline 149
; 
;         case OS_FLAG_WAIT_CLR_ANY:
;              flags_rdy = ~pgrp->OSFlagFlags & flags;       /* Extract only the bits we want            */
	movw R30,R16
	ldd R10,z+3
	com R10
	and R10,R18
	.dbline 150
;              if (flags_rdy != (OS_FLAGS)0) {               /* See if any flag cleared                  */
	breq L29
	.dbline 150
	.dbline 151
;                  if (consume == TRUE) {                    /* See if we need to consume the flags      */
	mov R24,R12
	cpi R24,1
	brne L30
	.dbline 151
	.dbline 152
;                      pgrp->OSFlagFlags |= flags_rdy;       /* Set ONLY the flags that we got           */
	movw R24,R16
	adiw R24,3
	movw R30,R24
	ldd R4,z+0
	or R4,R10
	std z+0,R4
	.dbline 153
;                  }
	.dbline 154
	xjmp L30
L29:
	.dbline 154
;              } else {
	.dbline 155
;                  *err  = OS_FLAG_ERR_NOT_RDY;
	ldi R24,152
	movw R30,R22
	std z+0,R24
	.dbline 156
;              }
L30:
	.dbline 157
;              flags_cur = pgrp->OSFlagFlags;                /* Will return the state of the group       */
	movw R30,R16
	ldd R20,z+3
	.dbline 158
;              OS_EXIT_CRITICAL();
	st -y,r16
	pop r16
	out 0x3F,r16
	ld r16,y+
	.dbline 158
	.dbline 159
;              break;
	xjmp L11
L10:
	.dbline 163
; #endif
; 
;         default:
;              OS_EXIT_CRITICAL();
	st -y,r16
	pop r16
	out 0x3F,r16
	ld r16,y+
	.dbline 163
	.dbline 164
;              flags_cur = (OS_FLAGS)0;
	clr R20
	.dbline 165
;              *err      = OS_FLAG_ERR_WAIT_TYPE;
	ldi R24,151
	movw R30,R22
	std z+0,R24
	.dbline 166
;              break;
L11:
	.dbline 168
;     }
;     return (flags_cur);
	mov R16,R20
	.dbline -2
L3:
	xcall pop_gset4
	.dbline 0 ; func end
	ret
	.dbsym r flags_rdy 10 c
	.dbsym r consume 12 c
	.dbsym r flags_cur 20 c
	.dbsym r err 22 pc
	.dbsym r wait_type 20 c
	.dbsym r flags 18 c
	.dbsym r pgrp 16 pS[.1]
	.dbend
	.dbfunc e OSFlagCreate _OSFlagCreate fpS[.1]
;           pgrp -> R20,R21
;            err -> R18,R19
;          flags -> R16
	.even
_OSFlagCreate::
	xcall push_gset1
	.dbline -1
	.dbline 194
; }
; #endif
; 
; /*$PAGE*/
; /*
; *********************************************************************************************************
; *                                           CREATE AN EVENT FLAG
; *
; * Description: This function is called to create an event flag group.
; *
; * Arguments  : flags         Contains the initial value to store in the event flag group.
; *
; *              err           is a pointer to an error code which will be returned to your application:
; *                               OS_NO_ERR                if the call was successful.
; *                               OS_ERR_CREATE_ISR        if you attempted to create an Event Flag from an
; *                                                        ISR.
; *                               OS_FLAG_GRP_DEPLETED     if there are no more event flag groups

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -