Commit b03d8134 authored by Thanassis Tsiodras's avatar Thanassis Tsiodras

POSIX API.

parent d5521483
......@@ -2,92 +2,53 @@
* 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 DEFINE_VARS
#include "system.h"
#include <stdio.h>
#include <stdlib.h>
void *POSIX_Init(void);
#define CONFIGURE_INIT
#include "system.h"
rtems_task Init(rtems_task_argument argument)
void *POSIX_Init()
{
rtems_status_code status;
rtems_name Task_name[TASKS]; /* task names */
rtems_id Task_id[TASKS]; /* task ids */
int status;
int i;
pthread_t children[TASKS];
#ifdef MEMCHECK
memcheck();
#endif
all_OK = 1;
g_init_task_id = rtems_task_self();
int all_OK = 1;
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,
#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);
status = pthread_create(
&children[i],
NULL,
(i%2) == 0 ? &Task1_EntryPoint : &Task2_EntryPoint,
(void*)i);
(void) status;
}
// To give coverage code the opportunity to work, wait for children tasks
// to die first. RTEMS events are used for synchronization.
{
printf("[MAIN] Waiting for testing tasks to complete...\n");
rtems_option options = (RTEMS_EVENT_ANY | RTEMS_WAIT);
rtems_event_set in = 0;
for (i=0; i<TASKS; i++)
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");
puts("[MAIN] Waiting for testing tasks to complete...");
for (i=0; i<TASKS; i++) {
pthread_join(children[i], NULL);
printf("[MAIN] Thread 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);
exit(0);
}
......@@ -3,17 +3,21 @@
#include <rtems.h>
rtems_task Init(rtems_task_argument argument);
rtems_task Task1_EntryPoint(rtems_task_argument argument);
rtems_task Task2_EntryPoint(rtems_task_argument argument);
void *POSIX_Init(void);
void *Task1_EntryPoint(void *argument);
void *Task2_EntryPoint(void *argument);
void task_begin(int task_no);
void task_end(int task_no);
void memcheck(void);
#define CONFIGURE_APPLICATION_NEEDS_CLOCK_DRIVER
#define CONFIGURE_MAXIMUM_TASKS 64
#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
#if __RTEMS_MAJOR__ < 5
......
#include "system.h"
#include <stdio.h>
rtems_task Task1_EntryPoint(rtems_task_argument argument)
void *Task1_EntryPoint(void *argument)
{
int task_no = (int) argument;
task_begin(task_no);
......@@ -31,7 +31,7 @@ rtems_task Task1_EntryPoint(rtems_task_argument argument)
fflush(stdout);
all_OK = 0;
task_end(task_no);
return;
return NULL;
}
if (target != result) {
printf(
......@@ -40,10 +40,11 @@ rtems_task Task1_EntryPoint(rtems_task_argument argument)
fflush(stdout);
all_OK = 0;
task_end(task_no);
return;
return NULL;
}
}
printf("[TASK %d] Computed the correct floating point result.\n", task_no);
fflush(stdout);
task_end(task_no);
return NULL;
}
#include "system.h"
#include <stdio.h>
rtems_task Task2_EntryPoint(rtems_task_argument argument)
void *Task2_EntryPoint(void *argument)
{
int task_no = (int) argument;
task_begin(task_no);
......@@ -21,9 +21,10 @@ rtems_task Task2_EntryPoint(rtems_task_argument argument)
fflush(stdout);
all_OK = 0;
task_end(task_no);
return;
return NULL;
}
printf("[TASK %d] Computed the correct integer result.\n", task_no);
fflush(stdout);
task_end((int) argument);
return NULL;
}
#ifndef __VERSION_H__
#define __VERSION_H__
const char version[] = "1.104 (940a750)";
const char version[] = "1.112 (d552148)";
#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