📄 os_sem.s79
字号:
CFI EndBlock cfiBlock2
REQUIRE OSSemCreate
// 63 #endif
// 64
// 65 /*$PAGE*/
// 66 /*
// 67 *********************************************************************************************************
// 68 * CREATE A SEMAPHORE
// 69 *
// 70 * Description: This function creates a semaphore.
// 71 *
// 72 * Arguments : cnt is the initial value for the semaphore. If the value is 0, no resource is
// 73 * available (or no event has occurred). You initialize the semaphore to a
// 74 * non-zero value to specify how many resources are available (e.g. if you have
// 75 * 10 resources, you would initialize the semaphore to 10).
// 76 *
// 77 * Returns : != (void *)0 is a pointer to the event control clock (OS_EVENT) associated with the
// 78 * created semaphore
// 79 * == (void *)0 if no event control blocks were available
// 80 *********************************************************************************************************
// 81 */
// 82
RSEG CODE:CODE:NOROOT(2)
CFI Block cfiBlock3 Using cfiCommon1
CFI Function OSSemCreate
THUMB
// 83 OS_EVENT *OSSemCreate (INT16U cnt)
// 84 {
OSSemCreate:
PUSH {R4,R5,LR}
CFI ?RET Frame(CFA, -4)
CFI R5 Frame(CFA, -8)
CFI R4 Frame(CFA, -12)
CFI CFA R13+12
MOVS R4,R0
// 85 #if OS_CRITICAL_METHOD == 3 /* Allocate storage for CPU status register */
// 86 OS_CPU_SR cpu_sr;
// 87 #endif
// 88 OS_EVENT *pevent;
// 89
// 90
// 91 if (OSIntNesting > 0) { /* See if called from ISR ... */
LDR R0,??DataTable7 ;; OSIntNesting
LDRB R0,[R0, #+0]
CMP R0,#+0
BEQ ??OSSemCreate_0
// 92 return ((OS_EVENT *)0); /* ... can't CREATE from an ISR */
MOVS R0,#+0
B ??OSSemCreate_1
// 93 }
// 94 OS_ENTER_CRITICAL();
??OSSemCreate_0:
_BLF OS_CPU_SR_Save,??OS_CPU_SR_Save??rT
// 95 pevent = OSEventFreeList; /* Get next free event control block */
LDR R1,??DataTable6 ;; OSEventFreeList
LDR R5,[R1, #+0]
// 96 if (OSEventFreeList != (OS_EVENT *)0) { /* See if pool of free ECB pool was empty */
CMP R5,#+0
BEQ ??OSSemCreate_2
// 97 OSEventFreeList = (OS_EVENT *)OSEventFreeList->OSEventPtr;
LDR R2,[R5, #+4]
STR R2,[R1, #+0]
// 98 }
// 99 OS_EXIT_CRITICAL();
??OSSemCreate_2:
_BLF OS_CPU_SR_Restore,??OS_CPU_SR_Restore??rT
// 100 if (pevent != (OS_EVENT *)0) { /* Get an event control block */
CMP R5,#+0
BEQ ??OSSemCreate_3
// 101 pevent->OSEventType = OS_EVENT_TYPE_SEM;
MOVS R0,#+3
STRB R0,[R5, #+0]
// 102 pevent->OSEventCnt = cnt; /* Set semaphore value */
STRH R4,[R5, #+2]
// 103 pevent->OSEventPtr = (void *)0; /* Unlink from ECB free list */
MOVS R0,#+0
STR R0,[R5, #+4]
// 104 #if OS_EVENT_NAME_SIZE > 1
// 105 pevent->OSEventName[0] = '?'; /* Unknown name */
MOVS R0,#+63
STRB R0,[R5, #+16]
// 106 pevent->OSEventName[1] = OS_ASCII_NUL;
MOVS R0,#+0
STRB R0,[R5, #+17]
// 107 #endif
// 108 OS_EventWaitListInit(pevent); /* Initialize to 'nobody waiting' on sem. */
MOVS R0,R5
_BLF OS_EventWaitListInit,??OS_EventWaitListInit??rT
// 109 }
// 110 return (pevent);
??OSSemCreate_3:
MOVS R0,R5
??OSSemCreate_1:
POP {R4,R5}
POP {R1}
BX R1 ;; return
CFI EndBlock cfiBlock3
// 111 }
RSEG CODE:CODE:NOROOT(2)
CFI Block cfiBlock4 Using cfiCommon0
CFI NoFunction
ARM
??OSSemDel??rA:
ADD R12,PC,#+1
BX R12
CFI EndBlock cfiBlock4
REQUIRE OSSemDel
// 112
// 113 /*$PAGE*/
// 114 /*
// 115 *********************************************************************************************************
// 116 * DELETE A SEMAPHORE
// 117 *
// 118 * Description: This function deletes a semaphore and readies all tasks pending on the semaphore.
// 119 *
// 120 * Arguments : pevent is a pointer to the event control block associated with the desired
// 121 * semaphore.
// 122 *
// 123 * opt determines delete options as follows:
// 124 * opt == OS_DEL_NO_PEND Delete semaphore ONLY if no task pending
// 125 * opt == OS_DEL_ALWAYS Deletes the semaphore even if tasks are waiting.
// 126 * In this case, all the tasks pending will be readied.
// 127 *
// 128 * err is a pointer to an error code that can contain one of the following values:
// 129 * OS_NO_ERR The call was successful and the semaphore was deleted
// 130 * OS_ERR_DEL_ISR If you attempted to delete the semaphore from an ISR
// 131 * OS_ERR_INVALID_OPT An invalid option was specified
// 132 * OS_ERR_TASK_WAITING One or more tasks were waiting on the semaphore
// 133 * OS_ERR_EVENT_TYPE If you didn't pass a pointer to a semaphore
// 134 * OS_ERR_PEVENT_NULL If 'pevent' is a NULL pointer.
// 135 *
// 136 * Returns : pevent upon error
// 137 * (OS_EVENT *)0 if the semaphore was successfully deleted.
// 138 *
// 139 * Note(s) : 1) This function must be used with care. Tasks that would normally expect the presence of
// 140 * the semaphore MUST check the return code of OSSemPend().
// 141 * 2) OSSemAccept() callers will not know that the intended semaphore has been deleted unless
// 142 * they check 'pevent' to see that it's a NULL pointer.
// 143 * 3) This call can potentially disable interrupts for a long time. The interrupt disable
// 144 * time is directly proportional to the number of tasks waiting on the semaphore.
// 145 * 4) Because ALL tasks pending on the semaphore will be readied, you MUST be careful in
// 146 * applications where the semaphore is used for mutual exclusion because the resource(s)
// 147 * will no longer be guarded by the semaphore.
// 148 *********************************************************************************************************
// 149 */
// 150
// 151 #if OS_SEM_DEL_EN > 0
RSEG CODE:CODE:NOROOT(2)
CFI Block cfiBlock5 Using cfiCommon1
CFI Function OSSemDel
THUMB
// 152 OS_EVENT *OSSemDel (OS_EVENT *pevent, INT8U opt, INT8U *err)
// 153 {
OSSemDel:
PUSH {R1,R4-R7,LR}
CFI ?RET Frame(CFA, -4)
CFI R7 Frame(CFA, -8)
CFI R6 Frame(CFA, -12)
CFI R5 Frame(CFA, -16)
CFI R4 Frame(CFA, -20)
CFI CFA R13+24
MOVS R4,R0
MOVS R5,R2
// 154 #if OS_CRITICAL_METHOD == 3 /* Allocate storage for CPU status register */
// 155 OS_CPU_SR cpu_sr;
// 156 #endif
// 157 BOOLEAN tasks_waiting;
// 158
// 159
// 160 if (OSIntNesting > 0) { /* See if called from ISR ... */
LDR R0,??DataTable7 ;; OSIntNesting
LDRB R0,[R0, #+0]
CMP R0,#+0
BEQ ??OSSemDel_0
// 161 *err = OS_ERR_DEL_ISR; /* ... can't DELETE from an ISR */
MOVS R0,#+140
B.N ??OSSemDel_1
// 162 return (pevent);
// 163 }
// 164 #if OS_ARG_CHK_EN > 0
// 165 if (pevent == (OS_EVENT *)0) { /* Validate 'pevent' */
??OSSemDel_0:
CMP R4,#+0
BNE ??OSSemDel_2
// 166 *err = OS_ERR_PEVENT_NULL;
MOVS R0,#+4
STRB R0,[R5, #+0]
// 167 return (pevent);
MOVS R0,#+0
B ??OSSemDel_3
// 168 }
// 169 #endif
// 170 if (pevent->OSEventType != OS_EVENT_TYPE_SEM) { /* Validate event block type */
??OSSemDel_2:
LDRB R0,[R4, #+0]
CMP R0,#+3
BEQ ??OSSemDel_4
// 171 *err = OS_ERR_EVENT_TYPE;
MOVS R0,#+1
B.N ??OSSemDel_1
// 172 return (pevent);
// 173 }
// 174 OS_ENTER_CRITICAL();
??OSSemDel_4:
_BLF OS_CPU_SR_Save,??OS_CPU_SR_Save??rT
MOVS R6,R0
// 175 if (pevent->OSEventGrp != 0x00) { /* See if any tasks waiting on semaphore */
LDRB R0,[R4, #+1]
CMP R0,#+0
BEQ ??OSSemDel_5
// 176 tasks_waiting = TRUE; /* Yes */
MOVS R7,#+1
B ??OSSemDel_6
// 177 } else {
// 178 tasks_waiting = FALSE; /* No */
??OSSemDel_5:
MOVS R7,#+0
// 179 }
// 180 switch (opt) {
??OSSemDel_6:
MOV R0,SP
LDRB R0,[R0, #+0]
CMP R0,#+0
BEQ ??OSSemDel_7
CMP R0,#+1
BEQ ??OSSemDel_8
B ??OSSemDel_9
// 181 case OS_DEL_NO_PEND: /* Delete semaphore only if no task waiting */
// 182 if (tasks_waiting == FALSE) {
??OSSemDel_7:
CMP R7,#+0
BNE ??OSSemDel_10
// 183 #if OS_EVENT_NAME_SIZE > 1
// 184 pevent->OSEventName[0] = '?'; /* Unknown name */
MOVS R0,#+63
STRB R0,[R4, #+16]
// 185 pevent->OSEventName[1] = OS_ASCII_NUL;
MOVS R0,#+0
STRB R0,[R4, #+17]
// 186 #endif
// 187 pevent->OSEventType = OS_EVENT_TYPE_UNUSED;
STRB R0,[R4, #+0]
// 188 pevent->OSEventPtr = OSEventFreeList; /* Return Event Control Block to free list */
LDR R0,??DataTable6 ;; OSEventFreeList
LDR R0,[R0, #+0]
STR R0,[R4, #+4]
// 189 pevent->OSEventCnt = 0;
MOVS R0,#+0
STRH R0,[R4, #+2]
// 190 OSEventFreeList = pevent; /* Get next free event control block */
LDR R0,??DataTable6 ;; OSEventFreeList
STR R4,[R0, #+0]
// 191 OS_EXIT_CRITICAL();
MOVS R0,R6
_BLF OS_CPU_SR_Restore,??OS_CPU_SR_Restore??rT
// 192 *err = OS_NO_ERR;
??OSSemDel_11:
MOVS R0,#+0
STRB R0,[R5, #+0]
// 193 return ((OS_EVENT *)0); /* Semaphore has been deleted */
B ??OSSemDel_3
// 194 } else {
// 195 OS_EXIT_CRITICAL();
??OSSemDel_10:
MOVS R0,R6
_BLF OS_CPU_SR_Restore,??OS_CPU_SR_Restore??rT
// 196 *err = OS_ERR_TASK_WAITING;
MOVS R0,#+8
B.N ??OSSemDel_1
// 197 return (pevent);
// 198 }
// 199
// 200 case OS_DEL_ALWAYS: /* Always delete the semaphore */
// 201 while (pevent->OSEventGrp != 0x00) { /* Ready ALL tasks waiting for semaphore */
// 202 OS_EventTaskRdy(pevent, (void *)0, OS_STAT_SEM);
??OSSemDel_12:
MOVS R2,#+1
MOVS R1,#+0
MOVS R0,R4
_BLF OS_EventTaskRdy,??OS_EventTaskRdy??rT
// 203 }
??OSSemDel_8:
LDRB R0,[R4, #+1]
CMP R0,#+0
BNE ??OSSemDel_12
// 204 #if OS_EVENT_NAME_SIZE > 1
// 205 pevent->OSEventName[0] = '?'; /* Unknown name */
MOVS R0,#+63
STRB R0,[R4, #+16]
// 206 pevent->OSEventName[1] = OS_ASCII_NUL;
MOVS R0,#+0
STRB R0,[R4, #+17]
// 207 #endif
// 208 pevent->OSEventType = OS_EVENT_TYPE_UNUSED;
STRB R0,[R4, #+0]
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -