Commit b77bd7c4 authored by julien.delange's avatar julien.delange

* port the main initialization barrier for RTEMS_PURE



git-svn-id: https://tecsw.estec.esa.int/svn/taste/trunk/po-hi-c@1240 129961e7-ef38-4bb5-a8f7-c9a525a55882
parent 6abc7f0e
...@@ -69,6 +69,7 @@ ...@@ -69,6 +69,7 @@
#define CONFIGURE_USE_IMFS_AS_BASE_FILESYSTEM #define CONFIGURE_USE_IMFS_AS_BASE_FILESYSTEM
#define CONFIGURE_RTEMS_INIT_TASKS_TABLE #define CONFIGURE_RTEMS_INIT_TASKS_TABLE
#define CONFIGURE_MAXIMUM_TASKS 20 #define CONFIGURE_MAXIMUM_TASKS 20
#define CONFIGURE_MAXIMUM_BARRIERS 20
#define CONFIGURE_INIT #define CONFIGURE_INIT
#include <rtems.h> #include <rtems.h>
#include <inttypes.h> #include <inttypes.h>
......
...@@ -22,6 +22,8 @@ ...@@ -22,6 +22,8 @@
#define __PO_HI_ERROR_CLOCK -15 #define __PO_HI_ERROR_CLOCK -15
#define __PO_HI_ERROR_QUEUE_FULL -20 #define __PO_HI_ERROR_QUEUE_FULL -20
#define __PO_HI_ERROR_UNKNOWN -30
/* Errors related to the pthread library */ /* Errors related to the pthread library */
#define __PO_HI_ERROR_PTHREAD_COND -50 #define __PO_HI_ERROR_PTHREAD_COND -50
#define __PO_HI_ERROR_PTHREAD_MUTEX -51 #define __PO_HI_ERROR_PTHREAD_MUTEX -51
......
...@@ -29,6 +29,10 @@ pthread_cond_t cond_init; ...@@ -29,6 +29,10 @@ pthread_cond_t cond_init;
pthread_mutex_t mutex_init; pthread_mutex_t mutex_init;
#endif #endif
#ifdef RTEMS_PURE
rtems_id __po_hi_main_initialization_barrier;
#endif
int initialized_tasks = 0; int initialized_tasks = 0;
/* The barrier is initialized with __PO_HI_NB_TASKS +1 /* The barrier is initialized with __PO_HI_NB_TASKS +1
* members, because the main function must pass the barrier * members, because the main function must pass the barrier
...@@ -45,28 +49,6 @@ int __po_hi_initialize () ...@@ -45,28 +49,6 @@ int __po_hi_initialize ()
{ {
#if defined (POSIX) || defined (RTEMS_POSIX) #if defined (POSIX) || defined (RTEMS_POSIX)
pthread_mutexattr_t mutex_attr; pthread_mutexattr_t mutex_attr;
#endif
#if defined (RTEMS_POSIX) || defined (RTEMS_PURE)
#include <rtems/rtems/clock.h>
rtems_time_of_day time;
time.year = 1988;
time.month = 12;
time.day = 31;
time.hour = 9;
time.minute = 1;
time.second = 10;
time.ticks = 0;
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) if (pthread_mutexattr_init (&mutex_attr) != 0)
{ {
__DEBUGMSG ("[MAIN] Unable to init mutex attributes\n"); __DEBUGMSG ("[MAIN] Unable to init mutex attributes\n");
...@@ -91,6 +73,36 @@ int __po_hi_initialize () ...@@ -91,6 +73,36 @@ int __po_hi_initialize ()
{ {
return (__PO_HI_ERROR_PTHREAD_COND); return (__PO_HI_ERROR_PTHREAD_COND);
} }
#endif
#if defined (RTEMS_POSIX) || defined (RTEMS_PURE)
#include <rtems/rtems/clock.h>
rtems_status_code ret;
rtems_time_of_day time;
time.year = 1988;
time.month = 12;
time.day = 31;
time.hour = 9;
time.minute = 1;
time.second = 10;
time.ticks = 0;
ret = rtems_clock_set( &time );
if (ret != RTEMS_SUCCESSFUL)
{
__DEBUGMSG ("[MAIN] Cannot set the clock\n");
return __PO_HI_ERROR_CLOCK;
}
__DEBUGMSG ("[MAIN] Create a barrier that wait for %d tasks\n", nb_tasks_to_init);
ret = rtems_barrier_create (rtems_build_name ('B', 'A', 'R', 'M'), RTEMS_BARRIER_AUTOMATIC_RELEASE, nb_tasks_to_init, &__po_hi_main_initialization_barrier);
if (ret != RTEMS_SUCCESSFUL)
{
__DEBUGMSG ("[MAIN] Cannot create the main barrier, return code=%d\n", ret);
}
#endif #endif
__po_hi_initialize_tasking (); __po_hi_initialize_tasking ();
...@@ -122,6 +134,18 @@ int __po_hi_wait_initialization () ...@@ -122,6 +134,18 @@ int __po_hi_wait_initialization ()
pthread_cond_broadcast (&cond_init); pthread_cond_broadcast (&cond_init);
pthread_mutex_unlock (&mutex_init); pthread_mutex_unlock (&mutex_init);
return (__PO_HI_SUCCESS); return (__PO_HI_SUCCESS);
#elif defined (RTEMS_PURE)
rtems_status_code ret;
__DEBUGMSG ("[MAIN] Task wait for the barrier\n");
ret = rtems_barrier_wait (__po_hi_main_initialization_barrier, RTEMS_WAIT);
if (ret != RTEMS_SUCCESSFUL)
{
__DEBUGMSG ("[MAIN] Error while waiting for the barrier, return code=%d\n", ret);
return (__PO_HI_ERROR_UNKNOWN);
}
__DEBUGMSG ("[MAIN] Task release the barrier\n");
return (__PO_HI_SUCCESS);
#else #else
return (__PO_HI_UNAVAILABLE); return (__PO_HI_UNAVAILABLE);
#endif #endif
......
...@@ -129,7 +129,8 @@ int __po_hi_wait_for_next_period (__po_hi_task_id task) ...@@ -129,7 +129,8 @@ int __po_hi_wait_for_next_period (__po_hi_task_id task)
return (__PO_HI_ERROR_TASK_PERIOD); return (__PO_HI_ERROR_TASK_PERIOD);
break; break;
default: default:
return (__PO_HI_UNAVAILABLE); __DEBUGMSG ("Error in rtems_rate_monotonic_period (unknown, error code=%d)\n", ret);
return (__PO_HI_ERROR_UNKNOWN);
break; break;
} }
......
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