source: rtems/cpukit/score/include/rtems/score/isrlock.h @ b8aa1c1

4.115
Last change on this file since b8aa1c1 was b8aa1c1, checked in by Sebastian Huber <sebastian.huber@…>, on 03/05/15 at 08:53:09

score: C/C++ compatibility macros for ISR locks

Update #2273.

  • Property mode set to 100644
File size: 7.1 KB
Line 
1/**
2 * @file
3 *
4 * @ingroup ScoreISRLocks
5 *
6 * @brief ISR Locks
7 */
8
9/*
10 * Copyright (c) 2013-2015 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
20 * http://www.rtems.org/license/LICENSE.
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 *
53 * @warning Empty structures are implementation-defined in C.  GCC gives them a
54 * size of zero.  In C++ empty structures have a non-zero size.
55 */
56typedef struct {
57#if defined( RTEMS_SMP )
58  SMP_lock_Control Lock;
59#endif
60} ISR_lock_Control;
61
62/**
63 * @brief Local ISR lock context for acquire and release pairs.
64 */
65typedef struct {
66#if defined( RTEMS_SMP )
67  SMP_lock_Context Lock_context;
68#else
69  ISR_Level isr_level;
70#endif
71} ISR_lock_Context;
72
73/**
74 * @brief Defines an ISR lock member.
75 *
76 * Do not add a ';' after this macro.
77 *
78 * @param _designator The designator for the interrupt lock.
79 */
80#if defined( RTEMS_SMP )
81  #define ISR_LOCK_MEMBER( _designator ) ISR_lock_Control _designator;
82#else
83  #define ISR_LOCK_MEMBER( _designator )
84#endif
85
86/**
87 * @brief Declares an ISR lock variable.
88 *
89 * Do not add a ';' after this macro.
90 *
91 * @param _qualifier The qualifier for the interrupt lock, e.g. extern.
92 * @param _designator The designator for the interrupt lock.
93 */
94#if defined( RTEMS_SMP )
95  #define ISR_LOCK_DECLARE( _qualifier, _designator ) \
96    _qualifier ISR_lock_Control _designator;
97#else
98  #define ISR_LOCK_DECLARE( _qualifier, _designator )
99#endif
100
101/**
102 * @brief Defines an ISR lock variable.
103 *
104 * Do not add a ';' after this macro.
105 *
106 * @param _qualifier The qualifier for the interrupt lock, e.g. static.
107 * @param _designator The designator for the interrupt lock.
108 * @param _name The name for the interrupt lock.  It must be a string.  The
109 * name is only used if profiling is enabled.
110 */
111#if defined( RTEMS_SMP )
112  #define ISR_LOCK_DEFINE( _qualifier, _designator, _name ) \
113    _qualifier ISR_lock_Control _designator = { SMP_LOCK_INITIALIZER( _name ) };
114#else
115  #define ISR_LOCK_DEFINE( _qualifier, _designator, _name )
116#endif
117
118/**
119 * @brief Defines an ISR lock variable reference.
120 *
121 * Do not add a ';' after this macro.
122 *
123 * @param _designator The designator for the interrupt lock reference.
124 * @param _target The target for the interrupt lock reference.
125 */
126#if defined( RTEMS_SMP )
127  #define ISR_LOCK_REFERENCE( _designator, _target ) \
128    ISR_lock_Control *_designator = _target;
129#else
130  #define ISR_LOCK_REFERENCE( _designator, _target )
131#endif
132
133/**
134 * @brief Initializer for static initialization of ISR locks.
135 *
136 * @param _name The name for the interrupt lock.  It must be a string.  The
137 * name is only used if profiling is enabled.
138 */
139#if defined( RTEMS_SMP )
140  #define ISR_LOCK_INITIALIZER( _name ) \
141    { SMP_LOCK_INITIALIZER( _name ) }
142#else
143  #define ISR_LOCK_INITIALIZER( _name ) \
144    { }
145#endif
146
147/**
148 * @brief Initializes an ISR lock.
149 *
150 * Concurrent initialization leads to unpredictable results.
151 *
152 * @param[in] _lock The ISR lock control.
153 * @param[in] _name The name for the ISR lock.  This name must be a
154 * string persistent throughout the life time of this lock.  The name is only
155 * used if profiling is enabled.
156 */
157#if defined( RTEMS_SMP )
158  #define _ISR_lock_Initialize( _lock, _name ) \
159    _SMP_lock_Initialize( &( _lock )->Lock, _name )
160#else
161  #define _ISR_lock_Initialize( _lock, _name )
162#endif
163
164/**
165 * @brief Destroys an ISR lock.
166 *
167 * Concurrent destruction leads to unpredictable results.
168 *
169 * @param[in] _lock The ISR lock control.
170 */
171#if defined( RTEMS_SMP )
172  #define _ISR_lock_Destroy( _lock ) \
173    _SMP_lock_Destroy( &( _lock )->Lock )
174#else
175  #define _ISR_lock_Destroy( _lock )
176#endif
177
178/**
179 * @brief Acquires an ISR lock.
180 *
181 * Interrupts will be disabled.  On SMP configurations this function acquires
182 * an SMP lock.
183 *
184 * This function can be used in thread and interrupt context.
185 *
186 * @param[in] _lock The ISR lock control.
187 * @param[in] context The local ISR lock context for an acquire and release
188 * pair.
189 *
190 * @see _ISR_lock_Release_and_ISR_enable().
191 */
192#if defined( RTEMS_SMP )
193  #define _ISR_lock_ISR_disable_and_acquire( _lock, _context ) \
194    _SMP_lock_ISR_disable_and_acquire( \
195      &( _lock )->Lock, \
196      &( _context )->Lock_context \
197    )
198#else
199  #define _ISR_lock_ISR_disable_and_acquire( _lock, _context ) \
200    _ISR_Disable( ( _context )->isr_level )
201#endif
202
203/**
204 * @brief Releases an ISR lock.
205 *
206 * The interrupt status will be restored.  On SMP configurations this function
207 * releases an SMP lock.
208 *
209 * This function can be used in thread and interrupt context.
210 *
211 * @param[in] _lock The ISR lock control.
212 * @param[in] _context The local ISR lock context for an acquire and release
213 * pair.
214 *
215 * @see _ISR_lock_ISR_disable_and_acquire().
216 */
217#if defined( RTEMS_SMP )
218  #define _ISR_lock_Release_and_ISR_enable( _lock, _context ) \
219    _SMP_lock_Release_and_ISR_enable( \
220      &( _lock )->Lock, \
221      &( _context )->Lock_context \
222    )
223#else
224  #define _ISR_lock_Release_and_ISR_enable( _lock, _context ) \
225    _ISR_Enable( ( _context )->isr_level )
226#endif
227
228/**
229 * @brief Acquires an ISR lock inside an ISR disabled section.
230 *
231 * The interrupt status will remain unchanged.  On SMP configurations this
232 * function acquires an SMP lock.
233 *
234 * In case the executing context can be interrupted by higher priority
235 * interrupts and these interrupts enter the critical section protected by this
236 * lock, then the result is unpredictable.
237 *
238 * @param[in] _lock The ISR lock control.
239 * @param[in] _context The local ISR lock context for an acquire and release
240 * pair.
241 *
242 * @see _ISR_lock_Release().
243 */
244#if defined( RTEMS_SMP )
245  #define _ISR_lock_Acquire( _lock, _context ) \
246    _SMP_lock_Acquire( \
247      &( _lock )->Lock, \
248      &( _context )->Lock_context \
249    )
250#else
251  #define _ISR_lock_Acquire( _lock, _context )
252#endif
253
254/**
255 * @brief Releases an ISR lock inside an ISR disabled section.
256 *
257 * The interrupt status will remain unchanged.  On SMP configurations this
258 * function releases an SMP lock.
259 *
260 * @param[in] _lock The ISR lock control.
261 * @param[in] _context The local ISR lock context for an acquire and release
262 * pair.
263 *
264 * @see _ISR_lock_Acquire().
265 */
266#if defined( RTEMS_SMP )
267  #define _ISR_lock_Release( _lock, _context ) \
268    _SMP_lock_Release( \
269      &( _lock )->Lock, \
270      &( _context )->Lock_context \
271    )
272#else
273  #define _ISR_lock_Release( _lock, _context )
274#endif
275
276/** @} */
277
278#ifdef __cplusplus
279}
280#endif
281
282#endif /* _RTEMS_SCORE_ISR_LOCK_H */
Note: See TracBrowser for help on using the repository browser.