source: rtems/testsuites/sptests/sp44/init.c @ b1274bd9

4.104.115
Last change on this file since b1274bd9 was b1274bd9, checked in by Ralf Corsepius <ralf.corsepius@…>, on 11/30/09 at 03:33:25

Whitespace removal.

  • Property mode set to 100644
File size: 3.9 KB
Line 
1/*
2 * Original version submitted as part of PR1212
3 *
4 * This example shows a possible blocking of timeslicing if task mode is
5 * changed to timeslicing in the middle of its executing.
6 *
7 * The expected output is:
8 *
9 *   Task #0's turn. Now setting turn to 1
10 *   Task #1's turn. Now setting turn to 0
11 *   Task #0's turn. Now setting turn to 1
12 *   Task #1's turn. Now setting turn to 0
13 *   Task #0's turn. Now setting turn to 1
14 *   Task #1's turn. Now setting turn to 0
15 *   Task #0's turn. Now setting turn to 1
16 *   ...
17 *
18 * The actural output is:
19 *
20 *   Task #0's turn. Now setting turn to 1
21 *
22 * Task #1 can not be dispatched also both tasks have timeslice enabled.
23 *
24 * Setting TASK_A/B_INITMODE to RTEMS_DEFAULT_MODES | RTEMS_TIMESLICE
25 * will produce the expected output.
26 *
27 * $Id$
28 */
29
30#include <tmacros.h>
31#include <rtems.h>
32#include <stdio.h>
33#include <stdlib.h>
34
35rtems_task Init(rtems_task_argument ignored);
36rtems_task TaskAB_entry(rtems_task_argument me);
37
38/*** Task priorities ***/
39#define TASK_A_PRIORITY    10
40#define TASK_B_PRIORITY   10
41
42/*** Task names ***/
43#define TASK_A_NAME     1
44#define TASK_B_NAME     2
45
46/*** Task atributes ***/
47#define TASK_A_INITMODE    RTEMS_DEFAULT_MODES
48#define TASK_B_INITMODE    RTEMS_DEFAULT_MODES
49
50/*** Task generic parameters ***/
51#define TASK_A_STACKSIZE   RTEMS_MINIMUM_STACK_SIZE
52#define TASK_A_MODEATTR    RTEMS_DEFAULT_ATTRIBUTES
53#define TASK_B_STACKSIZE   RTEMS_MINIMUM_STACK_SIZE
54#define TASK_B_MODEATTR    RTEMS_DEFAULT_ATTRIBUTES
55
56volatile uint32_t turn;
57rtems_id TaskA_id, TaskB_id;
58
59#define TEST_FAILED(_status, _msg) \
60  do { \
61    printf("Test failed, status code: %d, msg: %s\n", _status, _msg); \
62    exit(1); \
63  } while(0)
64
65/* TASK A/B */
66rtems_task TaskAB_entry(rtems_task_argument me)
67{
68  static rtems_mode previous_mode_set;
69  rtems_status_code status;
70  uint32_t iterations = 0;
71
72  status = rtems_task_mode(RTEMS_PREEMPT | RTEMS_TIMESLICE,
73                  RTEMS_PREEMPT_MASK | RTEMS_TIMESLICE_MASK,
74                  &previous_mode_set);
75  if (status != RTEMS_SUCCESSFUL)
76    TEST_FAILED(status, "Unable to change task mode.");
77
78  while(1) {
79    if (turn == me) {
80      printf("Task #%" PRIdrtems_task_argument "'s turn. Now setting turn to %" PRIdrtems_task_argument "\n", me, 1 - me);
81      turn = 1 - me;
82
83      if ( ++iterations == 10 ) {
84        puts( "*** END OF SP44 TEST ***" );
85        exit( 0 );
86      }
87    }
88  }
89}
90
91rtems_task Init(rtems_task_argument ignored)
92{
93  static rtems_status_code status;
94
95  puts( "\n\n*** SP44 TEST ***" );
96
97  /* Create Task A */
98  status = rtems_task_create(TASK_A_NAME, TASK_A_PRIORITY, TASK_A_STACKSIZE,
99         TASK_A_INITMODE, TASK_A_MODEATTR, &TaskA_id);
100
101  if (status != RTEMS_SUCCESSFUL)
102    TEST_FAILED(status,"rtems_task_create failed.\n");
103
104  /* Start Task A */
105  status = rtems_task_start(TaskA_id, TaskAB_entry, 0);
106  if (status != RTEMS_SUCCESSFUL)
107    TEST_FAILED(status,"rtems_task_start failed.\n");
108
109  /* Create Task B */
110  status = rtems_task_create(TASK_B_NAME, TASK_B_PRIORITY, TASK_B_STACKSIZE,
111         TASK_B_INITMODE, TASK_B_MODEATTR, &TaskB_id);
112
113  if (status != RTEMS_SUCCESSFUL)
114    TEST_FAILED(status,"rtems_task_create failed.\n");
115
116  /* Start Task B */
117  status = rtems_task_start(TaskB_id, TaskAB_entry, 1);
118  if (status != RTEMS_SUCCESSFUL)
119    TEST_FAILED(status,"rtems_task_start failed.\n");
120
121  /* Suspend itself */
122  status = rtems_task_suspend(RTEMS_SELF);
123  if (status != RTEMS_SUCCESSFUL)
124    TEST_FAILED(status,"rtems_task_suspend failed.\n");
125
126  /* This task is not suposed to be executed anymore */
127  printf("\nNOT SUPOSED TO RETURN HERE...\n");
128  exit(1);
129}
130
131/* configuration information */
132
133#define CONFIGURE_APPLICATION_NEEDS_CLOCK_DRIVER
134#define CONFIGURE_APPLICATION_NEEDS_CONSOLE_DRIVER
135
136#define CONFIGURE_MICROSECONDS_PER_TICK 1000
137#define CONFIGURE_TICKS_PER_TIMESLICE   10
138#define CONFIGURE_MAXIMUM_TASKS         3
139
140#define CONFIGURE_RTEMS_INIT_TASKS_TABLE
141
142#define CONFIGURE_INIT
143
144#include <rtems/confdefs.h>
Note: See TracBrowser for help on using the repository browser.