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

Subversion Repositories openrisc

[/] [openrisc/] [trunk/] [rtos/] [rtems/] [c/] [src/] [tests/] [sptests/] [sp26/] [task1.c] - Blame information for rev 721

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

Line No. Rev Author Line
1 30 unneback
/*
2
 *  COPYRIGHT (c) 1989-1999.
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.OARcorp.com/rtems/license.html.
8
 *
9
 *  $Id: task1.c,v 1.2 2001-09-27 12:02:36 chris Exp $
10
 */
11
 
12
#include <stdio.h>
13
#include <rtems.h>
14
#include <rtems/error.h>
15
 
16
static rtems_id taskId1;
17
static rtems_id taskId2;
18
rtems_interval ticksPerSecond;
19
 
20
static int
21
isSuspended (rtems_id tid)
22
{
23
  rtems_status_code sc;
24
 
25
  sc = rtems_task_is_suspended (tid);
26
  if (sc == RTEMS_ALREADY_SUSPENDED)
27
    return 1;
28
  if (sc != RTEMS_SUCCESSFUL)
29
    printf ("rtems_task_is_suspended: %s\n", rtems_status_text (sc));
30
  return 0;
31
}
32
 
33
static void
34
subTask1 (rtems_task_argument arg)
35
{
36
  rtems_status_code sc;
37
 
38
  rtems_task_wake_after (ticksPerSecond * 3);
39
  sc = rtems_event_send (taskId2, 1);
40
  if (sc != RTEMS_SUCCESSFUL) {
41
    printf ("subTask1 - Can't send event (%d)\n", sc);
42
    rtems_task_suspend (RTEMS_SELF);
43
  }
44
  rtems_task_wake_after (ticksPerSecond * 3);
45
  printf ("subTask1 - Event sent\n");
46
  rtems_task_suspend (RTEMS_SELF);
47
  printf ("subTask1 - Back to task 1\n");
48
  rtems_task_wake_after (ticksPerSecond * 3);
49
  rtems_task_suspend (RTEMS_SELF);
50
}
51
 
52
static void
53
subTask2 (rtems_task_argument arg)
54
{
55
  rtems_status_code sc;
56
  rtems_event_set ev;
57
 
58
  rtems_task_wake_after (ticksPerSecond * 1);
59
  sc = rtems_event_receive (1, RTEMS_WAIT|RTEMS_EVENT_ANY, RTEMS_NO_TIMEOUT, &ev);
60
  if (sc != RTEMS_SUCCESSFUL) {
61
    printf ("subTask2 - Can't receive event (%d)\n", sc);
62
    rtems_task_suspend (RTEMS_SELF);
63
  }
64
  printf ("subTask2 - Task 1 suspended? - should be 0: %d\n",
65
     isSuspended (taskId1));
66
  rtems_task_wake_after (ticksPerSecond * 4);
67
  printf ("subTask2 - Task 1 suspended? - should be 1: %d\n",
68
     isSuspended (taskId1));
69
  rtems_task_resume (taskId1);
70
  printf ("subTask2 - Task 1 suspended? - should be 0: %d\n",
71
     isSuspended (taskId1));
72
  rtems_task_wake_after (ticksPerSecond * 4);
73
  printf ("subTask2 - Task 1 suspended? - should be 1: %d\n",
74
     isSuspended (taskId1));
75
 
76
  puts( "*** END OF TEST 26 ***" );
77
  exit( 0 );
78
}
79
 
80
static void
81
createTask (char c, rtems_id *tid)
82
{
83
  rtems_status_code sc;
84
 
85
  sc = rtems_task_create (rtems_build_name('S','u','b',c),
86
    100,
87
    RTEMS_MINIMUM_STACK_SIZE * 4,
88
    RTEMS_PREEMPT|RTEMS_NO_TIMESLICE|RTEMS_NO_ASR|RTEMS_INTERRUPT_LEVEL(0),
89
    RTEMS_NO_FLOATING_POINT|RTEMS_LOCAL,
90
    tid);
91
  if (sc != RTEMS_SUCCESSFUL) {
92
    printf ("Can't create task (%d)\n", sc);
93
    rtems_task_suspend (RTEMS_SELF);
94
  }
95
}
96
 
97
static void
98
startTask (rtems_id tid, rtems_task_entry entry_point)
99
{
100
  rtems_status_code sc;
101
 
102
  sc = rtems_task_start (tid, entry_point, 0);
103
  if (sc != RTEMS_SUCCESSFUL) {
104
    printf ("Can't start task (%d)\n", sc);
105
    rtems_task_suspend (RTEMS_SELF);
106
  }
107
}
108
 
109
void
110
task1 (void)
111
{
112
  rtems_clock_get (RTEMS_CLOCK_GET_TICKS_PER_SECOND, &ticksPerSecond);
113
  createTask ('1', &taskId1);
114
  createTask ('2', &taskId2);
115
  startTask (taskId1, subTask1);
116
  startTask (taskId2, subTask2);
117
  rtems_task_suspend (RTEMS_SELF);
118
}

powered by: WebSVN 2.1.0

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