RTEMS
percpustatewait.c
1 /*
2  * Copyright (c) 2014 embedded brains GmbH. All rights reserved.
3  *
4  * embedded brains GmbH
5  * Dornierstr. 4
6  * 82178 Puchheim
7  * Germany
8  * <rtems@embedded-brains.de>
9  *
10  * The license and distribution terms for this file may be
11  * found in the file LICENSE in this distribution or at
12  * http://www.rtems.org/license/LICENSE.
13  */
14 
15 #ifdef HAVE_CONFIG_H
16 #include "config.h"
17 #endif
18 
19 #include <rtems/score/percpu.h>
20 #include <rtems/counter.h>
21 
23  uint32_t cpu_index,
24  uint32_t timeout_in_ns
25 )
26 {
27  const Per_CPU_Control *cpu = _Per_CPU_Get_by_index( cpu_index );
28  Per_CPU_State state = cpu->state;
29 
30  if ( timeout_in_ns > 0 ) {
31  rtems_counter_ticks ticks =
32  rtems_counter_nanoseconds_to_ticks( timeout_in_ns );
34  rtems_counter_ticks delta = 0;
35 
36  while ( ticks > delta && state == PER_CPU_STATE_INITIAL ) {
38 
39  _CPU_SMP_Processor_event_receive();
40  state = cpu->state;
41 
42  ticks -= delta;
43 
44  b = rtems_counter_read();
45  delta = rtems_counter_difference( b, a );
46  a = b;
47  }
48  } else {
49  while ( state == PER_CPU_STATE_INITIAL ) {
50  _CPU_SMP_Processor_event_receive();
51  state = cpu->state;
52  }
53  }
54 
55  return state != PER_CPU_STATE_INITIAL;
56 }
The per CPU controls are initialized to zero.
Definition: percpu.h:137
bool _Per_CPU_State_wait_for_non_initial_state(uint32_t cpu_index, uint32_t timeout_in_ns)
Waits for a processor to change into a non-initial state.
static rtems_counter_ticks rtems_counter_read(void)
Reads the current counter value.
Definition: counter.h:79
rtems_counter_ticks rtems_counter_nanoseconds_to_ticks(uint32_t nanoseconds)
Converts nanoseconds into counter ticks.
Per CPU Core Structure.
Definition: percpu.h:347
Free-Running Counter and Busy Wait Delay API.
Per_CPU_State state
Indicates the current state of the CPU.
Definition: percpu.h:552
Per_CPU_State
State of a processor.
Definition: percpu.h:128
static rtems_counter_ticks rtems_counter_difference(rtems_counter_ticks second, rtems_counter_ticks first)
Returns the difference between the second and first CPU counter value.
Definition: counter.h:96
CPU_Counter_ticks rtems_counter_ticks
Unsigned integer type for counter values.
Definition: counter.h:62