📄 os_mutex.lst
字号:
\ 00000068 0000C4E5 STRB R0,[R4, #+0]
108 return (0);
\ 0000006C 0000A0E3 MOV R0,#+0
\ 00000070 250000EA B ??OSMutexAccept_1
109 }
110 OS_ENTER_CRITICAL(); /* Get value (0 or 1) of Mutex */
\ ??OSMutexAccept_4:
\ 00000074 ........ _BLF OS_CPU_SR_Save,??OS_CPU_SR_Save??rA
111 pip = (INT8U)(pevent->OSEventCnt >> 8); /* Get PIP from mutex */
\ 00000078 B810D5E1 LDRH R1,[R5, #+8]
\ 0000007C 2114B0E1 LSRS R1,R1,#+8
112 if ((pevent->OSEventCnt & OS_MUTEX_KEEP_LOWER_8) == OS_MUTEX_AVAILABLE) {
\ 00000080 B820D5E1 LDRH R2,[R5, #+8]
\ 00000084 FF2012E2 ANDS R2,R2,#0xFF
\ 00000088 FF0052E3 CMP R2,#+255
\ 0000008C 1A00001A BNE ??OSMutexAccept_5
113 pevent->OSEventCnt &= OS_MUTEX_KEEP_UPPER_8; /* Mask off LSByte (Acquire Mutex) */
\ 00000090 B820D5E1 LDRH R2,[R5, #+8]
\ 00000094 FF2C12E2 ANDS R2,R2,#0xFF00
\ 00000098 B820C5E1 STRH R2,[R5, #+8]
114 pevent->OSEventCnt |= OSTCBCur->OSTCBPrio; /* Save current task priority in LSByte */
\ 0000009C B820D5E1 LDRH R2,[R5, #+8]
\ 000000A0 ........ LDR R3,??DataTable44 ;; OSTCBCur
\ 000000A4 003093E5 LDR R3,[R3, #+0]
\ 000000A8 2E30D3E5 LDRB R3,[R3, #+46]
\ 000000AC 022093E1 ORRS R2,R3,R2
\ 000000B0 B820C5E1 STRH R2,[R5, #+8]
115 pevent->OSEventPtr = (void *)OSTCBCur; /* Link TCB of task owning Mutex */
\ 000000B4 ........ LDR R2,??DataTable44 ;; OSTCBCur
\ 000000B8 002092E5 LDR R2,[R2, #+0]
\ 000000BC 042085E5 STR R2,[R5, #+4]
116 if (OSTCBCur->OSTCBPrio <= pip) { /* PIP 'must' have a SMALLER prio ... */
\ 000000C0 ........ LDR R2,??DataTable44 ;; OSTCBCur
\ 000000C4 002092E5 LDR R2,[R2, #+0]
\ 000000C8 2E20D2E5 LDRB R2,[R2, #+46]
\ 000000CC FF1011E2 ANDS R1,R1,#0xFF ;; Zero extend
\ 000000D0 020051E1 CMP R1,R2
\ 000000D4 0300003A BCC ??OSMutexAccept_6
117 OS_EXIT_CRITICAL(); /* ... than current task! */
\ 000000D8 ........ _BLF OS_CPU_SR_Restore,??OS_CPU_SR_Restore??rA
118 *err = OS_ERR_PIP_LOWER;
\ 000000DC 7800A0E3 MOV R0,#+120
\ 000000E0 0000C4E5 STRB R0,[R4, #+0]
\ 000000E4 020000EA B ??OSMutexAccept_7
119 } else {
120 OS_EXIT_CRITICAL();
\ ??OSMutexAccept_6:
\ 000000E8 ........ _BLF OS_CPU_SR_Restore,??OS_CPU_SR_Restore??rA
121 *err = OS_ERR_NONE;
\ 000000EC 0000A0E3 MOV R0,#+0
\ 000000F0 0000C4E5 STRB R0,[R4, #+0]
122 }
123 return (1);
\ ??OSMutexAccept_7:
\ 000000F4 0100A0E3 MOV R0,#+1
\ 000000F8 030000EA B ??OSMutexAccept_1
124 }
125 OS_EXIT_CRITICAL();
\ ??OSMutexAccept_5:
\ 000000FC ........ _BLF OS_CPU_SR_Restore,??OS_CPU_SR_Restore??rA
126 *err = OS_ERR_NONE;
\ 00000100 0000A0E3 MOV R0,#+0
\ 00000104 0000C4E5 STRB R0,[R4, #+0]
127 return (0);
\ 00000108 0000A0E3 MOV R0,#+0
\ ??OSMutexAccept_1:
\ 0000010C 3080BDE8 POP {R4,R5,PC} ;; return
128 }
129 #endif
130
131 /*$PAGE*/
132 /*
133 *********************************************************************************************************
134 * CREATE A MUTUAL EXCLUSION SEMAPHORE
135 *
136 * Description: This function creates a mutual exclusion semaphore.
137 *
138 * Arguments : prio is the priority to use when accessing the mutual exclusion semaphore. In
139 * other words, when the semaphore is acquired and a higher priority task
140 * attempts to obtain the semaphore then the priority of the task owning the
141 * semaphore is raised to this priority. It is assumed that you will specify
142 * a priority that is LOWER in value than ANY of the tasks competing for the
143 * mutex.
144 *
145 * err is a pointer to an error code which will be returned to your application:
146 * OS_ERR_NONE if the call was successful.
147 * OS_ERR_CREATE_ISR if you attempted to create a MUTEX from an ISR
148 * OS_ERR_PRIO_EXIST if a task at the priority inheritance priority
149 * already exist.
150 * OS_ERR_PEVENT_NULL No more event control blocks available.
151 * OS_ERR_PRIO_INVALID if the priority you specify is higher that the
152 * maximum allowed (i.e. > OS_LOWEST_PRIO)
153 *
154 * Returns : != (void *)0 is a pointer to the event control clock (OS_EVENT) associated with the
155 * created mutex.
156 * == (void *)0 if an error is detected.
157 *
158 * Note(s) : 1) The LEAST significant 8 bits of '.OSEventCnt' are used to hold the priority number
159 * of the task owning the mutex or 0xFF if no task owns the mutex.
160 *
161 * 2) The MOST significant 8 bits of '.OSEventCnt' are used to hold the priority number
162 * to use to reduce priority inversion.
163 *********************************************************************************************************
164 */
165
\ In segment CODE, align 4, keep-with-next
166 OS_EVENT *OSMutexCreate (INT8U prio, INT8U *err)
167 {
\ OSMutexCreate:
\ 00000000 70402DE9 PUSH {R4-R6,LR}
\ 00000004 0050B0E1 MOVS R5,R0
\ 00000008 0140B0E1 MOVS R4,R1
168 OS_EVENT *pevent;
169 #if OS_CRITICAL_METHOD == 3 /* Allocate storage for CPU status register */
170 OS_CPU_SR cpu_sr = 0;
\ 0000000C 0000A0E3 MOV R0,#+0
171 #endif
172
173
174
175 #if OS_ARG_CHK_EN > 0
176 if (err == (INT8U *)0) { /* Validate 'err' */
\ 00000010 000054E3 CMP R4,#+0
\ 00000014 0100001A BNE ??OSMutexCreate_0
177 return ((OS_EVENT *)0);
\ 00000018 0000A0E3 MOV R0,#+0
\ 0000001C 440000EA B ??OSMutexCreate_1
178 }
179 if (prio >= OS_LOWEST_PRIO) { /* Validate PIP */
\ ??OSMutexCreate_0:
\ 00000020 1F0055E3 CMP R5,#+31
\ 00000024 0300003A BCC ??OSMutexCreate_2
180 *err = OS_ERR_PRIO_INVALID;
\ 00000028 2A00A0E3 MOV R0,#+42
\ 0000002C 0000C4E5 STRB R0,[R4, #+0]
181 return ((OS_EVENT *)0);
\ 00000030 0000A0E3 MOV R0,#+0
\ 00000034 3E0000EA B ??OSMutexCreate_1
182 }
183 #endif
184 if (OSIntNesting > 0) { /* See if called from ISR ... */
\ ??OSMutexCreate_2:
\ 00000038 ........ LDR R0,??DataTable47 ;; OSIntNesting
\ 0000003C 0000D0E5 LDRB R0,[R0, #+0]
\ 00000040 010050E3 CMP R0,#+1
\ 00000044 0300003A BCC ??OSMutexCreate_3
185 *err = OS_ERR_CREATE_ISR; /* ... can't CREATE mutex from an ISR */
\ 00000048 1000A0E3 MOV R0,#+16
\ 0000004C 0000C4E5 STRB R0,[R4, #+0]
186 return ((OS_EVENT *)0);
\ 00000050 0000A0E3 MOV R0,#+0
\ 00000054 360000EA B ??OSMutexCreate_1
187 }
188 OS_ENTER_CRITICAL();
\ ??OSMutexCreate_3:
\ 00000058 ........ _BLF OS_CPU_SR_Save,??OS_CPU_SR_Save??rA
189 if (OSTCBPrioTbl[prio] != (OS_TCB *)0) { /* Mutex priority must not already exist */
\ 0000005C 0510B0E1 MOVS R1,R5
\ 00000060 0420A0E3 MOV R2,#+4
\ 00000064 ........ LDR R3,??DataTable57 ;; OSTCBPrioTbl
\ 00000068 923121E0 MLA R1,R2,R1,R3
\ 0000006C 001091E5 LDR R1,[R1, #+0]
\ 00000070 000051E3 CMP R1,#+0
\ 00000074 0400000A BEQ ??OSMutexCreate_4
190 OS_EXIT_CRITICAL(); /* Task already exist at priority ... */
\ 00000078 ........ _BLF OS_CPU_SR_Restore,??OS_CPU_SR_Restore??rA
191 *err = OS_ERR_PRIO_EXIST; /* ... inheritance priority */
\ 0000007C 2800A0E3 MOV R0,#+40
\ 00000080 0000C4E5 STRB R0,[R4, #+0]
192 return ((OS_EVENT *)0);
\ 00000084 0000A0E3 MOV R0,#+0
\ 00000088 290000EA B ??OSMutexCreate_1
193 }
194 OSTCBPrioTbl[prio] = (OS_TCB *)1; /* Reserve the table entry */
\ ??OSMutexCreate_4:
\ 0000008C 0510B0E1 MOVS R1,R5
\ 00000090 0420A0E3 MOV R2,#+4
\ 00000094 ........ LDR R3,??DataTable57 ;; OSTCBPrioTbl
\ 00000098 923121E0 MLA R1,R2,R1,R3
\ 0000009C 0120A0E3 MOV R2,#+1
\ 000000A0 002081E5 STR R2,[R1, #+0]
195 pevent = OSEventFreeList; /* Get next free event control block */
\ 000000A4 ........ LDR R1,??DataTable17 ;; OSEventFreeList
\ 000000A8 006091E5 LDR R6,[R1, #+0]
196 if (pevent == (OS_EVENT *)0) { /* See if an ECB was available */
\ 000000AC 000056E3 CMP R6,#+0
\ 000000B0 0900001A BNE ??OSMutexCreate_5
197 OSTCBPrioTbl[prio] = (OS_TCB *)0; /* No, Release the table entry */
\ 000000B4 0410A0E3 MOV R1,#+4
\ 000000B8 ........ LDR R2,??DataTable57 ;; OSTCBPrioTbl
\ 000000BC 912522E0 MLA R2,R1,R5,R2
\ 000000C0 0010A0E3 MOV R1,#+0
\ 000000C4 001082E5 STR R1,[R2, #+0]
198 OS_EXIT_CRITICAL();
\ 000000C8 ........ _BLF OS_CPU_SR_Restore,??OS_CPU_SR_Restore??rA
199 *err = OS_ERR_PEVENT_NULL; /* No more event control blocks */
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -