Back to home page

LXR

 
 

    


File indexing completed on 2025-05-11 08:24:08

0001 /**
0002  *  @file
0003  *
0004  *  LEON3 Shared Memory Lock Routines
0005  *
0006  *  This shared memory locked queue support routine need to be
0007  *  able to lock the specified locked queue.  Interrupts are
0008  *  disabled while the queue is locked to prevent preemption
0009  *  and deadlock when two tasks poll for the same lock.
0010  *  previous level.
0011  */
0012 
0013 /*
0014  *  COPYRIGHT (c) 1989-2012.
0015  *  On-Line Applications Research Corporation (OAR).
0016  *
0017  *  The license and distribution terms for this file may be
0018  *  found in the file LICENSE in this distribution or at
0019  *  http://www.rtems.org/license/LICENSE.
0020  */
0021 
0022 #include <rtems.h>
0023 #include <bsp.h>
0024 #include <shm_driver.h>
0025 
0026 
0027 /*
0028  *  Initialize the lock for the specified locked queue.
0029  */
0030 void Shm_Initialize_lock(
0031   Shm_Locked_queue_Control *lq_cb
0032 )
0033 {
0034   lq_cb->lock = LQ_UNLOCKED;
0035 }
0036 
0037 /*
0038  *  This shared memory locked queue support routine locks the
0039  *  specified locked queue.  It disables interrupts to prevent
0040  *  a deadlock condition.
0041  */
0042 extern unsigned int LEON3_Atomic_Swap(uint32_t value, uint32_t *address);
0043 
0044 __asm__ (
0045     ".text\n"
0046     ".align 4\n"
0047     "LEON3_Atomic_Swap:\n"
0048     "  retl\n"
0049     "  swapa [%o1] 1, %o0\n"
0050 );
0051 
0052 
0053 
0054 void Shm_Lock(
0055   Shm_Locked_queue_Control *lq_cb
0056 )
0057 {
0058   uint32_t isr_level;
0059   uint32_t *lockptr = (uint32_t *) &lq_cb->lock;
0060   uint32_t lock_value;
0061 
0062   lock_value = SHM_LOCK_VALUE;
0063   rtems_interrupt_disable( isr_level );
0064 
0065     Shm_isrstat = isr_level;
0066     while ( lock_value ) {
0067       lock_value = LEON3_Atomic_Swap(lock_value, lockptr);
0068       /*
0069        *  If not available, then may want to delay to reduce load on lock.
0070        */
0071    }
0072 }
0073 
0074 /*
0075  *  Shm_Unlock
0076  *
0077  *  Unlock the lock for the specified locked queue.
0078  */
0079 
0080 void Shm_Unlock(
0081   Shm_Locked_queue_Control *lq_cb
0082 )
0083 {
0084   uint32_t isr_level;
0085 
0086   lq_cb->lock = SHM_UNLOCK_VALUE;
0087   isr_level = Shm_isrstat;
0088   rtems_interrupt_enable( isr_level );
0089 }
0090