source: rtems/c/src/lib/libbsp/sparc/leon3/shmsupp/lock.c @ c499856

4.115
Last change on this file since c499856 was c499856, checked in by Chris Johns <chrisj@…>, on 03/20/14 at 21:10:47

Change all references of rtems.com to rtems.org.

  • Property mode set to 100644
File size: 1.8 KB
Line 
1/**
2 *  @file
3 *
4 *  LEON3 Shared Memory Lock Routines
5 *
6 *  This shared memory locked queue support routine need to be
7 *  able to lock the specified locked queue.  Interrupts are
8 *  disabled while the queue is locked to prevent preemption
9 *  and deadlock when two tasks poll for the same lock.
10 *  previous level.
11 */
12
13/*
14 *  COPYRIGHT (c) 1989-2012.
15 *  On-Line Applications Research Corporation (OAR).
16 *
17 *  The license and distribution terms for this file may be
18 *  found in the file LICENSE in this distribution or at
19 *  http://www.rtems.org/license/LICENSE.
20 */
21
22#include <rtems.h>
23#include <bsp.h>
24#include <shm_driver.h>
25
26
27/*
28 *  Initialize the lock for the specified locked queue.
29 */
30void Shm_Initialize_lock(
31  Shm_Locked_queue_Control *lq_cb
32)
33{
34  lq_cb->lock = LQ_UNLOCKED;
35}
36
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 */
42extern unsigned int LEON3_Atomic_Swap(uint32_t value, uint32_t *address);
43
44__asm__ (
45    ".text\n"
46    ".align 4\n"
47"LEON3_Atomic_Swap:\n"
48"       retl\n"
49"       swapa [%o1] 1, %o0\n"
50);
51
52
53
54void Shm_Lock(
55  Shm_Locked_queue_Control *lq_cb
56)
57{
58  uint32_t isr_level;
59  uint32_t *lockptr = (uint32_t *) &lq_cb->lock;
60  uint32_t lock_value;
61
62  lock_value = SHM_LOCK_VALUE;
63  rtems_interrupt_disable( isr_level );
64
65    Shm_isrstat = isr_level;
66    while ( lock_value ) {
67      lock_value = LEON3_Atomic_Swap(lock_value, lockptr);
68      /*
69       *  If not available, then may want to delay to reduce load on lock.
70       */
71   }
72}
73
74/*
75 *  Shm_Unlock
76 *
77 *  Unlock the lock for the specified locked queue.
78 */
79
80void Shm_Unlock(
81  Shm_Locked_queue_Control *lq_cb
82)
83{
84  uint32_t isr_level;
85
86  lq_cb->lock = SHM_UNLOCK_VALUE;
87  isr_level = Shm_isrstat;
88  rtems_interrupt_enable( isr_level );
89}
90
Note: See TracBrowser for help on using the repository browser.