[4c90eb4] | 1 | /** |
---|
| 2 | * @file |
---|
[5f9b3db] | 3 | * |
---|
[4c90eb4] | 4 | * @brief Create a Period |
---|
| 5 | * @ingroup ClassicRateMon Rate Monotonic Scheduler |
---|
| 6 | */ |
---|
| 7 | |
---|
| 8 | /* |
---|
[e1bce86] | 9 | * COPYRIGHT (c) 1989-2007. |
---|
[5f9b3db] | 10 | * On-Line Applications Research Corporation (OAR). |
---|
| 11 | * |
---|
| 12 | * The license and distribution terms for this file may be |
---|
| 13 | * found in the file LICENSE in this distribution or at |
---|
[c499856] | 14 | * http://www.rtems.org/license/LICENSE. |
---|
[5f9b3db] | 15 | */ |
---|
| 16 | |
---|
[1095ec1] | 17 | #if HAVE_CONFIG_H |
---|
| 18 | #include "config.h" |
---|
| 19 | #endif |
---|
| 20 | |
---|
[5f9b3db] | 21 | #include <rtems/system.h> |
---|
| 22 | #include <rtems/rtems/status.h> |
---|
| 23 | #include <rtems/rtems/support.h> |
---|
| 24 | #include <rtems/score/isr.h> |
---|
[ecdcf01] | 25 | #include <rtems/rtems/ratemonimpl.h> |
---|
[5f9b3db] | 26 | #include <rtems/score/thread.h> |
---|
[4b48ece0] | 27 | #include <rtems/score/watchdogimpl.h> |
---|
[5f9b3db] | 28 | |
---|
[64adc13] | 29 | /* |
---|
[5f9b3db] | 30 | * rtems_rate_monotonic_create |
---|
| 31 | * |
---|
| 32 | * This directive creates a rate monotonic timer and performs |
---|
| 33 | * some initialization. |
---|
| 34 | * |
---|
| 35 | * Input parameters: |
---|
| 36 | * name - name of period |
---|
| 37 | * id - pointer to rate monotonic id |
---|
| 38 | * |
---|
| 39 | * Output parameters: |
---|
[e980b219] | 40 | * id - rate monotonic id |
---|
[5f9b3db] | 41 | * RTEMS_SUCCESSFUL - if successful |
---|
[e980b219] | 42 | * error code - if unsuccessful |
---|
[5f9b3db] | 43 | */ |
---|
| 44 | |
---|
| 45 | rtems_status_code rtems_rate_monotonic_create( |
---|
[d3b72ca3] | 46 | rtems_name name, |
---|
| 47 | rtems_id *id |
---|
[5f9b3db] | 48 | ) |
---|
| 49 | { |
---|
| 50 | Rate_monotonic_Control *the_period; |
---|
| 51 | |
---|
| 52 | if ( !rtems_is_name_valid( name ) ) |
---|
| 53 | return RTEMS_INVALID_NAME; |
---|
| 54 | |
---|
[e980b219] | 55 | if ( !id ) |
---|
| 56 | return RTEMS_INVALID_ADDRESS; |
---|
| 57 | |
---|
[5f9b3db] | 58 | the_period = _Rate_monotonic_Allocate(); |
---|
| 59 | |
---|
| 60 | if ( !the_period ) { |
---|
[23fec9f0] | 61 | _Objects_Allocator_unlock(); |
---|
[5f9b3db] | 62 | return RTEMS_TOO_MANY; |
---|
| 63 | } |
---|
| 64 | |
---|
[ee0e4135] | 65 | _ISR_lock_Initialize( &the_period->Lock, "Rate Monotonic Period" ); |
---|
[300f6a48] | 66 | _Priority_Node_initialize( &the_period->Priority, 0 ); |
---|
| 67 | _Priority_Node_set_inactive( &the_period->Priority ); |
---|
[ee0e4135] | 68 | |
---|
[23fec9f0] | 69 | the_period->owner = _Thread_Get_executing(); |
---|
[5f9b3db] | 70 | the_period->state = RATE_MONOTONIC_INACTIVE; |
---|
| 71 | |
---|
[03b900d] | 72 | _Watchdog_Preinitialize( &the_period->Timer, _Per_CPU_Get_by_index( 0 ) ); |
---|
| 73 | _Watchdog_Initialize( &the_period->Timer, _Rate_monotonic_Timeout ); |
---|
[f3b7be3] | 74 | |
---|
[e1bce86] | 75 | _Rate_monotonic_Reset_statistics( the_period ); |
---|
| 76 | |
---|
[6312db3] | 77 | _Objects_Open( |
---|
| 78 | &_Rate_monotonic_Information, |
---|
| 79 | &the_period->Object, |
---|
| 80 | (Objects_Name) name |
---|
| 81 | ); |
---|
[5f9b3db] | 82 | |
---|
| 83 | *id = the_period->Object.id; |
---|
[23fec9f0] | 84 | _Objects_Allocator_unlock(); |
---|
[5f9b3db] | 85 | return RTEMS_SUCCESSFUL; |
---|
| 86 | } |
---|