[pok-devel] [28] Add arinc GET_PARTITION_STATUS and SET_PARTITION_MODE functions

[ Thread Index | Date Index | More lists.tuxfamily.org/pok-devel Archives ]


Revision: 28
Author:   mha
Date:     2012-02-16 12:21:32 +0100 (Thu, 16 Feb 2012)
Log Message:
-----------
Add arinc GET_PARTITION_STATUS and SET_PARTITION_MODE functions

Modified Paths:
--------------
    trunk/doc/develguide/pok-devel.tex
    trunk/kernel/core/partition.c
    trunk/kernel/core/syscall.c
    trunk/kernel/include/core/partition.h
    trunk/kernel/include/core/syscall.h
    trunk/libpok/arinc653/partition.c
    trunk/libpok/include/core/partition.h
    trunk/libpok/include/core/syscall.h

Modified: trunk/doc/develguide/pok-devel.tex
===================================================================
--- trunk/doc/develguide/pok-devel.tex	2012-02-15 21:07:43 UTC (rev 27)
+++ trunk/doc/develguide/pok-devel.tex	2012-02-16 11:21:32 UTC (rev 28)
@@ -247,7 +247,7 @@
 needs all functions of \texttt{libc/stdio}.
 
 Then, each function of libpok is surrounded with a \texttt{POK\_CONFIG\_NEEDS\_FUNC*}
-or \texttt{POK\_CONFIG\_NEEDS\_*}. \LARGE{You have to introduce that in your code when
+or \texttt{POK\_CONFIG\_NEEDS\_*}. {\LARGE You have to introduce that in your code when
 you introduce new services in POK}.
 
 Then, the file in \texttt{include/core/dependencies.h} specifies which functions

Modified: trunk/kernel/core/partition.c
===================================================================
--- trunk/kernel/core/partition.c	2012-02-15 21:07:43 UTC (rev 27)
+++ trunk/kernel/core/partition.c	2012-02-16 11:21:32 UTC (rev 28)
@@ -48,7 +48,9 @@
 
 uint8_t			 pok_partitions_index = 0;
 
+extern uint64_t		pok_sched_slots[];
 
+
 /**
  **\brief Setup the scheduler used in partition pid
  */
@@ -229,6 +231,9 @@
        * Load the partition in its address space
        */
       pok_partitions[i].thread_main_entry = program_entry;
+      
+      pok_partitions[i].lock_level = 0;
+      pok_partitions[i].start_condition = NORMAL_START;
 
 #ifdef POK_NEEDS_INSTRUMENTATION
       pok_instrumentation_partition_archi (i);
@@ -256,7 +261,7 @@
           * to the NORMAL mode is currently in the INIT mode
           */
 
-         if (pok_partitions[pid].mode != POK_PARTITION_MODE_INIT_WARM)
+         if (pok_partitions[pid].mode == POK_PARTITION_MODE_IDLE)
          {
             return POK_ERRNO_PARTITION_MODE;
          }
@@ -285,16 +290,8 @@
 
 #ifdef POK_NEEDS_ERROR_HANDLING
       case POK_PARTITION_MODE_STOPPED:
-
+ 
          /*
-          * The partition can be stopped once it was in the normal mode
-          */
-         if (pok_partitions[pid].mode != POK_PARTITION_MODE_NORMAL)
-         {
-            return POK_ERRNO_PARTITION_MODE;
-         }
-
-         /*
           * Only the error thread can stop the partition
           */
          if ((POK_CURRENT_PARTITION.thread_error == 0 ) ||
@@ -308,10 +305,11 @@
          break;
 
       case POK_PARTITION_MODE_INIT_WARM:
-         if (pok_partitions[pid].mode != POK_PARTITION_MODE_NORMAL)
-         {
-            return POK_ERRNO_PARTITION_MODE;
-         }
+      case POK_PARTITION_MODE_INIT_COLD:
+	if (pok_partitions[pid].mode == POK_PARTITION_MODE_INIT_COLD && mode == POK_PARTITION_MODE_INIT_WARM)
+          { 
+             return POK_ERRNO_PARTITION_MODE;
+          }
 
          /*
           * Check that only the error thread can restart the partition
@@ -327,7 +325,7 @@
           * was in the NORMAL mode. So, we check the previous mode
           */
 
-         pok_partitions[pid].mode = POK_PARTITION_MODE_INIT_WARM;  /* Here, we change the mode */
+         pok_partitions[pid].mode = mode;  /* Here, we change the mode */
 
          pok_partition_reinit (pid);
 
@@ -367,6 +365,45 @@
    return (pok_partition_set_mode (POK_SCHED_CURRENT_PARTITION, mode));
 }
 
+/**
+ * Get partition information. Used for ARINC GET_PARTITION_STATUS function.
+ */
+pok_ret_t pok_current_partition_get_id (uint8_t *id)
+{
+  *id = POK_SCHED_CURRENT_PARTITION;
+  return POK_ERRNO_OK;
+}
+
+pok_ret_t pok_current_partition_get_period (uint64_t *period)
+{
+  *period = POK_CURRENT_PARTITION.period;
+  return POK_ERRNO_OK;
+}
+
+pok_ret_t pok_current_partition_get_duration (uint64_t *duration)
+{
+  *duration = pok_sched_slots[POK_SCHED_CURRENT_PARTITION];
+  return POK_ERRNO_OK;
+}
+
+pok_ret_t pok_current_partition_get_operating_mode (pok_partition_mode_t *op_mode)
+{
+  *op_mode = POK_CURRENT_PARTITION.mode;
+  return POK_ERRNO_OK;
+}
+
+pok_ret_t pok_current_partition_get_lock_level (uint32_t *lock_level)
+{
+  *lock_level = POK_CURRENT_PARTITION.lock_level;
+  return POK_ERRNO_OK;
+}
+
+pok_ret_t pok_current_partition_get_start_condition (pok_start_condition_t *start_condition)
+{
+  *start_condition = POK_CURRENT_PARTITION.start_condition;
+  return POK_ERRNO_OK;
+}
+
 #ifdef POK_NEEDS_ERROR_HANDLING
 
 /**

Modified: trunk/kernel/core/syscall.c
===================================================================
--- trunk/kernel/core/syscall.c	2012-02-15 21:07:43 UTC (rev 27)
+++ trunk/kernel/core/syscall.c	2012-02-16 11:21:32 UTC (rev 28)
@@ -150,6 +150,24 @@
       case POK_SYSCALL_PARTITION_SET_MODE:
          return pok_partition_set_mode_current ((pok_partition_mode_t)args->arg1);
          break;
+      case POK_SYSCALL_PARTITION_GET_ID:
+	return pok_current_partition_get_id ((uint8_t*)(args->arg1 + infos->base_addr));
+         break;
+      case POK_SYSCALL_PARTITION_GET_PERIOD:
+	return pok_current_partition_get_period ((uint64_t*)(args->arg1 + infos->base_addr));
+	 break;
+      case POK_SYSCALL_PARTITION_GET_DURATION:
+	return pok_current_partition_get_duration ((uint64_t*)(args->arg1 + infos->base_addr));
+	 break;
+      case POK_SYSCALL_PARTITION_GET_LOCK_LEVEL:
+	return pok_current_partition_get_lock_level ((uint32_t*)(args->arg1 + infos->base_addr));
+         break;
+      case POK_SYSCALL_PARTITION_GET_OPERATING_MODE:
+	return pok_current_partition_get_operating_mode ((pok_partition_mode_t*)(args->arg1 + infos->base_addr));
+         break;
+      case POK_SYSCALL_PARTITION_GET_START_CONDITION:
+	return pok_current_partition_get_start_condition ((pok_start_condition_t*)(args->arg1 + infos->base_addr));
+         break;
 #endif
 
 #ifdef POK_NEEDS_ERROR_HANDLING

Modified: trunk/kernel/include/core/partition.h
===================================================================
--- trunk/kernel/include/core/partition.h	2012-02-15 21:07:43 UTC (rev 27)
+++ trunk/kernel/include/core/partition.h	2012-02-16 11:21:32 UTC (rev 28)
@@ -51,6 +51,15 @@
    POK_PARTITION_MODE_STOPPED   = 6, /**< Partition is stopped, it will no longer be executed */
 }pok_partition_mode_t;
 
+typedef enum
+{
+  NORMAL_START          = 0,
+  PARTITION_RESTART     = 1,
+  HM_MODULE_RESTART     = 2,
+  HM_PARTITION_RESTART  = 3
+}pok_start_condition_t;
+
+
 /*!
  * \struct pok_partition_t
  * \brief This structure contains all needed information for partition management
@@ -105,6 +114,9 @@
   uint16_t		io_min;                        /**< If the partition is allowed to perform I/O, the lower bound of the I/O */
   uint16_t		io_max;                        /**< If the partition is allowed to perform I/O, the uppder bound of the I/O */
 #endif
+
+  uint32_t		lock_level;
+  pok_start_condition_t	start_condition;
 } pok_partition_t;
 
 extern pok_partition_t pok_partitions[POK_CONFIG_NB_PARTITIONS];
@@ -144,6 +156,18 @@
 
 pok_ret_t pok_partition_restart_thread (const uint32_t tid);
 
+pok_ret_t pok_current_partition_get_id (uint8_t *id);
+
+pok_ret_t pok_current_partition_get_period (uint64_t *period);
+
+pok_ret_t pok_current_partition_get_duration (uint64_t *duration);
+
+pok_ret_t pok_current_partition_get_operating_mode (pok_partition_mode_t *op_mode);
+
+pok_ret_t pok_current_partition_get_lock_level (uint32_t *lock_level);
+
+pok_ret_t pok_current_partition_get_start_condition (pok_start_condition_t *start_condition);
+
 #endif /* __POK_NEEDS_PARTITIONS */
 
 #endif /* __POK_PARTITION_H__ */

Modified: trunk/kernel/include/core/syscall.h
===================================================================
--- trunk/kernel/include/core/syscall.h	2012-02-15 21:07:43 UTC (rev 27)
+++ trunk/kernel/include/core/syscall.h	2012-02-16 11:21:32 UTC (rev 28)
@@ -66,6 +66,12 @@
 #endif
 #ifdef POK_NEEDS_PARTITIONS
    POK_SYSCALL_PARTITION_SET_MODE                  = 404,
+   POK_SYSCALL_PARTITION_GET_ID                    = 405,
+   POK_SYSCALL_PARTITION_GET_PERIOD                = 406,
+   POK_SYSCALL_PARTITION_GET_DURATION              = 407,
+   POK_SYSCALL_PARTITION_GET_LOCK_LEVEL            = 408,
+   POK_SYSCALL_PARTITION_GET_OPERATING_MODE        = 409,
+   POK_SYSCALL_PARTITION_GET_START_CONDITION       = 410,
 #endif
 #ifdef POK_NEEDS_IO
    POK_SYSCALL_INB                                 = 501,

Modified: trunk/libpok/arinc653/partition.c
===================================================================
--- trunk/libpok/arinc653/partition.c	2012-02-15 21:07:43 UTC (rev 27)
+++ trunk/libpok/arinc653/partition.c	2012-02-16 11:21:32 UTC (rev 28)
@@ -27,16 +27,23 @@
 void GET_PARTITION_STATUS (PARTITION_STATUS_TYPE *partition_status,
                            RETURN_CODE_TYPE      *return_code)
 {
-   (void) partition_status;
-   *return_code = NOT_AVAILABLE;
+  pok_current_partition_get_id(&partition_status->IDENTIFIER);
+  pok_current_partition_get_period(&partition_status->PERIOD);
+  pok_current_partition_get_duration(&partition_status->DURATION);
+  pok_current_partition_get_lock_level(&partition_status->LOCK_LEVEL);
+  pok_current_partition_get_operating_mode(&partition_status->OPERATING_MODE);
+  pok_current_partition_get_start_condition(&partition_status->START_CONDITION);
+  *return_code = NO_ERROR;
 }
 
 void SET_PARTITION_MODE (OPERATING_MODE_TYPE operating_mode,
                          RETURN_CODE_TYPE *return_code)
 {
-   pok_partition_mode_t core_mode = POK_PARTITION_MODE_NORMAL;
-   pok_ret_t            core_ret;
+  pok_partition_mode_t core_mode;
+  pok_ret_t            core_ret;
+  pok_partition_mode_t current_mode;
 
+  pok_current_partition_get_operating_mode(&current_mode);
    switch (operating_mode)
    {
       case IDLE:
@@ -49,17 +56,29 @@
 
       case COLD_START:
          core_mode = POK_PARTITION_MODE_INIT_COLD;
-         break;
+         *return_code = NOT_AVAILABLE;
+	 return;
 
       case WARM_START:
          core_mode = POK_PARTITION_MODE_INIT_WARM;
          break;
 
       default:
-         *return_code = INVALID_MODE;
+         *return_code = INVALID_PARAM;
          return;
    }
 
+   if (current_mode == core_mode)
+     {
+       *return_code = NO_ACTION;
+       return ;
+     }
+   if (current_mode == POK_PARTITION_MODE_INIT_COLD &&
+       core_mode == POK_PARTITION_MODE_INIT_WARM)
+     {
+       *return_code = INVALID_MODE;
+       return ;
+     }
    core_ret = pok_partition_set_mode (core_mode);
    *return_code = core_ret;
 }

Modified: trunk/libpok/include/core/partition.h
===================================================================
--- trunk/libpok/include/core/partition.h	2012-02-15 21:07:43 UTC (rev 27)
+++ trunk/libpok/include/core/partition.h	2012-02-16 11:21:32 UTC (rev 28)
@@ -32,6 +32,18 @@
    POK_PARTITION_MODE_STOPPED   = 6,
 }pok_partition_mode_t;
 
+
 #define pok_partition_set_mode(mode) pok_syscall2(POK_SYSCALL_PARTITION_SET_MODE,(uint32_t)mode,0)
 
+#define pok_current_partition_get_id(id) pok_syscall2(POK_SYSCALL_PARTITION_GET_ID,(uint32_t)id,0)
+
+#define pok_current_partition_get_period(period) pok_syscall2(POK_SYSCALL_PARTITION_GET_PERIOD,(uint32_t)period,0)
+
+#define pok_current_partition_get_duration(duration) pok_syscall2(POK_SYSCALL_PARTITION_GET_DURATION,(uint32_t)duration,0)
+
+#define pok_current_partition_get_lock_level(lock_level) pok_syscall2(POK_SYSCALL_PARTITION_GET_LOCK_LEVEL,(uint32_t)lock_level,0)
+
+#define pok_current_partition_get_operating_mode(op_mode) pok_syscall2(POK_SYSCALL_PARTITION_GET_OPERATING_MODE,(uint32_t)op_mode,0)
+
+#define pok_current_partition_get_start_condition(start_condition) pok_syscall2(POK_SYSCALL_PARTITION_GET_START_CONDITION,(uint32_t)start_condition,0)
 #endif

Modified: trunk/libpok/include/core/syscall.h
===================================================================
--- trunk/libpok/include/core/syscall.h	2012-02-15 21:07:43 UTC (rev 27)
+++ trunk/libpok/include/core/syscall.h	2012-02-16 11:21:32 UTC (rev 28)
@@ -66,6 +66,12 @@
 #endif
 #ifdef POK_NEEDS_PARTITIONS
    POK_SYSCALL_PARTITION_SET_MODE                  = 404,
+   POK_SYSCALL_PARTITION_GET_ID	                   = 405,
+   POK_SYSCALL_PARTITION_GET_PERIOD                = 406,
+   POK_SYSCALL_PARTITION_GET_DURATION              = 407,
+   POK_SYSCALL_PARTITION_GET_LOCK_LEVEL            = 408,
+   POK_SYSCALL_PARTITION_GET_OPERATING_MODE        = 409,
+   POK_SYSCALL_PARTITION_GET_START_CONDITION       = 410,
 #endif
 #ifdef POK_NEEDS_IO
    POK_SYSCALL_INB                                 = 501,


Mail converted by MHonArc 2.6.19+ http://listengine.tuxfamily.org/