RTEMS  5.0.0
isrlock.h
Go to the documentation of this file.
1 
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
30 extern "C" {
31 #endif
32 
56 typedef struct {
57 #if defined( RTEMS_SMP )
58  SMP_lock_Control Lock;
59 #endif
61 
65 typedef 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 
75  CPU_Counter_ticks ISR_disable_instant;
76 #endif
78 
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 
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 
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 
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 
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 
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 
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 
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 
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 
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 
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 
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 
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 
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 
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 
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 
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 
410 #ifdef __cplusplus
411 }
412 #endif
413 
414 #endif /* _RTEMS_SCORE_ISR_LOCK_H */
#define RTEMS_INLINE_ROUTINE
Definition: basedefs.h:65
ISR Level Type.
ISR lock control.
Definition: isrlock.h:56
uint32_t ISR_Level
Definition: isrlevel.h:38
RTEMS_INLINE_ROUTINE void _ISR_lock_Context_set_level(ISR_lock_Context *context, ISR_Level level)
Sets the ISR level in the ISR lock context.
Definition: isrlock.h:159
unsigned context
Definition: tlb.h:108
SMP Lock API.
Local ISR lock context for acquire and release pairs.
Definition: isrlock.h:65