Notice: We have migrated to GitLab launching 2024-05-01 see here: https://gitlab.rtems.org/

Ticket #2772: init.c

File init.c, 2.3 KB (added by Kuan-Hsun Chen, on 08/05/16 at 16:38:05)

Example init task

Line 
1/**
2 * @file sprmsched01/init.c
3 *
4 * @brief A init task body for sprmsched01 example.
5 *
6 */
7
8/*
9 *  COPYRIGHT (c) 2016 Kuan-Hsun Chen, TU Dortmund University (TUDo).
10 *
11 *  The license and distribution terms for this file may be
12 *  found in the file LICENSE in this distribution or at
13 *  http://www.rtems.com/license/LICENSE.
14 */
15
16#ifdef HAVE_CONFIG_H
17#include "config.h"
18#endif
19
20#define CONFIGURE_INIT
21#include "system.h"
22
23#include <rtems/rtems/tasksimpl.h>
24#include <rtems/test.h>
25#include <rtems/status-checks.h>
26
27const char rtems_test_name[] = "Rate Monotonic 01";
28
29/* Global variables */
30rtems_id   Task_id[ 2 ];         /* array of task ids */
31rtems_name Task_name[ 2 ];       /* array of task names */
32uint32_t tick_per_second;        /* time reference */
33int testnumber = 15;                  /* stop condition */
34
35#if 1
36rtems_task Init(
37        rtems_task_argument argument
38)
39{
40  TEST_BEGIN();
41  rtems_status_code status;
42  rtems_time_of_day time;
43
44
45  tick_per_second = rtems_clock_get_ticks_per_second();
46  printf("\nTicks per second in your system: %" PRIu32 "\n", tick_per_second);
47
48  Task_name[ 1 ] = rtems_build_name( 'T', 'A', '1', ' ' );
49  Task_name[ 2 ] = rtems_build_name( 'T', 'A', '2', ' ' );
50
51  /* Create two tasks */
52  status = rtems_task_create(
53    Task_name[ 1 ], 2, RTEMS_MINIMUM_STACK_SIZE * 2, RTEMS_DEFAULT_MODES,
54    RTEMS_DEFAULT_ATTRIBUTES, &Task_id[ 1 ]
55  );
56  if ( status != RTEMS_SUCCESSFUL) {
57    printf( "rtems_task_create 1 failed with status of %d.\n", status );
58    rtems_test_exit(0);
59  }
60
61  status = rtems_task_create(
62    Task_name[ 2 ], 5, RTEMS_MINIMUM_STACK_SIZE * 2, RTEMS_DEFAULT_MODES,
63    RTEMS_DEFAULT_ATTRIBUTES, &Task_id[ 2 ]
64  );
65  if ( status != RTEMS_SUCCESSFUL) {
66    printf( "rtems_task_create 2 failed with status of %d.\n", status );
67    rtems_test_exit(0);
68  }
69
70  /* After creating the periods for tasks, start to run them sequencially. */
71
72  status = rtems_task_start( Task_id[ 1 ], Task_1, 1);
73  if ( status != RTEMS_SUCCESSFUL) {
74    printf( "rtems_task_start 1 failed with status of %d.\n", status );
75    rtems_test_exit(0);
76  }
77  status = rtems_task_start( Task_id[ 2 ], Task_2, 1);
78  if ( status != RTEMS_SUCCESSFUL) {
79    printf( "rtems_task_start 2 failed with status of %d.\n", status );
80    rtems_test_exit(0);
81  }
82
83  status = rtems_task_delete( RTEMS_SELF );
84}
85
86#endif