diff options
author | Sebastian Huber <sebastian.huber@embedded-brains.de> | 2014-06-05 11:19:32 +0200 |
---|---|---|
committer | Sebastian Huber <sebastian.huber@embedded-brains.de> | 2014-06-05 14:55:16 +0200 |
commit | 9a1bab2525679abc75eb321f61e4b130f8801490 (patch) | |
tree | 01cbc61810dde5bbec4a80c26e41833902fde7b2 /cpukit/score/src/percpustatewait.c | |
parent | score: Avoid NULL pointer access (diff) | |
download | rtems-9a1bab2525679abc75eb321f61e4b130f8801490.tar.bz2 |
score: _Per_CPU_State_wait_for_non_initial_state()
Replace _Per_CPU_State_wait_for_ready_to_start_multitasking() with
_Per_CPU_State_wait_for_non_initial_state(). Implement this function.
Diffstat (limited to 'cpukit/score/src/percpustatewait.c')
-rw-r--r-- | cpukit/score/src/percpustatewait.c | 56 |
1 files changed, 56 insertions, 0 deletions
diff --git a/cpukit/score/src/percpustatewait.c b/cpukit/score/src/percpustatewait.c new file mode 100644 index 0000000000..bde367b698 --- /dev/null +++ b/cpukit/score/src/percpustatewait.c @@ -0,0 +1,56 @@ +/* + * Copyright (c) 2014 embedded brains GmbH. All rights reserved. + * + * embedded brains GmbH + * Dornierstr. 4 + * 82178 Puchheim + * Germany + * <rtems@embedded-brains.de> + * + * The license and distribution terms for this file may be + * found in the file LICENSE in this distribution or at + * http://www.rtems.org/license/LICENSE. + */ + +#if HAVE_CONFIG_H + #include "config.h" +#endif + +#include <rtems/score/percpu.h> +#include <rtems/counter.h> + +bool _Per_CPU_State_wait_for_non_initial_state( + uint32_t cpu_index, + uint32_t timeout_in_ns +) +{ + const Per_CPU_Control *cpu = _Per_CPU_Get_by_index( cpu_index ); + Per_CPU_State state = cpu->state; + + if ( timeout_in_ns > 0 ) { + rtems_counter_ticks ticks = + rtems_counter_nanoseconds_to_ticks( timeout_in_ns ); + rtems_counter_ticks a = rtems_counter_read(); + rtems_counter_ticks delta = 0; + + while ( ticks > delta && state == PER_CPU_STATE_INITIAL ) { + rtems_counter_ticks b; + + _CPU_SMP_Processor_event_receive(); + state = cpu->state; + + ticks -= delta; + + b = rtems_counter_read(); + delta = rtems_counter_difference( b, a ); + a = b; + } + } else { + while ( state == PER_CPU_STATE_INITIAL ) { + _CPU_SMP_Processor_event_receive(); + state = cpu->state; + } + } + + return state != PER_CPU_STATE_INITIAL; +} |