OpenCores
URL https://opencores.org/ocsvn/openrisc_2011-10-31/openrisc_2011-10-31/trunk

Subversion Repositories openrisc_2011-10-31

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

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:38 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
#define CONFIGURE_MAXIMUM_TASKS             2
16
#define CONFIGURE_MAXIMUM_SEMAPHORES        2
17
 
18
#define CONFIGURE_INIT
19
 
20
#include <confdefs.h>
21
 
22
#include <rtems/error.h>
23
#include <stdio.h>
24
 
25
rtems_interval ticksPerSecond;
26
 
27
rtems_task
28
subtask (rtems_task_argument arg)
29
{
30
        rtems_status_code sc;
31
        rtems_id sem = (rtems_id)arg;
32
 
33
        for (;;) {
34
                rtems_task_wake_after (ticksPerSecond * 2);
35
 
36
                sc = rtems_semaphore_release (sem);
37
                if (sc != RTEMS_SUCCESSFUL)
38
                        printf ("%d: Can't release semaphore: %s\n", __LINE__, rtems_status_text (sc));
39
        }
40
}
41
 
42
void
43
startTask (rtems_id arg)
44
{
45
        rtems_id tid;
46
        rtems_status_code sc;
47
 
48
        sc = rtems_task_create (rtems_build_name ('S', 'R', 'V', 'A'),
49
                100,
50
                10000,
51
                RTEMS_PREEMPT|RTEMS_NO_TIMESLICE|RTEMS_NO_ASR|RTEMS_INTERRUPT_LEVEL(0),
52
                RTEMS_NO_FLOATING_POINT|RTEMS_LOCAL,
53
                &tid);
54
        if (sc != RTEMS_SUCCESSFUL) {
55
                printf ("Can't create task: %s\n", rtems_status_text (sc));
56
                rtems_task_suspend (RTEMS_SELF);
57
        }
58
        sc = rtems_task_start (tid, subtask, arg);
59
        if (sc != RTEMS_SUCCESSFUL) {
60
                printf ("Can't start task: %s\n", rtems_status_text (sc));
61
                rtems_task_suspend (RTEMS_SELF);
62
        }
63
}
64
 
65
rtems_task Init (rtems_task_argument ignored)
66
{
67
        int i;
68
        rtems_id semrec, semnorec;
69
        rtems_status_code sc;
70
        rtems_interval then, now;
71
 
72
        puts( "*** SP29 - SIMPLE SEMAPHORE TEST ***" );
73
        puts( "This test only prints on errors." );
74
 
75
        sc = rtems_clock_get (RTEMS_CLOCK_GET_TICKS_PER_SECOND, &ticksPerSecond);
76
        if (sc != RTEMS_SUCCESSFUL) {
77
                printf ("Can't get ticks per second: %s\n", rtems_status_text (sc));
78
                exit (1);
79
        }
80
        sc = rtems_semaphore_create (rtems_build_name ('S', 'M', 'r', 'c'),
81
                1,
82
                RTEMS_PRIORITY|RTEMS_BINARY_SEMAPHORE|RTEMS_INHERIT_PRIORITY |RTEMS_NO_PRIORITY_CEILING|RTEMS_LOCAL,
83
                0,
84
                &semrec);
85
        if (sc != RTEMS_SUCCESSFUL) {
86
                printf ("%d: Can't create recursive-lock semaphore: %s\n", __LINE__, rtems_status_text (sc));
87
                exit (1);
88
        }
89
        sc = rtems_semaphore_create (rtems_build_name ('S', 'M', 'n', 'c'),
90
                1,
91
                RTEMS_PRIORITY|RTEMS_SIMPLE_BINARY_SEMAPHORE|RTEMS_INHERIT_PRIORITY |RTEMS_NO_PRIORITY_CEILING|RTEMS_LOCAL,
92
                0,
93
                &semnorec);
94
        if (sc != RTEMS_SUCCESSFUL) {
95
                printf ("%d: Can't create non-recursive-lock semaphore: %s\n", __LINE__, rtems_status_text (sc));
96
                exit (1);
97
        }
98
 
99
        sc = rtems_semaphore_obtain (semrec, RTEMS_NO_WAIT, 0);
100
        if (sc != RTEMS_SUCCESSFUL) {
101
                printf ("%d: Can't obtain recursive-lock semaphore: %s\n", __LINE__, rtems_status_text (sc));
102
        }
103
        sc = rtems_semaphore_obtain (semrec, RTEMS_NO_WAIT, 0);
104
        if (sc != RTEMS_SUCCESSFUL) {
105
                printf ("%d: Can't reobtain recursive-lock semaphore: %s\n", __LINE__, rtems_status_text (sc));
106
        }
107
 
108
        sc = rtems_semaphore_obtain (semnorec, RTEMS_NO_WAIT, 0);
109
        if (sc != RTEMS_SUCCESSFUL) {
110
                printf ("%d: Can't obtain non-recursive-lock semaphore: %s\n", __LINE__, rtems_status_text (sc));
111
        }
112
        sc = rtems_semaphore_obtain (semnorec, RTEMS_NO_WAIT, 0);
113
        if (sc == RTEMS_SUCCESSFUL) {
114
                printf ("%d: Reobtain non-recursive-lock semaphore -- and should not have.\n", __LINE__);
115
        }
116
 
117
        sc = rtems_semaphore_release (semnorec);
118
        if (sc != RTEMS_SUCCESSFUL) {
119
                printf ("%d: Can't release non-recursive-lock semaphore: %s\n", __LINE__, rtems_status_text (sc));
120
        }
121
        sc = rtems_semaphore_release (semnorec);
122
        if (sc != RTEMS_SUCCESSFUL) {
123
                printf ("%d: Can't rerelease non-recursive-lock semaphore: %s\n", __LINE__, rtems_status_text (sc));
124
        }
125
        sc = rtems_semaphore_obtain (semnorec, RTEMS_NO_WAIT, 0);
126
        if (sc != RTEMS_SUCCESSFUL) {
127
                printf ("%d: Can't obtain non-recursive-lock semaphore: %s\n", __LINE__, rtems_status_text (sc));
128
        }
129
        sc = rtems_semaphore_obtain (semnorec, RTEMS_NO_WAIT, 0);
130
        if (sc == RTEMS_SUCCESSFUL) {
131
                printf ("%d: Reobtain non-recursive-lock semaphore -- and should not have.\n", __LINE__);
132
        }
133
        else if (sc != RTEMS_UNSATISFIED) {
134
                printf ("%d: Reobtain non-recursive-lock semaphore failed, but error is %d (%s), not RTEMS_UNSATISFIED.\n", __LINE__, sc, rtems_status_text (sc));
135
        }
136
 
137
        sc = rtems_semaphore_release (semnorec);
138
        if (sc != RTEMS_SUCCESSFUL) {
139
                printf ("%d: Can't release non-recursive-lock semaphore: %s\n", __LINE__, rtems_status_text (sc));
140
        }
141
        sc = rtems_semaphore_release (semnorec);
142
        if (sc != RTEMS_SUCCESSFUL) {
143
                printf ("%d: Can't rerelease non-recursive-lock semaphore: %s\n", __LINE__, rtems_status_text (sc));
144
        }
145
        sc = rtems_semaphore_obtain (semnorec, RTEMS_NO_WAIT, 0);
146
        if (sc != RTEMS_SUCCESSFUL) {
147
                printf ("%d: Can't obtain non-recursive-lock semaphore: %s\n", __LINE__, rtems_status_text (sc));
148
        }
149
        /*
150
         *  Since this task is holding this, this task will block and timeout.
151
         *  Then the timeout error will be returned.
152
         */
153
        rtems_clock_get (RTEMS_CLOCK_GET_TICKS_SINCE_BOOT, &then);
154
        sc = rtems_semaphore_obtain (semnorec, RTEMS_WAIT, 5);
155
        rtems_clock_get (RTEMS_CLOCK_GET_TICKS_SINCE_BOOT, &now);
156
        if (sc == RTEMS_SUCCESSFUL) {
157
                printf ("%d: Reobtain non-recursive-lock semaphore -- and should not have.\n", __LINE__);
158
        }
159
        else if (sc != RTEMS_TIMEOUT) {
160
                printf ("%d: Reobtain non-recursive-lock semaphore failed, but error is %d (%s), not RTEMS_TIMEOUT.\n", __LINE__, sc, rtems_status_text (sc));
161
        }
162
        if ((then - now) < 4)
163
                printf ("%d: Reobtain non-recursive-lock semaphore failed without timeout.\n", __LINE__);
164
 
165
        startTask (semnorec);
166
        rtems_clock_get (RTEMS_CLOCK_GET_TICKS_SINCE_BOOT, &then);
167
        for (i = 0 ; i < 5 ; i++) {
168
                int diff;
169
 
170
                sc = rtems_semaphore_obtain (semnorec, RTEMS_WAIT, RTEMS_NO_TIMEOUT);
171
                rtems_clock_get (RTEMS_CLOCK_GET_TICKS_SINCE_BOOT, &now);
172
                diff = now - then;
173
                then = now;
174
                if (sc != RTEMS_SUCCESSFUL)
175
                        printf ("%d: Failed to obtain non-recursive-lock semaphore: %s\n", __LINE__, rtems_status_text (sc));
176
                else if (diff < (2 * ticksPerSecond))
177
                        printf ("%d: Obtained obtain non-recursive-lock semaphore too quickly -- %d ticks not %d ticks\n", __LINE__, diff, (2 * ticksPerSecond) );
178
        }
179
 
180
        puts( "*** END OF SP29 ***" );
181
        exit (0);
182
}

powered by: WebSVN 2.1.0

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