init.c 2.01 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)
34
            i == 0 ? RTEMS_FLOATING_POINT : RTEMS_DEFAULT_ATTRIBUTES,
35 36 37 38 39 40 41 42 43
            &Task_id[i]);
	if (status != RTEMS_SUCCESSFUL) {
	    printf("Failed to rtems_task_create... status:%0x\n", status);
            rtems_task_delete(RTEMS_SELF);
	}

        // Start Task
        status = rtems_task_start(
            Task_id[i],
44
            i == 0 ? Task1_EntryPoint : Task2_EntryPoint,
45 46
            i);
    }
47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65
    // To give coverage code room to breathe!
    printf("Parent task waits for his children to complete...\n");
    {
        rtems_option options = (RTEMS_EVENT_ANY | RTEMS_WAIT);
        rtems_event_set in = (RTEMS_EVENT_0 | RTEMS_EVENT_1);
        rtems_event_set out;
        rtems_event_set completed = 0;
        while((completed & in) != (RTEMS_EVENT_0 | RTEMS_EVENT_1)) {
            status = rtems_event_receive(in, options, RTEMS_NO_TIMEOUT, &out);
            if ( status == RTEMS_SUCCESSFUL ) {
                completed |= out;
                printf("Task completed!\n");
                fflush(stdout);
            }
        }
        printf("All tasks completed!\n");
        fflush(stdout);
    }
    exit(0);
66
}