init.c 1.37 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27
/*
 * Example initialization file - spawns 2 native FPU tasks
 *
 */
#define CONFIGURE_INIT
#define TASKS 2

#include "system.h"
#include <stdio.h>

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;

    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,
28
            RTEMS_TIMESLICE,  // use RTEMS_DEFAULT_MODES | RTEMS_TIMESLICE for Linux/Windows like
29
                                  // handling of tasks with same priority (i.e. pre-emption)
30
            i == 1 ? RTEMS_FLOATING_POINT : RTEMS_DEFAULT_ATTRIBUTES,
31 32 33 34 35 36 37 38 39
            &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],
40
            i == 1 ? Task1_EntryPoint : Task2_EntryPoint,
41 42 43 44 45 46 47
            i);
    }
    printf("Parent task sleeps for a second...\n");
    rtems_task_wake_after(100);
    printf("Parent task bids adieu...\n");
    rtems_task_delete(RTEMS_SELF);
}