📄 os_mbox.lst
字号:
114 * opt == OS_DEL_NO_PEND Delete the mailbox ONLY if no task pending
115 * opt == OS_DEL_ALWAYS Deletes the mailbox even if tasks are waiting.
116 * In this case, all the tasks pending will be readied.
117 *
118 * err is a pointer to an error code that can contain one of the following values:
119 * OS_NO_ERR The call was successful and the mailbox was deleted
120 * OS_ERR_DEL_ISR If you attempted to delete the mailbox from an ISR
121 * OS_ERR_INVALID_OPT An invalid option was specified
122 * OS_ERR_TASK_WAITING One or more tasks were waiting on the mailbox
123 * OS_ERR_EVENT_TYPE If you didn't pass a pointer to a mailbox
124 * OS_ERR_PEVENT_NULL If 'pevent' is a NULL pointer.
125 *
126 * Returns : pevent upon error
127 * (OS_EVENT *)0 if the mailbox was successfully deleted.
128 *
129 * Note(s) : 1) This function must be used with care. Tasks that would normally expect the presence of
130 * the mailbox MUST check the return code of OSMboxPend().
131 * 2) OSMboxAccept() callers will not know that the intended mailbox has been deleted!
132 * 3) This call can potentially disable interrupts for a long time. The interrupt disable
133 * time is directly proportional to the number of tasks waiting on the mailbox.
134 * 4) Because ALL tasks pending on the mailbox will be readied, you MUST be careful in
135 * applications where the mailbox is used for mutual exclusion because the resource(s)
136 * will no longer be guarded by the mailbox.
137 *********************************************************************************************************
138 */
139
140 #if OS_MBOX_DEL_EN > 0
141 OS_EVENT *OSMboxDel (OS_EVENT *pevent, INT8U opt, INT8U *err)
142 {
\ 0060 0A12 PUSH R10
\ 0062 0B12 PUSH R11
\ 0064 0812 PUSH R8
\ 0066 0B4C MOV R12,R11
\ 0068 18410800 MOV 8(SP),R8
143 #if OS_CRITICAL_METHOD == 3 /* Allocate storage for CPU status register */
144 OS_CPU_SR cpu_sr;
145 #endif
146 BOOLEAN tasks_waiting;
147
148
149 if (OSIntNesting > 0) { /* See if called from ISR ... */
\ 006C C2930000 CMP.B #0,&OSIntNesting
\ 0070 0524 JEQ (?0069)
150 *err = OS_ERR_DEL_ISR; /* ... can't DELETE from an ISR */
\ 0072 F8408C00 MOV.B #140,0(R8)
\ 0076 0000
151 return (pevent);
\ 0078 0C4B MOV R11,R12
152 }
\ 007A 4B3C JMP (?0088)
\ 007C ?0069:
153 #if OS_ARG_CHK_EN > 0
154 if (pevent == (OS_EVENT *)0) { /* Validate 'pevent' */
\ 007C 0B93 CMP #0,R11
\ 007E 0420 JNE (?0071)
155 *err = OS_ERR_PEVENT_NULL;
\ 0080 E8420000 MOV.B #4,0(R8)
156 return (pevent);
\ 0084 0C43 MOV #0,R12
157 }
\ 0086 453C JMP (?0088)
\ 0088 ?0071:
158 if (pevent->OSEventType != OS_EVENT_TYPE_MBOX) { /* Validate event block type */
\ 0088 5C43 MOV.B #1,R12
\ 008A 6C9B CMP.B @R11,R12
\ 008C 0424 JEQ (?0073)
159 *err = OS_ERR_EVENT_TYPE;
\ 008E D8430000 MOV.B #1,0(R8)
160 return (pevent);
\ 0092 0C4B MOV R11,R12
161 }
\ 0094 3E3C JMP (?0088)
\ 0096 ?0073:
162 #endif
163 OS_ENTER_CRITICAL();
\ 0096 32C2 DINT
164 if (pevent->OSEventGrp != 0x00) { /* See if any tasks waiting on mailbox */
\ 0098 CB930100 CMP.B #0,1(R11)
\ 009C 0224 JEQ (?0075)
165 tasks_waiting = TRUE; /* Yes */
\ 009E 5A43 MOV.B #1,R10
166 } else {
\ 00A0 013C JMP (?0076)
\ 00A2 ?0075:
167 tasks_waiting = FALSE; /* No */
\ 00A2 4A43 MOV.B #0,R10
\ 00A4 ?0076:
168 }
169 switch (opt) {
\ 00A4 4E83 SUB.B #0,R14
\ 00A6 0324 JEQ (?0078)
\ 00A8 5E83 SUB.B #1,R14
\ 00AA 1424 JEQ (?0081)
\ 00AC 2D3C JMP (?0087)
\ 00AE ?0078:
170 case OS_DEL_NO_PEND: /* Delete mailbox only if no task waiting */
171 if (tasks_waiting == FALSE) {
\ 00AE 4A93 CMP.B #0,R10
\ 00B0 0C20 JNE (?0080)
172 pevent->OSEventType = OS_EVENT_TYPE_UNUSED;
\ 00B2 CB430000 MOV.B #0,0(R11)
173 pevent->OSEventPtr = OSEventFreeList; /* Return Event Control Block to free list */
\ 00B6 9B420000 MOV &OSEventFreeList,4(R11)
\ 00BA 0400
174 OSEventFreeList = pevent; /* Get next free event control block */
\ 00BC 824B0000 MOV R11,&OSEventFreeList
175 OS_EXIT_CRITICAL();
\ 00C0 32D2 EINT
176 *err = OS_NO_ERR;
\ 00C2 C8430000 MOV.B #0,0(R8)
177 return ((OS_EVENT *)0); /* Mailbox has been deleted */
\ 00C6 0C43 MOV #0,R12
178 } else {
\ 00C8 243C JMP (?0088)
\ 00CA ?0080:
179 OS_EXIT_CRITICAL();
\ 00CA 32D2 EINT
180 *err = OS_ERR_TASK_WAITING;
\ 00CC F8420000 MOV.B #8,0(R8)
181 return (pevent);
\ 00D0 0C4B MOV R11,R12
182 }
\ 00D2 1F3C JMP (?0088)
\ 00D4 ?0081:
183
184 case OS_DEL_ALWAYS: /* Always delete the mailbox */
185 while (pevent->OSEventGrp != 0x00) { /* Ready ALL tasks waiting for mailbox */
\ 00D4 CB930100 CMP.B #0,1(R11)
\ 00D8 0724 JEQ (?0082)
186 OS_EventTaskRdy(pevent, (void *)0, OS_STAT_MBOX);
\ 00DA 6312 PUSH.B #2
\ 00DC 0E43 MOV #0,R14
\ 00DE 0C4B MOV R11,R12
\ 00E0 B0120000 CALL #OS_EventTaskRdy
\ 00E4 2153 ADD #2,SP
\ 00E6 F63F JMP (?0081)
\ 00E8 ?0082:
187 }
188 pevent->OSEventType = OS_EVENT_TYPE_UNUSED;
\ 00E8 CB430000 MOV.B #0,0(R11)
189 pevent->OSEventPtr = OSEventFreeList; /* Return Event Control Block to free list */
\ 00EC 9B420000 MOV &OSEventFreeList,4(R11)
\ 00F0 0400
190 OSEventFreeList = pevent; /* Get next free event control block */
\ 00F2 824B0000 MOV R11,&OSEventFreeList
191 OS_EXIT_CRITICAL();
\ 00F6 32D2 EINT
192 if (tasks_waiting == TRUE) { /* Reschedule only if task(s) were waiting */
\ 00F8 5A93 CMP.B #1,R10
\ 00FA 0220 JNE (?0086)
193 OS_Sched(); /* Find highest priority task ready to run */
\ 00FC B0120000 CALL #OS_Sched
\ 0100 ?0086:
194 }
195 *err = OS_NO_ERR;
\ 0100 C8430000 MOV.B #0,0(R8)
196 return ((OS_EVENT *)0); /* Mailbox has been deleted */
\ 0104 0C43 MOV #0,R12
197
198 default:
\ 0106 053C JMP (?0088)
\ 0108 ?0087:
199 OS_EXIT_CRITICAL();
\ 0108 32D2 EINT
200 *err = OS_ERR_INVALID_OPT;
\ 010A F8400700 MOV.B #7,0(R8)
\ 010E 0000
201 return (pevent);
\ 0110 0C4B MOV R11,R12
202 }
\ 0112 ?0088:
\ 0112 3841 POP R8
\ 0114 3B41 POP R11
\ 0116 3A41 POP R10
\ 0118 3041 RET
\ 011A ?0077:
203 }
\ 011A OSMboxPend:
204 #endif
205
206 /*$PAGE*/
207 /*
208 *********************************************************************************************************
209 * PEND ON MAILBOX FOR A MESSAGE
210 *
211 * Description: This function waits for a message to be sent to a mailbox
212 *
213 * Arguments : pevent is a pointer to the event control block associated with the desired mailbox
214 *
215 * timeout is an optional timeout period (in clock ticks). If non-zero, your task will
216 * wait for a message to arrive at the mailbox up to the amount of time
217 * specified by this argument. If you specify 0, however, your task will wait
218 * forever at the specified mailbox or, until a message arrives.
219 *
220 * err is a pointer to where an error message will be deposited. Possible error
221 * messages are:
222 *
223 * OS_NO_ERR The call was successful and your task received a
224 * message.
225 * OS_TIMEOUT A message was not received within the specified timeout
226 * OS_ERR_EVENT_TYPE Invalid event type
227 * OS_ERR_PEND_ISR If you called this function from an ISR and the result
228 * would lead to a suspension.
229 * OS_ERR_PEVENT_NULL If 'pevent' is a NULL pointer
230 *
231 * Returns : != (void *)0 is a pointer to the message received
232 * == (void *)0 if no message was received or,
233 * if 'pevent' is a NULL pointer or,
234 * if you didn't pass the proper pointer to the event control block.
235 *********************************************************************************************************
236 */
237
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -