OpenCores
URL https://opencores.org/ocsvn/openrisc_2011-10-31/openrisc_2011-10-31/trunk

Subversion Repositories openrisc_2011-10-31

[/] [openrisc/] [trunk/] [rtos/] [rtems/] [c/] [src/] [lib/] [libbsp/] [a29k/] [portsw/] [shmsupp/] [lock.c] - Blame information for rev 30

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 30 unneback
/*  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.OARcorp.com/rtems/license.html.
15
 *
16
 *  $Id: lock.c,v 1.2 2001-09-27 11:59:40 chris Exp $
17
 */
18
 
19
#include <rtems.h>
20
#include <bsp.h>
21
#include <shm_driver.h>
22
 
23
#ifndef lint
24
static char _sccsid[] = "@(#)lock.c 04/08/96     1.1\n";
25
#endif
26
 
27
/*
28
 *  Shm_Initialize_lock
29
 *
30
 *  Initialize the lock for the specified locked queue.
31
 */
32
 
33
void Shm_Initialize_lock(
34
  Shm_Locked_queue_Control *lq_cb
35
)
36
{
37
  lq_cb->lock = LQ_UNLOCKED;
38
}
39
 
40
/*  void _Shm_Lock( &lq_cb )
41
 *
42
 *  This shared memory locked queue support routine locks the
43
 *  specified locked queue.  It disables interrupts to prevent
44
 *  a deadlock condition.
45
 */
46
 
47
void Shm_Lock(
48
  Shm_Locked_queue_Control *lq_cb
49
)
50
{
51
  rtems_unsigned32 isr_level;
52
  rtems_unsigned32 *lockptr = &lq_cb->lock;
53
  rtems_unsigned32 lock_value;
54
 
55
  lock_value = 0x80000000;
56
  rtems_interrupt_disable( isr_level );
57
 
58
    Shm_isrstat = isr_level;
59
    while ( lock_value ) {
60
      asm volatile( ""
61
                         : "=r" (lockptr), "=r" (lock_value)
62
                         : "0" (lockptr),  "1" (lock_value)
63
                  );
64
      /*
65
       *  If not available, then may want to delay to reduce load on lock.
66
       */
67
 
68
      if ( lock_value )
69
        delay( 10 );   /* approximately 10 microseconds */
70
   }
71
}
72
 
73
/*
74
 *  Shm_Unlock
75
 *
76
 *  Unlock the lock for the specified locked queue.
77
 */
78
 
79
void Shm_Unlock(
80
  Shm_Locked_queue_Control *lq_cb
81
)
82
{
83
  rtems_unsigned32 isr_level;
84
 
85
  lq_cb->lock = SHM_UNLOCK_VALUE;
86
  isr_level = Shm_isrstat;
87
  rtems_interrupt_enable( isr_level );
88
}
89
 

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.