[c4fb617] | 1 | /* SPDX-License-Identifier: BSD-2-Clause */ |
---|
| 2 | |
---|
[52adc808] | 3 | /** |
---|
[6b5f22dc] | 4 | * @file |
---|
[5f9b3db] | 5 | * |
---|
[6b5f22dc] | 6 | * @ingroup RTEMSImplClassicRateMonotonic |
---|
| 7 | * |
---|
| 8 | * @brief This source file contains the implementation of |
---|
| 9 | * _Rate_monotonic_Timeout(). |
---|
[52adc808] | 10 | */ |
---|
| 11 | |
---|
| 12 | /* |
---|
[94d9bee] | 13 | * COPYRIGHT (c) 1989-2009. |
---|
[5f9b3db] | 14 | * On-Line Applications Research Corporation (OAR). |
---|
| 15 | * |
---|
[0794197] | 16 | * COPYRIGHT (c) 2016-2017 Kuan-Hsun Chen. |
---|
[3a46b72] | 17 | * |
---|
[c4fb617] | 18 | * Redistribution and use in source and binary forms, with or without |
---|
| 19 | * modification, are permitted provided that the following conditions |
---|
| 20 | * are met: |
---|
| 21 | * 1. Redistributions of source code must retain the above copyright |
---|
| 22 | * notice, this list of conditions and the following disclaimer. |
---|
| 23 | * 2. Redistributions in binary form must reproduce the above copyright |
---|
| 24 | * notice, this list of conditions and the following disclaimer in the |
---|
| 25 | * documentation and/or other materials provided with the distribution. |
---|
| 26 | * |
---|
| 27 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" |
---|
| 28 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
---|
| 29 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE |
---|
| 30 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE |
---|
| 31 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR |
---|
| 32 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF |
---|
| 33 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS |
---|
| 34 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN |
---|
| 35 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) |
---|
| 36 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE |
---|
| 37 | * POSSIBILITY OF SUCH DAMAGE. |
---|
[5f9b3db] | 38 | */ |
---|
| 39 | |
---|
[80cf60e] | 40 | #ifdef HAVE_CONFIG_H |
---|
[1095ec1] | 41 | #include "config.h" |
---|
| 42 | #endif |
---|
| 43 | |
---|
[ecdcf01] | 44 | #include <rtems/rtems/ratemonimpl.h> |
---|
[5f9b3db] | 45 | |
---|
[1240aade] | 46 | static void _Rate_monotonic_Renew_deadline( |
---|
| 47 | Rate_monotonic_Control *the_period, |
---|
| 48 | ISR_lock_Context *lock_context |
---|
| 49 | ) |
---|
| 50 | { |
---|
| 51 | uint64_t deadline; |
---|
| 52 | |
---|
[0794197] | 53 | /* stay at 0xffffffff if postponed_jobs is going to overflow */ |
---|
| 54 | if ( the_period->postponed_jobs != UINT32_MAX ) { |
---|
| 55 | ++the_period->postponed_jobs; |
---|
| 56 | } |
---|
| 57 | |
---|
[1240aade] | 58 | the_period->state = RATE_MONOTONIC_EXPIRED; |
---|
| 59 | |
---|
[91ce012c] | 60 | deadline = _Watchdog_Per_CPU_insert_ticks( |
---|
[1240aade] | 61 | &the_period->Timer, |
---|
| 62 | _Per_CPU_Get(), |
---|
| 63 | the_period->next_length |
---|
| 64 | ); |
---|
| 65 | the_period->latest_deadline = deadline; |
---|
| 66 | |
---|
| 67 | _Rate_monotonic_Release( the_period, lock_context ); |
---|
| 68 | } |
---|
| 69 | |
---|
[90960bd] | 70 | void _Rate_monotonic_Timeout( Watchdog_Control *the_watchdog ) |
---|
[5f9b3db] | 71 | { |
---|
| 72 | Rate_monotonic_Control *the_period; |
---|
[90960bd] | 73 | Thread_Control *owner; |
---|
| 74 | ISR_lock_Context lock_context; |
---|
| 75 | Thread_Wait_flags wait_flags; |
---|
| 76 | |
---|
| 77 | the_period = RTEMS_CONTAINER_OF( the_watchdog, Rate_monotonic_Control, Timer ); |
---|
| 78 | owner = the_period->owner; |
---|
| 79 | |
---|
| 80 | _ISR_lock_ISR_disable( &lock_context ); |
---|
[ee0e4135] | 81 | _Rate_monotonic_Acquire_critical( the_period, &lock_context ); |
---|
[90960bd] | 82 | wait_flags = _Thread_Wait_flags_get( owner ); |
---|
| 83 | |
---|
| 84 | if ( |
---|
| 85 | ( wait_flags & THREAD_WAIT_CLASS_PERIOD ) != 0 |
---|
| 86 | && owner->Wait.return_argument == the_period |
---|
| 87 | ) { |
---|
| 88 | bool unblock; |
---|
| 89 | bool success; |
---|
| 90 | |
---|
| 91 | owner->Wait.return_argument = NULL; |
---|
| 92 | |
---|
[02987728] | 93 | success = _Thread_Wait_flags_try_change_release( |
---|
[90960bd] | 94 | owner, |
---|
| 95 | RATE_MONOTONIC_INTEND_TO_BLOCK, |
---|
[e429e97] | 96 | THREAD_WAIT_STATE_READY |
---|
[90960bd] | 97 | ); |
---|
| 98 | if ( success ) { |
---|
| 99 | unblock = false; |
---|
| 100 | } else { |
---|
| 101 | _Assert( _Thread_Wait_flags_get( owner ) == RATE_MONOTONIC_BLOCKED ); |
---|
[e429e97] | 102 | _Thread_Wait_flags_set( owner, THREAD_WAIT_STATE_READY ); |
---|
[90960bd] | 103 | unblock = true; |
---|
| 104 | } |
---|
| 105 | |
---|
| 106 | _Rate_monotonic_Restart( the_period, owner, &lock_context ); |
---|
| 107 | |
---|
| 108 | if ( unblock ) { |
---|
| 109 | _Thread_Unblock( owner ); |
---|
| 110 | } |
---|
[03b900d] | 111 | } else { |
---|
[0794197] | 112 | _Rate_monotonic_Renew_deadline( the_period, &lock_context ); |
---|
[5f9b3db] | 113 | } |
---|
| 114 | } |
---|