📄 os_mutex.ls1
字号:
314 ; * time is directly proportional to the number of tasks waiting on the mut
ex.
315 ; * 3) Because ALL tasks pending on the mutex will be readied, you MUST be car
eful because the
316 ; * resource(s) will no longer be guarded by the mutex.
317 ; *****************************************************************************************
****************
318 ; */
319 ;
320 ; #if OS_MUTEX_DEL_EN
321 ; OS_EVENT *OSMutexDel (OS_EVENT *pevent, INT8U opt, INT8U *err)LG_REENTRANT
A51 MACRO ASSEMBLER OS_MUTEX 05/17/2005 11:19:51 PAGE 7
322 ; {
323 ; #if OS_CRITICAL_METHOD == 3 /* Allocate storage for CPU status regis
ter */
324 ; OS_CPU_SR cpu_sr;
325 ; #endif
326 ; BOOLEAN tasks_waiting;
327 ; INT8U pip;
328 ;
329 ;
330 ; if (OSIntNesting > 0) { /* See if called from ISR ...
*/
331 ; *err = OS_ERR_DEL_ISR; /* ... can't DELETE from an IS
R */
332 ; return (pevent);
333 ; }
334 ; #if OS_ARG_CHK_EN > 0
335 ; if (pevent == (OS_EVENT *)0) { /* Validate 'pevent'
*/
336 ; *err = OS_ERR_PEVENT_NULL;
337 ; return ((OS_EVENT *)0);
338 ; }
339 ; if (pevent->OSEventType != OS_EVENT_TYPE_MUTEX) { /* Validate event block type
*/
340 ; *err = OS_ERR_EVENT_TYPE;
341 ; return (pevent);
342 ; }
343 ; #endif
344 ; OS_ENTER_CRITICAL();
345 ; if (pevent->OSEventGrp != 0x00) { /* See if any tasks waiting on
mutex */
346 ; tasks_waiting = TRUE; /* Yes
*/
347 ; } else {
348 ; tasks_waiting = FALSE; /* No
*/
349 ; }
350 ; switch (opt) {
351 ; case OS_DEL_NO_PEND: /* Delete mutex only if no tas
k waiting */
352 ; if (tasks_waiting == FALSE) {
353 ; pip = (INT8U)(pevent->OSEventCnt >> 8);
354 ; OSTCBPrioTbl[pip] = (OS_TCB *)0; /* Free up the PIP
*/
355 ; pevent->OSEventType = OS_EVENT_TYPE_UNUSED;
356 ; pevent->OSEventPtr = OSEventFreeList; /* Return Event Control Block
to free list */
357 ; OSEventFreeList = pevent;
358 ; OS_EXIT_CRITICAL();
359 ; *err = OS_NO_ERR;
360 ; return ((OS_EVENT *)0); /* Mutex has been deleted
*/
361 ; } else {
362 ; OS_EXIT_CRITICAL();
363 ; *err = OS_ERR_TASK_WAITING;
364 ; return (pevent);
365 ; }
366 ;
367 ; case OS_DEL_ALWAYS: /* Always delete the mutex
*/
368 ; while (pevent->OSEventGrp != 0x00) { /* Ready ALL tasks waiting for
mutex */
369 ; OS_EventTaskRdy(pevent, (void *)0, OS_STAT_MUTEX);
370 ; }
371 ; pip = (INT8U)(pevent->OSEventCnt >> 8);
372 ; OSTCBPrioTbl[pip] = (OS_TCB *)0; /* Free up the PIP
*/
A51 MACRO ASSEMBLER OS_MUTEX 05/17/2005 11:19:51 PAGE 8
373 ; pevent->OSEventType = OS_EVENT_TYPE_UNUSED;
374 ; pevent->OSEventPtr = OSEventFreeList; /* Return Event Control Block
to free list */
375 ; OSEventFreeList = pevent; /* Get next free event control
block */
376 ; OS_EXIT_CRITICAL();
377 ; if (tasks_waiting == TRUE) { /* Reschedule only if task(s)
were waiting */
378 ; OS_Sched(); /* Find highest priority task
ready to run */
379 ; }
380 ; *err = OS_NO_ERR;
381 ; return ((OS_EVENT *)0); /* Mutex has been deleted
*/
382 ;
383 ; default:
384 ; OS_EXIT_CRITICAL();
385 ; *err = OS_ERR_INVALID_OPT;
386 ; return (pevent);
387 ; }
388 ; }
389 ; #endif
390 ;
391 ; /*$PAGE*/
392 ; /*
393 ; *****************************************************************************************
****************
394 ; * PEND ON MUTUAL EXCLUSION SEMAPHORE
395 ; *
396 ; * Description: This function waits for a mutual exclusion semaphore.
397 ; *
398 ; * Arguments : pevent is a pointer to the event control block associated with the
desired
399 ; * mutex.
400 ; *
401 ; * timeout is an optional timeout period (in clock ticks). If non-zero
, your task will
402 ; * wait for the resource up to the amount of time specified by
this argument.
403 ; * If you specify 0, however, your task will wait forever at th
e specified
404 ; * mutex or, until the resource becomes available.
405 ; *
406 ; * err is a pointer to where an error message will be deposited. P
ossible error
407 ; * messages are:
408 ; * OS_NO_ERR The call was successful and your task
owns the mutex
409 ; * OS_TIMEOUT The mutex was not available within the
specified time.
410 ; * OS_ERR_EVENT_TYPE If you didn't pass a pointer to a mute
x
411 ; * OS_ERR_PEVENT_NULL 'pevent' is a NULL pointer
412 ; * OS_ERR_PEND_ISR If you called this function from an IS
R and the result
413 ; * would lead to a suspension.
414 ; *
415 ; * Returns : none
416 ; *
417 ; * Note(s) : 1) The task that owns the Mutex MUST NOT pend on any other event while it
owns the mutex.
418 ; * 2) You MUST NOT change the priority of the task that owns the mutex
419 ; *****************************************************************************************
****************
420 ; */
421 ; void OSMutexPend (OS_EVENT *pevent, INT16U timeout, INT8U *err)LG_REENTRANT
A51 MACRO ASSEMBLER OS_MUTEX 05/17/2005 11:19:51 PAGE 9
422 ; {
423 ; #if OS_CRITICAL_METHOD == 3 /* Allocate storage for CPU st
atus register */
424 ; OS_CPU_SR cpu_sr;
425 ; #endif
426 ; INT8U pip; /* Priority Inheritance Priori
ty (PIP) */
427 ; INT8U mprio; /* Mutex owner priority
*/
428 ; BOOLEAN rdy; /* Flag indicating task was re
ady */
429 ; OS_TCB *ptcb;
430 ;
431 ;
432 ; if (OSIntNesting > 0) { /* See if called from ISR ...
*/
433 ; *err = OS_ERR_PEND_ISR; /* ... can't PEND from an ISR
*/
434 ; return;
435 ; }
436 ; #if OS_ARG_CHK_EN > 0
437 ; if (pevent == (OS_EVENT *)0) { /* Validate 'pevent'
*/
438 ; *err = OS_ERR_PEVENT_NULL;
439 ; return;
440 ; }
441 ; if (pevent->OSEventType != OS_EVENT_TYPE_MUTEX) { /* Validate event block type
*/
442 ; *err = OS_ERR_EVENT_TYPE;
443 ; return;
444 ; }
445 ; #endif
446 ; OS_ENTER_CRITICAL();
/* Is Mutex available? */
447 ; if ((INT8U)(pevent->OSEventCnt & OS_MUTEX_KEEP_LOWER_8) == OS_MUTEX_AVAILABLE) {
448 ; pevent->OSEventCnt &= OS_MUTEX_KEEP_UPPER_8; /* Yes, Acquire the resource
*/
449 ; pevent->OSEventCnt |= OSTCBCur->OSTCBPrio; /* Save priority of ownin
g task */
450 ; pevent->OSEventPtr = (void *)OSTCBCur; /* Point to owning task's
OS_TCB */
451 ; OS_EXIT_CRITICAL();
452 ; *err = OS_NO_ERR;
453 ; return;
454 ; }
455 ; pip = (INT8U)(pevent->OSEventCnt >> 8); /* No, Get PIP from mut
ex */
456 ; mprio = (INT8U)(pevent->OSEventCnt & OS_MUTEX_KEEP_LOWER_8); /* Get priority of
mutex owner */
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -