source: rtems/cpukit/include/rtems/score/isrlock.h @ 926ed2b0

5
Last change on this file since 926ed2b0 was 926ed2b0, checked in by Sebastian Huber <sebastian.huber@…>, on 01/18/19 at 12:32:51

score: Remove unused _ISR_lock_Flash()

  • Property mode set to 100644
File size: 10.6 KB
Line 
1/**
2 * @file
3 *
4 * @ingroup ScoreISRLocks
5 *
6 * @brief ISR Locks
7 */
8
9/*
10 * Copyright (c) 2013, 2019 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#if defined( RTEMS_PROFILING )
72  /**
73   * @brief The last interrupt disable instant in CPU counter ticks.
74   */
75  CPU_Counter_ticks ISR_disable_instant;
76#endif
77} ISR_lock_Context;
78
79/**
80 * @brief Defines an ISR lock member.
81 *
82 * Do not add a ';' after this macro.
83 *
84 * @param _designator The designator for the interrupt lock.
85 */
86#if defined( RTEMS_SMP )
87  #define ISR_LOCK_MEMBER( _designator ) ISR_lock_Control _designator;
88#else
89  #define ISR_LOCK_MEMBER( _designator )
90#endif
91
92/**
93 * @brief Declares an ISR lock variable.
94 *
95 * Do not add a ';' after this macro.
96 *
97 * @param _qualifier The qualifier for the interrupt lock, e.g. extern.
98 * @param _designator The designator for the interrupt lock.
99 */
100#if defined( RTEMS_SMP )
101  #define ISR_LOCK_DECLARE( _qualifier, _designator ) \
102    _qualifier ISR_lock_Control _designator;
103#else
104  #define ISR_LOCK_DECLARE( _qualifier, _designator )
105#endif
106
107/**
108 * @brief Defines an ISR lock variable.
109 *
110 * Do not add a ';' after this macro.
111 *
112 * @param _qualifier The qualifier for the interrupt lock, e.g. static.
113 * @param _designator The designator for the interrupt lock.
114 * @param _name The name for the interrupt lock.  It must be a string.  The
115 * name is only used if profiling is enabled.
116 */
117#if defined( RTEMS_SMP )
118  #define ISR_LOCK_DEFINE( _qualifier, _designator, _name ) \
119    _qualifier ISR_lock_Control _designator = { SMP_LOCK_INITIALIZER( _name ) };
120#else
121  #define ISR_LOCK_DEFINE( _qualifier, _designator, _name )
122#endif
123
124/**
125 * @brief Defines an ISR lock variable reference.
126 *
127 * Do not add a ';' after this macro.
128 *
129 * @param _designator The designator for the interrupt lock reference.
130 * @param _target The target for the interrupt lock reference.
131 */
132#if defined( RTEMS_SMP )
133  #define ISR_LOCK_REFERENCE( _designator, _target ) \
134    ISR_lock_Control *_designator = _target;
135#else
136  #define ISR_LOCK_REFERENCE( _designator, _target )
137#endif
138
139/**
140 * @brief Initializer for static initialization of ISR locks.
141 *
142 * @param _name The name for the interrupt lock.  It must be a string.  The
143 * name is only used if profiling is enabled.
144 */
145#if defined( RTEMS_SMP )
146  #define ISR_LOCK_INITIALIZER( _name ) \
147    { SMP_LOCK_INITIALIZER( _name ) }
148#else
149  #define ISR_LOCK_INITIALIZER( _name ) \
150    { }
151#endif
152
153/**
154 * @brief Sets the ISR level in the ISR lock context.
155 *
156 * @param[in] context The ISR lock context.
157 * @param[in] level The ISR level.
158 */
159RTEMS_INLINE_ROUTINE void _ISR_lock_Context_set_level(
160  ISR_lock_Context *context,
161  ISR_Level         level
162)
163{
164#if defined( RTEMS_SMP )
165  context->Lock_context.isr_level = level;
166#else
167  context->isr_level = level;
168#endif
169}
170
171/**
172 * @brief Initializes an ISR lock.
173 *
174 * Concurrent initialization leads to unpredictable results.
175 *
176 * @param[in] _lock The ISR lock control.
177 * @param[in] _name The name for the ISR lock.  This name must be a
178 * string persistent throughout the life time of this lock.  The name is only
179 * used if profiling is enabled.
180 */
181#if defined( RTEMS_SMP )
182  #define _ISR_lock_Initialize( _lock, _name ) \
183    _SMP_lock_Initialize( &( _lock )->Lock, _name )
184#else
185  #define _ISR_lock_Initialize( _lock, _name )
186#endif
187
188/**
189 * @brief Destroys an ISR lock.
190 *
191 * Concurrent destruction leads to unpredictable results.
192 *
193 * @param[in] _lock The ISR lock control.
194 */
195#if defined( RTEMS_SMP )
196  #define _ISR_lock_Destroy( _lock ) \
197    _SMP_lock_Destroy( &( _lock )->Lock )
198#else
199  #define _ISR_lock_Destroy( _lock )
200#endif
201
202/**
203 * @brief Acquires an ISR lock.
204 *
205 * Interrupts will be disabled.  On SMP configurations this function acquires
206 * an SMP lock.
207 *
208 * This function can be used in thread and interrupt context.
209 *
210 * @param[in] _lock The ISR lock control.
211 * @param[in] _context The local ISR lock context for an acquire and release
212 * pair.
213 *
214 * @see _ISR_lock_Release_and_ISR_enable().
215 */
216#if defined( RTEMS_SMP )
217  #define _ISR_lock_ISR_disable_and_acquire( _lock, _context ) \
218    _SMP_lock_ISR_disable_and_acquire( \
219      &( _lock )->Lock, \
220      &( _context )->Lock_context \
221    )
222#else
223  #define _ISR_lock_ISR_disable_and_acquire( _lock, _context ) \
224    _ISR_Local_disable( ( _context )->isr_level )
225#endif
226
227/**
228 * @brief Releases an ISR lock.
229 *
230 * The interrupt status will be restored.  On SMP configurations this function
231 * releases an SMP lock.
232 *
233 * This function can be used in thread and interrupt context.
234 *
235 * @param[in] _lock The ISR lock control.
236 * @param[in] _context The local ISR lock context for an acquire and release
237 * pair.
238 *
239 * @see _ISR_lock_ISR_disable_and_acquire().
240 */
241#if defined( RTEMS_SMP )
242  #define _ISR_lock_Release_and_ISR_enable( _lock, _context ) \
243    _SMP_lock_Release_and_ISR_enable( \
244      &( _lock )->Lock, \
245      &( _context )->Lock_context \
246    )
247#else
248  #define _ISR_lock_Release_and_ISR_enable( _lock, _context ) \
249    _ISR_Local_enable( ( _context )->isr_level )
250#endif
251
252/**
253 * @brief Acquires an ISR lock inside an ISR disabled section.
254 *
255 * The interrupt status will remain unchanged.  On SMP configurations this
256 * function acquires an SMP lock.
257 *
258 * In case the executing context can be interrupted by higher priority
259 * interrupts and these interrupts enter the critical section protected by this
260 * lock, then the result is unpredictable.
261 *
262 * @param[in] _lock The ISR lock control.
263 * @param[in] _context The local ISR lock context for an acquire and release
264 * pair.
265 *
266 * @see _ISR_lock_Release().
267 */
268#if defined( RTEMS_SMP )
269  #define _ISR_lock_Acquire( _lock, _context ) \
270    do { \
271      _Assert( _ISR_Get_level() != 0 ); \
272      _SMP_lock_Acquire( \
273        &( _lock )->Lock, \
274        &( _context )->Lock_context \
275      ); \
276    } while ( 0 )
277#else
278  #define _ISR_lock_Acquire( _lock, _context ) \
279    do { (void) _context; } while ( 0 )
280#endif
281
282/**
283 * @brief Releases an ISR lock inside an ISR disabled section.
284 *
285 * The interrupt status will remain unchanged.  On SMP configurations this
286 * function releases an SMP lock.
287 *
288 * @param[in] _lock The ISR lock control.
289 * @param[in] _context The local ISR lock context for an acquire and release
290 * pair.
291 *
292 * @see _ISR_lock_Acquire().
293 */
294#if defined( RTEMS_SMP )
295  #define _ISR_lock_Release( _lock, _context ) \
296    _SMP_lock_Release( \
297      &( _lock )->Lock, \
298      &( _context )->Lock_context \
299    )
300#else
301  #define _ISR_lock_Release( _lock, _context ) \
302    do { (void) _context; } while ( 0 )
303#endif
304
305/**
306 * @brief Acquires an ISR lock inside an ISR disabled section (inline).
307 *
308 * @see _ISR_lock_Acquire().
309 */
310#if defined( RTEMS_SMP )
311  #define _ISR_lock_Acquire_inline( _lock, _context ) \
312    do { \
313      _Assert( _ISR_Get_level() != 0 ); \
314      _SMP_lock_Acquire_inline( \
315        &( _lock )->Lock, \
316        &( _context )->Lock_context \
317      ); \
318    } while ( 0 )
319#else
320  #define _ISR_lock_Acquire_inline( _lock, _context ) \
321    do { (void) _context; } while ( 0 )
322#endif
323
324/**
325 * @brief Releases an ISR lock inside an ISR disabled section (inline).
326 *
327 * @see _ISR_lock_Release().
328 */
329#if defined( RTEMS_SMP )
330  #define _ISR_lock_Release_inline( _lock, _context ) \
331    _SMP_lock_Release_inline( \
332      &( _lock )->Lock, \
333      &( _context )->Lock_context \
334    )
335#else
336  #define _ISR_lock_Release_inline( _lock, _context ) \
337    do { (void) _context; } while ( 0 )
338#endif
339
340#if defined( RTEMS_DEBUG )
341  /**
342   * @brief Returns true, if the ISR lock is owned by the current processor,
343   * otherwise false.
344   *
345   * On uni-processor configurations, this function returns true, if interrupts
346   * are disabled, otherwise false.
347   *
348   * @param[in] _lock The ISR lock control.
349   */
350  #if defined( RTEMS_SMP )
351    #define _ISR_lock_Is_owner( _lock ) \
352      _SMP_lock_Is_owner( &( _lock )->Lock )
353  #else
354    #define _ISR_lock_Is_owner( _lock ) \
355      ( _ISR_Get_level() != 0 )
356  #endif
357#endif
358
359#if defined( RTEMS_PROFILING )
360  #define _ISR_lock_ISR_disable_profile( _context ) \
361    ( _context )->ISR_disable_instant = _CPU_Counter_read();
362#else
363  #define _ISR_lock_ISR_disable_profile( _context )
364#endif
365
366/**
367 * @brief Disables interrupts and saves the previous interrupt state in the ISR
368 * lock context.
369 *
370 * This function can be used in thread and interrupt context.
371 *
372 * @param[in] _context The local ISR lock context to store the interrupt state.
373 *
374 * @see _ISR_lock_ISR_enable().
375 */
376#if defined( RTEMS_SMP )
377  #define _ISR_lock_ISR_disable( _context ) \
378    do { \
379      _ISR_Local_disable( ( _context )->Lock_context.isr_level ); \
380      _ISR_lock_ISR_disable_profile( _context ) \
381    } while ( 0 )
382#else
383  #define _ISR_lock_ISR_disable( _context ) \
384    do { \
385      _ISR_Local_disable( ( _context )->isr_level ); \
386      _ISR_lock_ISR_disable_profile( _context ) \
387    } while ( 0 )
388#endif
389
390/**
391 * @brief Restores the saved interrupt state of the ISR lock context.
392 *
393 * This function can be used in thread and interrupt context.
394 *
395 * @param[in] _context The local ISR lock context containing the saved
396 * interrupt state.
397 *
398 * @see _ISR_lock_ISR_disable().
399 */
400#if defined( RTEMS_SMP )
401  #define _ISR_lock_ISR_enable( _context ) \
402    _ISR_Local_enable( ( _context )->Lock_context.isr_level )
403#else
404  #define _ISR_lock_ISR_enable( _context ) \
405    _ISR_Local_enable( ( _context )->isr_level )
406#endif
407
408/** @} */
409
410#ifdef __cplusplus
411}
412#endif
413
414#endif /* _RTEMS_SCORE_ISR_LOCK_H */
Note: See TracBrowser for help on using the repository browser.