📄 os_sem.lis
字号:
.module OS_SEM.c
.area text(rom, con, rel)
0000 .dbfile F:\AVRPRA~1\ucosii-port2-mega8\OS_SEM.c
0000 .dbfunc e OSSemAccept _OSSemAccept fi
0000 .dbstruct 0 9 .1
0000 .dbfield 0 OSEventType c
0000 .dbfield 1 OSEventGrp c
0000 .dbfield 2 OSEventCnt i
0000 .dbfield 4 OSEventPtr pV
0000 .dbfield 6 OSEventTbl A[3:3]c
0000 .dbend
0000 ; cpu_sr -> R22
0000 ; cnt -> R20,R21
0000 ; pevent -> R10,R11
.even
0000 _OSSemAccept::
0000 00D0 rcall push_gset3
0002 5801 movw R10,R16
0004 .dbline -1
0004 .dbline 40
0004 ; /*
0004 ; *********************************************************************************************************
0004 ; * uC/OS-II
0004 ; * The Real-Time Kernel
0004 ; * SEMAPHORE MANAGEMENT
0004 ; *
0004 ; * (c) Copyright 1992-2001, Jean J. Labrosse, Weston, FL
0004 ; * All Rights Reserved
0004 ; *
0004 ; * File : OS_SEM.C
0004 ; * By : Jean J. Labrosse
0004 ; *********************************************************************************************************
0004 ; */
0004 ;
0004 ; #ifndef OS_MASTER_FILE
0004 ; #include "includes.h"
0004 ; #endif
0004 ;
0004 ; #if OS_SEM_EN > 0
0004 ; /*
0004 ; *********************************************************************************************************
0004 ; * ACCEPT SEMAPHORE
0004 ; *
0004 ; * Description: This function checks the semaphore to see if a resource is available or, if an event
0004 ; * occurred. Unlike OSSemPend(), OSSemAccept() does not suspend the calling task if the
0004 ; * resource is not available or the event did not occur.
0004 ; *
0004 ; * Arguments : pevent is a pointer to the event control block
0004 ; *
0004 ; * Returns : > 0 if the resource is available or the event did not occur the semaphore is
0004 ; * decremented to obtain the resource.
0004 ; * == 0 if the resource is not available or the event did not occur or,
0004 ; * if 'pevent' is a NULL pointer or,
0004 ; * if you didn't pass a pointer to a semaphore
0004 ; *********************************************************************************************************
0004 ; */
0004 ;
0004 ; #if OS_SEM_ACCEPT_EN > 0
0004 ; INT16U OSSemAccept (OS_EVENT *pevent)
0004 ; {
0004 .dbline 55
0004 ; #if OS_CRITICAL_METHOD == 3 /* Allocate storage for CPU status register */
0004 ; OS_CPU_SR cpu_sr;
0004 ; #endif
0004 ; INT16U cnt;
0004 ;
0004 ;
0004 ; #if OS_ARG_CHK_EN > 0
0004 ; if (pevent == (OS_EVENT *)0) { /* Validate 'pevent' */
0004 ; return (0);
0004 ; }
0004 ; if (pevent->OSEventType != OS_EVENT_TYPE_SEM) { /* Validate event block type */
0004 ; return (0);
0004 ; }
0004 ; #endif
0004 ; OS_ENTER_CRITICAL();
0004 00D0 rcall _OS_CPU_SR_Save
0006 602F mov R22,R16
0008 .dbline 56
0008 ; cnt = pevent->OSEventCnt;
0008 F501 movw R30,R10
000A 4281 ldd R20,z+2
000C 5381 ldd R21,z+3
000E .dbline 57
000E ; if (cnt > 0) { /* See if resource is available */
000E 4030 cpi R20,0
0010 4507 cpc R20,R21
0012 41F0 breq L4
0014 X0:
0014 .dbline 57
0014 .dbline 58
0014 ; pevent->OSEventCnt--; /* Yes, decrement semaphore and notify caller */
0014 C501 movw R24,R10
0016 0296 adiw R24,2
0018 FC01 movw R30,R24
001A 8081 ldd R24,z+0
001C 9181 ldd R25,z+1
001E 0197 sbiw R24,1
0020 9183 std z+1,R25
0022 8083 std z+0,R24
0024 .dbline 59
0024 ; }
0024 L4:
0024 .dbline 60
0024 ; OS_EXIT_CRITICAL();
0024 062F mov R16,R22
0026 00D0 rcall _OS_CPU_SR_Restore
0028 .dbline 61
0028 ; return (cnt); /* Return semaphore count */
0028 8A01 movw R16,R20
002A .dbline -2
002A L3:
002A 00D0 rcall pop_gset3
002C .dbline 0 ; func end
002C 0895 ret
002E .dbsym r cpu_sr 22 c
002E .dbsym r cnt 20 i
002E .dbsym r pevent 10 pS[.1]
002E .dbend
002E .dbfunc e OSSemCreate _OSSemCreate fpS[.1]
002E ; cpu_sr -> R10
002E ; pevent -> R20,R21
002E ; cnt -> R22,R23
.even
002E _OSSemCreate::
002E 00D0 rcall push_gset3
0030 B801 movw R22,R16
0032 .dbline -1
0032 .dbline 84
0032 ; }
0032 ; #endif
0032 ;
0032 ; /*$PAGE*/
0032 ; /*
0032 ; *********************************************************************************************************
0032 ; * CREATE A SEMAPHORE
0032 ; *
0032 ; * Description: This function creates a semaphore.
0032 ; *
0032 ; * Arguments : cnt is the initial value for the semaphore. If the value is 0, no resource is
0032 ; * available (or no event has occurred). You initialize the semaphore to a
0032 ; * non-zero value to specify how many resources are available (e.g. if you have
0032 ; * 10 resources, you would initialize the semaphore to 10).
0032 ; *
0032 ; * Returns : != (void *)0 is a pointer to the event control clock (OS_EVENT) associated with the
0032 ; * created semaphore
0032 ; * == (void *)0 if no event control blocks were available
0032 ; *********************************************************************************************************
0032 ; */
0032 ;
0032 ; OS_EVENT *OSSemCreate (INT16U cnt)
0032 ; {
0032 .dbline 91
0032 ; #if OS_CRITICAL_METHOD == 3 /* Allocate storage for CPU status register */
0032 ; OS_CPU_SR cpu_sr;
0032 ; #endif
0032 ; OS_EVENT *pevent;
0032 ;
0032 ;
0032 ; if (OSIntNesting > 0) { /* See if called from ISR ... */
0032 2224 clr R2
0034 30900000 lds R3,_OSIntNesting
0038 2314 cp R2,R3
003A 18F4 brsh L7
003C .dbline 91
003C .dbline 92
003C ; return ((OS_EVENT *)0); /* ... can't CREATE from an ISR */
003C 0027 clr R16
003E 1127 clr R17
0040 20C0 rjmp L6
0042 L7:
0042 .dbline 94
0042 ; }
0042 ; OS_ENTER_CRITICAL();
0042 00D0 rcall _OS_CPU_SR_Save
0044 A02E mov R10,R16
0046 .dbline 95
0046 ; pevent = OSEventFreeList; /* Get next free event control block */
0046 40910000 lds R20,_OSEventFreeList
004A 50910100 lds R21,_OSEventFreeList+1
004E .dbline 96
004E ; if (OSEventFreeList != (OS_EVENT *)0) { /* See if pool of free ECB pool was empty */
004E 4030 cpi R20,0
0050 4507 cpc R20,R21
0052 51F0 breq L9
0054 X1:
0054 .dbline 96
0054 .dbline 97
0054 ; OSEventFreeList = (OS_EVENT *)OSEventFreeList->OSEventPtr;
0054 E0910000 lds R30,_OSEventFreeList
0058 F0910100 lds R31,_OSEventFreeList+1
005C 2480 ldd R2,z+4
005E 3580 ldd R3,z+5
0060 30920100 sts _OSEventFreeList+1,R3
0064 20920000 sts _OSEventFreeList,R2
0068 .dbline 98
0068 ; }
0068 L9:
0068 .dbline 99
0068 ; OS_EXIT_CRITICAL();
0068 0A2D mov R16,R10
006A 00D0 rcall _OS_CPU_SR_Restore
006C .dbline 100
006C ; if (pevent != (OS_EVENT *)0) { /* Get an event control block */
006C 4030 cpi R20,0
006E 4507 cpc R20,R21
0070 39F0 breq L11
0072 X2:
0072 .dbline 100
0072 .dbline 101
0072 ; pevent->OSEventType = OS_EVENT_TYPE_SEM;
0072 83E0 ldi R24,3
0074 FA01 movw R30,R20
0076 8083 std z+0,R24
0078 .dbline 102
0078 ; pevent->OSEventCnt = cnt; /* Set semaphore value */
0078 7383 std z+3,R23
007A 6283 std z+2,R22
007C .dbline 103
007C ; OS_EventWaitListInit(pevent);
007C 8A01 movw R16,R20
007E 00D0 rcall _OS_EventWaitListInit
0080 .dbline 104
0080 ; }
0080 L11:
0080 .dbline 105
0080 ; return (pevent);
0080 8A01 movw R16,R20
0082 .dbline -2
0082 L6:
0082 00D0 rcall pop_gset3
0084 .dbline 0 ; func end
0084 0895 ret
0086 .dbsym r cpu_sr 10 c
0086 .dbsym r pevent 20 pS[.1]
0086 .dbsym r cnt 22 i
0086 .dbend
0086 .dbfunc e OSSemDel _OSSemDel fpS[.1]
0086 ; tasks_waiting -> R12
0086 ; cpu_sr -> R10
0086 ; err -> R22,R23
0086 ; opt -> R14
0086 ; pevent -> R20,R21
.even
0086 _OSSemDel::
0086 00D0 rcall push_gset5
0088 E22E mov R14,R18
008A A801 movw R20,R16
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -