source: rtems/c/src/lib/libbsp/nios2/nios2_iss/shmsupp/lock.c @ 783669fc

4.104.114.84.95
Last change on this file since 783669fc was 783669fc, checked in by Joel Sherrill <joel.sherrill@…>, on Aug 9, 2006 at 8:57:11 PM

2006-08-09 Kolja Waschk <waschk@…>

  • ChangeLog?, Makefile.am, README, acinclude.m4, configure.ac, nios2_iss/ChangeLog, nios2_iss/Makefile.am, nios2_iss/bsp_specs, nios2_iss/configure.ac, nios2_iss/nios2_iss.ptf, nios2_iss/nios2_iss.sh, nios2_iss/times, nios2_iss/console/console.c, nios2_iss/include/bsp.h, nios2_iss/include/bspopts.h.in, nios2_iss/include/coverhd.h, nios2_iss/include/tm27.h, nios2_iss/shmsupp/addrconv.c, nios2_iss/shmsupp/getcfg.c, nios2_iss/shmsupp/lock.c, nios2_iss/shmsupp/mpisr.c, nios2_iss/start/crtnn.s, nios2_iss/start/start.S, nios2_iss/startup/bspclean.c, nios2_iss/startup/bspstart.c, nios2_iss/startup/linkcmds, nios2_iss/startup/main.c, nios2_iss/startup/setvec.c, nios2_iss/timer/timer.c: New files.
  • Property mode set to 100644
File size: 1.9 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.com/license/LICENSE.
15 *
16 *  $Id$
17 */
18
19#include <rtems.h>
20#include <bsp.h>
21#include <shm_driver.h>
22
23/*
24 *  Shm_Initialize_lock
25 *
26 *  Initialize the lock for the specified locked queue.
27 */
28
29void Shm_Initialize_lock(
30  Shm_Locked_queue_Control *lq_cb
31)
32{
33  lq_cb->lock = LQ_UNLOCKED;
34}
35
36/*  void _Shm_Lock( &lq_cb )
37 *
38 *  This shared memory locked queue support routine locks the
39 *  specified locked queue.  It disables interrupts to prevent
40 *  a deadlock condition.
41 */
42
43void Shm_Lock(
44  Shm_Locked_queue_Control *lq_cb
45)
46{
47  uint32_t         isr_level;
48  uint32_t         *lockptr = (uint32_t*) &lq_cb->lock;
49  uint32_t         lock_value;
50
51  lock_value = 0x80000000;
52  rtems_interrupt_disable( isr_level );
53
54    Shm_isrstat = isr_level;
55    while ( lock_value ) {
56      asm volatile( ""
57                         : "=r" (lockptr), "=r" (lock_value)
58                         : "0" (lockptr),  "1" (lock_value)
59                  );
60      /*
61       *  If not available, then may want to delay to reduce load on lock.
62       */
63
64      if ( lock_value )
65        rtems_bsp_delay( 10 );   /* approximately 10 microseconds */
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.