[e90b1df] | 1 | /** |
---|
| 2 | * @file |
---|
| 3 | * |
---|
| 4 | * @ingroup ClassicTimerImpl |
---|
| 5 | * |
---|
| 6 | * @brief Classic Timer Implementation |
---|
| 7 | */ |
---|
| 8 | |
---|
| 9 | /* |
---|
| 10 | * COPYRIGHT (c) 1989-2011. |
---|
| 11 | * On-Line Applications Research Corporation (OAR). |
---|
| 12 | * |
---|
[03b900d] | 13 | * Copyright (c) 2016 embedded brains GmbH. |
---|
| 14 | * |
---|
[e90b1df] | 15 | * The license and distribution terms for this file may be |
---|
| 16 | * found in the file LICENSE in this distribution or at |
---|
[c499856] | 17 | * http://www.rtems.org/license/LICENSE. |
---|
[e90b1df] | 18 | */ |
---|
| 19 | |
---|
| 20 | #ifndef _RTEMS_RTEMS_TIMER_INL |
---|
| 21 | #define _RTEMS_RTEMS_TIMER_INL |
---|
| 22 | |
---|
[e1b7c188] | 23 | #include <rtems/rtems/timerdata.h> |
---|
[a2e3f33] | 24 | #include <rtems/score/objectimpl.h> |
---|
| 25 | #include <rtems/score/thread.h> |
---|
[54cf0e34] | 26 | #include <rtems/score/watchdogimpl.h> |
---|
[e90b1df] | 27 | |
---|
| 28 | #ifdef __cplusplus |
---|
| 29 | extern "C" { |
---|
| 30 | #endif |
---|
| 31 | |
---|
| 32 | /** |
---|
| 33 | * @defgroup ClassicTimerImpl Classic Timer Implementation |
---|
| 34 | * |
---|
| 35 | * @ingroup ClassicTimer |
---|
| 36 | * |
---|
| 37 | * @{ |
---|
| 38 | */ |
---|
| 39 | |
---|
[03b900d] | 40 | typedef struct Timer_server_Control { |
---|
| 41 | ISR_LOCK_MEMBER( Lock ) |
---|
[e90b1df] | 42 | |
---|
[03b900d] | 43 | Chain_Control Pending; |
---|
[e90b1df] | 44 | |
---|
[03b900d] | 45 | Objects_Id server_id; |
---|
| 46 | } Timer_server_Control; |
---|
[e90b1df] | 47 | |
---|
| 48 | /** |
---|
| 49 | * @brief Pointer to default timer server control block. |
---|
| 50 | * |
---|
| 51 | * This value is @c NULL when the default timer server is not initialized. |
---|
| 52 | */ |
---|
[26335844] | 53 | extern Timer_server_Control *volatile _Timer_server; |
---|
[e90b1df] | 54 | |
---|
| 55 | /** |
---|
| 56 | * @brief Timer_Allocate |
---|
| 57 | * |
---|
| 58 | * This function allocates a timer control block from |
---|
| 59 | * the inactive chain of free timer control blocks. |
---|
| 60 | */ |
---|
| 61 | RTEMS_INLINE_ROUTINE Timer_Control *_Timer_Allocate( void ) |
---|
| 62 | { |
---|
| 63 | return (Timer_Control *) _Objects_Allocate( &_Timer_Information ); |
---|
| 64 | } |
---|
| 65 | |
---|
| 66 | /** |
---|
| 67 | * @brief Timer_Free |
---|
| 68 | * |
---|
| 69 | * This routine frees a timer control block to the |
---|
| 70 | * inactive chain of free timer control blocks. |
---|
| 71 | */ |
---|
| 72 | RTEMS_INLINE_ROUTINE void _Timer_Free ( |
---|
| 73 | Timer_Control *the_timer |
---|
| 74 | ) |
---|
| 75 | { |
---|
| 76 | _Objects_Free( &_Timer_Information, &the_timer->Object ); |
---|
| 77 | } |
---|
| 78 | |
---|
[03b900d] | 79 | RTEMS_INLINE_ROUTINE Timer_Control *_Timer_Get( |
---|
[e90b1df] | 80 | Objects_Id id, |
---|
[03b900d] | 81 | ISR_lock_Context *lock_context |
---|
[e90b1df] | 82 | ) |
---|
| 83 | { |
---|
[582bb23c] | 84 | return (Timer_Control *) _Objects_Get( |
---|
[03b900d] | 85 | id, |
---|
[0a68d8e] | 86 | lock_context, |
---|
| 87 | &_Timer_Information |
---|
[03b900d] | 88 | ); |
---|
[e90b1df] | 89 | } |
---|
| 90 | |
---|
[03b900d] | 91 | RTEMS_INLINE_ROUTINE Per_CPU_Control *_Timer_Acquire_critical( |
---|
| 92 | Timer_Control *the_timer, |
---|
| 93 | ISR_lock_Context *lock_context |
---|
| 94 | ) |
---|
| 95 | { |
---|
| 96 | Per_CPU_Control *cpu; |
---|
| 97 | |
---|
| 98 | cpu = _Watchdog_Get_CPU( &the_timer->Ticker ); |
---|
| 99 | _Watchdog_Per_CPU_acquire_critical( cpu, lock_context ); |
---|
| 100 | |
---|
| 101 | return cpu; |
---|
| 102 | } |
---|
| 103 | |
---|
| 104 | RTEMS_INLINE_ROUTINE void _Timer_Release( |
---|
| 105 | Per_CPU_Control *cpu, |
---|
| 106 | ISR_lock_Context *lock_context |
---|
| 107 | ) |
---|
| 108 | { |
---|
| 109 | _Watchdog_Per_CPU_release_critical( cpu, lock_context ); |
---|
| 110 | _ISR_lock_ISR_enable( lock_context ); |
---|
| 111 | } |
---|
| 112 | |
---|
| 113 | RTEMS_INLINE_ROUTINE bool _Timer_Is_interval_class( |
---|
[e90b1df] | 114 | Timer_Classes the_class |
---|
| 115 | ) |
---|
| 116 | { |
---|
[03b900d] | 117 | Timer_Classes mask = |
---|
| 118 | TIMER_CLASS_BIT_NOT_DORMANT | TIMER_CLASS_BIT_TIME_OF_DAY; |
---|
| 119 | |
---|
| 120 | return ( the_class & mask ) == TIMER_CLASS_BIT_NOT_DORMANT; |
---|
[e90b1df] | 121 | } |
---|
| 122 | |
---|
[03b900d] | 123 | RTEMS_INLINE_ROUTINE bool _Timer_Is_on_task_class( |
---|
[e90b1df] | 124 | Timer_Classes the_class |
---|
| 125 | ) |
---|
| 126 | { |
---|
[03b900d] | 127 | Timer_Classes mask = |
---|
| 128 | TIMER_CLASS_BIT_NOT_DORMANT | TIMER_CLASS_BIT_ON_TASK; |
---|
| 129 | |
---|
| 130 | return ( the_class & mask ) == mask; |
---|
[e90b1df] | 131 | } |
---|
| 132 | |
---|
[03b900d] | 133 | RTEMS_INLINE_ROUTINE Per_CPU_Watchdog_index _Timer_Watchdog_header_index( |
---|
[e90b1df] | 134 | Timer_Classes the_class |
---|
| 135 | ) |
---|
| 136 | { |
---|
[03b900d] | 137 | return ( the_class & TIMER_CLASS_BIT_TIME_OF_DAY ); |
---|
| 138 | } |
---|
| 139 | |
---|
| 140 | RTEMS_INLINE_ROUTINE Watchdog_Interval _Timer_Get_CPU_ticks( |
---|
| 141 | const Per_CPU_Control *cpu |
---|
| 142 | ) |
---|
| 143 | { |
---|
| 144 | return (Watchdog_Interval) cpu->Watchdog.ticks; |
---|
[e90b1df] | 145 | } |
---|
| 146 | |
---|
[03b900d] | 147 | rtems_status_code _Timer_Fire( |
---|
| 148 | rtems_id id, |
---|
| 149 | rtems_interval interval, |
---|
| 150 | rtems_timer_service_routine_entry routine, |
---|
| 151 | void *user_data, |
---|
| 152 | Timer_Classes the_class, |
---|
| 153 | Watchdog_Service_routine_entry adaptor |
---|
| 154 | ); |
---|
| 155 | |
---|
| 156 | rtems_status_code _Timer_Fire_after( |
---|
| 157 | rtems_id id, |
---|
| 158 | rtems_interval ticks, |
---|
| 159 | rtems_timer_service_routine_entry routine, |
---|
| 160 | void *user_data, |
---|
| 161 | Timer_Classes the_class, |
---|
| 162 | Watchdog_Service_routine_entry adaptor |
---|
| 163 | ); |
---|
| 164 | |
---|
| 165 | rtems_status_code _Timer_Fire_when( |
---|
| 166 | rtems_id id, |
---|
| 167 | const rtems_time_of_day *wall_time, |
---|
| 168 | rtems_timer_service_routine_entry routine, |
---|
| 169 | void *user_data, |
---|
| 170 | Timer_Classes the_class, |
---|
| 171 | Watchdog_Service_routine_entry adaptor |
---|
| 172 | ); |
---|
| 173 | |
---|
| 174 | void _Timer_Cancel( Per_CPU_Control *cpu, Timer_Control *the_timer ); |
---|
| 175 | |
---|
| 176 | void _Timer_Routine_adaptor( Watchdog_Control *the_watchdog ); |
---|
| 177 | |
---|
| 178 | void _Timer_server_Routine_adaptor( Watchdog_Control *the_watchdog ); |
---|
| 179 | |
---|
| 180 | RTEMS_INLINE_ROUTINE void _Timer_server_Acquire_critical( |
---|
| 181 | Timer_server_Control *timer_server, |
---|
| 182 | ISR_lock_Context *lock_context |
---|
| 183 | ) |
---|
| 184 | { |
---|
| 185 | _ISR_lock_Acquire( &timer_server->Lock, lock_context ); |
---|
| 186 | } |
---|
| 187 | |
---|
| 188 | RTEMS_INLINE_ROUTINE void _Timer_server_Release_critical( |
---|
| 189 | Timer_server_Control *timer_server, |
---|
| 190 | ISR_lock_Context *lock_context |
---|
| 191 | ) |
---|
| 192 | { |
---|
| 193 | _ISR_lock_Release( &timer_server->Lock, lock_context ); |
---|
| 194 | } |
---|
[2903090] | 195 | |
---|
[e90b1df] | 196 | /**@}*/ |
---|
| 197 | |
---|
| 198 | #ifdef __cplusplus |
---|
| 199 | } |
---|
| 200 | #endif |
---|
| 201 | |
---|
| 202 | #endif |
---|
| 203 | /* end of include file */ |
---|