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

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
    memcheck();
22
    all_OK = 1;
23
    g_init_task_id = rtems_task_self();
24 25 26 27 28 29 30 31 32 33
    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,
34 35 36 37 38 39
#if CONFIGURE_SMP_MAXIMUM_PROCESSORS == 4
            // LEON3/LEON4 system - use full SMP
            RTEMS_DEFAULT_MODES,
#else
            // LEON2 system - emulate SMP via Linux/Windows-like
            // handling of tasks with same priority (i.e. pre-emption)
40
            RTEMS_DEFAULT_MODES | RTEMS_TIMESLICE,
41
#endif
42
            (i%2) == 0 ? RTEMS_FLOATING_POINT : RTEMS_DEFAULT_ATTRIBUTES,
43 44
            &Task_id[i]);
	if (status != RTEMS_SUCCESSFUL) {
45 46 47
	    printf(
                "[MAIN] Failed to rtems_task_create... status:%0x\n",
                status);
48 49 50 51 52 53
            rtems_task_delete(RTEMS_SELF);
	}

        // Start Task
        status = rtems_task_start(
            Task_id[i],
54
            (i%2) == 0 ? Task1_EntryPoint : Task2_EntryPoint,
55 56
            i);
    }
57 58
    // To give coverage code the opportunity to work, wait for children tasks
    // to die first. RTEMS events are used for synchronization.
59
    {
60
        printf("[MAIN] Waiting for testing tasks to complete...\n");
61
        rtems_option options = (RTEMS_EVENT_ANY | RTEMS_WAIT);
62 63
        rtems_event_set in = 0;
        for (i=0; i<TASKS; i++)
64
            in |= (RTEMS_EVENT_0 << i);
65
        rtems_event_set out;
66 67
        rtems_event_set non_completed = in;
        while (non_completed) {
68 69
            status = rtems_event_receive(in, options, RTEMS_NO_TIMEOUT, &out);
            if ( status == RTEMS_SUCCESSFUL ) {
70
                non_completed &= ~out;
71
                printf("[MAIN] Checking task completed.\n");
72 73 74
                fflush(stdout);
            }
        }
75 76 77 78 79
        printf("[MAIN] All testing tasks completed.\n");
        if (!all_OK)
            printf("[MAIN] Some tests failed... :-(\n");
        else
            printf("[MAIN] All tests passed! :-)\n");
80 81 82
        fflush(stdout);
    }
    exit(0);
83
}