1 | /** |
---|
2 | * @file |
---|
3 | * |
---|
4 | * @brief Inlined Routines from the POSIX Timer Manager |
---|
5 | * |
---|
6 | * This file contains the static inline implementation of the inlined routines |
---|
7 | * from the POSIX Timer Manager. |
---|
8 | */ |
---|
9 | |
---|
10 | /* |
---|
11 | * COPYRIGHT (c) 1989-2013. |
---|
12 | * On-Line Applications Research Corporation (OAR). |
---|
13 | * |
---|
14 | * The license and distribution terms for this file may be |
---|
15 | * found in the file LICENSE in this distribution or at |
---|
16 | * http://www.rtems.org/license/LICENSE. |
---|
17 | */ |
---|
18 | |
---|
19 | #ifndef _RTEMS_POSIX_TIMERIMPL_H |
---|
20 | #define _RTEMS_POSIX_TIMERIMPL_H |
---|
21 | |
---|
22 | #include <rtems/posix/timer.h> |
---|
23 | #include <rtems/score/objectimpl.h> |
---|
24 | #include <rtems/score/watchdogimpl.h> |
---|
25 | |
---|
26 | #ifdef __cplusplus |
---|
27 | extern "C" { |
---|
28 | #endif |
---|
29 | |
---|
30 | /** Timer is free */ |
---|
31 | #define POSIX_TIMER_STATE_FREE 0x01 |
---|
32 | |
---|
33 | /** Created timer but not running */ |
---|
34 | #define POSIX_TIMER_STATE_CREATE_NEW 0x02 |
---|
35 | |
---|
36 | /** Created timer and running */ |
---|
37 | #define POSIX_TIMER_STATE_CREATE_RUN 0x03 |
---|
38 | |
---|
39 | /** Created, ran and stopped timer */ |
---|
40 | #define POSIX_TIMER_STATE_CREATE_STOP 0x04 |
---|
41 | |
---|
42 | /** Indicates that the fire time is relative to the current one */ |
---|
43 | #define POSIX_TIMER_RELATIVE 0 |
---|
44 | |
---|
45 | /* |
---|
46 | * POSIX defines TIMER_ABSTIME but no constant for relative. So |
---|
47 | * we have one internally but we need to be careful it has a different |
---|
48 | * value. |
---|
49 | */ |
---|
50 | #if (POSIX_TIMER_RELATIVE == TIMER_ABSTIME) |
---|
51 | #error "POSIX_TIMER_RELATIVE == TIMER_ABSTIME" |
---|
52 | #endif |
---|
53 | |
---|
54 | /** |
---|
55 | * The following defines the information control block used to manage |
---|
56 | * this class of objects. |
---|
57 | */ |
---|
58 | extern Objects_Information _POSIX_Timer_Information; |
---|
59 | |
---|
60 | /** |
---|
61 | * @brief POSIX Timer Allocate |
---|
62 | * |
---|
63 | * This function allocates a timer control block from |
---|
64 | * the inactive chain of free timer control blocks. |
---|
65 | */ |
---|
66 | RTEMS_INLINE_ROUTINE POSIX_Timer_Control *_POSIX_Timer_Allocate( void ) |
---|
67 | { |
---|
68 | return (POSIX_Timer_Control *) _Objects_Allocate( &_POSIX_Timer_Information ); |
---|
69 | } |
---|
70 | |
---|
71 | /** |
---|
72 | * @brief POSIX Timer Free |
---|
73 | * |
---|
74 | * This routine frees a timer control block to the |
---|
75 | * inactive chain of free timer control blocks. |
---|
76 | */ |
---|
77 | RTEMS_INLINE_ROUTINE void _POSIX_Timer_Free ( |
---|
78 | POSIX_Timer_Control *the_timer |
---|
79 | ) |
---|
80 | { |
---|
81 | _Objects_Free( &_POSIX_Timer_Information, &the_timer->Object ); |
---|
82 | } |
---|
83 | |
---|
84 | void _POSIX_Timer_TSR( Watchdog_Control *the_watchdog ); |
---|
85 | |
---|
86 | /** |
---|
87 | * @brief POSIX Timer Get |
---|
88 | * |
---|
89 | * This function maps timer IDs to timer control blocks. |
---|
90 | * If ID corresponds to a local timer, then it returns |
---|
91 | * the timer control pointer which maps to ID and location |
---|
92 | * is set to OBJECTS_LOCAL. Otherwise, location is set |
---|
93 | * to OBJECTS_ERROR and the returned value is undefined. |
---|
94 | */ |
---|
95 | RTEMS_INLINE_ROUTINE POSIX_Timer_Control *_POSIX_Timer_Get ( |
---|
96 | timer_t id, |
---|
97 | ISR_lock_Context *lock_context |
---|
98 | ) |
---|
99 | { |
---|
100 | return (POSIX_Timer_Control *) _Objects_Get_local( |
---|
101 | &_POSIX_Timer_Information, |
---|
102 | (Objects_Id) id, |
---|
103 | lock_context |
---|
104 | ); |
---|
105 | } |
---|
106 | |
---|
107 | RTEMS_INLINE_ROUTINE Per_CPU_Control *_POSIX_Timer_Acquire_critical( |
---|
108 | POSIX_Timer_Control *ptimer, |
---|
109 | ISR_lock_Context *lock_context |
---|
110 | ) |
---|
111 | { |
---|
112 | Per_CPU_Control *cpu; |
---|
113 | |
---|
114 | cpu = _Watchdog_Get_CPU( &ptimer->Timer ); |
---|
115 | _Watchdog_Per_CPU_acquire_critical( cpu, lock_context ); |
---|
116 | |
---|
117 | return cpu; |
---|
118 | } |
---|
119 | |
---|
120 | RTEMS_INLINE_ROUTINE void _POSIX_Timer_Release( |
---|
121 | Per_CPU_Control *cpu, |
---|
122 | ISR_lock_Context *lock_context |
---|
123 | ) |
---|
124 | { |
---|
125 | _Watchdog_Per_CPU_release_critical( cpu, lock_context ); |
---|
126 | _ISR_lock_ISR_enable( lock_context ); |
---|
127 | } |
---|
128 | |
---|
129 | #ifdef __cplusplus |
---|
130 | } |
---|
131 | #endif |
---|
132 | |
---|
133 | #endif |
---|
134 | /* end of include file */ |
---|