1 | /* SPDX-License-Identifier: BSD-2-Clause */ |
---|
2 | |
---|
3 | /** |
---|
4 | * @file |
---|
5 | * |
---|
6 | * @brief Inlined Routines from the POSIX Timer Manager |
---|
7 | * |
---|
8 | * This file contains the static inline implementation of the inlined routines |
---|
9 | * from the POSIX Timer Manager. |
---|
10 | */ |
---|
11 | |
---|
12 | /* |
---|
13 | * COPYRIGHT (c) 1989-2013. |
---|
14 | * On-Line Applications Research Corporation (OAR). |
---|
15 | * |
---|
16 | * Redistribution and use in source and binary forms, with or without |
---|
17 | * modification, are permitted provided that the following conditions |
---|
18 | * are met: |
---|
19 | * 1. Redistributions of source code must retain the above copyright |
---|
20 | * notice, this list of conditions and the following disclaimer. |
---|
21 | * 2. Redistributions in binary form must reproduce the above copyright |
---|
22 | * notice, this list of conditions and the following disclaimer in the |
---|
23 | * documentation and/or other materials provided with the distribution. |
---|
24 | * |
---|
25 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" |
---|
26 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
---|
27 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE |
---|
28 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE |
---|
29 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR |
---|
30 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF |
---|
31 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS |
---|
32 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN |
---|
33 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) |
---|
34 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE |
---|
35 | * POSSIBILITY OF SUCH DAMAGE. |
---|
36 | */ |
---|
37 | |
---|
38 | #ifndef _RTEMS_POSIX_TIMERIMPL_H |
---|
39 | #define _RTEMS_POSIX_TIMERIMPL_H |
---|
40 | |
---|
41 | #include <rtems/posix/timer.h> |
---|
42 | #include <rtems/score/objectimpl.h> |
---|
43 | #include <rtems/score/watchdogimpl.h> |
---|
44 | |
---|
45 | #ifdef __cplusplus |
---|
46 | extern "C" { |
---|
47 | #endif |
---|
48 | |
---|
49 | /** Timer is free */ |
---|
50 | #define POSIX_TIMER_STATE_FREE 0x01 |
---|
51 | |
---|
52 | /** Created timer but not running */ |
---|
53 | #define POSIX_TIMER_STATE_CREATE_NEW 0x02 |
---|
54 | |
---|
55 | /** Created timer and running */ |
---|
56 | #define POSIX_TIMER_STATE_CREATE_RUN 0x03 |
---|
57 | |
---|
58 | /** Created, ran and stopped timer */ |
---|
59 | #define POSIX_TIMER_STATE_CREATE_STOP 0x04 |
---|
60 | |
---|
61 | /** Indicates that the fire time is relative to the current one */ |
---|
62 | #define POSIX_TIMER_RELATIVE 0 |
---|
63 | |
---|
64 | /* |
---|
65 | * POSIX defines TIMER_ABSTIME but no constant for relative. So |
---|
66 | * we have one internally but we need to be careful it has a different |
---|
67 | * value. |
---|
68 | */ |
---|
69 | #if (POSIX_TIMER_RELATIVE == TIMER_ABSTIME) |
---|
70 | #error "POSIX_TIMER_RELATIVE == TIMER_ABSTIME" |
---|
71 | #endif |
---|
72 | |
---|
73 | /** |
---|
74 | * @brief POSIX Timer Allocate |
---|
75 | * |
---|
76 | * This function allocates a timer control block from |
---|
77 | * the inactive chain of free timer control blocks. |
---|
78 | */ |
---|
79 | RTEMS_INLINE_ROUTINE POSIX_Timer_Control *_POSIX_Timer_Allocate( void ) |
---|
80 | { |
---|
81 | return (POSIX_Timer_Control *) _Objects_Allocate( &_POSIX_Timer_Information ); |
---|
82 | } |
---|
83 | |
---|
84 | /** |
---|
85 | * @brief POSIX Timer Free |
---|
86 | * |
---|
87 | * This routine frees a timer control block to the |
---|
88 | * inactive chain of free timer control blocks. |
---|
89 | */ |
---|
90 | RTEMS_INLINE_ROUTINE void _POSIX_Timer_Free ( |
---|
91 | POSIX_Timer_Control *the_timer |
---|
92 | ) |
---|
93 | { |
---|
94 | _Objects_Free( &_POSIX_Timer_Information, &the_timer->Object ); |
---|
95 | } |
---|
96 | |
---|
97 | void _POSIX_Timer_TSR( Watchdog_Control *the_watchdog ); |
---|
98 | |
---|
99 | /** |
---|
100 | * @brief POSIX Timer Get |
---|
101 | * |
---|
102 | * This function maps timer IDs to timer control blocks. |
---|
103 | * If ID corresponds to a local timer, then it returns |
---|
104 | * the timer control pointer which maps to ID and location |
---|
105 | * is set to OBJECTS_LOCAL. Otherwise, location is set |
---|
106 | * to OBJECTS_ERROR and the returned value is undefined. |
---|
107 | */ |
---|
108 | RTEMS_INLINE_ROUTINE POSIX_Timer_Control *_POSIX_Timer_Get ( |
---|
109 | timer_t id, |
---|
110 | ISR_lock_Context *lock_context |
---|
111 | ) |
---|
112 | { |
---|
113 | return (POSIX_Timer_Control *) _Objects_Get( |
---|
114 | (Objects_Id) id, |
---|
115 | lock_context, |
---|
116 | &_POSIX_Timer_Information |
---|
117 | ); |
---|
118 | } |
---|
119 | |
---|
120 | RTEMS_INLINE_ROUTINE Per_CPU_Control *_POSIX_Timer_Acquire_critical( |
---|
121 | POSIX_Timer_Control *ptimer, |
---|
122 | ISR_lock_Context *lock_context |
---|
123 | ) |
---|
124 | { |
---|
125 | Per_CPU_Control *cpu; |
---|
126 | |
---|
127 | cpu = _Watchdog_Get_CPU( &ptimer->Timer ); |
---|
128 | _Watchdog_Per_CPU_acquire_critical( cpu, lock_context ); |
---|
129 | |
---|
130 | return cpu; |
---|
131 | } |
---|
132 | |
---|
133 | RTEMS_INLINE_ROUTINE void _POSIX_Timer_Release( |
---|
134 | Per_CPU_Control *cpu, |
---|
135 | ISR_lock_Context *lock_context |
---|
136 | ) |
---|
137 | { |
---|
138 | _Watchdog_Per_CPU_release_critical( cpu, lock_context ); |
---|
139 | _ISR_lock_ISR_enable( lock_context ); |
---|
140 | } |
---|
141 | |
---|
142 | #ifdef __cplusplus |
---|
143 | } |
---|
144 | #endif |
---|
145 | |
---|
146 | #endif |
---|
147 | /* end of include file */ |
---|