source: rtems/cpukit/score/include/rtems/score/isrlock.h @ 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: 5.0 KB
RevLine 
[2d915cf]1/**
2 * @file
3 *
4 * @ingroup ScoreISRLocks
5 *
6 * @brief ISR Locks
7 */
8
9/*
10 * Copyright (c) 2013 embedded brains GmbH.  All rights reserved.
11 *
12 *  embedded brains GmbH
13 *  Dornierstr. 4
14 *  82178 Puchheim
15 *  Germany
16 *  <rtems@embedded-brains.de>
17 *
18 * The license and distribution terms for this file may be
19 * found in the file LICENSE in this distribution or at
[c499856]20 * http://www.rtems.org/license/LICENSE.
[2d915cf]21 */
22
23#ifndef _RTEMS_SCORE_ISR_LOCK_H
24#define _RTEMS_SCORE_ISR_LOCK_H
25
26#include <rtems/score/isrlevel.h>
27#include <rtems/score/smplock.h>
28
29#ifdef __cplusplus
30extern "C" {
31#endif
32
33/**
34 * @defgroup ScoreISRLocks ISR Locks
35 *
36 * @ingroup ScoreISR
37 *
38 * @brief Low-level lock to protect critical sections accessed by threads and
39 * interrupt service routines.
40 *
41 * On single processor configurations the ISR locks degrade to simple ISR
42 * disable/enable sequences.  No additional storage or objects are required.
43 *
44 * This synchronization primitive is supported on SMP configurations.  Here SMP
45 * locks are used.
46 *
47 * @{
48 */
49
50/**
51 * @brief ISR lock control.
52 */
53typedef struct {
[d50acdbb]54#if defined( RTEMS_SMP )
55  SMP_lock_Control lock;
56#endif
[2d915cf]57} ISR_lock_Control;
58
[d50acdbb]59/**
60 * @brief Local ISR lock context for acquire and release pairs.
61 */
62typedef struct {
63#if defined( RTEMS_SMP )
64  SMP_lock_Context lock_context;
65#else
66  ISR_Level isr_level;
67#endif
68} ISR_lock_Context;
69
[2d915cf]70/**
71 * @brief Initializer for static initialization of ISR locks.
72 */
73#if defined( RTEMS_SMP )
[53ad908]74  #define ISR_LOCK_INITIALIZER( name ) \
75    { SMP_LOCK_INITIALIZER( name ) }
[2d915cf]76#else
[53ad908]77  #define ISR_LOCK_INITIALIZER( name ) \
[2d915cf]78    { }
79#endif
80
81/**
82 * @brief Initializes an ISR lock.
83 *
84 * Concurrent initialization leads to unpredictable results.
85 *
[d50acdbb]86 * @param[in,out] lock The ISR lock control.
[53ad908]87 * @param[in] name The name for the ISR lock.  This name must be persistent
88 * throughout the life time of this lock.
[2d915cf]89 */
[53ad908]90static inline void _ISR_lock_Initialize(
91  ISR_lock_Control *lock,
92  const char *name
93)
[d50acdbb]94{
[2d915cf]95#if defined( RTEMS_SMP )
[53ad908]96  _SMP_lock_Initialize( &lock->lock, name );
[2d915cf]97#else
[d50acdbb]98  (void) lock;
[53ad908]99  (void) name;
[2d915cf]100#endif
[d50acdbb]101}
[2d915cf]102
[28779c7]103/**
104 * @brief Destroys an ISR lock.
105 *
106 * Concurrent destruction leads to unpredictable results.
107 *
108 * @param[in,out] lock The ISR lock control.
109 */
110static inline void _ISR_lock_Destroy( ISR_lock_Control *lock )
111{
112#if defined( RTEMS_SMP )
113  _SMP_lock_Destroy( &lock->lock );
114#else
115  (void) lock;
116#endif
117}
118
[2d915cf]119/**
120 * @brief Acquires an ISR lock.
121 *
122 * Interrupts will be disabled.  On SMP configurations this function acquires
123 * an SMP lock.
124 *
125 * This function can be used in thread and interrupt context.
126 *
[d50acdbb]127 * @param[in,out] lock The ISR lock control.
128 * @param[in,out] context The local ISR lock context for an acquire and release
129 * pair.
[2d915cf]130 *
[8d640134]131 * @see _ISR_lock_Release_and_ISR_enable().
[2d915cf]132 */
[d50acdbb]133static inline void _ISR_lock_ISR_disable_and_acquire(
134  ISR_lock_Control *lock,
135  ISR_lock_Context *context
136)
137{
[2d915cf]138#if defined( RTEMS_SMP )
[d50acdbb]139  _SMP_lock_ISR_disable_and_acquire( &lock->lock, &context->lock_context );
[2d915cf]140#else
[d50acdbb]141  (void) lock;
142  _ISR_Disable( context->isr_level );
[2d915cf]143#endif
[d50acdbb]144}
[2d915cf]145
146/**
147 * @brief Releases an ISR lock.
148 *
149 * The interrupt status will be restored.  On SMP configurations this function
150 * releases an SMP lock.
151 *
152 * This function can be used in thread and interrupt context.
153 *
[d50acdbb]154 * @param[in,out] lock The ISR lock control.
155 * @param[in,out] context The local ISR lock context for an acquire and release
156 * pair.
[2d915cf]157 *
[8d640134]158 * @see _ISR_lock_ISR_disable_and_acquire().
[2d915cf]159 */
[d50acdbb]160static inline void _ISR_lock_Release_and_ISR_enable(
161  ISR_lock_Control *lock,
162  ISR_lock_Context *context
163)
164{
[2d915cf]165#if defined( RTEMS_SMP )
[d50acdbb]166  _SMP_lock_Release_and_ISR_enable( &lock->lock, &context->lock_context );
[2d915cf]167#else
[d50acdbb]168  (void) lock;
169  _ISR_Enable( context->isr_level );
[2d915cf]170#endif
[d50acdbb]171}
[2d915cf]172
[8d640134]173/**
174 * @brief Acquires an ISR lock inside an ISR disabled section.
175 *
176 * The interrupt status will remain unchanged.  On SMP configurations this
177 * function acquires an SMP lock.
178 *
179 * In case the executing context can be interrupted by higher priority
180 * interrupts and these interrupts enter the critical section protected by this
181 * lock, then the result is unpredictable.
182 *
[d50acdbb]183 * @param[in,out] lock The ISR lock control.
184 * @param[in,out] context The local ISR lock context for an acquire and release
185 * pair.
[8d640134]186 *
187 * @see _ISR_lock_Release().
188 */
[d50acdbb]189static inline void _ISR_lock_Acquire(
190  ISR_lock_Control *lock,
191  ISR_lock_Context *context
192)
193{
[8d640134]194#if defined( RTEMS_SMP )
[d50acdbb]195  _SMP_lock_Acquire( &lock->lock, &context->lock_context );
[8d640134]196#else
[d50acdbb]197  (void) lock;
198  (void) context;
[8d640134]199#endif
[d50acdbb]200}
[8d640134]201
202/**
203 * @brief Releases an ISR lock inside an ISR disabled section.
204 *
205 * The interrupt status will remain unchanged.  On SMP configurations this
206 * function releases an SMP lock.
207 *
[d50acdbb]208 * @param[in,out] lock The ISR lock control.
209 * @param[in,out] context The local ISR lock context for an acquire and release
210 * pair.
[8d640134]211 *
212 * @see _ISR_lock_Acquire().
213 */
[d50acdbb]214static inline void _ISR_lock_Release(
215  ISR_lock_Control *lock,
216  ISR_lock_Context *context
217)
218{
[8d640134]219#if defined( RTEMS_SMP )
[d50acdbb]220  _SMP_lock_Release( &lock->lock, &context->lock_context );
[8d640134]221#else
[d50acdbb]222  (void) lock;
223  (void) context;
[8d640134]224#endif
[d50acdbb]225}
[8d640134]226
[2d915cf]227/** @} */
228
229#ifdef __cplusplus
230}
231#endif
232
233#endif /* _RTEMS_SCORE_ISR_LOCK_H */
Note: See TracBrowser for help on using the repository browser.