source: rtems/c/src/lib/libbsp/no_cpu/no_bsp/shmsupp/lock.c @ 82e507e

4.115
Last change on this file since 82e507e was 82e507e, checked in by Joel Sherrill <joel.sherrill@…>, on Mar 17, 2014 at 6:25:48 PM

no_bsp/shmsupp/lock.c: Remove rtems_bsp_delay()

  • Property mode set to 100644
File size: 2.0 KB
Line 
1/*  Shared Memory Lock Routines
2 *
3 *  This shared memory locked queue support routine need to be
4 *  able to lock the specified locked queue.  Interrupts are
5 *  disabled while the queue is locked to prevent preemption
6 *  and deadlock when two tasks poll for the same lock.
7 *  previous level.
8 *
9 *  COPYRIGHT (c) 1989-1999.
10 *  On-Line Applications Research Corporation (OAR).
11 *
12 *  The license and distribution terms for this file may be
13 *  found in the file LICENSE in this distribution or at
14 *  http://www.rtems.org/license/LICENSE.
15 */
16
17#include <rtems.h>
18#include <bsp.h>
19#include <shm_driver.h>
20
21/*
22 *  Shm_Initialize_lock
23 *
24 *  Initialize the lock for the specified locked queue.
25 */
26
27void Shm_Initialize_lock(
28  Shm_Locked_queue_Control *lq_cb
29)
30{
31  lq_cb->lock = LQ_UNLOCKED;
32}
33
34/*  void _Shm_Lock( &lq_cb )
35 *
36 *  This shared memory locked queue support routine locks the
37 *  specified locked queue.  It disables interrupts to prevent
38 *  a deadlock condition.
39 */
40
41void Shm_Lock(
42  Shm_Locked_queue_Control *lq_cb
43)
44{
45  uint32_t         isr_level;
46  uint32_t         *lockptr = (uint32_t*) &lq_cb->lock;
47  uint32_t         lock_value;
48
49  lock_value = 0x80000000;
50  rtems_interrupt_disable( isr_level );
51
52    Shm_isrstat = isr_level;
53    while ( lock_value ) {
54      __asm__ volatile( ""
55                         : "=r" (lockptr), "=r" (lock_value)
56                         : "0" (lockptr),  "1" (lock_value)
57                  );
58      /*
59       *  If not available, then may want to delay to reduce load on lock.
60       *
61       *  NOTE: BSP must initialize the counter facility. Delay value is BSP
62       *        dependent.
63       */
64      if ( lock_value )
65        rtems_counter_delay_nanoseconds( 100 );
66   }
67}
68
69/*
70 *  Shm_Unlock
71 *
72 *  Unlock the lock for the specified locked queue.
73 */
74
75void Shm_Unlock(
76  Shm_Locked_queue_Control *lq_cb
77)
78{
79  uint32_t         isr_level;
80
81  lq_cb->lock = SHM_UNLOCK_VALUE;
82  isr_level = Shm_isrstat;
83  rtems_interrupt_enable( isr_level );
84}
Note: See TracBrowser for help on using the repository browser.