Changeset c7bc6d4 in rtems


Ignore:
Timestamp:
Jun 10, 2013, 9:14:35 AM (6 years ago)
Author:
Sebastian Huber <sebastian.huber@…>
Branches:
4.11, master
Children:
2a8713a
Parents:
3ccce23
git-author:
Sebastian Huber <sebastian.huber@…> (06/10/13 09:14:35)
git-committer:
Sebastian Huber <sebastian.huber@…> (06/12/13 14:11:24)
Message:

rtems: Add interrupt locks

Interrupt locks are low-level lock to protect critical sections accessed
by threads and interrupt service routines.

Files:
3 edited

Legend:

Unmodified
Added
Removed
  • cpukit/rtems/include/rtems/rtems/intr.h

    r3ccce23 rc7bc6d4  
    2727
    2828#include <rtems/score/isr.h>
     29#include <rtems/score/smplock.h>
    2930
    3031/**
     
    135136#define rtems_interrupt_clear( _interrupt_to_clear )
    136137
     138/**
     139 * @defgroup ClassicINTRLocks Interrupt Locks
     140 *
     141 * @ingroup ClassicINTR
     142 *
     143 * @brief Low-level lock to protect critical sections accessed by threads and
     144 * interrupt service routines.
     145 *
     146 * This synchronization primitive is supported on SMP configurations.
     147 *
     148 * @{
     149 */
     150
     151/**
     152 * @brief Interrupt lock control.
     153 */
     154typedef struct {
     155  #if defined( RTEMS_SMP )
     156    SMP_lock_Control lock;
     157  #endif
     158} rtems_interrupt_lock;
     159
     160/**
     161 * @brief Initializer for static initialization of interrupt locks.
     162 */
     163#if defined( RTEMS_SMP )
     164  #define RTEMS_INTERRUPT_LOCK_INITIALIZER \
     165    { SMP_LOCK_INITIALIZER }
     166#else
     167  #define RTEMS_INTERRUPT_LOCK_INITIALIZER \
     168    { }
     169#endif
     170
     171/**
     172 * @brief Initializes an interrupt lock.
     173 *
     174 * Concurrent initialization leads to unpredictable results.
     175 */
     176#if defined( RTEMS_SMP )
     177  #define rtems_interrupt_lock_initialize( _lock ) \
     178    _SMP_lock_Initialize( &( _lock )->lock )
     179#else
     180  #define rtems_interrupt_lock_initialize( _lock ) \
     181    do { \
     182      (void) _lock; \
     183    } while (0)
     184#endif
     185
     186/**
     187 * @brief Acquires an interrupt lock.
     188 *
     189 * Interrupts will be disabled.  On SMP configurations this function acquires a
     190 * SMP lock.
     191 *
     192 * This function can be used in thread and interrupt context.
     193 *
     194 * @see rtems_interrupt_lock_release().
     195 */
     196#if defined( RTEMS_SMP )
     197  #define rtems_interrupt_lock_acquire( _lock, _isr_cookie ) \
     198    _SMP_lock_ISR_disable_and_acquire( &( _lock )->lock, _isr_cookie )
     199#else
     200  #define rtems_interrupt_lock_acquire( _lock, _isr_cookie ) \
     201    do { \
     202      (void) _lock; \
     203      rtems_interrupt_disable( _isr_cookie ); \
     204    } while (0)
     205#endif
     206
     207/**
     208 * @brief Releases an interrupt lock.
     209 *
     210 * The interrupt status will be restored.  On SMP configurations this function
     211 * releases a SMP lock.
     212 *
     213 * This function can be used in thread and interrupt context.
     214 *
     215 * @see rtems_interrupt_lock_acquire().
     216 */
     217#if defined( RTEMS_SMP )
     218  #define rtems_interrupt_lock_release( _lock, _isr_cookie ) \
     219    _SMP_lock_Release_and_ISR_enable( &( _lock )->lock, _isr_cookie )
     220#else
     221  #define rtems_interrupt_lock_release( _lock, _isr_cookie ) \
     222    do { \
     223      (void) _lock; \
     224      rtems_interrupt_enable( _isr_cookie ); \
     225    } while (0)
     226#endif
     227
     228/**
     229 * @brief Acquires an interrupt lock in the corresponding interrupt service
     230 * routine.
     231 *
     232 * The interrupt status will remain unchanged.  On SMP configurations this
     233 * function acquires a SMP lock.
     234 *
     235 * In case the corresponding interrupt service routine can be interrupted by
     236 * higher priority interrupts and these interrupts enter the critical section
     237 * protected by this lock, then the result is unpredictable.
     238 *
     239 * @see rtems_interrupt_lock_release_isr().
     240 */
     241#if defined( RTEMS_SMP )
     242  #define rtems_interrupt_lock_acquire_isr( _lock ) \
     243    _SMP_lock_Acquire( &( _lock )->lock )
     244#else
     245  #define rtems_interrupt_lock_acquire_isr( _lock ) \
     246    do { \
     247      (void) _lock; \
     248    } while (0)
     249#endif
     250
     251/**
     252 * @brief Releases an interrupt lock in the corresponding interrupt service
     253 * routine.
     254 *
     255 * The interrupt status will remain unchanged.  On SMP configurations this
     256 * function releases a SMP lock.
     257 *
     258 * @see rtems_interrupt_lock_acquire_isr().
     259 */
     260#if defined( RTEMS_SMP )
     261  #define rtems_interrupt_lock_release_isr( _lock ) \
     262    _SMP_lock_Release( &( _lock )->lock )
     263#else
     264  #define rtems_interrupt_lock_release_isr( _lock ) \
     265    do { \
     266      (void) _lock; \
     267    } while (0)
     268#endif
     269
     270/** @} */
     271
    137272#ifdef __cplusplus
    138273}
  • doc/user/intr.t

    r3ccce23 rc7bc6d4  
    2222@item @code{@value{DIRPREFIX}interrupt_enable} - Enable Interrupts
    2323@item @code{@value{DIRPREFIX}interrupt_flash} - Flash Interrupt
     24@item @code{@value{DIRPREFIX}interrupt_lock_initialize} - Initialize an ISR Lock
     25@item @code{@value{DIRPREFIX}interrupt_lock_acquire} - Acquire an ISR Lock
     26@item @code{@value{DIRPREFIX}interrupt_lock_release} - Release an ISR Lock
     27@item @code{@value{DIRPREFIX}interrupt_lock_acquire_isr} - Acquire an ISR Lock from ISR
     28@item @code{@value{DIRPREFIX}interrupt_lock_release_isr} - Release an ISR Lock from ISR
    2429@item @code{@value{DIRPREFIX}interrupt_is_in_progress} - Is an ISR in Progress
    2530@end itemize
     
    195200@item rtems_interrupt_disable
    196201@item rtems_interrupt_flash
     202@item rtems_interrupt_lock_acquire
     203@item rtems_interrupt_lock_release
     204@item rtems_interrupt_lock_acquire_isr
     205@item rtems_interrupt_lock_release_isr
    197206@item rtems_interrupt_is_in_progress
    198207@item rtems_interrupt_catch
     
    458467@c
    459468@page
     469@subsection INTERRUPT_LOCK_INITIALIZE - Initialize an ISR Lock
     470
     471@subheading CALLING SEQUENCE:
     472
     473@ifset is-C
     474@findex rtems_interrupt_lock_initialize
     475@example
     476void rtems_interrupt_lock_initialize(
     477  rtems_interrupt_lock *lock
     478);
     479@end example
     480@end ifset
     481
     482@subheading DIRECTIVE STATUS CODES:
     483
     484NONE
     485
     486@subheading DESCRIPTION:
     487
     488Initializes an interrupt lock.
     489
     490@subheading NOTES:
     491
     492Concurrent initialization leads to unpredictable results.
     493
     494@c
     495@c
     496@c
     497@page
     498@subsection INTERRUPT_LOCK_ACQUIRE - Acquire an ISR Lock
     499
     500@subheading CALLING SEQUENCE:
     501
     502@ifset is-C
     503@findex rtems_interrupt_lock_acquire
     504@example
     505void rtems_interrupt_lock_acquire(
     506  rtems_interrupt_lock *lock,
     507  rtems_interrupt_level level
     508);
     509@end example
     510@end ifset
     511
     512@subheading DIRECTIVE STATUS CODES:
     513
     514NONE
     515
     516@subheading DESCRIPTION:
     517
     518Interrupts will be disabled.  On SMP configurations this directive acquires a
     519SMP lock.
     520
     521@subheading NOTES:
     522
     523This directive will not cause the calling thread to be preempted.  This
     524directive can be used in thread and interrupt context.
     525
     526@c
     527@c
     528@c
     529@page
     530@subsection INTERRUPT_LOCK_RELEASE - Release an ISR Lock
     531
     532@subheading CALLING SEQUENCE:
     533
     534@ifset is-C
     535@findex rtems_interrupt_lock_release
     536@example
     537void rtems_interrupt_lock_release(
     538  rtems_interrupt_lock *lock,
     539  rtems_interrupt_level level
     540);
     541@end example
     542@end ifset
     543
     544@subheading DIRECTIVE STATUS CODES:
     545
     546NONE
     547
     548@subheading DESCRIPTION:
     549
     550The interrupt status will be restored.  On SMP configurations this directive
     551releases a SMP lock.
     552
     553@subheading NOTES:
     554
     555This directive will not cause the calling thread to be preempted.  This
     556directive can be used in thread and interrupt context.
     557
     558@c
     559@c
     560@c
     561@page
     562@subsection INTERRUPT_LOCK_ACQUIRE_ISR - Acquire an ISR Lock from ISR
     563
     564@subheading CALLING SEQUENCE:
     565
     566@ifset is-C
     567@findex rtems_interrupt_lock_acquire_isr
     568@example
     569void rtems_interrupt_lock_acquire_isr(
     570  rtems_interrupt_lock *lock,
     571  rtems_interrupt_level level
     572);
     573@end example
     574@end ifset
     575
     576@subheading DIRECTIVE STATUS CODES:
     577
     578NONE
     579
     580@subheading DESCRIPTION:
     581
     582The interrupt status will remain unchanged.  On SMP configurations this
     583directive acquires a SMP lock.
     584
     585In case the corresponding interrupt service routine can be interrupted by
     586higher priority interrupts and these interrupts enter the critical section
     587protected by this lock, then the result is unpredictable.
     588
     589@subheading NOTES:
     590
     591This directive should be called from the corresponding interrupt service
     592routine.
     593
     594@c
     595@c
     596@c
     597@page
     598@subsection INTERRUPT_LOCK_RELEASE_ISR - Release an ISR Lock from ISR
     599
     600@subheading CALLING SEQUENCE:
     601
     602@ifset is-C
     603@findex rtems_interrupt_lock_release_isr
     604@example
     605void rtems_interrupt_lock_release_isr(
     606  rtems_interrupt_lock *lock,
     607  rtems_interrupt_level level
     608);
     609@end example
     610@end ifset
     611
     612@subheading DIRECTIVE STATUS CODES:
     613
     614NONE
     615
     616@subheading DESCRIPTION:
     617
     618The interrupt status will remain unchanged.  On SMP configurations this
     619directive releases a SMP lock.
     620
     621@subheading NOTES:
     622
     623This directive should be called from the corresponding interrupt service
     624routine.
     625
     626@c
     627@c
     628@c
     629@page
    460630@subsection INTERRUPT_IS_IN_PROGRESS - Is an ISR in Progress
    461631
  • testsuites/sptests/sp37/init.c

    r3ccce23 rc7bc6d4  
    4444
    4545/* test bodies */
     46
     47static void test_interrupt_locks( void )
     48{
     49  rtems_interrupt_lock lock = RTEMS_INTERRUPT_LOCK_INITIALIZER;
     50  rtems_interrupt_level level;
     51
     52  rtems_interrupt_lock_initialize( &lock );
     53
     54  rtems_interrupt_lock_acquire( &lock, level );
     55  rtems_interrupt_lock_release( &lock, level );
     56
     57  rtems_interrupt_lock_acquire_isr( &lock );
     58  rtems_interrupt_lock_release_isr( &lock );
     59}
     60
    4661void test_interrupt_inline(void)
    4762{
     
    319334  check_isr_worked( "body", isr_in_progress_body );
    320335
     336  test_interrupt_locks();
     337
    321338  puts( "*** END OF TEST 37 ***" );
    322339  rtems_test_exit( 0 );
Note: See TracChangeset for help on using the changeset viewer.