📄 os_sem.lis
字号:
008C 2197 sbiw R28,1
008E 6B85 ldd R22,y+11
0090 7C85 ldd R23,y+12
0092 .dbline -1
0092 .dbline 148
0092 ; }
0092 ;
0092 ; /*$PAGE*/
0092 ; /*
0092 ; *********************************************************************************************************
0092 ; * DELETE A SEMAPHORE
0092 ; *
0092 ; * Description: This function deletes a semaphore and readies all tasks pending on the semaphore.
0092 ; *
0092 ; * Arguments : pevent is a pointer to the event control block associated with the desired
0092 ; * semaphore.
0092 ; *
0092 ; * opt determines delete options as follows:
0092 ; * opt == OS_DEL_NO_PEND Delete semaphore ONLY if no task pending
0092 ; * opt == OS_DEL_ALWAYS Deletes the semaphore even if tasks are waiting.
0092 ; * In this case, all the tasks pending will be readied.
0092 ; *
0092 ; * err is a pointer to an error code that can contain one of the following values:
0092 ; * OS_NO_ERR The call was successful and the semaphore was deleted
0092 ; * OS_ERR_DEL_ISR If you attempted to delete the semaphore from an ISR
0092 ; * OS_ERR_INVALID_OPT An invalid option was specified
0092 ; * OS_ERR_TASK_WAITING One or more tasks were waiting on the semaphore
0092 ; * OS_ERR_EVENT_TYPE If you didn't pass a pointer to a semaphore
0092 ; * OS_ERR_PEVENT_NULL If 'pevent' is a NULL pointer.
0092 ; *
0092 ; * Returns : pevent upon error
0092 ; * (OS_EVENT *)0 if the semaphore was successfully deleted.
0092 ; *
0092 ; * Note(s) : 1) This function must be used with care. Tasks that would normally expect the presence of
0092 ; * the semaphore MUST check the return code of OSSemPend().
0092 ; * 2) OSSemAccept() callers will not know that the intended semaphore has been deleted unless
0092 ; * they check 'pevent' to see that it's a NULL pointer.
0092 ; * 3) This call can potentially disable interrupts for a long time. The interrupt disable
0092 ; * time is directly proportional to the number of tasks waiting on the semaphore.
0092 ; * 4) Because ALL tasks pending on the semaphore will be readied, you MUST be careful in
0092 ; * applications where the semaphore is used for mutual exclusion because the resource(s)
0092 ; * will no longer be guarded by the semaphore.
0092 ; *********************************************************************************************************
0092 ; */
0092 ;
0092 ; #if OS_SEM_DEL_EN > 0
0092 ; OS_EVENT *OSSemDel (OS_EVENT *pevent, INT8U opt, INT8U *err)
0092 ; {
0092 .dbline 155
0092 ; #if OS_CRITICAL_METHOD == 3 /* Allocate storage for CPU status register */
0092 ; OS_CPU_SR cpu_sr;
0092 ; #endif
0092 ; BOOLEAN tasks_waiting;
0092 ;
0092 ;
0092 ; if (OSIntNesting > 0) { /* See if called from ISR ... */
0092 2224 clr R2
0094 30900000 lds R3,_OSIntNesting
0098 2314 cp R2,R3
009A 28F4 brsh L14
009C .dbline 155
009C .dbline 156
009C ; *err = OS_ERR_DEL_ISR; /* ... can't DELETE from an ISR */
009C 8CE8 ldi R24,140
009E FB01 movw R30,R22
00A0 8083 std z+0,R24
00A2 .dbline 157
00A2 ; return (pevent);
00A2 8A01 movw R16,R20
00A4 5DC0 rjmp L13
00A6 L14:
00A6 .dbline 169
00A6 ; }
00A6 ; #if OS_ARG_CHK_EN > 0
00A6 ; if (pevent == (OS_EVENT *)0) { /* Validate 'pevent' */
00A6 ; *err = OS_ERR_PEVENT_NULL;
00A6 ; return (pevent);
00A6 ; }
00A6 ; if (pevent->OSEventType != OS_EVENT_TYPE_SEM) { /* Validate event block type */
00A6 ; *err = OS_ERR_EVENT_TYPE;
00A6 ; return (pevent);
00A6 ; }
00A6 ; #endif
00A6 ; OS_ENTER_CRITICAL();
00A6 00D0 rcall _OS_CPU_SR_Save
00A8 A02E mov R10,R16
00AA .dbline 170
00AA ; if (pevent->OSEventGrp != 0x00) { /* See if any tasks waiting on semaphore */
00AA FA01 movw R30,R20
00AC 2180 ldd R2,z+1
00AE 2220 tst R2
00B0 19F0 breq L16
00B2 .dbline 170
00B2 .dbline 171
00B2 ; tasks_waiting = TRUE; /* Yes */
00B2 CC24 clr R12
00B4 C394 inc R12
00B6 .dbline 172
00B6 01C0 rjmp L17
00B8 L16:
00B8 .dbline 172
00B8 ; } else {
00B8 .dbline 173
00B8 ; tasks_waiting = FALSE; /* No */
00B8 CC24 clr R12
00BA .dbline 174
00BA ; }
00BA L17:
00BA .dbline 175
00BA FF24 clr R15
00BC EE20 tst R14
00BE 11F4 brne X3
00C0 FF20 tst R15
00C2 39F0 breq L21
00C4 X3:
00C4 C701 movw R24,R14
00C6 8130 cpi R24,1
00C8 E0E0 ldi R30,0
00CA 9E07 cpc R25,R30
00CC 09F4 brne X5
00CE 25C0 rjmp L26
00D0 X5:
00D0 41C0 rjmp L18
00D2 X4:
00D2 .dbline 175
00D2 ; switch (opt) {
00D2 L21:
00D2 .dbline 177
00D2 ; case OS_DEL_NO_PEND: /* Delete semaphore only if no task waiting */
00D2 ; if (tasks_waiting == FALSE) {
00D2 CC20 tst R12
00D4 A9F4 brne L22
00D6 .dbline 177
00D6 .dbline 178
00D6 ; pevent->OSEventType = OS_EVENT_TYPE_UNUSED;
00D6 2224 clr R2
00D8 FA01 movw R30,R20
00DA 2082 std z+0,R2
00DC .dbline 179
00DC ; pevent->OSEventPtr = OSEventFreeList; /* Return Event Control Block to free list */
00DC 20900000 lds R2,_OSEventFreeList
00E0 30900100 lds R3,_OSEventFreeList+1
00E4 3582 std z+5,R3
00E6 2482 std z+4,R2
00E8 .dbline 180
00E8 ; OSEventFreeList = pevent; /* Get next free event control block */
00E8 50930100 sts _OSEventFreeList+1,R21
00EC 40930000 sts _OSEventFreeList,R20
00F0 .dbline 181
00F0 ; OS_EXIT_CRITICAL();
00F0 0A2D mov R16,R10
00F2 00D0 rcall _OS_CPU_SR_Restore
00F4 .dbline 182
00F4 ; *err = OS_NO_ERR;
00F4 2224 clr R2
00F6 FB01 movw R30,R22
00F8 2082 std z+0,R2
00FA .dbline 183
00FA ; return ((OS_EVENT *)0); /* Semaphore has been deleted */
00FA 0027 clr R16
00FC 1127 clr R17
00FE 30C0 rjmp L13
0100 L22:
0100 .dbline 184
0100 ; } else {
0100 .dbline 185
0100 ; OS_EXIT_CRITICAL();
0100 0A2D mov R16,R10
0102 00D0 rcall _OS_CPU_SR_Restore
0104 .dbline 186
0104 ; *err = OS_ERR_TASK_WAITING;
0104 88E0 ldi R24,8
0106 FB01 movw R30,R22
0108 8083 std z+0,R24
010A .dbline 187
010A ; return (pevent);
010A 8A01 movw R16,R20
010C 29C0 rjmp L13
010E L25:
010E .dbline 191
010E .dbline 192
010E 81E0 ldi R24,1
0110 8883 std y+0,R24
0112 2227 clr R18
0114 3327 clr R19
0116 8A01 movw R16,R20
0118 00D0 rcall _OS_EventTaskRdy
011A .dbline 193
011A L26:
011A .dbline 191
011A ; }
011A ;
011A ; case OS_DEL_ALWAYS: /* Always delete the semaphore */
011A ; while (pevent->OSEventGrp != 0x00) { /* Ready ALL tasks waiting for semaphore */
011A FA01 movw R30,R20
011C 2180 ldd R2,z+1
011E 2220 tst R2
0120 B1F7 brne L25
0122 .dbline 194
0122 ; OS_EventTaskRdy(pevent, (void *)0, OS_STAT_SEM);
0122 ; }
0122 ; pevent->OSEventType = OS_EVENT_TYPE_UNUSED;
0122 2224 clr R2
0124 FA01 movw R30,R20
0126 2082 std z+0,R2
0128 .dbline 195
0128 ; pevent->OSEventPtr = OSEventFreeList; /* Return Event Control Block to free list */
0128 20900000 lds R2,_OSEventFreeList
012C 30900100 lds R3,_OSEventFreeList+1
0130 3582 std z+5,R3
0132 2482 std z+4,R2
0134 .dbline 196
0134 ; OSEventFreeList = pevent; /* Get next free event control block */
0134 50930100 sts _OSEventFreeList+1,R21
0138 40930000 sts _OSEventFreeList,R20
013C .dbline 197
013C ; OS_EXIT_CRITICAL();
013C 0A2D mov R16,R10
013E 00D0 rcall _OS_CPU_SR_Restore
0140 .dbline 198
0140 ; if (tasks_waiting == TRUE) { /* Reschedule only if task(s) were waiting */
0140 8C2D mov R24,R12
0142 8130 cpi R24,1
0144 09F4 brne L28
0146 .dbline 198
0146 .dbline 199
0146 ; OS_Sched(); /* Find highest priority task ready to run */
0146 00D0 rcall _OS_Sched
0148 .dbline 200
0148 ; }
0148 L28:
0148 .dbline 201
0148 ; *err = OS_NO_ERR;
0148 2224 clr R2
014A FB01 movw R30,R22
014C 2082 std z+0,R2
014E .dbline 202
014E ; return ((OS_EVENT *)0); /* Semaphore has been deleted */
014E 0027 clr R16
0150 1127 clr R17
0152 06C0 rjmp L13
0154 L18:
0154 .dbline 205
0154 ;
0154 ; default:
0154 ; OS_EXIT_CRITICAL();
0154 0A2D mov R16,R10
0156 00D0 rcall _OS_CPU_SR_Restore
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -