RTEMS 6.1-rc2
Loading...
Searching...
No Matches
isrlock.h
Go to the documentation of this file.
1/* SPDX-License-Identifier: BSD-2-Clause */
2
12/*
13 * Copyright (C) 2013, 2019 embedded brains GmbH & Co. KG
14 *
15 * Redistribution and use in source and binary forms, with or without
16 * modification, are permitted provided that the following conditions
17 * are met:
18 * 1. Redistributions of source code must retain the above copyright
19 * notice, this list of conditions and the following disclaimer.
20 * 2. Redistributions in binary form must reproduce the above copyright
21 * notice, this list of conditions and the following disclaimer in the
22 * documentation and/or other materials provided with the distribution.
23 *
24 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
25 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
26 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
27 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
28 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
29 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
30 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
31 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
32 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
33 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
34 * POSSIBILITY OF SUCH DAMAGE.
35 */
36
37#ifndef _RTEMS_SCORE_ISR_LOCK_H
38#define _RTEMS_SCORE_ISR_LOCK_H
39
41#include <rtems/score/smplock.h>
42
43#ifdef __cplusplus
44extern "C" {
45#endif
46
72typedef struct {
73#if defined( RTEMS_SMP )
74 SMP_lock_Control Lock;
75#endif
77
81typedef struct {
82#if defined( RTEMS_SMP )
83 SMP_lock_Context Lock_context;
84#else
85 ISR_Level isr_level;
86#endif
87#if defined( RTEMS_PROFILING )
91 CPU_Counter_ticks ISR_disable_instant;
92#endif
94
102#if defined( RTEMS_SMP )
103 #define ISR_LOCK_MEMBER( _designator ) ISR_lock_Control _designator;
104#else
105 #define ISR_LOCK_MEMBER( _designator )
106#endif
107
116#if defined( RTEMS_SMP )
117 #define ISR_LOCK_DECLARE( _qualifier, _designator ) \
118 _qualifier ISR_lock_Control _designator;
119#else
120 #define ISR_LOCK_DECLARE( _qualifier, _designator )
121#endif
122
133#if defined( RTEMS_SMP )
134 #define ISR_LOCK_DEFINE( _qualifier, _designator, _name ) \
135 _qualifier ISR_lock_Control _designator = { SMP_LOCK_INITIALIZER( _name ) };
136#else
137 #define ISR_LOCK_DEFINE( _qualifier, _designator, _name )
138#endif
139
148#if defined( RTEMS_SMP )
149 #define ISR_LOCK_REFERENCE( _designator, _target ) \
150 ISR_lock_Control *_designator = _target;
151#else
152 #define ISR_LOCK_REFERENCE( _designator, _target )
153#endif
154
161#if defined( RTEMS_SMP )
162 #define ISR_LOCK_INITIALIZER( _name ) \
163 { SMP_LOCK_INITIALIZER( _name ) }
164#else
165 #define ISR_LOCK_INITIALIZER( _name ) \
166 { }
167#endif
168
175static inline void _ISR_lock_Context_set_level(
177 ISR_Level level
178)
179{
180#if defined( RTEMS_SMP )
181 context->Lock_context.isr_level = level;
182#else
183 context->isr_level = level;
184#endif
185}
186
197#if defined( RTEMS_SMP )
198 #define _ISR_lock_Initialize( _lock, _name ) \
199 _SMP_lock_Initialize( &( _lock )->Lock, _name )
200#else
201 #define _ISR_lock_Initialize( _lock, _name )
202#endif
203
211#if defined( RTEMS_SMP )
212 #define _ISR_lock_Destroy( _lock ) \
213 _SMP_lock_Destroy( &( _lock )->Lock )
214#else
215 #define _ISR_lock_Destroy( _lock )
216#endif
217
226#if defined( RTEMS_SMP )
227 #define _ISR_lock_Set_name( _lock, _name ) \
228 _SMP_lock_Set_name( &( _lock )->Lock, _name )
229#else
230 #define _ISR_lock_Set_name( _lock, _name )
231#endif
232
247#if defined( RTEMS_SMP )
248 #define _ISR_lock_ISR_disable_and_acquire( _lock, _context ) \
249 _SMP_lock_ISR_disable_and_acquire( \
250 &( _lock )->Lock, \
251 &( _context )->Lock_context \
252 )
253#else
254 #define _ISR_lock_ISR_disable_and_acquire( _lock, _context ) \
255 _ISR_Local_disable( ( _context )->isr_level )
256#endif
257
272#if defined( RTEMS_SMP )
273 #define _ISR_lock_Release_and_ISR_enable( _lock, _context ) \
274 _SMP_lock_Release_and_ISR_enable( \
275 &( _lock )->Lock, \
276 &( _context )->Lock_context \
277 )
278#else
279 #define _ISR_lock_Release_and_ISR_enable( _lock, _context ) \
280 _ISR_Local_enable( ( _context )->isr_level )
281#endif
282
299#if defined( RTEMS_SMP )
300 #define _ISR_lock_Acquire( _lock, _context ) \
301 do { \
302 _Assert( _ISR_Get_level() != 0 ); \
303 _SMP_lock_Acquire( \
304 &( _lock )->Lock, \
305 &( _context )->Lock_context \
306 ); \
307 } while ( 0 )
308#else
309 #define _ISR_lock_Acquire( _lock, _context ) \
310 do { (void) _context; } while ( 0 )
311#endif
312
325#if defined( RTEMS_SMP )
326 #define _ISR_lock_Release( _lock, _context ) \
327 _SMP_lock_Release( \
328 &( _lock )->Lock, \
329 &( _context )->Lock_context \
330 )
331#else
332 #define _ISR_lock_Release( _lock, _context ) \
333 do { (void) _context; } while ( 0 )
334#endif
335
341#if defined( RTEMS_SMP )
342 #define _ISR_lock_Acquire_inline( _lock, _context ) \
343 do { \
344 _Assert( _ISR_Get_level() != 0 ); \
345 _SMP_lock_Acquire_inline( \
346 &( _lock )->Lock, \
347 &( _context )->Lock_context \
348 ); \
349 } while ( 0 )
350#else
351 #define _ISR_lock_Acquire_inline( _lock, _context ) \
352 do { (void) _context; } while ( 0 )
353#endif
354
360#if defined( RTEMS_SMP )
361 #define _ISR_lock_Release_inline( _lock, _context ) \
362 _SMP_lock_Release_inline( \
363 &( _lock )->Lock, \
364 &( _context )->Lock_context \
365 )
366#else
367 #define _ISR_lock_Release_inline( _lock, _context ) \
368 do { (void) _context; } while ( 0 )
369#endif
370
371#if defined( RTEMS_DEBUG )
381 #if defined( RTEMS_SMP )
382 #define _ISR_lock_Is_owner( _lock ) \
383 _SMP_lock_Is_owner( &( _lock )->Lock )
384 #else
385 #define _ISR_lock_Is_owner( _lock ) \
386 ( _ISR_Get_level() != 0 )
387 #endif
388#endif
389
390#if defined( RTEMS_PROFILING )
391 #define _ISR_lock_ISR_disable_profile( _context ) \
392 ( _context )->ISR_disable_instant = _CPU_Counter_read();
393#else
394 #define _ISR_lock_ISR_disable_profile( _context )
395#endif
396
407#if defined( RTEMS_SMP )
408 #define _ISR_lock_ISR_disable( _context ) \
409 do { \
410 _ISR_Local_disable( ( _context )->Lock_context.isr_level ); \
411 _ISR_lock_ISR_disable_profile( _context ) \
412 } while ( 0 )
413#else
414 #define _ISR_lock_ISR_disable( _context ) \
415 do { \
416 _ISR_Local_disable( ( _context )->isr_level ); \
417 _ISR_lock_ISR_disable_profile( _context ) \
418 } while ( 0 )
419#endif
420
431#if defined( RTEMS_SMP )
432 #define _ISR_lock_ISR_enable( _context ) \
433 _ISR_Local_enable( ( _context )->Lock_context.isr_level )
434#else
435 #define _ISR_lock_ISR_enable( _context ) \
436 _ISR_Local_enable( ( _context )->isr_level )
437#endif
438
441#ifdef __cplusplus
442}
443#endif
444
445#endif /* _RTEMS_SCORE_ISR_LOCK_H */
uint32_t ISR_Level
Definition: isrlevel.h:60
This header file provides the ISR_Level related interfaces of the ISR Handler.
rtems_termios_device_context * context
Definition: console-config.c:62
This header file provides the main interfaces of the SMP Locks.
Local ISR lock context for acquire and release pairs.
Definition: isrlock.h:81
ISR lock control.
Definition: isrlock.h:72