Commit b32b484a authored by Thanassis Tsiodras's avatar Thanassis Tsiodras

Refactored common code, made children waiting generic.

parent f58adda7
Pipeline #106 skipped
...@@ -39,7 +39,8 @@ VPATH=src ...@@ -39,7 +39,8 @@ VPATH=src
SRC= \ SRC= \
init.c \ init.c \
task1.c \ task1.c \
task2.c task2.c \
common.c
SUFFIX=$(CFG).$(FPU_SUFFIX).$(LEON) SUFFIX=$(CFG).$(FPU_SUFFIX).$(LEON)
......
#include "system.h"
#include <stdio.h>
void task_begin(int task_no)
{
printf("[TASK %d] Starting...\n", task_no);
fflush(stdout);
}
void task_end(int task_no)
{
rtems_event_send(g_init_task_id, RTEMS_EVENT_0 + task_no);
rtems_task_delete(RTEMS_SELF);
}
...@@ -44,22 +44,25 @@ rtems_task Init(rtems_task_argument argument) ...@@ -44,22 +44,25 @@ rtems_task Init(rtems_task_argument argument)
i == 0 ? Task1_EntryPoint : Task2_EntryPoint, i == 0 ? Task1_EntryPoint : Task2_EntryPoint,
i); i);
} }
// To give coverage code room to breathe! // To give coverage code the opportunity to work, wait for child tasks to die first.
printf("[PARENT] Parent task waits for his children to complete...\n"); // We use RTEMS events here, but you can use any sync API you want.
{ {
printf("[PARENT] Parent task waits for children to complete...\n");
rtems_option options = (RTEMS_EVENT_ANY | RTEMS_WAIT); rtems_option options = (RTEMS_EVENT_ANY | RTEMS_WAIT);
rtems_event_set in = (RTEMS_EVENT_0 | RTEMS_EVENT_1); rtems_event_set in = 0;
for (i=0; i<TASKS; i++)
in |= (RTEMS_EVENT_0 + i);
rtems_event_set out; rtems_event_set out;
rtems_event_set completed = 0; rtems_event_set non_completed = in;
while((completed & in) != (RTEMS_EVENT_0 | RTEMS_EVENT_1)) { while (non_completed) {
status = rtems_event_receive(in, options, RTEMS_NO_TIMEOUT, &out); status = rtems_event_receive(in, options, RTEMS_NO_TIMEOUT, &out);
if ( status == RTEMS_SUCCESSFUL ) { if ( status == RTEMS_SUCCESSFUL ) {
completed |= out; non_completed &= ~out;
printf("[PARENT] Task completed!\n"); printf("[PARENT] Child task completed.\n");
fflush(stdout); fflush(stdout);
} }
} }
printf("[PARENT] All tasks completed!\n"); printf("[PARENT] All tasks completed.\n");
fflush(stdout); fflush(stdout);
} }
exit(0); exit(0);
......
...@@ -6,6 +6,8 @@ ...@@ -6,6 +6,8 @@
rtems_task Init(rtems_task_argument argument); rtems_task Init(rtems_task_argument argument);
rtems_task Task1_EntryPoint(rtems_task_argument argument); rtems_task Task1_EntryPoint(rtems_task_argument argument);
rtems_task Task2_EntryPoint(rtems_task_argument argument); rtems_task Task2_EntryPoint(rtems_task_argument argument);
void task_begin(int task_no);
void task_end(int task_no);
#define CONFIGURE_APPLICATION_NEEDS_CLOCK_DRIVER #define CONFIGURE_APPLICATION_NEEDS_CLOCK_DRIVER
#define CONFIGURE_MAXIMUM_TASKS 64 #define CONFIGURE_MAXIMUM_TASKS 64
......
...@@ -4,8 +4,7 @@ ...@@ -4,8 +4,7 @@
rtems_task Task1_EntryPoint(rtems_task_argument argument) rtems_task Task1_EntryPoint(rtems_task_argument argument)
{ {
int task_no = (int) argument; int task_no = (int) argument;
printf("[TASK %d] Starting...\n", task_no); task_begin(task_no);
fflush(stdout);
int j; int j;
double d=task_no; double d=task_no;
...@@ -16,6 +15,6 @@ rtems_task Task1_EntryPoint(rtems_task_argument argument) ...@@ -16,6 +15,6 @@ rtems_task Task1_EntryPoint(rtems_task_argument argument)
d*=1.0001; d*=1.0001;
} }
printf("[TASK %d] Computed value was %ld\n", task_no, (long)d); printf("[TASK %d] Computed value was %ld\n", task_no, (long)d);
rtems_event_send(g_init_task_id, RTEMS_EVENT_0);
rtems_task_delete(RTEMS_SELF); task_end(task_no);
} }
...@@ -4,8 +4,7 @@ ...@@ -4,8 +4,7 @@
rtems_task Task2_EntryPoint(rtems_task_argument argument) rtems_task Task2_EntryPoint(rtems_task_argument argument)
{ {
int task_no = (int) argument; int task_no = (int) argument;
printf("[TASK %d] Starting...\n", task_no); task_begin(task_no);
fflush(stdout);
int j; int j;
long long int dummy = 0; long long int dummy = 0;
...@@ -16,6 +15,5 @@ rtems_task Task2_EntryPoint(rtems_task_argument argument) ...@@ -16,6 +15,5 @@ rtems_task Task2_EntryPoint(rtems_task_argument argument)
dummy++; dummy++;
} }
printf("[TASK %d] Computed value was %lld\n", task_no, dummy); printf("[TASK %d] Computed value was %lld\n", task_no, dummy);
rtems_event_send(g_init_task_id, RTEMS_EVENT_1); task_end((int) argument);
rtems_task_delete(RTEMS_SELF);
} }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment