Commit 24725d21 authored by julien.delange's avatar julien.delange
Browse files

* RTEMS_PURE mode works for RMA test



git-svn-id: https://tecsw.estec.esa.int/svn/taste/trunk/po-hi-c@1172 129961e7-ef38-4bb5-a8f7-c9a525a55882
parent 1221dc68
......@@ -50,6 +50,30 @@
#include <rtems/confdefs.h>
#endif /* RTEMS_POSIX */
#if defined(RTEMS_PURE)
#include <rtems.h>
#include <inttypes.h>
#define CONFIGURE_INIT
#include <bsp.h>
#define CONFIGURE_APPLICATION_NEEDS_CONSOLE_DRIVER
#define CONFIGURE_APPLICATION_NEEDS_CLOCK_DRIVER
#define CONFIGURE_APPLICATION_NEEDS_NULL_DRIVER
#define CONFIGURE_APPLICATION_NEEDS_TIMER_DRIVER
#define CONFIGURE_MAXIMUM_TIMERS 40
#define CONFIGURE_EXECUTIVE_RAM_SIZE (512*1024)
#define CONFIGURE_MAXIMUM_SEMAPHORES 20
#define CONFIGURE_MAXIMUM_TASKS 20
#define CONFIGURE_LIBIO_MAXIMUM_FILE_DESCRIPTORS 20
int Init ();
#define CONFIGURE_EXTRA_TASK_STACKS (20 * RTEMS_MINIMUM_STACK_SIZE)
#define CONFIGURE_USE_IMFS_AS_BASE_FILESYSTEM
#define CONFIGURE_RTEMS_INIT_TASKS_TABLE
#define CONFIGURE_MAXIMUM_TASKS 20
#include <rtems/confdefs.h>
#endif /* RTEMS_POSIX */
#if defined (X86_RTEMS)
#include <rtems/rtems_bsdnet.h>
......
......@@ -28,7 +28,6 @@
#define __PO_HI_MAIN_NAME Init
#define __PO_HI_MAIN_TYPE rtems_task
#define __PO_HI_MAIN_ARGS rtems_task_argument argument
rtems_task Init (rtems_task_argument);
#define __PO_HI_MAIN_RETURN 0
#define __ERRORMSG(s, args...) fprintf(stderr, s, ##args)
#elif defined(RTEMS_POSIX)
......@@ -53,7 +52,9 @@
#elif defined(RTEMS_PURE)
#include <rtems.h>
#include <inttypes.h>
#include <po_hi_time.h>
#include <bsp.h>
#define __PO_HI_DEFAULT_PRIORITY 10
#endif
#include <po_hi_types.h>
......@@ -81,10 +82,10 @@ int __po_hi_initialize_tasking();
* it returns the negative value ERROR_CREATE_TASK.
*/
int __po_hi_create_periodic_task (__po_hi_task_id id,
__po_hi_time_t period,
__po_hi_priority_t priority,
__po_hi_stack_t stack_size,
void* (*start_routine)(void));
__po_hi_time_t period,
__po_hi_priority_t priority,
__po_hi_stack_t stack_size,
void* (*start_routine)(void));
/*
* Create a sporadic task.
......
......@@ -24,7 +24,7 @@ GPROF = i386-rtems4.8-gprof
TARGET_SOURCES =
TARGET_TRANSPORT_SOURCES =
TARGET_CFLAGS = -DRTEMS_POSIX -DX86_RTEMS
TARGET_CFLAGS = -DRTEMS_PURE -DX86_RTEMS
TARGET_INCLUDE = -I $(RUNTIME_PATH)/config/
LD = i386-rtems4.8-ld
......
......@@ -9,8 +9,6 @@
* Copyright (C) 2010, European Space Agency (ESA)
*/
#include <pthread.h>
/* POSIX files */
#include <deployment.h>
/* included files from the generated code */
......@@ -23,8 +21,13 @@
#include <po_hi_protected.h>
/* included files from PolyORB-HI-C */
#if defined (POSIX) || defined (RTEMS_POSIX)
#include <pthread.h>
/* POSIX files */
pthread_cond_t cond_init;
pthread_mutex_t mutex_init;
#endif
int initialized_tasks = 0;
/* The barrier is initialized with __PO_HI_NB_TASKS +1
......@@ -40,25 +43,30 @@ void __po_hi_initialize_add_task ()
int __po_hi_initialize ()
{
#if defined (POSIX) || defined (RTEMS_POSIX)
pthread_mutexattr_t mutex_attr;
#endif
#ifdef RTEMS_POSIX
#if defined (RTEMS_POSIX) || defined (RTEMS_PURE)
#include <rtems/rtems/clock.h>
rtems_status_code status;
rtems_time_of_day time;
time.year = 1988;
time.month = 12;
time.day = 31;
time.hour = 9;
time.minute = 0;
time.second = 0;
time.minute = 1;
time.second = 10;
time.ticks = 0;
status = rtems_clock_set( &time );
if (rtems_clock_set( &time ) != RTEMS_SUCCESSFUL)
{
__DEBUGMSG ("Cannot set the clock\n");
}
#endif
#if defined (RTEMS_POSIX) || defined (POSIX)
if (pthread_mutexattr_init (&mutex_attr) != 0)
{
__DEBUGMSG ("[MAIN] Unable to init mutex attributes\n");
......@@ -83,6 +91,7 @@ int __po_hi_initialize ()
{
return (__PO_HI_ERROR_PTHREAD_COND);
}
#endif
__po_hi_initialize_tasking ();
......@@ -96,6 +105,7 @@ int __po_hi_initialize ()
int __po_hi_wait_initialization ()
{
#if defined (POSIX) || defined (RTEMS_POSIX)
if (pthread_mutex_lock (&mutex_init) != 0)
{
return (__PO_HI_ERROR_PTHREAD_MUTEX);
......@@ -112,6 +122,9 @@ int __po_hi_wait_initialization ()
pthread_cond_broadcast (&cond_init);
pthread_mutex_unlock (&mutex_init);
return (__PO_HI_SUCCESS);
#else
return (__PO_HI_UNAVAILABLE);
#endif
}
#ifdef __PO_HI_USE_GPROF
......
......@@ -18,10 +18,15 @@
#include <po_hi_task.h>
#include <po_hi_debug.h>
#include <po_hi_returns.h>
#include <po_hi_types.h>
/* Header files in PolyORB-HI */
#include <deployment.h>
/* Header files from generated code */
#ifdef RTEMS_PURE
#include <bsp.h>
#endif
int nb_tasks; /* number of created tasks */
......@@ -29,15 +34,16 @@ typedef struct
{
__po_hi_task_id id; /* Identifier of the task in the system */
__po_hi_time_t period;
__po_hi_time_t timer;
#if defined(RTEMS_POSIX) || defined(POSIX)
__po_hi_time_t timer;
pthread_t tid; /* The pthread_t type used by the
POSIX library */
pthread_mutex_t mutex;
pthread_cond_t cond;
#elif defined(RTEMS_PURE)
rtems_time_of_day timer; /* Next period to wait */
#endif
}
__po_hi_task_t;
} __po_hi_task_t;
/*
* Structure of a task, contains platform-dependent members
*/
......@@ -47,13 +53,17 @@ __po_hi_task_t tasks[__PO_HI_NB_TASKS];
void __po_hi_wait_for_tasks ()
{
int i;
#if defined(RTEMS_POSIX) || defined(POSIX)
int i;
for (i = 0; i < __PO_HI_NB_TASKS; i++)
{
pthread_join( tasks[i].tid , NULL );
}
#endif
#ifdef RTEMS_PURE
rtems_task_suspend(RTEMS_SELF);
#endif
}
/*
......@@ -63,6 +73,7 @@ void __po_hi_wait_for_tasks ()
*/
int __po_hi_compute_next_period (__po_hi_task_id task)
{
#if defined(RTEMS_POSIX) || defined(POSIX)
__po_hi_time_t mytime;
if (__po_hi_get_time (&mytime) != __PO_HI_SUCCESS)
......@@ -72,10 +83,28 @@ int __po_hi_compute_next_period (__po_hi_task_id task)
tasks[task].timer = __po_hi_add_times( mytime, tasks[task].period );
return (__PO_HI_SUCCESS);
#elif defined (RTEMS_PURE)
if (rtems_clock_get (RTEMS_CLOCK_GET_TOD, &tasks[task].timer) != RTEMS_SUCCESSFUL)
{
__DEBUGMSG ("ERROR WHILE TRYING TO GET THE CLOCK\n");
return (__PO_HI_UNAVAILABLE);
}
tasks[task].timer.second += 2;
/*
* TODO
* MUST FIX THAT
*/
return (__PO_HI_SUCCESS);
#else
return (__PO_HI_UNAVAILABLE);
#endif
}
int __po_hi_wait_for_next_period (__po_hi_task_id task)
{
#if defined (POSIX) || defined (RTEMS_POSIX)
int ret;
__po_hi_task_delay_until (tasks[task].timer, task);
if ( (ret = __po_hi_compute_next_period (task)) != 1)
......@@ -84,6 +113,20 @@ int __po_hi_wait_for_next_period (__po_hi_task_id task)
}
return (__PO_HI_SUCCESS);
#elif defined (RTEMS_PURE)
if (rtems_task_wake_when (&tasks[task].timer) != RTEMS_SUCCESSFUL)
{
__DEBUGMSG ("Error rtems_task_wake_when()\n");
// return (__PO_HI_UNAVAILABLE);
}
rtems_task_wake_after(RTEMS_YIELD_PROCESSOR);
__po_hi_compute_next_period (task);
return (__PO_HI_SUCCESS);
#else
return (__PO_HI_UNAVAILABLE);
#endif
}
int __po_hi_initialize_tasking( )
......@@ -194,7 +237,31 @@ int __po_hi_posix_initialize_task (__po_hi_task_t* task)
}
return (__PO_HI_SUCCESS);
}
#endif /* POSIX */
#endif /* POSIX || RTEMS_POSIX */
#ifdef RTEMS_PURE
int __po_hi_rtems_create_thread (__po_hi_priority_t priority,
__po_hi_stack_t stack_size,
void* (*start_routine)(void))
{
rtems_id id;
if (rtems_task_create (rtems_build_name( 'T', 'A', nb_tasks, ' ' ), 1, RTEMS_MINIMUM_STACK_SIZE, RTEMS_DEFAULT_MODES, RTEMS_DEFAULT_ATTRIBUTES | RTEMS_FLOATING_POINT, &id) != RTEMS_SUCCESSFUL)
{
__DEBUGMSG ("ERROR when creating the task\n");
}
if (rtems_task_start( id, start_routine, 0 ) != RTEMS_SUCCESSFUL)
{
__DEBUGMSG ("ERROR when starting the task\n");
}
return __PO_HI_SUCCESS;
}
#endif
int __po_hi_create_generic_task (__po_hi_task_id id,
__po_hi_time_t period,
......@@ -205,7 +272,15 @@ int __po_hi_create_generic_task (__po_hi_task_id id,
__po_hi_task_t* my_task;
if (id == -1)
{
#if defined (POSIX) || defined (RTEMS_POSIX)
__po_hi_posix_create_thread (priority, stack_size, start_routine);
return (__PO_HI_SUCCESS);
#elif defined (RTEMS_PURE)
__po_hi_rtems_create_thread (priority, stack_size, start_routine);
return (__PO_HI_SUCCESS);
#else
return (__PO_HI_UNAVAILABLE);
#endif
}
else
{
......@@ -213,9 +288,14 @@ int __po_hi_create_generic_task (__po_hi_task_id id,
my_task->period = period;
my_task->id = id;
#if defined (POSIX) || defined (RTEMS_POSIX)
my_task->tid = __po_hi_posix_create_thread (priority, stack_size, start_routine);
__po_hi_posix_initialize_task (my_task);
#elif defined (RTEMS_PURE)
__po_hi_rtems_create_thread (priority, stack_size, start_routine);
#else
return (__PO_HI_UNAVAILABLE);
#endif
nb_tasks++;
}
......@@ -267,6 +347,7 @@ int __po_hi_create_sporadic_task (__po_hi_task_id id,
int __po_hi_task_delay_until (__po_hi_time_t time, __po_hi_task_id task)
{
#if defined (POSIX) || defined (RTEMS_POSIX)
struct timespec timer;
int ret;
......@@ -290,4 +371,6 @@ int __po_hi_task_delay_until (__po_hi_time_t time, __po_hi_task_id task)
pthread_mutex_unlock (&tasks[task].mutex);
return (ret);
#endif
return (__PO_HI_UNAVAILABLE);
}
......@@ -9,14 +9,20 @@
*/
#include <time.h>
#include <pthread.h>
#include <errno.h>
#include <po_hi_config.h>
#include <po_hi_time.h>
#include <po_hi_returns.h>
#include <po_hi_debug.h>
#if defined (POSIX) || defined (RTEMS_POSIX)
#include <pthread.h>
#elif defined (RTEMS_PURE)
#include <bsp.h>
#endif
#ifdef NEED_CLOCK_GETTIME
#if defined (POSIX) && defined (NEED_CLOCK_GETTIME)
#include <sys/time.h>
int clock_gettime(int clk_id, struct timespec *tp)
{
......@@ -38,6 +44,7 @@ int clock_gettime(int clk_id, struct timespec *tp)
int __po_hi_get_time (__po_hi_time_t* mytime)
{
#if defined (POSIX) || defined (RTEMS_POSIX)
struct timespec ts;
__po_hi_time_t tmp;
......@@ -51,6 +58,23 @@ int __po_hi_get_time (__po_hi_time_t* mytime)
*mytime = tmp;
return (__PO_HI_SUCCESS);
#elif defined (RTEMS_PURE)
rtems_time_of_day current_time;
__po_hi_time_t tmp;
tmp = 0;
if (rtems_clock_get (RTEMS_CLOCK_GET_TOD, &current_time) != RTEMS_SUCCESSFUL)
{
__DEBUGMSG ("Error when trying to get the clock on RTEMS\n");
}
tmp = _TOD_To_seconds (&current_time) * 1000000;
tmp += current_time.ticks * _TOD_Microseconds_per_tick;
return (__PO_HI_SUCCESS);
#else
return (__PO_HI_UNAVAILABLE);
#endif
}
__po_hi_time_t __po_hi_add_times (__po_hi_time_t left, __po_hi_time_t right)
......@@ -83,6 +107,7 @@ __po_hi_time_t __po_hi_microseconds (__po_hi_uint32_t microseconds)
int __po_hi_delay_until (__po_hi_time_t time)
{
#if defined (POSIX) || defined (RTEMS_POSIX)
pthread_mutex_t mutex;
pthread_cond_t cond;
struct timespec timer;
......@@ -128,4 +153,9 @@ int __po_hi_delay_until (__po_hi_time_t time)
ret = __PO_HI_ERROR_PTHREAD_MUTEX;
}
return (ret);
#elif defined (RTEMS_PURE)
return (__PO_HI_UNAVAILABLE);
#else
return (__PO_HI_UNAVAILABLE);
#endif
}
......@@ -11,6 +11,7 @@
#include <po_hi_config.h>
#include <po_hi_time.h>
#include <po_hi_types.h>
#include <po_hi_debug.h>
#include <po_hi_utils.h>
/* Header files in PolyORB-HI */
......@@ -21,6 +22,7 @@
int __po_hi_simulate_wcet (__po_hi_time_t time1, __po_hi_time_t time2)
{
#if defined (POSIX) || defined (RTEMS_POSIX)
__po_hi_time_t tmp;
__po_hi_time_t limit;
__po_hi_get_time(&limit);
......@@ -34,6 +36,10 @@ int __po_hi_simulate_wcet (__po_hi_time_t time1, __po_hi_time_t time2)
}
}
return 0;
#else
__DEBUGMSG ("WCET simulation not handled at this time\n");
#endif
return 0;
}
......
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