source: rtems/testsuites/smptests/smp03/init.c @ c499856

4.115
Last change on this file since c499856 was c499856, checked in by Chris Johns <chrisj@…>, on 03/20/14 at 21:10:47

Change all references of rtems.com to rtems.org.

  • Property mode set to 100644
File size: 2.4 KB
Line 
1/*
2 *  COPYRIGHT (c) 1989-2011.
3 *  On-Line Applications Research Corporation (OAR).
4 *
5 *  The license and distribution terms for this file may be
6 *  found in the file LICENSE in this distribution or at
7 *  http://www.rtems.org/license/LICENSE.
8 */
9
10#ifdef HAVE_CONFIG_H
11#include "config.h"
12#endif
13
14#define CONFIGURE_INIT
15#include "system.h"
16
17#include <stdio.h>
18#include <inttypes.h>
19
20const char rtems_test_name[] = "SMP 3";
21
22static void success(void)
23{
24  TEST_END();
25  rtems_test_exit( 0 );
26}
27
28void Loop() {
29  volatile int i;
30
31  for (i=0; i<300000; i++);
32}
33
34void PrintTaskInfo(
35  const char *task_name
36)
37{
38  uint32_t cpu_num;
39
40  cpu_num = rtems_smp_get_current_processor();
41
42  locked_printf("  CPU %" PRIu32 " running task %s\n", cpu_num, task_name );
43}
44
45rtems_task Init(
46  rtems_task_argument argument
47)
48{
49  uint32_t          i;
50  char              ch = '0';
51  rtems_id          id;
52  rtems_status_code status;
53
54  Loop();
55
56  TEST_BEGIN();
57
58  locked_print_initialize();
59
60  if ( rtems_smp_get_processor_count() == 1 ) {
61    success();
62  }
63
64  /* Initialize the TaskRan array */
65  TaskRan[0] = true;
66  for ( i=1; i<rtems_smp_get_processor_count() ; i++ ) {
67    TaskRan[i] = false;
68  }
69
70  /* Show that the init task is running on this cpu */
71  PrintTaskInfo( "Init" );
72
73  /* for each remaining cpu create and start a task */
74  for ( i=1; i < rtems_smp_get_processor_count(); i++ ){
75
76    ch = '0' + i;
77
78    status = rtems_task_create(
79      rtems_build_name( 'T', 'A', ch, ' ' ),
80      CONFIGURE_INIT_TASK_PRIORITY + (2*i),
81      RTEMS_MINIMUM_STACK_SIZE,
82      RTEMS_PREEMPT,
83      RTEMS_DEFAULT_ATTRIBUTES,
84      &id
85    );
86    status = rtems_task_start( id, Test_task, i );
87   
88    /* Allow task to start before starting next task.
89     * This is necessary on some simulators.
90     */
91    while (TaskRan[i] == false)
92      ;
93  }
94
95  /* Create/Start an aditional task with the highest priority */
96  status = rtems_task_create(
97    rtems_build_name( 'T', 'A', ch, ' ' ),
98    3,
99    RTEMS_MINIMUM_STACK_SIZE,
100    RTEMS_PREEMPT,
101    RTEMS_DEFAULT_ATTRIBUTES,
102    &id
103  );
104  status = rtems_task_start(id,Test_task,rtems_smp_get_processor_count());
105
106  /* Wait on all tasks to run */
107  while (1) {
108    TestFinished = true;
109    for ( i=1; i < (rtems_smp_get_processor_count()+1) ; i++ ) {
110      if (TaskRan[i] == false)
111        TestFinished = false;
112    }
113    if (TestFinished) {
114      success();
115    }
116  }
117
118  rtems_test_exit( 0 );   
119}
Note: See TracBrowser for help on using the repository browser.