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

📄 os_flag.s

📁 ucos如何移植到单片机mega128
💻 S
📖 第 1 页 / 共 5 页
字号:
; *                            OS_FLAG_WAIT_SET_ALL   You will wait for ALL bits in 'mask' to be set   (1)
; *                            OS_FLAG_WAIT_CLR_ANY   You will wait for ANY bit  in 'mask' to be clear (0)
; *                            OS_FLAG_WAIT_SET_ANY   You will wait for ANY bit  in 'mask' 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
; *
; *              timeout       is an optional timeout (in clock ticks) that your task will wait for the
; *                            desired bit combination.  If you specify 0, however, your task will wait
; *                            forever at the specified event flag group or, until a message arrives.
; *
; *              err           is a pointer to an error code and can be:
; *                            OS_NO_ERR              The desired bits have been set within the specified
; *                                                   'timeout'.
; *                            OS_ERR_PEND_ISR        If you tried to PEND from an ISR
; *                            OS_FLAG_INVALID_PGRP   If 'pgrp' is a NULL pointer.
; *                            OS_ERR_EVENT_TYPE      You are not pointing to an event flag group
; *                            OS_TIMEOUT             The bit(s) have not been set in the specified
; *                                                   'timeout'.
; *                            OS_FLAG_ERR_WAIT_TYPE  You didn't specify a proper 'wait_type' argument.
; *
; * Returns    : The new state of the flags in the event flag group when the task is resumed or,
; *              0 if a timeout or an error occurred.
; *
; * Called from: Task ONLY
; *********************************************************************************************************
; */
; 
; OS_FLAGS  OSFlagPend (OS_FLAG_GRP *pgrp, OS_FLAGS flags, INT8U wait_type, INT16U timeout, INT8U *err)
; {
	.dbline 388
; #if OS_CRITICAL_METHOD == 3                                /* Allocate storage for CPU status register */
;     OS_CPU_SR     cpu_sr;
; #endif
;     OS_FLAG_NODE  node;
;     OS_FLAGS      flags_cur;
;     OS_FLAGS      flags_rdy;
;     BOOLEAN       consume;
; 
; 
;     if (OSIntNesting > 0) {                                /* See if called from ISR ...               */
	clr R2
	lds R3,_OSIntNesting
	cp R2,R3
	brsh L60
	.dbline 388
	.dbline 389
;         *err = OS_ERR_PEND_ISR;                            /* ... can't PEND from an ISR               */
	ldi R24,2
	movw R30,R22
	std z+0,R24
	.dbline 390
;         return ((OS_FLAGS)0);
	clr R16
	xjmp L59
L60:
	.dbline 393
;     }
; #if OS_ARG_CHK_EN > 0
;     if (pgrp == (OS_FLAG_GRP *)0) {                        /* Validate 'pgrp'                          */
	tst R6
	brne L62
	tst R7
	brne L62
X11:
	.dbline 393
	.dbline 394
;         *err = OS_FLAG_INVALID_PGRP;
	ldi R24,150
	movw R30,R22
	std z+0,R24
	.dbline 395
;         return ((OS_FLAGS)0);
	clr R16
	xjmp L59
L62:
	.dbline 397
;     }
;     if (pgrp->OSFlagType != OS_EVENT_TYPE_FLAG) {          /* Validate event block type                */
	movw R30,R6
	ldd R24,z+0
	cpi R24,5
	breq L64
	.dbline 397
	.dbline 398
;         *err = OS_ERR_EVENT_TYPE;
	ldi R24,1
	movw R30,R22
	std z+0,R24
	.dbline 399
;         return ((OS_FLAGS)0);
	clr R16
	xjmp L59
L64:
	.dbline 402
;     }
; #endif
;     if (wait_type & OS_FLAG_CONSUME) {                     /* See if we need to consume the flags      */
	sbrs R12,7
	rjmp L66
	.dbline 402
	.dbline 403
;         wait_type &= ~OS_FLAG_CONSUME;
	mov R24,R12
	andi R24,127
	mov R12,R24
	.dbline 404
;         consume    = TRUE;
	clr R14
	inc R14
	.dbline 405
	xjmp L67
L66:
	.dbline 405
;     } else {
	.dbline 406
;         consume    = FALSE;
	clr R14
	.dbline 407
;     }
L67:
	.dbline 409
; /*$PAGE*/
;     OS_ENTER_CRITICAL();
	st -y,r16
	in r16,0x3F
	cli
	push r16
	ld r16,y+
	.dbline 409
	.dbline 410
	mov R20,R12
	clr R21
	cpi R20,0
	cpc R20,R21
	brne X16
	xjmp L81
X16:
X12:
	cpi R20,1
	ldi R30,0
	cpc R21,R30
	brne X17
	xjmp L86
X17:
	cpi R20,2
	ldi R30,0
	cpc R21,R30
	breq L71
	cpi R20,3
	ldi R30,0
	cpc R21,R30
	brne X18
	xjmp L76
X18:
	xjmp L68
X13:
	.dbline 410
;     switch (wait_type) {
L71:
	.dbline 412
;         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,R6
	ldd R10,z+3
	ldd R0,y+26
	and R10,R0
	.dbline 413
;              if (flags_rdy == flags) {                     /* Must match ALL the bits that we want     */
	cp R10,R0
	brne L72
	.dbline 413
	.dbline 414
;                  if (consume == TRUE) {                    /* See if we need to consume the flags      */
	mov R24,R14
	cpi R24,1
	brne L74
	.dbline 414
	.dbline 415
;                      pgrp->OSFlagFlags &= ~flags_rdy;      /* Clear ONLY the flags that we wanted      */
	movw R24,R6
	adiw R24,3
	mov R4,R10
	com R4
	movw R30,R24
	ldd R5,z+0
	and R5,R4
	std z+0,R5
	.dbline 416
;                  }
L74:
	.dbline 417
;                  flags_cur = pgrp->OSFlagFlags;            /* Will return the state of the group       */
	movw R30,R6
	ldd R20,z+3
	.dbline 418
;                  OS_EXIT_CRITICAL();                       /* Yes, condition met, return to caller     */
	st -y,r16
	pop r16
	out 0x3F,r16
	ld r16,y+
	.dbline 418
	.dbline 419
;                  *err      = OS_NO_ERR;
	clr R2
	movw R30,R22
	std z+0,R2
	.dbline 420
;                  return (flags_cur);
	mov R16,R20
	xjmp L59
L72:
	.dbline 421
;              } else {                                      /* Block task until events occur or timeout */
	.dbline 422
;                  OS_FlagBlock(pgrp, &node, flags, wait_type, timeout);
	ldd R0,y+30
	ldd R1,y+31
	std y+5,R1
	std y+4,R0
	std y+2,R12
	ldd R0,y+26
	std y+0,R0
	movw R18,R28
	subi R18,250  ; offset = 6
	sbci R19,255
	movw R16,R6
	push R16
	push R17
	xcall _OS_FlagBlock
	pop R7
	pop R6
	.dbline 423
;                  OS_EXIT_CRITICAL();
	st -y,r16
	pop r16
	out 0x3F,r16
	ld r16,y+
	.dbline 423
	.dbline 424
;              }
	.dbline 425
;              break;
	xjmp L69
L76:
	.dbline 428
; 
;         case OS_FLAG_WAIT_SET_ANY:
;              flags_rdy = pgrp->OSFlagFlags & flags;        /* Extract only the bits we want            */
	movw R30,R6
	ldd R10,z+3
	ldd R0,y+26
	and R10,R0
	.dbline 429
;              if (flags_rdy != (OS_FLAGS)0) {               /* See if any flag set                      */
	breq L77
	.dbline 429
	.dbline 430
;                  if (consume == TRUE) {                    /* See if we need to consume the flags      */
	mov R24,R14
	cpi R24,1
	brne L79
	.dbline 430
	.dbline 431
;                      pgrp->OSFlagFlags &= ~flags_rdy;      /* Clear ONLY the flags that we got         */
	movw R24,R6
	adiw R24,3
	mov R4,R10
	com R4
	movw R30,R24
	ldd R5,z+0
	and R5,R4
	std z+0,R5
	.dbline 432
;                  }
L79:
	.dbline 433
;                  flags_cur = pgrp->OSFlagFlags;            /* Will return the state of the group       */
	movw R30,R6
	ldd R20,z+3
	.dbline 434
;                  OS_EXIT_CRITICAL();                       /* Yes, condition met, return to caller     */
	st -y,r16
	pop r16
	out 0x3F,r16
	ld r16,y+
	.dbline 434
	.dbline 435
;                  *err      = OS_NO_ERR;
	clr R2
	movw R30,R22
	std z+0,R2
	.dbline 436
;                  return (flags_cur);
	mov R16,R20
	xjmp L59
L77:
	.dbline 437
;              } else {                                      /* Block task until events occur or timeout */
	.dbline 438
;                  OS_FlagBlock(pgrp, &node, flags, wait_type, timeout);
	ldd R0,y+30
	ldd R1,y+31
	std y+5,R1
	std y+4,R0
	std y+2,R12
	ldd R0,y+26
	std y+0,R0
	movw R18,R28
	subi R18,250  ; offset = 6
	sbci R19,255
	movw R16,R6
	push R16
	push R17
	xcall _OS_FlagBlock
	pop R7
	pop R6
	.dbline 439
;                  OS_EXIT_CRITICAL();
	st -y,r16
	pop r16
	out 0x3F,r16
	ld r16,y+
	.dbline 439
	.dbline 440
;              }
	.dbline 441
;              break;
	xjmp L69
L81:
	.dbline 445
; 
; #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,R6
	ldd R10,z+3
	com R10
	ldd R0,y+26
	and R10,R0
	.dbline 446
;              if (flags_rdy == flags) {                     /* Must match ALL the bits that we want     */
	cp R10,R0
	brne L82
	.dbline 446
	.dbline 447
;                  if (consume == TRUE) {                    /* See if we need to consume the flags      */
	mov R24,R14
	cpi R24,1
	brne L84
	.dbline 447
	.dbline 448
;                      pgrp->OSFlagFlags |= flags_rdy;       /* Set ONLY the flags that we wanted        */
	movw R24,R6
	adiw R24,3
	movw R30,R24
	ldd R4,z+0
	or R4,R10
	std z+0,R4
	.dbline 449
;                  }
L84:
	.dbline 450
;                  flags_cur = pgrp->OSFlagFlags;            /* Will return the state of the group       */
	movw R30,R6
	ldd R20,z+3
	.dbline 451
;                  OS_EXIT_CRITICAL();                       /* Yes, condition met, return to caller     */
	st -y,r16
	pop r16
	out 0x3F,r16
	ld r16,y+
	.dbline 451
	.dbline 452
;                  *err      = OS_NO_ERR;
	clr R2
	movw R30,R22
	std z+0,R2
	.dbline 453
;                  return (flags_cur);
	mov R16,R20
	xjmp L59
L82:
	.dbline 454
;              } else {                                      /* Block task until events occur or timeout */
	.dbline 455
;                  OS_FlagBlock(pgrp, &node, flags, wait_type, timeout);
	ldd R0,y+30
	ldd R1,y+31
	std y+5,R1
	std y+4,R0
	std y+2,R12
	ldd R0,y+26
	std y+0,R0
	movw R18,R28
	subi R18,250  ; offset = 6
	sbci R19,255
	movw R16,R6
	push R16
	push R17
	xcall _OS_FlagBlock
	pop R7
	pop R6
	.dbline 456
;                  OS_EXIT_CRITICAL();
	st -y,r16
	pop r16
	out 0x3F,r16
	ld r16,y+
	.dbline 456
	.dbline 457
;              }
	.dbline 458
;              break;
	xjmp L69
L86:
	.dbline 461
; 
;         case OS_FLAG_WAIT_CLR_ANY:
;              flags_rdy = ~pgrp->OSFlagFlags & flags;       /* Extract only the bits we want            */
	movw R30,R6
	ldd R10,z+3
	com R10
	ldd R0,y+26
	and R10,R0
	.dbline 462
;              if (flags_rdy != (OS_FLAGS)0) {               /* See if any flag cleared                  */
	breq L87
	.dbline 462
	.dbline 463
;                  if (consume == TRUE) {                    /* See if we need to consume the flags      */
	mov R24,R14
	cpi R24,1
	brne L89
	.dbline 463
	.dbline 464
;                      pgrp->OSFlagFlags |= flags_rdy;       /* Set ONLY the flags that we got           */
	movw R24,R6
	adiw R24,3
	movw R30,R24
	ldd R4,z+0
	or R4,R10
	std z+0,R4
	.dbline 465
;                  }
L89:
	.dbline 466
;                  flags_cur = pgrp->OSFlagFlags;            /* Will return the state of the group       */
	movw R30,R6
	ldd R20,z+3
	.dbline 467
;                  OS_EXIT_CRITICAL();                       /* Yes, condition met, return to caller     */
	st -y,r16
	pop r16
	out 0x3F,r16
	ld r16,y+
	.dbline 467
	.dbline 468
;                  *err      = OS_NO_ERR;
	clr R2
	movw R30,R22
	std z+0,R2
	.dbline 469
;                  return (flags_cur);
	mov R16,R20
	xjmp L59
L87:
	.dbline 470
;              } else {                                      /* Block task until events occur or timeout */
	.dbline 471
;                  OS_FlagBlock(pgrp, &node, flags, wait_type, timeout);
	ldd R0,y+30
	ldd R1,y+31
	std y+5,R1
	std y+4,R0
	std y+2,R12
	ldd R0,y+26
	std y+0,R0
	movw R18,R28
	subi R18,250  ; offset = 6
	sbci R19,255
	movw R16,R6
	push R16
	push R17
	xcall _OS_FlagBlock
	pop R7
	pop R6
	.dbline 472
;                  OS_EXIT_CRITICAL();
	st -y,r16
	pop r16
	out 0x3F,r16
	ld r16,y+
	.dbline 472
	.dbline 473
;              }
	.dbline 474
;              break;
	xjmp L69
L68:
	.dbline 478
; #endif

⌨️ 快捷键说明

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