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

4.104.11
Last change on this file since a986c07 was a986c07, checked in by Joel Sherrill <joel.sherrill@…>, on Dec 14, 2008 at 6:36:00 PM

2008-12-14 Joel Sherrill <joel.sherrill@…>

  • sp07/init.c, sp12/init.c, sp12/pridrv.c, sp12/pritask.c, sp12/system.h, sp16/system.h, sp25/system.h, sp26/task1.c, sp28/init.c, sp29/init.c, sp35/priinv.c, sp42/init.c: Run all tests successfully with maxixum number of priorities as 16 instead of 256. This was done by temporarily modifying the score priority.h maximum. This allowed testing of all API code to ensure that it worked properly with a reduced number of priorities. Most modifications were to switch from hard-coded maximum to using the API provided methods to determine maximum number of priority levels.
  • Property mode set to 100644
File size: 3.0 KB
Line 
1/*
2 *  COPYRIGHT (c) 1989-2008.
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 - 1,
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.