OpenCores
URL https://opencores.org/ocsvn/openrisc/openrisc/trunk

Subversion Repositories openrisc

[/] [openrisc/] [trunk/] [rtos/] [rtems/] [c/] [src/] [tests/] [sptests/] [sp27/] [init.c] - Blame information for rev 587

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 30 unneback
/*
2
 *  Test for rtems_semaphore_flush
3
 *
4
 *  $Id: init.c,v 1.2 2001-09-27 12:02:36 chris Exp $
5
 */
6
 
7
#include <bsp.h>
8
 
9
rtems_task Init (rtems_task_argument argument);
10
 
11
#define CONFIGURE_RTEMS_INIT_TASKS_TABLE
12
 
13
#define CONFIGURE_APPLICATION_NEEDS_CONSOLE_DRIVER
14
#define CONFIGURE_APPLICATION_NEEDS_CLOCK_DRIVER
15
 
16
#define CONFIGURE_MAXIMUM_TASKS               6
17
 
18
#define CONFIGURE_MICROSECONDS_PER_TICK       52429
19
 
20
#define CONFIGURE_INIT
21
 
22
#include <confdefs.h>
23
 
24
#include <rtems/error.h>
25
#include <stdio.h>
26
 
27
#define NTASK 4
28
 
29
rtems_id semaphore;
30
volatile int flags[NTASK];
31
 
32
rtems_task
33
subtask (rtems_task_argument arg)
34
{
35
  rtems_status_code sc;
36
 
37
  for (;;) {
38
    flags[arg]++;
39
    sc = rtems_semaphore_obtain (semaphore, RTEMS_WAIT, RTEMS_NO_TIMEOUT);
40
    if (sc == RTEMS_SUCCESSFUL)
41
      puts ("Obtained semaphore -- and should not have done so!");
42
    else if (sc != RTEMS_UNSATISFIED)
43
      printf ("Can't get semaphore: %s\n", rtems_status_text (sc));
44
  }
45
}
46
 
47
void
48
starttask (int arg)
49
{
50
  rtems_id tid;
51
  rtems_status_code sc;
52
  rtems_task_priority priority;
53
 
54
  rtems_task_set_priority (RTEMS_SELF, RTEMS_CURRENT_PRIORITY, &priority);
55
  sc = rtems_task_create (rtems_build_name ('S', 'R', 'V', arg + 'A'),
56
    priority,
57
    RTEMS_MINIMUM_STACK_SIZE,
58
    RTEMS_PREEMPT|RTEMS_NO_TIMESLICE|RTEMS_NO_ASR|RTEMS_INTERRUPT_LEVEL(0),
59
    RTEMS_NO_FLOATING_POINT|RTEMS_LOCAL,
60
    &tid);
61
  if (sc != RTEMS_SUCCESSFUL) {
62
    printf ("Can't create task: %s\n", rtems_status_text (sc));
63
    rtems_task_suspend (RTEMS_SELF);
64
  }
65
  sc = rtems_task_start (tid, subtask, arg);
66
  if (sc != RTEMS_SUCCESSFUL) {
67
        printf ("Can't start task: %s\n", rtems_status_text (sc));
68
    rtems_task_suspend (RTEMS_SELF);
69
  }
70
}
71
 
72
rtems_task
73
Init (rtems_task_argument ignored)
74
{
75
  int pass, i;
76
  rtems_status_code sc;
77
 
78
  puts("**** Semaphore flush test ****");
79
  sc = rtems_semaphore_create (
80
    rtems_build_name ('S', 'E', 'M', 'F'),
81
    0,
82
    RTEMS_LOCAL|RTEMS_BINARY_SEMAPHORE|RTEMS_NO_INHERIT_PRIORITY|RTEMS_NO_PRIORITY_CEILING|RTEMS_FIFO,
83
    0,
84
    &semaphore);
85
  if (sc != RTEMS_SUCCESSFUL) {
86
    printf ("Can't flush semaphore: %s\n", rtems_status_text (sc));
87
    exit (1);
88
  }
89
  for (i = 0 ; i < NTASK ; i++)
90
    starttask (i);
91
  for (pass = 1 ; pass < 10 ; pass++) {
92
    rtems_task_wake_after (1);
93
    for (i = 0 ; i < NTASK ; i++) {
94
      if (flags[i] != pass)
95
        printf ("flags[%d] = %d -- expected %d\n", i, flags[i], pass);
96
    }
97
    sc = rtems_semaphore_flush (semaphore);
98
    if (sc != RTEMS_SUCCESSFUL) {
99
      printf ("Can't flush semaphore: %s\n", rtems_status_text (sc));
100
      exit (1);
101
    }
102
  }
103
  puts ("**** Semaphore flush test succeeded ****");
104
  exit (1);
105
}

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.