Commit b03d8134 authored by Thanassis Tsiodras's avatar Thanassis Tsiodras

POSIX API.

parent d5521483
...@@ -2,92 +2,53 @@ ...@@ -2,92 +2,53 @@
* Example initialization file - spawns 2 native FPU tasks * Example initialization file - spawns 2 native FPU tasks
* *
*/ */
#define CONFIGURE_INIT #include <stdio.h>
#include <stdlib.h>
#include <stdlib.h>
#include <pthread.h>
#define TASKS 4 #define TASKS 4
#define DEFINE_VARS #define DEFINE_VARS
#include "system.h"
#include <stdio.h> void *POSIX_Init(void);
#include <stdlib.h>
#define CONFIGURE_INIT
#include "system.h"
rtems_task Init(rtems_task_argument argument) void *POSIX_Init()
{ {
rtems_status_code status; int status;
rtems_name Task_name[TASKS]; /* task names */
rtems_id Task_id[TASKS]; /* task ids */
int i; int i;
pthread_t children[TASKS];
#ifdef MEMCHECK #ifdef MEMCHECK
memcheck(); memcheck();
#endif #endif
all_OK = 1; int all_OK = 1;
g_init_task_id = rtems_task_self();
for(i = 0; i < TASKS; i++) for(i = 0; i < TASKS; i++)
{ {
// Initialize Task name status = pthread_create(
Task_name[i] = rtems_build_name('T', 'T', "0" + i / 10, "0" + i % 10); &children[i],
NULL,
// Create Task (i%2) == 0 ? &Task1_EntryPoint : &Task2_EntryPoint,
status = rtems_task_create( (void*)i);
Task_name[i], (void) status;
(rtems_task_priority) 2,
RTEMS_MINIMUM_STACK_SIZE,
#if CONFIGURE_SMP_MAXIMUM_PROCESSORS == 1 || CONFIGURE_MAXIMUM_PROCESSORS == 1
// LEON2 system - emulate SMP via Linux/Windows-like
// handling of tasks with same priority (i.e. pre-emption)
RTEMS_DEFAULT_MODES | RTEMS_TIMESLICE,
#else
// LEON3/LEON4 system - use full SMP
RTEMS_DEFAULT_MODES,
#endif
#if __RTEMS_MAJOR__ == 5
// Currently, RCCrc3 has a bug - it needs floating point support
// for all tasks, even those that don't use the FPU - otherwise
// as soon as the FPU task dies, the binary dies as well.
RTEMS_FLOATING_POINT,
#else
(i%2) == 0 ? RTEMS_FLOATING_POINT : RTEMS_DEFAULT_ATTRIBUTES,
#endif
&Task_id[i]);
if (status != RTEMS_SUCCESSFUL) {
printf(
"[MAIN] Failed to rtems_task_create... status:%0x\n",
status);
rtems_task_delete(RTEMS_SELF);
}
// Start Task
status = rtems_task_start(
Task_id[i],
(i%2) == 0 ? Task1_EntryPoint : Task2_EntryPoint,
i);
} }
// To give coverage code the opportunity to work, wait for children tasks // To give coverage code the opportunity to work, wait for children tasks
// to die first. RTEMS events are used for synchronization. // to die first. RTEMS events are used for synchronization.
{
printf("[MAIN] Waiting for testing tasks to complete...\n"); puts("[MAIN] Waiting for testing tasks to complete...");
rtems_option options = (RTEMS_EVENT_ANY | RTEMS_WAIT); for (i=0; i<TASKS; i++) {
rtems_event_set in = 0; pthread_join(children[i], NULL);
for (i=0; i<TASKS; i++) printf("[MAIN] Thread completed.\n");
in |= (RTEMS_EVENT_0 << i);
rtems_event_set out;
rtems_event_set non_completed = in;
while (non_completed) {
status = rtems_event_receive(in, options, RTEMS_NO_TIMEOUT, &out);
if ( status == RTEMS_SUCCESSFUL ) {
non_completed &= ~out;
printf("[MAIN] Task completed.\n");
fflush(stdout);
}
}
printf("[MAIN] All testing tasks completed.\n");
if (!all_OK)
printf("[MAIN] Some tests failed... :-(\n");
else
printf("[MAIN] All tests passed! :-)\n");
fflush(stdout); fflush(stdout);
} }
printf("[MAIN] All testing tasks completed.\n");
if (!all_OK)
printf("[MAIN] Some tests failed... :-(\n");
else
printf("[MAIN] All tests passed! :-)\n");
fflush(stdout);
exit(0); exit(0);
} }
...@@ -3,17 +3,21 @@ ...@@ -3,17 +3,21 @@
#include <rtems.h> #include <rtems.h>
rtems_task Init(rtems_task_argument argument); void *POSIX_Init(void);
rtems_task Task1_EntryPoint(rtems_task_argument argument); void *Task1_EntryPoint(void *argument);
rtems_task Task2_EntryPoint(rtems_task_argument argument); void *Task2_EntryPoint(void *argument);
void task_begin(int task_no); void task_begin(int task_no);
void task_end(int task_no); void task_end(int task_no);
void memcheck(void); void memcheck(void);
#define CONFIGURE_APPLICATION_NEEDS_CLOCK_DRIVER
#define CONFIGURE_MAXIMUM_TASKS 64 #define CONFIGURE_MAXIMUM_TASKS 64
#define CONFIGURE_TICKS_PER_TIMESLICE 100 #define CONFIGURE_TICKS_PER_TIMESLICE 100
#define CONFIGURE_RTEMS_INIT_TASKS_TABLE //#define CONFIGURE_RTEMS_INIT_TASKS_TABLE
#define CONFIGURE_MAXIMUM_POSIX_THREADS 20
#define CONFIGURE_POSIX_INIT_THREAD_TABLE
#define CONFIGURE_APPLICATION_NEEDS_CLOCK_DRIVER
#define CONFIGURE_APPLICATION_NEEDS_CONSOLE_DRIVER #define CONFIGURE_APPLICATION_NEEDS_CONSOLE_DRIVER
#if __RTEMS_MAJOR__ < 5 #if __RTEMS_MAJOR__ < 5
......
#include "system.h" #include "system.h"
#include <stdio.h> #include <stdio.h>
rtems_task Task1_EntryPoint(rtems_task_argument argument) void *Task1_EntryPoint(void *argument)
{ {
int task_no = (int) argument; int task_no = (int) argument;
task_begin(task_no); task_begin(task_no);
...@@ -31,7 +31,7 @@ rtems_task Task1_EntryPoint(rtems_task_argument argument) ...@@ -31,7 +31,7 @@ rtems_task Task1_EntryPoint(rtems_task_argument argument)
fflush(stdout); fflush(stdout);
all_OK = 0; all_OK = 0;
task_end(task_no); task_end(task_no);
return; return NULL;
} }
if (target != result) { if (target != result) {
printf( printf(
...@@ -40,10 +40,11 @@ rtems_task Task1_EntryPoint(rtems_task_argument argument) ...@@ -40,10 +40,11 @@ rtems_task Task1_EntryPoint(rtems_task_argument argument)
fflush(stdout); fflush(stdout);
all_OK = 0; all_OK = 0;
task_end(task_no); task_end(task_no);
return; return NULL;
} }
} }
printf("[TASK %d] Computed the correct floating point result.\n", task_no); printf("[TASK %d] Computed the correct floating point result.\n", task_no);
fflush(stdout); fflush(stdout);
task_end(task_no); task_end(task_no);
return NULL;
} }
#include "system.h" #include "system.h"
#include <stdio.h> #include <stdio.h>
rtems_task Task2_EntryPoint(rtems_task_argument argument) void *Task2_EntryPoint(void *argument)
{ {
int task_no = (int) argument; int task_no = (int) argument;
task_begin(task_no); task_begin(task_no);
...@@ -21,9 +21,10 @@ rtems_task Task2_EntryPoint(rtems_task_argument argument) ...@@ -21,9 +21,10 @@ rtems_task Task2_EntryPoint(rtems_task_argument argument)
fflush(stdout); fflush(stdout);
all_OK = 0; all_OK = 0;
task_end(task_no); task_end(task_no);
return; return NULL;
} }
printf("[TASK %d] Computed the correct integer result.\n", task_no); printf("[TASK %d] Computed the correct integer result.\n", task_no);
fflush(stdout); fflush(stdout);
task_end((int) argument); task_end((int) argument);
return NULL;
} }
#ifndef __VERSION_H__ #ifndef __VERSION_H__
#define __VERSION_H__ #define __VERSION_H__
const char version[] = "1.104 (940a750)"; const char version[] = "1.112 (d552148)";
#endif #endif
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