os_sem.lis
来自「将本站的UCOSFORAVR128V276版本升级到了280版」· LIS 代码 · 共 1,276 行 · 第 1/5 页
LIS
1,276 行
.module os_sem.c
.area text(rom, con, rel)
0000 .dbfile E:\ypt050912\XIAZAI\xinzai\UCOSAVR128\Source\os_sem.c
0000 .dbfunc e OSSemAccept _OSSemAccept fi
0000 .dbstruct 0 8 os_event
0000 .dbfield 0 OSEventType c
0000 .dbfield 1 OSEventPtr pV
0000 .dbfield 3 OSEventCnt i
0000 .dbfield 5 OSEventGrp c
0000 .dbfield 6 OSEventTbl A[2:2]c
0000 .dbend
0000 ; cpu_sr -> R22
0000 ; cnt -> R20,R21
0000 ; pevent -> R10,R11
.even
0000 _OSSemAccept::
0000 0E940000 xcall push_gset3
0004 5801 movw R10,R16
0006 .dbline -1
0006 .dbline 41
0006 ; /*
0006 ; *********************************************************************************************************
0006 ; * uC/OS-II
0006 ; * The Real-Time Kernel
0006 ; * SEMAPHORE MANAGEMENT
0006 ; *
0006 ; * (c) Copyright 1992-2005, Jean J. Labrosse, Weston, FL
0006 ; * All Rights Reserved
0006 ; *
0006 ; * File : OS_SEM.C
0006 ; * By : Jean J. Labrosse
0006 ; * Version : V2.80
0006 ; *********************************************************************************************************
0006 ; */
0006 ;
0006 ; #ifndef OS_MASTER_FILE
0006 ; #include <ucos_ii.h>
0006 ; #endif
0006 ;
0006 ; #if OS_SEM_EN > 0
0006 ; /*
0006 ; *********************************************************************************************************
0006 ; * ACCEPT SEMAPHORE
0006 ; *
0006 ; * Description: This function checks the semaphore to see if a resource is available or, if an event
0006 ; * occurred. Unlike OSSemPend(), OSSemAccept() does not suspend the calling task if the
0006 ; * resource is not available or the event did not occur.
0006 ; *
0006 ; * Arguments : pevent is a pointer to the event control block
0006 ; *
0006 ; * Returns : > 0 if the resource is available or the event did not occur the semaphore is
0006 ; * decremented to obtain the resource.
0006 ; * == 0 if the resource is not available or the event did not occur or,
0006 ; * if 'pevent' is a NULL pointer or,
0006 ; * if you didn't pass a pointer to a semaphore
0006 ; *********************************************************************************************************
0006 ; */
0006 ;
0006 ; #if OS_SEM_ACCEPT_EN > 0
0006 ; INT16U OSSemAccept (OS_EVENT *pevent)
0006 ; {
0006 .dbline 44
0006 ; INT16U cnt;
0006 ; #if OS_CRITICAL_METHOD == 3 /* Allocate storage for CPU status register */
0006 ; OS_CPU_SR cpu_sr = 0;
0006 6627 clr R22
0008 .dbline 54
0008 ; #endif
0008 ;
0008 ;
0008 ;
0008 ; #if OS_ARG_CHK_EN > 0
0008 ; if (pevent == (OS_EVENT *)0) { /* Validate 'pevent' */
0008 ; return (0);
0008 ; }
0008 ; #endif
0008 ; if (pevent->OSEventType != OS_EVENT_TYPE_SEM) { /* Validate event block type */
0008 F501 movw R30,R10
000A 8081 ldd R24,z+0
000C 8330 cpi R24,3
000E 19F0 breq L2
0010 .dbline 54
0010 .dbline 55
0010 ; return (0);
0010 0027 clr R16
0012 1127 clr R17
0014 15C0 xjmp L1
0016 L2:
0016 .dbline 57
0016 ; }
0016 ; OS_ENTER_CRITICAL();
0016 0E940000 xcall _OS_CPU_SR_Save
001A 602F mov R22,R16
001C .dbline 58
001C ; cnt = pevent->OSEventCnt;
001C F501 movw R30,R10
001E 4381 ldd R20,z+3
0020 5481 ldd R21,z+4
0022 .dbline 59
0022 ; if (cnt > 0) { /* See if resource is available */
0022 4030 cpi R20,0
0024 4507 cpc R20,R21
0026 41F0 breq L4
0028 X0:
0028 .dbline 59
0028 .dbline 60
0028 ; pevent->OSEventCnt--; /* Yes, decrement semaphore and notify caller */
0028 C501 movw R24,R10
002A 0396 adiw R24,3
002C FC01 movw R30,R24
002E 8081 ldd R24,z+0
0030 9181 ldd R25,z+1
0032 0197 sbiw R24,1
0034 9183 std z+1,R25
0036 8083 std z+0,R24
0038 .dbline 61
0038 ; }
0038 L4:
0038 .dbline 62
0038 ; OS_EXIT_CRITICAL();
0038 062F mov R16,R22
003A 0E940000 xcall _OS_CPU_SR_Restore
003E .dbline 63
003E ; return (cnt); /* Return semaphore count */
003E 8A01 movw R16,R20
0040 .dbline -2
0040 L1:
0040 0E940000 xcall pop_gset3
0044 .dbline 0 ; func end
0044 0895 ret
0046 .dbsym r cpu_sr 22 c
0046 .dbsym r cnt 20 i
0046 .dbsym r pevent 10 pS[os_event]
0046 .dbend
0046 .dbfunc e OSSemCreate _OSSemCreate fpS[os_event]
0046 ; cpu_sr -> R10
0046 ; pevent -> R20,R21
0046 ; cnt -> R22,R23
.even
0046 _OSSemCreate::
0046 0E940000 xcall push_gset3
004A B801 movw R22,R16
004C .dbline -1
004C .dbline 86
004C ; }
004C ; #endif
004C ;
004C ; /*$PAGE*/
004C ; /*
004C ; *********************************************************************************************************
004C ; * CREATE A SEMAPHORE
004C ; *
004C ; * Description: This function creates a semaphore.
004C ; *
004C ; * Arguments : cnt is the initial value for the semaphore. If the value is 0, no resource is
004C ; * available (or no event has occurred). You initialize the semaphore to a
004C ; * non-zero value to specify how many resources are available (e.g. if you have
004C ; * 10 resources, you would initialize the semaphore to 10).
004C ; *
004C ; * Returns : != (void *)0 is a pointer to the event control clock (OS_EVENT) associated with the
004C ; * created semaphore
004C ; * == (void *)0 if no event control blocks were available
004C ; *********************************************************************************************************
004C ; */
004C ;
004C ; OS_EVENT *OSSemCreate (INT16U cnt)
004C ; {
004C .dbline 89
004C ; OS_EVENT *pevent;
004C ; #if OS_CRITICAL_METHOD == 3 /* Allocate storage for CPU status register */
004C ; OS_CPU_SR cpu_sr = 0;
004C AA24 clr R10
004E .dbline 94
004E ; #endif
004E ;
004E ;
004E ;
004E ; if (OSIntNesting > 0) { /* See if called from ISR ... */
004E 2224 clr R2
0050 30900000 lds R3,_OSIntNesting
0054 2314 cp R2,R3
0056 18F4 brsh L7
0058 .dbline 94
0058 .dbline 95
0058 ; return ((OS_EVENT *)0); /* ... can't CREATE from an ISR */
0058 0027 clr R16
005A 1127 clr R17
005C 28C0 xjmp L6
005E L7:
005E .dbline 97
005E ; }
005E ; OS_ENTER_CRITICAL();
005E 0E940000 xcall _OS_CPU_SR_Save
0062 A02E mov R10,R16
0064 .dbline 98
0064 ; pevent = OSEventFreeList; /* Get next free event control block */
0064 40910000 lds R20,_OSEventFreeList
0068 50910100 lds R21,_OSEventFreeList+1
006C .dbline 99
006C ; if (OSEventFreeList != (OS_EVENT *)0) { /* See if pool of free ECB pool was empty */
006C 4030 cpi R20,0
006E 4507 cpc R20,R21
0070 51F0 breq L9
0072 X1:
0072 .dbline 99
0072 .dbline 100
0072 ; OSEventFreeList = (OS_EVENT *)OSEventFreeList->OSEventPtr;
0072 E0910000 lds R30,_OSEventFreeList
0076 F0910100 lds R31,_OSEventFreeList+1
007A 2180 ldd R2,z+1
007C 3280 ldd R3,z+2
007E 30920100 sts _OSEventFreeList+1,R3
0082 20920000 sts _OSEventFreeList,R2
0086 .dbline 101
0086 ; }
0086 L9:
0086 .dbline 102
0086 ; OS_EXIT_CRITICAL();
0086 0A2D mov R16,R10
0088 0E940000 xcall _OS_CPU_SR_Restore
008C .dbline 103
008C ; if (pevent != (OS_EVENT *)0) { /* Get an event control block */
008C 4030 cpi R20,0
008E 4507 cpc R20,R21
0090 69F0 breq L11
0092 X2:
0092 .dbline 103
0092 .dbline 104
0092 ; pevent->OSEventType = OS_EVENT_TYPE_SEM;
0092 83E0 ldi R24,3
0094 FA01 movw R30,R20
0096 8083 std z+0,R24
0098 .dbline 105
0098 ; pevent->OSEventCnt = cnt; /* Set semaphore value */
0098 7483 std z+4,R23
009A 6383 std z+3,R22
009C .dbline 106
009C ; pevent->OSEventPtr = (void *)0; /* Unlink from ECB free list */
009C 2224 clr R2
009E 3324 clr R3
00A0 FA01 movw R30,R20
00A2 3282 std z+2,R3
00A4 2182 std z+1,R2
00A6 .dbline 111
00A6 ; #if OS_EVENT_NAME_SIZE > 1
00A6 ; pevent->OSEventName[0] = '?'; /* Unknown name */
00A6 ; pevent->OSEventName[1] = OS_ASCII_NUL;
00A6 ; #endif
00A6 ; OS_EventWaitListInit(pevent); /* Initialize to 'nobody waiting' on sem. */
00A6 8A01 movw R16,R20
00A8 0E940000 xcall _OS_EventWaitListInit
00AC .dbline 112
00AC ; }
00AC L11:
00AC .dbline 113
00AC ; return (pevent);
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?