init.c 2.17 KB
Newer Older
1 2 3 4 5 6 7
/*
 * Example initialization file - spawns 2 native FPU tasks
 *
 */
#define CONFIGURE_INIT
#define TASKS 2

8
#define DEFINE_VARS
9
#include "system.h"
10

11
#include <stdio.h>
Thanassis Tsiodras's avatar
Thanassis Tsiodras committed
12
#include <stdlib.h>
13 14 15 16 17 18 19 20

rtems_task Init(rtems_task_argument argument)
{
    rtems_status_code status;
    rtems_name Task_name[TASKS]; /* task names */
    rtems_id Task_id[TASKS]; /* task ids */
    int i;

21
    g_init_task_id = rtems_task_self();
22 23 24 25 26 27 28 29 30 31
    for(i = 0; i < TASKS; i++)
    {
        // Initialize Task name
        Task_name[i] = rtems_build_name('T', 'T', "0" + i / 10, "0" + i % 10);

        // Create Task
        status = rtems_task_create(
            Task_name[i],
            (rtems_task_priority) 2,
            RTEMS_MINIMUM_STACK_SIZE,
32
            RTEMS_DEFAULT_MODES,  // use RTEMS_DEFAULT_MODES | RTEMS_TIMESLICE for Linux/Windows like
33
                                  // handling of tasks with same priority (i.e. pre-emption)
Thanassis Tsiodras's avatar
Thanassis Tsiodras committed
34
            i == 0 ? RTEMS_FLOATING_POINT : RTEMS_DEFAULT_ATTRIBUTES,
35 36
            &Task_id[i]);
	if (status != RTEMS_SUCCESSFUL) {
37
	    printf("[PARENT] Failed to rtems_task_create... status:%0x\n", status);
38 39 40 41 42 43
            rtems_task_delete(RTEMS_SELF);
	}

        // Start Task
        status = rtems_task_start(
            Task_id[i],
Thanassis Tsiodras's avatar
Thanassis Tsiodras committed
44
            i == 0 ? Task1_EntryPoint : Task2_EntryPoint,
45 46
            i);
    }
47 48
    // To give coverage code the opportunity to work, wait for child tasks to die first.
    // We use RTEMS events here, but you can use any sync API you want.
49
    {
50
        printf("[PARENT] Parent task waits for children to complete...\n");
51
        rtems_option options = (RTEMS_EVENT_ANY | RTEMS_WAIT);
52 53 54
        rtems_event_set in = 0;
        for (i=0; i<TASKS; i++)
            in |= (RTEMS_EVENT_0 + i);
55
        rtems_event_set out;
56 57
        rtems_event_set non_completed = in;
        while (non_completed) {
58 59
            status = rtems_event_receive(in, options, RTEMS_NO_TIMEOUT, &out);
            if ( status == RTEMS_SUCCESSFUL ) {
60 61
                non_completed &= ~out;
                printf("[PARENT] Child task completed.\n");
62 63 64
                fflush(stdout);
            }
        }
65
        printf("[PARENT] All tasks completed.\n");
66 67 68
        fflush(stdout);
    }
    exit(0);
69
}