source: rtems/testsuites/sptests/sp26/task1.c @ b84f1fdc

4.104.11
Last change on this file since b84f1fdc was b84f1fdc, checked in by Joel Sherrill <joel.sherrill@…>, on May 10, 2009 at 2:39:46 PM

2009-05-10 Joel Sherrill <joel.sherrill@…>

  • sp04/system.h, sp04/task1.c, sp04/tswitch.c, sp07/init.c, sp12/init.c, sp13/putbuff.c, sp13/system.h, sp13/task1.c, sp15/init.c, sp16/system.h, sp19/fptask.c, sp25/system.h, sp26/task1.c, sp27/init.c, sp28/init.c, sp29/init.c, sp31/task1.c, sp33/init.c, sp34/changepri.c, sp35/priinv.c, sp37/init.c, sp38/init.c, sp39/init.c, sp41/init.c, sp42/init.c, sp43/init.c, sp44/init.c, sp45/init.c, sp46/init.c, sp47/init.c, sp48/init.c, spfatal03/testcase.h, spfatal05/testcase.h, spfatal06/testcase.h, spfatal_support/system.h, spobjgetnext/init.c, spsize/getint.c, spsize/size.c: Fix warnings.
  • Property mode set to 100644
File size: 3.0 KB
Line 
1/*
2 *  COPYRIGHT (c) 1989-2009.
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.com/license/LICENSE.
8 *
9 *  $Id$
10 */
11
12#include <stdio.h>
13#include <rtems.h>
14#include <rtems/error.h>
15
16static rtems_id taskId1;
17static rtems_id taskId2;
18rtems_interval ticksPerSecond;
19
20#include "system.h"
21
22static int
23isSuspended (rtems_id tid)
24{
25  rtems_status_code sc;
26
27  sc = rtems_task_is_suspended (tid);
28  if (sc == RTEMS_ALREADY_SUSPENDED)
29    return 1;
30  if (sc != RTEMS_SUCCESSFUL)
31    printf ("rtems_task_is_suspended: %s\n", rtems_status_text (sc));
32  return 0;
33}
34
35static void
36subTask1 (rtems_task_argument arg)
37{
38  rtems_status_code sc;
39
40  rtems_task_wake_after (ticksPerSecond * 3);
41  sc = rtems_event_send (taskId2, 1);
42  if (sc != RTEMS_SUCCESSFUL) {
43    printf ("subTask1 - Can't send event (%d)\n", sc);
44    rtems_task_suspend (RTEMS_SELF);
45  }
46  rtems_task_wake_after (ticksPerSecond * 3);
47  printf ("subTask1 - Event sent\n");
48  rtems_task_suspend (RTEMS_SELF);
49  printf ("subTask1 - Back to task 1\n");
50  rtems_task_wake_after (ticksPerSecond * 3);
51  rtems_task_suspend (RTEMS_SELF);
52}
53
54static void
55subTask2 (rtems_task_argument arg)
56{
57  rtems_status_code sc;
58  rtems_event_set ev;
59
60  rtems_task_wake_after (ticksPerSecond * 1);
61  sc = rtems_event_receive (1, RTEMS_WAIT|RTEMS_EVENT_ANY, RTEMS_NO_TIMEOUT, &ev);
62  if (sc != RTEMS_SUCCESSFUL) {
63    printf ("subTask2 - Can't receive event (%d)\n", sc);
64    rtems_task_suspend (RTEMS_SELF);
65  }
66  printf ("subTask2 - Task 1 suspended? - should be 0: %d\n",
67     isSuspended (taskId1));
68  rtems_task_wake_after (ticksPerSecond * 4);
69  printf ("subTask2 - Task 1 suspended? - should be 1: %d\n",
70     isSuspended (taskId1));
71  rtems_task_resume (taskId1);
72  printf ("subTask2 - Task 1 suspended? - should be 0: %d\n",
73     isSuspended (taskId1));
74  rtems_task_wake_after (ticksPerSecond * 4);
75  printf ("subTask2 - Task 1 suspended? - should be 1: %d\n",
76     isSuspended (taskId1));
77
78  puts( "*** END OF TEST 26 ***" );
79  rtems_test_exit( 0 );
80}
81
82static void
83createTask (char c, rtems_id *tid)
84{
85  rtems_status_code sc;
86
87  sc = rtems_task_create (rtems_build_name('S','u','b',c),
88    RTEMS_MAXIMUM_PRIORITY - 1u,
89    RTEMS_MINIMUM_STACK_SIZE * 4,
90    RTEMS_PREEMPT|RTEMS_NO_TIMESLICE|RTEMS_NO_ASR|RTEMS_INTERRUPT_LEVEL(0),
91    RTEMS_NO_FLOATING_POINT|RTEMS_LOCAL,
92    tid);
93  if (sc != RTEMS_SUCCESSFUL) {
94    printf ("Can't create task (%d)\n", sc);
95    rtems_task_suspend (RTEMS_SELF);
96  }
97}
98
99static void
100startTask (rtems_id tid, rtems_task_entry entry_point)
101{
102  rtems_status_code sc;
103
104  sc = rtems_task_start (tid, entry_point, 0);
105  if (sc != RTEMS_SUCCESSFUL) {
106    printf ("Can't start task (%d)\n", sc);
107    rtems_task_suspend (RTEMS_SELF);
108  }
109}
110
111void
112task1 (void)
113{
114  rtems_clock_get (RTEMS_CLOCK_GET_TICKS_PER_SECOND, &ticksPerSecond);
115  createTask ('1', &taskId1);
116  createTask ('2', &taskId2);
117  startTask (taskId1, subTask1);
118  startTask (taskId2, subTask2);
119  rtems_task_suspend (RTEMS_SELF);
120}
Note: See TracBrowser for help on using the repository browser.