[pok-devel] [38] dd ARINC653 suspend and resume functions

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


Revision: 38
Author:   mha
Date:     2012-08-29 14:45:22 +0200 (Wed, 29 Aug 2012)
Log Message:
-----------
dd ARINC653 suspend and resume functions

Modified Paths:
--------------
    trunk/kernel/core/syscall.c
    trunk/kernel/core/thread.c
    trunk/kernel/include/core/syscall.h
    trunk/kernel/include/core/thread.h
    trunk/libpok/arinc653/process.c
    trunk/libpok/core/Makefile
    trunk/libpok/core/threadid.c
    trunk/libpok/include/core/syscall.h
    trunk/libpok/include/core/thread.h
    trunk/misc/release-files

Added Paths:
-----------
    trunk/libpok/core/threadresume.c

Modified: trunk/kernel/core/syscall.c
===================================================================
--- trunk/kernel/core/syscall.c	2012-08-29 10:04:41 UTC (rev 37)
+++ trunk/kernel/core/syscall.c	2012-08-29 12:45:22 UTC (rev 38)
@@ -129,6 +129,13 @@
 	   return pok_thread_set_priority (args->arg1, args->arg2);
 	   break;
 
+   case POK_SYSCALL_THREAD_RESUME:
+	   return pok_thread_resume (args->arg1);
+	   break;
+   case POK_SYSCALL_THREAD_SUSPEND_TARGET:
+	   return pok_thread_suspend_target (args->arg1);
+	   break;
+
 #ifdef POK_NEEDS_ERROR_HANDLING
 
 /**

Modified: trunk/kernel/core/thread.c
===================================================================
--- trunk/kernel/core/thread.c	2012-08-29 10:04:41 UTC (rev 37)
+++ trunk/kernel/core/thread.c	2012-08-29 12:45:22 UTC (rev 38)
@@ -324,4 +324,23 @@
 	return POK_ERRNO_OK;
 }
 
+pok_ret_t pok_thread_resume (const uint32_t id)
+{
+	if (POK_CURRENT_PARTITION.thread_index_low > id || POK_CURRENT_PARTITION.thread_index_high < id)
+		return POK_ERRNO_THREADATTR;
+	pok_threads[id].wakeup_time = POK_GETTICK();
+	pok_threads[id].state = POK_STATE_RUNNABLE;
+	/* preemption is always enabled */
+	pok_sched();
+	return POK_ERRNO_OK;
+}
+
+pok_ret_t pok_thread_suspend_target (const uint32_t id)
+{
+	if (POK_CURRENT_PARTITION.thread_index_low > id || POK_CURRENT_PARTITION.thread_index_high < id || id == POK_SCHED_CURRENT_THREAD)
+		return POK_ERRNO_THREADATTR;
+	pok_threads[id].state = POK_STATE_STOPPED;
+	return POK_ERRNO_OK;
+}
+
 #endif

Modified: trunk/kernel/include/core/syscall.h
===================================================================
--- trunk/kernel/include/core/syscall.h	2012-08-29 10:04:41 UTC (rev 37)
+++ trunk/kernel/include/core/syscall.h	2012-08-29 12:45:22 UTC (rev 38)
@@ -36,6 +36,8 @@
    POK_SYSCALL_THREAD_ID                           =  58,
    POK_SYSCALL_THREAD_STATUS                       =  59,
    POK_SYSCALL_THREAD_SET_PRIORITY								 =  60,
+   POK_SYSCALL_THREAD_RESUME                       =  61,
+   POK_SYSCALL_THREAD_SUSPEND_TARGET               =  62,
 #ifdef POK_NEEDS_PORTS_SAMPLING
    POK_SYSCALL_MIDDLEWARE_SAMPLING_ID              = 101,
    POK_SYSCALL_MIDDLEWARE_SAMPLING_READ            = 102,

Modified: trunk/kernel/include/core/thread.h
===================================================================
--- trunk/kernel/include/core/thread.h	2012-08-29 10:04:41 UTC (rev 37)
+++ trunk/kernel/include/core/thread.h	2012-08-29 12:45:22 UTC (rev 38)
@@ -57,35 +57,35 @@
 
 typedef struct
 {
-   uint8_t      priority;
-   uint64_t     period;
-   uint64_t     deadline;
-   uint64_t     time_capacity;
-   uint64_t     remaining_time_capacity;
-   uint64_t     next_activation;
-   pok_state_t  state;
-   uint64_t	end_time;
-   uint64_t     wakeup_time;
+	 uint8_t      priority;
+	 uint64_t     period;
+	 uint64_t     deadline;
+	 uint64_t     time_capacity;
+	 uint64_t     remaining_time_capacity;
+	 uint64_t     next_activation;
+	 pok_state_t  state;
+	 uint64_t	end_time;
+	 uint64_t     wakeup_time;
 #ifdef POK_NEEDS_SCHED_HFPPS
-   uint64_t	payback; /**< Payback for HFPPS scheduling algorithm */
+	 uint64_t	payback; /**< Payback for HFPPS scheduling algorithm */
 #endif /* POK_NEEDS_SCHED_HFPPS */
-   void		   *entry;
-   uint8_t	   partition;
-   uint32_t	   sp;
-   uint32_t    init_stack_addr;
-   /* stack pointer
-    * FIXME: this is platform-dependent code, we have to handle that ! */
+	 void			 *entry;
+	 uint8_t		 partition;
+	 uint32_t		 sp;
+	 uint32_t    init_stack_addr;
+	 /* stack pointer
+		* FIXME: this is platform-dependent code, we have to handle that ! */
 } pok_thread_t;
 
 typedef struct
 {
-   uint8_t      priority;         /* Priority is from 0 to 255 */
-   void*        entry;            /* entrypoint of the thread  */
-   uint64_t     period;
-   uint64_t     deadline;
-   uint64_t     time_capacity;
-   uint32_t     stack_size;
-   pok_state_t  state;
+	 uint8_t      priority;         /* Priority is from 0 to 255 */
+	 void*        entry;            /* entrypoint of the thread  */
+	 uint64_t     period;
+	 uint64_t     deadline;
+	 uint64_t     time_capacity;
+	 uint32_t     stack_size;
+	 pok_state_t  state;
 } pok_thread_attr_t;
 /*
  * Attributes given to create a thread
@@ -101,11 +101,13 @@
 pok_ret_t      pok_thread_restart (const uint32_t tid);
 pok_ret_t      pok_thread_get_status (const uint32_t id, pok_thread_attr_t *attr);
 pok_ret_t      pok_thread_set_priority (const uint32_t id, const uint32_t priority);
+pok_ret_t      pok_thread_resume (const uint32_t id);
+pok_ret_t      pok_thread_suspend_target (const uint32_t id);
 
 #ifdef POK_NEEDS_PARTITIONS
 pok_ret_t		pok_partition_thread_create (uint32_t* thread_id,
-                                            const pok_thread_attr_t* attr,
-                                            const uint8_t  partition_id);
+																						const pok_thread_attr_t* attr,
+																						const uint8_t  partition_id);
 #endif
 
 extern pok_thread_t              pok_threads[POK_CONFIG_NB_THREADS];

Modified: trunk/libpok/arinc653/process.c
===================================================================
--- trunk/libpok/arinc653/process.c	2012-08-29 10:04:41 UTC (rev 37)
+++ trunk/libpok/arinc653/process.c	2012-08-29 12:45:22 UTC (rev 38)
@@ -155,20 +155,66 @@
 	 *return_code = NOT_AVAILABLE;
 }
 
+#endif
+
 void SUSPEND (PROCESS_ID_TYPE    process_id,
 							RETURN_CODE_TYPE   *return_code )
 {
-	 (void) process_id;
-	 *return_code = NOT_AVAILABLE;
+	pok_thread_attr_t  attr;
+	pok_ret_t    core_ret;
+
+	core_ret = pok_thread_status (process_id, &attr);
+	if (attr.state == DORMANT)
+		{
+			*return_code = INVALID_MODE;
+			return ;
+		}
+	if (attr.period == INFINITE_TIME_VALUE)
+		{
+			*return_code = INVALID_MODE;
+			return ;
+		}
+	if (attr.state == WAITING)
+		{
+			*return_code = NO_ACTION;
+			return ;
+		}
+	core_ret = pok_thread_suspend_target (process_id);
+	*return_code = core_ret;
 }
 
 void RESUME (PROCESS_ID_TYPE     process_id,
 						 RETURN_CODE_TYPE    *return_code )
 {
-	 (void) process_id;
-	 *return_code = NOT_AVAILABLE;
+	pok_thread_attr_t  attr;
+	pok_ret_t    core_ret;
+
+	core_ret = pok_thread_status (process_id, &attr);
+	if (core_ret != 0)
+		{
+			*return_code = INVALID_PARAM;
+			return ;
+		}
+	if (attr.state == DORMANT)
+		{
+			*return_code = INVALID_MODE;
+			return ;
+		}
+	if (attr.period == INFINITE_TIME_VALUE)
+		{
+			*return_code = INVALID_MODE;
+			return ;
+		}
+	if (attr.state != WAITING)
+		{
+			*return_code = INVALID_MODE;
+			return ;
+		}
+	core_ret = pok_thread_resume (process_id);
+	*return_code = core_ret;
 }
 
+#ifndef POK_CONFIG_OPTIMIZE_FOR_GENERATED_CODE
 void STOP (PROCESS_ID_TYPE    process_id,
 					 RETURN_CODE_TYPE   *return_code )
 {

Modified: trunk/libpok/core/Makefile
===================================================================
--- trunk/libpok/core/Makefile	2012-08-29 10:04:41 UTC (rev 37)
+++ trunk/libpok/core/Makefile	2012-08-29 12:45:22 UTC (rev 38)
@@ -37,7 +37,8 @@
 			threadsleep.o \
 			threadstatus.o \
 			threadid.o \
-			threadpriority.o
+			threadpriority.o \
+			threadresume.o
 
 LO_DEPS=
 

Modified: trunk/libpok/core/threadid.c
===================================================================
--- trunk/libpok/core/threadid.c	2012-08-29 10:04:41 UTC (rev 37)
+++ trunk/libpok/core/threadid.c	2012-08-29 12:45:22 UTC (rev 38)
@@ -1,6 +1,6 @@
 /*
  *                               POK header
- * 
+ *
  * The following file is a part of the POK project. Any modification should
  * made according to the POK licence. You CANNOT use this file or a part of
  * this file is this part of a file for your own project
@@ -9,9 +9,9 @@
  *
  * Please follow the coding guidelines described in doc/CODING_GUIDELINES
  *
- *                                      Copyright (c) 2007-2009 POK team 
+ *                                      Copyright (c) 2007-2009 POK team
  *
- * Created by julien on Tue Aug 25 19:43:46 2009 
+ * Created by julien on Tue Aug 25 19:43:46 2009
  */
 
 
@@ -26,8 +26,6 @@
 
 pok_ret_t pok_thread_id (uint32_t* thread_id)
 {
-   return pok_syscall2 (POK_SYSCALL_THREAD_ID, (uint32_t)thread_id, 0);
+	 return pok_syscall2 (POK_SYSCALL_THREAD_ID, (uint32_t)thread_id, 0);
 }
 #endif
-
-

Added: trunk/libpok/core/threadresume.c
===================================================================
--- trunk/libpok/core/threadresume.c	                        (rev 0)
+++ trunk/libpok/core/threadresume.c	2012-08-29 12:45:22 UTC (rev 38)
@@ -0,0 +1,31 @@
+/*
+ *                               POK header
+ *
+ * The following file is a part of the POK project. Any modification should
+ * made according to the POK licence. You CANNOT use this file or a part of
+ * this file is this part of a file for your own project
+ *
+ * For more information on the POK licence, please see our LICENCE FILE
+ *
+ * Please follow the coding guidelines described in doc/CODING_GUIDELINES
+ *
+ *                                      Copyright (c) 2007-2012 POK team
+ *
+ * Created by matias on Wed May 11 14:15:08 2012
+ */
+
+#include <core/dependencies.h>
+
+#ifdef POK_NEEDS_THREADS
+#include <arch.h>
+#include <types.h>
+#include <core/syscall.h>
+#include <core/thread.h>
+
+pok_ret_t pok_thread_resume (const uint32_t thread_id)
+{
+	return pok_syscall2  (POK_SYSCALL_THREAD_RESUME,
+	                      (uint32_t)thread_id, 0);
+}
+
+#endif

Modified: trunk/libpok/include/core/syscall.h
===================================================================
--- trunk/libpok/include/core/syscall.h	2012-08-29 10:04:41 UTC (rev 37)
+++ trunk/libpok/include/core/syscall.h	2012-08-29 12:45:22 UTC (rev 38)
@@ -36,6 +36,8 @@
 	 POK_SYSCALL_THREAD_ID                           =  58,
 	 POK_SYSCALL_THREAD_STATUS                       =  59,
 	 POK_SYSCALL_THREAD_SET_PRIORITY								 =  60,
+	 POK_SYSCALL_THREAD_RESUME                       =  61,
+	 POK_SYSCALL_THREAD_SUSPEND_TARGET               =  62,
 #ifdef POK_NEEDS_PORTS_SAMPLING
 	 POK_SYSCALL_MIDDLEWARE_SAMPLING_ID              = 101,
 	 POK_SYSCALL_MIDDLEWARE_SAMPLING_READ            = 102,

Modified: trunk/libpok/include/core/thread.h
===================================================================
--- trunk/libpok/include/core/thread.h	2012-08-29 10:04:41 UTC (rev 37)
+++ trunk/libpok/include/core/thread.h	2012-08-29 12:45:22 UTC (rev 38)
@@ -59,13 +59,16 @@
 void				 pok_thread_init (void);
 pok_ret_t      pok_thread_status(const uint32_t thread_id, pok_thread_attr_t* attr);
 pok_ret_t      pok_thread_set_priority(const uint32_t thread_id, const uint32_t priority);
+pok_ret_t      pok_thread_resume(const uint32_t thread_id);
 
-
 #define pok_thread_sleep_until(time) pok_syscall2(POK_SYSCALL_THREAD_SLEEP_UNTIL,(uint32_t)time,0)
 
 #define pok_thread_wait_infinite() pok_thread_suspend()
 
 #define pok_thread_suspend() pok_syscall2(POK_SYSCALL_THREAD_SUSPEND,NULL,NULL)
+
+#define pok_thread_suspend_target(thread_id) pok_syscall2(POK_SYSCALL_THREAD_SUSPEND_TARGET,thread_id,0)
+
 /*
  * Similar to: pok_ret_t      pok_thread_suspend (void);
  */

Modified: trunk/misc/release-files
===================================================================
--- trunk/misc/release-files	2012-08-29 10:04:41 UTC (rev 37)
+++ trunk/misc/release-files	2012-08-29 12:45:22 UTC (rev 38)
@@ -206,6 +206,7 @@
 libpok/core/threadpriority.c
 libpok/core/timecomputedeadline.c
 libpok/core/timeget.c
+libpok/core/threadresume.c
 libpok/include/arch/x86/types.h
 libpok/include/arch/x86/ioports.h
 libpok/include/arch/x86/pci.h


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