POK(kernelpart)
/home/jaouen/pok_official/pok/trunk/kernel/include/core/thread.h
Go to the documentation of this file.
00001 /*
00002  *                               POK header
00003  *
00004  * The following file is a part of the POK project. Any modification should
00005  * made according to the POK licence. You CANNOT use this file or a part of
00006  * this file is this part of a file for your own project
00007  *
00008  * For more information on the POK licence, please see our LICENCE FILE
00009  *
00010  * Please follow the coding guidelines described in doc/CODING_GUIDELINES
00011  *
00012  *                                      Copyright (c) 2007-2009 POK team
00013  *
00014  * Created by julien on Thu Jan 15 23:34:13 2009
00015  */
00016 
00017 
00018 #ifndef __POK_THREAD_H__
00019 #define __POK_THREAD_H__
00020 
00021 #ifdef POK_NEEDS_THREADS
00022 
00023 #include <types.h>
00024 #include <errno.h>
00025 #include <core/sched.h>
00026 
00027 
00028 /*
00029  * In POK, we add a kernel thread and an idle thread. The kernel
00030  * thread is used to execute kernel code while the idle thread
00031  * is used to save processor resources.
00032  */
00033 
00034 #define KERNEL_THREAD           POK_CONFIG_NB_THREADS -2
00035 #define IDLE_THREAD        POK_CONFIG_NB_THREADS -1
00036 
00037 #define POK_THREAD_DEFAULT_TIME_CAPACITY 10
00038 
00039 /*
00040 #define KERNEL_THREAD           POK_CONFIG_NB_THREADS
00041 #define IDLE_THREAD        POK_CONFIG_NB_THREADS + 1
00042 */
00043 
00044 #define POK_THREAD_MAX_PRIORITY  200
00045 
00046 
00047 /*
00048  * IDLE_STACK_SIZE is the stack size of the idle thread
00049  * DEFAULT_STACK_SIZE if the stack size of regulard threads
00050  */
00051 #define IDLE_STACK_SIZE         1024
00052 #define DEFAULT_STACK_SIZE      4096
00053 
00054 #ifndef POK_USER_STACK_SIZE
00055 #define POK_USER_STACK_SIZE 8096
00056 #endif
00057 
00058 typedef struct
00059 {
00060          uint8_t      priority;
00061          uint64_t     period;
00062          uint64_t     deadline;
00063          uint64_t     time_capacity;
00064          uint64_t     remaining_time_capacity;
00065          uint64_t     next_activation;
00066          pok_state_t  state;
00067          uint64_t       end_time;
00068          uint64_t     wakeup_time;
00069 #ifdef POK_NEEDS_SCHED_HFPPS
00070          uint64_t       payback; 
00071 #endif /* POK_NEEDS_SCHED_HFPPS */
00072          void                    *entry;
00073          uint8_t                 partition;
00074          uint32_t                sp;
00075          uint32_t    init_stack_addr;
00076   uint8_t       base_priority;
00077          /* stack pointer
00078                 * FIXME: this is platform-dependent code, we have to handle that ! */
00079 } pok_thread_t;
00080 
00081 typedef struct
00082 {
00083          uint8_t      priority;         /* Priority is from 0 to 255 */
00084          void*        entry;            /* entrypoint of the thread  */
00085          uint64_t     period;
00086          uint64_t     deadline;
00087          uint64_t     time_capacity;
00088          uint32_t     stack_size;
00089          pok_state_t  state;
00090 } pok_thread_attr_t;
00091 /*
00092  * Attributes given to create a thread
00093  */
00094 
00095 void           pok_thread_init (void);
00096 pok_ret_t      pok_thread_create (uint8_t* thread_id, const pok_thread_attr_t* attr);
00097 pok_ret_t      pok_thread_sleep (const uint32_t ms);
00098 pok_ret_t      pok_thread_sleep_until (const uint32_t ms);
00099 pok_ret_t      pok_thread_suspend (void);
00100 void           pok_thread_start (void (*entry)(), unsigned int id);
00101 pok_ret_t      pok_thread_suspend (void);
00102 pok_ret_t      pok_thread_restart (const uint32_t tid);
00103 pok_ret_t pok_thread_delayed_start (const uint32_t id, const uint32_t ms);
00104 pok_ret_t      pok_thread_get_status (const uint32_t id, pok_thread_attr_t *attr);
00105 pok_ret_t      pok_thread_set_priority (const uint32_t id, const uint32_t priority);
00106 pok_ret_t      pok_thread_resume (const uint32_t id);
00107 pok_ret_t      pok_thread_suspend_target (const uint32_t id);
00108 
00109 #ifdef POK_NEEDS_PARTITIONS
00110 pok_ret_t               pok_partition_thread_create (uint32_t* thread_id,
00111                                                                                                                                                                                 const pok_thread_attr_t* attr,
00112                                                                                                                                                                                 const uint8_t  partition_id);
00113 #endif
00114 
00115 extern pok_thread_t              pok_threads[POK_CONFIG_NB_THREADS];
00116 
00117 #define POK_CURRENT_THREAD pok_threads[POK_SCHED_CURRENT_THREAD]
00118 
00119 #endif /* __POK_NEEDS_THREADS */
00120 
00121 #endif /* __POK_THREAD_H__ */