📄 os_sem.ls1
字号:
are waiting.
189 ; * In this case, all the tasks pending
will be readied.
190 ; *
191 ; * err is a pointer to an error code that can contain one of the fo
llowing values:
192 ; * OS_NO_ERR The call was successful and the sema
phore was deleted
193 ; * OS_ERR_DEL_ISR If you attempted to delete the semap
hore from an ISR
194 ; * OS_ERR_INVALID_OPT An invalid option was specified
195 ; * OS_ERR_TASK_WAITING One or more tasks were waiting on th
e semaphore
196 ; * OS_ERR_EVENT_TYPE If you didn't pass a pointer to a se
maphore
197 ; * OS_ERR_PEVENT_NULL If 'pevent' is a NULL pointer.
198 ; *
199 ; * Returns : pevent upon error
200 ; * (OS_EVENT *)0 if the semaphore was successfully deleted.
201 ; *
202 ; * Note(s) : 1) This function must be used with care. Tasks that would normally expect
the presence of
203 ; * the semaphore MUST check the return code of OSSemPend().
204 ; * 2) OSSemAccept() callers will not know that the intended semaphore has bee
n deleted unless
205 ; * they check 'pevent' to see that it's a NULL pointer.
206 ; * 3) This call can potentially disable interrupts for a long time. The inte
rrupt disable
207 ; * time is directly proportional to the number of tasks waiting on the sem
aphore.
208 ; * 4) Because ALL tasks pending on the semaphore will be readied, you MUST be
careful in
209 ; * applications where the semaphore is used for mutual exclusion because t
he resource(s)
210 ; * will no longer be guarded by the semaphore.
211 ; *****************************************************************************************
****************
A51 MACRO ASSEMBLER OS_SEM 08/08/2005 11:36:53 PAGE 5
212 ; */
213 ;
214 ; #if OS_SEM_DEL_EN > 0
215 ; OS_EVENT *OSSemDel (OS_EVENT *pevent, INT8U opt, INT8U *err)
216 ; {
217 ;
218 ; BOOLEAN tasks_waiting;
219 ;
220 ;
221 ; if (OSIntNesting > 0) { /* See if called from ISR ...
*/
222 ; *err = OS_ERR_DEL_ISR; /* ... can't DELETE from an IS
R */
223 ; return (pevent);
224 ; }
225 ; #if OS_ARG_CHK_EN > 0
226 ; if (pevent == (OS_EVENT *)0) { /* Validate 'pevent'
*/
227 ; *err = OS_ERR_PEVENT_NULL;
228 ; return (pevent);
229 ; }
230 ; if (pevent->OSEventType != OS_EVENT_TYPE_SEM) { /* Validate event block type
*/
231 ; *err = OS_ERR_EVENT_TYPE;
232 ; return (pevent);
233 ; }
234 ; #endif
235 ; OS_ENTER_CRITICAL();
236 ; if (pevent->OSEventGrp != 0x00) { /* See if any tasks waiting on
semaphore */
237 ; tasks_waiting = TRUE; /* Yes
*/
238 ; } else {
239 ; tasks_waiting = FALSE; /* No
*/
240 ; }
241 ; switch (opt) {
242 ; case OS_DEL_NO_PEND: /* Delete semaphore only if no
task waiting */
243 ; if (tasks_waiting == FALSE) {
244 ; pevent->OSEventType = OS_EVENT_TYPE_UNUSED;
245 ; pevent->OSEventPtr = OSEventFreeList; /* Return Event Control Block
to free list */
246 ; OSEventFreeList = pevent; /* Get next free event control
block */
247 ; OS_EXIT_CRITICAL();
248 ; *err = OS_NO_ERR;
249 ; return ((OS_EVENT *)0); /* Semaphore has been deleted
*/
250 ; } else {
251 ; OS_EXIT_CRITICAL();
252 ; *err = OS_ERR_TASK_WAITING;
253 ; return (pevent);
254 ; }
255 ;
256 ; case OS_DEL_ALWAYS: /* Always delete the semaphore
*/
257 ; while (pevent->OSEventGrp != 0x00) { /* Ready ALL tasks waiting for
semaphore */
258 ; OS_EventTaskRdy(pevent, (void *)0, OS_STAT_SEM);
259 ; }
260 ; pevent->OSEventType = OS_EVENT_TYPE_UNUSED;
261 ; pevent->OSEventPtr = OSEventFreeList; /* Return Event Control Block
to free list */
262 ; OSEventFreeList = pevent; /* Get next free event control
block */
A51 MACRO ASSEMBLER OS_SEM 08/08/2005 11:36:53 PAGE 6
263 ; OS_EXIT_CRITICAL();
264 ; if (tasks_waiting == TRUE) { /* Reschedule only if task(s)
were waiting */
265 ; OS_Sched(); /* Find highest priority task
ready to run */
266 ; }
267 ; *err = OS_NO_ERR;
268 ; return ((OS_EVENT *)0); /* Semaphore has been deleted
*/
269 ;
270 ; default:
271 ; OS_EXIT_CRITICAL();
272 ; *err = OS_ERR_INVALID_OPT;
273 ; return (pevent);
274 ; }
275 ; }
276 ; #endif
277 ;
278 ; /*$PAGE*/
279 ; /*
280 ; *****************************************************************************************
****************
281 ; * PEND ON SEMAPHORE
282 ; *
283 ; * Description: This function waits for a semaphore.
284 ; *
285 ; * Arguments : pevent is a pointer to the event control block associated with the
desired
286 ; * semaphore.
287 ; *
288 ; * timeout is an optional timeout period (in clock ticks). If non-zero
, your task will
289 ; * wait for the resource up to the amount of time specified by
this argument.
290 ; * If you specify 0, however, your task will wait forever at th
e specified
291 ; * semaphore or, until the resource becomes available (or the e
vent occurs).
292 ; *
293 ; * err is a pointer to where an error message will be deposited. P
ossible error
294 ; * messages are:
295 ; *
296 ; * OS_NO_ERR The call was successful and your task ow
ns the resource
297 ; * or, the event you are waiting for occurr
ed.
298 ; * OS_TIMEOUT The semaphore was not received within th
e specified
299 ; * timeout.
300 ; * OS_ERR_EVENT_TYPE If you didn't pass a pointer to a semaph
ore.
301 ; * OS_ERR_PEND_ISR If you called this function from an ISR
and the result
302 ; * would lead to a suspension.
303 ; * OS_ERR_PEVENT_NULL If 'pevent' is a NULL pointer.
304 ; *
305 ; * Returns : none
306 ; *****************************************************************************************
****************
307 ; */
308 ;
309 ; void OSSemPend (OS_EVENT *pevent, INT16U timeout, INT8U *err)
310 ; {
311 ;
312 ;
A51 MACRO ASSEMBLER OS_SEM 08/08/2005 11:36:53 PAGE 7
313 ;
314 ; if (OSIntNesting > 0) { /* See if called from ISR ...
*/
315 ; *err = OS_ERR_PEND_ISR; /* ... can't PEND from an ISR
*/
316 ; return;
317 ; }
318 ; #if OS_ARG_CHK_EN > 0
319 ; if (pevent == (OS_EVENT *)0) { /* Validate 'pevent'
*/
320 ; *err = OS_ERR_PEVENT_NULL;
321 ; return;
322 ; }
323 ; if (pevent->OSEventType != OS_EVENT_TYPE_SEM) { /* Validate event block type
*/
324 ; *err = OS_ERR_EVENT_TYPE;
325 ; return;
326 ; }
327 ; #endif
328 ; OS_ENTER_CRITICAL();
329 ; if (pevent->OSEventCnt > 0) { /* If sem. is positive, resource av
ailable ... */
330 ; pevent->OSEventCnt--; /* ... decrement semaphore only if
positive. */
331 ; OS_EXIT_CRITICAL();
332 ; *err = OS_NO_ERR;
333 ; return;
334 ; }
335 ; /* Otherwise, must wait until event
occurs */
336 ; OSTCBCur->OSTCBStat |= OS_STAT_SEM; /* Resource not available, pend on
semaphore */
337 ; OSTCBCur->OSTCBDly = timeout; /* Store pend timeout in TCB
*/
338 ; OS_EventTaskWait(pevent); /* Suspend task until event or time
out occurs */
339 ; OS_EXIT_CRITICAL();
340 ; OS_Sched(); /* Find next highest priority task
ready */
341 ; OS_ENTER_CRITICAL();
342 ; if (OSTCBCur->OSTCBStat & OS_STAT_SEM) { /* Must have timed out if still wai
ting for event*/
343 ; OS_EventTO(pevent);
344 ; OS_EXIT_CRITICAL();
345 ; *err = OS_TIMEOUT; /* Indicate that didn't get event w
ithin TO */
346 ; return;
347 ; }
348 ; OSTCBCur->OSTCBEventPtr = (OS_EVENT *)0;
349 ; OS_EXIT_CRITICAL();
350 ; *err = OS_NO_ERR;
351 ; }
352 ; /*$PAGE*/
353 ; /*
354 ; *****************************************************************************************
****************
355 ; * POST TO A SEMAPHORE
356 ; *
357 ; * Description: This function signals a semaphore
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -