RTEMS 6.1-rc5
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, 2024 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
76#if defined( RTEMS_SMP )
77 #define ISR_LOCK_NEEDS_OBJECT 1
78#else
79 #define ISR_LOCK_NEEDS_OBJECT 0
80#endif
81
82#if ISR_LOCK_NEEDS_OBJECT
86typedef struct {
87 SMP_lock_Control Lock;
88} ISR_lock_Control;
89#endif
90
94typedef struct {
95#if defined( RTEMS_SMP )
96 SMP_lock_Context Lock_context;
97#else
98 ISR_Level isr_level;
99#endif
100#if defined( RTEMS_PROFILING )
104 CPU_Counter_ticks ISR_disable_instant;
105#endif
107
108#if ISR_LOCK_NEEDS_OBJECT
115 #define ISR_LOCK_INITIALIZER( _name ) { SMP_LOCK_INITIALIZER( _name ) }
116#endif
117
124static inline void _ISR_lock_Context_set_level(
126 ISR_Level level
127)
128{
129#if defined( RTEMS_SMP )
130 context->Lock_context.isr_level = level;
131#else
132 context->isr_level = level;
133#endif
134}
135
146#if defined( RTEMS_SMP )
147 #define _ISR_lock_Initialize( _lock, _name ) \
148 _SMP_lock_Initialize( &( _lock )->Lock, _name )
149#else
150 #define _ISR_lock_Initialize( _lock, _name ) \
151 do { (void) _name; } while (0)
152#endif
153
161#if defined( RTEMS_SMP )
162 #define _ISR_lock_Destroy( _lock ) \
163 _SMP_lock_Destroy( &( _lock )->Lock )
164#else
165 #define _ISR_lock_Destroy( _lock )
166#endif
167
176#if defined( RTEMS_SMP )
177 #define _ISR_lock_Set_name( _lock, _name ) \
178 _SMP_lock_Set_name( &( _lock )->Lock, _name )
179#else
180 #define _ISR_lock_Set_name( _lock, _name )
181#endif
182
197#if defined( RTEMS_SMP )
198 #define _ISR_lock_ISR_disable_and_acquire( _lock, _context ) \
199 _SMP_lock_ISR_disable_and_acquire( \
200 &( _lock )->Lock, \
201 &( _context )->Lock_context \
202 )
203#else
204 #define _ISR_lock_ISR_disable_and_acquire( _lock, _context ) \
205 _ISR_Local_disable( ( _context )->isr_level )
206#endif
207
222#if defined( RTEMS_SMP )
223 #define _ISR_lock_Release_and_ISR_enable( _lock, _context ) \
224 _SMP_lock_Release_and_ISR_enable( \
225 &( _lock )->Lock, \
226 &( _context )->Lock_context \
227 )
228#else
229 #define _ISR_lock_Release_and_ISR_enable( _lock, _context ) \
230 _ISR_Local_enable( ( _context )->isr_level )
231#endif
232
249#if defined( RTEMS_SMP )
250 #define _ISR_lock_Acquire( _lock, _context ) \
251 do { \
252 _Assert( _ISR_Get_level() != 0 ); \
253 _SMP_lock_Acquire( \
254 &( _lock )->Lock, \
255 &( _context )->Lock_context \
256 ); \
257 } while ( 0 )
258#else
259 #define _ISR_lock_Acquire( _lock, _context ) \
260 do { (void) _context; } while ( 0 )
261#endif
262
275#if defined( RTEMS_SMP )
276 #define _ISR_lock_Release( _lock, _context ) \
277 _SMP_lock_Release( \
278 &( _lock )->Lock, \
279 &( _context )->Lock_context \
280 )
281#else
282 #define _ISR_lock_Release( _lock, _context ) \
283 do { (void) _context; } while ( 0 )
284#endif
285
291#if defined( RTEMS_SMP )
292 #define _ISR_lock_Acquire_inline( _lock, _context ) \
293 do { \
294 _Assert( _ISR_Get_level() != 0 ); \
295 _SMP_lock_Acquire_inline( \
296 &( _lock )->Lock, \
297 &( _context )->Lock_context \
298 ); \
299 } while ( 0 )
300#else
301 #define _ISR_lock_Acquire_inline( _lock, _context ) \
302 do { (void) _context; } while ( 0 )
303#endif
304
310#if defined( RTEMS_SMP )
311 #define _ISR_lock_Release_inline( _lock, _context ) \
312 _SMP_lock_Release_inline( \
313 &( _lock )->Lock, \
314 &( _context )->Lock_context \
315 )
316#else
317 #define _ISR_lock_Release_inline( _lock, _context ) \
318 do { (void) _context; } while ( 0 )
319#endif
320
321#if defined( RTEMS_DEBUG )
331 #if defined( RTEMS_SMP )
332 #define _ISR_lock_Is_owner( _lock ) \
333 _SMP_lock_Is_owner( &( _lock )->Lock )
334 #else
335 #define _ISR_lock_Is_owner( _lock ) \
336 ( _ISR_Get_level() != 0 )
337 #endif
338#endif
339
340#if defined( RTEMS_PROFILING )
341 #define _ISR_lock_ISR_disable_profile( _context ) \
342 ( _context )->ISR_disable_instant = _CPU_Counter_read();
343#else
344 #define _ISR_lock_ISR_disable_profile( _context )
345#endif
346
357#if defined( RTEMS_SMP )
358 #define _ISR_lock_ISR_disable( _context ) \
359 do { \
360 _ISR_Local_disable( ( _context )->Lock_context.isr_level ); \
361 _ISR_lock_ISR_disable_profile( _context ) \
362 } while ( 0 )
363#else
364 #define _ISR_lock_ISR_disable( _context ) \
365 do { \
366 _ISR_Local_disable( ( _context )->isr_level ); \
367 _ISR_lock_ISR_disable_profile( _context ) \
368 } while ( 0 )
369#endif
370
381#if defined( RTEMS_SMP )
382 #define _ISR_lock_ISR_enable( _context ) \
383 _ISR_Local_enable( ( _context )->Lock_context.isr_level )
384#else
385 #define _ISR_lock_ISR_enable( _context ) \
386 _ISR_Local_enable( ( _context )->isr_level )
387#endif
388
391#ifdef __cplusplus
392}
393#endif
394
395#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:94